[BACK]Return to dir.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/dir.c, Revision 1.4

1.4     ! niklas      1: /*     $OpenBSD$       */
        !             2:
1.1       deraadt     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
1.3       millert    13: char           *wdir;
                     14: static char     cwd[NFILEN];
1.1       deraadt    15:
                     16: /*
                     17:  * Initialize anything the directory management routines need
                     18:  */
1.3       millert    19: VOID
1.1       deraadt    20: dirinit()
                     21: {
1.3       millert    22:
1.2       millert    23:        if (!(wdir = getcwd(cwd, sizeof(cwd))))
1.1       deraadt    24:                panic("Can't get current directory!");
                     25: }
                     26:
                     27: /*
                     28:  * Change current working directory
                     29:  */
1.3       millert    30: /* ARGSUSED */
                     31: int
1.1       deraadt    32: changedir(f, n)
1.3       millert    33:        int    f, n;
1.1       deraadt    34: {
1.3       millert    35:        int    s;
                     36:        char   bufc[NPAT];
1.1       deraadt    37:
1.3       millert    38:        if ((s = ereply("Change default directory: ", bufc, NPAT)) != TRUE)
                     39:                return (s);
1.1       deraadt    40:        if (bufc[0] == '\0')
                     41:                (VOID) strcpy(bufc, wdir);
                     42:        if (chdir(bufc) == -1) {
                     43:                ewprintf("Can't change dir to %s", bufc);
1.3       millert    44:                return (FALSE);
1.1       deraadt    45:        } else {
1.2       millert    46:                if (!(wdir = getcwd(cwd, sizeof(cwd))))
1.1       deraadt    47:                        panic("Can't get current directory!");
                     48:                ewprintf("Current directory is now %s", wdir);
1.3       millert    49:                return (TRUE);
1.1       deraadt    50:        }
                     51: }
                     52:
                     53: /*
                     54:  * Show current directory
                     55:  */
1.3       millert    56: /* ARGSUSED */
                     57: int
1.1       deraadt    58: showcwdir(f, n)
                     59: {
1.3       millert    60:
1.1       deraadt    61:        ewprintf("Current directory: %s", wdir);
1.3       millert    62:        return (TRUE);
1.1       deraadt    63: }
                     64: #endif