diff options
author | Ian C <ianc@noddybox.co.uk> | 2016-05-06 16:12:42 +0100 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2016-05-06 16:12:42 +0100 |
commit | d3713129e61a8953a61b8f15f7be6a3110197ed5 (patch) | |
tree | 2b6bc2e0ca728dc17bb3fbcba7632b6a929797e4 /src/label.c | |
parent | 0b3c0e2a2e347db8af3f29d4dc8c86797981bc85 (diff) |
Added simple library format.
Diffstat (limited to 'src/label.c')
-rw-r--r-- | src/label.c | 107 |
1 files changed, 106 insertions, 1 deletions
diff --git a/src/label.c b/src/label.c index 0807128..5fdc83e 100644 --- a/src/label.c +++ b/src/label.c @@ -57,8 +57,57 @@ static char namespace[MAX_LABEL_SIZE + 1]; static Stack *stack; -/* ---------------------------------------- PRIVATE FUNCTIONS INTERFACES +/* ---------------------------------------- PRIVATE FUNCTIONS */ + +static void WriteNumber(FILE *fp, int num) +{ + fprintf(fp, "%.11d", num); +} + + +static int ReadNumber(FILE *fp) +{ + char buff[12]; + int f; + + for(f= 0 ;f < 11; f++) + { + buff[f] = getc(fp); + } + + buff[f] = 0; + + return atoi(buff); +} + + +static void WriteName(FILE *fp, const char *name) +{ + fputs(name, fp); + putc(0, fp); +} + + +static char *ReadName(FILE *fp, char *name) +{ + int l = MAX_LABEL_SIZE; + int c; + char *p; + + p = name; + + while((c = getc(fp)) && (l--)) + { + *p++ = c; + } + + *p = 0; + + return name; +} + + static Label *FindLocal(const char *p, GlobalLabel *in) { int f; @@ -465,6 +514,62 @@ void LabelDump(FILE *fp, int dump_private) } } + +void LabelWriteBlob(FILE *fp) +{ + GlobalLabel *g = head; + int count; + int f; + + count = 0; + + while(g) + { + if (g->label.name[0] != '_') + { + count++; + } + + g = g->next; + } + + WriteNumber(fp, count); + + g = head; + + while(g) + { + if (g->label.name[0] != '_') + { + WriteName(fp, g->label.name); + WriteNumber(fp, g->label.value); + } + + g = g->next; + } +} + + +void LabelReadBlob(FILE *fp) +{ + int count; + int f; + + count = ReadNumber(fp); + + for(f = 0; f < count; f++) + { + char name[MAX_LABEL_SIZE + 1]; + int value; + + ReadName(fp, name); + value = ReadNumber(fp); + + LabelSet(name, value, GLOBAL_LABEL); + } +} + + /* vim: ai sw=4 ts=8 expandtab */ |