summaryrefslogtreecommitdiff
path: root/unsorted/Utils.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-01-15 12:14:05 +0000
committerAsh Wolf <ninji@wuffs.org>2023-01-15 12:14:05 +0000
commit35d488e972a9dd75ce3867c000405f128b79c615 (patch)
treee3319a23d9aa0d4725f88a99fdd5131488a334a9 /unsorted/Utils.c
parent8078e7f897aaae9b492b22475060052d68b9c547 (diff)
downloadMWCC-35d488e972a9dd75ce3867c000405f128b79c615.tar.gz
MWCC-35d488e972a9dd75ce3867c000405f128b79c615.zip
reorganise things a bit to align further with the actual names/structure
Diffstat (limited to 'unsorted/Utils.c')
-rw-r--r--unsorted/Utils.c174
1 files changed, 0 insertions, 174 deletions
diff --git a/unsorted/Utils.c b/unsorted/Utils.c
deleted file mode 100644
index b627c4d..0000000
--- a/unsorted/Utils.c
+++ /dev/null
@@ -1,174 +0,0 @@
-#include "parser.h"
-
-int my_tolower(char c) {
- if (c >= 'A' && c <= 'Z')
- return c | 0x20;
- else
- return c;
-}
-
-int my_isdigit(char c) {
- return (c >= '0' && c <= '9');
-}
-
-int my_isalpha(char c) {
- return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
-}
-
-int my_isalnum(char c) {
- return my_isdigit(c) || my_isalpha(c);
-}
-
-int my_isxdigit(char c) {
- return my_isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
-}
-
-char *Utils_SpellList(char *list, char *buffer, char opts) {
- char *sptr;
- char *eptr;
- char *nptr;
- char *bptr;
- int pflen;
- int npflen;
- int undo;
- char *neptr;
- int cnt;
-
- undo = 0;
- bptr = buffer;
- sptr = list;
- pflen = 0;
- while (sptr) {
- if ((opts & 1) && !pflen)
- *(bptr++) = *MAINOPTCHAR;
-
- eptr = strchr(sptr, '|');
- if (!eptr) {
- eptr = sptr + strlen(sptr);
- nptr = 0;
- } else if (eptr[1] == '|') {
- nptr = 0;
- } else {
- nptr = eptr + 1;
- }
-
- if (undo == 0 && !pflen) {
- if (opts & 8) {
- *(bptr++) = '[';
- *(bptr++) = 'n';
- *(bptr++) = 'o';
- *(bptr++) = ']';
- }
- if (opts & 0x20) {
- *(bptr++) = '[';
- *(bptr++) = 'n';
- *(bptr++) = 'o';
- *(bptr++) = '-';
- *(bptr++) = ']';
- }
- }
-
- npflen = 0;
- if (nptr) {
- while (sptr < nptr && *nptr && *nptr != '|' && sptr[npflen] == nptr[npflen])
- npflen++;
-
- if (npflen) {
- neptr = strchr(nptr, '|');
- if (!neptr)
- neptr = nptr + strlen(nptr);
- if ((neptr - nptr) < (eptr - sptr) || ((sptr[1] && sptr[1] != '|') ? (sptr[1] != nptr[1]) : 0))
- npflen = 0;
- if (opts & 0x40)
- npflen = 0;
- }
- }
-
- if (pflen) {
- sptr += pflen;
- while (sptr < eptr) {
- *(bptr++) = *(sptr++);
- }
- if (npflen > pflen) {
- *(bptr++) = '[';
- undo++;
- }
- if (npflen < pflen) {
- *(bptr++) = ']';
- undo--;
- }
- } else if (npflen) {
- for (cnt = npflen; cnt > 0; cnt--) {
- *(bptr++) = *(sptr++);
- }
- *(bptr++) = '[';
- undo++;
- }
-
- while (sptr < eptr) {
- *(bptr++) = *(sptr++);
- }
-
- if (opts & 0x10) {
- *(bptr++) = '[';
- *(bptr++) = '-';
- *(bptr++) = ']';
- }
- if (opts & 0x40) {
- *(bptr++) = '+';
- }
-
- sptr = nptr;
- if (nptr && bptr[-1] != '[') {
- if ((opts & 1) || (bptr[-1] == ']') || ((opts & 8) && !undo)) {
- *(bptr++) = ' ';
- *(bptr++) = '|';
- *(bptr++) = ' ';
- } else {
- *(bptr++) = '|';
- }
- }
-
- opts &= ~0x40;
- pflen = npflen;
- }
-
- for (cnt = undo; cnt; cnt--) {
- *(bptr++) = ']';
- }
-
- if (opts & 4)
- bptr += sprintf(bptr, "=...");
-
- *bptr = 0;
- return bptr;
-}
-
-int Utils_CompareOptionString(const char *a, const char *b, int cased, int sticky) {
- const char *ae;
- const char *be;
-
- for (ae = a; *ae && *ae != '|'; ae++) {}
- for (be = b; *be && *be != '|'; be++) {}
-
- if (sticky && (be - b) < (ae - a))
- return 0;
-
- if (cased) {
- while (a < ae && b < be) {
- if (*a != *b)
- break;
- a++;
- b++;
- }
- } else {
- while (a < ae && b < be) {
- if (my_tolower(*a) != my_tolower(*b))
- break;
- a++;
- b++;
- }
- }
-
- return (a == ae) && (sticky || b == be);
-}