xref: /openbsd-src/usr.bin/mg/dir.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: dir.c,v 1.6 2001/05/24 03:05:21 mickey Exp $	*/
2 
3 /*
4  * Name:	MG 2a
5  *		Directory management functions
6  * Created:	Ron Flax (ron@vsedev.vse.com)
7  *		Modified for MG 2a by Mic Kaczmarczik 03-Aug-1987
8  */
9 
10 #include "def.h"
11 
12 #ifndef NO_DIR
13 char		*wdir;
14 static char	cwd[NFILEN];
15 
16 /*
17  * Initialize anything the directory management routines need
18  */
19 void
20 dirinit()
21 {
22 
23 	if (!(wdir = getcwd(cwd, sizeof(cwd))))
24 		panic("Can't get current directory!");
25 }
26 
27 /*
28  * Change current working directory
29  */
30 /* ARGSUSED */
31 int
32 changedir(f, n)
33 	int	f, n;
34 {
35 	int	s;
36 	char	bufc[NPAT];
37 
38 	if ((s = ereply("Change default directory: ", bufc, NPAT)) != TRUE)
39 		return (s);
40 	if (bufc[0] == '\0')
41 		(void) strcpy(bufc, wdir);
42 	if (chdir(bufc) == -1) {
43 		ewprintf("Can't change dir to %s", bufc);
44 		return (FALSE);
45 	} else {
46 		if (!(wdir = getcwd(cwd, sizeof(cwd))))
47 			panic("Can't get current directory!");
48 		ewprintf("Current directory is now %s", wdir);
49 		return (TRUE);
50 	}
51 }
52 
53 /*
54  * Show current directory
55  */
56 /* ARGSUSED */
57 int
58 showcwdir(f, n)
59 {
60 
61 	ewprintf("Current directory: %s", wdir);
62 	return (TRUE);
63 }
64 #endif
65