36 char *
G_basename(
char *filename,
const char *desired_ext)
39 char *dot = strrchr(filename,
'.');
58 char *sep_ptr = strchr(str, sep);
63 return len - (size_t)(sep_ptr - str) - 1;
79 double integer, decimal;
81 integer = floor(number);
89 sprintf(intfmt,
"%%0%zud", ndigits);
91 sprintf(intstr, intfmt, (
int)integer);
94 sprintf(decfmt,
"_%%0%zud", ndecimals);
95 decimal = ((number - integer) * pow(10., (
double)ndecimals));
96 sprintf(decstr, decfmt, (
int)decimal);
98 result =
G_malloc(strlen(intstr) + strlen(decstr) + 1);
99 sprintf(result,
"%s%s", intstr, decstr);
111 char *envvar =
"GRASS_BASENAME_SEPARATOR";
114 envsep = getenv(envvar);
128 size_t i, length, lensep;
134 lensep = strlen(separator);
135 length = lensep * (len - 1) + 1;
136 for (i = 0; i < len; i++) {
137 length += strlen(strings[i]);
142 strcpy(result, strings[0]);
143 for (i = 1; i < len; i++) {
144 strcat(result, separator);
145 strcat(result, strings[i]);
165 char *separator, *numberstr, *result;
171 G_malloc(strlen(basename) + strlen(separator) + strlen(numberstr) + 1);
174 sprintf(result,
"%s%s%s", basename, separator, numberstr);
size_t G_get_num_decimals(const char *str)
Get number of decimals from a string.
char * G_join_basename_strings(const char **strings, size_t len)
join an array of strings using the basename separator
char * G_generate_basename(const char *basename, double number, size_t ndigits, size_t ndecimals)
Generate the format string.
char * G_basename(char *filename, const char *desired_ext)
Truncates filename to the base part (before the last '.') if it matches the extension,...
char * G_double_to_basename_format(double number, size_t ndigits, size_t ndecimals)
Convert a double to a string substituting the dot with underscore 12.3456 => '12_3456'.
char * G_get_basename_separator(void)
Return the environmental basename variable or the default value.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)