Annotation of researchv10no/dk/cmd/pupu/dkcc.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     dkcc -- Remote Execute or Login over DATAKIT VCS to UNIX-V
                      3:  */
                      4:        static char     SCCSID[] = "@(#)dkrx.c  2.1 DKHOST 84/07/03";
                      5: 
                      6: #include <stdio.h>
                      7: #include "sysexits.h"
                      8: #include "string.h"
                      9: extern int     dkp_ld ;
                     10: extern char *  dkerror ;
                     11: 
                     12:        char            system[64];
                     13:        char            *ttyname();
                     14: 
                     15: main(argc, argv)
                     16:        char            **argv;
                     17: {
                     18:        register int    f, exitcode;
                     19:        register char   *p, *ttyn;
                     20:        int             force, env;
                     21:        extern char *miscfield() ;
                     22:        char *          cmdname ;
                     23: 
                     24:        cmdname = argv[0] ;
                     25:        if(p = strrchr(argv[0], '/'))
                     26:                strcpy(system, p+1);
                     27:        else
                     28:                strcpy(system, argv[0]);
                     29: 
                     30:        argc--; argv++;
                     31: 
                     32:        if(strcmp(argv[0], "-f") == 0){
                     33:                force = 1;
                     34:                argc--; argv++;
                     35:        }else
                     36:                force = 0;
                     37: 
                     38:        env = 1;
                     39: 
                     40:        if(strcmp(system, "dkcc") == 0) {
                     41:                if(argc == 0){
                     42:                        fprintf(stderr, "Usage:  dkcc system [ command [ args ] ]\n");
                     43:                        exit(EX_USAGE);
                     44:                }
                     45: 
                     46: 
                     47:                strcpy(system, argv[0]);
                     48: 
                     49:                argc--; argv++;
                     50:        }
                     51: 
                     52: 
                     53:        if(argc > 0)
                     54:                strcpy(system, maphost(system, 'x', "rx", "aevx", ""));
                     55:        else
                     56:                strcpy(system, maphost(system, 'l', "rl", "vx", ""));
                     57: 
                     58:        if(p = miscfield((argc > 0) ? 'x' : 'l', 'c'))
                     59:                execalt(p, system, argv);
                     60: 
                     61:        if(p = miscfield((argc > 0) ? 'x' : 'l', 'v'))
                     62:                env = (*p == 'y');
                     63: 
                     64:        f = tdkdial(system, 2);
                     65:        if (f < 0) {
                     66:                fprintf(stderr, "%s: call to %s failed, %s\n", cmdname, system, dkerror) ;
                     67:                exit(-f);
                     68:        }
                     69:        dkproto(f, dkp_ld) ;
                     70: 
                     71:        exitcode = 0;
                     72: 
                     73:        if(env)
                     74:                exitcode = dkxenviron(f);
                     75: 
                     76:        if(exitcode >= 0 && argc > 0)
                     77:                exitcode = sendargs(f, argv, !!miscfield('x', 's'));
                     78: 
                     79:        if(exitcode >= 0)
                     80:                exitcode = dkxstdio(f);
                     81: 
                     82:        if(exitcode == -EX_IOERR && argc == 0)
                     83:                exit(0);                /* no exitcode specified */
                     84:        else if(exitcode < 0)
                     85:                exit(-exitcode);        /* if error processing the call */
                     86:        else if(exitcode & 0xFF)
                     87:                exit(exitcode | 0x80);  /* remote terminated on signal */
                     88:        else
                     89:                exit(exitcode>>8);      /* else it finished with this code */
                     90: }
                     91: 
                     92: execalt(string, system, argv)
                     93:        char            *string, *system;
                     94:        char            *argv[];
                     95: {
                     96:        char            **ap, *args[32];
                     97: 
                     98:        ap = args;
                     99: 
                    100:        do{
                    101:                *ap++ = string;
                    102: 
                    103:                if(string = strchr(string, ':'))
                    104:                        *string++ = '\0';
                    105:        }while(string);
                    106: 
                    107:        *ap++ = system;
                    108:        while(*ap++ = *argv++);
                    109: 
                    110:        execvp(args[0], args);
                    111: 
                    112:        fprintf(stderr, "dk: Can't exec %s\n", args[0]);
                    113:        exit(EX_UNAVAILABLE);
                    114: }
                    115: 
                    116: sendargs(fd, argarray, minusc)
                    117:        char            *argarray[];
                    118: {
                    119:        register int    aoffset;
                    120:        char            argstring[2048];
                    121: 
                    122:        if(minusc){
                    123:                aoffset = 3;
                    124:                strcpy(argstring, "-c");
                    125:        }else
                    126:                aoffset = 0;
                    127: 
                    128:        return(dkxlwrite(fd, argstring, bldargs(&argstring[aoffset], argarray) + aoffset));
                    129: }
                    130: 
                    131: bldargs(args, argv)
                    132:        char            *args;
                    133:        register char   *argv[];
                    134: {
                    135:        register char   *s, *t;
                    136: 
                    137:        s = args;
                    138: 
                    139:        if (t = *argv++) {
                    140:                while (*s++ = *t++);
                    141: 
                    142:                s[-1] = ' ';
                    143:        }
                    144:        while(t = *argv++){
                    145:                *s++ = '"';
                    146: 
                    147:                while(*s++ = *t++);
                    148: 
                    149:                s[-1] = '"';
                    150:                *s++ = ' ';
                    151:        }
                    152:        *s++ = '\0';
                    153:        return(s - args);
                    154: }

unix.superglobalmegacorp.com

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