} else if (strcmp (buffer, ".") == 0) {
break;
}
- line[0] = buffer;
- nb = 1;
/* add line into history */
add_history (buffer);
}
}
} else {
+ printf ("%s", iprompt);
if (read (STDIN_FILENO, buffer, BUFFER_SIZE) == 0) {
break;
}
- nb = 0;
- char *pt = line[nb++] = buffer;
- while (*pt != '\0') {
- if (*pt == '\n') {
- *pt = '\0';
- line[nb++] = pt + 1;
- }
- pt++;
- }
VERBOSE (INFO, fprintf (stdout, "line: '%s'\n", buffer));
}
+ /* pre-process buffer */
+ nb = 0;
+ char *pt = line[nb++] = buffer;
+ while (*pt != '\0') {
+ switch (*pt) {
+ case '\n':
+ *pt = '\0';
+ // fallthrough
+ case ';':
+ line[nb++] = pt + 1;
+ }
+ pt++;
+ }
+
/* look for end of line */
for (i = 0; i < nb; i++) {
if (*line[i] == '\0') {
} else if (element != NULL) {
VERBOSE (INFO, print_element (element, 0));
answer = evaluate_element (element, 0);
- print (answer);
+ if (!element->hidden) {
+ print (answer);
+ }
delelement (element);
ret = 0;
}
// test: echo -e '1 }\n1 )\n1 , 2\n ' | calc.exe | grep -c error | xargs test 3 =
// test: echo -e 'print (1)' | calc.exe -v 3 | grep -q Print
// test: echo -e 'si\t\t (pi / 2)' | calc.exe | grep -q '=> 1'
+// test: echo -e '1 + 1;\nans + 1' | calc.exe | grep -qv 2
// Gauss sequence
-// test: echo -e '{sto (1, 0), sto (10, 0), while (inc (10) < 100, {sto (1, rcl (1) + rcl (10)), print (rcl (1))})}' | calc.exe | grep -q '=> 5050'
+// test: echo -e '{sto (1, 0), sto (10, 0), while (inc (10) < 100, {sto (1, rcl (1) + rcl (10)), print (rcl (1))})};' | calc.exe | grep -q '=> 5050'
// Fibonacci sequence
-// test: echo -e '{sto (1, 1), sto (2, 1), sto (10, 1), while (inc (10) < 12 - 1, {sto (3, rcl (1) + rcl (2)), sto (1, rcl (2)), print (sto (2, rcl (3)))})}' | calc.exe | grep -q '=> 144'
+// test: echo -e '{sto (1, 1), sto (2, 1), sto (10, 1), while (inc (10) < 12 - 1, {sto (3, rcl (1) + rcl (2)), sto (1, rcl (2)), print (sto (2, rcl (3)))})};' | calc.exe | grep -q '=> 144'
// Gold number
-// test: echo -e '{sto (1, 1), sto (2, 1), sto (10, 1), while (inc (10) < 15 - 1, {sto (3, rcl (1) + rcl (2)), sto (1, rcl (2)), print (sto (2, rcl (3)) / rcl (1))})}' | calc.exe | grep -q '=> 1.61803'
+// test: echo -e '{sto (1, 1), sto (2, 1), sto (10, 1), while (inc (10) < 15 - 1, {sto (3, rcl (1) + rcl (2)), sto (1, rcl (2)), print (sto (2, rcl (3)) / rcl (1))})};' | calc.exe | grep -q '=> 1.61803'
/* vim: set ts=4 sw=4 et: */
element_t *new = NULL;
VERBOSE (INFO, fprintf (stdout, "Processing: %s\n", str));
+ /* end without printing */
+
+ if (*str == ';') {
+ if (root) {
+ root->hidden = 1;
+ }
+ break;
+ }
+
/* skip spaces and tabs */
if ((*str == ' ') || (*str == '\t')) {
fprintf (stdout, "storage functions:");
fprintf (stdout, " sto rcl inc dec\n");
fprintf (stdout, "conditional functions:");
- fprintf (stdout, " cond while print {}\n");
+ fprintf (stdout, " cond while print {} ;\n");
fprintf (stdout, "miscellaneous functions:");
fprintf (stdout, " quit help\n");
fprintf (stdout, "supported constants:");