On Sat, 07 Aug 1999 01:39:25 +0100, Arnd Hanses wrote:
>Better also let path through the underscore '_':
And even better would be better coding style (using some fancy macro):
This is all to be put into filetools.C
----------snip---------
// Let pass through FRIEND of LaTeX & shell; stop the foe:
// He's bound to sabotage... So apply REPLACER.
/* SMiyata: AND 0x7f a string bitwise 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-JIS and Big5 utilizes the region 0x80-0x9f which will be
converted to non-printable control characters.
AHanses: Used in 'toAsciiAlnum()'
*/
#define MASK_RANGE 127 /* LaTeX as such is '7-bit clean' */
#define FRIEND(c) (isalnum(c)||c==BLANK_MARK||c==SUFFIX_MARK)
#define SUFFIX_MARK '.' /* Let pass through the 'full-stop' */
#define BLANK_MARK '_' /* Let through the 'underscore' */
#define REPLACER 'x' /* Which is your favourite? */
[...]
// A premium selection of fine OS-specific hacks ;-)
// wrapped here for a cleaner code base (AHanses):
// A helper function for name picky processors; AHanses
inline static
LString toAsciiAlnum(LString const &string)
{
LString tmp(string);
for (int i = 0; i < tmp.length(); i++)
{
tmp[i] &= MASK_RANGE; // make the test result
// somewhat more foreseeable
/* SMiyata: AND 0x7f a string bitwise 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-JIS and Big5 utilizes the region 0x80-0x9f which will be
** converted to non-printable control characters.
*/
if ( FRIEND(tmp[i]) )
; /* Let them pass, they are friend of LaTeX & Co. */
else /* They are foe and bound to sabotage; stop them */
tmp[i] = REPLACER;
}
return tmp;
}
// Substitute chars that LaTeX or shell can't handle with safe ones
LString SpaceLess(LString const & file)
{
LString temp = toAsciiAlnum( OnlyFilename(file) );
/* AHanses: if >127, subtract
** 128, 256, etc., put REPLACER */
temp = AddName( OnlyPath(file), temp );
// Replace spaces with underscores, also in directory
temp.subst(' ','_');
return temp;
}
-----------snap-------------
Note:
I'm not sure why, but gcc -Wall doesn't give a damn warning in case of
suspicious code like this:
LString foo = (char*)bar;
Shouldn't there be one and how can this be achieved?
Cheers,
Arnd