de rien master
authorDavid Marec <DavidMarec@users.noreply.github.com>
Mon, 7 Nov 2022 22:03:45 +0000 (23:03 +0100)
committerDavid Marec <DavidMarec@users.noreply.github.com>
Mon, 7 Nov 2022 22:03:45 +0000 (23:03 +0100)
rt.c [new file with mode: 0644]

diff --git a/rt.c b/rt.c
new file mode 100644 (file)
index 0000000..2acf232
--- /dev/null
+++ b/rt.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+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);
+       }
+}