cvs commit: ALFS/nALFS/src nalfs.c parser.c parser.h

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sat Apr 3 11:58:09 PST 2004


kpfleming    04/04/03 12:58:09

  Modified:    nALFS/src nalfs.c parser.c parser.h
  Log:
  move element marking/unmarking logic in parser.c
  make marking/unmarking work properly for "internal" handlers (not HTYPE_NORMAL)
  
  Revision  Changes    Path
  1.56      +16 -41    ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- nalfs.c	27 Mar 2004 21:37:57 -0000	1.55
  +++ nalfs.c	3 Apr 2004 19:58:09 -0000	1.56
  @@ -222,60 +222,35 @@
    * (Un)Marking elements.
    */
   
  -static INLINE int has_child_with_mark(element_s *el)
  +static INLINE void do_mark_element(element_s *el)
   {
  -	element_s *child;
  -
  -
  -	for (child = el->children; child; child = child->next) {
  -		if (child->marked) {
  -			return 1;
  +	if ((el->handler->type & HTYPE_NORMAL) != 0) {
  +		if (el->marked) {
  +			unmark_element(el, 1);
  +		} else {
  +			mark_element(el, 1);
   		}
   	}
  -
  -	return 0;
  -}
  -
  -static void do_mark_element(element_s *el, int mark)
  -{
  -	element_s *child;
  -
  -	if ((el->handler->type & HTYPE_NORMAL) != 0)
  -		el->marked = mark;
  -
  -	for (child = el->children; child; child = child->next) {
  -		do_mark_element(child, mark);
  -	}
  -}
  -
  -static INLINE void mark_element(element_s *el)
  -{
  -	element_s *parent;
  -
  -	do_mark_element(el, el->marked ? 0 : 1);
  -
  -	/* Mark/unmark all our parents, if needed. */
  -	for (parent = el->parent; parent; parent = parent->parent) {
  -		parent->marked = has_child_with_mark(parent);
  -	}
   }
   
   static void clear_marks(element_s *el, int all)
   {
   	element_s *child;
   
  -
   	/*
   	 * FIXME: Elements with SOME_DONE should be unmarked too,
   	 *        if they don't contain any marked children.
   	 */
   
  -	if (all || el->run_status == RUN_STATUS_DONE) {
  -		el->marked = 0;
  -	}
  -
  -	for (child = el->children; child; child = child->next) {
  -		clear_marks(child, all);
  +	if (all) {
  +		unmark_element(el, 1);
  +	} else {
  +		if (el->run_status == RUN_STATUS_DONE) {
  +			unmark_element(el, 0);
  +		}
  +		for (child = el->children; child; child = child->next) {
  +			clear_marks(child, all);
  +		}
   	}
   }
   
  @@ -3643,7 +3618,7 @@
   
   		case '*': /* Mark current element. */
   		case KEY_IC:
  -			mark_element(Current_element);
  +			do_mark_element(Current_element);
   			++displayed.current;
   
   			rewrite_main();
  
  
  
  1.20      +47 -0     ALFS/nALFS/src/parser.c
  
  Index: parser.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- parser.c	21 Mar 2004 18:40:32 -0000	1.19
  +++ parser.c	3 Apr 2004 19:58:09 -0000	1.20
  @@ -316,3 +316,50 @@
   
   	return el->parent;
   }
  +
  +static int has_child_with_mark(const element_s * const el)
  +{
  +	element_s *child;
  +
  +	for (child = el->children; child; child = child->next)
  +		if (child->marked &&
  +		    ((child->handler->type & HTYPE_NORMAL) != 0))
  +			return 1;
  +
  +	return 0;
  +}
  +
  +void mark_element(element_s * const el, int recursive)
  +{
  +	element_s *child;
  +
  +	el->marked = 1;
  +	if (el->parent && !el->parent->marked)
  +		mark_element(el->parent, 0);
  +
  +	for (child = el->children; child; child = child->next) {
  +		if (child->marked)
  +			continue;
  +		if (recursive ||
  +		    ((child->handler->type & HTYPE_NORMAL) == 0))
  +			mark_element(child, 1);
  +	}
  +}
  +
  +void unmark_element(element_s * const el, int recursive)
  +{
  +	element_s *child;
  +
  +	el->marked = 0;
  +	if (el->parent && el->parent->marked &&
  +	    !has_child_with_mark(el->parent))
  +		unmark_element(el->parent, 0);
  +
  +	for (child = el->children; child; child = child->next) {
  +		if (!child->marked)
  +			continue;
  +		if (recursive ||
  +		    ((child->handler->type & HTYPE_NORMAL) == 0))
  +			unmark_element(child, 1);
  +	}
  +}
  
  
  
  1.15      +3 -0      ALFS/nALFS/src/parser.h
  
  Index: parser.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- parser.h	27 Mar 2004 19:51:56 -0000	1.14
  +++ parser.h	3 Apr 2004 19:58:09 -0000	1.15
  @@ -93,4 +93,7 @@
   element_s *get_next_element(const element_s * const el);
   element_s *get_prev_element(const element_s * const el);
   
  +void mark_element(element_s * const el, int recursive);
  +void unmark_element(element_s * const el, int recursive);
  +
   #endif /* H_PARSER_ */
  
  
  



More information about the alfs-log mailing list