X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=calc.c;h=71bea56baeee2a3e9e8ae5b2785e17d376529f83;hb=f9ee932b62fcaa73bf092537ae212e6ab9cd7285;hp=6043346c3d97ac7c97ae18505b592a58d94343f3;hpb=20a645614be5667c1c32169e837b97c067156edb;p=calc.git diff --git a/calc.c b/calc.c index 6043346..71bea56 100644 --- a/calc.c +++ b/calc.c @@ -43,7 +43,7 @@ int usage (int ret) FILE *fid = ret ? stderr : stdout; fprintf (fid, "usage: %s\n", progname); fprintf (fid, " -h : help message\n"); - fprintf (fid, " -b : in/out-put base (%d-%d)\n", ibase, obase); + fprintf (fid, " -b : in/out-put base (%s)\n", show_base ()); fprintf (fid, " -n : no readline mode (%s)\n", mode ? "yes" : "no"); fprintf (fid, " -n : no readline mode (%s)\n", mode ? "yes" : "no"); fprintf (fid, " -o : output prompt (%s)\n", oprompt); @@ -105,7 +105,7 @@ int main (int argc, char *argv[]) { char *buffer = NULL; char buffer_static[BUFFER_SIZE + 1] = {0}; - int i = 0, nb = 1; + int i = 0, nb = 1, in, out; int ret = 0; /* program name */ @@ -128,6 +128,7 @@ int main (int argc, char *argv[]) VERBOSE (ERROR, fprintf (stderr, "%s: invalid option -- '%s'\n", progname, arg); usage (1)); return 1; } + char *pt = NULL; char c = arg[1]; switch (c) { case 'b': @@ -136,7 +137,17 @@ int main (int argc, char *argv[]) VERBOSE (ERROR, fprintf (stderr, "%s: missing base definition\n", progname); usage (1)); return 1; } - ibase = obase = atoi (arg); + in = out = strtol (arg, &pt, 10); + if ((*pt == ' ') || (*pt == ',') || (*pt == '-')) { + pt++; + if (*pt == '\0') { + VERBOSE (ERROR, fprintf (stderr, "%s: missing output base definition\n", progname); usage (1)); + return 1; + } else { + out = atoi (pt); + } + } + set_base (in, out); break; case 'i': arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; @@ -187,8 +198,10 @@ int main (int argc, char *argv[]) completion_list = generate_completion_list (); rl_attempted_completion_function = completion; - /* startup hook */ + /* readline parameters */ rl_startup_hook = edit_hook; + rl_variable_bind ("blink-matching-paren", "On"); + //rl_set_screen_size (50, 40); /* read from input stream */ @@ -281,6 +294,10 @@ int main (int argc, char *argv[]) // test: calc.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }' // test: calc.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }' // test: calc.exe error 2>&1 | grep -q 'invalid option' +// test: calc.exe -b 2>&1 | grep -q 'missing base' +// test: calc.exe -b 10, 2>&1 | grep -q 'missing output base' +// test: calc.exe -b 10- 2>&1 | grep -q 'missing output base' +// test: calc.exe -b '10 ' 2>&1 | grep -q 'missing output base' // test: calc.exe -i 2>&1 | grep -q 'missing input prompt' // test: calc.exe -o 2>&1 | grep -q 'missing output prompt' // test: calc.exe -p 2>&1 | grep -q 'missing precision' @@ -441,6 +458,10 @@ int main (int argc, char *argv[]) // test: echo -e 'ff + ff' | calc.exe -b 16 | grep -q '=> 1fe' // test: echo -e '60 / 4' | calc.exe -b 8 | grep -q '=> 14' // test: echo -e 'z00-z0+1-2*z+20x' | calc.exe -b 36 | grep -q '=> 1000' +// test: echo -e '255' | calc.exe -b 10,16 | grep -q '=> ff' +// test: echo -e 'base (-2)\nbase (16, 0)' | calc.exe | grep -c error | xargs test 2 = +// test: echo -e 'base (10, 16)\n255' | calc.exe | grep -q '=> ff' +// test: echo -e 'base' | calc.exe | grep -q 'base (I/O): 10/10' // 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'