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