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