forked from uboborov/EFM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathefm_c.h
295 lines (245 loc) · 7.69 KB
/
efm_c.h
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
Copyright 2008-2009 Yury Bobrov
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef EFM_H_
#define EFM_H_
void com_wr_str(const char *str);
void com_wr_data(char *data, int len);
void com_wr_char(char c);
int com_get_char();
typedef int (*win_callback_t)(void *arg);
#define BUTTON 2
#define EDIT 3
#define BTN_LEFT 0x01
#define BTN_RIGHT 0x02
#define BTN_UP 0x03
#define BTN_DOWN 0x04
#define BTN_DEL 0x7F
#define BTN_BACKSPACE 0x08
#define BTN_TAB 0x09
#define BTN_ESC 0x1B
#define BTN_CTRL_N 0x0E
#define BTN_CTRL_Q 0x11
#define BTN_CTRL_W 0x17
#define BTN_F1 0x05
#define BTN_F2 0x06
#define BTN_F3 0x07
#define DIR_UP BTN_UP
#define DIR_DOWN BTN_DOWN
#define DIR_LEFT BTN_LEFT
#define DIR_RIGHT BTN_RIGHT
#define VT_INC(X) ((X) + 1)
#define VT_DEC(X) ((X) - 1)
//#define NET_IO
//#define PC_IO
//#define CONFIG_EMBEDDED
#if defined(CONFIG_EMBEDDED)
#define EFM_GRAPHIS_MODE 1
#define EFM_DIR_SLASH_C '\\'
#define EFM_DIR_SLASH_S "\\"
#define BTN_ENTER 0x0D
#define BTN_F4 0x0A
// input/output functions
#define wr_str net_wr_str
#define wr_data net_wr_data
#define wr_char net_wr_char
#define rd_char net_get_char
// memory management functions
#define efm_malloc safe_malloc
#define efm_free safe_free
// console dependent functions
#define set_cursor_pos vt_set_cursor_pos
#define clear_screen vt_clear_screen
#define clear_line vt_clear_line
#define set_mode vt_set_mode
// FS dependent functions
#define fs_dir FS_DIR
#define fs_dirent struct FS_DIRENT
#define fs_dname DirName
#define fs_fflag Attributes
#define FS_ATTR_DIR FS_ATTR_DIRECTORY
#define fs_opendir(p) FS_OpenDir(p)
#define fs_fremove(p) FS_Remove(p)
#define fs_rmdir(p) FS_RmDir(p)
#define fs_mkdir(p) FS_MkDir(p)
#define fs_readdir(dp) FS_ReadDir(dp)
#define fs_closedir(dp) FS_CloseDir(dp);
#define fs_file FS_FILE
#define fs_fopen(p,o) FS_FOpen(p,o)
#define fs_fclose(pf) FS_FClose(pf)
#define fs_fread(pb,s,n,pf) FS_FRead(pb,s,n,pf)
#define fs_fwrite(pb,s,n,pf) FS_FWrite(pb,s,n,pf)
#elif defined(PC_IO)
#define EFM_GRAPHIS_MODE 1
#define EFM_DIR_SLASH_C '\\'
#define EFM_DIR_SLASH_S "\\"
#define BTN_ENTER 0x0D
#define BTN_F4 0x0A
// input/output functions
#define wr_str com_wr_str
#define wr_data com_wr_data
#define wr_char com_wr_char
#define rd_char com_get_char
// memory management functions
#define efm_malloc malloc
#define efm_free free
// console dependent functions
#define set_cursor_pos vt_set_cursor_pos
#define clear_screen vt_clear_screen
#define clear_line vt_clear_line
#define set_mode vt_set_mode
// FS dependent functions
#define fs_dir DIR
#define fs_dirent struct dirent
#define fs_dname d_name
#define fs_fflag
#define FS_ATTR_DIR DT_DIR
#define fs_opendir(p) opendir(p)
#define fs_fremove(p) remove(p)
#define fs_rmdir(p) unlink(p)
#define fs_mkdir(p) mkdir(p)
#define fs_readdir(dp) readdir(dp)
#define fs_closedir(dp) closedir(dp);
#define fs_file FILE
#define fs_fopen(p,o) fopen(p,o)
#define fs_fclose(pf) fclose(pf)
#define fs_fread(pb,s,n,pf) fread(pb,s,n,pf)
#define fs_fwrite(pb,s,n,pf) fwrite(pb,s,n,pf)
#else
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "term.h"
#define EFM_GRAPHIS_MODE 0
#define EFM_DIR_SLASH_C '/'
#define EFM_DIR_SLASH_S "/"
#define BTN_ENTER 0x0A
#define BTN_F4 0x0B
// Embedded Linux
// input/output functions
#define wr_str com_wr_str
#define wr_data com_wr_data
#define wr_char com_wr_char
#define rd_char com_get_char
// memory management functions
#define efm_malloc malloc
#define efm_free free
// console dependent functions
#define set_cursor_pos vt_set_cursor_pos
#define clear_screen vt_clear_screen
#define clear_line vt_clear_line
#define set_mode vt_set_mode
// FS dependent functions
#define fs_dir DIR
#define fs_dirent struct dirent
#define fs_dname d_name
#define fs_fflag
#define FS_ATTR_DIR DT_DIR
#define fs_opendir(p) opendir(p)
#define fs_fremove(p) remove(p)
#define fs_rmdir(p) rmdir(p)
#define fs_mkdir(p) mkdir(p, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
#define fs_readdir(dp) readdir(dp)
#define fs_closedir(dp) closedir(dp);
#define fs_file FILE
#define fs_fopen(p,o) fopen(p,o)
#define fs_fclose(pf) fclose(pf)
#define fs_fread(pb,s,n,pf) fread(pb,s,n,pf)
#define fs_fwrite(pb,s,n,pf) fwrite(pb,s,n,pf)
#endif
typedef struct _panel_t {
struct _panel_t *next;
unsigned int num_col;
unsigned int num_row;
unsigned int cur_col;
unsigned int cur_row;
unsigned int panel_offset;
unsigned int pn;
unsigned int num_items;
char cur_path[128];
} panel_t;
typedef struct window {
// window h & h
unsigned int height;
unsigned int width;
// cols & rows
unsigned int num_col;
unsigned int num_row;
unsigned int cur_col;
unsigned int cur_row;
// start coord
unsigned int s_x;
unsigned int s_y;
// screen offset
unsigned int cur_pos_x;
unsigned int cur_pos_y;
// panels
panel_t panel[2];
unsigned int num_panel;
unsigned int active_panel;
// element
void *element[10];
unsigned int nelement;
// handler
int (*win_handler)(void *arg);
// caption
char *text;
// screen buffer
char *screen;
//
char *backup_region;
//
struct window *parent;
} window_t;
typedef struct _element_t {
unsigned int element_type;
unsigned int active;
void *pelement;
struct _element_t *next;
} element_t;
typedef struct _button_t {
unsigned int id;
unsigned int x;
unsigned int y;
unsigned int w;
unsigned int h;
char *caption;
unsigned int c_x;
unsigned int c_y;
unsigned int active;
struct _button_t *next;
win_callback_t button_func;
} button_t;
typedef struct _edit_t {
unsigned int id;
unsigned int x;
unsigned int y;
unsigned int w;
unsigned int h;
unsigned int cur_pos_x;
unsigned int cur_pos_y;
unsigned int len;
unsigned int active;
char *buf;
char *caption;
struct _edit_t *next;
win_callback_t edit_func;
} edit_t;
typedef struct {
window_t *win;
unsigned int ch;
void *in;
void *out;
unsigned int opcode;
} el_msg_t;
void run_efm();
void set_term_colsize(unsigned int colsize);
#endif /*EFM_H_*/