Updated italian translation
[midnight-commander.git] / slang / slmisc.c
blob9d252878b3836294a714a400f7fae29bb5600125
1 /* Copyright (c) 1992, 1999, 2001, 2002, 2003 John E. Davis
2 * This file is part of the S-Lang library.
4 * Trimmed down for use in GNU Midnight Commander.
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Perl Artistic License.
8 */
9 #define _GNU_SOURCE
10 #include "slinclud.h"
12 #include "slang.h"
13 #include "_slang.h"
14 const int SLang_Version = SLANG_VERSION;
16 /* p and ch may point to the same buffer */
17 char *_SLexpand_escaped_char(char *p, char *ch)
19 int i = 0;
20 int max = 0, num, base = 0;
21 char ch1;
23 ch1 = *p++;
25 switch (ch1)
27 default: num = ch1; break;
28 case 'n': num = '\n'; break;
29 case 't': num = '\t'; break;
30 case 'v': num = '\v'; break;
31 case 'b': num = '\b'; break;
32 case 'r': num = '\r'; break;
33 case 'f': num = '\f'; break;
34 case 'E': case 'e': num = 27; break;
35 case 'a': num = 7;
36 break;
38 /* octal */
39 case '0': case '1': case '2': case '3':
40 case '4': case '5': case '6': case '7':
41 max = '7';
42 base = 8; i = 2; num = ch1 - '0';
43 break;
45 case 'd': /* decimal -- S-Lang extension */
46 base = 10;
47 i = 3;
48 max = '9';
49 num = 0;
50 break;
52 case 'x': /* hex */
53 base = 16;
54 max = '9';
55 i = 2;
56 num = 0;
57 break;
60 while (i--)
62 ch1 = *p;
64 if ((ch1 <= max) && (ch1 >= '0'))
66 num = base * num + (ch1 - '0');
68 else if (base == 16)
70 ch1 |= 0x20;
71 if ((ch1 < 'a') || ((ch1 > 'f'))) break;
72 num = base * num + 10 + (ch1 - 'a');
74 else break;
75 p++;
78 *ch = (char) num;
79 return p;