William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 1 | #include <linux/ctype.h> |
| 2 | #include "spk_types.h" |
| 3 | #include "spk_priv.h" |
| 4 | #include "speakup.h" |
| 5 | |
| 6 | static struct st_var_header var_headers[] = { |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 7 | { "version", VERSION, VAR_PROC, NULL, NULL }, |
| 8 | { "synth_name", SYNTH, VAR_PROC, NULL, NULL }, |
| 9 | { "keymap", KEYMAP, VAR_PROC, NULL, NULL }, |
| 10 | { "silent", SILENT, VAR_PROC, NULL, NULL }, |
| 11 | { "punc_some", PUNC_SOME, VAR_PROC, NULL, NULL }, |
| 12 | { "punc_most", PUNC_MOST, VAR_PROC, NULL, NULL }, |
| 13 | { "punc_all", PUNC_ALL, VAR_PROC, NULL, NULL }, |
| 14 | { "delimiters", DELIM, VAR_PROC, NULL, NULL }, |
| 15 | { "repeats", REPEATS, VAR_PROC, NULL, NULL }, |
| 16 | { "ex_num", EXNUMBER, VAR_PROC, NULL, NULL }, |
| 17 | { "characters", CHARS, VAR_PROC, NULL, NULL }, |
| 18 | { "synth_direct", SYNTH_DIRECT, VAR_PROC, NULL, NULL }, |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 19 | { "caps_start", CAPS_START, VAR_STRING, spk_str_caps_start, NULL }, |
| 20 | { "caps_stop", CAPS_STOP, VAR_STRING, spk_str_caps_stop, NULL }, |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 21 | { "delay_time", DELAY, VAR_TIME, NULL, NULL }, |
| 22 | { "trigger_time", TRIGGER, VAR_TIME, NULL, NULL }, |
| 23 | { "jiffy_delta", JIFFY, VAR_TIME, NULL, NULL }, |
| 24 | { "full_time", FULL, VAR_TIME, NULL, NULL }, |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 25 | { "spell_delay", SPELL_DELAY, VAR_NUM, &spk_spell_delay, NULL }, |
| 26 | { "bleeps", BLEEPS, VAR_NUM, &spk_bleeps, NULL }, |
| 27 | { "attrib_bleep", ATTRIB_BLEEP, VAR_NUM, &spk_attrib_bleep, NULL }, |
| 28 | { "bleep_time", BLEEP_TIME, VAR_TIME, &spk_bleep_time, NULL }, |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 29 | { "cursor_time", CURSOR_TIME, VAR_TIME, NULL, NULL }, |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 30 | { "punc_level", PUNC_LEVEL, VAR_NUM, &spk_punc_level, NULL }, |
| 31 | { "reading_punc", READING_PUNC, VAR_NUM, &spk_reading_punc, NULL }, |
| 32 | { "say_control", SAY_CONTROL, VAR_NUM, &spk_say_ctrl, NULL }, |
| 33 | { "say_word_ctl", SAY_WORD_CTL, VAR_NUM, &spk_say_word_ctl, NULL }, |
| 34 | { "no_interrupt", NO_INTERRUPT, VAR_NUM, &spk_no_intr, NULL }, |
| 35 | { "key_echo", KEY_ECHO, VAR_NUM, &spk_key_echo, NULL }, |
| 36 | { "bell_pos", BELL_POS, VAR_NUM, &spk_bell_pos, NULL }, |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 37 | { "rate", RATE, VAR_NUM, NULL, NULL }, |
| 38 | { "pitch", PITCH, VAR_NUM, NULL, NULL }, |
| 39 | { "vol", VOL, VAR_NUM, NULL, NULL }, |
| 40 | { "tone", TONE, VAR_NUM, NULL, NULL }, |
| 41 | { "punct", PUNCT, VAR_NUM, NULL, NULL }, |
| 42 | { "voice", VOICE, VAR_NUM, NULL, NULL }, |
| 43 | { "freq", FREQUENCY, VAR_NUM, NULL, NULL }, |
| 44 | { "lang", LANG, VAR_NUM, NULL, NULL }, |
| 45 | { "chartab", CHARTAB, VAR_PROC, NULL, NULL }, |
| 46 | { "direct", DIRECT, VAR_NUM, NULL, NULL }, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | static struct st_var_header *var_ptrs[MAXVARS] = { 0, 0, 0 }; |
| 50 | |
| 51 | static struct punc_var_t punc_vars[] = { |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 52 | { PUNC_SOME, 1 }, |
| 53 | { PUNC_MOST, 2 }, |
| 54 | { PUNC_ALL, 3 }, |
| 55 | { DELIM, 4 }, |
| 56 | { REPEATS, 5 }, |
| 57 | { EXNUMBER, 6 }, |
| 58 | { -1, -1 }, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 59 | }; |
| 60 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 61 | int spk_chartab_get_value(char *keyword) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 62 | { |
| 63 | int value = 0; |
| 64 | |
| 65 | if (!strcmp(keyword, "ALPHA")) |
| 66 | value = ALPHA; |
| 67 | else if (!strcmp(keyword, "B_CTL")) |
| 68 | value = B_CTL; |
| 69 | else if (!strcmp(keyword, "WDLM")) |
| 70 | value = WDLM; |
| 71 | else if (!strcmp(keyword, "A_PUNC")) |
| 72 | value = A_PUNC; |
| 73 | else if (!strcmp(keyword, "PUNC")) |
| 74 | value = PUNC; |
| 75 | else if (!strcmp(keyword, "NUM")) |
| 76 | value = NUM; |
| 77 | else if (!strcmp(keyword, "A_CAP")) |
| 78 | value = A_CAP; |
| 79 | else if (!strcmp(keyword, "B_CAPSYM")) |
| 80 | value = B_CAPSYM; |
| 81 | else if (!strcmp(keyword, "B_SYM")) |
| 82 | value = B_SYM; |
| 83 | return value; |
| 84 | } |
| 85 | |
| 86 | void speakup_register_var(struct var_t *var) |
| 87 | { |
| 88 | static char nothing[2] = "\0"; |
| 89 | int i; |
| 90 | struct st_var_header *p_header; |
| 91 | |
| 92 | BUG_ON(!var || var->var_id < 0 || var->var_id >= MAXVARS); |
| 93 | if (var_ptrs[0] == NULL) { |
| 94 | for (i = 0; i < MAXVARS; i++) { |
| 95 | p_header = &var_headers[i]; |
| 96 | var_ptrs[p_header->var_id] = p_header; |
| 97 | p_header->data = NULL; |
| 98 | } |
| 99 | } |
| 100 | p_header = var_ptrs[var->var_id]; |
| 101 | if (p_header->data != NULL) |
| 102 | return; |
| 103 | p_header->data = var; |
| 104 | switch (p_header->var_type) { |
| 105 | case VAR_STRING: |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 106 | spk_set_string_var(nothing, p_header, 0); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 107 | break; |
| 108 | case VAR_NUM: |
| 109 | case VAR_TIME: |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 110 | spk_set_num_var(0, p_header, E_DEFAULT); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 111 | break; |
| 112 | default: |
| 113 | break; |
| 114 | } |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | void speakup_unregister_var(enum var_id_t var_id) |
| 119 | { |
| 120 | struct st_var_header *p_header; |
| 121 | BUG_ON(var_id < 0 || var_id >= MAXVARS); |
| 122 | p_header = var_ptrs[var_id]; |
| 123 | p_header->data = NULL; |
| 124 | } |
| 125 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 126 | struct st_var_header *spk_get_var_header(enum var_id_t var_id) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 127 | { |
| 128 | struct st_var_header *p_header; |
| 129 | if (var_id < 0 || var_id >= MAXVARS) |
| 130 | return NULL; |
| 131 | p_header = var_ptrs[var_id]; |
| 132 | if (p_header->data == NULL) |
| 133 | return NULL; |
| 134 | return p_header; |
| 135 | } |
| 136 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 137 | struct st_var_header *spk_var_header_by_name(const char *name) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 138 | { |
| 139 | int i; |
| 140 | struct st_var_header *where = NULL; |
| 141 | |
| 142 | if (name != NULL) { |
| 143 | i = 0; |
| 144 | while ((i < MAXVARS) && (where == NULL)) { |
| 145 | if (strcmp(name, var_ptrs[i]->name) == 0) |
| 146 | where = var_ptrs[i]; |
| 147 | else |
| 148 | i++; |
| 149 | } |
| 150 | } |
| 151 | return where; |
| 152 | } |
| 153 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 154 | struct var_t *spk_get_var(enum var_id_t var_id) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 155 | { |
| 156 | BUG_ON(var_id < 0 || var_id >= MAXVARS); |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 157 | BUG_ON(!var_ptrs[var_id]); |
| 158 | return var_ptrs[var_id]->data; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 159 | } |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 160 | EXPORT_SYMBOL_GPL(spk_get_var); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 161 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 162 | struct punc_var_t *spk_get_punc_var(enum var_id_t var_id) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 163 | { |
| 164 | struct punc_var_t *rv = NULL; |
| 165 | struct punc_var_t *where; |
| 166 | |
| 167 | where = punc_vars; |
| 168 | while ((where->var_id != -1) && (rv == NULL)) { |
| 169 | if (where->var_id == var_id) |
| 170 | rv = where; |
| 171 | else |
| 172 | where++; |
| 173 | } |
| 174 | return rv; |
| 175 | } |
| 176 | |
| 177 | /* handlers for setting vars */ |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 178 | int spk_set_num_var(int input, struct st_var_header *var, int how) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 179 | { |
| 180 | int val; |
| 181 | short ret = 0; |
| 182 | int *p_val = var->p_val; |
| 183 | int l; |
| 184 | char buf[32]; |
| 185 | char *cp; |
| 186 | struct var_t *var_data = var->data; |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 187 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 188 | if (var_data == NULL) |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 189 | return -ENODATA; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 190 | |
| 191 | if (how == E_NEW_DEFAULT) { |
| 192 | if (input < var_data->u.n.low || input > var_data->u.n.high) |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 193 | return -ERANGE; |
| 194 | var_data->u.n.default_val = input; |
| 195 | return 0; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 196 | } |
| 197 | if (how == E_DEFAULT) { |
| 198 | val = var_data->u.n.default_val; |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 199 | ret = -ERESTART; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 200 | } else { |
| 201 | if (how == E_SET) |
| 202 | val = input; |
| 203 | else |
| 204 | val = var_data->u.n.value; |
| 205 | if (how == E_INC) |
| 206 | val += input; |
| 207 | else if (how == E_DEC) |
| 208 | val -= input; |
| 209 | if (val < var_data->u.n.low || val > var_data->u.n.high) |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 210 | return -ERANGE; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 211 | } |
| 212 | var_data->u.n.value = val; |
| 213 | if (var->var_type == VAR_TIME && p_val != NULL) { |
| 214 | *p_val = msecs_to_jiffies(val); |
| 215 | return ret; |
| 216 | } |
| 217 | if (p_val != NULL) |
| 218 | *p_val = val; |
| 219 | if (var->var_id == PUNC_LEVEL) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 220 | spk_punc_mask = spk_punc_masks[val]; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 221 | return ret; |
| 222 | } |
| 223 | if (var_data->u.n.multiplier != 0) |
| 224 | val *= var_data->u.n.multiplier; |
| 225 | val += var_data->u.n.offset; |
| 226 | if (var->var_id < FIRST_SYNTH_VAR || synth == NULL) |
| 227 | return ret; |
| 228 | if (synth->synth_adjust != NULL) { |
| 229 | int status = synth->synth_adjust(var); |
| 230 | return (status != 0) ? status : ret; |
| 231 | } |
| 232 | if (!var_data->u.n.synth_fmt) |
| 233 | return ret; |
| 234 | if (var->var_id == PITCH) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 235 | cp = spk_pitch_buff; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 236 | else |
| 237 | cp = buf; |
| 238 | if (!var_data->u.n.out_str) |
| 239 | l = sprintf(cp, var_data->u.n.synth_fmt, (int)val); |
| 240 | else |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 241 | l = sprintf(cp, |
| 242 | var_data->u.n.synth_fmt, var_data->u.n.out_str[val]); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 243 | synth_printf("%s", cp); |
| 244 | return ret; |
| 245 | } |
| 246 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 247 | int spk_set_string_var(const char *page, struct st_var_header *var, int len) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 248 | { |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 249 | struct var_t *var_data = var->data; |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 250 | |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 251 | if (var_data == NULL) |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 252 | return -ENODATA; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 253 | if (len > MAXVARLEN) |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 254 | return -E2BIG; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 255 | if (!len) { |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 256 | if (!var_data->u.s.default_val) |
| 257 | return 0; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 258 | if (!var->p_val) |
| 259 | var->p_val = var_data->u.s.default_val; |
| 260 | if (var->p_val != var_data->u.s.default_val) |
| 261 | strcpy((char *)var->p_val, var_data->u.s.default_val); |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 262 | return -ERESTART; |
William Hubbs | a1277d8 | 2010-10-15 22:13:39 -0500 | [diff] [blame] | 263 | } else if (var->p_val) |
| 264 | strcpy((char *)var->p_val, page); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 265 | else |
Andy Shevchenko | 6a48f88 | 2013-03-28 11:02:44 +0200 | [diff] [blame^] | 266 | return -E2BIG; |
| 267 | return 0; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 268 | } |
| 269 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 270 | /* spk_set_mask_bits sets or clears the punc/delim/repeat bits, |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 271 | * if input is null uses the defaults. |
| 272 | * values for how: 0 clears bits of chars supplied, |
| 273 | * 1 clears allk, 2 sets bits for chars */ |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 274 | int spk_set_mask_bits(const char *input, const int which, const int how) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 275 | { |
| 276 | u_char *cp; |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 277 | short mask = spk_punc_info[which].mask; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 278 | if (how&1) { |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 279 | for (cp = (u_char *)spk_punc_info[3].value; *cp; cp++) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 280 | spk_chartab[*cp] &= ~mask; |
| 281 | } |
| 282 | cp = (u_char *)input; |
| 283 | if (cp == 0) |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 284 | cp = spk_punc_info[which].value; |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 285 | else { |
| 286 | for ( ; *cp; cp++) { |
| 287 | if (*cp < SPACE) |
| 288 | break; |
| 289 | if (mask < PUNC) { |
| 290 | if (!(spk_chartab[*cp]&PUNC)) |
| 291 | break; |
| 292 | } else if (spk_chartab[*cp]&B_NUM) |
| 293 | break; |
| 294 | } |
| 295 | if (*cp) |
| 296 | return -EINVAL; |
| 297 | cp = (u_char *)input; |
| 298 | } |
| 299 | if (how&2) { |
| 300 | for ( ; *cp; cp++) |
| 301 | if (*cp > SPACE) |
| 302 | spk_chartab[*cp] |= mask; |
| 303 | } else { |
| 304 | for ( ; *cp; cp++) |
| 305 | if (*cp > SPACE) |
| 306 | spk_chartab[*cp] &= ~mask; |
| 307 | } |
| 308 | return 0; |
| 309 | } |
| 310 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 311 | char *spk_strlwr(char *s) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 312 | { |
| 313 | char *p; |
| 314 | if (s == NULL) |
| 315 | return NULL; |
| 316 | |
| 317 | for (p = s; *p; p++) |
| 318 | *p = tolower(*p); |
| 319 | return s; |
| 320 | } |
| 321 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 322 | char *spk_s2uchar(char *start, char *dest) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 323 | { |
| 324 | int val = 0; |
Andy Shevchenko | 1627ab9 | 2013-03-28 11:02:43 +0200 | [diff] [blame] | 325 | val = simple_strtoul(skip_spaces(start), &start, 10); |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 326 | if (*start == ',') |
| 327 | start++; |
| 328 | *dest = (u_char)val; |
| 329 | return start; |
| 330 | } |
| 331 | |
Samuel Thibault | ca2beaf | 2013-01-02 02:37:40 +0100 | [diff] [blame] | 332 | char *spk_xlate(char *s) |
William Hubbs | c6e3fd2 | 2010-10-07 13:20:02 -0500 | [diff] [blame] | 333 | { |
| 334 | static const char finds[] = "nrtvafe"; |
| 335 | static const char subs[] = "\n\r\t\013\001\014\033"; |
| 336 | static const char hx[] = "0123456789abcdefABCDEF"; |
| 337 | char *p = s, *p1, *p2, c; |
| 338 | int num; |
| 339 | while ((p = strchr(p, '\\'))) { |
| 340 | p1 = p+1; |
| 341 | p2 = strchr(finds, *p1); |
| 342 | if (p2) { |
| 343 | *p++ = subs[p2-finds]; |
| 344 | p1++; |
| 345 | } else if (*p1 >= '0' && *p1 <= '7') { |
| 346 | num = (*p1++)&7; |
| 347 | while (num < 256 && *p1 >= '0' && *p1 <= '7') { |
| 348 | num <<= 3; |
| 349 | num = (*p1++)&7; |
| 350 | } |
| 351 | *p++ = num; |
| 352 | } else if (*p1 == 'x' && |
| 353 | strchr(hx, p1[1]) && strchr(hx, p1[2])) { |
| 354 | p1++; |
| 355 | c = *p1++; |
| 356 | if (c > '9') |
| 357 | c = (c - '7') & 0x0f; |
| 358 | else |
| 359 | c -= '0'; |
| 360 | num = c << 4; |
| 361 | c = *p1++; |
| 362 | if (c > '9') |
| 363 | c = (c-'7')&0x0f; |
| 364 | else |
| 365 | c -= '0'; |
| 366 | num += c; |
| 367 | *p++ = num; |
| 368 | } else |
| 369 | *p++ = *p1++; |
| 370 | p2 = p; |
| 371 | while (*p1) |
| 372 | *p2++ = *p1++; |
| 373 | *p2 = '\0'; |
| 374 | } |
| 375 | return s; |
| 376 | } |