lexer: get param, A get link in value

This commit is contained in:
_N3m0 2024-01-03 20:00:08 +01:00
parent 3cf1948081
commit 466a76fcbc
2 changed files with 28 additions and 22 deletions

48
lexer.c
View File

@ -1,6 +1,4 @@
#include "lexer.h" #include "lexer.h"
#include <curl/curl.h>
#include <string.h>
#define HTML_BALISE_LEN 12 #define HTML_BALISE_LEN 12
@ -81,34 +79,45 @@ void go_back(void){
} }
char* getParam(const char* word, int len, char* cursor, int* size){ char* getParam(const char* word, int len, char* cursor, int* size){
printf("looking for '%s' word in %d char.\n", word, len); char* res = NULL;
int found = 0;
len--;
do { do {
printf("cursor: '%c' len: '%d'.\n", *cursor, len); cursor = nextchar();
int succes = 0; for (int i=0; i<len; i++){
for (int i=0; i<len && succes != -1; i++){ if (word[i] != *cursor){
if (word[i] == *cursor){ found = -1;
cursor = nextchar();
succes = 0;
} else {
succes = -1;
break; break;
} else {
found = 1;
cursor = nextchar();
} }
} }
if (succes != -1){ if (found == 1){
printf("get %s param: ", word); while (*cursor != '"'){
cursor = nextchar();
}
char* begin = nextchar();
*size = 0; *size = 0;
cursor = nextchar();
do { do {
printf("%c", *cursor); cursor = nextchar();
(*size)++; (*size)++;
} while (*cursor != '"'); } while (*cursor != '"');
printf(".\n");
}
cursor = nextchar(); res = malloc(sizeof(char) * ((*size)+1));
strncpy(res, begin, *size);
res[*size] = '\0';
break;
}
} while (*cursor != '>'); } while (*cursor != '>');
return NULL;
return res;
} }
Token* create_text_token(Token* token, char* cursor){ Token* create_text_token(Token* token, char* cursor){
@ -143,7 +152,6 @@ Token* create_balise_token(Token* token, char* cursor){
token->type = token_by_name(balise); token->type = token_by_name(balise);
if (token->type == A){ if (token->type == A){
printf("cursor status before passing param: '%c'.\n", *cursor);
token->value = getParam("href", sizeof("href"), cursor, &token->len); token->value = getParam("href", sizeof("href"), cursor, &token->len);
} /*else if (token->type == IMG){ } /*else if (token->type == IMG){
int len, srclen, altlen; int len, srclen, altlen;

2
main.c
View File

@ -7,8 +7,6 @@ int main(int argc, char* argv[]){
getUserConfig(argc, argv); getUserConfig(argc, argv);
getPage(); getPage();
printPage();
Token* token = NULL; Token* token = NULL;
do { do {
token = nexttoken(); token = nexttoken();