src/ccodegen.c

Sun, 19 Apr 2015 10:48:00 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Apr 2015 10:48:00 +0200
changeset 24
e43dee5892f4
parent 21
537aec525835
child 26
05c3c6842aef
permissions
-rw-r--r--

improved code structure and added option for disabling line numbers

21
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
4 * Copyright 2015 Mike Becker. All rights reserved.
21
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 *
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 */
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "ccodegen.h"
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 #include <string.h>
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 #include <ctype.h>
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 const char* ckeywords[] = {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 "auto", "break", "case", "char", "const", "continue", "default", "do",
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 "double", "else", "enum", "extern", "float", "for", "goto", "if", "int",
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 "long", "register", "return", "short", "signed", "sizeof", "static",
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 "struct", "switch", "typedef", "union", "unsigned", "void", "volatile",
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 "while", NULL
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 };
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 int isctype(char *word, size_t len) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 return (word[len-2] == '_' && word[len-1] == 't');
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 int iscdirective(char *word) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 return (word[0] == '#');
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 void cparseline(char *src, char *dest, highlighter_t *hltr) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 size_t sp = 0, dp = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 /* indent */
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 while (isspace(src[sp])) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 dest[dp++] = src[sp++];
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 memset(hltr->word, 0, WORDBUF_SIZE);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 size_t wp = 0, ifp = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 int isstring = 0, iscomment = 0, isinclude = 0, parseinclude = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 int isescaping = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 if (hltr->iscommentml) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 iscomment = 1;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 dp += 29;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 for (char c = src[sp] ; c ; c=src[++sp]) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 /* comments */
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 if (c == '/') {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 if (hltr->iscommentml && sp > 0 && src[sp-1] == '*') {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 iscomment = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 hltr->iscommentml = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 memcpy(&(dest[dp]), "/</span>", 8);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 dp += 8;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 continue;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 iscomment = 1;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 hltr->iscommentml = (src[sp+1] == '*');
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 dp += 29;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 if (iscomment) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 if (c == '\n') {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 memcpy(&(dest[dp]), "</span>", 7);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 dp += 7;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 } else if (isinclude) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 if (c == '<') {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 memcpy(&(dest[dp]), "<span class=\"c2html-stdinclude\">", 32);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 dp += 32;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 } else if (c == '\"') {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 if (parseinclude) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 dest[dp++] = '\"';
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 dest[dp++] = '>';
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 memcpy(&(dest[dp]), hltr->includefile, ifp);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 dp += ifp;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 memcpy(&(dest[dp]), "</a>", 4);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 dp += 4;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 parseinclude = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 memcpy(&(dest[dp]),
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 "<a class=\"c2html-userinclude\" href=", 35);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 dp += 35;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 ifp = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 hltr->includefile[ifp++] = '\"';
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 parseinclude = 1;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 } else if (c == '>') {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 memcpy(&(dest[dp]), "</span>", 7);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 dp += 7;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 if (parseinclude) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 hltr->includefile[ifp++] = c;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 /* strings */
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 if (!isescaping && (c == '\'' || c == '\"')) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 isstring ^= 1;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 if (isstring) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 memcpy(&(dest[dp]), "<span class=\"c2html-string\">", 28);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 dp += 28;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 memcpy(&(dest[dp]), "</span>", 7);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 dp += 7;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 if (isstring) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 } else if (!iswordcharacter(c)) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 /* interpret word int_t */
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 if (wp > 0 && wp < WORDBUF_SIZE) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 int closespan = 1;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 if (iskeyword(hltr->word, hltr->keywords)) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 memcpy(&(dest[dp]),
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 "<span class=\"c2html-keyword\">", 29);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 dp += 29;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 } else if (hltr->istype(hltr->word, wp)) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 memcpy(&(dest[dp]),
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 "<span class=\"c2html-type\">", 26);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 dp += 26;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 } else if (hltr->isdirective(hltr->word)) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 isinclude = !strncmp(
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 "#include", hltr->word, WORDBUF_SIZE);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 memcpy(&(dest[dp]),
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 "<span class=\"c2html-directive\">", 31);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 dp += 31;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 } else if (iscapsonly(hltr->word, wp)) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 memcpy(&(dest[dp]),
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 "<span class=\"c2html-macroconst\">", 32);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 dp += 32;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 closespan = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 for (int i = 0 ; i < wp ; i++) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 dp = writeescapedchar(dest, dp, hltr->word[i]);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 if (closespan) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 memcpy(&(dest[dp]), "</span>", 7);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 dp += 7;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 memset(hltr->word, 0, WORDBUF_SIZE);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 wp = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 /* read word */
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 if (wp < WORDBUF_SIZE) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 hltr->word[wp++] = c;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 } else if (wp == WORDBUF_SIZE) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 for (int i = 0 ; i < WORDBUF_SIZE ; i++) {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 dp = writeescapedchar(dest, dp, hltr->word[i]);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 wp++;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 } else {
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 dp = writeescapedchar(dest, dp, c);
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 isescaping = !isescaping & (c == '\\');
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 }
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 dest[dp] = 0;
537aec525835 structured source code
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 }

mercurial