Alistair Delva | beaee83 | 2021-02-24 11:27:23 -0800 | [diff] [blame] | 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 UNUSEDP) |
| 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 | { |
Yi Kong | 39bbd96 | 2022-01-09 19:41:38 +0800 | [diff] [blame] | 37 | fprintf(stderr, "Mtools version %s, dated %s\n", |
Alistair Delva | beaee83 | 2021-02-24 11:27:23 -0800 | [diff] [blame] | 38 | mversion, mdate); |
Yi Kong | 39bbd96 | 2022-01-09 19:41:38 +0800 | [diff] [blame] | 39 | fprintf(stderr, |
Alistair Delva | beaee83 | 2021-02-24 11:27:23 -0800 | [diff] [blame] | 40 | "Usage: %s msdosfile [msdosfiles...]\n", |
| 41 | progname); |
| 42 | exit(ret); |
| 43 | } |
| 44 | |
| 45 | void mshortname(int argc, char **argv, int type UNUSEDP) NORETURN; |
| 46 | void 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 | } |