Go to the source code of this file.
Functions | |
int | ast_expr (char *expr, char *buf, int length) |
int ast_expr | ( | char * | expr, | |
char * | buf, | |||
int | length | |||
) |
Definition at line 2288 of file ast_expr2f.c.
02289 { 02290 struct parse_io io; 02291 int return_value = 0; 02292 02293 memset(&io, 0, sizeof(io)); 02294 io.string = expr; /* to pass to the error routine */ 02295 02296 ast_yylex_init(&io.scanner); 02297 02298 ast_yy_scan_string(expr, io.scanner); 02299 02300 ast_yyparse ((void *) &io); 02301 02302 ast_yylex_destroy(io.scanner); 02303 02304 if (!io.val) { 02305 if (length > 1) { 02306 strcpy(buf, "0"); 02307 return_value = 1; 02308 } 02309 } else { 02310 if (io.val->type == AST_EXPR_integer) { 02311 int res_length; 02312 02313 res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i); 02314 return_value = (res_length <= length) ? res_length : length; 02315 } else { 02316 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE_AEL) 02317 strncpy(buf, io.val->u.s, length - 1); 02318 #else /* !STANDALONE && !LOW_MEMORY */ 02319 ast_copy_string(buf, io.val->u.s, length); 02320 #endif /* STANDALONE || LOW_MEMORY */ 02321 return_value = strlen(buf); 02322 free(io.val->u.s); 02323 } 02324 free(io.val); 02325 } 02326 return return_value; 02327 }