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.5  2008/02/28 15:37:06  james
14  * *** empty log message ***
15  *
16  * Revision 1.4  2008/02/28 11:27:48  james
17  * *** empty log message ***
18  *
19  * Revision 1.3  2008/02/22 17:07:00  james
20  * *** empty log message ***
21  *
22  * Revision 1.2  2008/02/15 23:52:12  james
23  * *** empty log message ***
24  *
25  * Revision 1.1  2008/02/15 15:14:19  james
26  * *** empty log message ***
27  *
28  */
29
30 #include "project.h"
31
32
33 int
34 cmd_parse (Cmd * c, Context * ctx, char *buf)
35 {
36   if (!strcmp (buf, "quit"))
37     c->disconnect++;
38   else if (!strcmp (buf, "flow"))
39     ctx->k->set_flow (ctx->k, ctx, 1);
40   else if (!strcmp (buf, "noflow"))
41     ctx->k->set_flow (ctx->k, ctx, 0);
42   else if (!strcmp (buf, "ansi"))
43     ctx->k->set_ansi (ctx->k, ctx, 0);
44   else if (!strcmp (buf, "noansi"))
45     ctx->k->set_ansi (ctx->k, ctx, 1);
46   else if (!strncmp (buf, "baud", 4))
47     ctx->k->set_baud (ctx->k, ctx, atoi (buf + 4));
48   else if (!strcmp (buf, "break"))
49     ctx->k->send_break (ctx->k, ctx);
50   else if (!strcmp (buf, "hangup"))
51     ctx->k->hangup (ctx->k, ctx);
52   else if (!strcmp (buf, "reset"))
53     ctx->k->reset (ctx->k, ctx);
54   else if (!strncmp (buf, "width", 5))
55     ctx->k->set_size (ctx->k, ctx,atoi(buf+5),0);
56   else if (!strncmp (buf, "height", 6))
57     ctx->k->set_size (ctx->k, ctx,0,atoi(buf+6));
58   else return -1;
59
60 return 0;
61
62
63 }
64
65 void
66 cmd_show_status (Cmd * c, Context * ctx)
67 {
68   if (!ctx->v)
69     return;
70
71   if (c->error) 
72     vt102_status_line (ctx->v, "Command not recognized - press any key");
73   else if (!c->active)
74     vt102_status_line (ctx->v, c->csl);
75   else
76     vt102_status_line (ctx->v, c->buf);
77
78 }
79
80 int
81 cmd_key (Cmd * c, Context * ctx, int key)
82 {
83
84   if (c->error) {
85         c->error=0;
86         c->active=0;
87         cmd_show_status (c, ctx);
88         return 0;
89   }
90
91   if (key == 13)
92     {
93       if (cmd_parse (c, ctx, c->buf + 1))  {
94         c->error++;
95         } else{
96       c->active = 0;
97         }
98       cmd_show_status (c, ctx);
99       return 0;
100     }
101
102   if (((key == 8) || (key == 127)) && (c->ptr > 1))
103     {
104       c->ptr--;
105       c->buf[c->ptr] = 0;
106     }
107
108   if ((key >= 32) && (key < 127))
109     {
110
111       c->buf[c->ptr] = key;
112       c->ptr++;
113       c->buf[c->ptr] = 0;
114
115     }
116
117   cmd_show_status (c, ctx);
118
119   return 0;
120 }
121
122
123 int
124 cmd_activate (Cmd * c, Context * ctx)
125 {
126   c->active = 1;
127   c->ptr = 1;
128   c->buf[0] = ':';
129   c->buf[1] = 0;
130
131   cmd_show_status (c, ctx);
132
133   return 0;
134 }
135
136 void
137 cmd_new_status (Cmd * c, Context * ctx, char *msg)
138 {
139   strcpy (c->csl, msg);
140   cmd_show_status (c, ctx);
141 }
142
143
144
145 Cmd *
146 cmd_new (void)
147 {
148   Cmd *ret;
149
150   ret = (Cmd *) malloc (sizeof (Cmd));
151
152   ret->disconnect = 0;
153   ret->active = 0;
154   ret->csl[0] = 0;
155 }