aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-02-15 15:14:19 +0000
committerjames <>2008-02-15 15:14:19 +0000
commit19f0d6f858f40d948ea9d2f9537adc2f094dbad4 (patch)
treeb5fe51a0d147df4b9822326fd7c7ebe08256b83a
parentf9b87f6d2079298221b4e2110d6b7e6efc86aeb4 (diff)
downloadsympathy-19f0d6f858f40d948ea9d2f9537adc2f094dbad4.tar.gz
sympathy-19f0d6f858f40d948ea9d2f9537adc2f094dbad4.tar.bz2
sympathy-19f0d6f858f40d948ea9d2f9537adc2f094dbad4.zip
*** empty log message ***
-rw-r--r--src/cmd.c117
-rw-r--r--src/cmd.h33
2 files changed, 150 insertions, 0 deletions
diff --git a/src/cmd.c b/src/cmd.c
new file mode 100644
index 0000000..6017ccb
--- /dev/null
+++ b/src/cmd.c
@@ -0,0 +1,117 @@
+/*
+ * cmd.c:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+static char rcsid[] = "$Id$";
+
+/*
+ * $Log$
+ * Revision 1.1 2008/02/15 15:14:19 james
+ * *** empty log message ***
+ *
+ */
+
+#include "project.h"
+
+
+void
+cmd_parse (Cmd * c, Context * ctx, char *buf)
+{
+ if (!strcmp (buf, "quit"))
+ c->disconnect++;
+
+ if (!strcmp (buf, "flow"))
+ ctx->k->set_flow (ctx->k, ctx, 1);
+ if (!strcmp (buf, "noflow"))
+ ctx->k->set_flow (ctx->k, ctx, 0);
+ if (!strncmp (buf, "baud", 4))
+ ctx->k->set_baud (ctx->k, ctx, atoi (buf + 4));
+ if (!strncmp (buf, "break", 4))
+ ctx->k->send_break (ctx->k, ctx);
+
+}
+
+void
+cmd_show_status (Cmd * c, Context * ctx)
+{
+ if (!ctx->v)
+ return;
+
+ if (!c->active)
+ vt102_status_line (ctx->v, c->csl);
+ else
+ vt102_status_line (ctx->v, c->buf);
+
+
+}
+
+int
+cmd_key (Cmd * c, Context * ctx, int key)
+{
+
+ if (key == 13)
+ {
+ cmd_parse (c, ctx, c->buf + 1);
+ c->active = 0;
+ cmd_show_status (c, ctx);
+ return 0;
+ }
+
+ if (((key == 8) || (key == 127)) && (c->ptr > 1))
+ {
+ c->ptr--;
+ c->buf[c->ptr] = 0;
+ }
+
+ if ((key >= 32) && (key < 127))
+ {
+
+ c->buf[c->ptr] = key;
+ c->ptr++;
+ c->buf[c->ptr] = 0;
+
+ }
+
+ cmd_show_status (c, ctx);
+
+ return 0;
+}
+
+
+int
+cmd_activate (Cmd * c, Context * ctx)
+{
+ c->active = 1;
+ c->ptr = 1;
+ c->buf[0] = ':';
+ c->buf[1] = 0;
+
+ cmd_show_status (c, ctx);
+
+ return 0;
+}
+
+void
+cmd_new_status (Cmd * c, Context * ctx, char *msg)
+{
+ strcpy (c->csl, msg);
+ cmd_show_status (c, ctx);
+}
+
+
+
+Cmd *
+cmd_new (void)
+{
+ Cmd *ret;
+
+ ret = (Cmd *) malloc (sizeof (Cmd));
+
+ ret->disconnect = 0;
+ ret->active = 0;
+ ret->csl[0] = 0;
+}
diff --git a/src/cmd.h b/src/cmd.h
new file mode 100644
index 0000000..fb4e0ac
--- /dev/null
+++ b/src/cmd.h
@@ -0,0 +1,33 @@
+/*
+ * cmd.h:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * $Log$
+ * Revision 1.1 2008/02/15 15:14:19 james
+ * *** empty log message ***
+ *
+ */
+
+#ifndef __CMD_H__
+#define __CMD_H__
+
+#define CMD_KEY 2 /*CTRL B*/
+
+typedef struct {
+ int active;
+ int disconnect;
+ char csl[128];
+ char buf[128];
+ int ptr;
+} Cmd;
+
+#endif /* __CMD_H__ */