aboutsummaryrefslogtreecommitdiff
path: root/src/complete.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-03-17 05:52:37 -0400
committerB. Watson <urchlay@slackware.uk>2026-03-17 05:52:37 -0400
commitded1053f8b525e78d1121fd7f0a764ec5cc8cc05 (patch)
treee3872cde44718589276550ede7d9aae4ebd75c07 /src/complete.c
parente3b45c4788189bd04ed4cf9806191363715419ce (diff)
downloadfujinet-chat-ded1053f8b525e78d1121fd7f0a764ec5cc8cc05.tar.gz
Tab complete PM nics (private screen only). Also, no need to prefix messages with /m in server or private screens.
Diffstat (limited to 'src/complete.c')
-rw-r--r--src/complete.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/complete.c b/src/complete.c
new file mode 100644
index 0000000..0ac00a7
--- /dev/null
+++ b/src/complete.c
@@ -0,0 +1,89 @@
+#include <atari.h>
+#include <string.h>
+#include <ctype.h>
+#include "addrs.h"
+#include "edbox.h"
+#include "screen.h"
+#include "irc.h"
+
+#define COMP_S1 1
+#define COMP_PM 2
+#define COMP_CHAN 3
+
+#define MAX_PM_NICKS 10
+
+static char search_pos = 0, in_progress = 0;
+static char prefix[33];
+
+char comp_pm_nicks[MAX_PM_NICKS][25];
+char (*list)[25] = comp_pm_nicks;
+
+static char pm_nick_pos = 0; /* insertion point for _add() */
+
+void comp_add_pm_nick(const char *n) {
+ int i;
+
+ for(i = 0; i < 25; i++)
+ if(strncmp(n, comp_pm_nicks[i], 24) == 0)
+ return;
+
+ strncpy(comp_pm_nicks[pm_nick_pos], n, 24);
+ pm_nick_pos++;
+ pm_nick_pos %= MAX_PM_NICKS;
+}
+
+char match(const char *p, const char *q) {
+ int len;
+
+ len = strlen(prefix);
+ if(!len) return 0;
+
+ while(len--) {
+ if(tolower(*p) != tolower(*q))
+ return 0;
+ p++, q++;
+ }
+ return 1;
+}
+
+void comp_complete_done(void) {
+ in_progress = 0;
+}
+
+void comp_continue(void) {
+ search_pos %= MAX_PM_NICKS;
+ while(search_pos < MAX_PM_NICKS) {
+ if(match(prefix, list[search_pos])) {
+ edbox_set(list[search_pos]);
+ search_pos++;
+ return;
+ }
+ search_pos++;
+ }
+ edbox_set(prefix);
+ comp_complete_done();
+}
+
+void comp_start(void) {
+ if(scr_current != SCR_PRIV)
+ return;
+
+ /* just insert the last nick if there's nothing to search for */
+ if(!edbox_len) {
+ if(*last_pm_nick) edbox_set(last_pm_nick);
+ } else {
+ in_progress = COMP_PM;
+ search_pos = 0;
+ strncpy(prefix, edit_box, 24);
+ list = comp_pm_nicks;
+ comp_continue();
+ }
+}
+
+void comp_complete(void) {
+ if(in_progress)
+ comp_continue();
+ else
+ comp_start();
+}
+