1 /* Copyright 1986-1992 Emmet P. Gray.
2 * Copyright 1996-1998,2001,2002,2007,2009 Alain Knaff.
3 * This file is part of mtools.
5 * Mtools is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Mtools is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
18 * A program to create a manifest (shipping list) that is a shell script
19 * to return a Unix file name to it's original state after it has been
20 * clobbered by MSDOS's file name restrictions.
22 * This code also used in arc, mtools, and pcomm
25 #include "sysincludes.h"
29 static char *dos_name2(const char *name);
31 int main(int argc, char **argv)
37 /* print the version */
38 if(argc >= 2 && strcmp(argv[1], "-V") == 0) {
39 printf("Mtools version %s, dated %s\n", mversion, mdate);
44 fprintf(stderr, "Usage: mkmanifest [-V] <list-of-files>\n");
48 for (i=1; i<argc; i++) {
49 /* zap the leading path */
50 name = _basename(argv[i]);
52 new_name = dos_name2(name);
54 if (strcasecmp(new_name, name))
55 printf("mv %s %s\n", new_name, name);
60 static char *dos_name2(const char *name)
62 static const char *dev[9] = {"con", "aux", "com1", "com2", "lpt1",
63 "prn", "lpt2", "lpt3", "nul"};
70 strncpy(buf, name, MAX_PATH-1);
72 /* separate the name from extension */
75 for (i=strlen(buf)-1; i>=0; i--) {
76 if (buf[i] == '.' && !dot) {
81 if (isupper((unsigned char)buf[i]))
82 buf[i] = tolower((unsigned char)buf[i]);
88 /* if name is a device */
90 if (!strcasecmp(temp, dev[i]))
96 /* extension too long? */
97 if (ext && strlen(ext) > 3)
99 /* illegal characters? */
100 while ((s = strpbrk(temp, "^+=/[]:',?*\\<>|\". ")))
103 while (ext && (s = strpbrk(ext, "^+=/[]:',?*\\<>|\". ")))
105 strncpy(ans, temp, 12);