The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

lists.c File Reference

#include "jam.h"
#include "newstr.h"
#include "lists.h"

Include dependency graph for lists.c:

Include dependency graph

Go to the source code of this file.

Functions

LISTlist_append (LIST *l, LIST *nl)
LISTlist_copy (LIST *l, LIST *nl)
void list_free (LIST *head)
int list_length (LIST *l)
LISTlist_new (LIST *head, char *string)
LISTlist_pop_front (LIST *l)
void list_print (LIST *l)
LISTlist_sort (LIST *l)
LISTlist_sublist (LIST *l, int start, int count)
void lol_add (LOL *lol, LIST *l)
void lol_free (LOL *lol)
LISTlol_get (LOL *lol, int i)
void lol_init (LOL *lol)
void lol_print (LOL *lol)

Variables

LISTfreelist = 0


Function Documentation

LIST* list_append LIST l,
LIST nl
 

Definition at line 35 of file lists.c.

References LIST, _list::next, and _list::tail.

Referenced by addsettings(), compile_append(), downcase_list(), evaluate_rule(), list_sort(), and var_set().

00038 {
00039         if( !nl )
00040         {
00041             /* Just return l */
00042         }
00043         else if( !l )
00044         {
00045             l = nl;
00046         }
00047         else
00048         {
00049             /* Graft two non-empty lists. */
00050             l->tail->next = nl;
00051             l->tail = nl->tail;
00052         }
00053 
00054         return l;
00055 }

LIST* list_copy LIST l,
LIST nl
 

Definition at line 105 of file lists.c.

References copystr(), LIST, list_new(), list_next, and _list::string.

Referenced by builtin_update(), collect_arguments(), compile_local(), compile_set(), compile_settings(), copysettings(), list_sort(), make1cmds(), and var_expand().

00108 {
00109         for( ; nl; nl = list_next( nl ) )
00110             l = list_new( l, copystr( nl->string ) );
00111 
00112         return l;
00113 }

Here is the call graph for this function:

void list_free LIST head  ) 
 

Definition at line 220 of file lists.c.

References freelist, LIST, _list::next, and _list::tail.

Referenced by actions_free(), addsettings(), builtin_glob(), clear_targets_to_update(), cmd_free(), compile_eval(), compile_foreach(), compile_if(), compile_include(), compile_local(), compile_module(), compile_on(), compile_rules(), compile_set(), compile_settings(), compile_switch(), compile_while(), delete_var_(), freesettings(), list_pop_front(), list_sort(), lol_free(), make1cmds(), var_expand(), var_expand_unit_test(), var_set(), and var_string().

00221 {
00222         /* Just tack onto freelist. */
00223 
00224         if( head )
00225         {
00226             head->tail->next = freelist;
00227             freelist = head;
00228         }
00229 }

int list_length LIST l  ) 
 

Definition at line 267 of file lists.c.

References LIST, list_next, and n.

Referenced by main(), make1cmds(), and var_expand().

00268 {
00269         int n = 0;
00270 
00271         for( ; l; l = list_next( l ), ++n )
00272             ;
00273 
00274         return n;
00275 }

LIST* list_new LIST head,
char *  string
 

Definition at line 62 of file lists.c.

References freelist, freestr(), LIST, _list::next, string, _list::string, and _list::tail.

Referenced by add_hash_key(), add_module_name(), add_rule_name(), builtin_backtrace(), builtin_calc(), builtin_caller_module(), builtin_glob_back(), builtin_match(), builtin_normalize_path(), builtin_search_for_target(), builtin_subst(), call_bind_rule(), collect_arguments(), compile_eval(), compile_foreach(), downcase_list(), headers(), headers1(), list_copy(), list_sort(), list_sublist(), lol_build(), main(), make0(), make1cmds(), make1list(), make1settings(), mark_target_for_updating(), pwd(), type_check(), var_defines(), var_expand(), and var_expand_unit_test().

00065 {
00066         LIST *l;
00067 
00068         if( DEBUG_LISTS )
00069             printf( "list > %s <\n", string );
00070 
00071         /* Get list struct from freelist, if one available.  */
00072         /* Otherwise allocate. */
00073         /* If from freelist, must free string first */
00074 
00075         if( freelist )
00076         {
00077             l = freelist;
00078             freestr( l->string );
00079             freelist = freelist->next;
00080         }
00081         else
00082         {
00083             l = (LIST *)malloc( sizeof( *l ) );
00084         }
00085 
00086         /* If first on chain, head points here. */
00087         /* If adding to chain, tack us on. */
00088         /* Tail must point to this new, last element. */
00089 
00090         if( !head ) head = l;
00091         else head->tail->next = l;
00092         head->tail = l;
00093         l->next = 0;
00094 
00095         l->string = string;
00096 
00097         return head;
00098 }

Here is the call graph for this function:

LIST* list_pop_front LIST l  ) 
 

Definition at line 234 of file lists.c.

References LIST, list_free(), _list::next, and _list::tail.

Referenced by evaluate_rule().

00235 {
00236     LIST * result = l->next;
00237     if( result )
00238     {
00239         result->tail = l->tail;
00240         l->next = L0;
00241         l->tail = l;
00242     }
00243     list_free( l );
00244     return result;
00245 }

Here is the call graph for this function:

void list_print LIST l  ) 
 

Definition at line 252 of file lists.c.

References LIST, list_next, p, and _list::string.

Referenced by builtin_echo(), builtin_exit(), builtin_import(), compile_eval(), compile_include(), compile_local(), compile_on(), compile_set(), compile_settings(), compile_switch(), lol_print(), make1c(), make1d(), var_dump(), and var_expand().

