2 * Convert a Unix filename to a legal MSDOS name. Returns a pointer to
3 * the 'fixed' name. Will truncate file and extension names, will
4 * substitute the letter 'X' for any illegal character in the name.
12 fixname(filename
, verbose
)
16 static char *dev
[8] = {"CON", "AUX", "COM1", "LPT1", "PRN", "LPT2",
18 char *s
, *ans
, *name
, *ext
, *strcpy(), *strpbrk(), *strrchr();
19 char buf
[MAX_PATH
], *malloc();
23 strcpy(buf
, filename
);
25 /* zap the leading path */
26 if (s
= strrchr(name
, '/'))
28 if (s
= strrchr(name
, '\\'))
33 for (i
=strlen(buf
)-1; i
>=0; i
--) {
34 if (buf
[i
] == '.' && !dot
) {
40 buf
[i
] = toupper(buf
[i
]);
45 printf("\"%s\" Null name component, using \"%s.%s\"\n", filename
, name
, ext
);
48 if (!strcmp(name
, dev
[i
])) {
51 printf("\"%s\" Is a device name, using \"%s.%s\"\n", filename
, name
, ext
);
54 if (strlen(name
) > 8) {
57 printf("\"%s\" Name too long, using, \"%s.%s\"\n", filename
, name
, ext
);
59 if (strlen(ext
) > 3) {
62 printf("\"%s\" Extension too long, using \"%s.%s\"\n", filename
, name
, ext
);
65 while (s
= strpbrk(name
, "^+=/[]:',?*\\<>|\". ")) {
69 while (s
= strpbrk(ext
, "^+=/[]:',?*\\<>|\". ")) {
73 if (modified
&& verbose
)
74 printf("\"%s\" Contains illegal character(s), using \"%s.%s\"\n", filename
, name
, ext
);
77 sprintf(ans
, "%-8.8s%-3.3s", name
, ext
);