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

variable.c File Reference

#include "jam.h"
#include "lists.h"
#include "parse.h"
#include "variable.h"
#include "expand.h"
#include "hash.h"
#include "filesys.h"
#include "newstr.h"
#include "strings.h"
#include <stdlib.h>

Include dependency graph for variable.c:

Include dependency graph

Go to the source code of this file.

Classes

struct  _variable

Typedefs

typedef _variable VARIABLE

Functions

void delete_var_ (void *xvar, void *data)
void var_defines (char **e)
void var_done ()
void var_dump (char *symbol, LIST *value, char *what)
VARIABLEvar_enter (char *symbol)
LISTvar_get (char *symbol)
void var_hash_swap (struct hash **new_vars)
void var_set (char *symbol, LIST *value, int flag)
int var_string (char *in, char *out, int outsize, LOL *lol)
LISTvar_swap (char *symbol, LIST *value)

Variables

hashvarhash = 0


Typedef Documentation

typedef struct _variable VARIABLE
 

Definition at line 56 of file variable.c.

Referenced by delete_var_(), var_enter(), var_get(), var_set(), and var_swap().


Function Documentation

void delete_var_ void *  xvar,
void *  data
[static]
 

Definition at line 376 of file variable.c.

References freestr(), list_free(), _variable::symbol, v, and VARIABLE.

Referenced by var_done().

00377 {
00378     VARIABLE *v = (VARIABLE*)xvar;
00379     freestr( v->symbol );
00380     list_free( v-> value );
00381 }

Here is the call graph for this function:

void var_defines char **  e  ) 
 

Definition at line 88 of file variable.c.

References LIST, list_new(), newstr(), p, string_append_range(), string_free(), string_new(), string_truncate(), string::value, var_set(), and VAR_SET.

Referenced by main().

00089 {
00090     string buf[1];
00091 
00092     string_new( buf );
00093 
00094         for( ; *e; e++ )
00095         {
00096             char *val;
00097 
00098             /* Just say "no": windows defines this in the env, */
00099             /* but we don't want it to override our notion of OS. */
00100 
00101             if( !strcmp( *e, "OS=Windows_NT" ) )
00102                 continue;
00103 
00104 # ifdef OS_MAC
00105             /* On the mac (MPW), the var=val is actually var\0val */
00106             /* Think different. */
00107         
00108             if( ( val = strchr( *e, '=' ) ) || ( val = *e + strlen( *e ) ) )
00109 # else
00110             if( val = strchr( *e, '=' ) )
00111 # endif
00112             {
00113                 LIST *l = L0;
00114                 char *pp, *p;
00115 # ifdef OS_MAC
00116                 char split = ',';
00117 # else
00118                 char split = ' ';
00119 # endif
00120                 size_t len = strlen(val + 1);
00121                 if ( val[1] == '"' && val[len] == '"')
00122                 {
00123                     string_append_range( buf, val + 2, val + len );
00124                     l = list_new( l, newstr( buf->value ) );
00125                     string_truncate( buf, 0 );
00126                 }
00127                 else
00128                 {
00129                     /* Split *PATH at :'s, not spaces */
00130 
00131                     if( val - 4 >= *e )
00132                     {
00133                         if( !strncmp( val - 4, "PATH", 4 ) ||
00134                             !strncmp( val - 4, "Path", 4 ) ||
00135                             !strncmp( val - 4, "path", 4 ) )
00136                             split = SPLITPATH;
00137                     }
00138 
00139                     /* Do the split */
00140 
00141                     for( pp = val + 1; p = strchr( pp, split ); pp = p + 1 )
00142                     {
00143                         string_append_range( buf, pp, p );
00144                         l = list_new( l, newstr( buf->value ) );
00145                         string_truncate( buf, 0 );
00146                     }
00147 
00148                     l = list_new( l, newstr( pp ) );
00149                 }
00150 
00151                 /* Get name */
00152                 string_append_range( buf, *e, val );
00153                 var_set( buf->value, l, VAR_SET );
00154                 string_truncate( buf, 0 );
00155             }
00156         }
00157         string_free( buf );
00158 }

Here is the call graph for this function:

void var_done  ) 
 

Definition at line 384 of file variable.c.

References delete_var_(), hashdone(), hashenumerate(), and varhash.

Referenced by delete_module(), and main().

00385 {
00386     hashenumerate( varhash, delete_var_, (void*)0 );
00387         hashdone( varhash );
00388 }

Here is the call graph for this function:

void var_dump char *  symbol,
LIST value,
char *  what
[static]
 

Definition at line 363 of file variable.c.

References LIST, and list_print().

Referenced by var_get(), var_set(), and var_swap().

00367 {
00368         printf( "%s %s = ", what, symbol );
00369         list_print( value );
00370         printf( "\n" );
00371 }

Here is the call graph for this function:

VARIABLE * var_enter char *  symbol  )  [static]
 

Definition at line 342 of file variable.c.

References HASHDATA, hashenter, hashinit(), newstr(), _variable::symbol, v, _variable::value, varhash, and VARIABLE.

Referenced by var_set(), and var_swap().

