Deleted Added
full compact
commands.c (265251) commands.c (300395)
1/*
2 * Top users/processes display for Unix
3 * Version 3
4 *
5 * This program may be freely redistributed,
6 * but this entire comment MUST remain intact.
7 *
8 * Copyright (c) 1984, 1989, William LeFebvre, Rice University
9 * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
10 *
1/*
2 * Top users/processes display for Unix
3 * Version 3
4 *
5 * This program may be freely redistributed,
6 * but this entire comment MUST remain intact.
7 *
8 * Copyright (c) 1984, 1989, William LeFebvre, Rice University
9 * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
10 *
11 * $FreeBSD: head/contrib/top/commands.c 265251 2014-05-02 23:47:14Z bdrewery $
11 * $FreeBSD: head/contrib/top/commands.c 300395 2016-05-22 04:17:00Z ngie $
12 */
13
14/*
15 * This file contains the routines that implement some of the interactive
16 * mode commands. Note that some of the commands are implemented in-line
17 * in "main". This is necessary because they change the global state of
18 * "top" (i.e.: changing the number of processes to display).
19 */
20
21#include "os.h"
12 */
13
14/*
15 * This file contains the routines that implement some of the interactive
16 * mode commands. Note that some of the commands are implemented in-line
17 * in "main". This is necessary because they change the global state of
18 * "top" (i.e.: changing the number of processes to display).
19 */
20
21#include "os.h"
22#include <ctype.h>
23#include <signal.h>
24#include <errno.h>
22
25#include <sys/time.h>
26#include <sys/resource.h>
27
23#include <sys/time.h>
24#include <sys/resource.h>
25
26#include <ctype.h>
27#include <errno.h>
28#include <signal.h>
29#include <unistd.h>
30
31#include "commands.h"
28#include "sigdesc.h" /* generated automatically */
29#include "top.h"
30#include "boolean.h"
31#include "utils.h"
32#include "sigdesc.h" /* generated automatically */
33#include "top.h"
34#include "boolean.h"
35#include "utils.h"
36#include "machine.h"
32
33extern int errno;
34
35extern char *copyright;
36
37/* imported from screen.c */
38extern int overstrike;
39
40int err_compar();
41char *err_string();
37
38extern int errno;
39
40extern char *copyright;
41
42/* imported from screen.c */
43extern int overstrike;
44
45int err_compar();
46char *err_string();
47static int str_adderr(char *str, int len, int err);
48static int str_addarg(char *str, int len, char *arg, int first);
42
43/*
44 * show_help() - display the help screen; invoked in response to
45 * either 'h' or '?'.
46 */
47
49
50/*
51 * show_help() - display the help screen; invoked in response to
52 * either 'h' or '?'.
53 */
54
55void
48show_help()
49
50{
51 printf("Top version %s, %s\n", version_string(), copyright);
52 fputs("\n\n\
53A top users display for Unix\n\
54\n\
55These single-character commands are available:\n\

--- 62 unchanged lines hidden (view full) ---

118 *str = '\0';
119 while (*++str == ' ') /* loop */;
120
121 /* if there is nothing left of the string, return NULL */
122 /* This fix is dedicated to Greg Earle */
123 return(*str == '\0' ? NULL : str);
124}
125
56show_help()
57
58{
59 printf("Top version %s, %s\n", version_string(), copyright);
60 fputs("\n\n\
61A top users display for Unix\n\
62\n\
63These single-character commands are available:\n\

--- 62 unchanged lines hidden (view full) ---

126 *str = '\0';
127 while (*++str == ' ') /* loop */;
128
129 /* if there is nothing left of the string, return NULL */
130 /* This fix is dedicated to Greg Earle */
131 return(*str == '\0' ? NULL : str);
132}
133
134int
126scanint(str, intp)
127
128char *str;
129int *intp;
130
131{
132 register int val = 0;
133 register char ch;

--- 123 unchanged lines hidden (view full) ---

257 return(stringlen == 0 ? err_listem : string);
258}
259
260/*
261 * str_adderr(str, len, err) - add an explanation of error "err" to
262 * the string "str".
263 */
264
135scanint(str, intp)
136
137char *str;
138int *intp;
139
140{
141 register int val = 0;
142 register char ch;

--- 123 unchanged lines hidden (view full) ---

266 return(stringlen == 0 ? err_listem : string);
267}
268
269/*
270 * str_adderr(str, len, err) - add an explanation of error "err" to
271 * the string "str".
272 */
273
274static int
265str_adderr(str, len, err)
266
267char *str;
268int len;
269int err;
270
271{
272 register char *msg;

--- 11 unchanged lines hidden (view full) ---

284}
285
286/*
287 * str_addarg(str, len, arg, first) - add the string argument "arg" to
288 * the string "str". This is the first in the group when "first"
289 * is set (indicating that a comma should NOT be added to the front).
290 */
291
275str_adderr(str, len, err)
276
277char *str;
278int len;
279int err;
280
281{
282 register char *msg;

--- 11 unchanged lines hidden (view full) ---

294}
295
296/*
297 * str_addarg(str, len, arg, first) - add the string argument "arg" to
298 * the string "str". This is the first in the group when "first"
299 * is set (indicating that a comma should NOT be added to the front).
300 */
301
302static int
292str_addarg(str, len, arg, first)
293
294char *str;
295int len;
296char *arg;
297int first;
298
299{

--- 16 unchanged lines hidden (view full) ---

316 return(len - arglen);
317}
318
319/*
320 * err_compar(p1, p2) - comparison routine used by "qsort"
321 * for sorting errors.
322 */
323
303str_addarg(str, len, arg, first)
304
305char *str;
306int len;
307char *arg;
308int first;
309
310{

--- 16 unchanged lines hidden (view full) ---

327 return(len - arglen);
328}
329
330/*
331 * err_compar(p1, p2) - comparison routine used by "qsort"
332 * for sorting errors.
333 */
334
335int
324err_compar(p1, p2)
325
326register struct errs *p1, *p2;
327
328{
329 register int result;
330
331 if ((result = p1->errnum - p2->errnum) == 0)
332 {
333 return(strcmp(p1->arg, p2->arg));
334 }
335 return(result);
336}
337
338/*
339 * error_count() - return the number of errors currently logged.
340 */
341
336err_compar(p1, p2)
337
338register struct errs *p1, *p2;
339
340{
341 register int result;
342
343 if ((result = p1->errnum - p2->errnum) == 0)
344 {
345 return(strcmp(p1->arg, p2->arg));
346 }
347 return(result);
348}
349
350/*
351 * error_count() - return the number of errors currently logged.
352 */
353
354int
342error_count()
343
344{
345 return(errcnt);
346}
347
348/*
349 * show_errors() - display on stdout the current log of errors.
350 */
351
355error_count()
356
357{
358 return(errcnt);
359}
360
361/*
362 * show_errors() - display on stdout the current log of errors.
363 */
364
365void
352show_errors()
353
354{
355 register int cnt = 0;
356 register struct errs *errp = errs;
357
358 printf("%d error%s:\n\n", errcnt, errcnt == 1 ? "" : "s");
359 while (cnt++ < errcnt)

--- 168 unchanged lines hidden ---
366show_errors()
367
368{
369 register int cnt = 0;
370 register struct errs *errp = errs;
371
372 printf("%d error%s:\n\n", errcnt, errcnt == 1 ? "" : "s");
373 while (cnt++ < errcnt)

--- 168 unchanged lines hidden ---