| 1 | "); Token *tokens = tokenize(str, len); for(int i = 0; tokens[i].kind != T_DONE; i += 1) { if(!table_mode) if(i == 0 || tokens[i-1].kind == T_NEWL) buff_printf(&buff, " "); switch(tokens[i].kind) { case T_DONE: assert(0); break; case T_NEWL: if(table_mode) for(int j = 0; j < tokens[i].len; j += 1) { lineno += 1; buff_printf(&buff, " |
| %d | ", lineno);
}
else {
lineno += tokens[i].len;
for(int j = 0; j < tokens[i].len; j += 1)
buff_printf(&buff, " \n"); } break; case T_SPACE: buff_puts(&buff, str + tokens[i].off, tokens[i].len); break; case T_TAB: for(int j = 0; j < tokens[i].len; j += 1) buff_printf(&buff, " "); break; case T_KWORD: buff_printf(&buff, "%.*s", class_prefix, class_prefix, tokens[i].len, str + tokens[i].off, tokens[i].len, str + tokens[i].off); break; case T_VSTR: buff_printf(&buff, "", class_prefix); print_escaped(&buff, str + tokens[i].off, tokens[i].len); buff_printf(&buff, ""); break; case T_VCHAR: buff_printf(&buff, "", class_prefix); print_escaped(&buff, str + tokens[i].off, tokens[i].len); buff_printf(&buff, ""); break; case T_VINT: buff_printf(&buff, "%.*s", class_prefix, tokens[i].len, str + tokens[i].off); break; case T_VFLT: buff_printf(&buff, "%.*s", class_prefix, tokens[i].len, str + tokens[i].off); break; case T_FDECLNAME: buff_printf(&buff, "%.*s", class_prefix, class_prefix, tokens[i].len, str + tokens[i].off); break; case T_FCALLNAME: buff_printf(&buff, "%.*s", class_prefix, class_prefix, tokens[i].len, str + tokens[i].off); break; case T_IDENTIFIER: buff_printf(&buff, "%.*s", class_prefix, tokens[i].len, str + tokens[i].off); break; case T_COMMENT: { long j = tokens[i].off; long end = j + tokens[i].len; while(1) { long line_off = j; while(j < end && str[j] != '\n') j += 1; long line_len = j - line_off; buff_printf(&buff, "", class_prefix); print_escaped(&buff, str + line_off, line_len); buff_printf(&buff, ""); if(j == end) break; j += 1; // Skip the '\n'. lineno += 1; if(table_mode) buff_printf(&buff, " |
| %d | ", lineno);
else
buff_printf(&buff, " \n"); } break; } case T_OPERATOR: buff_printf(&buff, "", class_prefix); print_escaped(&buff, str + tokens[i].off, tokens[i].len); buff_printf(&buff, ""); break; case T_DIRECTIVE: buff_printf(&buff, "", class_prefix); print_escaped(&buff, str + tokens[i].off, tokens[i].len); buff_printf(&buff, ""); break; default: buff_printf(&buff, "%c", str[tokens[i].off]); break; } } if(table_mode) buff_printf(&buff, " |