/* file "my_scanf.c" * Defines an alternative to the scanf function provided by * stdio.h for use when running the Dhrystone benchmarks on DINK. * Created: 990119 CJC * Modified: 000327 MRR */ #include "dinkusr.h" #define getchar get_char #define getkb get_KEYBOARD #define putchar write_char void my_scanf(char *fmt, int *v) { char ch; int no_runs = 0; while ((ch = getchar(getkb())) != 0xd) /* Carriage return? */ { if ( (ch == 0x7f) || (ch == 0x8)) /* Delete? */ { putchar(0x8); /* Backspace */ putchar(0x20); /* Overprint a space. */ putchar(0x8); /* Backspace */ /* Assume modulo arithmetic to subtract last digit added. */ no_runs = no_runs / 10; } else if ( (ch >= '0') && (ch <= '9')) /* A digit? */ { putchar(ch); /* Echo it and */ /* Accumulate the value. */ no_runs = (no_runs * 10) + (ch - 48); /* ASCII character - 48 equals the digit. */ } } *v = no_runs; /* Assign second Arg the value. */ }