📄 bwb_elx.c
字号:
default: /* anything else */ loop = FALSE; paren_level = 0; /* do not look for arguments */ break; } } /* find arguments within parentheses */ /* for each argument, find a string ending with ',' or with end parenthesis */ n_args = 0; s_pos = 0; CURTASK exps[ CURTASK expsc ].string[ 0 ] = '\0'; while( paren_level > 0 ) { /* check the current character */ switch( expression[ CURTASK exps[ CURTASK expsc ].pos_adv ] ) { case ',': /* end of an argument */ if ( paren_level == 1 ) /* ignore ',' within parentheses */ { /* call bwb_exp() recursively to resolve the argument */ if ( exp_validarg( CURTASK exps[ CURTASK expsc ].string ) == TRUE ) {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): valid argument (not last)." ); bwb_debug( bwb_ebuf );#endif CURTASK exps[ CURTASK expsc ].rec_pos = 0; e = bwb_exp( CURTASK exps[ CURTASK expsc ].string, FALSE, &( CURTASK exps[ CURTASK expsc ].rec_pos ) ); /* assign operation and value at this level */ var_make( &( argv[ n_args ] ), e->type ); switch( argv[ n_args ].type ) { case NUMBER: * var_findnval( &( argv[ n_args ] ), argv[ n_args ].array_pos ) = exp_getnval( e ); break; case STRING: str_btob( var_findsval( &( argv[ n_args ] ), argv[ n_args ].array_pos ), exp_getsval( e ) ); break; } ++n_args; /* increment number of arguments */ } s_pos = 0; /* reset counter */ CURTASK exps[ CURTASK expsc ].string[ 0 ] = '\0'; } else { CURTASK exps[ CURTASK expsc ].string[ s_pos ] = expression[ CURTASK exps[ CURTASK expsc ].pos_adv ]; ++s_pos; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = '\0'; } break; case '(': ++paren_level; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = expression[ CURTASK exps[ CURTASK expsc ].pos_adv ]; ++s_pos; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = '\0'; break; case ')': --paren_level;#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): hit close parenthesis." ); bwb_debug( bwb_ebuf );#endif if ( paren_level == 0 ) {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): paren level 0." ); bwb_debug( bwb_ebuf );#endif /* call bwb_exp() recursively to resolve the argument */ if ( exp_validarg( CURTASK exps[ CURTASK expsc ].string ) == TRUE ) {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): valid argument (last)." ); bwb_debug( bwb_ebuf );#endif CURTASK exps[ CURTASK expsc ].rec_pos = 0; e = bwb_exp( CURTASK exps[ CURTASK expsc ].string, FALSE, &( CURTASK exps[ CURTASK expsc ].rec_pos ) );#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): return from bwb_exp(), last arg, type <%c> op <%d>", e->type, e->operation ); bwb_debug( bwb_ebuf );#endif /* assign operation and value at this level */ var_make( &( argv[ n_args ] ), e->type ); switch( argv[ n_args ].type ) { case NUMBER: * var_findnval( &( argv[ n_args ] ), argv[ n_args ].array_pos ) = exp_getnval( e ); break; case STRING: str_btob( var_findsval( &( argv[ n_args ] ), argv[ n_args ].array_pos ), exp_getsval( e ) ); break; } ++n_args; /* increment number of arguments */ } s_pos = 0; /* reset counter */ CURTASK exps[ CURTASK expsc ].string[ 0 ] = '\0'; } else { CURTASK exps[ CURTASK expsc ].string[ s_pos ] = expression[ CURTASK exps[ CURTASK expsc ].pos_adv ]; ++s_pos; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = '\0'; } break; case '\"': /* embedded string constant */ /* add the initial quotation mark */ CURTASK exps[ CURTASK expsc ].string[ s_pos ] = expression[ CURTASK exps[ CURTASK expsc ].pos_adv ]; ++s_pos; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = '\0'; ++CURTASK exps[ CURTASK expsc ].pos_adv; /* add intervening characters */ while ( ( expression[ CURTASK exps[ CURTASK expsc ].pos_adv ] != '\"' ) && ( expression[ CURTASK exps[ CURTASK expsc ].pos_adv ] != '\0' ) ) { CURTASK exps[ CURTASK expsc ].string[ s_pos ] = expression[ CURTASK exps[ CURTASK expsc ].pos_adv ]; ++s_pos; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = '\0'; ++CURTASK exps[ CURTASK expsc ].pos_adv; } /* add the concluding quotation mark */ CURTASK exps[ CURTASK expsc ].string[ s_pos ] = expression[ CURTASK exps[ CURTASK expsc ].pos_adv ]; ++s_pos; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = '\0'; /* the following bracketed out 14 July 1992; since this counter */ /* incremented at the end of the switch statement, this may */ /* increment it past the next character needed */ /* ++CURTASK exps[ CURTASK expsc ].pos_adv; */ break; default: CURTASK exps[ CURTASK expsc ].string[ s_pos ] = expression[ CURTASK exps[ CURTASK expsc ].pos_adv ]; ++s_pos; CURTASK exps[ CURTASK expsc ].string[ s_pos ] = '\0';#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): new char <%d>=<%c>", expression[ CURTASK exps[ CURTASK expsc ].pos_adv ], expression[ CURTASK exps[ CURTASK expsc ].pos_adv ] ); bwb_debug( bwb_ebuf ); sprintf( bwb_ebuf, "in exp_function(): building <%s>.", CURTASK exps[ CURTASK expsc ].string ); bwb_debug( bwb_ebuf );#endif break; } /* advance the counter */ ++CURTASK exps[ CURTASK expsc ].pos_adv; }#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): ready to call function vector" ); bwb_debug( bwb_ebuf );#endif /* call the function vector */#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): calling preset function" ); bwb_debug( bwb_ebuf );#endif v = CURTASK exps[ CURTASK expsc ].function->vector ( n_args, &( argv[ 0 ] ), CURTASK exps[ CURTASK expsc ].function->id ); /*-------------------------------------------------*/ /* Now free the argv memory */ /* (some other less fortunate routine may need it) */ /* JBV, 10/95 */ /*-------------------------------------------------*/ FREE( argv, "exp_function" );#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): return from function vector, type <%c>", v->type ); bwb_debug( bwb_ebuf );#endif /* assign the value at this level */ CURTASK exps[ CURTASK expsc ].type = (char) v->type; switch( v->type ) { case STRING: CURTASK exps[ CURTASK expsc ].operation = CONST_STRING;#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): ready to assign STRING" ); bwb_debug( bwb_ebuf );#endif b = var_findsval( v, v->array_pos ); str_btob( exp_getsval( &( CURTASK exps[ CURTASK expsc ] )), b );#if INTENSIVE_DEBUG str_btoc( tbuf, b ); sprintf( bwb_ebuf, "in exp_function(): string assigned <%s>", tbuf ); bwb_debug( bwb_ebuf );#endif break; default: CURTASK exps[ CURTASK expsc ].operation = NUMBER; CURTASK exps[ CURTASK expsc ].nval = var_getnval( v ); break; }#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_function(): end of function" ); bwb_debug( bwb_ebuf );#endif /* return */ return TRUE; }/*************************************************************** FUNCTION: exp_variable() DESCRIPTION: This function interprets a variable.***************************************************************/#if ANSI_Cintexp_variable( char *expression )#elseintexp_variable( expression ) char *expression;#endif { int pos; int *pp; int n_params; register int n; struct bwb_variable *v; bstring *b; int p;#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_variable(): entered function." ); bwb_debug( bwb_ebuf );#endif /* get the variable name */ exp_getvfname( expression, CURTASK exps[ CURTASK expsc ].string ); /* now find the variable itself */ v = CURTASK exps[ CURTASK expsc ].xvar = var_find( CURTASK exps[ CURTASK expsc ].string );#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_variable(): level <%d>, found variable name <%s>", CURTASK expsc, CURTASK exps[ CURTASK expsc ].xvar->name ); bwb_debug( bwb_ebuf );#endif /* note that this level is a variable */ CURTASK exps[ CURTASK expsc ].operation = VARIABLE; /* read subscripts */ pos = strlen( CURTASK exps[ CURTASK expsc ].string ); if ( ( v->dimensions == 1 ) && ( v->array_sizes[ 0 ] == 1 )) {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_variable(): variable <%s> has 1 dimension", CURTASK exps[ CURTASK expsc ].xvar->name ); bwb_debug( bwb_ebuf );#endif pos = strlen( v->name ); n_params = 1; pp = &p; pp[ 0 ] = dim_base; } else {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_variable(): variable <%s> has > 1 dimensions", CURTASK exps[ CURTASK expsc ].xvar->name ); bwb_debug( bwb_ebuf );#endif dim_getparams( expression, &pos, &n_params, &pp ); } CURTASK exps[ CURTASK expsc ].pos_adv = pos; for ( n = 0; n < v->dimensions; ++n ) { CURTASK exps[ CURTASK expsc ].array_pos[ n ] = v->array_pos[ n ] = pp[ n ]; }#if INTENSIVE_DEBUG for ( n = 0; n < v->dimensions; ++ n ) { sprintf( bwb_ebuf, "in exp_variable(): var <%s> array_pos element <%d> is <%d>.", v->name, n, v->array_pos[ n ] ); bwb_debug( bwb_ebuf ); }#endif /* assign the type and value at this level */ CURTASK exps[ CURTASK expsc ].type = (char) v->type; switch( v->type ) { case STRING: b = var_findsval( v, v->array_pos );#if TEST_BSTRING sprintf( bwb_ebuf, "in exp_variable(): b string name is <%s>", b->name ); bwb_debug( bwb_ebuf );#endif#if OLDWAY CURTASK exps[ CURTASK expsc ].sval.length = b->length; CURTASK exps[ CURTASK expsc ].sval.sbuffer = b->sbuffer;#endif str_btob( &( CURTASK exps[ CURTASK expsc ].sval ), b ); break; default: CURTASK exps[ CURTASK expsc ].nval = var_getnval( v ); break; }#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in exp_variable(): exit, name <%s>, level <%d>, op <%d>", v->name, CURTASK expsc, CURTASK exps[ CURTASK expsc ].operation ); bwb_debug( bwb_ebuf );#endif /* return */ return TRUE; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -