blob: 1e3aa967862bcc436cc4cc5d6b87d7643a521cb1 [file] [log] [blame]
Alistair Delvabeaee832021-02-24 11:27:23 -08001/* 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
26static int print_short_name(direntry_t *entry, MainParam_t *mp UNUSEDP)
27{
28 fprintShortPwd(stdout, entry);
29 putchar('\n');
30 return GOT_ONE;
31}
32
33
34static void usage(int ret) NORETURN;
35static void usage(int ret)
36{
Yi Kong39bbd962022-01-09 19:41:38 +080037 fprintf(stderr, "Mtools version %s, dated %s\n",
Alistair Delvabeaee832021-02-24 11:27:23 -080038 mversion, mdate);
Yi Kong39bbd962022-01-09 19:41:38 +080039 fprintf(stderr,
Alistair Delvabeaee832021-02-24 11:27:23 -080040 "Usage: %s msdosfile [msdosfiles...]\n",
41 progname);
42 exit(ret);
43}
44
45void mshortname(int argc, char **argv, int type UNUSEDP) NORETURN;
46void mshortname(int argc, char **argv, int type UNUSEDP)
47{
48 struct MainParam_t mp;
49 int c;
50
51 if(helpFlag(argc, argv))
52 usage(0);
53 while ((c = getopt(argc, argv, "i:h")) != EOF) {
54 switch (c) {
55 case 'i':
56 set_cmd_line_image(optarg);
57 break;
58 case 'h':
59 usage(0);
60 case '?':
61 usage(1);
62 }
63 }
64
65 if(optind == argc) {
66 usage(0);
67 }
68
69 if (optind >= argc)
70 usage(1);
71
72 init_mp(&mp);
73 mp.callback = print_short_name;
74 mp.arg = NULL;
75 mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR;
76 exit(main_loop(&mp, argv + optind, argc - optind));
77}