Bump to 4.0.43
[platform/upstream/mtools.git] / mshowfat.c
1 /*  Copyright 1997,2000-2002,2009,2011 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  * mcopy.c
18  * Copy an MSDOS files to and from Unix
19  *
20  */
21
22
23 #include "sysincludes.h"
24 #include "mtools.h"
25 #include "mainloop.h"
26 #include "plain_io.h"
27 #include "nameclash.h"
28 #include "file.h"
29 #include "fs.h"
30
31 typedef struct Arg_t {
32         MainParam_t mp;
33         off_t offset;
34 } Arg_t;
35
36 static int dos_showfat(direntry_t *entry, MainParam_t *mp)
37 {
38         Stream_t *File=mp->File;
39         Arg_t *arg = (Arg_t *) mp->arg;
40         fprintPwd(stdout, entry,0);
41         putchar(' ');
42         if(arg->offset == -1) {
43                 printFat(File);
44         } else {
45                 printFatWithOffset(File, arg->offset);
46         }
47         printf("\n");
48         return GOT_ONE;
49 }
50
51 static int unix_showfat(MainParam_t *mp UNUSEDP)
52 {
53         fprintf(stderr,"File does not reside on a Dos fs\n");
54         return ERROR_ONE;
55 }
56
57
58 static void usage(int ret) NORETURN;
59 static void usage(int ret)
60 {
61         fprintf(stderr,
62                 "Mtools version %s, dated %s\n", mversion, mdate);
63         fprintf(stderr,
64                 "Usage: %s files\n", progname);
65         exit(ret);
66 }
67
68 void mshowfat(int argc, char **argv, int mtype UNUSEDP) NORETURN;
69 void mshowfat(int argc, char **argv, int mtype UNUSEDP)
70 {
71         Arg_t arg;
72         int c, ret;
73
74         /* get command line options */
75         if(helpFlag(argc, argv))
76                 usage(0);
77         arg.offset = -1;
78         while ((c = getopt(argc, argv, "i:ho:")) != EOF) {
79                 switch (c) {
80                         case 'o':
81                                 arg.offset = str_to_offset(optarg);
82                                 break;
83                         case 'i':
84                                 set_cmd_line_image(optarg);
85                                 break;
86                         case 'h':
87                                 usage(0);
88                         case '?':
89                                 usage(1);
90                 }
91         }
92
93         if (argc - optind < 1)
94                 usage(1);
95
96         /* only 1 file to handle... */
97         init_mp(&arg.mp);
98         arg.mp.arg = (void *) &arg;
99
100         arg.mp.callback = dos_showfat;
101         arg.mp.unixcallback = unix_showfat;
102
103         arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN;
104         ret=main_loop(&arg.mp, argv + optind, argc - optind);
105         exit(ret);
106 }