Skip to content

Commit f6ce2b9

Browse files
handle parsing path for basename
1 parent 5218968 commit f6ce2b9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

code/logic/common.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,14 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
323323
}
324324
} else if (strncmp(argv[i], "config=", 7) == 0) {
325325
const char* config_file = argv[i] + 7;
326-
if (pizza_io_cstr_compare(config_file, "pizza_test.ini") == 0) {
326+
const char* basename = strrchr(config_file, '/');
327+
if (!basename) {
328+
basename = config_file; // No '/' found, use the entire filename
329+
} else {
330+
basename++; // Skip the '/'
331+
}
332+
333+
if (pizza_io_cstr_compare(basename, "pizza_test.ini") == 0) {
327334
pallet.config_file = config_file;
328335
} else {
329336
pizza_io_printf("{red}Error: Invalid configuration file name. Must be 'pizza_test.ini'.{reset}\n");
@@ -390,14 +397,21 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
390397
// *****************************************************************************
391398

392399
int fossil_pizza_ini_parse(const char *filename, fossil_pizza_pallet_t *pallet) {
393-
if (pizza_io_cstr_compare(filename, "pizza_test.ini") != 0) {
400+
const char *basename = strrchr(filename, '/');
401+
if (!basename) {
402+
basename = filename; // No '/' found, use the entire filename
403+
} else {
404+
basename++; // Skip the '/'
405+
}
406+
407+
if (pizza_io_cstr_compare(basename, "pizza_test.ini") != 0) {
394408
fprintf(stderr, "Error: INI file must be named 'pizza_test.ini'.\n");
395409
return -1;
396410
}
397411

398412
FILE *file = fopen(filename, "r");
399413
if (!file) {
400-
fprintf(stderr, "Error: Unable to open INI file: %s\n", filename);
414+
fprintf(stderr, "Error: Unable to open INI file: %s\n", basename);
401415
return -1;
402416
}
403417

0 commit comments

Comments
 (0)