while (argc-- > 1) {
char *arg = *(++argv);
if (arg[0] != '-') {
- fprintf (stderr, "%s: invalid option -- %s\n", progname, arg);
+ fprintf (stderr, "%s: invalid option -- '%s'\n", progname, arg);
return usage (1);
}
char c = arg[1];
}
nb = 0;
char *pt = line[nb++] = buffer;
- while (*pt++ != '\0') {
+ while (*pt != '\0') {
if (*pt == '\n') {
*pt = '\0';
- line[nb++] = ++pt;
+ line[nb++] = pt + 1;
}
+ pt++;
}
VERBOSE (INFO, fprintf (stdout, "line: '%s'\n", buffer));
}
}
element_t *element = parser (line[i], NULL, 0);
if (element == ERROR_OP) {
- VERBOSE (WARNING, fprintf (stdout, "error while parsing: %s\n", line[i]); fflush (stdout));
+ VERBOSE (WARNING, fprintf (stdout, "error while parsing: '%s'\n", line[i]); fflush (stdout));
ret = 1;
} else {
VERBOSE (INFO, print_element (element, 0));
// test: echo "95 - 6.3 * 15 - 1" | calc.exe | grep -q '=> -0\.5'
// test: echo "95-6.3+15" | calc.exe | grep -q '=> 103.7'
// test: echo "-cos (0) + 1" | calc.exe | grep -q '=> -0'
+// test: echo "-cos(0)+1" | calc.exe | grep -q '=> -0'
// test: echo "quit" | calc.exe | grep -q 'bye'
// test: echo "help" | calc.exe | grep -q 'miscellaneous'
// test: echo "1 + 2 *" | calc.exe | grep -q 'error'
new->value = value;
root = new;
str = pt;
- } else if (root->func == Val) {
- if ((*str == '+') || (*str == '-')) {
- if ((prio) && (prio > 1)) {
- VERBOSE (DEBUG, fprintf (stdout, "stop because operator priority\n"));
- *next = str;
- return root;
- }
- if (subparser (&root, &str, Add, 2, 1) == ERROR_OP) {
- delelement (root);
- return ERROR_OP;
- }
- } else {
+ } else if ((*str == '+') || (*str == '-')) {
+ if ((prio) && (prio > 1)) {
+ VERBOSE (DEBUG, fprintf (stdout, "stop because operator priority\n"));
+ *next = str;
+ return root;
+ }
+ if (subparser (&root, &str, Add, 2, 1) == ERROR_OP) {
delelement (root);
return ERROR_OP;
}