comparison macro.c @ 128:1cda505ddc78

Don't expand macros within character constants.
author David A. Holland
date Fri, 14 Jun 2013 20:59:24 -0400
parents c13f36775fe8
children 2e1496dd96c4
comparison
equal deleted inserted replaced
127:a0a86380456e 128:1cda505ddc78
1064 doexpand(struct expstate *es, struct place *p, char *buf, size_t len) 1064 doexpand(struct expstate *es, struct place *p, char *buf, size_t len)
1065 { 1065 {
1066 char *s; 1066 char *s;
1067 size_t x; 1067 size_t x;
1068 bool inquote = false; 1068 bool inquote = false;
1069 char quote = '\0';
1069 1070
1070 while (len > 0) { 1071 while (len > 0) {
1071 x = strspn(buf, ws); 1072 x = strspn(buf, ws);
1072 if (x > len) { 1073 if (x > len) {
1073 /* XXX gross, need strnspn */ 1074 /* XXX gross, need strnspn */
1126 buf++; 1127 buf++;
1127 len--; 1128 len--;
1128 continue; 1129 continue;
1129 } 1130 }
1130 1131
1131 if (len > 1 && buf[0] == '\\' && buf[1] == '"') { 1132 if (len > 1 && buf[0] == '\\' &&
1133 (buf[1] == '"' || buf[1] == '\'')) {
1132 expand_got_other(es, p, buf, 2); 1134 expand_got_other(es, p, buf, 2);
1133 buf += 2; 1135 buf += 2;
1134 len -= 2; 1136 len -= 2;
1135 continue; 1137 continue;
1136 } 1138 }
1137 if (buf[0] == '"') { 1139 if (!inquote && (buf[0] == '"' || buf[0] == '\'')) {
1138 inquote = !inquote; 1140 inquote = true;
1141 quote = buf[0];
1142 } else if (inquote && buf[0] == quote) {
1143 inquote = false;
1139 } 1144 }
1140 1145
1141 expand_got_other(es, p, buf, 1); 1146 expand_got_other(es, p, buf, 1);
1142 buf++; 1147 buf++;
1143 len--; 1148 len--;