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 2352 of file ast_expr2f.c.
02353 { 02354 struct parse_io io; 02355 int return_value = 0; 02356 02357 memset(&io, 0, sizeof(io)); 02358 io.string = expr; /* to pass to the error routine */ 02359 02360 ast_yylex_init(&io.scanner); 02361 02362 ast_yy_scan_string(expr, io.scanner); 02363 02364 ast_yyparse ((void *) &io); 02365 02366 ast_yylex_destroy(io.scanner); 02367 02368 if (!io.val) { 02369 if (length > 1) { 02370 strcpy(buf, "0"); 02371 return_value = 1; 02372 } 02373 } else { 02374 if (io.val->type == AST_EXPR_integer) { 02375 int res_length; 02376 02377 res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i); 02378 return_value = (res_length <= length) ? res_length : length; 02379 } else { 02380 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE_AEL) 02381 strncpy(buf, io.val->u.s, length - 1); 02382 #else /* !STANDALONE && !LOW_MEMORY */ 02383 ast_copy_string(buf, io.val->u.s, length); 02384 #endif /* STANDALONE || LOW_MEMORY */ 02385 return_value = strlen(buf); 02386 free(io.val->u.s); 02387 } 02388 free(io.val); 02389 } 02390 return return_value; 02391 }