Annotation of src/usr.bin/systat/engine.h, Revision 1.7
1.7 ! mpf 1: /* $Id: engine.h,v 1.6 2010/07/16 05:22:48 lum Exp $ */
1.1 canacar 2: /*
3: * Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
17:
18: #ifndef _ENGINE_H_
19: #define _ENGINE_H_
20:
21: #include <curses.h>
22:
23: #define DEFAULT_WIDTH 80
24: #define DEFAULT_HEIGHT 25
25:
26: /* XXX do not hardcode! */
27: #define HEADER_LINES 4
28:
29:
30: #define CTRL_A 1
31: #define CTRL_B 2
32: #define CTRL_E 5
33: #define CTRL_F 6
34: #define CTRL_G 7
35: #define CTRL_H 8
36: #define CTRL_L 12
37: #define CTRL_N 14
38: #define CTRL_P 16
39: #define CTRL_V 22
40:
41: #define META_V 246
42:
43: #define MAX_LINE_BUF 1024
44:
45:
46: #define FLD_ALIGN_LEFT 0
47: #define FLD_ALIGN_RIGHT 1
48: #define FLD_ALIGN_CENTER 2
49: #define FLD_ALIGN_COLUMN 3
50: #define FLD_ALIGN_BAR 4
51:
52: #define FLD_FLAG_HIDDEN 1
53:
54:
55: typedef struct {
56: char *title;
57: int norm_width;
58: int max_width;
59: int increment;
60: int align;
61: int start;
62: int width;
63: unsigned flags;
64: int arg;
65: } field_def;
66:
67: typedef struct {
68: char *name;
69: char *match;
70: int hotkey;
71: int (*func) (const void *, const void *);
72: } order_type;
73:
74: struct view_manager {
75: char *name;
76: int (*select_fn) (void);
77: int (*read_fn) (void);
78: void (*sort_fn) (void);
79: int (*header_fn) (void);
80: void (*print_fn) (void);
81: int (*key_fn) (int);
82: order_type *order_list;
83: order_type *order_curr;
84: };
85:
86: typedef struct {
87: field_def **view;
88: char *name;
89: int hotkey;
90: struct view_manager *mgr;
91: } field_view;
92:
93: struct command {
94: char *prompt;
1.3 canacar 95: void ( *exec)(const char *);
1.1 canacar 96: };
97:
98:
99: void tb_start(void);
100:
101: void tb_end(void);
102:
103: int tbprintf(char *format, ...) GCC_PRINTFLIKE(1,2);
1.7 ! mpf 104: int tbprintft(char *format, ...) GCC_PRINTFLIKE(1,2);
1.1 canacar 105:
106: void end_line(void);
107: void end_page(void);
108:
1.5 canacar 109: void print_fld_str(field_def *, const char *);
110: void print_fld_age(field_def *, unsigned int);
111: void print_fld_sdiv(field_def *, u_int64_t, int);
112: void print_fld_size(field_def *, u_int64_t);
113: void print_fld_ssdiv(field_def *, int64_t, int);
114: void print_fld_ssize(field_def *, int64_t);
115: void print_fld_bw(field_def *, double);
116: void print_fld_rate(field_def *, double);
117: void print_fld_uint(field_def *, unsigned int);
118: void print_fld_float(field_def *, double, int);
119: void print_fld_bar(field_def *, int);
120: void print_fld_tb(field_def *);
1.1 canacar 121:
122: void print_title(void);
123:
124: void hide_field(field_def *fld);
125: void show_field(field_def *fld);
126: void field_setup(void);
127:
128: void add_view(field_view *fv);
1.3 canacar 129: int set_view(const char *opt);
1.1 canacar 130: void next_view(void);
131: void prev_view(void);
132:
1.3 canacar 133: void set_order(const char *opt);
1.1 canacar 134: void next_order(void);
135:
136: void setup_term(int maxpr);
1.6 lum 137: int check_termcap(void);
1.1 canacar 138:
139: void engine_initialize(void);
140: void engine_loop(int countmax);
141:
142: struct command *command_set(struct command *cmd, const char *init);
143: const char *message_set(const char *msg);
144:
145: void foreach_view(void (*callback)(field_view *));
146:
147: extern int sortdir;
148: extern useconds_t udelay;
149: extern int dispstart;
150: extern int interactive;
151: extern int maxprint;
152: extern int paused;
153: extern int rawmode;
154: extern int rawwidth;
155: extern int columns, lines;
156:
157: extern int need_update;
158: extern int need_sort;
1.7 ! mpf 159: extern int separate_thousands;
1.1 canacar 160:
161: extern volatile sig_atomic_t gotsig_close;
162: extern volatile sig_atomic_t gotsig_resize;
163: extern volatile sig_atomic_t gotsig_alarm;
164:
165: extern field_view *curr_view;
166: extern struct view_manager *curr_mgr;
167:
168: extern char tmp_buf[MAX_LINE_BUF];
169:
170: extern int curr_line; /* XXX temp */
171: extern u_int32_t num_disp;
172: #endif