1 
2 /*
3  * YASR ("Yet Another Screen Reader") is an attempt at a lightweight,
4  * portable screen reader.
5  *
6  * Copyright (C) 2001-2003 by Michael P. Gorse. All rights reserved.
7  *
8  * YASR comes with ABSOLUTELY NO WARRANTY.
9  *
10  * This is free software, placed under the terms of the
11  * GNU Lesser General Public License, as published by the Free Software
12  * Foundation.  Please see the file COPYING for details.
13  *
14  * Web Page: http://yasr.sf.net
15  *
16  * This software is maintained by:
17  * Michael P. Gorse <mgorse@users.sourceforge.net>
18  */
19 
20 /* yasr.h -- header file for yasr */
21 
22 #include "config.h"
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <ctype.h>
27 #include <string.h>
28 #include <signal.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <fcntl.h>
32 #include <sys/ioctl.h>
33 #include <unistd.h>
34 #include <termios.h>
35 #include <sys/time.h>
36 #ifdef HAVE_LOCALE_H
37 #include <locale.h>
38 #endif
39 #include "gettext.h"
40 #ifdef ENABLE_NLS
41 #define _(x) gettext(x)
42 #define N_(x) gettext_noop(x)
43 #else
44 #define _(x) x
45 #define N_(x) x
46 #endif
47 
48 #ifdef HAVE_UTIL_H
49 #include <util.h>
50 #elif defined(HAVE_LIBUTIL_H)
51 #include <libutil.h>
52 #elif defined(HAVE_PTY_H)
53 #include <pty.h>
54 #endif
55 
56 #include <errno.h>
57 
58 #include "tts.h"
59 
60 typedef short chartype;
61 
62 typedef unsigned char uchar;
63 
64 typedef struct Curpos Curpos;
65 struct Curpos
66 {
67     int cr;
68     int cc;
69 };
70 
71 typedef struct Win Win;
72 struct Win
73 {
74     int carry;
75     int cc;
76     int cols;
77     int cr;
78     int mode;			/* flags changed by h/l csi sequences */
79     char attr;			/* flags changed by the m csi sequences */
80     Curpos savecp;
81     chartype **row;
82     int rows;
83     char *tab;
84     Win *next;
85 };
86 
87 typedef struct Func Func;
88 struct Func
89 {
90     void (*f) ();
91     char *desc;
92 };
93 
94 typedef struct Keybind Keybind;
95 struct Keybind
96 {
97     int key;
98     int index;
99     int numargs;
100     int *argp;
101     Keybind *next;
102 };
103 
104 typedef struct Keymap Keymap;
105 struct Keymap
106 {
107     int numkeys;
108     Keybind *kb;
109 };
110 
111 typedef enum mpunct mpunct;
112 enum mpunct
113 {
114     PUNCT_NONE,
115     PUNCT_SOME,
116     PUNCT_MOST,
117     PUNCT_ALL
118 };
119 
120 #define OPT_STR_SIZE 256
121 
122 typedef struct Tts Tts;
123 struct Tts
124 {
125     int fd;
126     int flood;
127     char *obuf;
128     int obufhead, obuflen, obuftail;
129     int oflag;			/* set to 1 every time tts_send is called */
130     int outlen;
131     char buf[256];
132     int synth;
133     pid_t pid;
134     char port[OPT_STR_SIZE];
135     int reinit; /* 1 if tts is being reinitialized */
136     int fd_slave;
137 };
138 
139 typedef struct Uirev Uirev;
140 struct Uirev
141 {
142     int cc;
143     int cr;
144     int lastkey;
145     int meta;
146     int repeat;
147     int udmode;
148     char findbuf[200];
149     int findbuflen;
150     int used;
151     Keymap keymap;
152 };
153 
154 typedef struct Ui Ui;
155 struct Ui
156 {
157     int abort;			/* set if the user aborts entering something */
158     char buf[100];
159     int buflen;
160     int curtrack;		/* 0 = none, 1 = with cursor keys, 2 = always */
161     int disable;		/* key to disable */
162     int disabled;		/* true if disabled */
163     int (*func) (int);
164     int kbsay;
165     int num;	/* number that the user is entering */
166     char str[100];	/* string that the user is entering */
167     int strlen;
168     int (*oldfunc) (int);
169     int meta;
170     int minrc;	/* min. repeat count */
171     int revmode;
172     int silent;
173     int rc_detached;
174   int split_caps;
175     Keymap keymap;
176 };
177 
178 typedef struct Opt Opt;
179 struct Opt
180 {
181     int *ptr;
182     char *internal_name;	/* English name */
183     char *localized_name;
184     char *setstr;
185     int type;
186     int shift;			/* # bits to shift, if type & 0x80 */
187     int tree;
188     union
189     {
190       struct { int min; int max; } val_int;
191       struct { double min; double max; } val_float;
192       int enum_max;
193       int submenu;
194     } v;
195     int synth;
196     char **arg;
197 };
198 
199 extern Tts tts;
200 extern Ui ui;
201 extern Uirev rev;
202 extern Win *win;
203 extern int cl_synth;
204 extern int cl_synthport;
205 
206 extern Opt opt[];
207 extern int synthopt;
208 extern char *conffile;
209 extern unsigned char buf[256];
210 extern int kbuf[100];
211 extern int kbuflen;
212 extern char usershell[OPT_STR_SIZE];
213 extern char ttsbuf[80];
214 extern char voices[TTS_SYNTH_COUNT][64];
215 extern int special;
216 
217 extern Func funcs[];
218 
219 /* ui.c prototypes */
220 extern void rev_rttc(int *argp);
221 extern void rev_rctb(int *argp);
222 extern void rev_rs(int *argp);
223 extern void rev_line(int *argp);
224 extern void rev_word(int *argp);
225 extern void rev_ch(int *argp);
226 extern void rev_curpos(int *argp);
227 extern void rev_toline(int *argp);
228 extern void rev_tocol(int *argp);
229 extern void rev_searchtocursor(int *argp);
230 extern void rev_searchtoend(int *argp);
231 extern void rev_find(int *argp);
232 extern int ui_ennum(int ch);
233 extern int ui_build_str(int ch);
234 extern void ui_funcman(int (*f) (int));
235 extern void ui_kbwiz(int *argp);
236 extern void ui_optmenu(int *argp);
237 extern void ui_saychar(int row, int col);
238 extern void ui_sayword(int cr, int cc);
239 extern void ui_saylinepart(int row, int c1, int c2, int say_blank);
240 extern void ui_sayline(int row, int say_blank);
241 extern void ui_bypass(int *argp);
242 extern void ui_curpos(int *argp);
243 extern void ui_revtog(int *argp);
244 extern void ui_detachtog(int *argp);
245 extern void ui_routerc(int *argp);
246 extern void ui_silence(int *argp);
247 extern void ui_opt_set(int *argp);
248 extern void ui_bol(int *argp);
249 extern void ui_eol(int *argp);
250 extern int ui_keypress(int key);
251 extern void ui_sayascii(int *argp);
252 extern void rev_nextpar(int *argp);
253 extern void rev_prevpar(int *argp);
254 extern void uinit();
255 
256 /* tts.c prototypes */
257 extern void tts_charoff();
258 extern void tts_printf_ll(const char *str, ...);
259 extern void tts_charon();
260 extern void tts_addchr(char ch);
261 extern void tts_out(unsigned char *ibuf, int len);
262 extern void tts_say(char *buf);
263 extern void tts_saychar(unsigned char ch);
264 extern void tts_sayphonetic(unsigned char ch);
265 extern void tts_send(char *buf, int len);
266 extern void tts_flush();
267 extern void tts_silence();
268 extern void tts_end();
269 extern int tts_init(int first_call);
270 extern void tts_reinit(int *argp);
271 extern int tts_reinit2();
272 extern void tts_say_printf(char *fmt, ...);
273 extern void tts_initsynth(int *argp);
274 extern int dict_read(char *buf);
275 extern void dict_write(FILE * fp);
276 
277 /* config.c prototypes */
278 extern void readconf();
279 
280 /* main.c prototypes */
281 void speak(char *ibuf, int len);
282 extern char realchar(chartype ch);
283 int readable(int fd, int wait);
284 
285 /* debug.c prototypes */
286 extern void open_debug(char *);
287 extern void debug(char *format, ...);
288 extern void close_debug();
289 
290 /* getfn.c prototypes */
291 char *getfn(char *name);
292 
293 /* keybind.c prototypes */
294 /* Undefine this to remove the keyboard wizard and make yasr slightly smaller*/
295 #define USE_KBWIZ
296 
297 extern int kb_search(Keymap * map, int k);
298 extern int kb_add(Keymap * map, int k, int i, int na, int *a, int flag);
299 extern int kbwiz(int ch);
300 
301 /* option.c prototypes */
302 extern int optmenu(int ch);
303 extern int opt_getval(int menu, int flag);
304 extern void opt_init();
305 extern int opt_read(char *buf, int synth);
306 extern void opt_say(int num, int flag);
307 extern void opt_set(int num, void *val);
308 extern void opt_queue_empty(int ll);
309 extern void opt_write(FILE * fp);
310 
311 /* openpty.c prototypes */
312 extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
313 
314 /* cfmakeraw.c prototypes */
315 extern void cfmakeraw(struct termios *);
316 
317 /* login_tty.c prototypes */
318 extern int login_tty(int);
319 
320 /* forkpty.c prototypes */
321 extern int forkpty(int *, char *, struct termios *, struct winsize *);
322 
323 /* tbc - Would it be more efficient to ensure that "blank" grids always held
324    ascii 0x20 rather than ascii 0x00? */
325 #define y_isblank(ch) ((ch & 0xdf) == 0)
326 #define cblank(r, c)  ((win->row[r][c] & 0xdf) == 0)
327 #define ttssend(x)    if (x) tts_send(x, strlen(x))
328 
329 #define NUMOPTS 59
330 
331 /* Option types */
332 #define OT_INT      0x00
333 #define OT_FLOAT    0x01
334 #define OT_ENUM     0x02
335 #define OT_STR      0x03
336 #define OT_TREE     0x04
337 #define OT_PRESET   0x05
338 #define OT_SYNTH    0x40
339 #define OT_BITSLICE 0x80
340 
341 #if DEBUG
342 #include "debug.h"
343 #endif
344