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 3159 of file ast_expr2f.c.
03160 { 03161 struct parse_io io; 03162 int return_value = 0; 03163 03164 memset(&io, 0, sizeof(io)); 03165 io.string = expr; /* to pass to the error routine */ 03166 03167 ast_yylex_init(&io.scanner); 03168 03169 ast_yy_scan_string(expr, io.scanner); 03170 03171 ast_yyparse ((void *) &io); 03172 03173 ast_yylex_destroy(io.scanner); 03174 03175 if (!io.val) { 03176 if (length > 1) { 03177 strcpy(buf, "0"); 03178 return_value = 1; 03179 } 03180 } else { 03181 if (io.val->type == AST_EXPR_integer) { 03182 int res_length; 03183 03184 res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i); 03185 return_value = (res_length <= length) ? res_length : length; 03186 } else { 03187 #if defined(STANDALONE) || defined(LOW_MEMORY) || defined(STANDALONE_AEL) 03188 strncpy(buf, io.val->u.s, length - 1); 03189 #else /* !STANDALONE && !LOW_MEMORY */ 03190 ast_copy_string(buf, io.val->u.s, length); 03191 #endif /* STANDALONE || LOW_MEMORY */ 03192 return_value = strlen(buf); 03193 free(io.val->u.s); 03194 } 03195 free(io.val); 03196 } 03197 return return_value; 03198 }