00253 {
00254         LIST *p = 0; 
00255         for( ; l; p = l, l = list_next( l ) )
00256             if ( p ) 
00257                 printf( "%s ", p->string );
00258         if ( p )
00259             printf( "%s", p->string );                
00260 }

LIST* list_sort LIST l  ) 
 

Definition at line 137 of file lists.c.

References f(), LIST, list_append(), list_copy(), list_free(), list_new(), _list::next, s, and _list::string.

Referenced by builtin_sort().

00139 {
00140 
00141     LIST* first = 0;
00142     LIST* second = 0;
00143     LIST* merged = l;
00144     LIST* result;
00145 
00146     if (!l)
00147         return L0;
00148 
00149     for(;;) {
00150         
00151         /* Split the list in two */
00152         LIST** dst = &first;
00153         LIST* src = merged;
00154         
00155         for(;;) {
00156             
00157             *dst = list_append(*dst, list_new(0, src->string));
00158             
00159             if (!src->next)
00160                 break;
00161 
00162             if (strcmp(src->string, src->next->string) > 0) 
00163             {
00164                 if (dst == &first)
00165                     dst = &second;
00166                 else
00167                     dst = &first;
00168             }
00169             
00170             src = src->next;
00171         }
00172 
00173         if (merged != l)
00174             list_free( merged );
00175         merged = 0;
00176         
00177         if (second == 0) {
00178             result = first;
00179             break;
00180         }
00181 
00182         
00183         /* Merge lists 'first' and 'second' into 'merged' and free
00184            'first'/'second'. */
00185         {
00186             LIST* f = first;
00187             LIST* s = second;
00188 
00189             while(f && s)
00190             {
00191                 if (strcmp(f->string, s->string) < 0)
00192                 {
00193                     merged = list_append( merged, list_new(0, f->string ));
00194                     f = f->next;
00195                 }
00196                 else
00197                 {
00198                     merged = list_append( merged, list_new(0, s->string ));
00199                     s = s->next;
00200                 }
00201             }
00202 
00203             merged = list_copy( merged, f );
00204             merged = list_copy( merged, s );
00205             list_free( first );
00206             list_free( second );
00207             first = 0;
00208             second = 0;
00209         }                            
00210     }
00211 
00212     return result;
00213 }

Here is the call graph for this function:

LIST* list_sublist LIST l,
int  start,
int  count
 

Definition at line 120 of file lists.c.

References copystr(), LIST, list_new(), list_next, and _list::string.

Referenced by make1cmds().

00124 {
00125         LIST    *nl = 0;
00126 
00127         for( ; l && start--; l = list_next( l ) )
00128             ;
00129 
00130         for( ; l && count--; l = list_next( l ) )
00131             nl = list_new( nl, copystr( l->string ) );
00132 
00133         return nl;
00134 }

Here is the call graph for this function:

void lol_add LOL lol,
LIST l
 

Definition at line 292 of file lists.c.

References _lol::count, LIST, _lol::list, and LOL.

Referenced by call_bind_rule(), cmd_new(), compile_rule(), compile_setcomp(), headers(), lol_build(), and type_check().

00295 {
00296         if( lol->count < LOL_MAX )
00297             lol->list[ lol->count++ ] = l;
00298 }

void lol_free LOL lol  ) 
 

Definition at line 305 of file lists.c.

References _lol::count, i, _lol::list, list_free(), and LOL.

Referenced by args_free(), cmd_free(), frame_free(), and var_expand_unit_test().

00306 {
00307         int i;
00308 
00309         for( i = 0; i < lol->count; i++ )
00310             list_free( lol->list[i] );
00311 
00312         lol->count = 0;
00313 }

Here is the call graph for this function:

LIST* lol_get LOL lol,
int  i
 

Definition at line 320 of file lists.c.

References _lol::count, i, _lol::list, and LOL.

Referenced by builtin_backtrace(), builtin_calc(), builtin_caller_module(), builtin_delete_module(), builtin_depends(), builtin_echo(), builtin_exit(), builtin_export(), builtin_flags(), builtin_glob(), builtin_hdrmacro(), builtin_import(), builtin_import_module(), builtin_imported_modules(), builtin_instance(), builtin_match(), builtin_normalize_path(), builtin_rulenames(), builtin_search_for_target(), builtin_sort(), builtin_subst(), builtin_update(), builtin_varnames(), call_bind_rule(), collect_arguments(), evaluate_rule(), headers(), make1c(), make1d(), and var_expand().

00323 {
00324         return i < lol->count ? lol->list[i] : 0;
00325 }

void lol_init LOL lol  ) 
 

Definition at line 282 of file lists.c.

References _lol::count, and LOL.

Referenced by args_new(), cmd_new(), evaluate_rule(), frame_init(), lol_build(), and var_expand_unit_test().

00283 {
00284     lol->count = 0;
00285 }

void lol_print LOL lol  ) 
 

Definition at line 332 of file lists.c.

References _lol::count, i, _lol::list, list_print(), and LOL.

Referenced by argument_error(), and evaluate_rule().

00333 {
00334         int i;
00335 
00336         for( i = 0; i < lol->count; i++ )
00337         {
00338             if( i )
00339                 printf( " : " );
00340             list_print( lol->list[i] );
00341         }
00342 }

Here is the call graph for this function:


Variable Documentation

LIST* freelist = 0 [static]
 

Definition at line 28 of file lists.c.

Referenced by list_free(), and list_new().


Generated on Mon Nov 8 17:08:09 2004 for MPT by  doxygen 1.3.9.1