Annotation of 43BSD/contrib/spms/src/bin/pmv/pmv.c, revision 1.1

1.1     ! root        1: static char *rcsid = "$Header$";
        !             2: /*
        !             3:  * pmv - move or rename files
        !             4:  *
        !             5:  * Author: Peter J. Nicklin
        !             6:  */
        !             7: #include "bin.h"
        !             8: #include "macro.h"
        !             9: #include "null.h"
        !            10: #include "path.h"
        !            11: #include "yesno.h"
        !            12: 
        !            13: char *PGN = "pmv";                     /* program name */
        !            14: 
        !            15: main(argc, argv)
        !            16:        int argc;
        !            17:        char **argv;
        !            18: {
        !            19:        extern int PPDEBUG;             /* project pathname debug flag */
        !            20:        char **nargv;                   /* new argument list */
        !            21:        char *strsav();                 /* save string somewhere */
        !            22:        int filecount = 0;              /* # of valid files or directories */
        !            23:        int nargi = 0;                  /* new argument list index */
        !            24:        int xppath();                   /* expand project pathname */
        !            25:        PATH pathbuf;                   /* pathname struct buffer */
        !            26: 
        !            27:        nargv = argv;
        !            28:        nargv[nargi++] = "mv";
        !            29: 
        !            30:        {
        !            31:        register char *s;               /* option pointer */
        !            32:        while (--argc > 0 && **++argv == '-')
        !            33:                {
        !            34:                s = argv[0]+1;
        !            35:                if (*s == '\0')         /* special kludge to handle `-' flag */
        !            36:                        {
        !            37:                        nargv[nargi++] = *argv++;
        !            38:                        break;
        !            39:                        }
        !            40:                else    {
        !            41:                        for (; *s != '\0'; s++)
        !            42:                                switch (*s)
        !            43:                                        {
        !            44:                                        case 'D':
        !            45:                                                PPDEBUG = YES;
        !            46:                                                break;
        !            47:                                        default:
        !            48:                                                nargv[nargi++] = *argv;
        !            49:                                                break;
        !            50:                                        }
        !            51:                        }
        !            52:                }
        !            53:        }
        !            54:        if (argc < 2)
        !            55:                fatal("usage: %s f1 f2; or %s f1 ... f2 d1", PGN, PGN);
        !            56: 
        !            57:        /* expand project pathnames and attach to new argument list */
        !            58:        for (; argc > 1; argc--, argv++)
        !            59:                if (xppath(*argv, &pathbuf) == -1)
        !            60:                        patherr(*argv);
        !            61:                else switch (pathbuf.p_mode & P_IFMT)
        !            62:                        {
        !            63:                        case P_IFNEW:
        !            64:                                patherr(*argv);
        !            65:                                break;
        !            66:                        case P_IFPDIR:
        !            67:                                warn("can't move project directory %s", *argv);
        !            68:                                break;
        !            69:                        case P_IFHOME:
        !            70:                        case P_IFPROOT:
        !            71:                                warn("can't move project %s", *argv);
        !            72:                                break;
        !            73:                        default:
        !            74:                                nargv[nargi++] = strsav(pathbuf.p_path);
        !            75:                                filecount++;
        !            76:                        }
        !            77: 
        !            78:        if (filecount == 0)
        !            79:                exit(1);
        !            80:        else if (xppath(*argv, &pathbuf) == -1)
        !            81:                {
        !            82:                patherr(*argv);
        !            83:                exit(1);
        !            84:                }
        !            85:        else    {
        !            86:                nargv[nargi++] = strsav(pathbuf.p_path);
        !            87:                nargv[nargi] = NULL;
        !            88:                }
        !            89:        
        !            90:        /* execute "mv" command */
        !            91:        execv(MV, nargv);
        !            92:        fatal("can't exec %s", MV);
        !            93: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.