L
luser-ex-troll
Having determined what's in the string, interpreting the number
represented is almost trivial.
int grok(char *s) { /*dig?*/
if (czek(s, fsm_dec, acc_dec )) {
printf( "dec: %d\n", (int)strtol(s,NULL,10) );
return 1; }
else if (czek(s, fsm_rad, acc_rad )) {
printf( "rad: %d\n",
(int)strtol(strchr(s,'#')+1, NULL, strtol(s,NULL,10)) );
return 1; }
else if (czek(s, fsm_real,acc_real)) {
printf("real: %f\n", strtod(s,NULL));
return 1; }
/*else*/
printf("grok? %s\n", s);
return 0; }
That saves a few hundred lines (and having to type the alphabet
twice!).
represented is almost trivial.
int grok(char *s) { /*dig?*/
if (czek(s, fsm_dec, acc_dec )) {
printf( "dec: %d\n", (int)strtol(s,NULL,10) );
return 1; }
else if (czek(s, fsm_rad, acc_rad )) {
printf( "rad: %d\n",
(int)strtol(strchr(s,'#')+1, NULL, strtol(s,NULL,10)) );
return 1; }
else if (czek(s, fsm_real,acc_real)) {
printf("real: %f\n", strtod(s,NULL));
return 1; }
/*else*/
printf("grok? %s\n", s);
return 0; }
That saves a few hundred lines (and having to type the alphabet
twice!).