00343 {
00344         VARIABLE var, *v = &var;
00345 
00346         if( !varhash )
00347             varhash = hashinit( sizeof( VARIABLE ), "variables" );
00348 
00349         v->symbol = symbol;
00350         v->value = 0;
00351 
00352         if( hashenter( varhash, (HASHDATA **)&v ) )
00353             v->symbol = newstr( symbol );       /* never freed */
00354 
00355         return v;
00356 }

Here is the call graph for this function:

LIST* var_get char *  symbol  ) 
 

Definition at line 254 of file variable.c.

References hashcheck, HASHDATA, _variable::symbol, v, var_dump(), varhash, and VARIABLE.

Referenced by call_bind_rule(), headers(), make0(), make1cmds(), make1settings(), search(), and var_expand().

00255 {
00256         VARIABLE var, *v = &var;
00257 
00258         v->symbol = symbol;
00259 
00260         if( varhash && hashcheck( varhash, (HASHDATA **)&v ) )
00261         {
00262             if( DEBUG_VARGET )
00263                 var_dump( v->symbol, v->value, "get" );
00264             return v->value;
00265         }
00266     
00267         return 0;
00268 }

Here is the call graph for this function:

void var_hash_swap struct hash **  new_vars  ) 
 

Definition at line 73 of file variable.c.

References varhash.

Referenced by delete_module(), enter_module(), and exit_module().

00074 {
00075     struct hash* old = varhash;
00076     varhash = *new_vars;
00077     *new_vars = old;
00078 }

void var_set char *  symbol,
LIST value,
int  flag
 

Definition at line 282 of file variable.c.

References LIST, list_append(), list_free(), v, _variable::value, VAR_APPEND, VAR_DEFAULT, var_dump(), var_enter(), VAR_SET, and VARIABLE.

Referenced by compile_foreach(), compile_set(), main(), make_class_module(), var_defines(), and var_expand_unit_test().

00286 {
00287         VARIABLE *v = var_enter( symbol );
00288 
00289         if( DEBUG_VARSET )
00290             var_dump( symbol, value, "set" );
00291         
00292         switch( flag )
00293         {
00294         case VAR_SET:
00295             /* Replace value */
00296             list_free( v->value );
00297             v->value = value;
00298             break;
00299 
00300         case VAR_APPEND:
00301             /* Append value */
00302             v->value = list_append( v->value, value );
00303             break;
00304 
00305         case VAR_DEFAULT:
00306             /* Set only if unset */
00307             if( !v->value )
00308                 v->value = value;
00309             else
00310                 list_free( value );
00311             break;
00312         }
00313 }

Here is the call graph for this function:

int var_string char *  in,
char *  out,
int  outsize,
LOL lol
 

Definition at line 167 of file variable.c.

References L0, LIST, list_free(), list_next, LOL, _list::string, and var_expand().

Referenced by cmd_new().

00172 {
00173         char    *out0 = out;
00174         char    *oute = out + outsize - 1;
00175 
00176         while( *in )
00177         {
00178             char        *lastword;
00179             int         dollar = 0;
00180 
00181             /* Copy white space */
00182 
00183             while( isspace( *in ) )
00184             {
00185                 if( out >= oute )
00186                     return -1;
00187 
00188                 *out++ = *in++;
00189             }
00190 
00191             lastword = out;
00192 
00193             /* Copy non-white space, watching for variables */
00194 
00195             while( *in && !isspace( *in ) )
00196             {
00197                 if( out >= oute )
00198                     return -1;
00199 
00200                 if( in[0] == '$' && in[1] == '(' )
00201                     dollar++;
00202 
00203                 *out++ = *in++;
00204             }
00205 
00206         /* Add zero to 'out' so that 'lastword' is correctly zero-terminated. */
00207         if (out >= oute)
00208             return -1;
00209         /* Don't increment, intentionally. */
00210         *out= '\0';
00211            
00212             /* If a variable encountered, expand it and and embed the */
00213             /* space-separated members of the list in the output. */
00214 
00215             if( dollar )
00216             {
00217                 LIST    *l;
00218 
00219                 l = var_expand( L0, lastword, out, lol, 0 );
00220 
00221                 out = lastword;
00222 
00223                 for( ; l; l = list_next( l ) )
00224                 {
00225                     int so = strlen( l->string );
00226 
00227                     if( out + so >= oute )
00228                         return -1;
00229 
00230                     strcpy( out, l->string );
00231                     out += so;
00232                     *out++ = ' ';
00233                 }
00234 
00235                 list_free( l );
00236             }
00237         }
00238 
00239         if( out >= oute )
00240             return -1;
00241 
00242         *out++ = '\0';
00243 
00244         return out - out0;
00245 }

Here is the call graph for this function:

LIST* var_swap char *  symbol,
LIST value
 

Definition at line 320 of file variable.c.

References LIST, v, _variable::value, var_dump(), var_enter(), and VARIABLE.

Referenced by pushsettings().

00323 {
00324         VARIABLE *v = var_enter( symbol );
00325         LIST     *oldvalue = v->value;
00326 
00327         if( DEBUG_VARSET )
00328             var_dump( symbol, value, "set" );
00329 
00330         v->value = value;
00331 
00332         return oldvalue;
00333 }

Here is the call graph for this function:


Variable Documentation

struct hash* varhash = 0 [static]
 

Definition at line 50 of file variable.c.

Referenced by var_done(), var_enter(), var_get(), and var_hash_swap().


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