#include #include #include #include #include #include #include char *stripwhite (char *string) { char *s, *t; for (s = string; isspace (*s); s++) ; if (*s == 0) return (s); t = s + strlen (s) - 1; while (t > s && isspace (*t)) t--; *++t = '\0'; return s; } static char test[4096]; void numbers(const char *input) { char *word, *brkt; size_t i = 0; FILE *f = fopen("toto.bin", "w"); char r; int mode; strncpy(test, input, 4096); char *sep=":;,\t -"; for (word=strtok_r(test, sep, &brkt); word; word=strtok_r(NULL, sep, &brkt)) { if ( (strnstr(word, "0x", 2) == word) | (strnstr(word, "0X", 2) == word) | (strnstr(word, "X", 1) == word) | (strnstr(word, "x", 1) == word) ) mode = 16; else mode = 10; r=strtol(word, NULL, mode); printf("<%s> = %d", word, (int)r); fwrite(&r, 1, 1, f); } fclose(f); } int main() { int ex=0; while(!ex) { char* line=readline("$ "); char* s; if(!line){ break; } numbers(line); s=stripwhite(line); add_history (s); if(s){ ex=!strcmp(line,"quit"); } free(line); } }