fix output paths

pull/2/head
cosmonaut 2022-07-26 12:45:08 -07:00
parent 03222b0826
commit 50daba69a3
1 changed files with 12 additions and 4 deletions

View File

@ -112,6 +112,7 @@ int main(int argc, char *argv[])
char *arg; char *arg;
char *inputDirPath = NULL; char *inputDirPath = NULL;
char *outputDirPath = NULL; char *outputDirPath = NULL;
char separatorString[2];
char *imageOutputFilename; char *imageOutputFilename;
char *metadataFilename; char *metadataFilename;
JsonBuilder *jsonBuilder; JsonBuilder *jsonBuilder;
@ -119,6 +120,9 @@ int main(int argc, char *argv[])
int32_t imageCount; int32_t imageCount;
int32_t i; int32_t i;
separatorString[0] = SEPARATOR;
separatorString[1] = '\0';
/* Set defaults */ /* Set defaults */
createInfo.padding = 0; createInfo.padding = 0;
createInfo.trim = 1; createInfo.trim = 1;
@ -213,8 +217,10 @@ int main(int argc, char *argv[])
/* output pixel data */ /* output pixel data */
Cram_GetPixelData(context, &pixelData, &width, &height); Cram_GetPixelData(context, &pixelData, &width, &height);
imageOutputFilename = malloc(strlen(createInfo.name) + 5); imageOutputFilename = malloc(strlen(outputDirPath) + strlen(createInfo.name) + 6);
strcpy(imageOutputFilename, createInfo.name); strcpy(imageOutputFilename, outputDirPath);
strcat(imageOutputFilename, separatorString);
strcat(imageOutputFilename, createInfo.name);
strcat(imageOutputFilename, ".png"); strcat(imageOutputFilename, ".png");
stbi_write_png( stbi_write_png(
@ -252,8 +258,10 @@ int main(int argc, char *argv[])
JsonBuilder_FinishArrayProperty(jsonBuilder); JsonBuilder_FinishArrayProperty(jsonBuilder);
JsonBuilder_Finish(jsonBuilder); JsonBuilder_Finish(jsonBuilder);
metadataFilename = malloc(strlen(createInfo.name) + 6); metadataFilename = malloc(strlen(outputDirPath) + strlen(createInfo.name) + 7);
strcpy(metadataFilename, createInfo.name); strcpy(metadataFilename, outputDirPath);
strcat(metadataFilename, separatorString);
strcat(metadataFilename, createInfo.name);
strcat(metadataFilename, ".json"); strcat(metadataFilename, ".json");
FILE *jsonOutput = fopen(metadataFilename, "w"); FILE *jsonOutput = fopen(metadataFilename, "w");