blob: 81e4eb6939be91ea2867ace626a96553fe012ba8 [file] [log] [blame]
Alistair Delvabeaee832021-02-24 11:27:23 -08001/* Copyright 1986-1992 Emmet P. Gray.
2 * Copyright 1996,1997,2000-2002,2009 Alain Knaff.
3 * This file is part of mtools.
4 *
5 * Mtools is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * Mtools is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * mcd.c: Change MSDOS directories
19 */
20
21#include "sysincludes.h"
22#include "msdos.h"
23#include "mainloop.h"
24#include "mtools.h"
25
26
27static int mcd_callback(direntry_t *entry, MainParam_t *mp UNUSEDP)
28{
29 FILE *fp;
30
31 if (!(fp = open_mcwd("w"))){
32 fprintf(stderr,"mcd: Can't open mcwd .file for writing\n");
33 return ERROR_ONE;
34 }
Yi Kong39bbd962022-01-09 19:41:38 +080035
Alistair Delvabeaee832021-02-24 11:27:23 -080036 fprintPwd(fp, entry,0);
37 fprintf(fp, "\n");
38 fclose(fp);
39 return GOT_ONE | STOP_NOW;
40}
41
Yi Kong39bbd962022-01-09 19:41:38 +080042static void usage(int ret) NORETURN;
43static void usage(int ret)
44{
45 fprintf(stderr, "Mtools version %s, dated %s\n",
46 mversion, mdate);
47 fprintf(stderr, "Usage: %s: [-V] [-i image] msdosdirectory\n",
48 progname);
49 exit(ret);
50}
51
Alistair Delvabeaee832021-02-24 11:27:23 -080052
53void mcd(int argc, char **argv, int type UNUSEDP) NORETURN;
54void mcd(int argc, char **argv, int type UNUSEDP)
55{
56 struct MainParam_t mp;
Yi Kong39bbd962022-01-09 19:41:38 +080057 int c;
58
59 while ((c = getopt(argc, argv, "i:")) != EOF) {
60 switch(c) {
61 case 'i':
62 set_cmd_line_image(optarg);
63 break;
64 case 'h':
65 usage(0);
66 default:
67 usage(1);
68 }
Alistair Delvabeaee832021-02-24 11:27:23 -080069 }
70
Yi Kong39bbd962022-01-09 19:41:38 +080071 if (argc > optind + 1)
72 usage(1);
73
Alistair Delvabeaee832021-02-24 11:27:23 -080074 init_mp(&mp);
75 mp.lookupflags = ACCEPT_DIR | NO_DOTS;
76 mp.dirCallback = mcd_callback;
77 if (argc == 1) {
78 printf("%s\n", mp.mcwd);
79 exit(0);
Yi Kong39bbd962022-01-09 19:41:38 +080080 } else
81 exit(main_loop(&mp, argv + optind, 1));
Alistair Delvabeaee832021-02-24 11:27:23 -080082}