1 /* $Id: engine.h,v 1.5 2008/12/07 02:56:06 canacar 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 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 99 void tb_start(void); 100 101 void tb_end(void); 102 103 int tbprintf(char *format, ...) GCC_PRINTFLIKE(1,2); 104 105 void end_line(void); 106 void end_page(void); 107 108 void print_fld_str(field_def *, const char *); 109 void print_fld_age(field_def *, unsigned int); 110 void print_fld_sdiv(field_def *, u_int64_t, int); 111 void print_fld_size(field_def *, u_int64_t); 112 void print_fld_ssdiv(field_def *, int64_t, int); 113 void print_fld_ssize(field_def *, int64_t); 114 void print_fld_bw(field_def *, double); 115 void print_fld_rate(field_def *, double); 116 void print_fld_uint(field_def *, unsigned int); 117 void print_fld_float(field_def *, double, int); 118 void print_fld_bar(field_def *, int); 119 void print_fld_tb(field_def *); 120 121 void print_title(void); 122 123 void hide_field(field_def *fld); 124 void show_field(field_def *fld); 125 void field_setup(void); 126 127 void add_view(field_view *fv); 128 int set_view(const char *opt); 129 void next_view(void); 130 void prev_view(void); 131 132 void set_order(const char *opt); 133 void next_order(void); 134 135 void setup_term(int maxpr); 136 137 void engine_initialize(void); 138 void engine_loop(int countmax); 139 140 struct command *command_set(struct command *cmd, const char *init); 141 const char *message_set(const char *msg); 142 143 void foreach_view(void (*callback)(field_view *)); 144 145 extern int sortdir; 146 extern useconds_t udelay; 147 extern int dispstart; 148 extern int interactive; 149 extern int maxprint; 150 extern int paused; 151 extern int rawmode; 152 extern int rawwidth; 153 extern int columns, lines; 154 155 extern int need_update; 156 extern int need_sort; 157 158 extern volatile sig_atomic_t gotsig_close; 159 extern volatile sig_atomic_t gotsig_resize; 160 extern volatile sig_atomic_t gotsig_alarm; 161 162 extern field_view *curr_view; 163 extern struct view_manager *curr_mgr; 164 165 extern char tmp_buf[MAX_LINE_BUF]; 166 167 extern int curr_line; /* XXX temp */ 168 extern u_int32_t num_disp; 169 #endif 170