Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
chresc.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11/*
12 * Glenn Fowler
13 * AT&T Research
14 *
15 * return the next character in the string s
16 * \ character constants are converted
17 * p is updated to point to the next character in s
18 */
19
20#include <ast/ast.h>
21
22int chresc(const char *s, char **p)
23{
24 const char *q;
25 int c;
26
27 switch (c = *s++) {
28 case 0:
29 s--;
30 break;
31 case '\\':
32 switch (c = *s++) {
33 case '0':
34 case '1':
35 case '2':
36 case '3':
37 case '4':
38 case '5':
39 case '6':
40 case '7':
41 c -= '0';
42 q = s + 2;
43 while (s < q)
44 switch (*s) {
45 case '0':
46 case '1':
47 case '2':
48 case '3':
49 case '4':
50 case '5':
51 case '6':
52 case '7':
53 c = (c << 3) + *s++ - '0';
54 break;
55 default:
56 q = s;
57 break;
58 }
59 break;
60 case 'a':
61 c = CC_bel;
62 break;
63 case 'b':
64 c = '\b';
65 break;
66 case 'f':
67 c = '\f';
68 break;
69 case 'n':
70 c = '\n';
71 break;
72 case 'r':
73 c = '\r';
74 break;
75 case 's':
76 c = ' ';
77 break;
78 case 't':
79 c = '\t';
80 break;
81 case 'v':
82 c = CC_vt;
83 break;
84 case 'x':
85 c = 0;
86 q = s;
87 while (q)
88 switch (*s) {
89 case 'a':
90 case 'b':
91 case 'c':
92 case 'd':
93 case 'e':
94 case 'f':
95 c = (c << 4) + *s++ - 'a' + 10;
96 break;
97 case 'A':
98 case 'B':
99 case 'C':
100 case 'D':
101 case 'E':
102 case 'F':
103 c = (c << 4) + *s++ - 'A' + 10;
104 break;
105 case '0':
106 case '1':
107 case '2':
108 case '3':
109 case '4':
110 case '5':
111 case '6':
112 case '7':
113 case '8':
114 case '9':
115 c = (c << 4) + *s++ - '0';
116 break;
117 default:
118 q = 0;
119 break;
120 }
121 break;
122 case 'E':
123 c = CC_esc;
124 break;
125 case 0:
126 s--;
127 break;
128 default:
129 break;
130 }
131 break;
132 default:
133 break;
134 }
135 if (p)
136 *p = (char *) s;
137 return c;
138}
#define CC_bel
Definition ast.h:29
#define CC_vt
Definition ast.h:31
#define CC_esc
Definition ast.h:30
int chresc(const char *s, char **p)
Definition chresc.c:22
Definition grammar.c:93