cvs commit: ALFS/nALFS/src/handlers conditionals.c alfs.c build.c check.c chroot.c configure.c copy.c download.c execute.c link.c log.c make.c mkdir.c move.c owner.c ownership.c package.c patch.c permissions.c postbuild.c prebuild.c search_replace.c setenv.c stage.c stamp.c su.c textdump.c unpack.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Thu Feb 5 21:54:37 PST 2004


kpfleming    04/02/05 22:54:37

  Modified:    nALFS/src backend.c backend.h handlers.h
               nALFS/src/handlers alfs.c build.c check.c chroot.c
                        configure.c copy.c download.c execute.c link.c
                        log.c make.c mkdir.c move.c owner.c ownership.c
                        package.c patch.c permissions.c postbuild.c
                        prebuild.c search_replace.c setenv.c stage.c
                        stamp.c su.c textdump.c unpack.c
  Added:       nALFS/src/handlers conditionals.c
  Log:
  phase 1 of conditional logic changes
  src/backend changes allow for filtering list of child elements to be run
  src/handlers.h changes allow handlers to flagged with multiple types
  all handlers type changed from 0 to HTYPE_NORMAL
  all handler_info structure arrays last element changed to assign only "name" element to eliminate compiler warnings when structure definition is extended
  add <then> and <else> elements to stage.c
  
  Revision  Changes    Path
  1.7       +48 -5     ALFS/nALFS/src/backend.c
  
  Index: backend.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/backend.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- backend.c	3 Nov 2003 21:45:04 -0000	1.6
  +++ backend.c	6 Feb 2004 05:54:36 -0000	1.7
  @@ -1,9 +1,10 @@
   /*
    *  backend.c - Backend.
    *
  - *  Copyright (C) 2001, 2002
  + *  Copyright (C) 2001, 2002, 2004
    *
    *  Neven Has <haski at sezampro.yu>
  + *  Kevin P. Fleming <kpfleming at linuxfromscratch.org>
    *
    *  This program is free software; you can redistribute it and/or modify
    *  it under the terms of the GNU General Public License as published by
  @@ -376,17 +377,59 @@
   	return i;
   }
   
  -int execute_children(element_s *el)
  +int do_execute_test_element(element_s *element, int *result)
  +{
  +	int i = 0;
  +	element_s *profile = get_profile_by_element(element);
  +
  +
  +	if (! (Can_run(element) && element->should_run)) {
  +		return 0;
  +	}
  +
  +	comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_STARTED,
  +		"%s %s %d", profile->name, element->name, element->id);
  +
  +	if (*opt_use_relative_dirs)
  +		change_to_profiles_dir(element);
  +
  +	i = element->handler->info->test(element, result);
  +
  +	if (i == 0) {
  +		// TODO: Is there a point of setting these at all?
  +		element->run_status = get_element_status(element);
  +		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_ENDED,
  +			"%s %s %d", profile->name, element->name, element->id);
  +	} else {
  +		element->run_status = RUN_STATUS_FAILED;
  +		comm_send_ctrl_msg(BACKEND_CTRL_SOCK, CTRL_ELEMENT_FAILED,
  +			"%s %s %d", profile->name, element->name, element->id);
  +	}
  +
  +	return i;
  +}
  +
  +int execute_children(element_s *element)
  +{
  +	return execute_children_filtered(element,
  +					 HTYPE_NORMAL | HTYPE_EXECUTE | 
  +					 HTYPE_PACKAGE | HTYPE_TEXTDUMP);
  +}
  +
  +int execute_children_filtered(element_s *element, handler_type_e type_filter)
   {
   	element_s *child;
   
   
  -	for (child = el->children; child; child = child->next) {
  +	for (child = element->children; child; child = child->next) {
   		int i;
   
  -		if ((i = do_execute_element(child))) {
  +		if (child->handler &&
  +		    ((child->handler->info->type & type_filter) == 0))
  +			continue;
  +
  +		if ((i = do_execute_element(child)))
   			return i;
  -		}
   	}
   
   	return 0;
  
  
  
  1.3       +5 -1      ALFS/nALFS/src/backend.h
  
  Index: backend.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/backend.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- backend.h	17 Sep 2003 21:51:17 -0000	1.2
  +++ backend.h	6 Feb 2004 05:54:36 -0000	1.3
  @@ -1,9 +1,10 @@
   /*
    *  backend.h - Backend.
    *
  - *  Copyright (C) 2001, 2002
  + *  Copyright (C) 2001, 2002, 2004
    *
    *  Neven Has <haski at sezampro.yu>
  + *  Kevin P. Fleming <kpfleming at linuxfromscratch.org>
    *
    *  This program is free software; you can redistribute it and/or modify
    *  it under the terms of the GNU General Public License as published by
  @@ -27,6 +28,7 @@
   
   #include "parser.h"
   #include "comm.h"
  +#include "handlers.h"
   
   
   #define Start_receiving_sigio() \
  @@ -42,7 +44,9 @@
   
   int execute_command(const char *format, ...);
   
  +int do_execute_test_element(element_s *element, int *result);
   int execute_children(element_s *element);
  +int execute_children_filtered(element_s *element, handler_type_e type_filter);
   
   void start_backend(element_s *el);
   
  
  
  
  1.8       +12 -5     ALFS/nALFS/src/handlers.h
  
  Index: handlers.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- handlers.h	28 Oct 2003 01:18:57 -0000	1.7
  +++ handlers.h	6 Feb 2004 05:54:36 -0000	1.8
  @@ -1,9 +1,10 @@
   /*
    *  handlers.h - Handlers' functions.
    *
  - *  Copyright (C) 2001, 2002
  + *  Copyright (C) 2001, 2002, 2004
    *
    *  Neven Has <haski at sezampro.yu>
  + *  Kevin P. Fleming <kpfleming at linuxfromscratch.org>
    *
    *  This program is free software; you can redistribute it and/or modify
    *  it under the terms of the GNU General Public License as published by
  @@ -30,10 +31,13 @@
   
   
   typedef enum handler_type_e {
  -	/* Using 0 for all other handlers, for now */
  -	HTYPE_EXECUTE = 1,
  -	HTYPE_PACKAGE,
  -	HTYPE_TEXTDUMP
  +	HTYPE_NORMAL = 1,
  +	HTYPE_PACKAGE = 2,
  +	HTYPE_TEXTDUMP = 4,
  +	HTYPE_TEST = 8,		/* handler provides a test result */
  +	HTYPE_TRUE_RESULT = 16,	/* handler should be run for a true test */
  +	HTYPE_FALSE_RESULT = 32,/* handler should be run for a false test */
  +	HTYPE_EXECUTE = 64,
   } handler_type_e;
   
   typedef enum handler_data_e {
  @@ -42,6 +46,7 @@
   
   typedef char *(*handler_data_f)(element_s *, handler_data_e data);
   typedef int (*handler_f)(element_s *);
  +typedef int (*handler_test)(element_s *, int *);
   
   typedef struct handler_info_s {
   	const char *name;		/* Name of the element it handles. */
  @@ -60,6 +65,8 @@
   	int priority;           /* Higher priority handlers "override" lower
   				   priority ones (allows user to make custom
   				   handlers that replace standard ones) */
  +
  +	handler_test test;	/* used by HTYPE_TEST */
   } handler_info_s;
   
   
  
  
  
  1.12      +5 -5      ALFS/nALFS/src/handlers/alfs.c
  
  Index: alfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/alfs.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- alfs.c	23 Nov 2003 19:38:16 -0000	1.11
  +++ alfs.c	6 Feb 2004 05:54:36 -0000	1.12
  @@ -54,7 +54,7 @@
   		.syntax_version = "2.0",
   		.parameters = alfs_parameters,
   		.main = alfs_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
  @@ -67,7 +67,7 @@
   		.syntax_version = "3.0",
   		.parameters = alfs_parameters,
   		.main = alfs_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
  @@ -80,7 +80,7 @@
   		.syntax_version = "3.1",
   		.parameters = alfs_parameters,
   		.main = alfs_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
  @@ -93,13 +93,13 @@
   		.syntax_version = "3.2",
   		.parameters = alfs_parameters,
   		.main = alfs_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.12      +2 -2      ALFS/nALFS/src/handlers/build.c
  
  Index: build.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/build.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.c	4 Nov 2003 19:42:51 -0000	1.11
  +++ build.c	6 Feb 2004 05:54:36 -0000	1.12
  @@ -67,13 +67,13 @@
   		.syntax_version = "2.0",
   		.parameters = build_parameters,
   		.main = build_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.11      +2 -2      ALFS/nALFS/src/handlers/check.c
  
  Index: check.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/check.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- check.c	6 Nov 2003 17:01:13 -0000	1.10
  +++ check.c	6 Feb 2004 05:54:36 -0000	1.11
  @@ -135,13 +135,13 @@
   		.syntax_version = "3.0",
   		.parameters = check_parameters,
   		.main = check_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +2 -2      ALFS/nALFS/src/handlers/chroot.c
  
  Index: chroot.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/chroot.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- chroot.c	6 Nov 2003 17:01:13 -0000	1.12
  +++ chroot.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -127,13 +127,13 @@
   		.syntax_version = "2.0",
   		.parameters = chroot_parameters,
   		.main = chroot_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +5 -5      ALFS/nALFS/src/handlers/configure.c
  
  Index: configure.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/configure.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- configure.c	23 Nov 2003 19:38:16 -0000	1.12
  +++ configure.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -138,7 +138,7 @@
   		.syntax_version = "2.0",
   		.parameters = configure_parameters_ver2,
   		.main = configure_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -151,7 +151,7 @@
   		.syntax_version = "3.0",
   		.parameters = configure_parameters_ver3,
   		.main = configure_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -164,7 +164,7 @@
   		.syntax_version = "3.1",
   		.parameters = configure_parameters_ver3,
   		.main = configure_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -177,13 +177,13 @@
   		.syntax_version = "3.2",
   		.parameters = configure_parameters_ver3,
   		.main = configure_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +5 -5      ALFS/nALFS/src/handlers/copy.c
  
  Index: copy.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/copy.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- copy.c	23 Nov 2003 19:38:16 -0000	1.12
  +++ copy.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -234,7 +234,7 @@
   		.syntax_version = "2.0",
   		.parameters = copy_parameters_ver2,
   		.main = copy_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -247,7 +247,7 @@
   		.syntax_version = "3.0",
   		.parameters = copy_parameters_ver3,
   		.main = copy_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -260,7 +260,7 @@
   		.syntax_version = "3.1",
   		.parameters = copy_parameters_ver3,
   		.main = copy_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -273,13 +273,13 @@
   		.syntax_version = "3.2",
   		.parameters = copy_parameters_ver3,
   		.main = copy_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.14      +3 -3      ALFS/nALFS/src/handlers/download.c
  
  Index: download.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/download.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- download.c	3 Feb 2004 20:26:59 -0000	1.13
  +++ download.c	6 Feb 2004 05:54:36 -0000	1.14
  @@ -246,7 +246,7 @@
   		.syntax_version = "3.1",
   		.parameters = download_parameters,
   		.main = download_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -259,13 +259,13 @@
   		.syntax_version = "3.2",
   		.parameters = download_parameters_3_2,
   		.main = download_main_3_2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.16      +1 -1      ALFS/nALFS/src/handlers/execute.c
  
  Index: execute.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/execute.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- execute.c	23 Nov 2003 19:38:16 -0000	1.15
  +++ execute.c	6 Feb 2004 05:54:36 -0000	1.16
  @@ -206,6 +206,6 @@
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +5 -5      ALFS/nALFS/src/handlers/link.c
  
  Index: link.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/link.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- link.c	23 Nov 2003 19:38:16 -0000	1.12
  +++ link.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -265,7 +265,7 @@
   		.syntax_version = "2.0",
   		.parameters = link_parameters_ver2,
   		.main = link_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -278,7 +278,7 @@
   		.syntax_version = "3.0",
   		.parameters = link_parameters_ver3,
   		.main = link_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -291,7 +291,7 @@
   		.syntax_version = "3.1",
   		.parameters = link_parameters_ver3,
   		.main = link_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -304,13 +304,13 @@
   		.syntax_version = "3.2",
   		.parameters = link_parameters_ver3,
   		.main = link_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +3 -3      ALFS/nALFS/src/handlers/log.c
  
  Index: log.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/log.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- log.c	6 Nov 2003 17:01:13 -0000	1.12
  +++ log.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -60,7 +60,7 @@
   		.syntax_version = "2.0",
   		.parameters = log_parameters,
   		.main = log_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
  @@ -73,13 +73,13 @@
   		.syntax_version = "3.0",
   		.parameters = log_parameters,
   		.main = log_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +5 -5      ALFS/nALFS/src/handlers/make.c
  
  Index: make.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/make.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- make.c	23 Nov 2003 19:38:16 -0000	1.12
  +++ make.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -128,7 +128,7 @@
   		.syntax_version = "2.0",
   		.parameters = make_parameters_ver2,
   		.main = make_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -141,7 +141,7 @@
   		.syntax_version = "3.0",
   		.parameters = make_parameters_ver3,
   		.main = make_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -154,7 +154,7 @@
   		.syntax_version = "3.1",
   		.parameters = make_parameters_ver3,
   		.main = make_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -167,13 +167,13 @@
   		.syntax_version = "3.2",
   		.parameters = make_parameters_ver3,
   		.main = make_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +5 -5      ALFS/nALFS/src/handlers/mkdir.c
  
  Index: mkdir.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/mkdir.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- mkdir.c	23 Nov 2003 19:38:16 -0000	1.12
  +++ mkdir.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -226,7 +226,7 @@
   		.syntax_version = "2.0",
   		.parameters = mkdir_parameters_ver2,
   		.main = mkdir_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -239,7 +239,7 @@
   		.syntax_version = "3.0",
   		.parameters = mkdir_parameters_ver3,
   		.main = mkdir_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -252,7 +252,7 @@
   		.syntax_version = "3.1",
   		.parameters = mkdir_parameters_ver3,
   		.main = mkdir_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -265,13 +265,13 @@
   		.syntax_version = "3.2",
   		.parameters = mkdir_parameters_ver3,
   		.main = mkdir_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +5 -5      ALFS/nALFS/src/handlers/move.c
  
  Index: move.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/move.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- move.c	23 Nov 2003 19:38:16 -0000	1.12
  +++ move.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -189,7 +189,7 @@
   		.syntax_version = "2.0",
   		.parameters = move_parameters_ver2,
   		.main = move_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -202,7 +202,7 @@
   		.syntax_version = "3.0",
   		.parameters = move_parameters_ver3,
   		.main = move_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -215,7 +215,7 @@
   		.syntax_version = "3.1",
   		.parameters = move_parameters_ver3,
   		.main = move_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -228,13 +228,13 @@
   		.syntax_version = "3.2",
   		.parameters = move_parameters_ver3,
   		.main = move_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +2 -2      ALFS/nALFS/src/handlers/owner.c
  
  Index: owner.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/owner.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- owner.c	6 Nov 2003 17:01:13 -0000	1.12
  +++ owner.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -189,13 +189,13 @@
   		.syntax_version = "2.0",
   		.parameters = owner_parameters,
   		.main = owner_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.11      +4 -4      ALFS/nALFS/src/handlers/ownership.c
  
  Index: ownership.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/ownership.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ownership.c	23 Nov 2003 19:38:16 -0000	1.10
  +++ ownership.c	6 Feb 2004 05:54:36 -0000	1.11
  @@ -176,7 +176,7 @@
   		.syntax_version = "3.0",
   		.parameters = ownership_parameters,
   		.main = ownership_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -189,7 +189,7 @@
   		.syntax_version = "3.1",
   		.parameters = ownership_parameters,
   		.main = ownership_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -202,13 +202,13 @@
   		.syntax_version = "3.2",
   		.parameters = ownership_parameters,
   		.main = ownership_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.14      +1 -1      ALFS/nALFS/src/handlers/package.c
  
  Index: package.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/package.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- package.c	23 Nov 2003 19:38:16 -0000	1.13
  +++ package.c	6 Feb 2004 05:54:36 -0000	1.14
  @@ -334,6 +334,6 @@
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.17      +5 -5      ALFS/nALFS/src/handlers/patch.c
  
  Index: patch.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/patch.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- patch.c	17 Jan 2004 04:20:59 -0000	1.16
  +++ patch.c	6 Feb 2004 05:54:36 -0000	1.17
  @@ -278,7 +278,7 @@
   		.syntax_version = "2.0",
   		.parameters = patch_parameters_ver2,
   		.main = patch_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -291,7 +291,7 @@
   		.syntax_version = "3.0",
   		.parameters = patch_parameters_ver3,
   		.main = patch_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -304,7 +304,7 @@
   		.syntax_version = "3.1",
   		.parameters = patch_parameters_ver3,
   		.main = patch_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -317,13 +317,13 @@
   		.syntax_version = "3.2",
   		.parameters = patch_parameters_ver3_2,
   		.main = patch_main_ver3_2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.13      +5 -5      ALFS/nALFS/src/handlers/permissions.c
  
  Index: permissions.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/permissions.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- permissions.c	23 Nov 2003 19:38:16 -0000	1.12
  +++ permissions.c	6 Feb 2004 05:54:36 -0000	1.13
  @@ -221,7 +221,7 @@
   		.syntax_version = "2.0",
   		.parameters = permissions_parameters_ver2,
   		.main = permissions_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -234,7 +234,7 @@
   		.syntax_version = "3.0",
   		.parameters = permissions_parameters_ver3,
   		.main = permissions_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -247,7 +247,7 @@
   		.syntax_version = "3.1",
   		.parameters = permissions_parameters_ver3,
   		.main = permissions_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -260,13 +260,13 @@
   		.syntax_version = "3.2",
   		.parameters = permissions_parameters_ver3,
   		.main = permissions_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.12      +2 -2      ALFS/nALFS/src/handlers/postbuild.c
  
  Index: postbuild.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/postbuild.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- postbuild.c	4 Nov 2003 19:42:51 -0000	1.11
  +++ postbuild.c	6 Feb 2004 05:54:36 -0000	1.12
  @@ -67,13 +67,13 @@
   		.syntax_version = "2.0",
   		.parameters = postbuild_parameters,
   		.main = postbuild_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.12      +2 -2      ALFS/nALFS/src/handlers/prebuild.c
  
  Index: prebuild.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/prebuild.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- prebuild.c	4 Nov 2003 19:42:51 -0000	1.11
  +++ prebuild.c	6 Feb 2004 05:54:36 -0000	1.12
  @@ -67,13 +67,13 @@
   		.syntax_version = "2.0",
   		.parameters = prebuild_parameters,
   		.main = prebuild_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.14      +5 -5      ALFS/nALFS/src/handlers/search_replace.c
  
  Index: search_replace.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/search_replace.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- search_replace.c	23 Nov 2003 19:38:16 -0000	1.13
  +++ search_replace.c	6 Feb 2004 05:54:36 -0000	1.14
  @@ -236,7 +236,7 @@
   		.syntax_version = "2.0",
   		.parameters = search_replace_parameters_ver2,
   		.main = search_replace_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -249,7 +249,7 @@
   		.syntax_version = "3.0",
   		.parameters = search_replace_parameters_ver3,
   		.main = search_replace_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -262,7 +262,7 @@
   		.syntax_version = "3.1",
   		.parameters = search_replace_parameters_ver3,
   		.main = search_replace_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -275,13 +275,13 @@
   		.syntax_version = "3.2",
   		.parameters = search_replace_parameters_ver3,
   		.main = search_replace_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.12      +3 -3      ALFS/nALFS/src/handlers/setenv.c
  
  Index: setenv.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/setenv.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- setenv.c	6 Nov 2003 17:01:13 -0000	1.11
  +++ setenv.c	6 Feb 2004 05:54:36 -0000	1.12
  @@ -148,7 +148,7 @@
   		.syntax_version = "2.0",
   		.parameters = setenv_parameters,
   		.main = setenv_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -161,13 +161,13 @@
   		.syntax_version = "3.0",
   		.parameters = setenv_parameters,
   		.main = setenv_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.15      +102 -4    ALFS/nALFS/src/handlers/stage.c
  
  Index: stage.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stage.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- stage.c	30 Dec 2003 15:58:13 -0000	1.14
  +++ stage.c	6 Feb 2004 05:54:36 -0000	1.15
  @@ -405,6 +405,60 @@
   	return status;
   }
   
  +#if HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
  +
  +static int then_main(element_s *el)
  +{
  +	int status;
  +	element_s *stageinfo;
  +       
  +
  +	if (*opt_be_verbose)
  +		Nprint_h("Executing <then> block.");
  +
  +	log_start_time(el);
  +
  +	if ((stageinfo = first_param("stageinfo", el))) {
  +		status = parse_stageinfo_and_execute_children(el, stageinfo);
  +	} else {
  +		status = execute_children(el);
  +	}
  +
  +	log_end_time(el, status);
  +
  +	if (*opt_be_verbose)
  +		Nprint_h("<then> block complete.");
  +
  +	return status;
  +}
  +
  +static int else_main(element_s *el)
  +{
  +	int status;
  +	element_s *stageinfo;
  +       
  +
  +	if (*opt_be_verbose)
  +		Nprint_h("Executing <else> block.");
  +
  +	log_start_time(el);
  +
  +	if ((stageinfo = first_param("stageinfo", el))) {
  +		status = parse_stageinfo_and_execute_children(el, stageinfo);
  +	} else {
  +		status = execute_children(el);
  +	}
  +
  +	log_end_time(el, status);
  +
  +	if (*opt_be_verbose)
  +		Nprint_h("<else> block complete.");
  +
  +	return status;
  +}
  +
  +#endif /* HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
  +
   #endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
   
   
  @@ -420,7 +474,7 @@
   		.syntax_version = "3.0",
   		.parameters = stage_parameters,
   		.main = stage_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
  @@ -433,7 +487,29 @@
   		.syntax_version = "3.1",
   		.parameters = stage_parameters,
   		.main = stage_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
  +		.alloc_data = NULL,
  +		.is_action = 0,
  +		.priority = 0
  +	},
  +	{
  +		.name = "then",
  +		.description = "then",
  +		.syntax_version = "3.1",
  +		.parameters = stage_parameters,
  +		.main = then_main,
  +		.type = HTYPE_TRUE_RESULT,
  +		.alloc_data = NULL,
  +		.is_action = 0,
  +		.priority = 0
  +	},
  +	{
  +		.name = "else",
  +		.description = "else",
  +		.syntax_version = "3.1",
  +		.parameters = stage_parameters,
  +		.main = else_main,
  +		.type = HTYPE_FALSE_RESULT,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
  @@ -446,13 +522,35 @@
   		.syntax_version = "3.2",
   		.parameters = stage_parameters,
   		.main = stage_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
  +		.alloc_data = NULL,
  +		.is_action = 0,
  +		.priority = 0
  +	},
  +	{
  +		.name = "then",
  +		.description = "then",
  +		.syntax_version = "3.2",
  +		.parameters = stage_parameters,
  +		.main = then_main,
  +		.type = HTYPE_TRUE_RESULT,
  +		.alloc_data = NULL,
  +		.is_action = 0,
  +		.priority = 0
  +	},
  +	{
  +		.name = "else",
  +		.description = "else",
  +		.syntax_version = "3.2",
  +		.parameters = stage_parameters,
  +		.main = else_main,
  +		.type = HTYPE_FALSE_RESULT,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.11      +2 -2      ALFS/nALFS/src/handlers/stamp.c
  
  Index: stamp.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stamp.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- stamp.c	6 Nov 2003 17:01:13 -0000	1.10
  +++ stamp.c	6 Feb 2004 05:54:36 -0000	1.11
  @@ -76,13 +76,13 @@
   		.syntax_version = "3.0",
   		.parameters = stamp_parameters,
   		.main = stamp_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.14      +2 -2      ALFS/nALFS/src/handlers/su.c
  
  Index: su.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/su.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- su.c	30 Dec 2003 15:58:13 -0000	1.13
  +++ su.c	6 Feb 2004 05:54:36 -0000	1.14
  @@ -215,13 +215,13 @@
   		.syntax_version = "2.0",
   		.parameters = su_parameters,
   		.main = su_main,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 0,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.15      +1 -1      ALFS/nALFS/src/handlers/textdump.c
  
  Index: textdump.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/textdump.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- textdump.c	23 Nov 2003 19:38:16 -0000	1.14
  +++ textdump.c	6 Feb 2004 05:54:36 -0000	1.15
  @@ -218,6 +218,6 @@
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.20      +5 -5      ALFS/nALFS/src/handlers/unpack.c
  
  Index: unpack.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/unpack.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- unpack.c	3 Feb 2004 20:26:20 -0000	1.19
  +++ unpack.c	6 Feb 2004 05:54:36 -0000	1.20
  @@ -355,7 +355,7 @@
   		.syntax_version = "2.0",
   		.parameters = unpack_parameters_ver2,
   		.main = unpack_main_ver2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -368,7 +368,7 @@
   		.syntax_version = "3.0",
   		.parameters = unpack_parameters_ver3,
   		.main = unpack_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -381,7 +381,7 @@
   		.syntax_version = "3.1",
   		.parameters = unpack_parameters_ver3,
   		.main = unpack_main_ver3,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
  @@ -394,13 +394,13 @@
   		.syntax_version = "3.2",
   		.parameters = unpack_parameters_ver3_2,
   		.main = unpack_main_ver3_2,
  -		.type = 0,
  +		.type = HTYPE_NORMAL,
   		.alloc_data = NULL,
   		.is_action = 1,
   		.priority = 0
   	},
   #endif
   	{
  -		NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0
  +		.name = NULL
   	}
   };
  
  
  
  1.1                  ALFS/nALFS/src/handlers/conditionals.c
  
  Index: conditionals.c
  ===================================================================
  /*
   *  conditionals.c - Handlers for conditional logic.
   *
   *  Copyright (C) 2004
   *
   *  Kevin P. Fleming <kpfleming at linuxfromscratch.org>
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  
  #include <stdlib.h>
  
  #ifdef HAVE_CONFIG_H
  #include <config.h>
  #endif
  
  #define MODULE_NAME conditionals
  #include <nALFS.h>
  
  #include "handlers.h"
  #include "backend.h"
  #include "nprint.h"
  #include "utility.h"
  #include "parser.h"
  
  
  static const char *null_parameters[] = { NULL };
  
  #if HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
  static int do_shelltest(const char *test, int *result)
  {
  	int status = 0;
  	long num_value;
  	char *temp;
  
  	num_value = strtol(test, &temp, 0);
  	if (*temp == '\0') {
  		/* strtol found the test string to be completely numeric */
  		*result = (num_value == 0) ? 0 : 1;
  	} else if (strcasecmp(test, "true") == 0) {
  		*result = 1;
  	} else if (strcasecmp(test, "yes") == 0) {
  		*result = 1;
  	} else if (strcasecmp(test, "y") == 0) {
  		*result = 1;
  	} else if (strcasecmp(test, "t") == 0) {
  		*result = 1;
  	} else if (strcasecmp(test, "false") == 0) {
  		*result = 0;
  	} else if (strcasecmp(test, "no") == 0) {
  		*result = 0;
  	} else if (strcasecmp(test, "n") == 0) {
  		*result = 0;
  	} else if (strcasecmp(test, "f") == 0) {
  		*result = 0;
  	} else {
  		Nprint_h("    test %s", temp);
  		status = execute_command("test %s", temp);
  		if ((status == 0) || (status == 1)) {
  			*result = (status == 0) ? 1 : 0;
  			status = 0;
  		} else
  			status -1;
  	}
  
  	return status;
  }
  #endif
  
  #if HANDLER_SYNTAX_3_1
  static const char *if_parameters_3_1[] = { "then", "else", NULL };
  
  static int if_main_3_1(element_s *element)
  {
  	return -1;
  }
  #endif
  
  #if HANDLER_SYNTAX_3_2
  static const char *if_parameters_3_2[] = { "test", "package-version", "package-built", "and", "or", "not", "then", "else", NULL };
  static const char *boolean_parameters_3_2[] = { "test", "package-version", "package-built", "and", "or", "not", NULL };
  
  static int if_main_3_2(element_s *element)
  {
  	int i;
  	element_s *child;
  	int test_result = 1;
  	handler_type_e result_handler_type = HTYPE_TRUE_RESULT;
  
  	for (child = element->children; test_result && child; child = child->next) {
  		if (!child->handler) {
  			Nprint_h_err("<%s> element not allowed inside <if>.", child->name);
  			return -1;
  		}
  		if ((child->handler->info->type & HTYPE_TEST) != 0) {
  			i = do_execute_test_element(child, &test_result);
  			if (i != 0)
  				return i;
  		}
  	}
  
  	if (!test_result)
  		result_handler_type = HTYPE_FALSE_RESULT;
  
  	return execute_children_filtered(element, result_handler_type);
  }
  
  static int and_test_3_2(element_s *element, int *result)
  {
  	int i;
  	element_s *child;
  
  	*result = 1;
  	for (child = element->children; *result && child; child = child->next) {
  		if (child->handler &&
  		    ((child->handler->info->type & HTYPE_TEST) != 0)) {
  			i = do_execute_test_element(child, result);
  			if (i != 0)
  				return i;
  		} else {
  			Nprint_h_err("<%s> element not allowed inside <and>.", child->name);
  			return -1;
  		}
  	}
  
  	return 0;
  }
  
  static int or_test_3_2(element_s *element, int *result)
  {
  	int i;
  	element_s *child;
  
  	*result = 0;
  	for (child = element->children; !*result && child; child = child->next) {
  		if (child->handler &&
  		    ((child->handler->info->type & HTYPE_TEST) != 0)) {
  			i = do_execute_test_element(child, result);
  			if (i != 0)
  				return i;
  		} else {
  			Nprint_h_err("<%s> element not allowed inside <or>.", child->name);
  			return -1;
  		}
  	}
  
  	return 0;
  }
  
  static int not_test_3_2(element_s *element, int *result)
  {
  	int i;
  	element_s *child;
  
  	child = element->children;
  	if (child->next) {
  		Nprint_h_err("multiple elements not allowed inside <not>.");
  		return -1;
  	}
  
  	if (child->handler &&
  	    ((child->handler->info->type & HTYPE_TEST) != 0)) {
  		i = do_execute_test_element(child, result);
  		if (i != 0)
  			return i;
  		*result = !*result;
  	} else {
  		Nprint_h_err("<%s> element not allowed inside <not>.", child->name);
  		return -1;
  	}
  
  	return 0;
  }
  
  static int shelltest_test_3_2(element_s *element, int *result)
  {
  	char *test;
  	int status = -1;
  
  	if ((test = alloc_trimmed_str(element->content)) == NULL) {
  		Nprint_h_err("No test content specified.");
  	} else {
  		status = do_shelltest(test, result);
  		xfree(test);
  	}
  
  	return status;
  }
  
  static int package_version_test_3_2(element_s *element, int *result)
  {
  	return 0;
  }
  
  static int package_built_test_3_2(element_s *element, int *result)
  {
  	return 0;
  }
  #endif
  
  /*
   * Handlers' information.
   */
  
  handler_info_s HANDLER_SYMBOL(info)[] = {
  #if HANDLER_SYNTAX_3_1
  	{
  		.name = "if",
  		.description = "if",
  		.syntax_version = "3.1",
  		.parameters = if_parameters_3_1,
  		.main = if_main_3_1,
  		.type = HTYPE_NORMAL,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  #endif
  #if HANDLER_SYNTAX_3_2
  	{
  		.name = "if",
  		.description = "if",
  		.syntax_version = "3.2",
  		.parameters = if_parameters_3_2,
  		.main = if_main_3_2,
  		.type = HTYPE_NORMAL,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  	{
  		.name = "and",
  		.description = "and",
  		.syntax_version = "3.2",
  		.parameters = boolean_parameters_3_2,
  		.test = and_test_3_2,
  		.type = HTYPE_TEST,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  	{
  		.name = "or",
  		.description = "or",
  		.syntax_version = "3.2",
  		.parameters = boolean_parameters_3_2,
  		.test = or_test_3_2,
  		.type = HTYPE_TEST,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  	{
  		.name = "not",
  		.description = "not",
  		.syntax_version = "3.2",
  		.parameters = boolean_parameters_3_2,
  		.test = not_test_3_2,
  		.type = HTYPE_TEST,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  	{
  		.name = "test",
  		.description = "Shell Test",
  		.syntax_version = "3.2",
  		.parameters = null_parameters,
  		.test = shelltest_test_3_2,
  		.type = HTYPE_TEST,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  	{
  		.name = "package-built",
  		.description = "Package Built",
  		.syntax_version = "3.2",
  		.parameters = null_parameters,
  		.test = package_built_test_3_2,
  		.type = HTYPE_TEST,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  	{
  		.name = "package-version",
  		.description = "Package Version",
  		.syntax_version = "3.2",
  		.parameters = null_parameters,
  		.test = package_version_test_3_2,
  		.type = HTYPE_TEST,
  		.alloc_data = NULL,
  		.is_action = 1,
  		.priority = 0
  	},
  #endif
  	{
  		.name = NULL
  	}
  };
  
  
  



More information about the alfs-log mailing list