X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tools%2Fmy_str.h;fp=tools%2Fmy_str.h;h=44caa7cd4b189987255299fc47052cfbe9a35074;hb=57e4efe91798516df7ebe3ddd9a4aba5cadc497b;hp=0000000000000000000000000000000000000000;hpb=a2f78da4b699ffcdec280c7cb489fefc38c3a3cc;p=ia32rtools.git diff --git a/tools/my_str.h b/tools/my_str.h new file mode 100644 index 0000000..44caa7c --- /dev/null +++ b/tools/my_str.h @@ -0,0 +1,56 @@ +static int my_isblank(char c) +{ + return c == '\t' || c == ' ' || c == '\r' || c == '\n'; +} + +static int my_issep(char c) +{ + return c == '(' || c == ')' || c == '[' || c == ']' + || c == '<' || c == '>' || c == ','; +} + +static char *sskip(char *s) +{ + while (my_isblank(*s)) + s++; + + return s; +} + +static char *next_word(char *w, size_t wsize, char *s) +{ + size_t i; + + s = sskip(s); + + for (i = 0; i < wsize - 1; i++) { + if (*s == 0 || my_isblank(s[i])) + break; + w[i] = s[i]; + } + w[i] = 0; + + if (*s != 0 && !my_isblank(s[i])) + printf("warning: '%s' truncated\n", w); + + return s + i; +} + +static inline char *next_idt(char *w, size_t wsize, char *s) +{ + size_t i; + + s = sskip(s); + + for (i = 0; i < wsize - 1; i++) { + if (*s == 0 || my_isblank(s[i]) || my_issep(s[i])) + break; + w[i] = s[i]; + } + w[i] = 0; + + if (*s != 0 && !my_isblank(s[i]) && !my_issep(s[i])) + printf("warning: '%s' truncated\n", w); + + return s + i; +}