File: netstatopt.c

package info (click to toggle)
netrek-client-cow 3.3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,552 kB
  • sloc: ansic: 43,108; sh: 2,871; python: 380; makefile: 112; sed: 16
file content (166 lines) | stat: -rw-r--r-- 3,056 bytes parent folder | download | duplicates (5)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "config.h"
#include "copyright.h"

#include <stdio.h>
#include <ctype.h>
#include "Wlib.h"
#include "defs.h"
#include "struct.h"
#include "data.h"
#include "packets.h"
#include "netstat.h"
#include "netstatopt.h"

void nswindow(void)
{
  register int i;

  for (i = 0; i < NETSTAT_NUMFIELDS; i++)
    nsrefresh(i);

  /* Map window */
  W_MapWindow(netstatWin);
}

/* Refresh item i */
void nsrefresh(int i)
{
  double  ns_get_tstat(void), ns_get_lstat(void);
  char    buf[BUFSIZ], *ns_get_nfthresh_s(void);
  W_Color color;

  switch (i)
    {

    case NETSTAT_SWITCH:
      sprintf(buf, "%sollect network stats",
	      netstat ? "C" : "Don't c");
      color = textColor;
      break;
    case NETSTAT_RESET:
      sprintf(buf, "Reset network stats");
      color = textColor;
      break;
    case NETSTAT_TOTAL:
      sprintf(buf, "Total              : %4.2f", ns_get_tstat());
      color = yColor;
      break;
    case NETSTAT_LOCAL:
      sprintf(buf, "This ship          : %4.2f", ns_get_lstat());
      color = yColor;
      break;
    case NETSTAT_FAILURES:
      sprintf(buf, "Network failures   : %d", ns_get_nfailures());
      color = yColor;
      break;
    case NETSTAT_NFTHRESH:
      sprintf(buf, "Network failure threshold: %s_", ns_get_nfthresh_s());
      color = textColor;
      break;
    case NETSTAT_DONE:
      sprintf(buf, "Done");
      color = textColor;
      break;
    }
  W_WriteText(netstatWin, 0, i, color, buf, strlen(buf), 0);
}

void    nsaction(W_Event * data)
{
  char   *ns_get_nfthresh_s(void);
  int     v;
  register int i;
  register char *cp;

  switch (data->y)
    {

    case NETSTAT_SWITCH:
      if (data->type == W_EV_BUTTON)
	{
	  if (netstat)
	    {
	      netstat = 0;
	      W_UnmapWindow(lMeter);
	    }
	  else
	    {
	      netstat = 1;
	      ns_init(5);
	    }
	}
      nsrefresh(NETSTAT_SWITCH);
      break;

    case NETSTAT_RESET:
      if (data->type == W_EV_BUTTON)
	{
	  ns_init(0);
	  nsrefresh(NETSTAT_TOTAL);
	  nsrefresh(NETSTAT_LOCAL);
	  nsrefresh(NETSTAT_FAILURES);
	}
      break;

    case NETSTAT_NFTHRESH:
      if (data->type == W_EV_KEY)
	{
	  switch (data->key)
	    {
	    case '\b':
	    case '\177':
	      cp = ns_get_nfthresh_s();
	      i = strlen(cp);
	      if (i > 0)
		{
		  cp += i - 1;
		  *cp = '\0';
		}
	      break;
	    case '\025':
	    case '\030':
	      ns_set_nfthresh_s("");
	      break;

	    default:
	      if (data->key >= '0' && data->key <= '9')
		{
		  cp = ns_get_nfthresh_s();
		  i = strlen(cp);
		  if (i < 4)
		    {
		      cp += i;
		      cp[1] = '\0';
		      cp[0] = data->key;
		    }
		}
	      break;
	    }
	  nsrefresh(NETSTAT_NFTHRESH);
	}
      break;



    case NETSTAT_DONE:
      if (data->type == W_EV_BUTTON)
	{
	  if (sscanf(ns_get_nfthresh_s(), "%d", &v) != 1)
	    {
	      ns_set_nfthresh_s(NETSTAT_DF_NFT_S);
	      ns_set_nfthresh(NETSTAT_DF_NFT);
	    }
	  else
	    ns_set_nfthresh(v);

	  nsdone();
	}
      break;
    }
}

void nsdone(void)
{
  /* Unmap window */
  W_UnmapWindow(netstatWin);
}