File: aca.h

package info (click to toggle)
aca 0.1.6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 492 kB
  • ctags: 569
  • sloc: ansic: 4,254; sh: 2,237; makefile: 256
file content (379 lines) | stat: -rw-r--r-- 12,410 bytes parent folder | download | duplicates (2)
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379

/*
 *  Copyright (c) 1998 - 1999, 2001 Karel Zak "Zakkr" <zakkr@zf.jcu.cz>
 *
 *  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.
 *
 *  $Id: aca.h,v 1.2 2001/01/02 14:16:15 zakkr Exp $
 */

#ifndef __ACA_H
#define __ACA_H

/* ------------------------------------------------------------------------ */

#include <curses.h>

#if !(defined(TRUE) && defined(FALSE))
	#define TRUE	1
	#define FALSE	0
#endif	

#define	RE_ERROR	-1
#define RE_OK		0

#define chN		((char *) 	NULL)
#define inN		((int  *) 	NULL)
#define voN		((void *) 	NULL)

#include <libintl.h>

extern 	char		*_aca_text_domain;

/*
 * If you use complete built-in widgets, mark widget.text_domain as
 * ACA_TD.
 */
#define	ACA_TD		(_aca_text_domain)



   typedef struct {
      int	color,			/* TRUE / FALSE */
      		output_7bit_only, 	/* if TRUE: ACA support only 7bit ascii */
      		input_8bit,		/* if FALSE: ACA set curses meta() */
      
      /* aca timer (all is in milliseconds) */
      		getch_timeout, 		/* select() timeval or curses timeout */
      		fallasleep,		/* elapsed time to go to asleep */
      		fallasleep_incr,	/* fall asleep deepen and deepen 
      					   (this is increment of deep) */
      
      /* after timeout elpse ACA call your func. (if this func. is set) */					   
      		extra_timeout_call; 			/* TRUE / FALSE */
      void	(*extra_timeout_call_fn)(int x);	
      
      /* your func. - ACA call this func. if screen is resized */
      int	extra_resize;				/* TRUE / FALSE */	
      void	(*extra_resize_call_fn)(void *data),
   		*extra_resize_data; 
      
      int	line,			/* TRUE (usage standard line) or FALSE ( '-' '|' '+')  */		
      		keypad,			/* TRUE / FALSE - usage termcap/curses */	
      		spec,			/* TRUE / FALSE - special characters (as a arrow) */
      		forcekey;	
   
   #ifdef HAVE_MOUSE
     int	mouse,			/* TRUE / FALSE	*/	
   		mouse_y,		/* mouse line */
   		mouse_x;		/* mouse col */
     #endif
   	   	
   } ACA;

   extern ACA	aca;

#if DEBUG==1
	#define	_D(x)	fprintf(stderr, "DEBUG: %s\n", x)
#else
	#define	_D(x)
#endif

   extern void print_aca_setting(FILE *f);

/* ------------------------------------------------------------------------ */

/* --- color part --- */

   typedef struct {
      int	color,		/* color number 	*/
	      	fc,		/* foreground color 	*/
	      	bc,		/* background color 	*/
      		bw;		/* black / white	*/
   } aca_COLORS;

   typedef struct {
      int	sel,		/* selected area 			*/
      		nsel,		/* not selected area 			*/
      		sel_astr,	/* selected ACTIVE STRING 		*/
      		nsel_astr,	/* not selected ACTIVE STRING 		*/
      		border_sel,	/* selected border			*/
      		border_nsel,	/* not selected border 			*/
      		title_sel,	/* selected title 			*/
      		title_nsel,	/* not selected title 			*/
      		title_sel_astr, /* selected ACTIVE STRING in title	*/
      		title_nsel_astr,/* not selected ACTIVE STRING in title	*/
		descript;	/* description line(s) color 		*/
   } WidgetColor;

   typedef struct {
   /* dialogs colors */
      int		dlg_bgr,
      			dlg_header,
      			dlg_warning;
      
      /* widgets color */
      WidgetColor	button,		/* color for Wbutton	*/
      			radio,		/* color for Wradio	*/
      			input,		/* color for Winput	*/
      
      	/* color for Wmenu (in any dialogs - see menu flag M_MENUIN) */
      			menu_in,	
      
      	/* color for Wmenu (see menu flag M_MENUOUT) */
      			menu_out,
      
      	/* color for Wmenu (see menu flag M_MENUDIRECT) */
      			menu_direct;
   } TemplateColor;

   extern aca_COLORS 	*GL_c;
   extern TemplateColor	*TplC;

   extern int		aca_init_color(int num);
   extern void		aca_init_pair(int color_num, int fc, int bc, int bw);
   extern TemplateColor *set_TplC( TemplateColor *t);

   inline extern 	void aca_c(int x);

#define aca_uc(x)	attroff ((aca.color ? (*(GL_c+x)).color : (*(GL_c+x)).bw))
#define bold		attron(A_BOLD)
#define ubold		attroff(A_BOLD) 
#define blink		attron(A_BLINK)	  	
#define ublink		attroff(A_BLINK)

