Well,
this works on my box even for unprintable control characters, they are
simply ommitted. (Did not test every possible 8 bit combination, too
lazy to write a test program).
Is this safe on all UNICES?
Better ideas someone?
More generic approach desirable?
Shall I submit a patch or better wait?
Is this correct C++ syntax? (Please note, I can speak only a bit of C,
so please stay patient with me)
Greets,
Arnd
LString.C:
--------------- ----------
/* SMiyata: Bitwise AND 0x7f the string is more efficient than subst();
** ISO-8859-x and EUC (Extended Unix Code) works just fine with this.
** The only remaining problem is that Microsoft/IBM codepages,
** Shift-JISand Big5 utilizes the region 0x80-0x9f which will be
** converted to non-printable control characters.
*/
LString& LString::discardSign(LString&) /* AHanses: rewrite for const?
*/
{
for (int i=0; i<length(); i++)
p->s[i] &= 0x7f;
return *this;
}
---------- ----------------
filetools.C:
---------- ----------------
// Substitutes spaces with underscores in filename (and path)
LString SpaceLess(LString const & file)
{
LString name = OnlyFilename(file);
LString path = OnlyPath(file);
// Substitute chars that LaTeX can't handle with safe ones
name.discardSign(name); /* AHanses: lower bits remain untouched
*/
name.subst('~','-');
name.subst('$','S');
name.subst('%','_');
name.subst('\'','_');
// Substitute some more chars that LaTeX or /bin/sh can't
handle -ck-
name.subst('`', '_');
name.subst('"', '_');
name.subst('&', 'G');
name.subst('|', 'I');
name.subst(';', ','); /* AHanses: The Murphy-circle ':',
';', ':',... fix! */
name.subst('(', 'c');
name.subst(')', 'C');
name.subst('<', 'k');
name.subst('>', 'K');
LString temp = AddName(path, name);
// Replace spaces with underscores, also in directory
temp.subst(' ','_');
/* AHanses: Seems to handle 'umlauts' in directory
correctly, too */
return temp;
}
---------- ----------------