add gzip compression support to c split-messages implementation

This commit is contained in:
Vincent Sanders 2020-06-15 09:06:25 +01:00
parent b0a3eba82d
commit f31fb08c73
2 changed files with 14 additions and 6 deletions

View File

@ -35,4 +35,4 @@ $(TOOLROOT)/xxd: utils/xxd.c $(TOOLROOT)/created
# #
$(TOOLROOT)/split-messages: utils/split-messages.c $(TOOLROOT)/created $(TOOLROOT)/split-messages: utils/split-messages.c $(TOOLROOT)/created
$(VQ)echo "BUILD CC: $@" $(VQ)echo "BUILD CC: $@"
$(Q)$(BUILD_CC) $(BUILD_CFLAGS) -o $@ $< $(BUILD_LDFLAGS) $(Q)$(BUILD_CC) $(BUILD_CFLAGS) -o $@ $< $(BUILD_LDFLAGS) -lz

View File

@ -9,6 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <zlib.h>
#include "errors.h" #include "errors.h"
@ -456,25 +457,32 @@ fatmessages_read(struct param *param, struct trnsltn_entry **tlist)
static nserror static nserror
message_write(struct param *param, struct trnsltn_entry *tlist) 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) { if (outf == NULL) {
perror("Unable to open output file"); perror("Unable to open output file");
return NSERROR_PERMISSION; return NSERROR_PERMISSION;
} }
fprintf(outf, gzprintf(outf,
"# This messages file is automatically generated from %s\n" "# This messages file is automatically generated from %s\n"
"# at build-time. Please go and edit that instead of this.\n\n", "# at build-time. Please go and edit that instead of this.\n\n",
param->infilename); param->infilename);
while (tlist != NULL) { while (tlist != NULL) {
fprintf(outf, "%s:%s\n", tlist->key, tlist->value); gzprintf(outf, "%s:%s\n", tlist->key, tlist->value);
tlist = tlist->next; tlist = tlist->next;
} }
fclose(outf); gzclose(outf);
return NSERROR_OK; return NSERROR_OK;
} }