#define	ACA_HLINE	(aca.line ? ACS_HLINE 		: '-')  
#define	ACA_VLINE	(aca.line ? ACS_VLINE 		: '|')
#define	ACA_ULCORNER	(aca.line ? ACS_ULCORNER 	: '+')
#define	ACA_URCORNER	(aca.line ? ACS_URCORNER 	: '+')
#define	ACA_LLCORNER	(aca.line ? ACS_LLCORNER 	: '+')
#define	ACA_LRCORNER	(aca.line ? ACS_LRCORNER 	: '+')
#define	ACA_TTEE	(aca.line ? ACS_TTEE 		: '+')
#define	ACA_BTEE	(aca.line ? ACS_BTEE 		: '+')
#define	ACA_LTEE	(aca.line ? ACS_LTEE 		: '+')
#define	ACA_RTEE	(aca.line ? ACS_RTEE 		: '+')
#define	ACA_DARROW	((aca.line && aca.spec) ? ACS_DARROW 	: 'v')
#define	ACA_UARROW	((aca.line && aca.spec) ? ACS_UARROW 	: '^')
#define	ACA_RARROW	((aca.line && aca.spec) ? ACS_RARROW 	: '>')
#define	ACA_LARROW	((aca.line && aca.spec) ? ACS_LARROW	: '<')

   extern void 	mvaddastr(int y, int x, char *astr, int acolor, int color);
   extern void	center_addnstr(int y, int x, char *str, int max);
   extern void	left_addnstr(int y, int x, char *str, int maxlines, int max);	
   extern void	mvaddline_nstr (int y, int x, char *str, int line, int max);	
   extern void	mvaddline_nstr_sht (int y, int x, char *str, int line, int max, int sht);	

   extern void	aca_border(int y, int x, int yn, int xn, int color);
   extern void	draw_linebox(int y, int x, int yn, int xn, int color);
   extern void	clear_linebox(int y, int x, int yn, int xn, int color);
   extern void	clean_box(int y, int x, int yn, int xn, int color);

#define clean_hline(y, x, n, c)	{ aca_c(c); mvhline(y, x, ' ', n); } 

   extern chtype	**init_refresh_buffer();
   extern void	fill_refresh_buffer(chtype **b);
   extern void	print_refresh_buffer(chtype **b);

   extern inline 	void show_run();

   extern int	gethotkey(char *astr);
   extern int	astrlen(char *astr);
   extern char	*astr2str(char *str, char *astr);


/* ------ aca INI part ------ */

#define MAXSIZ_SECTION_NAME	32	/* with '[' and ']' !!! */
#define MAXSIZ_SECTION_CONTENT	BUFSIZ
#define MAXSIZ_SECTION_VALUE	32

   typedef struct INI_SectionData {
      	char		*value,
      			*content;
      		
      		/*  your func. - (if is set) ACA call it for content save,
      		    (you can change content) - your func. must (itself) alloc 
      		    memory for content and set content to data->content */
   	int		(*value_call_fn)(struct INI_SectionData *data, char *value, char *content);
   } INI_SectionData;

   typedef struct INI_Section {
      	char		*name;
      	int		flag;      	
      	INI_SectionData	*data;
      		
      		/* your func. - (if is set) ACA call it before INI_set_data()
      		   for all values in section */
      	int		(*sect_call_fn)(struct INI_Section *sect, char *value, char *content);	
   } INI_Section;

   typedef struct {
   	char		*filename;
   	INI_Section	*section;	
   } aca_INI;
   
/* Section flags: */
#define SECT_SAVE	0x01		/* section need save */ 
#define SECT_SAVED	0x02		/* section is saved  */		
#define SECT_LOAD	0x04   		/* section need load */
#define SECT_LOADED	0x08		/* section is loaded */
#define SECT_DELETE	0x10		/* section is delete */

   
#define TERMINAM_KEYS_SECTION		{ GL_term_name, SECT_LOAD, (INI_SectionData *) NULL, NULL }   
   
   extern INI_Section *INI_sect_flag(aca_INI *ini, char *sname, int flag);	  
  
#define INI_flag_save(ini, sname)   INI_sect_flag(ini, sname, SECT_SAVE)	  
#define INI_flag_delete(ini, sname) INI_sect_flag(ini, sname, SECT_DELETE)	  
#define INI_flag_load(ini, sname)   INI_sect_flag(ini, sname, SECT_LOAD)	  
#define INI_flag_loaded(ini, sname) INI_sect_flag(ini, sname, SECT_LOADED)

   extern INI_Section *INI_set_sect_flag(aca_INI *ini, char *sname, int flag, int set);

#define INI_set_flag_save(ini, sname)   INI_set_sect_flag(ini, sname, SECT_SAVE, TRUE)	  
#define INI_set_flag_delete(ini, sname) INI_set_sect_flag(ini, sname, SECT_DELETE, TRUE)	  
#define INI_set_flag_load(ini, sname)   INI_set_sect_flag(ini, sname, SECT_LOAD, TRUE)	  
#define INI_set_flag_loaded(ini, sname) INI_set_sect_flag(ini, sname, SECT_LOADED, TRUE)

