comparison macro.c @ 85:c91dc1315745

Don't expand macros inside comments.
author David A. Holland
date Mon, 10 Jun 2013 21:36:24 -0400
parents 7e4723d34248
children 2b153df78214
comparison
equal deleted inserted replaced
84:7e4723d34248 85:c91dc1315745
1049 1049
1050 static 1050 static
1051 void 1051 void
1052 doexpand(struct expstate *es, struct place *p, char *buf, size_t len) 1052 doexpand(struct expstate *es, struct place *p, char *buf, size_t len)
1053 { 1053 {
1054 char *s;
1054 size_t x; 1055 size_t x;
1056 bool inquote = false;
1055 1057
1056 while (len > 0) { 1058 while (len > 0) {
1057 x = strspn(buf, ws); 1059 x = strspn(buf, ws);
1058 if (x > len) { 1060 if (x > len) {
1059 /* XXX gross, need strnspn */ 1061 /* XXX gross, need strnspn */
1078 buf += x; 1080 buf += x;
1079 len -= x; 1081 len -= x;
1080 continue; 1082 continue;
1081 } 1083 }
1082 1084
1085 if (!inquote && len > 1 && buf[0] == '/' && buf[1] == '*') {
1086 s = strstr(buf, "*/");
1087 if (s) {
1088 x = s - buf;
1089 } else {
1090 x = len;
1091 }
1092 expand_got_ws(es, p, buf, x);
1093 buf += x;
1094 len -= x;
1095 continue;
1096 }
1097
1083 if (buf[0] == '(') { 1098 if (buf[0] == '(') {
1084 expand_got_lparen(es, p, buf, 1); 1099 expand_got_lparen(es, p, buf, 1);
1085 buf++; 1100 buf++;
1086 len--; 1101 len--;
1087 continue; 1102 continue;
1099 buf++; 1114 buf++;
1100 len--; 1115 len--;
1101 continue; 1116 continue;
1102 } 1117 }
1103 1118
1119 if (len > 1 && buf[0] == '\\' && buf[1] == '"') {
1120 expand_got_other(es, p, buf, 2);
1121 buf += 2;
1122 len -= 2;
1123 continue;
1124 }
1125 if (buf[0] == '"') {
1126 inquote = !inquote;
1127 }
1128
1104 expand_got_other(es, p, buf, 1); 1129 expand_got_other(es, p, buf, 1);
1105 buf++; 1130 buf++;
1106 len--; 1131 len--;
1107 } 1132 }
1108 } 1133 }