aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd.c8
-rw-r--r--src/complete.c89
-rw-r--r--src/complete.h3
-rw-r--r--src/edbox.c17
-rw-r--r--src/edbox.h4
-rw-r--r--src/irc.c2
-rw-r--r--src/irc.h1
7 files changed, 123 insertions, 1 deletions
diff --git a/src/cmd.c b/src/cmd.c
index ef75b66..d984c9a 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -477,6 +477,8 @@ void cmd_command(char *cmd) {
cmd_slash();
else if(target)
cmd_chan_text();
+ else if(scr_current == SCR_PRIV || scr_current == SCR_SERVER)
+ cmd_send_pm(cmd);
else
err_no_scr_target();
}
@@ -504,3 +506,9 @@ void cmd_rejoin_chans(void) {
mass_join(0);
edbox_clear();
}
+
+/* args contains the destination, space, the msg */
+void cmd_send_pm(char *args) {
+ arg1 = args;
+ do_msg();
+}
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();
+}
+
diff --git a/src/complete.h b/src/complete.h
new file mode 100644
index 0000000..4b0663b
--- /dev/null
+++ b/src/complete.h
@@ -0,0 +1,3 @@
+void comp_complete(void);
+void comp_complete_done(void);
+void comp_add_pm_nick(const char *n);
diff --git a/src/edbox.c b/src/edbox.c
index 6ac1e7c..5d529d3 100644
--- a/src/edbox.c
+++ b/src/edbox.c
@@ -5,12 +5,13 @@
#include "screen.h"
#include "edbox.h"
#include "keyclick.h"
+#include "complete.h"
/* TODO: tab completion */
int edbox_visible = 0;
static u16 edbox_pos; /* range 0 to EDBOX_SIZE - 1 */
-static u16 edbox_len; /* idem */
+u16 edbox_len; /* idem */
void (*edbox_callback)(void);
@@ -133,6 +134,9 @@ static void normal_keystroke(void) {
c = cgetc();
+ if(c != CH_TAB)
+ comp_complete_done();
+
switch(c) {
case CH_EOL:
// hide_cursor(); // already done by the caller
@@ -189,6 +193,9 @@ static void normal_keystroke(void) {
case 0x05: /* ^E */
edbox_pos = edbox_len;
break;
+ case CH_TAB:
+ comp_complete();
+ break;
default:
edbox_putc(c);
break;
@@ -264,3 +271,11 @@ void edbox_keystroke(void) {
if(edbox_visible) edbox_show();
show_cursor();
}
+
+void edbox_set(char *contents) {
+ edbox_clear();
+ while(*contents) {
+ edit_box[edbox_len++] = *contents++;
+ }
+ edbox_pos = edbox_len;
+}
diff --git a/src/edbox.h b/src/edbox.h
index c919ee9..4863407 100644
--- a/src/edbox.h
+++ b/src/edbox.h
@@ -5,6 +5,7 @@
#define EDBOX_SIZE 240
extern int edbox_visible;
+extern u16 edbox_len;
/* clear the contents of the edit box (whether it's visible or not) */
void edbox_clear(void);
@@ -24,3 +25,6 @@ void edbox_keystroke(void);
/* called when the user presses Return */
extern void (*edbox_callback)(void);
+
+/* set edit box contents (clears out whatever was there) */
+void edbox_set(char *contents);
diff --git a/src/irc.c b/src/irc.c
index d34fe8d..7611cef 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -14,6 +14,7 @@
#include "nio.h"
#include "config.h"
#include "indic8.h"
+#include "complete.h"
#ifndef VERSION
#define VERSION "?????"
@@ -504,6 +505,7 @@ void select_screen(void) {
if(!s) {
if(streq_i(msg_cmd, "PRIVMSG")) { /* or maybe NOTICE? */
strncpy(last_pm_nick, msg_src, 32);
+ comp_add_pm_nick(last_pm_nick);
s = SCR_PRIV;
} else {
s = SCR_SERVER;
diff --git a/src/irc.h b/src/irc.h
index 14c66aa..e2315a5 100644
--- a/src/irc.h
+++ b/src/irc.h
@@ -67,4 +67,5 @@ void cmd_command(char *cmd);
void cmd_execute(void);
void cmd_rejoin_chans(void);
void cmd_ctcp_ping(char *nick);
+void cmd_send_pm(char *args);
unsigned int read_rtclok(void); /* irc.c needs this one so it's not static */