xref: /openbsd/usr.bin/systat/engine.h (revision 07a32fc5)
1 /* $OpenBSD: engine.h,v 1.14 2021/07/02 15:34:16 millert Exp $	 */
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 	const 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;
95 	void ( *exec)(const char *);
96 };
97 
98 enum message_mode {
99 	MESSAGE_NONE,
100 	MESSAGE_HELP,
101 	MESSAGE_VIEW,
102 	MESSAGE_ORDER
103 };
104 
105 void tb_start(void);
106 
107 void tb_end(void);
108 
109 int tbprintf(char *format, ...) GCC_PRINTFLIKE(1,2);
110 int tbprintft(char *format, ...) GCC_PRINTFLIKE(1,2);
111 
112 void end_line(void);
113 void end_page(void);
114 
115 void print_fld_str(field_def *, const char *);
116 void print_fld_age(field_def *, unsigned int);
117 void print_fld_sdiv(field_def *, u_int64_t, int);
118 void print_fld_size(field_def *, u_int64_t);
119 void print_fld_ssdiv(field_def *, int64_t, int);
120 void print_fld_ssize(field_def *, int64_t);
121 void print_fld_bw(field_def *, double);
122 void print_fld_rate(field_def *, double);
123 void print_fld_uint(field_def *, unsigned int);
124 void print_fld_float(field_def *, double, int);
125 void print_fld_bar(field_def *, int);
126 void print_fld_tb(field_def *);
127 
128 void print_title(void);
129 
130 void hide_field(field_def *fld);
131 void show_field(field_def *fld);
132 void field_setup(void);
133 
134 void add_view(field_view *fv);
135 int set_view(const char *opt);
136 void next_view(void);
137 void prev_view(void);
138 
139 int foreach_order(void (*callback)(order_type *));
140 void set_order(const char *opt);
141 void next_order(void);
142 void show_help(void);
143 void show_view(void);
144 void show_order(void);
145 
146 void setup_term(int maxpr);
147 int check_termcap(void);
148 void refresh_delay(double delay);
149 
150 void engine_initialize(void);
151 void engine_loop(int countmax);
152 
153 struct command *command_set(struct command *cmd, const char *init);
154 void message_toggle(enum message_mode);
155 const char *message_set(const char *msg);
156 
157 void foreach_view(void (*callback)(field_view *));
158 
159 extern int sortdir;
160 extern int dispstart;
161 extern int humanreadable;
162 extern int interactive;
163 extern int averageonly;
164 extern int maxprint;
165 extern int paused;
166 extern int rawmode;
167 extern int rawwidth;
168 extern int columns, lines;
169 
170 extern int need_update;
171 extern int need_sort;
172 extern int separate_thousands;
173 
174 extern volatile sig_atomic_t gotsig_close;
175 extern volatile sig_atomic_t gotsig_resize;
176 extern volatile sig_atomic_t gotsig_alarm;
177 
178 extern field_view *curr_view;
179 extern struct view_manager *curr_mgr;
180 
181 extern char tmp_buf[MAX_LINE_BUF];
182 
183 extern int curr_line; /* XXX temp */
184 extern u_int32_t num_disp;
185 #endif
186