25 tokenizer->
input = input;
75 token.
type = N_GUI_TOKEN_EOF;
85 *inside_open_tag =
false;
86 token.
type = N_GUI_TOKEN_TAG_CLOSE;
89 *inside_open_tag =
true;
90 token.
type = N_GUI_TOKEN_TAG_OPEN;
99 *inside_open_tag =
false;
100 token.
type = N_GUI_TOKEN_TAG_CLOSE;
108 token.
type = N_GUI_TOKEN_ATTR_VALUE;
110 if (ch ==
'"' || ch ==
'\'') {
119 token.
value[pos] =
'\0';
125 if (*inside_open_tag && (isalpha(ch) || ch ==
'-') ) {
132 token.
value[pos] =
'\0';
136 token.
type = N_GUI_TOKEN_ATTR_NAME;
138 token.
type = N_GUI_TOKEN_TAG_NAME;
144 if (ch !=
'<' && ch !=
'>') {
145 if (!*inside_open_tag) {
147 while (ch !=
'<' && ch !=
'>' && !
n_gui_is_eof(tokenizer)) {
153 token.
value[pos] =
'\0';
154 token.
type = N_GUI_TOKEN_TEXT;
172 switch (token.
type) {
173 case N_GUI_TOKEN_TAG_OPEN: printf(
"N_GUI_TOKEN_TAG_OPEN: %s\n", token.
value);
break;
174 case N_GUI_TOKEN_TAG_CLOSE: printf(
"N_GUI_TOKEN_TAG_CLOSE: %s\n", token.
value);
break;
175 case N_GUI_TOKEN_TAG_NAME: printf(
"N_GUI_TOKEN_TAG_NAME: %s\n", token.
value);
break;
176 case N_GUI_TOKEN_ATTR_NAME: printf(
"N_GUI_TOKEN_ATTR_NAME: %s\n", token.
value);
break;
177 case N_GUI_TOKEN_ATTR_VALUE: printf(
"N_GUI_TOKEN_ATTR_VALUE: %s\n", token.
value);
break;
178 case N_GUI_TOKEN_TEXT: printf(
"N_GUI_TOKEN_TEXT: %s\n", token.
value);
break;
179 case N_GUI_TOKEN_EOF: printf(
"N_GUI_TOKEN_EOF\n");
break;
197 N_STR *nstr_css = NULL ;
210 bool inside_open_tag =
false;
211 while ((token =
n_gui_next_token(&tokenizer, &inside_open_tag)).type != N_GUI_TOKEN_EOF) {
212 switch (token.
type) {
213 case N_GUI_TOKEN_TAG_OPEN:
218 case N_GUI_TOKEN_TAG_CLOSE:
222 case N_GUI_TOKEN_TAG_NAME:
226 case N_GUI_TOKEN_ATTR_NAME:
230 case N_GUI_TOKEN_ATTR_VALUE:
234 case N_GUI_TOKEN_TEXT:
238 case N_GUI_TOKEN_EOF:
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
#define N_ENUM_DEFINE(MACRO_DEFINITION, enum_name)
Macro to define an N_ENUM.
char value[N_GUI_MAX_TOKEN_SIZE]
token content
size_t position
position in the input text
const char * input
pointer to the input text
char n_gui_next_char(N_GUI_TOKENIZER *tokenizer)
Get next character from input.
void n_gui_print_token(N_GUI_TOKEN token)
Function to print a token (for debugging purposes)
int n_gui_is_eof(N_GUI_TOKENIZER *tokenizer)
char n_gui_peek_char(N_GUI_TOKENIZER *tokenizer)
Peek at next character without advancing the position.
N_GUI_DIALOG * n_gui_load_dialog(char *html, char *css)
Load a html + css file into a N_GUI_DIALOG.
#define N_GUI_MAX_TOKEN_SIZE
maximum size of a single token content
void n_gui_init_tokenizer(N_GUI_TOKENIZER *tokenizer, const char *input)
Initialize tokenizer.
N_GUI_TOKEN n_gui_next_token(N_GUI_TOKENIZER *tokenizer, bool *inside_open_tag)
Read next N_GUI_TOKEN from input.
structure of a N_GUI_DIALOG
structure of a N_GUI_TOKENIZER token
structure of a N_GUI_DIALOG tokenizer
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
N_STR * file_to_nstr(char *filename)
Load a whole file into a N_STR.
A box including a string and his lenght.
Common headers and low-level hugly functions & define.
N_ENUM_N_GUI_TOKEN
N_GUI context codes.
__N_GUI_TOKEN
type for a token
N_STR and string function declaration.