From: David Marec Date: Mon, 7 Nov 2022 22:03:45 +0000 (+0100) Subject: de rien X-Git-Url: http://popeye.lapinbilly.eu/git/?p=parefeu.git;a=commitdiff_plain de rien --- diff --git a/rt.c b/rt.c new file mode 100644 index 0000000..2acf232 --- /dev/null +++ b/rt.c @@ -0,0 +1,79 @@ +#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); + } +}