diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-03-31 04:10:12 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-03-31 04:10:12 -0400 |
| commit | ed04dd7fb0c859870e708da809b002508f959b1c (patch) | |
| tree | 795176851a8010f6284c723e56c6471b78531513 | |
| parent | 5a1d4762bc8fdd39a014bd5f469089f944bc5944 (diff) | |
| download | fujinet-chat-ed04dd7fb0c859870e708da809b002508f959b1c.tar.gz | |
Replace strcmp() and friends, tolower(), with custom (small) routines. now at 5129 bytes free.
| -rw-r--r-- | src/cmd.c | 1 | ||||
| -rw-r--r-- | src/complete.c | 5 | ||||
| -rw-r--r-- | src/irc.c | 5 | ||||
| -rw-r--r-- | src/irc.h | 2 | ||||
| -rw-r--r-- | src/screen.c | 3 | ||||
| -rw-r--r-- | src/streq.h | 4 | ||||
| -rw-r--r-- | src/streq.s | 84 |
7 files changed, 99 insertions, 5 deletions
@@ -7,6 +7,7 @@ #include "screen.h" #include "edbox.h" #include "config.h" +#include "streq.h" /* A "command" is actually anything the user types, whether or not it starts with a / character. */ diff --git a/src/complete.c b/src/complete.c index 108bc90..1af6930 100644 --- a/src/complete.c +++ b/src/complete.c @@ -5,6 +5,7 @@ #include "edbox.h" #include "screen.h" #include "irc.h" +#include "streq.h" #define COMP_S1 1 #define COMP_PM 2 @@ -27,7 +28,7 @@ static void add_list(const char *n) { int i; for(i = 0; i < 25; i++) - if(strncmp(n, add_to[i], 24) == 0) + if(strneq_i(n, add_to[i], 24)) return; /* we already got this one */ strncpy(add_to[pm_nick_pos], n, 24); @@ -55,7 +56,7 @@ char match(const char *p, const char *q) { if(!len) return 0; while(len--) { - if(tolower(*p) != tolower(*q)) + if(lcase(*p) != lcase(*q)) return 0; p++, q++; } @@ -16,6 +16,7 @@ #include "complete.h" #include "keytab.h" #include "kgetc.h" +#include "streq.h" #ifndef VERSION #define VERSION "?????" @@ -514,7 +515,7 @@ static void invalid_msg(char type) { } #endif -static char cmd_is(const char *cmd) { +static char cmd_is(char *cmd) { return streq_i(msg_cmd, cmd); } @@ -947,7 +948,7 @@ void start_keystroke(char c) { return; } - switch(tolower(c)) { + switch(lcase(c)) { case XCH_UP: case '-': scrollback(); @@ -1,7 +1,9 @@ #define MAX_IRC_MSG_LEN 512 +/* #define streq(x,y) !strcmp(x,y) #define streq_i(x,y) !strcasecmp(x,y) +*/ /**** main.c */ extern char *rx_buf; diff --git a/src/screen.c b/src/screen.c index 258a4a7..646e7ec 100644 --- a/src/screen.c +++ b/src/screen.c @@ -5,6 +5,7 @@ #include "screen.h" #include "edbox.h" #include "indic8.h" +#include "streq.h" #define SDLST ((u16 *)0x0230) @@ -198,7 +199,7 @@ char scr_getbyname(const char *name) { if(!name) return 0; for(i = 2; i < MAX_SCREENS; i++) { - if(strcasecmp(name, scr_names[i]) == 0) + if(streq(name, scr_names[i])) return i; } diff --git a/src/streq.h b/src/streq.h new file mode 100644 index 0000000..0996e29 --- /dev/null +++ b/src/streq.h @@ -0,0 +1,4 @@ +extern char lcase(char c); +extern char streq(const char *s1, const char *s2); +extern char streq_i(const char *s1, const char *s2); +extern char strneq_i(const char *s1, const char *s2, char limit); diff --git a/src/streq.s b/src/streq.s new file mode 100644 index 0000000..2116203 --- /dev/null +++ b/src/streq.s @@ -0,0 +1,84 @@ + + .importzp sreg, ptr1, ptr2 + .import popptr1, popax + .export _streq, _streq_i, _strneq_i, _lcase + + ; extern __fastcall__ char lcase(char c); + ; extern __fastcall__ char streq(char *s1, char *s2); + ; extern __fastcall__ char streq_i(char *s1, char *s2); + ; extern __fastcall__ char strneq_i(char *s1, char *s2, char len); + + ; these are fast and small replacements for standard C library functions. + ; lcase() is a drop-in replacement for tolower(). + ; streq() is basically strcmp() except it returns true for equality, + ; false for inequality (so you can't e.g. use it for sorting). + ; also, it only supports strings up to 256 bytes long. + ; streq_i() is the case-insensitive verson of streq(). + ; strneq_i() is case-insensitive and stops after 'len' characters. + + limit = sreg+3 ; number of characters to compare (0 = 256) + insens = sreg ; bit 7 set = case insensitive, otherwise not + temp = sreg+1 ; nothing to see here, move along :) + +_lcase: + cmp #'Z'+1 + bcs lcret + cmp #'A' + bcc lcret + ora #$20 +lcret: + rts + +_strneq_i: + sta limit + jsr popax + ldy #$80 + sty insens + jmp doit + +_streq_i: + ldy #$80 + .byte $2c ; BIT abs, skip next +_streq: + ldy #0 + sty insens + ldy #0 + sty limit + +doit: + sta ptr2 + stx ptr2+1 + jsr popptr1 ; returns with Y=0 + +cmploop: + lda (ptr2),y + bit insens + bpl no_case_1 + jsr _lcase + +no_case_1: + sta temp + lda (ptr1),y + tax + bit insens + bpl no_case_2 + jsr _lcase + +no_case_2: + sec + sbc temp + bne ret0 + txa + beq ret1 + + iny + cpy limit + bne cmploop + +ret1: + lda #1 + .byte $2c +ret0: + lda #0 + tax + rts |
