Annotation of coherent/d/usr/bin/emacs/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:        register uchar *cp;
                     45:        char    *getenv();
                     46: #endif
                     47: #if    VMS
                     48:        movecursor(term.t_nrow, 0);             /* In last line.        */
                     49:        mlputs("[Starting DCL]\r\n");
                     50:        tflush();                               /* Ignore "ttcol".      */
                     51:        sgarbf = TRUE;
                     52:        return (sys(NULL));                     /* NULL => DCL.         */
                     53: #endif
                     54: #if    CPM
                     55:        mlwrite("Not in CP/M-86");
                     56: #endif
                     57: #if    GEM
                     58:        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
                     59:        tflush();
                     60:        tclose();
                     61:        system("msh");
                     62:        sgarbf = TRUE;
                     63:        topen();
                     64:        return (TRUE);
                     65: #endif
                     66: #if    MSDOS
                     67:        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
                     68:        tflush();
                     69:        ttclose();
                     70:        execall("c:\\command.com", "");         /* Run CLI.             */
                     71:        ttopen();
                     72:        sgarbf = TRUE;
                     73:        return (TRUE);
                     74: #endif
                     75: #if    V7
                     76:        movecursor(term.t_nrow, 0);             /* Seek to last line.   */
                     77:        tflush();
                     78:        tclose();                               /* stty to old settings */
                     79:        if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
                     80:                system(cp);
                     81:        else
                     82:                system("exec /bin/sh");
                     83:        sgarbf = TRUE;
                     84:        topen();
                     85:        return (TRUE);
                     86: #endif
                     87: }
                     88: 
                     89: /*
                     90:  * Run a one-liner in a subjob.
                     91:  * When the command returns, wait for a single
                     92:  * character to be typed, then mark the screen as
                     93:  * garbage so a full repaint is done.
                     94:  * Bound to "C-X !".
                     95:  */
                     96: spawn(f, n)
                     97: {
                     98:        register int    s;
                     99:        uchar           line[NLINE];
                    100: #if    VMS
                    101:        if ((s=mlreply("DCL command: ", line, NLINE)) != TRUE)
                    102:                return (s);
                    103:        tputc('\n');                            /* Already have '\r'    */
                    104:        tflush();
                    105:        s = sys(line);                          /* Run the command.     */
                    106:        mlputs("\r\n\n[End]");                  /* Pause.               */
                    107:        tflush();
                    108:        while (tgetc() != '\r')
                    109:                ;
                    110:        sgarbf = TRUE;
                    111:        return (s);
                    112: #endif
                    113: #if    CPM
                    114:        mlwrite("Not in CP/M-86");
                    115:        return (FALSE);
                    116: #endif
                    117: #if    GEM
                    118:        if ((s=mlreply("! ", line, NLINE)) != TRUE)
                    119:                return (s);
                    120:        tputc('\n');                            /* Already have '\r'    */
                    121:        tflush();
                    122:        tclose();
                    123:        system(line);
                    124:        topen();
                    125:        mlputs("[End]");                        /* Pause.               */
                    126:        tflush();
                    127:        while ((s = tgetc()) != '\r' && s != ' ')
                    128:                ;
                    129:        sgarbf = TRUE;
                    130:        return (TRUE);
                    131: #endif
                    132: #if    MSDOS
                    133:        if ((s=mlreply("DOS command: ", line, NLINE)) != TRUE)
                    134:                return (s);
                    135:        (*term.t_putchar)('\n');
                    136:        ttclose();
                    137:        system(line);
                    138:        ttopen();
                    139:        mlputs("\n[End]");
                    140:        while (tgetc() != '\r')                 /* Pause.               */
                    141:                ;
                    142:        sgarbf = TRUE;
                    143:        return (TRUE);
                    144: #endif
                    145: #if    V7
                    146:        if ((s=mlreply("! ", line, NLINE)) != TRUE)
                    147:                return (s);
                    148:        tputc('\n');                            /* Already have '\r'    */
                    149:        tflush();
                    150:        tclose();                               /* stty to old modes    */
                    151:        system(line);
                    152:        sleep(2);
                    153:        topen();
                    154:        mlputs("[End]");                        /* Pause.               */
                    155:        tflush();
                    156:        while ((s = tgetc()) != '\r' && s != ' ')
                    157:                ;
                    158:        sgarbf = TRUE;
                    159:        return (TRUE);
                    160: #endif
                    161: }
                    162: 
                    163: #if    VMS
                    164: /*
                    165:  * Run a command. The "cmd" is a pointer
                    166:  * to a command string, or NULL if you want to run
                    167:  * a copy of DCL in the subjob (this is how the standard
                    168:  * routine LIB$SPAWN works. You have to do wierd stuff
                    169:  * with the terminal on the way in and the way out,
                    170:  * because DCL does not want the channel to be
                    171:  * in raw mode.
                    172:  */
                    173: sys(cmd)
                    174: register uchar *cmd;
                    175: {
                    176:        struct  dsc$descriptor  cdsc;
                    177:        struct  dsc$descriptor  *cdscp;
                    178:        long    status;
                    179:        long    substatus;
                    180:        long    iosb[2];
                    181: 
                    182:        status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
                    183:                          oldmode, sizeof(oldmode), 0, 0, 0, 0);
                    184:        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                    185:                return (FALSE);
                    186:        cdscp = NULL;                           /* Assume DCL.          */
                    187:        if (cmd != NULL) {                      /* Build descriptor.    */
                    188:                cdsc.dsc$a_pointer = cmd;
                    189:                cdsc.dsc$w_length  = strlen(cmd);
                    190:                cdsc.dsc$b_dtype   = DSC$K_DTYPE_T;
                    191:                cdsc.dsc$b_class   = DSC$K_CLASS_S;
                    192:                cdscp = &cdsc;
                    193:        }
                    194:        status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
                    195:        if (status != SS$_NORMAL)
                    196:                substatus = status;
                    197:        status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
                    198:                          newmode, sizeof(newmode), 0, 0, 0, 0);
                    199:        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                    200:                return (FALSE);
                    201:        if ((substatus&STS$M_SUCCESS) == 0)     /* Command failed.      */
                    202:                return (FALSE);
                    203:        return (TRUE);
                    204: }
                    205: #endif

unix.superglobalmegacorp.com

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