Allow alternate labels for patch names

This commit is contained in:
Rangi
2022-03-12 22:38:29 -05:00
parent 31c3c94d64
commit f33a041930
6 changed files with 55 additions and 48 deletions

View File

@@ -344,16 +344,26 @@ struct Buffer *process_template(const char *template_filename, const char *patch
case '[':
// "[...]" is a patch label; buffer its contents
putc(c, output);
bool alternate = false;
buffer->size = 0;
for (c = getc(input); c != EOF; c = getc(input)) {
putc(c, output);
if (c == ']') {
if (!alternate && c == '@') {
// "@" designates an alternate name for the ".VC_" label
alternate = true;
buffer->size = 0;
} else if (c == ']') {
putc(c, output);
break;
} else if (!isalnum(c) && c != '_' && c != '@' && c != '#') {
// Convert non-identifier characters to underscores
c = '_';
} else {
if (!alternate) {
putc(c, output);
if (!isalnum(c) && c != '_') {
// Convert non-identifier characters to underscores
c = '_';
}
}
buffer_append(buffer, &c);
}
buffer_append(buffer, &c);
}
buffer_append(buffer, &(char []){'\0'});
// The current patch should have a corresponding ".VC_" label