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