Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtksh / ksh93 / src / lib / libast / string / chresc.c
1 /* $XConsortium: chresc.c /main/3 1995/11/01 18:41:33 rswiston $ */
2 /***************************************************************
3 *                                                              *
4 *                      AT&T - PROPRIETARY                      *
5 *                                                              *
6 *         THIS IS PROPRIETARY SOURCE CODE LICENSED BY          *
7 *                          AT&T CORP.                          *
8 *                                                              *
9 *                Copyright (c) 1995 AT&T Corp.                 *
10 *                     All Rights Reserved                      *
11 *                                                              *
12 *           This software is licensed by AT&T Corp.            *
13 *       under the terms and conditions of the license in       *
14 *       http://www.research.att.com/orgs/ssr/book/reuse        *
15 *                                                              *
16 *               This software was created by the               *
17 *           Software Engineering Research Department           *
18 *                    AT&T Bell Laboratories                    *
19 *                                                              *
20 *               For further information contact                *
21 *                     gsf@research.att.com                     *
22 *                                                              *
23 ***************************************************************/
24
25 /* : : generated by proto : : */
26
27 #if !defined(__PROTO__)
28 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
29 #if defined(__cplusplus)
30 #define __MANGLE__      "C"
31 #else
32 #define __MANGLE__
33 #endif
34 #define __STDARG__
35 #define __PROTO__(x)    x
36 #define __OTORP__(x)
37 #define __PARAM__(n,o)  n
38 #if !defined(__STDC__) && !defined(__cplusplus)
39 #if !defined(c_plusplus)
40 #define const
41 #endif
42 #define signed
43 #define void            int
44 #define volatile
45 #define __V_            char
46 #else
47 #define __V_            void
48 #endif
49 #else
50 #define __PROTO__(x)    ()
51 #define __OTORP__(x)    x
52 #define __PARAM__(n,o)  o
53 #define __MANGLE__
54 #define __V_            char
55 #define const
56 #define signed
57 #define void            int
58 #define volatile
59 #endif
60 #if defined(__cplusplus) || defined(c_plusplus)
61 #define __VARARG__      ...
62 #else
63 #define __VARARG__
64 #endif
65 #if defined(__STDARG__)
66 #define __VA_START__(p,a)       va_start(p,a)
67 #else
68 #define __VA_START__(p,a)       va_start(p)
69 #endif
70 #endif
71 #include <ast.h>
72
73 int
74 chresc __PARAM__((register const char* s, char** p), (s, p)) __OTORP__(register const char* s; char** p;){
75         register const char*    q;
76         register int            c;
77
78         switch (c = *s++)
79         {
80         case 0:
81                 s--;
82                 break;
83         case '\\':
84                 switch (c = *s++)
85                 {
86                 case '0': case '1': case '2': case '3':
87                 case '4': case '5': case '6': case '7':
88                         c -= '0';
89                         q = s + 2;
90                         while (s < q) switch (*s)
91                         {
92                         case '0': case '1': case '2': case '3':
93                         case '4': case '5': case '6': case '7':
94                                 c = (c << 3) + *s++ - '0';
95                                 break;
96                         default:
97                                 q = s;
98                                 break;
99                         }
100                         break;
101                 case 'a':
102                         c = '\007';
103                         break;
104                 case 'b':
105                         c = '\b';
106                         break;
107                 case 'f':
108                         c = '\f';
109                         break;
110                 case 'n':
111                         c = '\n';
112                         break;
113                 case 'r':
114                         c = '\r';
115                         break;
116                 case 's':
117                         c = ' ';
118                         break;
119                 case 't':
120                         c = '\t';
121                         break;
122                 case 'v':
123                         c = '\013';
124                         break;
125                 case 'x':
126                         c = 0;
127                         q = s;
128                         while (q) switch (*s)
129                         {
130                         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
131                                 c = (c << 4) + *s++ - 'a' + 10;
132                                 break;
133                         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
134                                 c = (c << 4) + *s++ - 'A' + 10;
135                                 break;
136                         case '0': case '1': case '2': case '3': case '4':
137                         case '5': case '6': case '7': case '8': case '9':
138                                 c = (c << 4) + *s++ - '0';
139                                 break;
140                         default:
141                                 q = 0;
142                                 break;
143                         }
144                         break;
145                 case 'E':
146                         c = '\033';
147                         break;
148                 case 0:
149                         s--;
150                         break;
151                 }
152                 break;
153         }
154         if (p) *p = (char*)s;
155         return(c);
156 }