Compare commits
10 Commits
56b705b741
...
562449a727
Author | SHA1 | Date |
---|---|---|
|
562449a727 | |
|
3603776303 | |
|
8619caa1b6 | |
|
25f9d42e9f | |
|
d4d0cc1812 | |
|
466a76fcbc | |
|
3cf1948081 | |
|
b37d65b10f | |
|
2f51400fef | |
|
0cd1120020 |
8
Makefile
8
Makefile
|
@ -1,5 +1,5 @@
|
|||
BIN=webpage
|
||||
SRCS=main.c config.c page.c lexer.c
|
||||
SRCS=main.c config.c page.c lexer.c eval.c
|
||||
INC=.
|
||||
LIB=curl
|
||||
FLAGS=-Wall -Wextra -Og -g -ggdb -fvar-tracking
|
||||
|
@ -12,7 +12,11 @@ $(BIN) : $(SRCS)
|
|||
run : $(BIN)
|
||||
./$(BIN) $(input)
|
||||
|
||||
check :
|
||||
cppcheck --enable=all --suppress=missingIncludeSystem -I$(INC) .
|
||||
flawfinder .
|
||||
|
||||
clean :
|
||||
rm -f $(BIN) *.o
|
||||
|
||||
.PHONY : run clean
|
||||
.PHONY : run check clean
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
#include "eval.h"
|
||||
#include "format.h"
|
||||
#include "lexer.h"
|
||||
#include "form.h"
|
||||
|
||||
// TODO: BLOCKQUOTE OL PROGRESS CODE TABLE
|
||||
|
||||
#define PAGE_WIDTH 80
|
||||
|
||||
#define EXPAND_LIT(x) x, sizeof(x)
|
||||
|
||||
PageState state = {0};
|
||||
|
||||
void print_text(const char* text, int len){
|
||||
for (int i=0; i<len; i++){
|
||||
if (state.beginLine) printf("\n");
|
||||
|
||||
if (text[i] != '\n'){
|
||||
printf("%c", text[i]);
|
||||
state.y++;
|
||||
state.beginLine = 0;
|
||||
}
|
||||
|
||||
if (!state.beginLine && (state.y >= PAGE_WIDTH || text[i] == '\n')){
|
||||
state.y = 0;
|
||||
state.x++;
|
||||
state.beginLine = 1;
|
||||
}
|
||||
}
|
||||
|
||||
state.beginLine = state.beginLine || text[len] == '\n';
|
||||
}
|
||||
|
||||
void break_line(void){
|
||||
state.y = 0;
|
||||
state.x++;
|
||||
state.beginLine = 1;
|
||||
}
|
||||
|
||||
void evaluate(Token* token){
|
||||
if (token->type == TITLE)
|
||||
{
|
||||
printf(FC_BOLD);
|
||||
print_text(EXPAND_LIT("--- "));
|
||||
}
|
||||
else if (token->type == END_TITLE)
|
||||
{
|
||||
print_text(EXPAND_LIT(" ---"));
|
||||
printf(FC_nBOLD);
|
||||
break_line();
|
||||
}
|
||||
else if (token->type == UL){
|
||||
state.inList = 1;
|
||||
}
|
||||
else if (token->type == UL){
|
||||
state.inList = 0;
|
||||
}
|
||||
else if (token->type == LI)
|
||||
{
|
||||
break_line();
|
||||
print_text(EXPAND_LIT("- "));
|
||||
}
|
||||
else if (token->type == END_LI)
|
||||
{
|
||||
//print_text(EXPAND_LIT("\n"));
|
||||
}
|
||||
else if (token->type == STRONG || token->type == B)
|
||||
{
|
||||
printf(FC_BOLD);
|
||||
}
|
||||
else if (token->type == END_STRONG || token->type == END_B)
|
||||
{
|
||||
printf(FC_nBOLD);
|
||||
print_text(EXPAND_LIT(" "));
|
||||
}
|
||||
else if (token->type == EM || token->type == I)
|
||||
{
|
||||
printf(FC_ITA);
|
||||
}
|
||||
else if (token->type == END_EM || token->type == END_I)
|
||||
{
|
||||
printf(FC_nITA);
|
||||
}
|
||||
else if (token->type == IMG)
|
||||
{
|
||||
print_text(EXPAND_LIT("["));
|
||||
print_text(EXPAND_LIT("IMG"));
|
||||
print_text(EXPAND_LIT("]"));
|
||||
}
|
||||
else if (token->type == A)
|
||||
{
|
||||
print_text(EXPAND_LIT("["));
|
||||
char* s = malloc(sizeof(int)*2);
|
||||
sprintf(s, "%d", state.nbLink);
|
||||
print_text(s, strlen(s));
|
||||
state.nbLink++;
|
||||
free(s);
|
||||
print_text(EXPAND_LIT("]"));
|
||||
printf(FC_UDL);
|
||||
}
|
||||
else if (token->type == END_A)
|
||||
{
|
||||
printf(FC_nUDL);
|
||||
print_text(EXPAND_LIT(" "));
|
||||
}
|
||||
else if (token->type == P)
|
||||
{
|
||||
if (!state.inList) break_line();
|
||||
}
|
||||
else if (token->type == END_P)
|
||||
{
|
||||
break_line();
|
||||
}
|
||||
else if (token->type == TEXT)
|
||||
{
|
||||
print_text(token->value, token->len);
|
||||
}
|
||||
else if (token->type == H1 || token->type == H2 || token->type == H3 || token->type == H4 || token->type == H5 || token->type == H6)
|
||||
{
|
||||
break_line();
|
||||
printf(FC_BOLD);
|
||||
}
|
||||
else if (token->type == END_H1 || token->type == END_H2 || token->type == END_H3 || token->type == END_H4 || token->type == END_H5 || token->type == END_H6)
|
||||
{
|
||||
printf(FC_nBOLD);
|
||||
}
|
||||
else if (token->type == HR)
|
||||
{
|
||||
printf(FC_nUDL);
|
||||
break_line();
|
||||
print_text(EXPAND_LIT("-------------------------------------------------------------------------------"));
|
||||
}
|
||||
else if (token->type == BLOCKQUOTE)
|
||||
{
|
||||
print_text(EXPAND_LIT(" "));
|
||||
printf(FC_SWAP);
|
||||
}
|
||||
else if (token->type == END_BLOCKQUOTE)
|
||||
{
|
||||
printf(FC_nSWAP);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef EVAL_H
|
||||
#define EVAL_H
|
||||
|
||||
#include "lexer.h"
|
||||
|
||||
typedef struct PageState {
|
||||
int nbLink;
|
||||
int x;
|
||||
int y;
|
||||
int beginLine;
|
||||
int inList;
|
||||
} PageState;
|
||||
|
||||
void evaluate(Token* token);
|
||||
|
||||
#endif // EVAL_H
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef FORMAT_H
|
||||
#define FORMAT_H
|
||||
|
||||
// COLOR
|
||||
|
||||
#define FC_RES "\033[0m"
|
||||
#define FC_BOLD "\033[1m"
|
||||
#define FC_ITA "\033[3m"
|
||||
#define FC_UDL "\033[4m"
|
||||
#define FC_BIK "\033[5m"
|
||||
#define FC_SWAP "\033[7m"
|
||||
#define FC_HID "\033[8m"
|
||||
#define FC_STR "\033[9m"
|
||||
#define FC_DEF "\033[39m"
|
||||
#define FC_nBOLD "\033[22m"
|
||||
#define FC_nITA "\033[23m"
|
||||
#define FC_nUDL "\033[24m"
|
||||
#define FC_nBIK "\033[25m"
|
||||
#define FC_nSWAP "\033[27m"
|
||||
#define FC_nHID "\033[28m"
|
||||
#define FC_nSTR "\033[29m"
|
||||
#define FC_bDEF "\033[49m"
|
||||
|
||||
#define FC_BLK "\033[30m"
|
||||
#define FC_RED "\033[31m"
|
||||
#define FC_GRN "\033[32m"
|
||||
#define FC_YEL "\033[33m"
|
||||
#define FC_BLU "\033[34m"
|
||||
#define FC_MAG "\033[35m"
|
||||
#define FC_CYA "\033[36m"
|
||||
#define FC_WHI "\033[37m"
|
||||
|
||||
#define FC_lBLK "\033[90m"
|
||||
#define FC_lRED "\033[91m"
|
||||
#define FC_lGRN "\033[92m"
|
||||
#define FC_lYEL "\033[93m"
|
||||
#define FC_lBLU "\033[94m"
|
||||
#define FC_lMAG "\033[95m"
|
||||
#define FC_lCYA "\033[96m"
|
||||
#define FC_lWHI "\033[97m"
|
||||
|
||||
#define FC_bBLK "\033[40m"
|
||||
#define FC_bRED "\033[41m"
|
||||
#define FC_bGRN "\033[42m"
|
||||
#define FC_bYEL "\033[43m"
|
||||
#define FC_bBLU "\033[44m"
|
||||
#define FC_bMAG "\033[45m"
|
||||
#define FC_bCYA "\033[46m"
|
||||
#define FC_bWHI "\033[47m"
|
||||
|
||||
#define FC_blBLK "\033[100m"
|
||||
#define FC_blRED "\033[101m"
|
||||
#define FC_blGRN "\033[102m"
|
||||
#define FC_blYEL "\033[103m"
|
||||
#define FC_blBLU "\033[104m"
|
||||
#define FC_blMAG "\033[105m"
|
||||
#define FC_blCYA "\033[106m"
|
||||
#define FC_blWHI "\033[107m"
|
||||
|
||||
#endif // FORMAT_H
|
303
lexer.c
303
lexer.c
|
@ -1,6 +1,7 @@
|
|||
#include "lexer.h"
|
||||
|
||||
#define HTML_BALISE_LEN 12
|
||||
#define DA_LEN 64
|
||||
|
||||
typedef struct Cursor {
|
||||
int chunk;
|
||||
|
@ -17,68 +18,15 @@ Cursor prev = {
|
|||
.offset = -2,
|
||||
};
|
||||
|
||||
TokenType token_by_name(const char name[HTML_BALISE_LEN]);
|
||||
|
||||
void printtoken(Token* token){
|
||||
if (token == NULL){
|
||||
puts("NULL TOKEN");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (token->type) {
|
||||
case UNDEFINED_TYPE:
|
||||
printf("UNDEFINED_TYPE: ");
|
||||
break;
|
||||
case DONT_CARE:
|
||||
printf("DONT_CARE: ");
|
||||
break;
|
||||
case TEXT:
|
||||
printf("TEXT: ");
|
||||
break;
|
||||
case BODY:
|
||||
printf("BODY: ");
|
||||
break;
|
||||
case END_BODY:
|
||||
printf("END_BODY: ");
|
||||
break;
|
||||
case HTML:
|
||||
printf("HTML: ");
|
||||
break;
|
||||
case END_HTML:
|
||||
printf("END_HTML: ");
|
||||
break;
|
||||
case A:
|
||||
printf("A: ");
|
||||
break;
|
||||
case END_A:
|
||||
printf("END_A: ");
|
||||
break;
|
||||
case UL:
|
||||
printf("UL: ");
|
||||
break;
|
||||
case LI:
|
||||
printf("LI: ");
|
||||
break;
|
||||
case H1:
|
||||
printf("H1: ");
|
||||
break;
|
||||
case H2:
|
||||
printf("H2: ");
|
||||
break;
|
||||
case H3:
|
||||
printf("H3: ");
|
||||
break;
|
||||
case H4:
|
||||
printf("H4: ");
|
||||
break;
|
||||
case H5:
|
||||
printf("H5: ");
|
||||
break;
|
||||
case H6:
|
||||
printf("H6: ");
|
||||
break;
|
||||
default:
|
||||
printf("ERROR: UNKNOWN TOKEN: ");
|
||||
break;
|
||||
}
|
||||
printf("%d: ", token->type);
|
||||
|
||||
if (token->value == NULL){
|
||||
puts("'NO VALUE FOUND'");
|
||||
|
@ -126,60 +74,77 @@ void go_back(void){
|
|||
prev.offset--;
|
||||
|
||||
if (curr.chunk < 0 || curr.offset < 0){
|
||||
puts("ERROR: go way too back.");
|
||||
puts("ERROR: cursor got way too back.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
TokenType token_by_name(const char name[HTML_BALISE_LEN]){
|
||||
if (name == NULL){
|
||||
return UNDEFINED_TYPE;
|
||||
} else if (strncmp(name, "body", HTML_BALISE_LEN) == 0){
|
||||
return BODY;
|
||||
} else if (strncmp(name, "/body", HTML_BALISE_LEN) == 0){
|
||||
return END_BODY;
|
||||
} else if (strncmp(name, "html", HTML_BALISE_LEN) == 0){
|
||||
return HTML;
|
||||
} else if (strncmp(name, "/html", HTML_BALISE_LEN) == 0){
|
||||
return END_HTML;
|
||||
} else if (strncmp(name, "a", HTML_BALISE_LEN) == 0){
|
||||
return A;
|
||||
} else if (strncmp(name, "/a", HTML_BALISE_LEN) == 0){
|
||||
return END_A;
|
||||
} else if (strncmp(name, "ul", HTML_BALISE_LEN) == 0){
|
||||
return UL;
|
||||
} else if (strncmp(name, "li", HTML_BALISE_LEN) == 0){
|
||||
return LI;
|
||||
} else if (strncmp(name, "h1", HTML_BALISE_LEN) == 0){
|
||||
return H1;
|
||||
} else if (strncmp(name, "h2", HTML_BALISE_LEN) == 0){
|
||||
return H2;
|
||||
} else if (strncmp(name, "h3", HTML_BALISE_LEN) == 0){
|
||||
return H3;
|
||||
} else if (strncmp(name, "h4", HTML_BALISE_LEN) == 0){
|
||||
return H4;
|
||||
} else if (strncmp(name, "h5", HTML_BALISE_LEN) == 0){
|
||||
return H5;
|
||||
} else if (strncmp(name, "h6", HTML_BALISE_LEN) == 0){
|
||||
return H6;
|
||||
}
|
||||
|
||||
return DONT_CARE;
|
||||
}
|
||||
|
||||
Token* create_text_token(Token* token, char* cursor){
|
||||
int i = 0;
|
||||
char* getParam(const char* word, int len, char* cursor, int* size){
|
||||
char* res = NULL;
|
||||
int found = 0;
|
||||
len--;
|
||||
|
||||
do {
|
||||
cursor = nextchar();
|
||||
for (int i=0; i<len; i++){
|
||||
if (word[i] != *cursor){
|
||||
found = -1;
|
||||
break;
|
||||
} else {
|
||||
found = 1;
|
||||
cursor = nextchar();
|
||||
}
|
||||
}
|
||||
|
||||
if (found == 1){
|
||||
while (*cursor != '"'){
|
||||
cursor = nextchar();
|
||||
}
|
||||
|
||||
int cap = DA_LEN;
|
||||
res = malloc(sizeof(char) * cap);
|
||||
*size = 0;
|
||||
|
||||
do {
|
||||
cursor = nextchar();
|
||||
res[*size] = *cursor;
|
||||
(*size)++;
|
||||
if (*size >= cap){
|
||||
cap *= 2;
|
||||
res = realloc(res, cap);
|
||||
}
|
||||
} while (*cursor != '"');
|
||||
|
||||
res[*size-1] = '\0';
|
||||
|
||||
break;
|
||||
}
|
||||
} while (*cursor != '>');
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Token* create_text_token(Token* token, char* cursor){
|
||||
token = malloc(sizeof(Token));
|
||||
token->value = malloc(sizeof(char) * DA_LEN);
|
||||
int i = 0, cap = DA_LEN;
|
||||
|
||||
go_back();
|
||||
do {
|
||||
cursor = nextchar();
|
||||
token->value[i] = *cursor;
|
||||
i++;
|
||||
if (i >= cap){
|
||||
cap *= 2;
|
||||
token->value = realloc(token->value, cap);
|
||||
}
|
||||
} while (*cursor != '<');
|
||||
token->value[i-1] = '\0';
|
||||
go_back();
|
||||
|
||||
token = malloc(sizeof(Token));
|
||||
token->type = TEXT;
|
||||
token->value = "TODO";
|
||||
token->len = i;
|
||||
token->len = i-1;
|
||||
|
||||
return token;
|
||||
}
|
||||
|
@ -197,9 +162,27 @@ Token* create_balise_token(Token* token, char* cursor){
|
|||
|
||||
token = malloc(sizeof(Token));
|
||||
token->type = token_by_name(balise);
|
||||
token->value = malloc(sizeof(char) * len);
|
||||
strncpy(token->value, balise, len+1);
|
||||
token->len = len;
|
||||
|
||||
if (token->type == A){
|
||||
token->value = getParam("href", sizeof("href"), cursor, &token->len);
|
||||
} else if (token->type == IMG) {
|
||||
int srclen, altlen, totallen;
|
||||
char* src = getParam("src", sizeof("src"), cursor, &srclen);
|
||||
char* alt = getParam("alt", sizeof("alt"), cursor, &altlen);
|
||||
totallen = srclen * altlen + 1;
|
||||
|
||||
token->value = malloc(sizeof(char) * (totallen));
|
||||
strncpy(token->value, src, srclen);
|
||||
token->value[srclen-1] = ' ';
|
||||
strncpy(token->value+srclen, alt, altlen);
|
||||
token->value[totallen] = '\0';
|
||||
token->len = totallen;
|
||||
|
||||
} else {
|
||||
token->value = malloc(sizeof(char) * len);
|
||||
strncpy(token->value, balise, len+1);
|
||||
token->len = len;
|
||||
}
|
||||
|
||||
go_back();
|
||||
do {
|
||||
|
@ -228,3 +211,121 @@ Token* nexttoken(void){
|
|||
|
||||
return token;
|
||||
}
|
||||
|
||||
TokenType token_by_name(const char name[HTML_BALISE_LEN]){
|
||||
if (name == NULL){
|
||||
return UNDEFINED_TYPE;
|
||||
} else if (strncmp(name, "body", HTML_BALISE_LEN) == 0){
|
||||
return BODY;
|
||||
} else if (strncmp(name, "/body", HTML_BALISE_LEN) == 0){
|
||||
return END_BODY;
|
||||
} else if (strncmp(name, "/html", HTML_BALISE_LEN) == 0){
|
||||
return END_HTML;
|
||||
} else if (strncmp(name, "title", HTML_BALISE_LEN) == 0){
|
||||
return TITLE;
|
||||
} else if (strncmp(name, "/title", HTML_BALISE_LEN) == 0){
|
||||
return END_TITLE;
|
||||
} else if (strncmp(name, "em", HTML_BALISE_LEN) == 0){
|
||||
return EM;
|
||||
} else if (strncmp(name, "/em", HTML_BALISE_LEN) == 0){
|
||||
return END_EM;
|
||||
} else if (strncmp(name, "i", HTML_BALISE_LEN) == 0){
|
||||
return I;
|
||||
} else if (strncmp(name, "/i", HTML_BALISE_LEN) == 0){
|
||||
return END_I;
|
||||
} else if (strncmp(name, "b", HTML_BALISE_LEN) == 0){
|
||||
return B;
|
||||
} else if (strncmp(name, "/b", HTML_BALISE_LEN) == 0){
|
||||
return END_B;
|
||||
} else if (strncmp(name, "strong", HTML_BALISE_LEN) == 0){
|
||||
return STRONG;
|
||||
} else if (strncmp(name, "/strong", HTML_BALISE_LEN) == 0){
|
||||
return END_STRONG;
|
||||
} else if (strncmp(name, "hr", HTML_BALISE_LEN) == 0){
|
||||
return HR;
|
||||
} else if (strncmp(name, "br", HTML_BALISE_LEN) == 0){
|
||||
return BR;
|
||||
} else if (strncmp(name, "p", HTML_BALISE_LEN) == 0){
|
||||
return P;
|
||||
} else if (strncmp(name, "/p", HTML_BALISE_LEN) == 0){
|
||||
return END_P;
|
||||
} else if (strncmp(name, "a", HTML_BALISE_LEN) == 0){
|
||||
return A;
|
||||
} else if (strncmp(name, "/a", HTML_BALISE_LEN) == 0){
|
||||
return END_A;
|
||||
} else if (strncmp(name, "ol", HTML_BALISE_LEN) == 0){
|
||||
return OL;
|
||||
} else if (strncmp(name, "/ol", HTML_BALISE_LEN) == 0){
|
||||
return END_OL;
|
||||
} else if (strncmp(name, "ul", HTML_BALISE_LEN) == 0){
|
||||
return UL;
|
||||
} else if (strncmp(name, "/ul", HTML_BALISE_LEN) == 0){
|
||||
return END_UL;
|
||||
} else if (strncmp(name, "li", HTML_BALISE_LEN) == 0){
|
||||
return LI;
|
||||
} else if (strncmp(name, "/li", HTML_BALISE_LEN) == 0){
|
||||
return END_LI;
|
||||
} else if (strncmp(name, "img", HTML_BALISE_LEN) == 0){
|
||||
return IMG;
|
||||
} else if (strncmp(name, "/img", HTML_BALISE_LEN) == 0){
|
||||
return END_IMG;
|
||||
} else if (strncmp(name, "blockquote", HTML_BALISE_LEN) == 0){
|
||||
return BLOCKQUOTE;
|
||||
} else if (strncmp(name, "/blockquote", HTML_BALISE_LEN) == 0){
|
||||
return END_BLOCKQUOTE;
|
||||
} else if (strncmp(name, "code", HTML_BALISE_LEN) == 0){
|
||||
return CODE;
|
||||
} else if (strncmp(name, "/code", HTML_BALISE_LEN) == 0){
|
||||
return END_CODE;
|
||||
} else if (strncmp(name, "h1", HTML_BALISE_LEN) == 0){
|
||||
return H1;
|
||||
} else if (strncmp(name, "h2", HTML_BALISE_LEN) == 0){
|
||||
return H2;
|
||||
} else if (strncmp(name, "h3", HTML_BALISE_LEN) == 0){
|
||||
return H3;
|
||||
} else if (strncmp(name, "h4", HTML_BALISE_LEN) == 0){
|
||||
return H4;
|
||||
} else if (strncmp(name, "h5", HTML_BALISE_LEN) == 0){
|
||||
return H5;
|
||||
} else if (strncmp(name, "h6", HTML_BALISE_LEN) == 0){
|
||||
return H6;
|
||||
} else if (strncmp(name, "/h1", HTML_BALISE_LEN) == 0){
|
||||
return END_H1;
|
||||
} else if (strncmp(name, "/h2", HTML_BALISE_LEN) == 0){
|
||||
return END_H2;
|
||||
} else if (strncmp(name, "/h3", HTML_BALISE_LEN) == 0){
|
||||
return END_H3;
|
||||
} else if (strncmp(name, "/h4", HTML_BALISE_LEN) == 0){
|
||||
return END_H4;
|
||||
} else if (strncmp(name, "/h5", HTML_BALISE_LEN) == 0){
|
||||
return END_H5;
|
||||
} else if (strncmp(name, "/h6", HTML_BALISE_LEN) == 0){
|
||||
return H6;
|
||||
} else if (strncmp(name, "table", HTML_BALISE_LEN) == 0){
|
||||
return TABLE;
|
||||
} else if (strncmp(name, "/table", HTML_BALISE_LEN) == 0){
|
||||
return END_TABLE;
|
||||
} else if (strncmp(name, "thead", HTML_BALISE_LEN) == 0){
|
||||
return THEAD;
|
||||
} else if (strncmp(name, "/thead", HTML_BALISE_LEN) == 0){
|
||||
return END_THEAD;
|
||||
} else if (strncmp(name, "tbody", HTML_BALISE_LEN) == 0){
|
||||
return TBODY;
|
||||
} else if (strncmp(name, "/tbody", HTML_BALISE_LEN) == 0){
|
||||
return END_TBODY;
|
||||
} else if (strncmp(name, "tr", HTML_BALISE_LEN) == 0){
|
||||
return TR;
|
||||
} else if (strncmp(name, "/tr", HTML_BALISE_LEN) == 0){
|
||||
return END_TR;
|
||||
} else if (strncmp(name, "th", HTML_BALISE_LEN) == 0){
|
||||
return TH;
|
||||
} else if (strncmp(name, "/th", HTML_BALISE_LEN) == 0){
|
||||
return END_TH;
|
||||
} else if (strncmp(name, "progress", HTML_BALISE_LEN) == 0){
|
||||
return PROGRESS;
|
||||
} else if (strncmp(name, "/progress", HTML_BALISE_LEN) == 0){
|
||||
return END_PROGRESS;
|
||||
}
|
||||
|
||||
return DONT_CARE;
|
||||
}
|
||||
|
|
18
lexer.h
18
lexer.h
|
@ -7,15 +7,27 @@
|
|||
|
||||
#include "page.h"
|
||||
|
||||
// 46 enum
|
||||
typedef enum TokenType {
|
||||
UNDEFINED_TYPE,
|
||||
DONT_CARE,
|
||||
TEXT,
|
||||
TITLE, END_TITLE,
|
||||
TEXT, END_HTML,
|
||||
BODY, END_BODY,
|
||||
HTML, END_HTML,
|
||||
A, END_A,
|
||||
UL, LI,
|
||||
IMG, END_IMG,
|
||||
BLOCKQUOTE, END_BLOCKQUOTE,
|
||||
CODE, END_CODE,
|
||||
HR, BR, P, END_P,
|
||||
PROGRESS, END_PROGRESS,
|
||||
STRONG, B, I, EM,
|
||||
END_STRONG, END_B, END_I, END_EM,
|
||||
UL, OL, LI, END_UL, END_OL, END_LI,
|
||||
TABLE, END_TABLE, THEAD,
|
||||
END_THEAD, TBODY, END_TBODY,
|
||||
TR, TH, END_TR, END_TH,
|
||||
H1, H2, H3, H4, H5, H6,
|
||||
END_H1, END_H2, END_H3, END_H4, END_H5, END_H6,
|
||||
} TokenType;
|
||||
|
||||
typedef struct Token {
|
||||
|
|
10
main.c
10
main.c
|
@ -1,18 +1,22 @@
|
|||
#include "config.h"
|
||||
#include "page.h"
|
||||
#include "lexer.h"
|
||||
#include "eval.h"
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
getUserConfig(argc, argv);
|
||||
getPage();
|
||||
|
||||
//printPage();
|
||||
|
||||
Token* token = NULL;
|
||||
do {
|
||||
token = nexttoken();
|
||||
printtoken(token);
|
||||
//evaluate(token);
|
||||
} while (token != NULL && token->type != END_BODY);
|
||||
evaluate(token);
|
||||
} while (token != NULL && token->type != END_HTML);
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue