chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / cmd.c
1 /*
2  * cmd.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] = "$Id$";
10
11 /*
12  * $Log$
13  * Revision 1.3  2008/02/22 17:07:00  james
14  * *** empty log message ***
15  *
16  * Revision 1.2  2008/02/15 23:52:12  james
17  * *** empty log message ***
18  *
19  * Revision 1.1  2008/02/15 15:14:19  james
20  * *** empty log message ***
21  *
22  */
23
24 #include "project.h"
25
26
27 void
28 cmd_parse (Cmd * c, Context * ctx, char *buf)
29 {
30   if (!strcmp (buf, "quit"))
31     c->disconnect++;
32
33   if (!strcmp (buf, "flow"))
34     ctx->k->set_flow (ctx->k, ctx, 1);
35   if (!strcmp (buf, "noflow"))
36     ctx->k->set_flow (ctx->k, ctx, 0);
37   if (!strcmp (buf, "ansi"))
38     ctx->k->set_ansi (ctx->k, ctx, 0);
39   if (!strcmp (buf, "noansi"))
40     ctx->k->set_ansi (ctx->k, ctx, 1);
41   if (!strncmp (buf, "baud", 4))
42     ctx->k->set_baud (ctx->k, ctx, atoi (buf + 4));
43   if (!strncmp (buf, "break", 4))
44     ctx->k->send_break (ctx->k, ctx);
45   if (!strncmp (buf, "hangup", 4))
46     ctx->k->hangup (ctx->k, ctx);
47
48 }
49
50 void
51 cmd_show_status (Cmd * c, Context * ctx)
52 {
53   if (!ctx->v)
54     return;
55
56   if (!c->active)
57     vt102_status_line (ctx->v, c->csl);
58   else
59     vt102_status_line (ctx->v, c->buf);
60
61
62 }
63
64 int
65 cmd_key (Cmd * c, Context * ctx, int key)
66 {
67
68   if (key == 13)
69     {
70       cmd_parse (c, ctx, c->buf + 1);
71       c->active = 0;
72       cmd_show_status (c, ctx);
73       return 0;
74     }
75
76   if (((key == 8) || (key == 127)) && (c->ptr > 1))
77     {
78       c->ptr--;
79       c->buf[c->ptr] = 0;
80     }
81
82   if ((key >= 32) && (key < 127))
83     {
84
85       c->buf[c->ptr] = key;
86       c->ptr++;
87       c->buf[c->ptr] = 0;
88
89     }
90
91   cmd_show_status (c, ctx);
92
93   return 0;
94 }
95
96
97 int
98 cmd_activate (Cmd * c, Context * ctx)
99 {
100   c->active = 1;
101   c->ptr = 1;
102   c->buf[0] = ':';
103   c->buf[1] = 0;
104
105   cmd_show_status (c, ctx);
106
107   return 0;
108 }
109
110 void
111 cmd_new_status (Cmd * c, Context * ctx, char *msg)
112 {
113   strcpy (c->csl, msg);
114   cmd_show_status (c, ctx);
115 }
116
117
118
119 Cmd *
120 cmd_new (void)
121 {
122   Cmd *ret;
123
124   ret = (Cmd *) malloc (sizeof (Cmd));
125
126   ret->disconnect = 0;
127   ret->active = 0;
128   ret->csl[0] = 0;
129 }