38 char *
G_basename(
char *filename,
const char *desired_ext)
41 char *dot = strrchr(filename,
'.');
62 char *sep_ptr = strchr(str, sep);
66 return len - (size_t)(sep_ptr - str) - 1;
80 size_t ndigits,
size_t ndecimals)
83 integer = floor(number);
91 sprintf(intfmt,
"%%0%zud", ndigits);
93 sprintf(intstr, intfmt, (
int)integer);
96 sprintf(decfmt,
"_%%0%zud", ndecimals);
97 decimal = ((number -
integer) * pow(10., (
double)ndecimals));
98 sprintf(decstr, decfmt, (
int)decimal);
100 result =
G_malloc(strlen(intstr) + strlen(decstr) + 1);
101 sprintf(result,
"%s%s", intstr, decstr);
114 char *envvar =
"GRASS_BASENAME_SEPARATOR";
132 size_t i, length, lensep;
138 lensep = strlen(separator);
139 length = lensep * (len - 1) + 1;
140 for (i = 0; i < len; i++){
141 length += strlen(strings[i]);
147 strcpy(result, strings[0]);
148 for (i = 1; i < len; i++){
149 strcat(result, separator);
150 strcat(result, strings[i]);
169 size_t ndigits,
size_t ndecimals)
171 char *separator, *numberstr, *result;
176 result =
G_malloc(strlen(basename) + strlen(separator) + strlen(numberstr) + 1);
179 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_get_basename_separator()
Return the environmental basename variable or the default value.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
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, otherwise leaves it unchanged.
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'.