BSD 4_4 release
[unix-history] / usr / src / usr.bin / tn3270 / distribution / sys_dos / spintc.c
index 3350bd3..aa16405 100644 (file)
@@ -1,10 +1,45 @@
-#define        LINT_ARGS
+/*-
+ * Copyright (c) 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)spintc.c   8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 #include <stdio.h>
 #include <dos.h>
 #include <stdlib.h>
 
 
 #include <stdio.h>
 #include <dos.h>
 #include <stdlib.h>
 
-#include "../ntn3270/general.h"
+#include "../general/general.h"
 #include "spint.h"
 
 #define        PSP_ENVIRONMENT         0x2c
 #include "spint.h"
 
 #define        PSP_ENVIRONMENT         0x2c
@@ -22,15 +57,64 @@ typedef struct {
        fcb2_ptr_segment;       /* Segment of FCB 2 */
 } ExecList;
 
        fcb2_ptr_segment;       /* Segment of FCB 2 */
 } ExecList;
 
+
+static int int_offset, int_segment;
+
+
 void
 void
-do_spawn(command, spawn)
+spint_finish(spint)
+Spint *spint;
+{
+    union REGS regs;
+    struct SREGS sregs;
+
+    if (spint->done == 0) {
+       return;                         /* Not done yet */
+    }
+
+    /*
+     * Restore old interrupt handler.
+     */
+
+    regs.h.ah = 0x25;
+    regs.h.al = spint->int_no;
+    regs.x.dx = int_offset;
+    sregs.ds = int_segment;
+    intdosx(&regs, &regs, &sregs);
+
+    if (spint->regs.x.cflag) {
+       fprintf(stderr, "0x%x return code from EXEC.\n", spint->regs.x.ax);
+       spint->done = 1;
+       spint->rc = 99;
+       return;
+    }
+
+    regs.h.ah = 0x4d;                  /* Get return code */
+
+    intdos(&regs, &regs);
+
+    spint->rc = regs.x.ax;
+}
+
+void
+spint_continue(spint)
+Spint *spint;
+{
+    _spint_continue(spint);            /* Return to caller */
+    spint_finish(spint);
+}
+
+
+void
+spint_start(command, spint)
 char *command;
 char *command;
