diff options
author | Vincent Sanders <vince@kyllikki.org> | 2020-06-15 09:06:25 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2020-06-15 09:06:25 +0100 |
commit | f31fb08c73b9f4c93f3f89fa865715502afcf390 (patch) | |
tree | 7a0d1e4050b9faa3c6ac9b49df09cb526e8568cf /utils | |
parent | b0a3eba82d691b550aa7221049738bfa7cd0fc60 (diff) | |
download | netsurf-f31fb08c73b9f4c93f3f89fa865715502afcf390.tar.gz netsurf-f31fb08c73b9f4c93f3f89fa865715502afcf390.tar.bz2 |
add gzip compression support to c split-messages implementation
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Makefile | 2 | ||||
-rw-r--r-- | utils/split-messages.c | 18 |
2 files changed, 14 insertions, 6 deletions
diff --git a/utils/Makefile b/utils/Makefile index 01c5ee778..7b20978ca 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -35,4 +35,4 @@ $(TOOLROOT)/xxd: utils/xxd.c $(TOOLROOT)/created # $(TOOLROOT)/split-messages: utils/split-messages.c $(TOOLROOT)/created $(VQ)echo "BUILD CC: $@" - $(Q)$(BUILD_CC) $(BUILD_CFLAGS) -o $@ $< $(BUILD_LDFLAGS) + $(Q)$(BUILD_CC) $(BUILD_CFLAGS) -o $@ $< $(BUILD_LDFLAGS) -lz diff --git a/utils/split-messages.c b/utils/split-messages.c index 76224cba1..fa384feb2 100644 --- a/utils/split-messages.c +++ b/utils/split-messages.c @@ -9,6 +9,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <zlib.h> #include "errors.h" @@ -456,25 +457,32 @@ fatmessages_read(struct param *param, struct trnsltn_entry **tlist) static nserror message_write(struct param *param, struct trnsltn_entry *tlist) { - FILE *outf; + gzFile outf; + const char *mode; - outf = fopen(param->outfilename, "w"); + if (param->compress == 0) { + mode = "wbT"; + } else { + mode = "wb9"; + } + + outf = gzopen(param->outfilename, mode); if (outf == NULL) { perror("Unable to open output file"); return NSERROR_PERMISSION; } - fprintf(outf, + gzprintf(outf, "# This messages file is automatically generated from %s\n" "# at build-time. Please go and edit that instead of this.\n\n", param->infilename); while (tlist != NULL) { - fprintf(outf, "%s:%s\n", tlist->key, tlist->value); + gzprintf(outf, "%s:%s\n", tlist->key, tlist->value); tlist = tlist->next; } - fclose(outf); + gzclose(outf); return NSERROR_OK; } |