Originally Posted by
Yonut
If the questions are from you wanting me to 'consider this', then maybe you should answer them.
As for non-displayed ASCII characters, how many files have you downloaded or created that have non-displayed ASCII characters in them? And why are you trying to create them that way?!?
And the period, or 'dot' as you put it, in the filenames are interpreted as spaces. And a period can be encoded for things like `Mr.`, `vs.` or even '...'. Extensions are ignored.
It's not in the list, and no it won't be added.
I cannot answer the questions because they are policy questions, not technical ones. Nothing I have shown you will fail to work depending on how you decide - the questions are just things that invite a "management" decision rather than a "programming" decision.
Non-displayed ASCII characters are such a problem that the GNU project has modified the CLI of many standard utilities to support accepting filenames delimited with ASCII NUL bytes, in an attempt to handle every possible flavor of filename. (Except, obviously, those with NULs in. ;-) Look for utilities that take a -0 (dash zero) flag.
Handling the periods as spaces is fine, that would fit into the lookup table without any extra effort.
Something like this:
Code:
#define DOT(ch) [ch] = '.'
#define SELF(ch) [ch] = (ch)
#define NOP(ch) [ch] = 0
static char Fix_chars[256] = {
// Non-graphic ASCII chars
NOP(0), NOP(1), NOP(2), /* lots of these */
SELF(' '), ... SELF('A'), ... SELF('Z'), ... SELF('a'), ... SELF('z'),
// Specials
DOT('\''), DOT(','), DOT(';'), DOT('"'), ..., DOT('@'),
// High-bit chars? I have no idea.
};
int
fix_filename(
const char *filename,
int for_tv)
{
char * new_name = sm_malloc(PATH_MAX);
for (char *in = filename, *out=new_name; *in != `\0'; ++in) {
int fix = Fix_chars[*in];
switch (fix) {
case 0: // skip the character entirely
break;
case '.': // special processing
*out = '\0'; // end string here so add_character can find it
add_character(*in, new_name);
// Move forward to end-of-string, which might be *out already,
// if add_character() adds nothing.
while (*out != '\0')
++out;
break;
default:
*out++ = fix;
break;
}
}
*out = '\0';
// optionally shrink allocated buffer
char *n2 = realloc(new_name, strlen(new_name) + 1);
return n2 ? n2 : new_name;
}