summaryrefslogtreecommitdiffstats
path: root/init.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1998-06-08 09:17:25 +0000
committerThomas Roessler <roessler@does-not-exist.org>1998-06-08 09:17:25 +0000
commit57c930bf79e06c485142efeb62ffb1e9d8fe3d3b (patch)
treec3c1e876454aead42f16023f45b23a73961a03d6 /init.c
parent1a5381e07e97fe482c2b3a7c75f99938f0b105d4 (diff)
Mutt 0.92.9i.mutt-0-92-9i
Diffstat (limited to 'init.c')
-rw-r--r--init.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/init.c b/init.c
index ddcb531e..accc95d8 100644
--- a/init.c
+++ b/init.c
@@ -1120,6 +1120,79 @@ finish:
return (r);
}
+/* helper function for completion. Changes the dest buffer if
+ necessary/possible to aid completion.
+ dest == completion result gets here.
+ src == candidate for completion.
+ try == user entered data for completion.
+ len == length of dest buffer.
+*/
+static void candidate (char *dest, char *try, char *src, int len)
+{
+ int l;
+
+ if (strstr (src, try) == src)
+ {
+ if (dest[0] == 0)
+ {
+ strncpy (dest, src, len);
+ strncat (dest, " ", len);
+ }
+ else
+ {
+ for (l = 0; src[l] && src[l] == dest[l]; l++);
+ dest[l] = 0;
+ }
+ }
+}
+
+int mutt_command_complete (char *buffer, size_t len, int pos)
+{
+ char cmd[STRING];
+ char completed[STRING] = { 0 };
+ char *pt;
+ int num;
+
+ if (buffer[0] == 0)
+ return 0;
+ strncpy (cmd, buffer, pos);
+ pt = cmd;
+ pt[pos] = 0;
+ while (!isspace (*pt))
+ pt++;
+ *pt = 0;
+
+ pt = buffer + pos;
+ while ((pt > buffer) && !isspace (*pt))
+ pt--;
+ if (pt == buffer) /* complete cmd */
+ {
+ for (num = 0; Commands[num].name; num++)
+ candidate (completed, cmd, Commands[num].name, sizeof (completed));
+
+ if (completed[0] == 0)
+ return 0;
+ strncpy (buffer, completed, len);
+ }
+ else if (!strncasecmp (cmd, "set", 3)
+ || !strncasecmp (cmd, "unset", 5)
+ || !strncasecmp (cmd, "toggle", 6))
+ { /* complete variables */
+ pt++;
+ if (*pt == 0)
+ return 0;
+ strncpy (cmd, pt, sizeof (cmd));
+ for (num = 0; MuttVars[num].option; num++)
+ candidate (completed, cmd, MuttVars[num].option, sizeof (completed));
+ if (completed[0] == 0)
+ return 0;
+ strncpy (pt, completed, buffer + len - pt);
+ }
+ else
+ return 0;
+ return 1;
+}
+
char *mutt_getnamebyvalue (int val, const struct mapping_t *map)
{
int i;