#include "auto.h" #include <stdio.h> auto_t new_auto(auto_t old) { auto_t new; new = malloc(sizeof(struct auto_s)); new->type = 0; new->value = malloc(100); new->len = 0; new->next = 0; if (old != 0) { old->next = new; } return new; } auto_t start_auto(char* content, size_t len) { auto_head header; auto_t automaton; header = malloc(sizeof(struct auto_head_s)); automaton = new_auto(0); header->content = content; header->pos = 0; header->length = len; header->lauto = automaton; strauto(header); return automaton; } void debug_auto(auto_t automaton) { fputs("*****AUTOMATON******\n", stderr); while (automaton != 0) { fprintf(stderr, "AUTO BLOCK\n\ Type: %u\n\ Value: %s\n\ Length: %u\n\n", automaton->type, automaton->value, automaton->len); automaton = automaton->next; } fputs("******END AUTOMATON******\n\n", stderr); } void varauto(auto_head head) { char c; /* Start a new compileline */ head->lauto = new_auto(head->lauto); c = head->content[head->pos]; head->pos++; while(c != ' ' && c != '}' && head->lauto->len < 99) { head->lauto->value[head->lauto->len] = c; c = head->content[head->pos]; head->pos++; head->lauto->len++; } head->lauto->type = 1; head->lauto->value[head->lauto->len] = 0; //End string } void balauto(auto_head head) { char c = head->content[head->pos]; if (c == '$') { head->pos++; varauto(head); } } void strauto(auto_head header) { char c; header->length--; while (header->pos < header->length) { c = header->content[header->pos]; header->pos++; /* It's a balise */ if (c == '{') { balauto(header); header->lauto = new_auto(header->lauto); } /* No juste a char */ else { if (header->lauto->len % 100 == 0) //End of the buffer, want more space { header->lauto->value = realloc(header->lauto->value, header->lauto->len + 100); } header->lauto->value[header->lauto->len] = c; header->lauto->len++; } } }