50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
#include "collection.h"
|
|
#include "parse.h"
|
|
#include <assert.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
if (argc < 2) {
|
|
fprintf(stderr, "error: no filename\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
char* filename = argv[1];
|
|
char* text = read_textfile(filename);
|
|
if (!text) {
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
printf("--- text ---\n%s\n", text);
|
|
|
|
Preproc* preproc;
|
|
preproc_init(&preproc, strdup(filename), text);
|
|
|
|
printf("--- tokens ---\n");
|
|
|
|
int line = 1;
|
|
int col = 1;
|
|
Tok tok;
|
|
while ((tok = preproc_next(preproc)).ty != Tok_Eof) {
|
|
// printf("%s\t%s\n", tokty_str(tok.ty), tok.text);
|
|
while (line < tok.line) {
|
|
printf("\n");
|
|
line += 1;
|
|
col = 1;
|
|
}
|
|
while (col < tok.col) {
|
|
printf(" ");
|
|
col += 1;
|
|
}
|
|
printf("%s", tok.text);
|
|
line = tok.line;
|
|
col = tok.col + strlen(tok.text);
|
|
}
|
|
fputs("\n", stdout);
|
|
|
|
preproc_deinit(preproc);
|
|
}
|