1 /* Copyright 1996-2004,2007-2010 Alain Knaff.
2 * This file is part of mtools.
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.
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.
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/>.
18 #include "sysincludes.h"
23 static const struct dispatch {
25 void (*fn)(int, char **, int);
28 {"mattrib",mattrib, 0},
29 {"mbadblocks",mbadblocks, 0},
36 {"mdoctorfat",mdoctorfat, 0},
38 {"mformat",mformat, 0},
43 {"mpartition",mpartition, 0},
48 {"mshowfat", mshowfat, 0},
49 {"mshortname", mshortname, 0},
50 {"mtoolstest", mtoolstest, 0},
55 #define NDISPATCH (sizeof dispatch / sizeof dispatch[0])
57 int main(int argc,char **argv)
64 locale=setlocale(LC_ALL, "");
65 if(locale == NULL || !strcmp(locale, "C"))
66 setlocale(LC_ALL, "en_US");
71 _wildcard(&argc,&argv);
81 printf("INIT: %d %d\n", getuid(), geteuid());
83 printf("DROP: %d %d\n", getuid(), geteuid());
85 printf("RECLAIM: %d %d\n", getuid(), geteuid());
89 printf("DROP: %d %d\n", getuid(), geteuid());
93 printf("DESTROY: %d %d\n", getuid(), geteuid());
95 sprintf(command, "a.out %d", euid);
103 _wildcard(&argc,&argv);
107 argv[0] = _getname(argv[0]); _remext(argv[0]); name = argv[0];
109 #ifdef OS_mingw32msvc
112 name = _basename(argv[0]);
116 /* this allows the different tools to be called as "mtools -c <command>"
117 ** where <command> is mdir, mdel, mcopy etcetera
118 ** Mainly done for the BeOS, which doesn't support links yet.
122 !strcmp(argv[1], "-c") &&
123 !strcmp(name, "mtools")) {
131 /* print the version */
133 (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "--version") ==0)) {
134 printf("%s (GNU mtools) %s\n",
136 printf("configured with the following options: ");
138 printf("enable-xdf ");
140 printf("disable-xdf ");
143 printf("enable-vold ");
145 printf("disable-vold ");
147 #ifdef USING_NEW_VOLD
148 printf("enable-new-vold ");
150 printf("disable-new-vold ");
153 printf("enable-debug ");
155 printf("disable-debug ");
158 printf("enable-raw-term ");
160 printf("disable-raw-term ");
168 for (i = 0; i < NDISPATCH; i++) {
169 if (!strcmp(name,dispatch[i].cmd))
170 dispatch[i].fn(argc, argv, dispatch[i].type);
172 if (strcmp(name,"mtools"))
173 fprintf(stderr,"Unknown mtools command '%s'\n",name);
174 fprintf(stderr,"Supported commands:");
175 for (i = 0; i < NDISPATCH; i++) {
176 if (i%8 == 0) putc('\n', stderr);
177 else fprintf(stderr, ", ");
178 fprintf(stderr, "%s", dispatch[i].cmd);
185 int helpFlag(int argc, char **argv) {
186 return (argc > 1 && !strcmp(argv[1], "--help"));