#include #include #include #include #include #include #include #include #include "code_point.h" #include "html_token.hpp" #include "tokenizer.hpp" #include using namespace matte; const char *argp_program_version = "html_parser 0.1"; const char *argp_program_bug_address = ""; static char doc[] = "A description of your program."; static char args_doc[] = "-f [FILENAME]..."; static struct argp_option options[] = { { "file", 'f', "FILE", 0, "File to parse."}, { 0 } }; struct Arguments { char* filename; }; static error_t parse_opt(int key, char *arg, struct argp_state *state) { Arguments* a = (Arguments*)state->input; switch (key) { case 'f': { a->filename = arg; break; } case ARGP_KEY_ARG: return 0; default: return ARGP_ERR_UNKNOWN; } return 0; } static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 }; int main(int argc, char *argv[]) { Arguments arguments; arguments.filename = nullptr; auto error = argp_parse(&argp, argc, argv, 0, 0, &arguments); if (arguments.filename == nullptr) { exit(EXIT_FAILURE); } FILE* file = fopen(arguments.filename, "rb"); if (file == NULL) { exit(EXIT_FAILURE); } code_point_t wc; code_point_t buffer[1024]; size_t ptr = 0; while ((wc=fgetwc(file))!=WEOF) { buffer[ptr++] = wc; } buffer[ptr] = '\0'; fclose(file); Tokenizer tokenizer = create(buffer); while (true ) { auto token = read_next(&tokenizer); token.print(); if (token.type == HtmlTokenType_EOF) { break; } } return EXIT_SUCCESS; }