diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-05-25 00:25:01 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-05-25 00:25:01 -0300 |
| commit | 5f883a80175a4cc9abda9d647a6a0d73bda84878 (patch) | |
| tree | d585487084c455a5ff0659a8cff6fdaf9d357ba9 /src/script.cc | |
| parent | 3f557369c7bbd08fdf2e6dbd9271873b20a9a144 (diff) | |
| download | game-5f883a80175a4cc9abda9d647a6a0d73bda84878.tar.gz game-5f883a80175a4cc9abda9d647a6a0d73bda84878.zip | |
move string utility to `util.cc` + small script identifier fix
Diffstat (limited to 'src/script.cc')
| -rw-r--r-- | src/script.cc | 106 |
1 files changed, 2 insertions, 104 deletions
diff --git a/src/script.cc b/src/script.cc index 5dd3751..39141f7 100644 --- a/src/script.cc +++ b/src/script.cc @@ -15,108 +15,6 @@ static char ErrorString[100]; // Helper Functions // ============================================================================= -// TODO(fusion): Move to `util.cc`? - -static bool isSpace(int c){ - return c == ' ' - || c == '\t' - || c == '\n' - || c == '\r' - || c == '\v' - || c == '\f'; -} - -static bool isAlpha(int c){ - // TODO(fusion): This is most likely wrong! We're assuming a direct conversion - // from `char` to `int` which will cause sign extension for negative values. This - // wouldn't be a problem if we expected to parse only streams of `char[]` but can - // be problematic for the output of `getc` which returns bytes as `unsigned char` - // converted to `int`. - // TLDR: The parameter `c` should be `uint8`. - return ('A' <= c && c <= 'Z') - || ('a' <= c && c <= 'z') - || c == -0x1C // E4 => ä - || c == -0x0A // F6 => ö - || c == -0x04 // FC => ü - || c == -0x3C // C4 => Ä - || c == -0x2A // D6 => Ö - || c == -0x24 // DC => Ü - || c == -0x21; // DF => ß -} - -static bool isEngAlpha(int c){ - return ('A' <= c && c <= 'Z') - || ('a' <= c && c <= 'z'); -} - -static bool isDigit(int c){ - return ('0' <= c && c <= '9'); -} - -static int toLower(int c){ - // TODO(fusion): Same problem as `isAlpha`. - if(('A' <= c && c <= 'Z') || (0xC0 <= c && c <= 0xDE && c != 0xD7)){ - c += 32; - } - return c; -} - -static int toUpper(int c){ - // TODO(fusion): Same problem as `isAlpha`. - if(('A' <= c && c <= 'Z') || (0xE0 <= c && c <= 0xFE && c != 0xF7)){ - c -= 32; - } - return c; -} - -static char *strLower(char *s){ - for(int i = 0; s[i] != 0; i += 1){ - s[i] = (char)toLower(s[i]); - } - return s; -} - -static char *strUpper(char *s){ - for(int i = 0; s[i] != 0; i += 1){ - s[i] = (char)toUpper(s[i]); - } - return s; -} - -static int stricmp(const char *s1, const char *s2, int Pos){ - for(int i = 0; i < Pos; i += 1){ - int c1 = toLower(s1[i]); - int c2 = toLower(s2[i]); - if(c1 > c2){ - return 1; - }else if(c1 < c2){ - return -1; - }else{ - ASSERT(c1 == c2); - if(c1 == 0){ - return 0; - } - } - } -} - -static char *findFirst(char *s, char c){ - return strchr(s, (int)c); -} - -static char *findLast(char *s, char c){ - char *Current = s; - char *Last = NULL; - while(true){ - Current = strchr(Current, (int)c); - if(Current == NULL) - break; - Last = Current; - Current += 1; // skip character - } - return Last; -} - static void SaveFile(const char *Filename){ if(Filename == NULL){ error("SaveFile: Filename ist NULL.\n"); @@ -143,7 +41,7 @@ static void SaveFile(const char *Filename){ // NOTE(fusion): This function was in pretty bad shape after this point. The // reason is probably because GHIDRA didn't make sense of it using `alloca` - // or some other mechanism to allocate a buffer on the stack to copy the whole + // or some other mechanism to allocate a buffer on the stack and copy the whole // file in one go. It's probably not a good idea to mimic that here so we'll // do it gradually. @@ -535,7 +433,7 @@ void TReadScriptFile::nextToken(void){ while(true){ int next = getc(File); if(isAlpha(next) || isDigit(next) || next == '_'){ - if(IdentLength >= 30){ + if(IdentLength >= (MAX_IDENT_LENGTH - 1)){ this->error("identifier too long"); } this->String[IdentLength] = (char)next; |
