diff options
author | Pixel <> | 2001-04-16 15:12:16 +0000 |
---|---|---|
committer | Pixel <> | 2001-04-16 15:12:16 +0000 |
commit | e09044e963015cf672d0f992264ee1563717602a (patch) | |
tree | 1a55d7d5e46401a41ca7bc24e597d90b0b720601 /lib/linker.c | |
parent | 3953a2906211a6c0007079dcafe66aa372ab33d1 (diff) |
Indentation
Diffstat (limited to 'lib/linker.c')
-rw-r--r-- | lib/linker.c | 143 |
1 files changed, 83 insertions, 60 deletions
diff --git a/lib/linker.c b/lib/linker.c index f28bc0f..b6930e3 100644 --- a/lib/linker.c +++ b/lib/linker.c @@ -13,31 +13,32 @@ /* Les quelques structures de données utiles */ typedef struct object_t { - Uint32 s_text, s_data, s_bss, * text, * data, textstart, datastart, bssstart; + Uint32 s_text, s_data, s_bss, *text, *data, textstart, datastart, bssstart; } object_t; typedef struct symbol_t { - char * name; + char *name; int objindex; Uint32 offset; int type; - struct symbol_t * next; + struct symbol_t *next; } symbol_t; /* Et les variables globales */ Uint32 startpoint = -1, textsize = 0, datasize = 0, bsssize = 0; -object_t ** objects; -symbol_t * symbols, * psymbols; +object_t **objects; +symbol_t *symbols, *psymbols; int objindex = 0, nbrsymbs = 0; _TableauVariable symbs; /* Quelques fonctions pour nous simplifier la vie... */ -static FILE * openfilewriting(char * name) { - FILE * f; +static FILE *openfilewriting(char *name) +{ + FILE *f; if (!(f = fopen(name, "wb"))) { pushcontext(strerror(errno)); @@ -46,8 +47,9 @@ static FILE * openfilewriting(char * name) { return f; } -static FILE * openfilereading(char * name) { - FILE * f; +static FILE *openfilereading(char *name) +{ + FILE *f; if (!(f = fopen(name, "rb"))) { pushcontext(strerror(errno)); @@ -56,7 +58,8 @@ static FILE * openfilereading(char * name) { return f; } -static void writeword(Uint32 a, FILE * f) { +static void writeword(Uint32 a, FILE * f) +{ if (fwrite(&a, sizeof(unsigned long int), 1, f) != 1) { if (ferror(f)) { pushcontext(strerror(errno)); @@ -65,7 +68,8 @@ static void writeword(Uint32 a, FILE * f) { } } -static Uint32 readword(FILE * f) { +static Uint32 readword(FILE * f) +{ Uint32 a; if (fread(&a, sizeof(a), 1, f) != 1) { @@ -74,9 +78,10 @@ static Uint32 readword(FILE * f) { return a; } -static char * readstring(FILE * f) { +static char *readstring(FILE * f) +{ Uint32 s; - char * r; + char *r; int i; s = readword(f); @@ -90,19 +95,20 @@ static char * readstring(FILE * f) { /* Rajoute un symbole dans la pile */ -static void addsymbol(char * name, int offset, int type) { - symbol_t * newsymbol; - +static void addsymbol(char *name, int offset, int type) +{ + symbol_t *newsymbol; + newsymbol = (symbol_t *) Emalloc(sizeof(symbol_t)); newsymbol->next = NULL; newsymbol->type = type; newsymbol->offset = offset; newsymbol->objindex = objindex; newsymbol->name = name; - + psymbols->next = newsymbol; psymbols = newsymbol; - + if (newsymbol->type & 1) { nbrsymbs++; } else { @@ -112,11 +118,12 @@ static void addsymbol(char * name, int offset, int type) { /* Rajoute un fichier dans les structures */ -void addfile(char * nom) { - FILE * f; +void addfile(char *nom) +{ + FILE *f; Uint32 start, nbsymbols, type, offset; int i; - char * snom, errctx[BUFSIZ]; + char *snom, errctx[BUFSIZ]; f = openfilereading(nom); sprintf(errctx, _("Processing file %s"), nom); @@ -125,18 +132,18 @@ void addfile(char * nom) { if (readword(f) != 0x4f424e4e) { exception(1, _("Bad signature")); } - - readword(f); /* Taille du fichier */ + + readword(f); /* Taille du fichier */ start = readword(f); if ((startpoint != -1) && (start != -1)) { exception(1, _("Startpoint already defined.")); } startpoint = start; - + objects[objindex]->s_text = readword(f); objects[objindex]->s_data = readword(f); objects[objindex]->s_bss = readword(f); - readword(f); /* Taille de la table des symboles */ + readword(f); /* Taille de la table des symboles */ nbsymbols = readword(f); pushcontext(_("Reading symbols")); @@ -147,7 +154,7 @@ void addfile(char * nom) { addsymbol(snom, offset, type); } popcontext(); - + objects[objindex]->textstart = textsize; objects[objindex]->datastart = datasize; objects[objindex]->bssstart = bsssize; @@ -165,7 +172,7 @@ void addfile(char * nom) { } popcontext(); fclose(f); - + textsize += objects[objindex]->s_text; datasize += objects[objindex]->s_data; bsssize += objects[objindex]->s_bss; @@ -176,7 +183,8 @@ void addfile(char * nom) { /* Simplification de vie... */ -static void dumptab(Uint32 * tab, int s, FILE * f) { +static void dumptab(Uint32 * tab, int s, FILE * f) +{ int i; for (i = 0; i < s; i++) { @@ -186,18 +194,21 @@ static void dumptab(Uint32 * tab, int s, FILE * f) { /* Nous dumpons la mémoire dans le fichier */ -static void dumptext(object_t * obj, FILE * f) { +static void dumptext(object_t * obj, FILE * f) +{ dumptab(obj->text, obj->s_text, f); } -static void dumpdata(object_t * obj, FILE * f) { +static void dumpdata(object_t * obj, FILE * f) +{ dumptab(obj->data, obj->s_data, f); } /* Cette fonction va calculer les quelques relogements statiques et dynamiques que nous a laissé l'assembleur */ -static void dumprelog(FILE * f) { - symbol_t * s = symbols, * t; +static void dumprelog(FILE * f) +{ + symbol_t *s = symbols, *t; char trouve, err[BUFSIZ]; for (s = s->next; s; s = s->next) { @@ -207,17 +218,20 @@ static void dumprelog(FILE * f) { sprintf(err, _("Symbol %s not found"), s->name); exception(1, err); } - switch(s->type) { - case 1: /* text */ - switch(t->type) { + switch (s->type) { + case 1: /* text */ + switch (t->type) { case 0: - objects[s->objindex]->text[s->offset] += objects[t->objindex]->textstart + t->offset; + objects[s->objindex]->text[s->offset] += + objects[t->objindex]->textstart + t->offset; break; case 2: - objects[s->objindex]->text[s->offset] += textsize + objects[t->objindex]->datastart + t->offset; + objects[s->objindex]->text[s->offset] += + textsize + objects[t->objindex]->datastart + t->offset; break; case 4: - objects[s->objindex]->text[s->offset] += textsize + datasize + objects[t->objindex]->bssstart + t->offset; + objects[s->objindex]->text[s->offset] += + textsize + datasize + objects[t->objindex]->bssstart + t->offset; break; default: exception(1, _("Internal error")); @@ -225,16 +239,19 @@ static void dumprelog(FILE * f) { } writeword(objects[s->objindex]->textstart + s->offset, f); break; - case 3: /* data */ - switch(t->type) { + case 3: /* data */ + switch (t->type) { case 0: - objects[s->objindex]->data[s->offset] += objects[t->objindex]->textstart + t->offset; + objects[s->objindex]->data[s->offset] += + objects[t->objindex]->textstart + t->offset; break; case 2: - objects[s->objindex]->data[s->offset] += textsize + objects[t->objindex]->datastart + t->offset; + objects[s->objindex]->data[s->offset] += + textsize + objects[t->objindex]->datastart + t->offset; break; case 4: - objects[s->objindex]->data[s->offset] += textsize + datasize + objects[t->objindex]->bssstart + t->offset; + objects[s->objindex]->data[s->offset] += + textsize + datasize + objects[t->objindex]->bssstart + t->offset; break; default: exception(1, _("Internal error")); @@ -252,17 +269,18 @@ static void dumprelog(FILE * f) { /* Cette fonction sert à écrire le fichier de sortie. */ -void dumpfile(char * nom) { - FILE * f; +void dumpfile(char *nom) +{ + FILE *f; int i; pushcontext(_("Writing output file")); f = openfilewriting(nom); - + if (startpoint == -1) { exception(1, _("No startpoint defined.")); } - + pushcontext(_("Writing headers")); writeword(0x58454e4e, f); writeword(nbrsymbs + textsize + datasize + 7, f); @@ -284,50 +302,55 @@ void dumpfile(char * nom) { dumpdata(objects[i], f); } popcontext(); - + popcontext(); - fprintf(stderr, _("Statistics: %i words of text, %i words of data and reserving %i words\n"), textsize, datasize, bsssize); + fprintf(stderr, _("Statistics: %i words of text, %i words of data and reserving %i words\n"), textsize, + datasize, bsssize); fprintf(stderr, _("Output file size: %i words containing %i relocating offsets.\n"), ftell(f), nbrsymbs); fclose(f); } /* Fonctions d'initialisations et de libération de mémoire */ -void init(int n) { +void init(int n) +{ int i; - + Initialise(&symbs); objects = (object_t **) Emalloc(n * sizeof(object_t *)); psymbols = symbols = (symbol_t *) Emalloc(sizeof(symbol_t)); - + for (i = 0; i < n; i++) { objects[i] = (object_t *) Emalloc(sizeof(object_t)); - objects[i]->s_text = objects[i]->s_data = objects[i]->s_bss = objects[i]->textstart = objects[i]->datastart = 0; + objects[i]->s_text = objects[i]->s_data = objects[i]->s_bss = objects[i]->textstart = + objects[i]->datastart = 0; objects[i]->text = objects[i]->data = NULL; } - + symbols->next = NULL; } -void free_symbol(symbol_t * s) { +void free_symbol(symbol_t * s) +{ if (s->next) free_symbol(s); - + free(s->name); free(s); } -void flush(void) { +void flush(void) +{ int i; - + DetruitTab(&symbs); for (i = 0; i < objindex; i++) { if (objects[i]->text) free(objects[i]->text); - if (objects[i]->data); - free(objects[i]->data); + if (objects[i]->data) ; + free(objects[i]->data); free(objects[i]); } free(objects); |