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
|
/*
* YASR ("Yet Another Screen Reader") is an attempt at a lightweight,
* portable screen reader.
*
* Copyright (C) 2001-2002 by Michael P. Gorse. All rights reserved.
*
* YASR comes with ABSOLUTELY NO WARRANTY.
*
* This is free software, placed under the terms of the
* GNU Lesser General Public License, as published by the Free Software
* Foundation. Please see the file COPYING for details.
*
* Web Page: http://mgorse.dhs.org:8000/yasr/
*
* This software is maintained by:
* Michael P. Gorse <[email protected]>
*/
#include "yasr.h"
#include <sys/param.h>
static void conf_write(int *);
Func funcs[] = {
{&rev_line, "say line"}, /* 0 */
{&rev_ch, "say character"}, /* 1 */
{&rev_curpos, "say review cursor"}, /* 2 */
{&rev_find, "find"}, /* 3 */
{&ui_silence, "flush"}, /* 4 */
{&ui_revtog, "toggle review mode"}, /* 5 */
{&ui_curpos, "say cursor"}, /* 6 */
{&rev_rttc, "read top to cursor"}, /* 7 */
{&rev_rctb, "read cursor to bottom"}, /* 8 */
{&rev_rs, "read screen"}, /* 9 */
{&rev_searchtocursor, "search back"}, /* 10 */
{&rev_searchtoend, "search forward"}, /* 11 */
{&ui_bypass, "bypass"}, /* 12 */
{&rev_word, "say word"}, /* 13 */
{&ui_optmenu, "options menu"}, /* 14 */
{&ui_kbwiz, "keyboard wizard"}, /* 15 */
{&conf_write, "write configuration"}, /* 16 */
{&ui_opt_set, "set option"}, /* 17 */
{&ui_bol, "beginning of line"}, /* 18 */
{&ui_eol, "end of line"}, /* 19 */
{&tts_reinit, "reinitialize"}, /* 20 */
{&ui_detachtog, "toggle cursor detachment"}, /* 21 */
{&rev_toline, "Move review cursor to line"}, /* 22 */
{&rev_tocol, "move review cursor to column"}, /* 23 */
{&ui_routerc, "route review cursor"}, /* 24 */
{&ui_sayascii, "ascii"}, /* 25 */
{&rev_nextpar, "next paragraph"}, /* 26 */
{&rev_prevpar, "previous paragraph"}, /* 27 */
{NULL, NULL} /* required terminator */
};
void readconf()
{
FILE *fp;
int args, arg[16], *argp;
int i, key, ln = 0, mode = 0;
char *home, *ptr, *s;
char confname[strlen(PACKAGE_DATA_DIR) 10 1];
if ((home = getenv("HOME")) != NULL)
{
(void) strcpy((char *) buf, home);
(void) strcat((char *) buf, "/.yasr.conf");
}
(void) sprintf(confname, "%s/yasr.conf", PACKAGE_DATA_DIR);
if (!(fp = fopen(conffile, "r")) &&
!(fp = fopen((char *) buf, "r")) && !(fp = fopen(confname, "r")))
{
(void) printf("yasr: unable to find %s or ~/.yasr.conf or %s.\n", conffile, confname);
exit(1);
}
for (;;)
{
ln ;
(void) fgets((char *) buf, 200, fp);
if (feof(fp))
{
break;
}
ptr = (char *) buf;
while (*ptr == 32 || *ptr == 9)
{
ptr ;
}
if (ptr[0] == '#')
{
continue;
}
buf[strlen((char *) buf) - 1] = 0;
if (buf[strlen((char *) buf) - 1] == '\r')
{
buf[strlen((char *) buf) - 1] = 0;
}
if (!strlen(ptr))
{
continue;
}
if (!strcasecmp(ptr, "[reviewkeys]"))
{
mode = 1;
}
else if (!strcasecmp(ptr, "[normalkeys]"))
{
mode = 2;
}
else if (!strcasecmp((char *) buf, "[options]"))
{
mode = 3;
}
else if (!strcasecmp((char *) buf, "[dict]"))
{
mode = 4;
}
else if (buf[0] == '[')
{
mode = 0;
buf[strlen((char *) buf) - 1] = '\0';
for (i = 0; i <= opt[synthopt].v.enum_max; i )
{
if (!strcasecmp((char *) buf 1, opt[synthopt].arg[i]))
{
mode = -i - 1;
}
}
}
else
{
switch (mode)
{
case 1:
case 2: /* keybind */
key = strtol(ptr, &s, 0);
s ;
ptr = strtok(s, ":");
if (atoi(s)) i = atoi(s);
else
{
for (i = 0; funcs[i].desc; i )
{
if (!strcasecmp(s, funcs[i].desc))
{
break;
}
}
}
if (!funcs[i].desc)
{
printf("Syntax error on line %d of configuration file.\n", ln);
exit(1);
}
args = 0;
while ((ptr = strtok(NULL, ":")))
{
/* tbc -- is allowing numbers okay? */
arg[args ] = atoi(ptr);
}
if (args)
{
argp = (int *) malloc(args * sizeof(int));
(void) memcpy(argp, arg, args * sizeof(int));
}
else argp = NULL;
if (mode == 1)
{
(void) kb_add(&rev.keymap, key, i, args, argp, 2);
}
else
{
(void) kb_add(&ui.keymap, key, i, args, argp, 2);
}
break;
case 4:
(void) dict_read((char *) buf);
break;
default: /* option */
if (opt_read((char *) buf, mode < 0 ? -mode - 1 : 0))
{
printf
("Error on line %d of configuration file: invalid option\n", ln);
exit(1);
}
if (!strcasecmp((char *) buf, "synthesizer port"))
{
(void) tts_init(1);
}
break;
}
}
}
(void) fclose(fp);
}
static void kb_write(FILE * fp, Keymap * map)
{
int i, j;
int *argp;
char tmpstr[12];
Keybind *kb;
for (i = 0, kb = map->kb; i < map->numkeys; i , kb )
{
(void) sprintf((char *) buf, "0x%x:%s", kb->key, funcs[kb->index].desc);
argp = kb->argp;
for (j = 0; j < kb->numargs; j )
{
(void) sprintf(tmpstr, ":%d", *(argp ));
(void) strcat((char *) buf, tmpstr);
}
(void) fprintf(fp, "%s\n", buf);
}
}
/*ARGSUSED*/ static void conf_write(int *argp)
{
FILE *fp;
char filename[200];
(void) strcpy(filename, getenv("HOME"));
(void) strcat(filename, "/.yasr.conf");
fp = fopen(filename, "w");
if (!fp)
{
tts_say_printf("Unable to write configuration file %s.", filename);
return;
}
(void) fprintf(fp, "[normalkeys]\n");
kb_write(fp, &ui.keymap);
(void) fprintf(fp, "[reviewkeys]\n");
kb_write(fp, &rev.keymap);
(void) fprintf(fp, "[options]\n");
opt_write(fp);
(void) fprintf(fp, "[dict]\n");
dict_write(fp);
(void) fclose(fp);
tts_say_printf("Configuration saved to %s.", filename);
}
|