Annotation of coherent/g/usr/bin/me/spawn.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * The routines in this file
                      3:  * are called to create a subjob running
                      4:  * a command interpreter. This code is a big
                      5:  * fat nothing on CP/M-86. You lose.
                      6:  */
                      7: #include       <stdio.h>
                      8: #include       "ed.h"
                      9: 
                     10: #if    VMS
                     11: #define        EFN     0                               /* Event flag.          */
                     12: 
                     13: #include       <ssdef.h>                       /* Random headers.      */
                     14: #include       <stsdef.h>
                     15: #include       <descrip.h>
                     16: #include       <iodef.h>
                     17: 
                     18: extern int     oldmode[];                      /* In "termio.c"        */
                     19: extern int     newmode[];                      /* In "termio.c"        */
                     20: extern short   iochan;                         /* In "termio.c"        */
                     21: #endif
                     22: 
                     23: #if    MSDOS
                     24: #include       <dos.h>
                     25: #endif
                     26: 
                     27: #if    V7
                     28: #include       <signal.h>
                     29: #endif
                     30: 
                     31: /*
                     32:  * Create a subjob with a copy
                     33:  * of the command intrepreter in it. When the
                     34:  * command interpreter exits, mark the screen as
                     35:  * garbage so that you do a full repaint. Bound
                     36:  * to "C-C". The message at
                     37:  * the start in VMS puts out a newline. Under
                     38:  * some (unknown) condition, you don't get one
                     39:  * free when DCL starts up.
                     40:  */
                     41: spawncli(f, n)
                     42: {
                     43: #if    V7
                     44:        uchar *cp;
                     45:        char buf[80];
                     46:        char    *getenv();
                     47: #endif
                     48: #if    VMS
                     49:        movecursor(term.t_nrow, 0);             /* In last line.        */
                     50:        mlputs("[Starting DCL]\r\n");
                     51:        tflush();                               /* Ignore "ttcol".      */
                     52:        sgarbf = TRUE;
                     53:        return (sys(NULL));                     /* NULL => DCL.         */
                     54: #endif
                     55: #if    CPM
                     56:        mlwrite("Not in CP/M-86");
                     57: #endif
                     58: #if    GEM
                     59:        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
                     60:        tflush();
                     61:        tclose();
                     62:        system("msh");
                     63:        sgarbf = TRUE;
                     64:        topen();
                     65:        return (TRUE);
                     66: #endif
                     67: #if    MSDOS
                     68:        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
                     69:        tflush();
                     70:        ttclose();
                     71:        execall("c:\\command.com", "");         /* Run CLI.             */
                     72:        ttopen();
                     73:        sgarbf = TRUE;
                     74:        return (TRUE);
                     75: #endif
                     76: #if    V7
                     77:        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
                     78:        tflush();
                     79:        tclose();                               /* stty to old settings */
                     80:        if ((cp = getenv("SHELL")) != NULL && *cp != '\0') {
                     81:                sprintf(buf, "exec %s", cp);
                     82:                system(buf);
                     83:        }
                     84:        else
                     85:                system("exec /bin/sh");
                     86: 
                     87:        sgarbf = TRUE;
                     88:        topen();
                     89: 
                     90:        return (TRUE);
                     91: #endif
                     92: }
                     93: 
                     94: /*
                     95:  * Run a one-liner in a subjob.
                     96:  * When the command returns, wait for a single
                     97:  * character to be typed, then mark the screen as
                     98:  * garbage so a full repaint is done.
                     99:  * Bound to "C-X !".
                    100:  */
                    101: spawn(f, n)
                    102: {
                    103:        register int    s;
                    104:        uchar           line[NLINE];
                    105: #if    VMS
                    106:        if ((s=mlreply("DCL command: ", line, NLINE)) != TRUE)
                    107:                return (s);
                    108:        tputc('\n');                            /* Already have '\r'    */
                    109:        tflush();
                    110:        s = sys(line);                          /* Run the command.     */
                    111:        mlputs("\r\n\n[End]");                  /* Pause.               */
                    112:        tflush();
                    113:        while (tgetc() != '\r')
                    114:                ;
                    115:        sgarbf = TRUE;
                    116:        return (s);
                    117: #endif
                    118: #if    CPM
                    119:        mlwrite("Not in CP/M-86");
                    120:        return (FALSE);
                    121: #endif
                    122: #if    GEM
                    123:        if ((s=mlreply("! ", line, NLINE)) != TRUE)
                    124:                return (s);
                    125:        tputc('\n');                            /* Already have '\r'    */
                    126:        tflush();
                    127:        tclose();
                    128:        system(line);
                    129:        topen();
                    130:        mlputs("[End]");                        /* Pause.               */
                    131:        tflush();
                    132:        while ((s = tgetc()) != '\r' && s != ' ')
                    133:                ;
                    134:        sgarbf = TRUE;
                    135:        return (TRUE);
                    136: #endif
                    137: #if    MSDOS
                    138:        if ((s=mlreply("DOS command: ", line, NLINE)) != TRUE)
                    139:                return (s);
                    140:        (*term.t_putchar)('\n');
                    141:        ttclose();
                    142:        system(line);
                    143:        ttopen();
                    144:        mlputs("\n[End]");
                    145:        while (tgetc() != '\r')                 /* Pause.               */
                    146:                ;
                    147:        sgarbf = TRUE;
                    148:        return (TRUE);
                    149: #endif
                    150: #if    V7
                    151:        if ((s=mlreply("! ", line, NLINE)) != TRUE)
                    152:                return (s);
                    153:        tputc('\n');                            /* Already have '\r'    */
                    154:        tflush();
                    155:        tclose();                               /* stty to old modes    */
                    156:        system(line);
                    157:        sleep(2);
                    158:        topen();
                    159:        mlputs("[End]");                        /* Pause.               */
                    160:        tflush();
                    161:        while ((s = tgetc()) != '\r' && s != ' ')
                    162:                ;
                    163:        sgarbf = TRUE;
                    164:        return (TRUE);
                    165: #endif
                    166: }
                    167: 
                    168: #if    VMS
                    169: /*
                    170:  * Run a command. The "cmd" is a pointer
                    171:  * to a command string, or NULL if you want to run
                    172:  * a copy of DCL in the subjob (this is how the standard
                    173:  * routine LIB$SPAWN works. You have to do wierd stuff
                    174:  * with the terminal on the way in and the way out,
                    175:  * because DCL does not want the channel to be
                    176:  * in raw mode.
                    177:  */
                    178: sys(cmd)
                    179: register uchar *cmd;
                    180: {
                    181:        struct  dsc$descriptor  cdsc;
                    182:        struct  dsc$descriptor  *cdscp;
                    183:        long    status;
                    184:        long    substatus;
                    185:        long    iosb[2];
                    186: 
                    187:        status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
                    188:                          oldmode, sizeof(oldmode), 0, 0, 0, 0);
                    189:        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                    190:                return (FALSE);
                    191:        cdscp = NULL;                           /* Assume DCL.          */
                    192:        if (cmd != NULL) {                      /* Build descriptor.    */
                    193:                cdsc.dsc$a_pointer = cmd;
                    194:                cdsc.dsc$w_length  = strlen(cmd);
                    195:                cdsc.dsc$b_dtype   = DSC$K_DTYPE_T;
                    196:                cdsc.dsc$b_class   = DSC$K_CLASS_S;
                    197:                cdscp = &cdsc;
                    198:        }
                    199:        status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
                    200:        if (status != SS$_NORMAL)
                    201:                substatus = status;
                    202:        status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
                    203:                          newmode, sizeof(newmode), 0, 0, 0, 0);
                    204:        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                    205:                return (FALSE);
                    206:        if ((substatus&STS$M_SUCCESS) == 0)     /* Command failed.      */
                    207:                return (FALSE);
                    208:        return (TRUE);
                    209: }
                    210: #endif

unix.superglobalmegacorp.com

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