Annotation of coherent/e/bin/xargs.c, revision 1.1

1.1     ! root        1: /* xargs -- quickie version of System V xargs(1): read a list of
        !             2:  *     arguments from stdin, apply to the command which is
        !             3:  *     the argument(s) of xargs
        !             4:  */
        !             5: 
        !             6: #include <stdio.h>
        !             7: 
        !             8: char *cmdname;         /* should point to argv[0] */
        !             9: 
        !            10: char command[BUFSIZ];  /* command given to xargs */
        !            11: char line[BUFSIZ];     /* current input line */        
        !            12: char cmdbuf[BUFSIZ];   /* command + input lines */
        !            13: 
        !            14: main(argc, argv)
        !            15:        int argc;
        !            16:        char *argv[];
        !            17: {
        !            18:        char *gets();
        !            19:        char *strcat(), *strcpy();
        !            20: 
        !            21:        cmdname = argv[0];
        !            22: 
        !            23:        /* skip (xargs) command name */
        !            24: 
        !            25:        argv++, argc--;
        !            26: 
        !            27:        /* construct command from arguments */
        !            28: 
        !            29:        strcpy(command, "exec");
        !            30:        while (argc--) {
        !            31:                (void) strcat(command, " ");
        !            32:                (void) strcat(command, *argv++);
        !            33:        }
        !            34: 
        !            35:        /* initialize for command execution loop */
        !            36: 
        !            37:        (void) strcpy(cmdbuf, command);
        !            38: 
        !            39:        /* here's where all the action is: read in arguments
        !            40:         * from stdin, appending to the current command buffer
        !            41:         * if next line would overflow command buffer, execute
        !            42:         * command buffer and reinitialize
        !            43:         */
        !            44: 
        !            45:        while (gets(line) != NULL) {
        !            46: 
        !            47:                /* the "+2" is for the blank and trailing null char */
        !            48: 
        !            49:                if (strlen(cmdbuf)+strlen(line)+2 > BUFSIZ) {
        !            50:                        docmd(cmdbuf);
        !            51:                        (void) strcpy(cmdbuf, command);
        !            52:                }
        !            53:                (void) strcat(cmdbuf, " ");
        !            54:                (void) strcat(cmdbuf, line);
        !            55:        }
        !            56: 
        !            57:        /* see if there is any left to do */
        !            58: 
        !            59:        if (strlen(cmdbuf) != strlen(command)) {
        !            60:                docmd(cmdbuf);
        !            61:        }
        !            62: }
        !            63: 
        !            64: docmd(cmdbuf)
        !            65: char *cmdbuf;
        !            66: {
        !            67:        return system(cmdbuf);
        !            68: }
        !            69: 
        !            70: 

unix.superglobalmegacorp.com

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