~ubuntu-branches/ubuntu/trusty/netrek-client-cow/trusty

« back to all changes in this revision

Viewing changes to netstatopt.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2008-09-26 21:44:49 UTC
  • Revision ID: james.westby@ubuntu.com-20080926214449-ylybi4033uv3lz2q
Tags: upstream-3.2.8
ImportĀ upstreamĀ versionĀ 3.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * $Log: netstatopt.c,v $
 
4
 * Revision 1.1.1.1  1998/11/01 17:24:10  siegl
 
5
 * COW 3.0 initial revision
 
6
 * */
 
7
#include "config.h"
 
8
#include "copyright.h"
 
9
 
 
10
#include <stdio.h>
 
11
#include <ctype.h>
 
12
#include "Wlib.h"
 
13
#include "defs.h"
 
14
#include "struct.h"
 
15
#include "data.h"
 
16
#include "packets.h"
 
17
 
 
18
 
 
19
nswindow(void)
 
20
{
 
21
  register int i;
 
22
 
 
23
  for (i = 0; i < NETSTAT_NUMFIELDS; i++)
 
24
    nsrefresh(i);
 
25
 
 
26
  /* Map window */
 
27
  W_MapWindow(netstatWin);
 
28
}
 
29
 
 
30
/* Refresh item i */
 
31
nsrefresh(int i)
 
32
{
 
33
  double  ns_get_tstat(void), ns_get_lstat(void);
 
34
  char    buf[BUFSIZ], *ns_get_nfthresh_s(void);
 
35
  W_Color color;
 
36
 
 
37
  switch (i)
 
38
    {
 
39
 
 
40
    case NETSTAT_SWITCH:
 
41
      sprintf(buf, "%sollect network stats",
 
42
              netstat ? "C" : "Don't c");
 
43
      color = textColor;
 
44
      break;
 
45
    case NETSTAT_RESET:
 
46
      sprintf(buf, "Reset network stats");
 
47
      color = textColor;
 
48
      break;
 
49
    case NETSTAT_TOTAL:
 
50
      sprintf(buf, "Total              : %4.2f", ns_get_tstat());
 
51
      color = yColor;
 
52
      break;
 
53
    case NETSTAT_LOCAL:
 
54
      sprintf(buf, "This ship          : %4.2f", ns_get_lstat());
 
55
      color = yColor;
 
56
      break;
 
57
    case NETSTAT_FAILURES:
 
58
      sprintf(buf, "Network failures   : %d", ns_get_nfailures());
 
59
      color = yColor;
 
60
      break;
 
61
    case NETSTAT_NFTHRESH:
 
62
      sprintf(buf, "Network failure threshold: %s_", ns_get_nfthresh_s());
 
63
      color = textColor;
 
64
      break;
 
65
    case NETSTAT_DONE:
 
66
      sprintf(buf, "Done");
 
67
      color = textColor;
 
68
      break;
 
69
    }
 
70
  W_WriteText(netstatWin, 0, i, color, buf, strlen(buf), 0);
 
71
}
 
72
 
 
73
void    nsaction(W_Event * data)
 
74
{
 
75
  char   *ns_get_nfthresh_s(void);
 
76
  int     v;
 
77
  register int i;
 
78
  register char *cp;
 
79
 
 
80
  switch (data->y)
 
81
    {
 
82
 
 
83
    case NETSTAT_SWITCH:
 
84
      if (data->type == W_EV_BUTTON)
 
85
        {
 
86
          if (netstat)
 
87
            {
 
88
              netstat = 0;
 
89
              W_UnmapWindow(lMeter);
 
90
            }
 
91
          else
 
92
            {
 
93
              netstat = 1;
 
94
              ns_init(5);
 
95
            }
 
96
        }
 
97
      nsrefresh(NETSTAT_SWITCH);
 
98
      break;
 
99
 
 
100
    case NETSTAT_RESET:
 
101
      if (data->type == W_EV_BUTTON)
 
102
        {
 
103
          ns_init(0);
 
104
          nsrefresh(NETSTAT_TOTAL);
 
105
          nsrefresh(NETSTAT_LOCAL);
 
106
          nsrefresh(NETSTAT_FAILURES);
 
107
        }
 
108
      break;
 
109
 
 
110
    case NETSTAT_NFTHRESH:
 
111
      if (data->type == W_EV_KEY)
 
112
        {
 
113
          switch (data->key)
 
114
            {
 
115
            case '\b':
 
116
            case '\177':
 
117
              cp = ns_get_nfthresh_s();
 
118
              i = strlen(cp);
 
119
              if (i > 0)
 
120
                {
 
121
                  cp += i - 1;
 
122
                  *cp = '\0';
 
123
                }
 
124
              break;
 
125
            case '\025':
 
126
            case '\030':
 
127
              ns_set_nfthresh_s("");
 
128
              break;
 
129
 
 
130
            default:
 
131
              if (data->key >= '0' && data->key <= '9')
 
132
                {
 
133
                  cp = ns_get_nfthresh_s();
 
134
                  i = strlen(cp);
 
135
                  if (i < 4)
 
136
                    {
 
137
                      cp += i;
 
138
                      cp[1] = '\0';
 
139
                      cp[0] = data->key;
 
140
                    }
 
141
                }
 
142
              break;
 
143
            }
 
144
          nsrefresh(NETSTAT_NFTHRESH);
 
145
        }
 
146
      break;
 
147
 
 
148
 
 
149
 
 
150
    case NETSTAT_DONE:
 
151
      if (data->type == W_EV_BUTTON)
 
152
        {
 
153
          if (sscanf(ns_get_nfthresh_s(), "%d", &v) != 1)
 
154
            {
 
155
              ns_set_nfthresh_s(NETSTAT_DF_NFT_S);
 
156
              ns_set_nfthresh(NETSTAT_DF_NFT);
 
157
            }
 
158
          else
 
159
            ns_set_nfthresh(v);
 
160
 
 
161
          nsdone();
 
162
        }
 
163
      break;
 
164
    }
 
165
}
 
166
 
 
167
nsdone(void)
 
168
{
 
169
  /* Unmap window */
 
170
  W_UnmapWindow(netstatWin);
 
171
}