Pipe input to textconv
This avoids a situation when make thinks it has successfully built the target, after textconv fails for some reason.
This commit is contained in:
parent
95c6bc20b4
commit
964aba4831
2 changed files with 61 additions and 24 deletions
6
Makefile
6
Makefile
|
@ -590,12 +590,10 @@ endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(BUILD_DIR)/text/%/define_courses.inc.c: text/define_courses.inc.c text/%/courses.h
|
$(BUILD_DIR)/text/%/define_courses.inc.c: text/define_courses.inc.c text/%/courses.h
|
||||||
$(CPP) $(VERSION_CFLAGS) $< -o $@ -I text/$*/
|
$(CPP) $(VERSION_CFLAGS) $< -o - -I text/$*/ | $(TEXTCONV) charmap.txt - $@
|
||||||
$(TEXTCONV) charmap.txt $@ $@
|
|
||||||
|
|
||||||
$(BUILD_DIR)/text/%/define_text.inc.c: text/define_text.inc.c text/%/courses.h text/%/dialogs.h
|
$(BUILD_DIR)/text/%/define_text.inc.c: text/define_text.inc.c text/%/courses.h text/%/dialogs.h
|
||||||
$(CPP) $(VERSION_CFLAGS) $< -o $@ -I text/$*/
|
$(CPP) $(VERSION_CFLAGS) $< -o - -I text/$*/ | $(TEXTCONV) charmap.txt - $@
|
||||||
$(TEXTCONV) charmap.txt $@ $@
|
|
||||||
|
|
||||||
RSP_DIRS := $(BUILD_DIR)/rsp
|
RSP_DIRS := $(BUILD_DIR)/rsp
|
||||||
ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(TEXT_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION) $(RSP_DIRS)
|
ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(TEXT_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION) $(RSP_DIRS)
|
||||||
|
|
|
@ -54,6 +54,8 @@ static void parse_error(const char *filename, int lineNum, const char *msgfmt, .
|
||||||
// Reads the whole file and returns a null-terminated buffer with its contents
|
// Reads the whole file and returns a null-terminated buffer with its contents
|
||||||
void *read_text_file(const char *filename)
|
void *read_text_file(const char *filename)
|
||||||
{
|
{
|
||||||
|
if (strcmp(filename, "-") != 0)
|
||||||
|
{
|
||||||
FILE *file = fopen(filename, "rb");
|
FILE *file = fopen(filename, "rb");
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -67,6 +69,8 @@ void *read_text_file(const char *filename)
|
||||||
|
|
||||||
// allocate buffer
|
// allocate buffer
|
||||||
buffer = malloc(size + 1);
|
buffer = malloc(size + 1);
|
||||||
|
if (buffer == NULL)
|
||||||
|
fatal_error("could not allocate buffer of size %u", (uint32_t)(size + 1));
|
||||||
|
|
||||||
// read file
|
// read file
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
|
@ -79,6 +83,40 @@ void *read_text_file(const char *filename)
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t size = 0;
|
||||||
|
size_t capacity = 1024;
|
||||||
|
uint8_t *buffer = malloc(capacity + 1);
|
||||||
|
|
||||||
|
if (buffer == NULL)
|
||||||
|
fatal_error("could not allocate buffer of size %u", (uint32_t)(capacity + 1));
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
size += fread(buffer + size, 1, capacity - size, stdin);
|
||||||
|
if (size == capacity)
|
||||||
|
{
|
||||||
|
capacity *= 2;
|
||||||
|
buffer = realloc(buffer, capacity + 1);
|
||||||
|
if (buffer == NULL)
|
||||||
|
fatal_error("could not allocate buffer of size %u", (uint32_t)(capacity + 1));
|
||||||
|
}
|
||||||
|
else if (feof(stdin))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fatal_error("error reading from stdin: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// null-terminate the buffer
|
||||||
|
buffer[size] = 0;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *skip_whitespace(char *str)
|
static char *skip_whitespace(char *str)
|
||||||
|
@ -351,7 +389,7 @@ static char *convert_string(char *pos, FILE *fout, const char *inputFileName, ch
|
||||||
static void convert_file(const char *infilename, const char *outfilename)
|
static void convert_file(const char *infilename, const char *outfilename)
|
||||||
{
|
{
|
||||||
char *in = read_text_file(infilename);
|
char *in = read_text_file(infilename);
|
||||||
FILE *fout = fopen(outfilename, "wb");
|
FILE *fout = strcmp(outfilename, "-") != 0 ? fopen(outfilename, "wb") : stdout;
|
||||||
|
|
||||||
if (fout == NULL)
|
if (fout == NULL)
|
||||||
fatal_error("failed to open file '%s' for writing: %s", strerror(errno));
|
fatal_error("failed to open file '%s' for writing: %s", strerror(errno));
|
||||||
|
@ -436,6 +474,7 @@ static void convert_file(const char *infilename, const char *outfilename)
|
||||||
|
|
||||||
eof:
|
eof:
|
||||||
fwrite(start, pos - start, 1, fout);
|
fwrite(start, pos - start, 1, fout);
|
||||||
|
if (strcmp(outfilename, "-") != 0)
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
free(in);
|
free(in);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue