diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/assembler.c | 20 | ||||
-rw-r--r-- | lib/exceptions.c | 29 | ||||
-rw-r--r-- | lib/hash.c | 5 | ||||
-rw-r--r-- | lib/meta.c | 31 | ||||
-rw-r--r-- | lib/numbers.c | 1 | ||||
-rw-r--r-- | lib/parser.c | 2 |
7 files changed, 75 insertions, 15 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 4d66b47..b463138 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,7 +4,7 @@ AM_CFLAGS = -O3 -Wall -Wstrict-prototypes $(CFLAGS) INCLUDES = -I. -I.. -I$(includedir) -I../include lib_LTLIBRARIES = libCompilo.la -libCompilo_la_SOURCES = assembler.c parser.c meta.c numbers.c hash.h +libCompilo_la_SOURCES = assembler.c parser.c meta.c numbers.c hash.c exceptions.c libCompilo_la_LDFLAGS = -version-info $(ProjetArchi_VERSION_INFO) diff --git a/lib/assembler.c b/lib/assembler.c index e69de29..3fd358c 100644 --- a/lib/assembler.c +++ b/lib/assembler.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "meta.h" +#include "hash.h" +#include "parser.h" + + +void push_pile(char * a) { +} + +void act_pile(int o) { +} + +int assembler_init(void) { + return 0; +} + +void assembler_flush(void) { +} diff --git a/lib/exceptions.c b/lib/exceptions.c new file mode 100644 index 0000000..349e8a9 --- /dev/null +++ b/lib/exceptions.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "config.h" +#include "exceptions.h" + +char * Estrdup(char * o) { + char * r; + + if (!(r = strdup(o))) { + exception(1, _("Out of memory.")); + } + return r; +} + +void * Emalloc(size_t s) { + void * r; + + if (!(r = malloc(s))) { + exception(1, _("Out of memory.")); + } + return r; +} + +void exception(int level, char *msg) +{ + fprintf(stderr, "%s\n", msg); + exit(level); +} @@ -2,7 +2,6 @@ #include <stdlib.h> #include <string.h> #include "hash.h" -#include "global.h" static char *CHAINEHACHAGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; static void TraitementDesErreurs(int codeerreur) @@ -100,7 +99,7 @@ static void Detruit(_ListeChaine * l) { _ListeChaine l_aux = NULL; while (*l) { - l_aux = l->Suivant; + l_aux = (*l)->Suivant; free((*l)->Elem.NomVar); free(*l); *l = l_aux; @@ -182,6 +181,8 @@ int Initialise(_TableauVariable * t) } void DetruitTab(_TableauVariable * t){ + int i; + for (i = 0; i < strlen(CHAINEHACHAGE); i++) { Detruit(&((*t)[i])); } @@ -10,7 +10,7 @@ void exception(int, char *); char * Estrdup(char *); void * Emalloc(size_t); #endif -#include "global.h" +#include "exceptions.h" #include "numbers.h" #include "meta.h" @@ -448,6 +448,25 @@ void meta_flush(void) { instructs = NULL; } +int meta_load(char * n) { + FILE * f; + char buf[BUFSIZ], *p; + + if (!(f = fopen(n, "r"))) { + return 1; + } + while (fgets(buf, BUFSIZ, f)) { + if ((p = strchr(buf, '\r'))) { + *p = '\0'; + } + if ((p = strchr(buf, '\n'))) { + *p = '\0'; + } + meta_parse_line(buf); + } + return 0; +} + #ifndef HAVE_CONFIG_H char * Estrdup(char * o) { char * r; @@ -475,8 +494,6 @@ void exception(int level, char *msg) void main(void) { - FILE *f; - char buf[BUFSIZ], *p; phon_t *phon; field_t *field; pattern_t *pattern; @@ -486,13 +503,7 @@ void main(void) if (meta_init()) exception(1, _("Meta parser init failed.")); - f = fopen("instructions.txt", "r"); - while (fgets(buf, BUFSIZ, f)) { - if ((p = strchr(buf, '\n'))) { - *p = '\0'; - } - meta_parse_line(buf); - } + meta_load("instructions.txt"); fprintf(stderr, "\nListe des phonèmes:\n"); for (phon = phons->next; phon; phon = phon->next) { diff --git a/lib/numbers.c b/lib/numbers.c index ba45f29..8334dd4 100644 --- a/lib/numbers.c +++ b/lib/numbers.c @@ -1,4 +1,3 @@ -#include "global.h" #include "numbers.h" int char_to_number(char *st, int *valid) diff --git a/lib/parser.c b/lib/parser.c index a2947e6..ee3e64c 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -6,7 +6,7 @@ #define _(x) x void exception(int, char *); #endif -#include "global.h" +#include "exceptions.h" #include "parser.h" |