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

2
main.c
View File

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