X-Git-Url: https://secure.softndesign.org/git/?a=blobdiff_plain;f=format.c;fp=format.c;h=e6b1fb609cfb90ae4d2d77f996c992f77dfc6e91;hb=743e93f0edf2c7779d0af4e16e17662994e0caaf;hp=4b9e6cf5ebeefce69d9b085a3118cf7676579da0;hpb=20a645614be5667c1c32169e837b97c067156edb;p=calc.git diff --git a/format.c b/format.c index 4b9e6cf..e6b1fb6 100644 --- a/format.c +++ b/format.c @@ -6,8 +6,8 @@ /* global variables */ -int ibase = 10; -int obase = 10; +int _ibase = 10; +int _obase = 10; #define DEFAULT_FORMAT "=> %.6g\n" char *_format = NULL; @@ -70,6 +70,28 @@ void free_format () } } +void set_base (int in, int out) +{ + _ibase = in; + _obase = out; +} + +int is_input_decimal () +{ + return (_ibase == 10); +} + +char *show_base () +{ + static char str[16] = {0}; + sprintf (str, "%d/%d", _ibase, _obase); + return str; +} + +int get_ibase () +{ + return _ibase; +} char *itoa (unsigned long value) { @@ -79,9 +101,9 @@ char *itoa (unsigned long value) char buffer[8 * sizeof (long) + 1] = {0}; int size = 0; do { - char x = value % obase; + char x = value % _obase; buffer[size++] = (x > 9) ? 'a' + x - 10 : '0' + x; - value /= obase; + value /= _obase; } while (value != 0); /* revert */ @@ -94,14 +116,9 @@ char *itoa (unsigned long value) return str; } -/* vim: set ts=4 sw=4 et: */ - - - - double print (double value) { - if (obase == 10) { + if (_obase == 10) { fprintf (stdout, _format ? _format : DEFAULT_FORMAT, value); } else { fprintf (stdout, "%s%s\n", (_prompt) ? _prompt : DEFAULT_PROMPT, itoa ((unsigned int)value)); @@ -112,7 +129,7 @@ double print (double value) double printl (double value) { - if (obase == 10) { + if (_obase == 10) { fprintf (stdout, _minform ? _minform : DEFAULT_MINFORM, value); } else { fprintf (stdout, "%s%s", (_prompt) ? _prompt : DEFAULT_PROMPT, itoa ((unsigned int)value));