comparison output.c @ 81:27c9aafcaca1

Don't recognize comments within double-quote strings. Blah.
author David A. Holland
date Mon, 10 Jun 2013 21:30:20 -0400
parents 4cc1c575951f
children 343af355df1b
comparison
equal deleted inserted replaced
80:7e64b1dd0a26 81:27c9aafcaca1
97 static 97 static
98 void 98 void
99 filter_output(const struct place *p, const char *buf, size_t len) 99 filter_output(const struct place *p, const char *buf, size_t len)
100 { 100 {
101 size_t pos, start; 101 size_t pos, start;
102 bool inesc = false;
103 bool inquote = false;
102 104
103 start = 0; 105 start = 0;
104 for (pos = 0; pos < len - 1; pos++) { 106 for (pos = 0; pos < len - 1; pos++) {
105 if (buf[pos] == '/' && buf[pos+1] == '*') { 107 if (!inquote && buf[pos] == '/' && buf[pos+1] == '*') {
106 if (!incomment) { 108 if (!incomment) {
107 if (pos > start) { 109 if (pos > start) {
108 dowrite(buf + start, pos - start); 110 dowrite(buf + start, pos - start);
109 } 111 }
110 start = pos; 112 start = pos;
124 incomment = false; 126 incomment = false;
125 /* cancel out the loop's pos++ */ 127 /* cancel out the loop's pos++ */
126 pos--; 128 pos--;
127 continue; 129 continue;
128 } 130 }
131 }
132
133 if (incomment) {
134 /* nothing */
135 } else if (inesc) {
136 inesc = false;
137 } else if (buf[pos] == '\\') {
138 inesc = true;
139 } else if (buf[pos] == '"') {
140 inquote = !inquote;
129 } 141 }
130 } 142 }
131 pos++; 143 pos++;
132 144
133 if (pos > start) { 145 if (pos > start) {