-Spawn *spawn;
+Spint *spint;
 {
     ExecList mylist;
     char *comspec;
 {
     ExecList mylist;
     char *comspec;
-    void int_spawn();
-    int int_offset, int_segment;
+    void _spint_int();
+    union REGS regs;
+    struct SREGS sregs;
 
     /*
      * Get comspec.
 
     /*
      * Get comspec.
@@ -38,8 +122,8 @@ Spawn *spawn;
     comspec = getenv("COMSPEC");
     if (comspec == 0) {                        /* Can't find where command.com is */
        fprintf(stderr, "Unable to find COMSPEC in the environment.");
     comspec = getenv("COMSPEC");
     if (comspec == 0) {                        /* Can't find where command.com is */
        fprintf(stderr, "Unable to find COMSPEC in the environment.");
-       spawn->done = 1;
-       spawn->rc = 99; /* XXX */
+       spint->done = 1;
+       spint->rc = 99; /* XXX */
        return;
     }
 
        return;
     }
 
@@ -47,36 +131,36 @@ Spawn *spawn;
      * Now, hook up our interrupt routine.
      */
 
      * Now, hook up our interrupt routine.
      */
 
-    spawn->regs.h.ah = 0x35;
-    spawn->regs.h.al = spawn->int_no;
-    intdosx(&spawn->regs, &spawn->regs, &spawn->sregs);
+    regs.h.ah = 0x35;
+    regs.h.al = spint->int_no;
+    intdosx(&regs, &regs, &sregs);
 
     /* Save old routine */
 
     /* Save old routine */
-    int_offset = spawn->regs.x.bx;
-    int_segment = spawn->sregs.es;
+    int_offset = regs.x.bx;
+    int_segment = sregs.es;
 
 
-    spawn->regs.h.ah = 0x25;
-    spawn->regs.h.al = spawn->int_no;
-    spawn->regs.x.dx = (int) int_spawn;
-    segread(&spawn->sregs);
-    spawn->sregs.ds = spawn->sregs.cs;
-    intdosx(&spawn->regs, &spawn->regs, &spawn->sregs);
+    regs.h.ah = 0x25;
+    regs.h.al = spint->int_no;
+    regs.x.dx = (int) _spint_int;
+    segread(&sregs);
+    sregs.ds = sregs.cs;
+    intdosx(&regs, &regs, &sregs);
 
     /*
      * Read in segment registers.
      */
 
 
     /*
      * Read in segment registers.
      */
 
-    segread(&spawn->sregs);
+    segread(&spint->sregs);
 
     /*
      * Set up registers for the EXEC call.
      */
 
 
     /*
      * Set up registers for the EXEC call.
      */
 
-    spawn->regs.h.ah = 0x4b;
-    spawn->regs.h.al = 0;
-    spawn->regs.x.dx = (int) comspec;
-    spawn->sregs.es = spawn->sregs.ds;         /* Superfluous, probably */
-    spawn->regs.x.bx = (int) &mylist;
+    spint->regs.h.ah = 0x4b;
+    spint->regs.h.al = 0;
+    spint->regs.x.dx = (int) comspec;
+    spint->sregs.es = spint->sregs.ds;         /* Superfluous, probably */
+    spint->regs.x.bx = (int) &mylist;
 
     /*
      * Set up EXEC parameter list.
 
     /*
      * Set up EXEC parameter list.
@@ -84,7 +168,7 @@ Spawn *spawn;
 
     ClearElement(mylist);
     mylist.cmd_ptr_offset = (int) command;
 
     ClearElement(mylist);
     mylist.cmd_ptr_offset = (int) command;
-    mylist.cmd_ptr_segment = spawn->sregs.ds;
+    mylist.cmd_ptr_segment = spint->sregs.ds;
     mylist.fcb1_ptr_offset = PSP_FCB1;
     mylist.fcb1_ptr_segment = _psp;
     mylist.fcb2_ptr_offset = PSP_FCB2;
     mylist.fcb1_ptr_offset = PSP_FCB1;
     mylist.fcb1_ptr_segment = _psp;
     mylist.fcb2_ptr_offset = PSP_FCB2;
@@ -93,117 +177,10 @@ Spawn *spawn;
 
     /*
      * Call to assembly language routine to actually set up for
 
     /*
      * Call to assembly language routine to actually set up for
-     * the spawn.
-     */
-
-    start_spawn(spawn);
-    spawn->done = 1;                   /* XXX */
-
-    if (spawn->done == 0) {
-       return;                         /* Not done yet */
-    }
-
-    if (spawn->regs.x.cflag) {
-       fprintf(stderr, "0x%x return code from EXEC.\n", spawn->regs.x.ax);
-       spawn->done = 1;
-       spawn->rc = 99;
-       return;
-    }
-
-    spawn->regs.h.ah = 0x4d;                   /* Get return code */
-
-    intdos(&spawn->regs, &spawn->regs);
-
-    spawn->rc = spawn->regs.x.ax;
-
-    /*
-     * Restore old interrupt handler.
+     * the spint.
      */
 
      */
 
-    spawn->regs.h.ah = 0x25;
-    spawn->regs.h.al = spawn->int_no;
-    spawn->regs.x.dx = int_offset;
-    spawn->sregs.ds = int_segment;
-    intdosx(&spawn->regs, &spawn->regs, &spawn->sregs);
-}
-\f
-/* XXX */
-
-#define        INTERRUPT_NUMBER        73
-
-main(argc, argv, envp)
-int    argc;                           /* Number of passed arguments */
-char   *argv[];                        /* Arguments passed */
-char   *envp[];                        /* Inherited environment */
-{
-    Spawn spawned;
-    static char command[256];
-
-    ClearElement(spawned);
-    spawned.int_no = INTERRUPT_NUMBER;
-    if (argc == 1) {
-       command[0] = 0;
-    } else {
-       char *cmdptr;
-       int length;
-
-       argc--;
-       argv++;
-       strcpy(command, " /c");
-       cmdptr = command+strlen(command);
-       while (argc) {
-           if ((cmdptr+strlen(*argv)) >= (command+sizeof command)) {
-               fprintf(stderr, "Argument list too long at argument *%s*.\n",
-                           *argv);
-               return 0;
-           }
-           *cmdptr++ = ' ';            /* Blank separators */
-           strcpy(cmdptr, *argv);
-           cmdptr += strlen(cmdptr);
-           argc--;
-           argv++;
-       }
-       length = strlen(command)-1;
-       if (length < 0) {
-           length = 0;
-       }
-       command[0] = length;
-    }
+    _spint_start(spint);
 
 
-    /*
-     * do_spawn() returns when either the command has finished, or when
-     * the required interrupt comes in.  In the latter case, the appropriate
-     * thing to do is to process the interrupt, and then return to
-     * the interrupt issuer by calling continue_spawn().
-     */
-    do_spawn(command, &spawned);
-    while (spawned.done == 0) {
-       /* Process request */
-       spawned.regs.h.al = 0;
-       spawned.regs.x.cflag = 0;               /* No errors (yet) */
-       switch (spawned.regs.h.ah) {
-       case 1:                 /* Add */
-           spawned.regs.x.bx += spawned.regs.x.cx;
-           break;
-       case 2:                 /* Subtract */
-           spawned.regs.x.bx -= spawned.regs.x.cx;
-           break;
-       case 3:                 /* Multiply */
-           spawned.regs.x.bx *= spawned.regs.x.cx;
-           break;
-       case 4:                 /* Divide */
-           spawned.regs.x.bx /= spawned.regs.x.cx;
-           break;
-       default:
-           spawned.regs.h.al = -1;     /* Error */
-           spawned.regs.x.cflag = 1;
-           break;
-       }
-       spawned.regs.h.ah = 0;                  /* We saw this */
-       continue_spawn(&spawned);
-    }
-    if (spawned.rc != 0) {
-       fprintf(stderr, "Process generated a return code of 0x%x.\n",
-                                                               spawned.rc);
-    }
+    spint_finish(spint);
 }
 }