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