|
|
|
@ -125,43 +125,45 @@ static char *resolve_input_path(const char *name) { |
|
|
|
*/ |
|
|
|
|
|
|
|
if (inputdir) { |
|
|
|
DS_CREATE(ds, 100); |
|
|
|
int rc_ds = 0; |
|
|
|
rc_ds |= ds_cat_str(&ds, inputdir); /* copy the dir name */ |
|
|
|
const size_t n = ds_get_length(&ds); /* end of copied dir name */ |
|
|
|
|
|
|
|
/* Append a directory separator if not present already */ |
|
|
|
const char ch_last = n > 0 ? inputdir[n - 1] : '\0'; |
|
|
|
if (ch_last != DIR_TERM |
|
|
|
DS_CREATE(ds, 100); |
|
|
|
int rc_ds = 0; |
|
|
|
rc_ds |= ds_cat_str(&ds, inputdir); /* copy the dir name */ |
|
|
|
const size_t n = ds_get_length(&ds); /* end of copied dir name */ |
|
|
|
|
|
|
|
/* Append a directory separator if not present already */ |
|
|
|
const char ch_last = n > 0 ? inputdir[n - 1] : '\0'; |
|
|
|
if (ch_last != DIR_TERM |
|
|
|
#ifdef _WIN32 |
|
|
|
&& ch_last != DIR_TERM_LINUX |
|
|
|
&& ch_last != DIR_TERM_LINUX |
|
|
|
#endif |
|
|
|
) { |
|
|
|
rc_ds |= ds_cat_char(&ds, DIR_TERM); |
|
|
|
} |
|
|
|
rc_ds |= ds_cat_str(&ds, name); /* append the file name */ |
|
|
|
) { |
|
|
|
rc_ds |= ds_cat_char(&ds, DIR_TERM); |
|
|
|
} |
|
|
|
rc_ds |= ds_cat_str(&ds, name); /* append the file name */ |
|
|
|
|
|
|
|
if (rc_ds != 0) { |
|
|
|
(void)fprintf(cp_err, "Unable to build \"dir\" path name " |
|
|
|
"in inp_pathresolve_at"); |
|
|
|
controlled_exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
if (rc_ds != 0) { |
|
|
|
(void)fprintf(cp_err, "Unable to build \"dir\" path name " |
|
|
|
"in inp_pathresolve_at"); |
|
|
|
controlled_exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
char *const r = resolve_path(ds_get_buf(&ds)); |
|
|
|
ds_free(&ds); |
|
|
|
return r; |
|
|
|
} else { |
|
|
|
DS_CREATE(ds, 100); |
|
|
|
if (ds_cat_printf(&ds, ".%c%s", DIR_TERM, name) != 0) { |
|
|
|
(void)fprintf(cp_err, |
|
|
|
char* const r = resolve_path(ds_get_buf(&ds)); |
|
|
|
ds_free(&ds); |
|
|
|
if (r) |
|
|
|
return r; |
|
|
|
} |
|
|
|
/* no inputdir, or not found rel. to inputdir: |
|
|
|
search rel. to current working directory */ |
|
|
|
DS_CREATE(ds, 100); |
|
|
|
if (ds_cat_printf(&ds, ".%c%s", DIR_TERM, name) != 0) { |
|
|
|
(void)fprintf(cp_err, |
|
|
|
"Unable to build \".\" path name in inp_pathresolve_at"); |
|
|
|
controlled_exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
char *const r = resolve_path(ds_get_buf(&ds)); |
|
|
|
ds_free(&ds); |
|
|
|
if (r != (char *)NULL) { |
|
|
|
return r; |
|
|
|
} |
|
|
|
controlled_exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
char *const r = resolve_path(ds_get_buf(&ds)); |
|
|
|
ds_free(&ds); |
|
|
|
if (r != (char *)NULL) { |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|