#define INI_unset_flag_save(ini, sname)   INI_set_sect_flag(ini, sname, SECT_SAVE, FALSE)	  
#define INI_unset_flag_delete(ini, sname) INI_set_sect_flag(ini, sname, SECT_DELETE, FALSE)	  
#define INI_unset_flag_load(ini, sname)   INI_set_sect_flag(ini, sname, SECT_LOAD, FALSE)	  
#define INI_unset_flag_loaded(ini, sname) INI_set_sect_flag(ini, sname, SECT_LOADED, FALSE)

   extern int INI_goto_section(FILE *f, char *section);
   extern int INI_load(aca_INI *ini); 
   extern int INI_save(aca_INI *ini); 
   extern int INI_init_data(INI_SectionData *sdata, char *value, char *content);
   extern int INI_set_data(INI_SectionData *sdata, char *value, char *content);
   extern INI_SectionData *INI_load_section(FILE *f, INI_Section *sect); 
   extern void INI_fprintf(FILE *f, aca_INI *ini);
   
   extern int		INI_existData(INI_Section *sect);
   extern INI_Section 	*INI_section (aca_INI *ini, char *sectname);
   extern char 		*INI_value (INI_Section *s, char *valname);
   
   extern char	*separe_str(char *value, int sep);



/* ------------------------------------------------------------------------ */

   typedef struct {
      int	curses;			/* curses standard KEY_ */
      char	*capname,		/* capname of key */
      		*seq,			/* term seqention */	
      		*default_seq;		/* default seqention */	
      int	ctrl,			/* key alternative CTRL+key */
      learn;			/* TRUE / FALSE */			
   } ACA_BASIC_KEYS;

#define MAX_SEQTIME		200000		
#define MAX_BASIC_KEYS		20
 
   extern  ACA_BASIC_KEYS 	basic_keys[];

   extern char	*GL_term_name;
   extern char	GL_seq_buff[256];
   extern int	GL_last_key;
   extern int	GL_current_key;	
   extern int	GL_inlearn_mode;	/* if aca learning key (now!) */

#define	SeqN		((char *) NULL)
#define XCTRL(x)	((x) & 31)
#define T_XCTRL(x)	(x==XCTRL(x) ? TRUE : FALSE)
#define ESC_CHAR	'\033'
#define ESC_STR 	"\033"

/* double ctrl key */
#define D_CTRL_KEY(x, y) \
	((XCTRL(x) == GL_last_key && XCTRL(y) == GL_current_key) ? TRUE : FALSE)	

/* esc key */
#define ESC_KEY(x) \
	(((ESC_CHAR == GL_last_key) && x == GL_current_key) ? TRUE : FALSE)	

/* for menu_seek() (refresh menu, but not go) */ 
#define K_STAY			-100	

/* if screen size is changed get_k() return K_SCREE...	*/
#define K_SCREEN_RESIZED	-110

#define K_MOUSE_L		KEY_MOUSE
#define K_MOUSE_M		-120
#define K_MOUSE_R		-130	
#define K_MOUSE_NOT		-140


extern   void 	aca_keypad(int x);
extern   void	aca_dump_keys(FILE *f, ACA_BASIC_KEYS *k);
extern   int 	learn_keydump_check();
extern   int 	isfunckey( int key ); 
extern   int 	set_learn_key(char *name, char *seq);
extern   void 	init_keys(aca_INI *ini);
extern	 void   init_keys_ini(INI_Section *sect);
extern   int 	timeout_calls(int current);
extern   void 	clean_input ();
extern   int 	find_in_lbuff(char *seq);
extern   int 	check_seq(char *buffer);
extern   int 	get_k();
extern   void 	init_lbuff();
extern   void 	set_lbuff(int key, char *seq);
extern   void 	cpy_lbuff();
extern	 void	cpy_learn2ini(aca_INI *ini);
extern   int 	learn_key(int key);


/* ------------------------------------------------------------------------ */

/* global values */
   extern int	GL_winch_flag,
   		GL_interrupt_flag;

   extern void	end_aca();

   extern void	init_winch();

   extern void	aca_default();
   extern void	init_aca(int def);
   extern void	set_inout_bits (int output_7bit_only, int input_8bit);
   extern void	cur_pre_exec();
   extern void	cur_post_exec();

   extern void	screen_resizer();

   extern FILE	*aca_fileopen(char *filename, char *mode, int errors);

#define READ_LOAD	1
#define MMAP_LOAD	2	

   extern char	*aca_loadfile(int fd, int *flag);
   extern void	aca_unloadfile(char *fbuff, int flag);

   extern int	lines_instr(char *str);
   extern int	linesize_instr(char *str, int *size);
   extern char	*get_line(char *str, int num);
   extern int	line_len(char *str);
   extern int	get_linepoz(char *str, int line, int item);



#define CLEAN_BIT	1
#define	ACA_BITNUM	8

   extern void	set_bit(unsigned int *b, int n, int set);
   extern int	show_bit(int unsigned x, int unsigned i);


/*
 * For text stored in aca.po
 */
#ifndef _aca
	#define	_aca(str)	dgettext(ACA_TD, str)
	#define Naca_(str)	(str)
#endif

#endif /* __ACA_H */