aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd.c
blob: 7105c5b1a28bf920c9c4046194e55bea767bff8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * cmd.c:
 *
 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

static char rcsid[] = "$Id$";

/*
 * $Log$
 * Revision 1.3  2008/02/22 17:07:00  james
 * *** empty log message ***
 *
 * Revision 1.2  2008/02/15 23:52:12  james
 * *** empty log message ***
 *
 * Revision 1.1  2008/02/15 15:14:19  james
 * *** empty log message ***
 *
 */

#include "project.h"


void
cmd_parse (Cmd * c, Context * ctx, char *buf)
{
  if (!strcmp (buf, "quit"))
    c->disconnect++;

  if (!strcmp (buf, "flow"))
    ctx->k->set_flow (ctx->k, ctx, 1);
  if (!strcmp (buf, "noflow"))
    ctx->k->set_flow (ctx->k, ctx, 0);
  if (!strcmp (buf, "ansi"))
    ctx->k->set_ansi (ctx->k, ctx, 0);
  if (!strcmp (buf, "noansi"))
    ctx->k->set_ansi (ctx->k, ctx, 1);
  if (!strncmp (buf, "baud", 4))
    ctx->k->set_baud (ctx->k, ctx, atoi (buf + 4));
  if (!strncmp (buf, "break", 4))
    ctx->k->send_break (ctx->k, ctx);
  if (!strncmp (buf, "hangup", 4))
    ctx->k->hangup (ctx->k, ctx);

}

void
cmd_show_status (Cmd * c, Context * ctx)
{
  if (!ctx->v)
    return;

  if (!c->active)
    vt102_status_line (ctx->v, c->csl);
  else
    vt102_status_line (ctx->v, c->buf);


}

int
cmd_key (Cmd * c, Context * ctx, int key)
{

  if (key == 13)
    {
      cmd_parse (c, ctx, c->buf + 1);
      c->active = 0;
      cmd_show_status (c, ctx);
      return 0;
    }

  if (((key == 8) || (key == 127)) && (c->ptr > 1))
    {
      c->ptr--;
      c->buf[c->ptr] = 0;
    }

  if ((key >= 32) && (key < 127))
    {

      c->buf[c->ptr] = key;
      c->ptr++;
      c->buf[c->ptr] = 0;

    }

  cmd_show_status (c, ctx);

  return 0;
}


int
cmd_activate (Cmd * c, Context * ctx)
{
  c->active = 1;
  c->ptr = 1;
  c->buf[0] = ':';
  c->buf[1] = 0;

  cmd_show_status (c, ctx);

  return 0;
}

void
cmd_new_status (Cmd * c, Context * ctx, char *msg)
{
  strcpy (c->csl, msg);
  cmd_show_status (c, ctx);
}



Cmd *
cmd_new (void)
{
  Cmd *ret;

  ret = (Cmd *) malloc (sizeof (Cmd));

  ret->disconnect = 0;
  ret->active = 0;
  ret->csl[0] = 0;
}