From 551fbf43202d02c68f4d90d0cf8b5257444b80ea Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 2 Apr 2026 06:50:36 -0400 Subject: Replace strstr() with find_nick(). Now 6133 bytes free. --- src/edbox.c | 12 ++---------- src/irc.c | 3 +++ src/streq.h | 1 + src/streq.s | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/edbox.c b/src/edbox.c index bbad5c1..0725379 100644 --- a/src/edbox.c +++ b/src/edbox.c @@ -121,14 +121,6 @@ static void word_left(char del) { if(del && !edbox_pos) edit_box[edbox_pos] = /* ' ' */ 0; } -static void del_word(void) { - word_left(1); -} - -static void back_word(void) { - word_left(0); -} - static void forward_word(void) { while(edbox_pos < edbox_len && edit_box[edbox_pos] == ' ') edbox_pos++; @@ -196,7 +188,7 @@ void edbox_keystroke(char c) { right(); break; case XCH_LWORD: - back_word(); + word_left(0); break; case XCH_RWORD: forward_word(); @@ -231,7 +223,7 @@ void edbox_keystroke(char c) { backspace(); break; case 0x17: /* ^W */ - del_word(); + word_left(1); break; case 0x01: /* ^A */ edbox_pos = 0; diff --git a/src/irc.c b/src/irc.c index a6b4621..e518205 100644 --- a/src/irc.c +++ b/src/irc.c @@ -225,10 +225,13 @@ static void do_ctcp(char is_notice) { static void do_privmsg(void) { /* TODO: this shouldn't be case-sensitive */ + /* if(strstr(msg_text, config.nick)) hilite = 1; else hilite = 0; + */ + hilite = find_nick(); if(*msg_text == '\x01') { do_ctcp(0); diff --git a/src/streq.h b/src/streq.h index 0996e29..65b6ddb 100644 --- a/src/streq.h +++ b/src/streq.h @@ -2,3 +2,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); +extern char find_nick(void); diff --git a/src/streq.s b/src/streq.s index 2116203..d063a35 100644 --- a/src/streq.s +++ b/src/streq.s @@ -1,12 +1,14 @@ .importzp sreg, ptr1, ptr2 .import popptr1, popax - .export _streq, _streq_i, _strneq_i, _lcase + .import _msg_text + .export _streq, _streq_i, _strneq_i, _lcase, _find_nick ; 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); + ; extern __fastcall__ char find_nick(void); ; these are fast and small replacements for standard C library functions. ; lcase() is a drop-in replacement for tolower(). @@ -15,10 +17,17 @@ ; 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. + ; find_nick() does a case-insensitive search of msg_text for + ; config.nick. returns 1 if found, 0 if not. NOTE: only searches the + ; first 256 bytes of msg_text! this is a minor infelicity, but people + ; rarely type that much text in one message... 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 :) + temp2 = sreg+2 + + NICK = $0480 ; aka config.nick _lcase: cmp #'Z'+1 @@ -82,3 +91,44 @@ ret0: lda #0 tax rts + +_find_nick: + lda _msg_text + sta ptr1 + lda _msg_text+1 + sta ptr1+1 + ldy #0 + ; loop over _msg_text, looking for the first character of NICK, + ; but convert both to lowercase before comparing. +@l: + lda (ptr1),y + beq ret0 ; if we hit the end of _msg_text, we're done, no match. + jsr _lcase + sta temp ; temp = lcase(A) + lda NICK ; compare to lcase(NICK[0]) + jsr _lcase + cmp temp + beq @found1 ; found a match for the first char, see if the rest matches. +@next: + iny + bne @l + beq ret0 +@found1: ; found a case-insensitive match for the first char of NICL... + sty temp2 ; save Y so we can pick back up in the @l loop if this isn't a match. + iny ; start with _msg_text char after the initial match. + ldx #1 ; start with 2nd char of NICK +@l2: + lda (ptr1),y + jsr _lcase + sta temp + lda NICK,x + beq ret1 ; if we hit the null terminator of NICK, we have a successful match! + jsr _lcase + cmp temp + bne @nope ; no match, get out of @l2 + iny + inx + bne @l2 ; matched a char, look at the next +@nope: + ldy temp2 ; restore Y + jmp @next ; jump to the bottom of the @l loop. -- cgit v1.2.3