Imported Upstream version 4.0.18
[platform/upstream/mtools.git] / mshortname.c
1 /*  Copyright 2010 Alain Knaff.
2  *  This file is part of mtools.
3  *
4  *  Mtools is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  Mtools is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  * mshortname.c
18  * Change MSDOS file attribute flags
19  */
20
21 #include "sysincludes.h"
22 #include "msdos.h"
23 #include "mtools.h"
24 #include "mainloop.h"
25
26 static int print_short_name(direntry_t *entry, MainParam_t *mp)
27 {
28         fprintShortPwd(stdout, entry);
29         putchar('\n');
30         return GOT_ONE;
31 }
32
33
34 static void usage(int ret) NORETURN;
35 static void usage(int ret)
36 {
37         fprintf(stderr, "Mtools version %s, dated %s\n", 
38                 mversion, mdate);
39         fprintf(stderr, 
40                 "Usage: %s msdosfile [msdosfiles...]\n",
41                 progname);
42         exit(ret);
43 }
44
45 void mshortname(int argc, char **argv, int type)
46 {
47         struct MainParam_t mp;
48         int c;
49
50         if(helpFlag(argc, argv))
51                 usage(0);
52         while ((c = getopt(argc, argv, "i:h")) != EOF) {
53                 switch (c) {
54                         case 'i':
55                                 set_cmd_line_image(optarg);
56                                 break;
57                         case 'h':
58                                 usage(0);
59                         case '?':
60                                 usage(1);
61                 }
62         }
63
64         if(optind == argc) {
65                 usage(0);
66         }
67
68         if (optind >= argc)
69                 usage(1);
70
71         init_mp(&mp);
72         mp.callback = print_short_name;
73         mp.arg = NULL;
74         mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR;
75         exit(main_loop(&mp, argv + optind, argc - optind));
76 }