Graphviz 14.1.2~dev.20260121.0931
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 "config.h"
21
22#include <ast/ast.h>
23
24int chresc(const char *s, char **p)
25{
26 const char *q;
27 int c;
28
29 switch (c = *s++) {
30 case 0:
31 s--;
32 break;
33 case '\\':
34 switch (c = *s++) {
35 case '0':
36 case '1':
37 case '2':
38 case '3':
39 case '4':
40 case '5':
41 case '6':
42 case '7':
43 c -= '0';
44 q = s + 2;
45 while (s < q)
46 switch (*s) {
47 case '0':
48 case '1':
49 case '2':
50 case '3':
51 case '4':
52 case '5':
53 case '6':
54 case '7':
55 c = (c << 3) + *s++ - '0';
56 break;
57 default:
58 q = s;
59 break;
60 }
61 break;
62 case 'a':
63 c = CC_bel;
64 break;
65 case 'b':
66 c = '\b';
67 break;
68 case 'f':
69 c = '\f';
70 break;
71 case 'n':
72 c = '\n';
73 break;
74 case 'r':
75 c = '\r';
76 break;
77 case 's':
78 c = ' ';
79 break;
80 case 't':
81 c = '\t';
82 break;
83 case 'v':
84 c = CC_vt;
85 break;
86 case 'x':
87 c = 0;
88 q = s;
89 while (q)
90 switch (*s) {
91 case 'a':
92 case 'b':
93 case 'c':
94 case 'd':
95 case 'e':
96 case 'f':
97 c = (c << 4) + *s++ - 'a' + 10;
98 break;
99 case 'A':
100 case 'B':
101 case 'C':
102 case 'D':
103 case 'E':
104 case 'F':
105 c = (c << 4) + *s++ - 'A' + 10;
106 break;
107 case '0':
108 case '1':
109 case '2':
110 case '3':
111 case '4':
112 case '5':
113 case '6':
114 case '7':
115 case '8':
116 case '9':
117 c = (c << 4) + *s++ - '0';
118 break;
119 default:
120 q = 0;
121 break;
122 }
123 break;
124 case 'E':
125 c = CC_esc;
126 break;
127 case 0:
128 s--;
129 break;
130 default:
131 break;
132 }
133 break;
134 default:
135 break;
136 }
137 if (p)
138 *p = (char *) s;
139 return c;
140}
#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:24
Definition grammar.c:90