Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/miscutils/dc.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/miscutils/dc.c
r2725 r3232 12 12 //usage:#define dc_full_usage "\n\n" 13 13 //usage: "Tiny RPN calculator. Operations:\n" 14 //usage: "+, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor,\n"14 //usage: "+, add, -, sub, *, mul, /, div, %, mod, "IF_FEATURE_DC_LIBM("**, exp, ")"and, or, not, xor,\n" 15 15 //usage: "p - print top of the stack (without popping),\n" 16 16 //usage: "f - print entire stack,\n" 17 17 //usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" 18 //usage: "Examples: 'dc 2 2 add ' -> 4, 'dc 8 8 * 2 2 + /' -> 16"18 //usage: "Examples: 'dc 2 2 add p' -> 4, 'dc 8 8 mul 2 2 + / p' -> 16" 19 19 //usage: 20 20 //usage:#define dc_example_usage … … 220 220 {"f", print_stack_no_pop}, 221 221 {"o", set_output_base}, 222 { "", NULL }223 222 }; 224 223 225 224 static void stack_machine(const char *argument) 226 225 { 227 char *end Pointer;226 char *end; 228 227 double d; 229 const struct op *o = operators; 230 231 d = strtod(argument, &endPointer); 232 233 if (endPointer != argument && *endPointer == '\0') { 228 const struct op *o; 229 230 d = strtod(argument, &end); 231 if (end != argument && *end == '\0') { 234 232 push(d); 235 233 return; 236 234 } 237 235 238 while (o->function) { 236 o = operators; 237 do { 239 238 if (strcmp(o->name, argument) == 0) { 240 239 o->function(); … … 242 241 } 243 242 o++; 244 } 243 } while (o != operators + ARRAY_SIZE(operators)); 244 245 245 bb_error_msg_and_die("syntax error at '%s'", argument); 246 }247 248 /* return pointer to next token in buffer and set *buffer to one char249 * past the end of the above mentioned token250 */251 static char *get_token(char **buffer)252 {253 char *current = skip_whitespace(*buffer);254 if (*current != '\0') {255 *buffer = skip_non_whitespace(current);256 return current;257 }258 return NULL;259 246 } 260 247 … … 273 260 cursor = line; 274 261 while (1) { 275 token = get_token(&cursor);276 if ( !token)262 token = skip_whitespace(cursor); 263 if (*token == '\0') 277 264 break; 278 *cursor++ = '\0'; 265 cursor = skip_non_whitespace(token); 266 if (*cursor != '\0') 267 *cursor++ = '\0'; 279 268 stack_machine(token); 280 269 } … … 282 271 } 283 272 } else { 284 // why? it breaks "dc -2 2 *p"273 // why? it breaks "dc -2 2 + p" 285 274 //if (argv[0][0] == '-') 286 275 // bb_show_usage();
Note:
See TracChangeset
for help on using the changeset viewer.