Reindented source code using astyle.
authorAdrian Pistol <vifino@tty.sh>
Mon, 31 Oct 2016 04:28:59 +0000 (05:28 +0100)
committerAdrian Pistol <vifino@tty.sh>
Mon, 31 Oct 2016 04:28:59 +0000 (05:28 +0100)
I tried GNU Indent too, but it decided to act up and throw random tabs here and there, which astyle did not.

23 files changed:
Makefile
aout.c
aout.h
branch.c
bsd_ioctl.c
bsd_signal.c
bsdtrap.c
bsdtrap.h
cpu.c
debug.c
defines.h
double.c
ea.c
fp.c
itab.c
ke11a.c
magic.c
main.c
single.c
v1trap.c
v1trap.h
v7trap.c
v7trap.h

index 04a46da..255280b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,8 +37,7 @@ BINDIR=$(PREFIX)/bin
 VERSION= apout2.3beta1
 SRCS=  cpu.c aout.c aout.h branch.c double.c ea.c itab.c main.c ke11a.c \
        single.c fp.c v7trap.c bsdtrap.c defines.h v7trap.h debug.c \
-       bsdtrap.h bsd_ioctl.c bsd_signal.c magic.c v1trap.c v1trap.h \
-       apout.1 apout.0 README COPYRIGHT CHANGES LIMITATIONS TODO Makefile
+       bsdtrap.h bsd_ioctl.c bsd_signal.c magic.c v1trap.c v1trap.h
 OBJS=  aout.o branch.o bsd_ioctl.o bsd_signal.o bsdtrap.o cpu.o debug.o \
        double.o ea.o fp.o itab.o ke11a.o magic.o main.o single.o v1trap.o \
        v7trap.o
@@ -46,7 +45,7 @@ OBJS= aout.o branch.o bsd_ioctl.o bsd_signal.o bsdtrap.o cpu.o debug.o \
 apout: $(OBJS)
        $(CC) $(LDFLAGS) $(OBJS) -o apout $(LIBS)
 
-install: apout
+install: apout apout.1
        cp apout $(BINDIR)
        chmod 755 $(BINDIR)/apout
        cp apout.1 $(MANDIR)
@@ -58,6 +57,9 @@ clean:
 apout.0: apout.1
        nroff -man apout.1 > apout.0
 
+indent: $(SRCS)
+       astyle --style=kr $(SRCS)
+
 disttar: clean apout.0
        - mkdir $(VERSION)
        cp $(SRCS) $(VERSION)
diff --git a/aout.c b/aout.c
index 290dc01..7758966 100644 (file)
--- a/aout.c
+++ b/aout.c
@@ -17,12 +17,40 @@ static u_int8_t darray[PDP_MEM_SIZE], iarray[PDP_MEM_SIZE];
  * a.out, if there are any. Missing overlays have size 0 and pointer NULL.
  */
 static struct {
-  u_int16_t size;
-  u_int8_t *ovlay;
+    u_int16_t size;
+    u_int8_t *ovlay;
 } ovlist[NOVL] = {
-    {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL},
-    {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL}, {0, NULL},
-    {0, NULL}, {0, NULL}, {0, NULL}
+    {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }, {
+        0, NULL
+    }
 };
 
 static u_int8_t *ovbase;       /* Base address of 2.11BSD overlays */
@@ -42,11 +70,12 @@ int Binary;                 /* Type of binary this a.out is */
  * Eventually there will be code to get some environment variables
  */
 static char *default_envp[4] = {
-  "PATH=/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/games:/usr/local/bin:.",
-  "HOME=/",
-  "TERM=vt100",
-  "USER=root"
+    "PATH=/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/games:/usr/local/bin:.",
+    "HOME=/",
+    "TERM=vt100",
+    "USER=root"
 };
+
 static int default_envc = 4;
 
 /* Prototypes */
@@ -57,57 +86,72 @@ static void set_arg_env(int want_env);
  * Also return an integer describing which version of UNIX the a.out
  * belongs to. If errors on reading, return -1.
  */
-int load_aout_header(FILE * zin, struct exec * E)
+int load_aout_header(FILE * zin, struct exec *E)
 {
-  char *cptr;
+    char *cptr;
 
-                               /* Read the a_magic value first */
-                               /* This makes it easier to deal with */
-                               /* parsing any script interpreter below */
-  if (fread(E, sizeof(u_int16_t), 1, zin) != 1) return (-1);
+    /* Read the a_magic value first */
+    /* This makes it easier to deal with */
+    /* parsing any script interpreter below */
+    if (fread(E, sizeof(u_int16_t), 1, zin) != 1)
+        return (-1);
 
-  switch (E->a_magic) {
-    case ANY_SCRIPT:           /* Shell script, return now */
-      return (IS_UNKNOWN);
+    switch (E->a_magic) {
+    case ANY_SCRIPT:   /* Shell script, return now */
+        return (IS_UNKNOWN);
     case V1_NORMAL:
-    case ANY_NORMAL:           /* These are recognised below */
+    case ANY_NORMAL:   /* These are recognised below */
     case ANY_ROTEXT:
     case ANY_SPLITID:
     case BSD_OVERLAY:
     case BSD_ROVERLAY:
     case A68_MAGIC:
-      break;
-
-    default:                   /* Unrecognised binary, mark as such */
-      E->a_magic = UNKNOWN_AOUT; return (IS_UNKNOWN);
-  }
-
-                               /* We can deal with this a.out, so */
-                               /* read in the rest of the header */
-  cptr = (char *) &(E->a_text);
-  if (fread(cptr, 1, sizeof(struct exec) - sizeof(u_int16_t), zin)
-               < 16 - sizeof (u_int16_t)) return (-1);
-
-  switch (E->a_magic) {
-    case A68_MAGIC: if (E->a_data==A68_DATA) return(IS_A68);
-                   else { E->a_magic = UNKNOWN_AOUT; return (IS_UNKNOWN); }
-    case V1_NORMAL: return (IS_V1);
+        break;
+
+    default:           /* Unrecognised binary, mark as such */
+        E->a_magic = UNKNOWN_AOUT;
+        return (IS_UNKNOWN);
+    }
+
+    /* We can deal with this a.out, so */
+    /* read in the rest of the header */
+    cptr = (char *) &(E->a_text);
+    if (fread(cptr, 1, sizeof(struct exec) - sizeof(u_int16_t), zin)
+            < 16 - sizeof(u_int16_t))
+        return (-1);
+
+    switch (E->a_magic) {
+    case A68_MAGIC:
+        if (E->a_data == A68_DATA)
+            return (IS_A68);
+        else {
+            E->a_magic = UNKNOWN_AOUT;
+            return (IS_UNKNOWN);
+        }
+    case V1_NORMAL:
+        return (IS_V1);
     case BSD_OVERLAY:
-    case BSD_ROVERLAY: return (IS_211BSD);
+    case BSD_ROVERLAY:
+        return (IS_211BSD);
     case ANY_NORMAL:
     case ANY_ROTEXT:
     case ANY_SPLITID:  /* Check crt0.o 2nd magic for V2/V6/V7/2.11BSD */
-      if (E->a_magic2 == V2_M2) return (IS_V2);
-      if (E->a_magic2 == V6_M2) return (IS_V6);
-      if (E->a_magic2 == V7_M2) return (IS_V7);
-      if (E->a_magic2 == BSD_M2) return (IS_211BSD);
-
-                               /* Still no idea, use checksum to determine */
-      return(special_magic((u_int16_t *) E));
-
-    default:                   /* Should never get here */
-      E->a_magic = UNKNOWN_AOUT; return (IS_UNKNOWN);
-  }
+        if (E->a_magic2 == V2_M2)
+            return (IS_V2);
+        if (E->a_magic2 == V6_M2)
+            return (IS_V6);
+        if (E->a_magic2 == V7_M2)
+            return (IS_V7);
+        if (E->a_magic2 == BSD_M2)
+            return (IS_211BSD);
+
+        /* Still no idea, use checksum to determine */
+        return (special_magic((u_int16_t *) E));
+
+    default:           /* Should never get here */
+        E->a_magic = UNKNOWN_AOUT;
+        return (IS_UNKNOWN);
+    }
 }
 
 
@@ -115,60 +159,75 @@ int load_aout_header(FILE * zin, struct exec * E)
  * and the re-call load_a_out to load in that binary. Returns 0 on
  * success, -1 on error. Input file is always closed by this routine.
  */
-int load_script(const char *file, const char *origpath,FILE * zin, int want_env)
+int load_script(const char *file, const char *origpath, FILE * zin,
+                int want_env)
 {
 #define SCRIPT_LINESIZE 512    /* Max size of 1st line in script */
-  char *script_line;
-  char *script_arg[MAX_ARGS];
-  int i, script_cnt = 0;
-  char **ap;
-
-  for (i=0;i<Argc;i++)
-    TrapDebug((dbg_file, "In load_script Argv[%d] is %s\n", i, Argv[i]));
-                               /* Get the first line of the file */
-  if (((script_line = (char *) malloc(SCRIPT_LINESIZE)) == NULL) ||
-      (fgets(script_line, SCRIPT_LINESIZE, zin) == NULL)) {
-    (void) fprintf(stderr, "Apout - could not read 1st line of script\n");
-    (void) fclose(zin);
-    return (-1);
-  }
-                               /* Now break into separate words */
-  for (ap = script_arg; (*ap = strsep(&script_line, " \t\n")) != NULL;)
-    if (**ap != '\0') {
-      ap++; script_cnt++;
-      if (script_cnt >= MAX_ARGS) break;
-    }
-  if (fclose(zin) != 0) { free(script_line); return (-1); }
+    char *script_line;
+    char *script_arg[MAX_ARGS];
+    int i, script_cnt = 0;
+    char **ap;
 
+    for (i = 0; i < Argc; i++)
+        TrapDebug((dbg_file, "In load_script Argv[%d] is %s\n", i,
+                   Argv[i]));
+    /* Get the first line of the file */
+    if (((script_line = (char *) malloc(SCRIPT_LINESIZE)) == NULL) ||
+            (fgets(script_line, SCRIPT_LINESIZE, zin) == NULL)) {
+        (void) fprintf(stderr,
+                       "Apout - could not read 1st line of script\n");
+        (void) fclose(zin);
+        return (-1);
+    }
+    /* Now break into separate words */
+    for (ap = script_arg; (*ap = strsep(&script_line, " \t\n")) != NULL;)
+        if (**ap != '\0') {
+            ap++;
+            script_cnt++;
+            if (script_cnt >= MAX_ARGS)
+                break;
+        }
+    if (fclose(zin) != 0) {
+        free(script_line);
+        return (-1);
+    }
 #ifdef DEBUG
-  TrapDebug((dbg_file, "Script: extra args are is %d\n", script_cnt));
-  if (trap_debug) {
-    for (i = 0; i < script_cnt; i++)
-      fprintf(dbg_file, " script_arg[%d] is %s\n", i, script_arg[i]);
-  }
+    TrapDebug((dbg_file, "Script: extra args are is %d\n", script_cnt));
+    if (trap_debug) {
+        for (i = 0; i < script_cnt; i++)
+            fprintf(dbg_file, " script_arg[%d] is %s\n", i, script_arg[i]);
+    }
 #endif
 
-                               /* Ensure we have room to shift the args */
-  if ((Argc + script_cnt) > MAX_ARGS) {
-    (void) fprintf(stderr, "Apout - out of argv space in script\n");
-    free(script_line); return (-1);
-  }
-                               /* Now shift the args up and insert new ones */
-  for (i = Argc - 1; i != 0; i--) Argv[i + script_cnt] = Argv[i];
-  for (i=0;i<Argc;i++)
-    TrapDebug((dbg_file, "Part A load_script Argv[%d] is %s\n", i, Argv[i]));
-  for (i = 0; i < script_cnt; i++) Argv[i] = script_arg[i];
-  if (origpath!=NULL) Argv[i] = strdup(origpath);
-  else Argv[i] = strdup(file);
-  Argc += script_cnt;
-  for (i=0;i<Argc;i++)
-    TrapDebug((dbg_file, "Part B load_script Argv[%d] is %s\n", i, Argv[i]));
-
-  file = xlate_filename(script_arg[0]);
-  free(script_line);
-  for (i=0;i<Argc;i++)
-    TrapDebug((dbg_file, "Leaving load_script Argv[%d] is %s\n", i, Argv[i]));
-  return (load_a_out(file, origpath, want_env));
+    /* Ensure we have room to shift the args */
+    if ((Argc + script_cnt) > MAX_ARGS) {
+        (void) fprintf(stderr, "Apout - out of argv space in script\n");
+        free(script_line);
+        return (-1);
+    }
+    /* Now shift the args up and insert new ones */
+    for (i = Argc - 1; i != 0; i--)
+        Argv[i + script_cnt] = Argv[i];
+    for (i = 0; i < Argc; i++)
+        TrapDebug((dbg_file, "Part A load_script Argv[%d] is %s\n", i,
+                   Argv[i]));
+    for (i = 0; i < script_cnt; i++)
+        Argv[i] = script_arg[i];
+    if (origpath != NULL)
+        Argv[i] = strdup(origpath);
+    else
+        Argv[i] = strdup(file);
+    Argc += script_cnt;
+    for (i = 0; i < Argc; i++)
+        TrapDebug((dbg_file, "Part B load_script Argv[%d] is %s\n", i,
+                   Argv[i]));
+
+    file = xlate_filename(script_arg[0]);
+    free(script_line);
+    for (i = 0; i < Argc; i++)
+        TrapDebug((dbg_file, "Leaving load_script Argv[%d] is %s\n", i,
+                   Argv[i]));
+    return (load_a_out(file, origpath, want_env));
 }
 
 
@@ -179,331 +238,380 @@ int load_script(const char *file, const char *origpath,FILE * zin, int want_env)
  * parent, or NULL if this is not known.
  */
 int load_a_out(const char *file, const char *origpath, int want_env)
-{                              /* @globals errno,stdout,stderr; @ */
+{
+    /* @globals errno,stdout,stderr; @ */
 #define V12_MEMBASE 16384      /* Offset for V1/V2 binaries load */
-  FILE *zin;
-  struct exec e;
-  u_int8_t *ibase, *dbase, *bbase;     /* Instruction, data, bss bases */
-  u_int16_t size;
-  int i;
+    FILE *zin;
+    struct exec e;
+    u_int8_t *ibase, *dbase, *bbase;   /* Instruction, data, bss bases */
+    u_int16_t size;
+    int i;
 #ifdef EMU211
-  int j;
+    int j;
 #endif
 #ifdef RUN_V1_RAW
-  struct stat stb;
+    struct stat stb;
 #endif
 
-  for (i=0;i<Argc;i++)
-    TrapDebug((dbg_file, "In load_a_out Argv[%d] is %s\n", i, Argv[i]));
+    for (i = 0; i < Argc; i++)
+        TrapDebug((dbg_file, "In load_a_out Argv[%d] is %s\n", i,
+                   Argv[i]));
 
-  (void) signal(SIGBUS, bus_error);    /* Catch all bus errors here */
+    (void) signal(SIGBUS, bus_error);  /* Catch all bus errors here */
 
-  if ((zin = fopen(file, "r"))==NULL)  /* Open the file */
-    return (-1);
+    if ((zin = fopen(file, "r")) == NULL)      /* Open the file */
+        return (-1);
 
-  Binary = load_aout_header(zin, &e);  /* Determine a.out & Unix type */
+    Binary = load_aout_header(zin, &e);        /* Determine a.out & Unix type */
 
-  if (e.a_magic == ANY_SCRIPT) {       /* Shell script, run that */
-    return (load_script(file, origpath, zin, want_env));
-  }
+    if (e.a_magic == ANY_SCRIPT) {     /* Shell script, run that */
+        return (load_script(file, origpath, zin, want_env));
+    }
 #ifndef EMU211
-  if (Binary == IS_211BSD) {
-    (void) fprintf(stderr, "Apout not compiled to support 2.11BSD binaries\n");
-    (void) fclose(zin); return (-1);
-  }
+    if (Binary == IS_211BSD) {
+        (void) fprintf(stderr,
+                       "Apout not compiled to support 2.11BSD binaries\n");
+        (void) fclose(zin);
+        return (-1);
+    }
 #endif
 #ifndef EMUV1
-  if (Binary == IS_V1) {
-    (void) fprintf(stderr,
-                  "Apout not compiled to support 1st Edition binaries\n");
-    (void) fclose(zin); return (-1);
-  }
-  if (Binary == IS_V2) {
-    (void) fprintf(stderr,
-                  "Apout not compiled to support 2nd Edition binaries\n");
-    (void) fclose(zin); return (-1);
-  }
+    if (Binary == IS_V1) {
+        (void) fprintf(stderr,
+                       "Apout not compiled to support 1st Edition binaries\n");
+        (void) fclose(zin);
+        return (-1);
+    }
+    if (Binary == IS_V2) {
+        (void) fprintf(stderr,
+                       "Apout not compiled to support 2nd Edition binaries\n");
+        (void) fclose(zin);
+        return (-1);
+    }
 #endif
 
 #ifdef NATIVES
-                                       /* Executable was not recognised.
-                                        * Try to exec it as a native binary.
-                                        * If it fails, doesn't matter. If it
-                                        * succeeds, then great. This allows
-                                        * us to have mixed native and PDP-11
-                                        * binaries in the same filespace.
-                                        */
-  if (e.a_magic == UNKNOWN_AOUT) {
+    /* Executable was not recognised.
+     * Try to exec it as a native binary.
+     * If it fails, doesn't matter. If it
+     * succeeds, then great. This allows
+     * us to have mixed native and PDP-11
+     * binaries in the same filespace.
+     */
+    if (e.a_magic == UNKNOWN_AOUT) {
 #ifdef DEBUG
-    TrapDebug((dbg_file, "About to try native exec on %s\n", file));
-    fflush(dbg_file);
+        TrapDebug((dbg_file, "About to try native exec on %s\n", file));
+        fflush(dbg_file);
 #endif
-    (void) fclose(zin);
-    execv(file, Argv);         /* envp[] is the one Apout's main() got */
-    TrapDebug((dbg_file, "Nope, didn't work\n"));
+        (void) fclose(zin);
+        execv(file, Argv);     /* envp[] is the one Apout's main() got */
+        TrapDebug((dbg_file, "Nope, didn't work\n"));
 #endif
 
 #ifdef RUN_V1_RAW
-                               /* Try to run it as a V1 raw binary */
+        /* Try to run it as a V1 raw binary */
 #ifdef DEBUG
-    TrapDebug((dbg_file, "About to try PDP-11 raw exec on %s\n", file));
-    fflush(dbg_file);
-#endif /* DEBUG */
-    if ((zin = fopen(file, "r"))==NULL)        /* reopen the file */
-      return (-1);
-    e.a_magic = V1_RAW;
-    Binary = IS_V1;
+        TrapDebug((dbg_file, "About to try PDP-11 raw exec on %s\n",
+                   file));
+        fflush(dbg_file);
+#endif                         /* DEBUG */
+        if ((zin = fopen(file, "r")) == NULL)  /* reopen the file */
+            return (-1);
+        e.a_magic = V1_RAW;
+        Binary = IS_V1;
 #else
-     (void) fprintf(stderr, "Apout - unknown a.out file %s\n", file);
-     return (-1);
-#endif /* RUN_V1_RAW */
-  }
-                                       /* Now we know what environment to
-                                        * create, set up the memory areas
-                                        * according to the magic numbers
-                                        */
+        (void) fprintf(stderr, "Apout - unknown a.out file %s\n", file);
+        return (-1);
+#endif                         /* RUN_V1_RAW */
+    }
+    /* Now we know what environment to
+     * create, set up the memory areas
+     * according to the magic numbers
+     */
 #ifdef DEBUG
-  switch(Binary) {
-    case IS_A68: TrapDebug((dbg_file, "A68 binary\n")); break;
-    case IS_V1:  TrapDebug((dbg_file, "V1 binary\n")); break;
-    case IS_V2:  TrapDebug((dbg_file, "V2 binary\n")); break;
-    case IS_V5:  TrapDebug((dbg_file, "V5 binary\n")); break;
-    case IS_V6:  TrapDebug((dbg_file, "V6 binary\n")); break;
-    case IS_V7:  TrapDebug((dbg_file, "V7 binary\n")); break;
-    case IS_211BSD: TrapDebug((dbg_file, "2.11BSD binary\n")); break;
-  }
+    switch (Binary) {
+    case IS_A68:
+        TrapDebug((dbg_file, "A68 binary\n"));
+        break;
+    case IS_V1:
+        TrapDebug((dbg_file, "V1 binary\n"));
+        break;
+    case IS_V2:
+        TrapDebug((dbg_file, "V2 binary\n"));
+        break;
+    case IS_V5:
+        TrapDebug((dbg_file, "V5 binary\n"));
+        break;
+    case IS_V6:
+        TrapDebug((dbg_file, "V6 binary\n"));
+        break;
+    case IS_V7:
+        TrapDebug((dbg_file, "V7 binary\n"));
+        break;
+    case IS_211BSD:
+        TrapDebug((dbg_file, "2.11BSD binary\n"));
+        break;
+    }
 #endif
 
-  switch (e.a_magic) {
+    switch (e.a_magic) {
 #ifdef RUN_V1_RAW
     case V1_RAW:
-      if (fseek(zin, 0, SEEK_SET) != 0) {
-       (void) fclose(zin); return (-1);
-      }
-      ispace = dspace = darray;
-      ibase = &(ispace[V12_MEMBASE]);  /* Load & run the binary starting */
-      dbase = ibase;                   /* at address 16384 (040000) */
-      dwrite_base = 0;
-      e.a_entry = V12_MEMBASE;
-      /* Reset the exec header fields to make loading code below
-       * work properly
-       */
-      if (stat(file, &stb)) {
-       fprintf(stderr, "Apout - cannot stat %s\n", file);
-       return -1;
-      }
-      e.a_text = stb.st_size;
-      bbase = &(ispace[V12_MEMBASE + e.a_text]);
-      e.a_data = 0;
-      break;
+        if (fseek(zin, 0, SEEK_SET) != 0) {
+            (void) fclose(zin);
+            return (-1);
+        }
+        ispace = dspace = darray;
+        ibase = &(ispace[V12_MEMBASE]);        /* Load & run the binary starting */
+        dbase = ibase; /* at address 16384 (040000) */
+        dwrite_base = 0;
+        e.a_entry = V12_MEMBASE;
+        /* Reset the exec header fields to make loading code below
+         * work properly
+         */
+        if (stat(file, &stb)) {
+            fprintf(stderr, "Apout - cannot stat %s\n", file);
+            return -1;
+        }
+        e.a_text = stb.st_size;
+        bbase = &(ispace[V12_MEMBASE + e.a_text]);
+        e.a_data = 0;
+        break;
 #endif
 #ifdef EMUV1
-    case V1_NORMAL:                    /* V1 a.out binary looks like */
-      e.a_bss = e.a_syms;              /* 0405                       */
-      e.a_syms = e.a_data;             /* size of text               */
-      e.a_data = 0;                    /* size of symbol table       */
-                                       /* reloc bits                 */
-                                       /* size of data (i.e bss)     */
-                                       /* unused and zeroed          */
-                                       /* We must rearrange fields   */
-                                       /* Move back to start of V1 header */
-      if (fseek(zin, 0, SEEK_SET) != 0) {
-       (void) fclose(zin); return (-1);
-      }
-      ispace = dspace = darray;
-      ibase = &(ispace[V12_MEMBASE]);  /* Load & run the binary starting */
-      dbase = &(ispace[e.a_text]);     /* at address 16384 (040000) */
-      bbase = &(ispace[e.a_text + e.a_data]);
-      dwrite_base = 0;
-      e.a_entry = V12_MEMBASE;
-      break;
+    case V1_NORMAL:    /* V1 a.out binary looks like */
+        e.a_bss = e.a_syms;    /* 0405                       */
+        e.a_syms = e.a_data;   /* size of text               */
+        e.a_data = 0;  /* size of symbol table       */
+        /* reloc bits                 */
+        /* size of data (i.e bss)     */
+        /* unused and zeroed          */
+        /* We must rearrange fields   */
+        /* Move back to start of V1 header */
+        if (fseek(zin, 0, SEEK_SET) != 0) {
+            (void) fclose(zin);
+            return (-1);
+        }
+        ispace = dspace = darray;
+        ibase = &(ispace[V12_MEMBASE]);        /* Load & run the binary starting */
+        dbase = &(ispace[e.a_text]);   /* at address 16384 (040000) */
+        bbase = &(ispace[e.a_text + e.a_data]);
+        dwrite_base = 0;
+        e.a_entry = V12_MEMBASE;
+        break;
 #endif
-    case A68_MAGIC:                    /* Algol 68 image */
-       if (fseek(zin, 0, SEEK_SET) != 0) {
-         (void) fclose(zin); return (-1);
-       }
-       e.a_text= e.ov_siz[0]+1;
-       e.a_data= 0;
-       e.a_bss= 0160000-e.a_text;
-       e.a_entry= e.a_flag;
-       ibase = ispace = dspace = darray;
-       dbase= ibase;
-       dwrite_base = 0;
-       bbase= &(ispace[e.a_text+e.a_data]);
-       break;
+    case A68_MAGIC:    /* Algol 68 image */
+        if (fseek(zin, 0, SEEK_SET) != 0) {
+            (void) fclose(zin);
+            return (-1);
+        }
+        e.a_text = e.ov_siz[0] + 1;
+        e.a_data = 0;
+        e.a_bss = 0160000 - e.a_text;
+        e.a_entry = e.a_flag;
+        ibase = ispace = dspace = darray;
+        dbase = ibase;
+        dwrite_base = 0;
+        bbase = &(ispace[e.a_text + e.a_data]);
+        break;
     case ANY_NORMAL:
-                                       /* Move back to end of V5/6/7 header */
-      if (fseek(zin, 16, SEEK_SET) != 0) {
-       (void) fclose(zin); return (-1);
-      }
-      ibase = ispace = dspace = darray;
+        /* Move back to end of V5/6/7 header */
+        if (fseek(zin, 16, SEEK_SET) != 0) {
+            (void) fclose(zin);
+            return (-1);
+        }
+        ibase = ispace = dspace = darray;
 #ifdef EMUV1
-      if (Binary == IS_V2) {
-       ibase = &(ispace[V12_MEMBASE]);
-        e.a_entry = V12_MEMBASE;
-        dbase = &(ispace[e.a_text + V12_MEMBASE]);
-        bbase = &(ispace[e.a_text + e.a_data + V12_MEMBASE]);
-      } else
+        if (Binary == IS_V2) {
+            ibase = &(ispace[V12_MEMBASE]);
+            e.a_entry = V12_MEMBASE;
+            dbase = &(ispace[e.a_text + V12_MEMBASE]);
+            bbase = &(ispace[e.a_text + e.a_data + V12_MEMBASE]);
+        } else
 #endif
-      {
-        dbase = &(ispace[e.a_text]);
-        bbase = &(ispace[e.a_text + e.a_data]);
-      }
-      if ((Binary < IS_V7))
-          dwrite_base = 0;
-      else dwrite_base = e.a_text;
-      break;
+        {
+            dbase = &(ispace[e.a_text]);
+            bbase = &(ispace[e.a_text + e.a_data]);
+        }
+        if ((Binary < IS_V7))
+            dwrite_base = 0;
+        else
+            dwrite_base = e.a_text;
+        break;
     case ANY_ROTEXT:
-                                       /* Move back to end of V5/6/7 header */
-      if (fseek(zin, 16, SEEK_SET) != 0) {
-       (void) fclose(zin); return (-1);
-      }
-      /* @fallthrough@ */
+        /* Move back to end of V5/6/7 header */
+        if (fseek(zin, 16, SEEK_SET) != 0) {
+            (void) fclose(zin);
+            return (-1);
+        }
+    /* @fallthrough@ */
     case BSD_OVERLAY:
-                               /* Round up text area to next 8K boundary */
-      if (e.a_text % EIGHT_K) {
-       size = EIGHT_K * (1 + e.a_text / EIGHT_K);
-      } else size = e.a_text;
-                               /* And the next 8K boundary if overlays! */
-      if (e.a_magic == BSD_OVERLAY) {
-       if (e.max_ovl % EIGHT_K) {
-         size += EIGHT_K * (1 + e.max_ovl / EIGHT_K);
-       } else size += e.max_ovl;
-      }
-      ibase = ispace = dspace = darray;
-      dbase = &(ispace[size]);
-      bbase = &(ispace[size + e.a_data]);
-      dwrite_base = size;
-      break;
+        /* Round up text area to next 8K boundary */
+        if (e.a_text % EIGHT_K) {
+            size = EIGHT_K * (1 + e.a_text / EIGHT_K);
+        } else
+            size = e.a_text;
+        /* And the next 8K boundary if overlays! */
+        if (e.a_magic == BSD_OVERLAY) {
+            if (e.max_ovl % EIGHT_K) {
+                size += EIGHT_K * (1 + e.max_ovl / EIGHT_K);
+            } else
+                size += e.max_ovl;
+        }
+        ibase = ispace = dspace = darray;
+        dbase = &(ispace[size]);
+        bbase = &(ispace[size + e.a_data]);
+        dwrite_base = size;
+        break;
     case ANY_SPLITID:
-                                       /* Move back to end of V5/6/7 header */
-      if (fseek(zin, 16, SEEK_SET) != 0) {
-       (void) fclose(zin); return (-1);
-      }
-      /* @fallthrough@ */
+        /* Move back to end of V5/6/7 header */
+        if (fseek(zin, 16, SEEK_SET) != 0) {
+            (void) fclose(zin);
+            return (-1);
+        }
+    /* @fallthrough@ */
     case BSD_ROVERLAY:
-      ibase = ispace = iarray;
-      dbase = dspace = darray;
-      bbase = &(dspace[e.a_data]);
-      
-                                       /* Try to stop null refs */
-      if (Binary == IS_211BSD) dwrite_base = 0;
-      else dwrite_base = 2;
-      break;
+        ibase = ispace = iarray;
+        dbase = dspace = darray;
+        bbase = &(dspace[e.a_data]);
+
+        /* Try to stop null refs */
+        if (Binary == IS_211BSD)
+            dwrite_base = 0;
+        else
+            dwrite_base = 2;
+        break;
     default:
-      (void) fprintf(stderr, "Apout - unknown a.out format 0%o\n", e.a_magic);
-      (void) fclose(zin); return (-1);
-  }
+        (void) fprintf(stderr, "Apout - unknown a.out format 0%o\n",
+                       e.a_magic);
+        (void) fclose(zin);
+        return (-1);
+    }
 
 
-               /* Initialise the instruction table for our environment */
-  switch (Binary) {
+    /* Initialise the instruction table for our environment */
+    switch (Binary) {
 #ifdef EMU211
     case IS_211BSD:
-      for (i = 548; i < 552; i++) itab[i] = bsdtrap;
-      break;
+        for (i = 548; i < 552; i++)
+            itab[i] = bsdtrap;
+        break;
 #endif
 #ifdef EMUV1
     case IS_V1:
     case IS_V2:
-      for (i = 544; i < 548; i++) itab[i] = rts;
-      for (i = 548; i < 552; i++) itab[i] = v1trap;
-      break;
+        for (i = 544; i < 548; i++)
+            itab[i] = rts;
+        for (i = 548; i < 552; i++)
+            itab[i] = v1trap;
+        break;
 #endif
     case IS_A68:
-      for (i = 544; i < 552; i++) itab[i] = v7trap;
-      break;
+        for (i = 544; i < 552; i++)
+            itab[i] = v7trap;
+        break;
     case IS_V5:
     case IS_V6:
     case IS_V7:
-      for (i = 548; i < 552; i++) itab[i] = v7trap;
-      break;
+        for (i = 548; i < 552; i++)
+            itab[i] = v7trap;
+        break;
     default:
-      fprintf(stderr, "Apout - unknown Unix version for %s\n", file);
-      exit(EXIT_FAILURE);
-  }
+        fprintf(stderr, "Apout - unknown Unix version for %s\n", file);
+        exit(EXIT_FAILURE);
+    }
 
 #ifdef ZERO_MEMORY
-  memset(darray, 0, PDP_MEM_SIZE);     /* Clear all memory */
-  if (ispace != dspace) memset(iarray, 0, PDP_MEM_SIZE);
+    memset(darray, 0, PDP_MEM_SIZE);   /* Clear all memory */
+    if (ispace != dspace)
+        memset(iarray, 0, PDP_MEM_SIZE);
 #endif
 
-                                       /* Now load the text into ibase */
-  for (size = e.a_text; size;) {
-    i = (int) fread(ibase, 1, (size_t) size, zin);
-    if (i == -1) { (void) fclose(zin); return (i); }
-    size -= i;
-    ibase += i;
-  }
+    /* Now load the text into ibase */
+    for (size = e.a_text; size;) {
+        i = (int) fread(ibase, 1, (size_t) size, zin);
+        if (i == -1) {
+            (void) fclose(zin);
+            return (i);
+        }
+        size -= i;
+        ibase += i;
+    }
 
 #ifdef EMU211
-  /* Now deal with any overlays */
-  if (Binary == IS_211BSD)
-    switch (e.a_magic) {
-      case BSD_OVERLAY:
-      case BSD_ROVERLAY:
-                               /* Round up text area to next 8K boundary */
-       if (e.a_text % EIGHT_K) {
-         size = EIGHT_K * (1 + e.a_text / EIGHT_K);
-       } else size = e.a_text;
-       ovbase = &ispace[size];
-
-       for (i = 0; i < NOVL; i++) {
-         if (e.ov_siz[i] == 0) {
-           ovlist[i].size = 0;
-           ovlist[i].ovlay = NULL;
-           continue;
-         }
-                                       /* Create memory for the overlay */
-         ovlist[i].size = e.ov_siz[i];
-         if (ovlist[i].ovlay)
-           free(ovlist[i].ovlay);
-         ovlist[i].ovlay = (u_int8_t *) malloc(e.ov_siz[i]);
-         if (ovlist[i].ovlay == NULL) {
-           fprintf(stderr, "Apout - can't malloc overlay!\n");
-           exit(EXIT_FAILURE);
-         }
-                                       /* Load the overlay into memory */
-         for (size = ovlist[i].size, ibase = ovlist[i].ovlay; size;) {
-           j = fread(ibase, 1, size, zin);
-           if (j == -1) {
-             fclose(zin); return (j);
-           }
-           size -= j;
-           ibase += j;
-         }
-       }
-
-                               /* And deal with the emt instructions */
-       for (i = 544; i < 548; i++)
-         itab[i] = do_bsd_overlay;
-    }
+    /* Now deal with any overlays */
+    if (Binary == IS_211BSD)
+        switch (e.a_magic) {
+        case BSD_OVERLAY:
+        case BSD_ROVERLAY:
+            /* Round up text area to next 8K boundary */
+            if (e.a_text % EIGHT_K) {
+                size = EIGHT_K * (1 + e.a_text / EIGHT_K);
+            } else
+                size = e.a_text;
+            ovbase = &ispace[size];
+
+            for (i = 0; i < NOVL; i++) {
+                if (e.ov_siz[i] == 0) {
+                    ovlist[i].size = 0;
+                    ovlist[i].ovlay = NULL;
+                    continue;
+                }
+                /* Create memory for the overlay */
+                ovlist[i].size = e.ov_siz[i];
+                if (ovlist[i].ovlay)
+                    free(ovlist[i].ovlay);
+                ovlist[i].ovlay = (u_int8_t *) malloc(e.ov_siz[i]);
+                if (ovlist[i].ovlay == NULL) {
+                    fprintf(stderr, "Apout - can't malloc overlay!\n");
+                    exit(EXIT_FAILURE);
+                }
+                /* Load the overlay into memory */
+                for (size = ovlist[i].size, ibase = ovlist[i].ovlay;
+                        size;) {
+                    j = fread(ibase, 1, size, zin);
+                    if (j == -1) {
+                        fclose(zin);
+                        return (j);
+                    }
+                    size -= j;
+                    ibase += j;
+                }
+            }
+
+            /* And deal with the emt instructions */
+            for (i = 544; i < 548; i++)
+                itab[i] = do_bsd_overlay;
+        }
 #endif
 
-                               /* Now load the data into dbase */
-  if (dbase)
-    for (size = e.a_data; size;) {
-      i = (int) fread(dbase, 1, (size_t) size, zin);
-      if (i == -1) { (void) fclose(zin); return (i); }
-      size -= i;
-      dbase += i;
-    }
+    /* Now load the data into dbase */
+    if (dbase)
+        for (size = e.a_data; size;) {
+            i = (int) fread(dbase, 1, (size_t) size, zin);
+            if (i == -1) {
+                (void) fclose(zin);
+                return (i);
+            }
+            size -= i;
+            dbase += i;
+        }
+
+    /* Now clear the bss */
+    if ((bbase != 0) && (e.a_bss != 0))
+        memset(bbase, 0, (size_t) e.a_bss);
+
 
-                               /* Now clear the bss */
-  if ((bbase != 0) && (e.a_bss != 0))
-    memset(bbase, 0, (size_t) e.a_bss);
-
-
-  /* Set up the registers and flags, and the stack */
-  (void) fclose(zin);
-  sim_init();
-  regs[PC] = e.a_entry;
-  if( Binary == IS_A68 ) {
-      regs[5]= e.max_ovl;
-      regs[4]= 0160000;
-  }
-  set_arg_env(want_env);
-  return (0);
+    /* Set up the registers and flags, and the stack */
+    (void) fclose(zin);
+    sim_init();
+    regs[PC] = e.a_entry;
+    if (Binary == IS_A68) {
+        regs[5] = e.max_ovl;
+        regs[4] = 0160000;
+    }
+    set_arg_env(want_env);
+    return (0);
 }
 
 /*
@@ -550,75 +658,78 @@ int load_a_out(const char *file, const char *origpath, int want_env)
  */
 static void set_arg_env(int want_env)
 {
-  int i, posn, len;
-  int eposn[MAX_ARGS];
-  int aposn[MAX_ARGS];
-
-                               /* Set default environment if there is none */
-  if (Envp[0] == NULL) {
-    Envc = default_envc;
-    for (i = 0; i < Envc; i++)
-      Envp[i] = default_envp[i];
-  }
+    int i, posn, len;
+    int eposn[MAX_ARGS];
+    int aposn[MAX_ARGS];
+
+    /* Set default environment if there is none */
+    if (Envp[0] == NULL) {
+        Envc = default_envc;
+        for (i = 0; i < Envc; i++)
+            Envp[i] = default_envp[i];
+    }
 #ifdef DEBUG
-                       /* Set up the program's name -- used for debugging */
-  if (progname) free(progname);
-  progname = strdup(Argv[0]);
-
-  if (trap_debug) {
-    fprintf(dbg_file, "In set_arg_env, Argc is %d\n", Argc);
-    for (i = 0; i < Argc; i++)
-      fprintf(dbg_file, "  Argv[%d] is %s\n", i, Argv[i]);
-    for (i = 0; i < Envc; i++)
-      fprintf(dbg_file, "  Envp[%d] is %s\n", i, Envp[i]);
-  }
+    /* Set up the program's name -- used for debugging */
+    if (progname)
+        free(progname);
+    progname = strdup(Argv[0]);
+
+    if (trap_debug) {
+        fprintf(dbg_file, "In set_arg_env, Argc is %d\n", Argc);
+        for (i = 0; i < Argc; i++)
+            fprintf(dbg_file, "  Argv[%d] is %s\n", i, Argv[i]);
+        for (i = 0; i < Envc; i++)
+            fprintf(dbg_file, "  Envp[%d] is %s\n", i, Envp[i]);
+    }
 #endif
 
-                       /* Now build the arguments and pointers on the stack */
+    /* Now build the arguments and pointers on the stack */
 
 #ifdef EMUV1
-  if ((Binary == IS_V1) || (Binary == IS_V2))
-    posn = KE11LO - 2;                         /* Start below the KE11A */
-  else
+    if ((Binary == IS_V1) || (Binary == IS_V2))
+        posn = KE11LO - 2;     /* Start below the KE11A */
+    else
 #endif
-    posn = PDP_MEM_SIZE - 2;
-  sl_word(posn, 0);                            /* Put a NULL on top of stack */
-
-  if (want_env == 1)
-    for (i = Envc - 1; i != -1; i--) {         /* For each env string */
-      len = strlen(Envp[i]) + 1;               /* get its length */
-      posn -= len;
-      memcpy(&dspace[posn], Envp[i], (size_t) len);
-      eposn[i] = posn;
-    }
-
-  for (i = Argc - 1; i != -1; i--) {           /* For each arg string */
-    len = strlen(Argv[i]) + 1;                 /* get its length */
-    posn -= len;
-    memcpy(&dspace[posn], Argv[i], (size_t) len);
-    aposn[i] = posn;
-  }
-  posn -= 2;
-  sl_word(posn, 0);                    /* Put a NULL at end of env array */
-
-  if (want_env == 1) {                 /* For each env string */
-    for (i = Envc - 1; i != -1; i--) {
-      posn -= 2;                       /* put a pointer to the string */
-      sl_word(posn, (u_int16_t) eposn[i]);
+        posn = PDP_MEM_SIZE - 2;
+    sl_word(posn, 0);          /* Put a NULL on top of stack */
+
+    if (want_env == 1)
+        for (i = Envc - 1; i != -1; i--) {     /* For each env string */
+            len = strlen(Envp[i]) + 1; /* get its length */
+            posn -= len;
+            memcpy(&dspace[posn], Envp[i], (size_t) len);
+            eposn[i] = posn;
+        }
+
+    for (i = Argc - 1; i != -1; i--) { /* For each arg string */
+        len = strlen(Argv[i]) + 1;     /* get its length */
+        posn -= len;
+        memcpy(&dspace[posn], Argv[i], (size_t) len);
+        aposn[i] = posn;
     }
     posn -= 2;
-  }
-                                       /* Put a NULL or -1 before arg ptrs */
-  if (want_env == 0) sl_word(posn, -1)
-  else sl_word(posn, 0);
-
-  for (i = Argc - 1; i != -1; i--) {           /* For each arg string */
+    sl_word(posn, 0);          /* Put a NULL at end of env array */
+
+    if (want_env == 1) {       /* For each env string */
+        for (i = Envc - 1; i != -1; i--) {
+            posn -= 2;         /* put a pointer to the string */
+            sl_word(posn, (u_int16_t) eposn[i]);
+        }
+        posn -= 2;
+    }
+    /* Put a NULL or -1 before arg ptrs */
+    if (want_env == 0)
+        sl_word(posn, -1)
+        else
+            sl_word(posn, 0);
+
+    for (i = Argc - 1; i != -1; i--) { /* For each arg string */
+        posn -= 2;
+        sl_word(posn, (u_int16_t) aposn[i]);   /* put a ptr to the string */
+    }
     posn -= 2;
-    sl_word(posn, (u_int16_t) aposn[i]);       /* put a ptr to the string */
-  }
-  posn -= 2;
-  sl_word(posn, (u_int16_t) Argc);             /* Save the count of args */
-  regs[SP] = (u_int16_t) posn;                 /* and initialise the SP */
+    sl_word(posn, (u_int16_t) Argc);   /* Save the count of args */
+    regs[SP] = (u_int16_t) posn;       /* and initialise the SP */
 }
 
 
@@ -631,17 +742,17 @@ static void set_arg_env(int want_env)
 
 void do_bsd_overlay()
 {
-  int ov = regs[0] - 1;
-
-  if (ovlist[ov].size == 0) {
-    fprintf(stderr, "Apout - can't switch to empty overlay %d\n", ov);
-    exit(EXIT_FAILURE);
-  }
-  JsrDebug((dbg_file, "switching to overlay %d\n", ov));
-
-  /* Memcpy overlay into main ispace */
-  memcpy(ovbase, ovlist[ov].ovlay, ovlist[ov].size);
-  ov_changes++;
-  current_ov = ov;
+    int ov = regs[0] - 1;
+
+    if (ovlist[ov].size == 0) {
+        fprintf(stderr, "Apout - can't switch to empty overlay %d\n", ov);
+        exit(EXIT_FAILURE);
+    }
+    JsrDebug((dbg_file, "switching to overlay %d\n", ov));
+
+    /* Memcpy overlay into main ispace */
+    memcpy(ovbase, ovlist[ov].ovlay, ovlist[ov].size);
+    ov_changes++;
+    current_ov = ov;
 }
 #endif
diff --git a/aout.h b/aout.h
index c863608..1b5e759 100644 (file)
--- a/aout.h
+++ b/aout.h
@@ -17,7 +17,7 @@
 #define ANY_SCRIPT     020443  /* Shell script, i.e #! */
 #define A68_MAGIC      0       /* Algol68 binaries have these magic nums */
 #define A68_DATA        0107116        /* Algol68 binaries have these magic nums */
-#define V1_RAW          0104421 /* V1 'raw' binary: rm, ln, chmod from s2
+#define V1_RAW          0104421        /* V1 'raw' binary: rm, ln, chmod from s2
                                   archive. */
 
 #define UNKNOWN_AOUT   034567  /* An unknown a.out header */
@@ -32,15 +32,15 @@ struct exec {
     u_int16_t a_entry;         /* entry point */
     u_int16_t a_unused;                /* unused */
     u_int16_t a_flag;          /* relocation info stripped */
-                               /* 16 bytes up to here */
+    /* 16 bytes up to here */
 
-                               /* 2.11BSD overlay files have the following */
+    /* 2.11BSD overlay files have the following */
 #define NOVL   15
-     int16_t max_ovl;          /* maximum overlay size */
+    int16_t max_ovl;           /* maximum overlay size */
     u_int16_t ov_siz[NOVL];    /* size of the i'th overlay */
-                               /* Note that if the file isn't a 2.11BSD */
-                               /* overlay, we have to rewind to undo */
-                               /* the read of this section */
+    /* Note that if the file isn't a 2.11BSD */
+    /* overlay, we have to rewind to undo */
+    /* the read of this section */
 };
 
 /* Because V5, V6, V7 and 2.11BSD share several magic numbers
@@ -50,7 +50,7 @@ struct exec {
  * differ at position 021
  */
 #define a_magic2       ov_siz[0]
-#define V2_M2          0177304         /* Doesn't apply to all, tho */
+#define V2_M2          0177304 /* Doesn't apply to all, tho */
 #define V6_M2          0010600
 #define V7_M2          0016600
 #define BSD_M2         0162706
index 94ab008..64476f0 100644 (file)
--- a/branch.c
+++ b/branch.c
 
 static u_int16_t offset;
 
-void bne() {
-    if (CC_Z==0) do_branch();
+void bne()
+{
+    if (CC_Z == 0)
+        do_branch();
 }
-void beq() {
-    if (CC_Z==1) do_branch();
+
+void beq()
+{
+    if (CC_Z == 1)
+        do_branch();
 }
-void bpl() {
-    if (CC_N==0) do_branch();
+
+void bpl()
+{
+    if (CC_N == 0)
+        do_branch();
 }
-void bmi() {
-    if (CC_N==1) do_branch();
+
+void bmi()
+{
+    if (CC_N == 1)
+        do_branch();
 }
-void bhi() {
-    if ((CC_Z==0) && (CC_C==0)) do_branch();
+
+void bhi()
+{
+    if ((CC_Z == 0) && (CC_C == 0))
+        do_branch();
 }
-void bvc() {
-    if (CC_V==0) do_branch();
+
+void bvc()
+{
+    if (CC_V == 0)
+        do_branch();
 }
-void bvs() {
-    if (CC_V==1) do_branch();
+
+void bvs()
+{
+    if (CC_V == 1)
+        do_branch();
 }
-void bcc() {
-    if (CC_C==0) do_branch();
+
+void bcc()
+{
+    if (CC_C == 0)
+        do_branch();
 }
-void bcs() {
-    if (CC_C==1) do_branch();
+
+void bcs()
+{
+    if (CC_C == 1)
+        do_branch();
 }
 
 /* br() - Branch Always. */
-void br() {
+void br()
+{
     do_branch();
 }
 
 
 /* blos() - Branch Lower or Same Instruction. */
-void blos() {
-    if ((CC_C!=0) || (CC_Z!=0)) do_branch();
+void blos()
+{
+    if ((CC_C != 0) || (CC_Z != 0))
+        do_branch();
 }
 
 /* bge() - Branch Greater Than or Equal Instruction. */
-void bge() {
-    if ((CC_N ^ CC_V) == 0) do_branch();
+void bge()
+{
+    if ((CC_N ^ CC_V) == 0)
+        do_branch();
 }
 
 /* blt() - Branch Less Than Instruction. */
-void blt() {
-    if ((CC_N ^ CC_V) == 1) do_branch();
+void blt()
+{
+    if ((CC_N ^ CC_V) == 1)
+        do_branch();
 }
 
 /* ble() - Branch Less Than Or Equal Instruction. */
-void ble() {
-    if (((CC_N ^ CC_V) == 1) || ((CC_Z)!=0)) do_branch();
+void ble()
+{
+    if (((CC_N ^ CC_V) == 1) || ((CC_Z) != 0))
+        do_branch();
 }
 
 /* bgt() - Branch Greater Than Instruction. */
-void bgt() {
-    if (((CC_N ^ CC_V) == 0) && ((CC_Z) == 0)) do_branch();
+void bgt()
+{
+    if (((CC_N ^ CC_V) == 0) && ((CC_Z) == 0))
+        do_branch();
 }
 
 /* jmp() - Jump Instruction. */
-void jmp() {
-    load_ea(); regs[PC]=dstword;
+void jmp()
+{
+    load_ea();
+    regs[PC] = dstword;
 }
 
 /* jsr() - Jump To Subroutine Instruction. */
-void jsr() {
+void jsr()
+{
     load_ea();
-    srcword=regs[SRC_REG]; push();
+    srcword = regs[SRC_REG];
+    push();
     regs[SRC_REG] = regs[PC];
     regs[PC] = dstword;
     JsrDebug((dbg_file, "jsr to 0%o\n", dstword));
 }
 
 /* rts() - Return From Subroutine Instruction. */
-void rts() {
+void rts()
+{
     regs[PC] = regs[DST_REG];
-    pop(); regs[DST_REG] = dstword;
+    pop();
+    regs[DST_REG] = dstword;
     JsrDebug((dbg_file, "rts to 0%o\n", regs[PC]));
 }
 
-void scc() {
-    if (ir & CC_NBIT) CC_N=1;
-    if (ir & CC_ZBIT) CC_Z=1;
-    if (ir & CC_VBIT) CC_V=1;
-    if (ir & CC_CBIT) CC_C=1;
+void scc()
+{
+    if (ir & CC_NBIT)
+        CC_N = 1;
+    if (ir & CC_ZBIT)
+        CC_Z = 1;
+    if (ir & CC_VBIT)
+        CC_V = 1;
+    if (ir & CC_CBIT)
+        CC_C = 1;
 }
-void ccc() {
-    if (ir & CC_NBIT) CC_N=0;
-    if (ir & CC_ZBIT) CC_Z=0;
-    if (ir & CC_VBIT) CC_V=0;
-    if (ir & CC_CBIT) CC_C=0;
+
+void ccc()
+{
+    if (ir & CC_NBIT)
+        CC_N = 0;
+    if (ir & CC_ZBIT)
+        CC_Z = 0;
+    if (ir & CC_VBIT)
+        CC_V = 0;
+    if (ir & CC_CBIT)
+        CC_C = 0;
 }
 
 /* sob() - Subtract One and Branch Instruction. */
-void sob() {
+void sob()
+{
     regs[SRC_REG] -= 1;
     if (regs[SRC_REG]) {
-       regs[PC] -= (ir & 077) * 2;
+        regs[PC] -= (ir & 077) * 2;
     }
 }
 
 /* mfps() - Move from Processor Status Instruction. */
-void mfps() {
-    srcbyte=(u_int8_t)0;
-    if (CC_N) srcbyte|= CC_NBIT;
-    if (CC_Z) srcbyte|= CC_ZBIT;
-    if (CC_V) srcbyte|= CC_VBIT;
-    if (CC_C) srcbyte|= CC_CBIT;
+void mfps()
+{
+    srcbyte = (u_int8_t) 0;
+    if (CC_N)
+        srcbyte |= CC_NBIT;
+    if (CC_Z)
+        srcbyte |= CC_ZBIT;
+    if (CC_V)
+        srcbyte |= CC_VBIT;
+    if (CC_C)
+        srcbyte |= CC_CBIT;
 
     CHGB_CC_N(srcbyte);
     CHGB_CC_Z(srcbyte);
     CLR_CC_V();
 
     if (DST_MODE) {
-       storeb_dst();
+        storeb_dst();
     } else {
-       if (srcbyte & SIGN_B) {
-           dstword = 0177400;
-       } else {
-           dstword = 0;
-       }
-       dstword += (u_int16_t)srcbyte;
-       store_dst();
+        if (srcbyte & SIGN_B) {
+            dstword = 0177400;
+        } else {
+            dstword = 0;
+        }
+        dstword += (u_int16_t) srcbyte;
+        store_dst();
     }
 }
 
 /* mtps() - Move to Processor Status Instruction. */
-void mtps() {
+void mtps()
+{
     loadb_dst();
-    if (dstbyte & CC_NBIT) CC_N=1;
-    if (dstbyte & CC_ZBIT) CC_Z=1;
-    if (dstbyte & CC_VBIT) CC_V=1;
-    if (dstbyte & CC_CBIT) CC_C=1;
+    if (dstbyte & CC_NBIT)
+        CC_N = 1;
+    if (dstbyte & CC_ZBIT)
+        CC_Z = 1;
+    if (dstbyte & CC_VBIT)
+        CC_V = 1;
+    if (dstbyte & CC_CBIT)
+        CC_C = 1;
 }
 
 /* mfpi() - Move From Previous Instruction Space Instruction. */
-void mfpi() {
-    loadp_dst(); push();
+void mfpi()
+{
+    loadp_dst();
+    push();
 }
 
 
 /* mtpi() - To From Previous Instruction Space Instruction. */
-void mtpi() {
-     pop(); storep_dst();
+void mtpi()
+{
+    pop();
+    storep_dst();
 }
 
 /* ash() - Arithmetic Shift Instruction. */
-void ash() {
+void ash()
+{
     u_int16_t temp;
     u_int16_t old;
     u_int16_t sign;
@@ -173,43 +243,43 @@ void ash() {
     load_dst();
     old = temp;
 
-    if ((dstword & 077) == 0) {                /* no shift */
-       CHG_CC_N(temp);
-       CHG_CC_Z(temp);
-       CLR_CC_V();
-       return;
+    if ((dstword & 077) == 0) {        /* no shift */
+        CHG_CC_N(temp);
+        CHG_CC_Z(temp);
+        CLR_CC_V();
+        return;
     }
-    if (dstword & 040) {               /* right shift */
-       count = 0100 - (dstword & 077);
-       sign = temp & SIGN;
-       while (count--) {
-           if (temp & LSBIT) {
-               SET_CC_C();
-           } else {
-               CLR_CC_C();
-           }
-           temp >>= 1;
-           temp += sign;
-       }
-    } else {                           /* left shift */
-       count = dstword & 037;
-       while (count--) {
-           if (temp & SIGN) {
-               SET_CC_C();
-           } else {
-               CLR_CC_C();
-           }
-           temp <<= 1;
-       }
+    if (dstword & 040) {       /* right shift */
+        count = 0100 - (dstword & 077);
+        sign = temp & SIGN;
+        while (count--) {
+            if (temp & LSBIT) {
+                SET_CC_C();
+            } else {
+                CLR_CC_C();
+            }
+            temp >>= 1;
+            temp += sign;
+        }
+    } else {                   /* left shift */
+        count = dstword & 037;
+        while (count--) {
+            if (temp & SIGN) {
+                SET_CC_C();
+            } else {
+                CLR_CC_C();
+            }
+            temp <<= 1;
+        }
     }
 
     CHG_CC_N(temp);
     CHG_CC_Z(temp);
 
     if ((old & SIGN) == (temp & SIGN)) {
-       CLR_CC_V();
+        CLR_CC_V();
     } else {
-       SET_CC_V();
+        SET_CC_V();
     }
     regs[SRC_REG] = temp;
 }
@@ -228,34 +298,36 @@ union s_u_long {
     long s_long;
 };
 
-void mul() {
+void mul()
+{
     union s_u_word data1;
     union s_u_word data2;
     union s_u_long tmp;
 
     data1.u_word = regs[SRC_REG];
     load_dst();
-    data2.u_word=dstword;
+    data2.u_word = dstword;
 
     tmp.s_long = ((long) data1.s_word) * ((long) data2.s_word);
 
-    regs[SRC_REG] = (u_int16_t)(tmp.u_long >> 16);
-    regs[(SRC_REG) | 1] = (u_int16_t)(tmp.u_long & 0177777);
+    regs[SRC_REG] = (u_int16_t) (tmp.u_long >> 16);
+    regs[(SRC_REG) | 1] = (u_int16_t) (tmp.u_long & 0177777);
 
     CLR_CC_ALL();
 
     if (tmp.u_long == 0)
-       SET_CC_Z();
+        SET_CC_Z();
     else
-       CLR_CC_Z();
+        CLR_CC_Z();
 
     if (tmp.u_long & 0x80000000)
-       SET_CC_N();
+        SET_CC_N();
     else
-       CLR_CC_N();
+        CLR_CC_N();
 }
 
-void divide() {
+void divide()
+{
     union s_u_long tmp;
     union s_u_long eql;
     union s_u_word data2;
@@ -265,40 +337,41 @@ void divide() {
     tmp.u_long += regs[(SRC_REG) | 1];
 
     load_dst();
-    data2.u_word=dstword;
+    data2.u_word = dstword;
 
     if (data2.u_word == 0) {
-       SET_CC_C();
-       SET_CC_V();
-       return;
+        SET_CC_C();
+        SET_CC_V();
+        return;
     } else {
-       CLR_CC_C();
+        CLR_CC_C();
     }
 
     eql.s_long = tmp.s_long / data2.s_word;
-    regs[SRC_REG] = (u_int16_t)eql.u_long & 0177777;
+    regs[SRC_REG] = (u_int16_t) eql.u_long & 0177777;
 
     if (eql.u_long == 0)
-       SET_CC_Z();
+        SET_CC_Z();
     else
-       CLR_CC_Z();
+        CLR_CC_Z();
 
     if ((eql.s_long > 077777) || (eql.s_long < -0100000))
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     if (eql.s_long < 0)
-       SET_CC_N();
+        SET_CC_N();
     else
-       CLR_CC_N();
+        CLR_CC_N();
 
     eql.s_long = tmp.s_long % data2.s_word;
-    regs[(SRC_REG) | 1] = (u_int16_t)eql.u_long & 0177777;
+    regs[(SRC_REG) | 1] = (u_int16_t) eql.u_long & 0177777;
 }
 
 /* ashc() - Arithmetic Shift Combined Instruction. */
-void ashc() {
+void ashc()
+{
     u_int32_t temp;
     u_int32_t old;
     u_int32_t sign;
@@ -310,69 +383,70 @@ void ashc() {
     old = temp;
     load_dst();
 
-    if ((dstword & 077) == 0) { /* no shift */
+    if ((dstword & 077) == 0) {        /* no shift */
 
-       CLR_CC_V();
+        CLR_CC_V();
 
-       if (temp & 0x80000000) {
-           SET_CC_N();
-       } else {
-           CLR_CC_N();
-       }
+        if (temp & 0x80000000) {
+            SET_CC_N();
+        } else {
+            CLR_CC_N();
+        }
 
-       if (temp) {
-           CLR_CC_Z();
-       } else {
-           SET_CC_Z();
-       }
-       return;
+        if (temp) {
+            CLR_CC_Z();
+        } else {
+            SET_CC_Z();
+        }
+        return;
     }
-    if (dstword & 040) {               /* right shift */
-       count = 0100 - (dstword & 077);
-       sign = temp & 0x80000000;
-       while (count--) {
-           if (temp & LSBIT) {
-               SET_CC_C();
-           } else {
-               CLR_CC_C();
-           }
-           temp >>= 1;
-           temp += sign;
-       }
+    if (dstword & 040) {       /* right shift */
+        count = 0100 - (dstword & 077);
+        sign = temp & 0x80000000;
+        while (count--) {
+            if (temp & LSBIT) {
+                SET_CC_C();
+            } else {
+                CLR_CC_C();
+            }
+            temp >>= 1;
+            temp += sign;
+        }
     } else {                   /* left shift */
-       count = dstword & 037;
-       while (count--) {
-           if (temp & 0x80000000) {
-               SET_CC_C();
-           } else {
-               CLR_CC_C();
-           }
-           temp <<= 1;
-       }
+        count = dstword & 037;
+        while (count--) {
+            if (temp & 0x80000000) {
+                SET_CC_C();
+            } else {
+                CLR_CC_C();
+            }
+            temp <<= 1;
+        }
     }
 
     if (temp & 0x80000000)
-       SET_CC_N();
+        SET_CC_N();
     else
-       CLR_CC_N();
+        CLR_CC_N();
 
     if (temp)
-       CLR_CC_Z();
+        CLR_CC_Z();
     else
-       SET_CC_Z();
+        SET_CC_Z();
 
     if ((old & 0x80000000) == (temp & 0x80000000)) {
-       CLR_CC_V();
+        CLR_CC_V();
     } else {
-       SET_CC_V();
+        SET_CC_V();
     }
 
-    regs[SRC_REG] = (u_int16_t)(temp >> 16);
+    regs[SRC_REG] = (u_int16_t) (temp >> 16);
     regs[(SRC_REG) | 1] = LOW16(temp);
 }
 
 /* xor() - Exclusive Or Instruction */
-void xor() {
+void xor()
+{
     tmpword = regs[SRC_REG];
 
     load_dst();
@@ -383,5 +457,6 @@ void xor() {
     CHG_CC_Z(tmpword);
     CLR_CC_V();
 
-    dstword=tmpword; store_dst_2();
+    dstword = tmpword;
+    store_dst_2();
 }
index 3fd1e0f..ab2aa76 100644 (file)
 
 /* sgtty structure */
 struct tr_sgttyb {
-  int8_t sg_ispeed;            /* input speed */
-  int8_t sg_ospeed;            /* output speed */
-  int8_t sg_erase;             /* erase character */
-  int8_t sg_kill;              /* kill character */
-  int16_t sg_flags;            /* mode flags */
+    int8_t sg_ispeed;          /* input speed */
+    int8_t sg_ospeed;          /* output speed */
+    int8_t sg_erase;           /* erase character */
+    int8_t sg_kill;            /* kill character */
+    int16_t sg_flags;          /* mode flags */
 };
 
 struct tr_tchars {
-        int8_t    t_intrc;        /* interrupt */
-        int8_t    t_quitc;        /* quit */
-        int8_t    t_startc;       /* start output */
-        int8_t    t_stopc;        /* stop output */
-        int8_t    t_eofc;         /* end-of-file */
-        int8_t    t_brkc;         /* input delimiter (like nl) */
+    int8_t t_intrc;            /* interrupt */
+    int8_t t_quitc;            /* quit */
+    int8_t t_startc;           /* start output */
+    int8_t t_stopc;            /* stop output */
+    int8_t t_eofc;             /* end-of-file */
+    int8_t t_brkc;             /* input delimiter (like nl) */
 };
 
 struct tr_ltchars {
-        int8_t    t_suspc;        /* stop process signal */
-        int8_t    t_dsuspc;       /* delayed stop process signal */
-        int8_t    t_rprntc;       /* reprint line */
-        int8_t    t_flushc;       /* flush output (toggles) */
-        int8_t    t_werasc;       /* word erase */
-        int8_t    t_lnextc;       /* literal next character */
+    int8_t t_suspc;            /* stop process signal */
+    int8_t t_dsuspc;           /* delayed stop process signal */
+    int8_t t_rprntc;           /* reprint line */
+    int8_t t_flushc;           /* flush output (toggles) */
+    int8_t t_werasc;           /* word erase */
+    int8_t t_lnextc;           /* literal next character */
 };
 
 /*
@@ -64,15 +64,15 @@ struct tr_ltchars {
  */
 #define      TR_TANDEM          0x00000001     /* send stopc on out q full */
 #define      TR_CBREAK          0x00000002     /* half-cooked mode */
-                                               /* 0x4 (old LCASE) */
+/* 0x4 (old LCASE) */
 #define      TR_ECHO            0x00000008     /* echo input */
 #define      TR_CRMOD           0x00000010     /* map \r to \r\n on output */
 #define      TR_RAW             0x00000020     /* no i/o processing */
 #define      TR_ODDP            0x00000040     /* get/send odd parity */
 #define      TR_EVENP           0x00000080     /* get/send even parity */
 #define      TR_ANYP            0x000000c0     /* get any parity/send none */
-                                               /* 0x100 (old NLDELAY) */
-                                               /* 0x200 */
+/* 0x100 (old NLDELAY) */
+/* 0x200 */
 #define      TR_XTABS           0x00000400     /* expand tabs on output */
 
 /* Values for sg_ispeed and sg_ospeed */
@@ -113,367 +113,563 @@ static int trap_settermios(u_int16_t fd, u_int32_t type, u_int16_t ucnt);
 
 int trap_ioctl()
 {
-  int i, val;
-  long larg1;
+    int i, val;
+    long larg1;
 #ifdef DEBUG
-  u_int8_t size, letter, value;
+    u_int8_t size, letter, value;
 #endif
-  int16_t *shortptr;
-  struct winsize *winptr;
+    int16_t *shortptr;
+    struct winsize *winptr;
 
-  larg1 = (sarg2 << 16) | uarg3;
+    larg1 = (sarg2 << 16) | uarg3;
 
 #ifdef DEBUG
-  if (trap_debug) {
-    fprintf(dbg_file, "val %d ",uarg1);
-    switch (larg1) {
-      case TR_FIOCLEX:   fprintf(dbg_file, "FIOCLEX "); break;
-      case TR_TIOCGETP:          fprintf(dbg_file, "TIOCGETP "); break;
-      case TR_TIOCSETP:          fprintf(dbg_file, "TIOCSETP "); break;
-      case TR_TIOCSETN:          fprintf(dbg_file, "TIOCSETN "); break;
-      case TR_TIOCSETC:          fprintf(dbg_file, "TIOCSETC "); break;
-      case TR_TIOCGETD:          fprintf(dbg_file, "TIOCGETD "); break;
-      case TR_TIOCSETD:          fprintf(dbg_file, "TIOCSETD "); break;
-      case TR_TIOCGETC:          fprintf(dbg_file, "TIOCGETC "); break;
-      case TR_TIOCGLTC:          fprintf(dbg_file, "TIOCGLTC "); break;
-      case TR_TIOCSLTC:          fprintf(dbg_file, "TIOCSLTC "); break;
-      case TR_TIOCGWINSZ: fprintf(dbg_file, "TIOCGWINSZ "); break;
-      case TR_TIOCSWINSZ: fprintf(dbg_file, "TIOCSWINSZ "); break;
-      case TR_FIOSETOWN:  fprintf(dbg_file, "FIOSETOWN "); break;
-      case TR_TIOCMGET:   fprintf(dbg_file, "TIOCMGET "); break;
-      case TR_TIOCGPGRP:  fprintf(dbg_file, "TIOCGPGRP "); break;
-      case TR_TIOCSPGRP:  fprintf(dbg_file, "TIOCSPGRP "); break;
-      default: fprintf(dbg_file, "0x%lx ", larg1);
-
-       value =  larg1 & 0xff;
-       letter = (larg1 >> 8) & 0xff;
-       size =   (larg1 >> 16) & 0xff;
-
-       fprintf(dbg_file, "('%c' ", letter);
-       fprintf(dbg_file, "size %d ", size);
-       fprintf(dbg_file, "val %d) ", value);
+    if (trap_debug) {
+        fprintf(dbg_file, "val %d ", uarg1);
+        switch (larg1) {
+        case TR_FIOCLEX:
+            fprintf(dbg_file, "FIOCLEX ");
+            break;
+        case TR_TIOCGETP:
+            fprintf(dbg_file, "TIOCGETP ");
+            break;
+        case TR_TIOCSETP:
+            fprintf(dbg_file, "TIOCSETP ");
+            break;
+        case TR_TIOCSETN:
+            fprintf(dbg_file, "TIOCSETN ");
+            break;
+        case TR_TIOCSETC:
+            fprintf(dbg_file, "TIOCSETC ");
+            break;
+        case TR_TIOCGETD:
+            fprintf(dbg_file, "TIOCGETD ");
+            break;
+        case TR_TIOCSETD:
+            fprintf(dbg_file, "TIOCSETD ");
+            break;
+        case TR_TIOCGETC:
+            fprintf(dbg_file, "TIOCGETC ");
+            break;
+        case TR_TIOCGLTC:
+            fprintf(dbg_file, "TIOCGLTC ");
+            break;
+        case TR_TIOCSLTC:
+            fprintf(dbg_file, "TIOCSLTC ");
+            break;
+        case TR_TIOCGWINSZ:
+            fprintf(dbg_file, "TIOCGWINSZ ");
+            break;
+        case TR_TIOCSWINSZ:
+            fprintf(dbg_file, "TIOCSWINSZ ");
+            break;
+        case TR_FIOSETOWN:
+            fprintf(dbg_file, "FIOSETOWN ");
+            break;
+        case TR_TIOCMGET:
+            fprintf(dbg_file, "TIOCMGET ");
+            break;
+        case TR_TIOCGPGRP:
+            fprintf(dbg_file, "TIOCGPGRP ");
+            break;
+        case TR_TIOCSPGRP:
+            fprintf(dbg_file, "TIOCSPGRP ");
+            break;
+        default:
+            fprintf(dbg_file, "0x%lx ", larg1);
+
+            value = larg1 & 0xff;
+            letter = (larg1 >> 8) & 0xff;
+            size = (larg1 >> 16) & 0xff;
+
+            fprintf(dbg_file, "('%c' ", letter);
+            fprintf(dbg_file, "size %d ", size);
+            fprintf(dbg_file, "val %d) ", value);
+        }
+        if (size)
+            fprintf(dbg_file, "ptr %d ", uarg4);
     }
-    if (size) fprintf(dbg_file, "ptr %d ", uarg4);
-  }
 #endif
 
-  switch (larg1) {
+    switch (larg1) {
 
     case TR_TIOCGETP:
     case TR_TIOCGETC:
     case TR_TIOCGLTC:
-      i = trap_gettermios(uarg1, larg1, uarg4); break;
+        i = trap_gettermios(uarg1, larg1, uarg4);
+        break;
 
     case TR_TIOCSETP:
     case TR_TIOCSETN:
     case TR_TIOCSETC:
     case TR_TIOCSLTC:
-      i = trap_settermios(uarg1, larg1, uarg4); break;
+        i = trap_settermios(uarg1, larg1, uarg4);
+        break;
 
     case TR_FIOCLEX:
-      i = ioctl(uarg1, FIOCLEX, NULL); break;
+        i = ioctl(uarg1, FIOCLEX, NULL);
+        break;
     case TR_TIOCGETD:
-      shortptr = (int16_t *) &dspace[uarg4];
-      i = ioctl(uarg1, TIOCGETD, &val);
-      if (i==0) *shortptr= val;
-      break;
+        shortptr = (int16_t *) & dspace[uarg4];
+        i = ioctl(uarg1, TIOCGETD, &val);
+        if (i == 0)
+            *shortptr = val;
+        break;
     case TR_TIOCGPGRP:
-      shortptr = (int16_t *) &dspace[uarg4];
-      i = ioctl(uarg1, TIOCGPGRP, &val);
-      if (i==0) *shortptr= val;
-      break;
+        shortptr = (int16_t *) & dspace[uarg4];
+        i = ioctl(uarg1, TIOCGPGRP, &val);
+        if (i == 0)
+            *shortptr = val;
+        break;
     case TR_TIOCSPGRP:
-      shortptr = (int16_t *) &dspace[uarg4];
-      val= *shortptr; i = ioctl(uarg1, TIOCSPGRP, &val); break;
+        shortptr = (int16_t *) & dspace[uarg4];
+        val = *shortptr;
+        i = ioctl(uarg1, TIOCSPGRP, &val);
+        break;
     case TR_TIOCSETD:
-      shortptr = (int16_t *) &dspace[uarg4];
-      val= *shortptr; i = ioctl(uarg1, TIOCSETD, &val); break;
+        shortptr = (int16_t *) & dspace[uarg4];
+        val = *shortptr;
+        i = ioctl(uarg1, TIOCSETD, &val);
+        break;
     case TR_FIOSETOWN:
-      shortptr = (int16_t *) &dspace[uarg4];
-      val= *shortptr;
-                               /* Something wrong here, wonder why! */
-      TrapDebug((dbg_file, "fd %d val %d ",uarg1,val));
-      i = ioctl(uarg1, FIOSETOWN, &val); break;
+        shortptr = (int16_t *) & dspace[uarg4];
+        val = *shortptr;
+        /* Something wrong here, wonder why! */
+        TrapDebug((dbg_file, "fd %d val %d ", uarg1, val));
+        i = ioctl(uarg1, FIOSETOWN, &val);
+        break;
     case TR_TIOCMGET:
-      shortptr = (int16_t *) &dspace[uarg4];
-      i = ioctl(uarg1, TIOCMGET, &val);
-      if (i==0) *shortptr= val;
-      break;
+        shortptr = (int16_t *) & dspace[uarg4];
+        i = ioctl(uarg1, TIOCMGET, &val);
+        if (i == 0)
+            *shortptr = val;
+        break;
 
     case TR_TIOCGWINSZ:
-                               /* 2.11BSD and POSIX winsize the same! */
-      winptr = (struct winsize *) &dspace[uarg4];
-      i= ioctl(uarg1, TIOCGWINSZ, winptr); break;
+        /* 2.11BSD and POSIX winsize the same! */
+        winptr = (struct winsize *) &dspace[uarg4];
+        i = ioctl(uarg1, TIOCGWINSZ, winptr);
+        break;
     case TR_TIOCSWINSZ:
-      winptr = (struct winsize *) &dspace[uarg4];
-      i= ioctl(uarg1, TIOCSWINSZ, winptr); break;
+        winptr = (struct winsize *) &dspace[uarg4];
+        i = ioctl(uarg1, TIOCSWINSZ, winptr);
+        break;
 
     default:
-      i = 0;
-  }
-  return (i);
+        i = 0;
+    }
+    return (i);
 }
 
 
 /* Convert from termios to old sgttyb structure */
-static void to_sgttyb(struct tr_sgttyb * sgtb, struct termios * tios)
+static void to_sgttyb(struct tr_sgttyb *sgtb, struct termios *tios)
 {
-  switch (tios->c_ispeed) {
-     case B0: sgtb->sg_ispeed= TR_B0; break;
-     case B50: sgtb->sg_ispeed= TR_B50; break;
-     case B75: sgtb->sg_ispeed= TR_B75; break;
-     case B110: sgtb->sg_ispeed= TR_B110; break;
-     case B134: sgtb->sg_ispeed= TR_B134; break;
-     case B150: sgtb->sg_ispeed= TR_B150; break;
-     case B200: sgtb->sg_ispeed= TR_B200; break;
-     case B300: sgtb->sg_ispeed= TR_B300; break;
-     case B600: sgtb->sg_ispeed= TR_B600; break;
-     case B1200: sgtb->sg_ispeed= TR_B1200; break;
-     case B1800: sgtb->sg_ispeed= TR_B1800; break;
-     case B2400: sgtb->sg_ispeed= TR_B2400; break;
-     case B4800: sgtb->sg_ispeed= TR_B4800; break;
-     case B9600: sgtb->sg_ispeed= TR_B9600; break;
-     case B19200: sgtb->sg_ispeed= TR_EXTA; break;
-     case B38400: sgtb->sg_ispeed= TR_EXTB; break;
-     default: sgtb->sg_ispeed= TR_B0; break;
-  }
-  switch (tios->c_ospeed) {
-     case B0: sgtb->sg_ospeed= TR_B0; break;
-     case B50: sgtb->sg_ospeed= TR_B50; break;
-     case B75: sgtb->sg_ospeed= TR_B75; break;
-     case B110: sgtb->sg_ospeed= TR_B110; break;
-     case B134: sgtb->sg_ospeed= TR_B134; break;
-     case B150: sgtb->sg_ospeed= TR_B150; break;
-     case B200: sgtb->sg_ospeed= TR_B200; break;
-     case B300: sgtb->sg_ospeed= TR_B300; break;
-     case B600: sgtb->sg_ospeed= TR_B600; break;
-     case B1200: sgtb->sg_ospeed= TR_B1200; break;
-     case B1800: sgtb->sg_ospeed= TR_B1800; break;
-     case B2400: sgtb->sg_ospeed= TR_B2400; break;
-     case B4800: sgtb->sg_ospeed= TR_B4800; break;
-     case B9600: sgtb->sg_ospeed= TR_B9600; break;
-     case B19200: sgtb->sg_ospeed= TR_EXTA; break;
-     case B38400: sgtb->sg_ospeed= TR_EXTB; break;
-     default: sgtb->sg_ospeed= TR_B0; break;
-  }
-  sgtb->sg_erase = tios->c_cc[VERASE];
-  sgtb->sg_kill = tios->c_cc[VKILL];
-  sgtb->sg_flags = 0;
-  if (tios->c_oflag & OXTABS)
-    sgtb->sg_flags |= TR_XTABS;
-  if (tios->c_cflag & PARENB) {
-    if (tios->c_cflag & PARODD)
-      sgtb->sg_flags |= TR_ODDP;
-    else
-      sgtb->sg_flags |= TR_EVENP;
-  } else
-    sgtb->sg_flags |= TR_ANYP;
-  if (tios->c_oflag & ONLCR)
-    sgtb->sg_flags |= TR_CRMOD;
-  if (tios->c_lflag & ECHO)
-    sgtb->sg_flags |= TR_ECHO;
-  if (!(tios->c_lflag & ICANON)) {
-    if (!(tios->c_lflag & ECHO))
-      sgtb->sg_flags |= TR_CBREAK;
-    else
-      sgtb->sg_flags |= TR_RAW;
-  }
+    switch (tios->c_ispeed) {
+    case B0:
+        sgtb->sg_ispeed = TR_B0;
+        break;
+    case B50:
+        sgtb->sg_ispeed = TR_B50;
+        break;
+    case B75:
+        sgtb->sg_ispeed = TR_B75;
+        break;
+    case B110:
+        sgtb->sg_ispeed = TR_B110;
+        break;
+    case B134:
+        sgtb->sg_ispeed = TR_B134;
+        break;
+    case B150:
+        sgtb->sg_ispeed = TR_B150;
+        break;
+    case B200:
+        sgtb->sg_ispeed = TR_B200;
+        break;
+    case B300:
+        sgtb->sg_ispeed = TR_B300;
+        break;
+    case B600:
+        sgtb->sg_ispeed = TR_B600;
+        break;
+    case B1200:
+        sgtb->sg_ispeed = TR_B1200;
+        break;
+    case B1800:
+        sgtb->sg_ispeed = TR_B1800;
+        break;
+    case B2400:
+        sgtb->sg_ispeed = TR_B2400;
+        break;
+    case B4800:
+        sgtb->sg_ispeed = TR_B4800;
+        break;
+    case B9600:
+        sgtb->sg_ispeed = TR_B9600;
+        break;
+    case B19200:
+        sgtb->sg_ispeed = TR_EXTA;
+        break;
+    case B38400:
+        sgtb->sg_ispeed = TR_EXTB;
+        break;
+    default:
+        sgtb->sg_ispeed = TR_B0;
+        break;
+    }
+    switch (tios->c_ospeed) {
+    case B0:
+        sgtb->sg_ospeed = TR_B0;
+        break;
+    case B50:
+        sgtb->sg_ospeed = TR_B50;
+        break;
+    case B75:
+        sgtb->sg_ospeed = TR_B75;
+        break;
+    case B110:
+        sgtb->sg_ospeed = TR_B110;
+        break;
+    case B134:
+        sgtb->sg_ospeed = TR_B134;
+        break;
+    case B150:
+        sgtb->sg_ospeed = TR_B150;
+        break;
+    case B200:
+        sgtb->sg_ospeed = TR_B200;
+        break;
+    case B300:
+        sgtb->sg_ospeed = TR_B300;
+        break;
+    case B600:
+        sgtb->sg_ospeed = TR_B600;
+        break;
+    case B1200:
+        sgtb->sg_ospeed = TR_B1200;
+        break;
+    case B1800:
+        sgtb->sg_ospeed = TR_B1800;
+        break;
+    case B2400:
+        sgtb->sg_ospeed = TR_B2400;
+        break;
+    case B4800:
+        sgtb->sg_ospeed = TR_B4800;
+        break;
+    case B9600:
+        sgtb->sg_ospeed = TR_B9600;
+        break;
+    case B19200:
+        sgtb->sg_ospeed = TR_EXTA;
+        break;
+    case B38400:
+        sgtb->sg_ospeed = TR_EXTB;
+        break;
+    default:
+        sgtb->sg_ospeed = TR_B0;
+        break;
+    }
+    sgtb->sg_erase = tios->c_cc[VERASE];
+    sgtb->sg_kill = tios->c_cc[VKILL];
+    sgtb->sg_flags = 0;
+    if (tios->c_oflag & OXTABS)
+        sgtb->sg_flags |= TR_XTABS;
+    if (tios->c_cflag & PARENB) {
+        if (tios->c_cflag & PARODD)
+            sgtb->sg_flags |= TR_ODDP;
+        else
+            sgtb->sg_flags |= TR_EVENP;
+    } else
+        sgtb->sg_flags |= TR_ANYP;
+    if (tios->c_oflag & ONLCR)
+        sgtb->sg_flags |= TR_CRMOD;
+    if (tios->c_lflag & ECHO)
+        sgtb->sg_flags |= TR_ECHO;
+    if (!(tios->c_lflag & ICANON)) {
+        if (!(tios->c_lflag & ECHO))
+            sgtb->sg_flags |= TR_CBREAK;
+        else
+            sgtb->sg_flags |= TR_RAW;
+    }
 }
 
 /* Convert from old sgttyb to termios structure */
-static void to_termios(struct tr_sgttyb * sgtb, struct termios * tios)
+static void to_termios(struct tr_sgttyb *sgtb, struct termios *tios)
 {
-  TrapDebug((dbg_file, "\n\tto_termios: sgtty flags are 0x%x ",
-                                                       sgtb->sg_flags));
-
-  switch (sgtb->sg_ispeed) {
-     case TR_B0: tios->c_ispeed= B0; break;
-     case TR_B50: tios->c_ispeed= B50; break;
-     case TR_B75: tios->c_ispeed= B75; break;
-     case TR_B110: tios->c_ispeed= B110; break;
-     case TR_B134: tios->c_ispeed= B134; break;
-     case TR_B150: tios->c_ispeed= B150; break;
-     case TR_B200: tios->c_ispeed= B200; break;
-     case TR_B300: tios->c_ispeed= B300; break;
-     case TR_B600: tios->c_ispeed= B600; break;
-     case TR_B1200: tios->c_ispeed= B1200; break;
-     case TR_B1800: tios->c_ispeed= B1800; break;
-     case TR_B2400: tios->c_ispeed= B2400; break;
-     case TR_B4800: tios->c_ispeed= B4800; break;
-     case TR_B9600: tios->c_ispeed= B9600; break;
-     case TR_EXTA: tios->c_ispeed= B19200; break;
-     case TR_EXTB: tios->c_ispeed= B38400; break;
-     default: tios->c_ispeed= B0; break;
-  }
-  switch (sgtb->sg_ospeed) {
-     case TR_B0: tios->c_ospeed= B0; break;
-     case TR_B50: tios->c_ospeed= B50; break;
-     case TR_B75: tios->c_ospeed= B75; break;
-     case TR_B110: tios->c_ospeed= B110; break;
-     case TR_B134: tios->c_ospeed= B134; break;
-     case TR_B150: tios->c_ospeed= B150; break;
-     case TR_B200: tios->c_ospeed= B200; break;
-     case TR_B300: tios->c_ospeed= B300; break;
-     case TR_B600: tios->c_ospeed= B600; break;
-     case TR_B1200: tios->c_ospeed= B1200; break;
-     case TR_B1800: tios->c_ospeed= B1800; break;
-     case TR_B2400: tios->c_ospeed= B2400; break;
-     case TR_B4800: tios->c_ospeed= B4800; break;
-     case TR_B9600: tios->c_ospeed= B9600; break;
-     case TR_EXTA: tios->c_ospeed= B19200; break;
-     case TR_EXTB: tios->c_ospeed= B38400; break;
-     default: tios->c_ospeed= B0; break;
-  }
-  tios->c_cc[VERASE] = sgtb->sg_erase;
-  tios->c_cc[VKILL] = sgtb->sg_kill;
-
-                               /* Initially turn off any flags we might set */
-  tios->c_oflag &= ~(OXTABS|ONLCR);
-  tios->c_cflag &= ~(PARENB|PARODD);
-  tios->c_lflag &= ~(ECHO);
-
-  if (sgtb->sg_flags & TR_XTABS)
-    tios->c_oflag |= OXTABS;
-  if (sgtb->sg_flags & TR_ODDP) {
-    tios->c_cflag |= PARENB;
-    tios->c_cflag &= ~PARODD;
-  }
-  if (sgtb->sg_flags & TR_EVENP)
-    tios->c_cflag |= PARENB | PARODD;
-  if (sgtb->sg_flags & TR_ANYP)
-    tios->c_cflag &= ~PARENB;
-  if (sgtb->sg_flags & TR_CRMOD)
-    tios->c_oflag |= ONLCR;
-  if (sgtb->sg_flags & TR_ECHO)
-    tios->c_lflag |= ECHO;
-
-  if (sgtb->sg_flags & TR_RAW) {
-    tios->c_lflag &= ~(ECHO|ICANON|IEXTEN|ISIG|BRKINT|ICRNL|INPCK|ISTRIP|IXON);
-    tios->c_cflag &= ~(CSIZE|PARENB);
-    tios->c_cflag |= CS8;
-    tios->c_oflag &= ~(OPOST);
-    tios->c_cc[VMIN] = 1;
-    tios->c_cc[VTIME] = 0;
-  }
-
-  if (sgtb->sg_flags & TR_CBREAK) {
-  TrapDebug((dbg_file, "\n\tto_termios: setting cbreak I hope "));
-    tios->c_lflag &= ~(ECHO|ICANON);
-    tios->c_cc[VMIN] = 1;
-    tios->c_cc[VTIME] = 0;
-  }
-  TrapDebug((dbg_file, "\n\tto_termios: iflag is 0x%x", (int)tios->c_iflag));
-  TrapDebug((dbg_file, "\n\tto_termios: oflag is 0x%x", (int)tios->c_oflag));
-  TrapDebug((dbg_file, "\n\tto_termios: lflag is 0x%x ", (int)tios->c_lflag));
+    TrapDebug((dbg_file, "\n\tto_termios: sgtty flags are 0x%x ",
+               sgtb->sg_flags));
+
+    switch (sgtb->sg_ispeed) {
+    case TR_B0:
+        tios->c_ispeed = B0;
+        break;
+    case TR_B50:
+        tios->c_ispeed = B50;
+        break;
+    case TR_B75:
+        tios->c_ispeed = B75;
+        break;
+    case TR_B110:
+        tios->c_ispeed = B110;
+        break;
+    case TR_B134:
+        tios->c_ispeed = B134;
+        break;
+    case TR_B150:
+        tios->c_ispeed = B150;
+        break;
+    case TR_B200:
+        tios->c_ispeed = B200;
+        break;
+    case TR_B300:
+        tios->c_ispeed = B300;
+        break;
+    case TR_B600:
+        tios->c_ispeed = B600;
+        break;
+    case TR_B1200:
+        tios->c_ispeed = B1200;
+        break;
+    case TR_B1800:
+        tios->c_ispeed = B1800;
+        break;
+    case TR_B2400:
+        tios->c_ispeed = B2400;
+        break;
+    case TR_B4800:
+        tios->c_ispeed = B4800;
+        break;
+    case TR_B9600:
+        tios->c_ispeed = B9600;
+        break;
+    case TR_EXTA:
+        tios->c_ispeed = B19200;
+        break;
+    case TR_EXTB:
+        tios->c_ispeed = B38400;
+        break;
+    default:
+        tios->c_ispeed = B0;
+        break;
+    }
+    switch (sgtb->sg_ospeed) {
+    case TR_B0:
+        tios->c_ospeed = B0;
+        break;
+    case TR_B50:
+        tios->c_ospeed = B50;
+        break;
+    case TR_B75:
+        tios->c_ospeed = B75;
+        break;
+    case TR_B110:
+        tios->c_ospeed = B110;
+        break;
+    case TR_B134:
+        tios->c_ospeed = B134;
+        break;
+    case TR_B150:
+        tios->c_ospeed = B150;
+        break;
+    case TR_B200:
+        tios->c_ospeed = B200;
+        break;
+    case TR_B300:
+        tios->c_ospeed = B300;
+        break;
+    case TR_B600:
+        tios->c_ospeed = B600;
+        break;
+    case TR_B1200:
+        tios->c_ospeed = B1200;
+        break;
+    case TR_B1800:
+        tios->c_ospeed = B1800;
+        break;
+    case TR_B2400:
+        tios->c_ospeed = B2400;
+        break;
+    case TR_B4800:
+        tios->c_ospeed = B4800;
+        break;
+    case TR_B9600:
+        tios->c_ospeed = B9600;
+        break;
+    case TR_EXTA:
+        tios->c_ospeed = B19200;
+        break;
+    case TR_EXTB:
+        tios->c_ospeed = B38400;
+        break;
+    default:
+        tios->c_ospeed = B0;
+        break;
+    }
+    tios->c_cc[VERASE] = sgtb->sg_erase;
+    tios->c_cc[VKILL] = sgtb->sg_kill;
+
+    /* Initially turn off any flags we might set */
+    tios->c_oflag &= ~(OXTABS | ONLCR);
+    tios->c_cflag &= ~(PARENB | PARODD);
+    tios->c_lflag &= ~(ECHO);
+
+    if (sgtb->sg_flags & TR_XTABS)
+        tios->c_oflag |= OXTABS;
+    if (sgtb->sg_flags & TR_ODDP) {
+        tios->c_cflag |= PARENB;
+        tios->c_cflag &= ~PARODD;
+    }
+    if (sgtb->sg_flags & TR_EVENP)
+        tios->c_cflag |= PARENB | PARODD;
+    if (sgtb->sg_flags & TR_ANYP)
+        tios->c_cflag &= ~PARENB;
+    if (sgtb->sg_flags & TR_CRMOD)
+        tios->c_oflag |= ONLCR;
+    if (sgtb->sg_flags & TR_ECHO)
+        tios->c_lflag |= ECHO;
+
+    if (sgtb->sg_flags & TR_RAW) {
+        tios->c_lflag &=
+            ~(ECHO | ICANON | IEXTEN | ISIG | BRKINT | ICRNL | INPCK |
+              ISTRIP | IXON);
+        tios->c_cflag &= ~(CSIZE | PARENB);
+        tios->c_cflag |= CS8;
+        tios->c_oflag &= ~(OPOST);
+        tios->c_cc[VMIN] = 1;
+        tios->c_cc[VTIME] = 0;
+    }
+
+    if (sgtb->sg_flags & TR_CBREAK) {
+        TrapDebug((dbg_file, "\n\tto_termios: setting cbreak I hope "));
+        tios->c_lflag &= ~(ECHO | ICANON);
+        tios->c_cc[VMIN] = 1;
+        tios->c_cc[VTIME] = 0;
+    }
+    TrapDebug((dbg_file, "\n\tto_termios: iflag is 0x%x",
+               (int) tios->c_iflag));
+    TrapDebug((dbg_file, "\n\tto_termios: oflag is 0x%x",
+               (int) tios->c_oflag));
+    TrapDebug((dbg_file, "\n\tto_termios: lflag is 0x%x ",
+               (int) tios->c_lflag));
 }
 
 /* Convert from termios to old [l]tchars structures */
 static void to_tchars(struct tr_tchars *tc, struct tr_ltchars *ltc,
-                                               struct termios * tios)
+                      struct termios *tios)
 {
-  if (tc) {
-        tc->t_intrc=tios->c_cc[VINTR];
-        tc->t_quitc=tios->c_cc[VQUIT];
-        tc->t_startc=tios->c_cc[VSTART];
-        tc->t_stopc=tios->c_cc[VSTOP];
-        tc->t_eofc=tios->c_cc[VEOF];
-        tc->t_brkc=tios->c_cc[VEOL];
-  }
-  if (ltc) {
-        ltc->t_suspc=tios->c_cc[VSUSP];
-        ltc->t_dsuspc=tios->c_cc[VDSUSP];
-        ltc->t_rprntc=tios->c_cc[VREPRINT];
-        ltc->t_flushc=tios->c_cc[VDISCARD];
-        ltc->t_werasc=tios->c_cc[VERASE];
-        ltc->t_lnextc=tios->c_cc[VLNEXT];
-  }
+    if (tc) {
+        tc->t_intrc = tios->c_cc[VINTR];
+        tc->t_quitc = tios->c_cc[VQUIT];
+        tc->t_startc = tios->c_cc[VSTART];
+        tc->t_stopc = tios->c_cc[VSTOP];
+        tc->t_eofc = tios->c_cc[VEOF];
+        tc->t_brkc = tios->c_cc[VEOL];
+    }
+    if (ltc) {
+        ltc->t_suspc = tios->c_cc[VSUSP];
+        ltc->t_dsuspc = tios->c_cc[VDSUSP];
+        ltc->t_rprntc = tios->c_cc[VREPRINT];
+        ltc->t_flushc = tios->c_cc[VDISCARD];
+        ltc->t_werasc = tios->c_cc[VERASE];
+        ltc->t_lnextc = tios->c_cc[VLNEXT];
+    }
 }
 
 /* Convert from old [l]tchars to termios structures */
 static void tc_to_tchars(struct tr_tchars *tc, struct tr_ltchars *ltc,
-                                               struct termios * tios)
+                         struct termios *tios)
 {
-  if (tc) {
-       tios->c_cc[VINTR]= tc->t_intrc;
-       tios->c_cc[VQUIT]= tc->t_quitc;
-       tios->c_cc[VSTART]= tc->t_startc;
-       tios->c_cc[VSTOP]= tc->t_stopc;
-       tios->c_cc[VEOF]= tc->t_eofc;
-       tios->c_cc[VEOL]= tc->t_brkc;
-  }
-  if (ltc) {
-       tios->c_cc[VSUSP]= ltc->t_suspc;
-       tios->c_cc[VDSUSP]= ltc->t_dsuspc;
-       tios->c_cc[VREPRINT]= ltc->t_rprntc;
-       tios->c_cc[VDISCARD]= ltc->t_flushc;
-       tios->c_cc[VERASE]= ltc->t_werasc;
-       tios->c_cc[VLNEXT]= ltc->t_lnextc;
-  }
+    if (tc) {
+        tios->c_cc[VINTR] = tc->t_intrc;
+        tios->c_cc[VQUIT] = tc->t_quitc;
+        tios->c_cc[VSTART] = tc->t_startc;
+        tios->c_cc[VSTOP] = tc->t_stopc;
+        tios->c_cc[VEOF] = tc->t_eofc;
+        tios->c_cc[VEOL] = tc->t_brkc;
+    }
+    if (ltc) {
+        tios->c_cc[VSUSP] = ltc->t_suspc;
+        tios->c_cc[VDSUSP] = ltc->t_dsuspc;
+        tios->c_cc[VREPRINT] = ltc->t_rprntc;
+        tios->c_cc[VDISCARD] = ltc->t_flushc;
+        tios->c_cc[VERASE] = ltc->t_werasc;
+        tios->c_cc[VLNEXT] = ltc->t_lnextc;
+    }
 }
+
 /* Handle most get ioctls that deal with termios stuff */
 static int trap_gettermios(u_int16_t fd, u_int32_t type, u_int16_t ucnt)
 {
-  struct termios tios;
-  struct tr_sgttyb *sgtb;
-  struct tr_tchars *tc;
-  struct tr_ltchars *ltc;
-  int i;
-
-  if (ucnt == 0) return -1;
-  i = tcgetattr(fd, &tios);
-  if (i == -1) return i;
-  CLR_CC_C();
-
-  switch (type) {
+    struct termios tios;
+    struct tr_sgttyb *sgtb;
+    struct tr_tchars *tc;
+    struct tr_ltchars *ltc;
+    int i;
+
+    if (ucnt == 0)
+        return -1;
+    i = tcgetattr(fd, &tios);
+    if (i == -1)
+        return i;
+    CLR_CC_C();
+
+    switch (type) {
     case TR_TIOCGETP:
-      sgtb = (struct tr_sgttyb *) &dspace[ucnt];
-      to_sgttyb(sgtb, &tios); return 0;
+        sgtb = (struct tr_sgttyb *) &dspace[ucnt];
+        to_sgttyb(sgtb, &tios);
+        return 0;
     case TR_TIOCGETC:
-      tc = (struct tr_tchars *) &dspace[ucnt];
-      to_tchars(tc, NULL, &tios); return 0;
+        tc = (struct tr_tchars *) &dspace[ucnt];
+        to_tchars(tc, NULL, &tios);
+        return 0;
     case TR_TIOCGLTC:
-      ltc = (struct tr_ltchars *) &dspace[ucnt];
-      to_tchars(NULL, ltc, &tios); return 0;
-  }
-  /* Unknown type, should never get here */
-  return -1;
+        ltc = (struct tr_ltchars *) &dspace[ucnt];
+        to_tchars(NULL, ltc, &tios);
+        return 0;
+    }
+    /* Unknown type, should never get here */
+    return -1;
 }
 
 /* Handle most set ioctls that deal with termios stuff */
 static int trap_settermios(u_int16_t fd, u_int32_t type, u_int16_t ucnt)
 {
-  struct termios tios;
-  struct tr_sgttyb *sgtb;
-  struct tr_tchars *tc;
-  struct tr_ltchars *ltc;
-  int i;
-
-  if (ucnt == 0) return -1;
-  i = tcgetattr(fd, &tios);
-  if (i == -1) return i;
-  switch (type) {
+    struct termios tios;
+    struct tr_sgttyb *sgtb;
+    struct tr_tchars *tc;
+    struct tr_ltchars *ltc;
+    int i;
+
+    if (ucnt == 0)
+        return -1;
+    i = tcgetattr(fd, &tios);
+    if (i == -1)
+        return i;
+    switch (type) {
     case TR_TIOCSETP:
-      sgtb = (struct tr_sgttyb *) & dspace[ucnt];
-      to_termios(sgtb, &tios);
-      i = tcsetattr(fd, TCSANOW, &tios);
-      return (i);
+        sgtb = (struct tr_sgttyb *) &dspace[ucnt];
+        to_termios(sgtb, &tios);
+        i = tcsetattr(fd, TCSANOW, &tios);
+        return (i);
     case TR_TIOCSETN:
-      sgtb = (struct tr_sgttyb *) & dspace[ucnt];
-      to_termios(sgtb, &tios);
-      i = tcsetattr(fd, TCSADRAIN, &tios);
-      return (i);
+        sgtb = (struct tr_sgttyb *) &dspace[ucnt];
+        to_termios(sgtb, &tios);
+        i = tcsetattr(fd, TCSADRAIN, &tios);
+        return (i);
     case TR_TIOCSETC:
-      tc = (struct tr_tchars *) & dspace[ucnt];
-      tc_to_tchars(tc, NULL, &tios);
-      i = tcsetattr(fd, TCSANOW, &tios);
-      return (i);
+        tc = (struct tr_tchars *) &dspace[ucnt];
+        tc_to_tchars(tc, NULL, &tios);
+        i = tcsetattr(fd, TCSANOW, &tios);
+        return (i);
     case TR_TIOCSLTC:
-      ltc = (struct tr_ltchars *) & dspace[ucnt];
-      tc_to_tchars(NULL, ltc, &tios);
-      i = tcsetattr(fd, TCSANOW, &tios);
-      return (i);
-  }
-  /* Unknown type, should never get here */
-  return -1;
+        ltc = (struct tr_ltchars *) &dspace[ucnt];
+        tc_to_tchars(NULL, ltc, &tios);
+        i = tcsetattr(fd, TCSANOW, &tios);
+        return (i);
+    }
+    /* Unknown type, should never get here */
+    return -1;
 }
 #endif                         /* EMU211 */
index 9e1875f..6994499 100644 (file)
@@ -34,7 +34,7 @@
 #define        BSDSIGCONT      19      /* continue a stopped process */
 #define        BSDSIGCHLD      20      /* to parent on child stop or exit */
 #define        BSDSIGTTIN      21      /* to readers pgrp upon background tty read */
-#define        BSDSIGTTOU      22   /* like TTIN for output if (tp->t_local&LTOSTOP) */
+#define        BSDSIGTTOU      22      /* like TTIN for output if (tp->t_local&LTOSTOP) */
 #define        BSDSIGIO        23      /* input/output possible signal */
 #define        BSDSIGXCPU      24      /* exceeded CPU time limit */
 #define        BSDSIGXFSZ      25      /* exceeded file size limit */
 /*
  * Signal vector "template" used in sigaction call.
  */
-struct bsd_sigaction {
-       int16_t sig_handler;            /* signal handler */
-       u_int32_t sa_mask;              /* signal mask to apply */
-       int16_t sa_flags;               /* see signal options below */
+struct bsd_sigaction {
+    int16_t sig_handler;       /* signal handler */
+    u_int32_t sa_mask;         /* signal mask to apply */
+    int16_t sa_flags;          /* see signal options below */
 };
 
 #define BSD_ONSTACK    0x0001  /* take signal on signal stack */
@@ -67,11 +67,11 @@ struct      bsd_sigaction {
 /* Translate 2.11BSD signal value to our value */
 
 static int bsdsig[] = {
-       0, SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGIOT, SIGEMT,
-       SIGFPE, SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGALRM,
-       SIGTERM, SIGURG, SIGSTOP, SIGTSTP, SIGCONT, SIGCHLD, SIGTTIN,
-       SIGTTOU, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH,
-       SIGUSR1, SIGUSR2
+    0, SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGIOT, SIGEMT,
+    SIGFPE, SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGALRM,
+    SIGTERM, SIGURG, SIGSTOP, SIGTSTP, SIGCONT, SIGCHLD, SIGTTIN,
+    SIGTTOU, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH,
+    SIGUSR1, SIGUSR2
 };
 
 /* We keep a set of struct sigactions
@@ -83,50 +83,54 @@ struct bsd_sigaction Sigact[NBSDSIG];
 /* Set all signals to their default value */
 void set_bsdsig_dfl(void)
 {
-  int i;
+    int i;
 
-  for (i=0;i<NBSDSIG;i++) {
-       if (bsdsig[i]) signal(bsdsig[i], SIG_DFL);
-       Sigact[i].sig_handler= BSDSIG_DFL;
-       Sigact[i].sa_mask= Sigact[i].sa_flags= 0;
-  }
+    for (i = 0; i < NBSDSIG; i++) {
+        if (bsdsig[i])
+            signal(bsdsig[i], SIG_DFL);
+        Sigact[i].sig_handler = BSDSIG_DFL;
+        Sigact[i].sa_mask = Sigact[i].sa_flags = 0;
+    }
 }
 
 int do_sigaction(int sig, int a, int oa)
 {
-  int i;
-  struct bsd_sigaction *act, *oact;
-  struct sigaction ouraction;
-
-  if ((sig<0) || (sig >= NBSDSIG)) return(EINVAL);
-
-  if (oa) {
-    oact= (struct bsd_sigaction *)&dspace[oa];
-    memcpy(oact, &Sigact[sig], sizeof(struct bsd_sigaction));
-  }
-
-  if (a) {
-    act= (struct bsd_sigaction *)&dspace[a];
-
-               /* If required, map mask here */
-               /* Currently, the assumption is a 1-1 match */
-    sigemptyset(&(ouraction.sa_mask));
-    for (i=1; i<NBSDSIG;i++) {
-       if bsdsigismember(&(act->sa_mask), i)
-               sigaddset(&(ouraction.sa_mask), i);
+    int i;
+    struct bsd_sigaction *act, *oact;
+    struct sigaction ouraction;
+
+    if ((sig < 0) || (sig >= NBSDSIG))
+        return (EINVAL);
+
+    if (oa) {
+        oact = (struct bsd_sigaction *) &dspace[oa];
+        memcpy(oact, &Sigact[sig], sizeof(struct bsd_sigaction));
     }
-               /* If required, map flags here */
-    ouraction.sa_flags= act->sa_flags;
-    ouraction.sa_handler= sigcatcher;
-  }
-
-  i= sigaction(bsdsig[sig], &ouraction, NULL);
-  if (i==-1) return(i);
-
-               /* Else save the new sigaction */
-  act= (struct bsd_sigaction *)&dspace[a];
-  memcpy(&Sigact[sig], act, sizeof(struct bsd_sigaction));
-  return(i);
+
+    if (a) {
+        act = (struct bsd_sigaction *) &dspace[a];
+
+        /* If required, map mask here */
+        /* Currently, the assumption is a 1-1 match */
+        sigemptyset(&(ouraction.sa_mask));
+        for (i = 1; i < NBSDSIG; i++) {
+            if bsdsigismember
+            (&(act->sa_mask), i)
+                sigaddset(&(ouraction.sa_mask), i);
+        }
+        /* If required, map flags here */
+        ouraction.sa_flags = act->sa_flags;
+        ouraction.sa_handler = sigcatcher;
+    }
+
+    i = sigaction(bsdsig[sig], &ouraction, NULL);
+    if (i == -1)
+        return (i);
+
+    /* Else save the new sigaction */
+    act = (struct bsd_sigaction *) &dspace[a];
+    memcpy(&Sigact[sig], act, sizeof(struct bsd_sigaction));
+    return (i);
 }
 
 
@@ -152,7 +156,7 @@ int do_sigaction(int sig, int a, int oa)
  */
 
 #if 0
-int    (*signal())();
+int (*signal()) ();
 
 typedef unsigned long sigset_t;
 
@@ -164,39 +168,39 @@ typedef unsigned long sigset_t;
 #define        BSDSIG_UNBLOCK  2       /* unblock specified signal set */
 #define        BSDSIG_SETMASK  3       /* set specified signal set */
 
-typedef        int (*sig_t)();         /* type of signal function */
+typedef int (*sig_t) ();       /* type of signal function */
 
 /*
  * Structure used in sigaltstack call.
  */
-struct sigaltstack {
-       char    *ss_base;               /* signal stack base */
-       int     ss_size;                /* signal stack length */
-       int     ss_flags;               /* SA_DISABLE and/or SA_ONSTACK */
+struct sigaltstack {
+    char *ss_base;             /* signal stack base */
+    int ss_size;               /* signal stack length */
+    int ss_flags;              /* SA_DISABLE and/or SA_ONSTACK */
 };
-#define        MINBSDSIGSTKSZ  128                     /* minimum allowable stack */
+#define        MINBSDSIGSTKSZ  128     /* minimum allowable stack */
 #define        BSDSIGSTKSZ     (MINBSDSIGSTKSZ + 384)  /* recommended stack size */
 
 /*
  * 4.3 compatibility:
  * Signal vector "template" used in sigvec call.
  */
-struct sigvec {
-       int     (*sv_handler)();        /* signal handler */
-       long    sv_mask;                /* signal mask to apply */
-       int     sv_flags;               /* see signal options below */
+struct sigvec {
+    int (*sv_handler) ();      /* signal handler */
+    long sv_mask;              /* signal mask to apply */
+    int sv_flags;              /* see signal options below */
 };
 #define SV_ONSTACK     SA_ONSTACK      /* take signal on signal stack */
 #define SV_INTERRUPT   SA_RESTART      /* same bit, opposite sense */
-#define sv_onstack sv_flags            /* isn't compatibility wonderful! */
+#define sv_onstack sv_flags    /* isn't compatibility wonderful! */
 
 /*
  * 4.3 compatibility:
  * Structure used in sigstack call.
  */
-struct sigstack {
-       char    *ss_sp;                 /* signal stack pointer */
-       int     ss_onstack;             /* current status */
+struct sigstack {
+    char *ss_sp;               /* signal stack pointer */
+    int ss_onstack;            /* current status */
 };
 
 /*
@@ -206,16 +210,16 @@ struct    sigstack {
  * to the handler to allow it to properly restore state if
  * a non-standard exit is performed.
  */
-struct sigcontext {
-       int     sc_onstack;             /* sigstack state to restore */
-       long    sc_mask;                /* signal mask to restore */
-       int     sc_sp;                  /* sp to restore */
-       int     sc_fp;                  /* fp to restore */
-       int     sc_r1;                  /* r1 to restore */
-       int     sc_r0;                  /* r0 to restore */
-       int     sc_pc;                  /* pc to restore */
-       int     sc_ps;                  /* psl to restore */
-       int     sc_ovno                 /* overlay to restore */
+struct sigcontext {
+    int sc_onstack;            /* sigstack state to restore */
+    long sc_mask;              /* signal mask to restore */
+    int sc_sp;                 /* sp to restore */
+    int sc_fp;                 /* fp to restore */
+    int sc_r1;                 /* r1 to restore */
+    int sc_r0;                 /* r0 to restore */
+    int sc_pc;                 /* pc to restore */
+    int sc_ps;                 /* psl to restore */
+    int sc_ovno                        /* overlay to restore */
 };
 
 /*
@@ -229,4 +233,4 @@ struct      sigcontext {
 #define sigfillset(set)         (*(set) = ~(sigset_t)0, (int)0)
 #define sigismember(set, signo) ((*(set) & (1L << ((signo) - 1))) != 0)
 
-#endif /* 0 */
+#endif                         /* 0 */
index 2c450d5..aca94c3 100644 (file)
--- a/bsdtrap.c
+++ b/bsdtrap.c
@@ -32,7 +32,7 @@
 #define MAX_BLKSIZE    1024    /* Maximum block size from stat/fstat */
 
 #undef STREAM_BUFFERING                /* This works, but doesn't seem to give */
-                               /* any speed improvement */
+/* any speed improvement */
 
 arglist *A;                    /* Pointer to various arguments on stack */
 
@@ -50,210 +50,247 @@ static int16_t map_fcntl P((int16_t f));
 #endif
 #undef P
 
-void
-bsdtrap()
+void bsdtrap()
 {
     int i, j, len, pid, pfd[2];
     char *buf, *buf2;
     int16_t *shortptr;
     long larg1;
-    char *fmode;                               /* used with fdopen only */
-    struct stat stbuf;                         /* used in STAT */
-    struct tr_stat *tr_stbuf;                  /* used in STAT */
+    char *fmode;               /* used with fdopen only */
+    struct stat stbuf;         /* used in STAT */
+    struct tr_stat *tr_stbuf;  /* used in STAT */
     struct tr_timeval *tr_del, *tr_oldel;      /* used in ADJTIME */
-    struct timeval del, oldel;                 /* used in ADJTIME */
-    struct timeval utv[2];                     /* used in UTIMES */
-    struct tr_timezone *tr_zone;               /* used in GETTIMEOFDAY */
-    struct timezone zone;                      /* used in GETTIMEOFDAY */
+    struct timeval del, oldel; /* used in ADJTIME */
+    struct timeval utv[2];     /* used in UTIMES */
+    struct tr_timezone *tr_zone;       /* used in GETTIMEOFDAY */
+    struct timezone zone;      /* used in GETTIMEOFDAY */
     struct tr_itimerval *tr_tval, *tr_oltval;  /* used in itimer calls */
-    struct itimerval tval, oltval;             /* used in itimer calls */
-    struct tr_sockaddr *tr_sock;               /* used in socket calls */
-    struct sockaddr sock;                      /* used in socket calls */
-    gid_t *gidset;                             /* used in GETGROUPS */
-    struct tr_rlimit *tr_rlp;                  /* used in rlimit calls */
-    struct rlimit rlp;                         /* used in rlimit calls */
-    struct tr_rusage *tr_use;                  /* used in getrusage */
-    struct rusage use;                         /* used in getrusage */
-    struct iovec *ivec;                                /* used in writev, readv */
-    struct tr_iovec *trivec;                   /* used in writev, readv */
-
-    TrapDebug((dbg_file, "pid %d %s: ", (int)getpid(),bsdtrap_name[ir & 0xff]));
-
-    A= (arglist *)&dspace[(regs[SP]+2)];
-
-    i=errno=0;
+    struct itimerval tval, oltval;     /* used in itimer calls */
+    struct tr_sockaddr *tr_sock;       /* used in socket calls */
+    struct sockaddr sock;      /* used in socket calls */
+    gid_t *gidset;             /* used in GETGROUPS */
+    struct tr_rlimit *tr_rlp;  /* used in rlimit calls */
+    struct rlimit rlp;         /* used in rlimit calls */
+    struct tr_rusage *tr_use;  /* used in getrusage */
+    struct rusage use;         /* used in getrusage */
+    struct iovec *ivec;                /* used in writev, readv */
+    struct tr_iovec *trivec;   /* used in writev, readv */
+
+    TrapDebug((dbg_file, "pid %d %s: ", (int) getpid(),
+               bsdtrap_name[ir & 0xff]));
+
+    A = (arglist *) & dspace[(regs[SP] + 2)];
+
+    i = errno = 0;
     switch (ir & 0xff) {
     case S_INDIR:
-       (void)printf("Does 2.11BSD use INDIR? I don't think so\n");
-       exit(EXIT_FAILURE);
-
-    case S_QUOTA:                              /* DONE - for now */
-    case S_SETQUOTA:                           /* DONE - for now */
-       i=-1; errno=EINVAL; break;
-
-                       /* These syscalls are not implemented, and */
-                       /* always return EPERM to the caller */
-    case S_PTRACE:                             /* DONE - bad syscall */
-    case S_MOUNT:                              /* DONE - bad syscall */
-    case S_UMOUNT:                             /* DONE - bad syscall */
-    case S_PROFIL:                             /* DONE - bad syscall */
-    case S_NOSYS147:                           /* DONE - bad syscall */
+        (void) printf("Does 2.11BSD use INDIR? I don't think so\n");
+        exit(EXIT_FAILURE);
+
+    case S_QUOTA:              /* DONE - for now */
+    case S_SETQUOTA:   /* DONE - for now */
+        i = -1;
+        errno = EINVAL;
+        break;
+
+    /* These syscalls are not implemented, and */
+    /* always return EPERM to the caller */
+    case S_PTRACE:             /* DONE - bad syscall */
+    case S_MOUNT:              /* DONE - bad syscall */
+    case S_UMOUNT:             /* DONE - bad syscall */
+    case S_PROFIL:             /* DONE - bad syscall */
+    case S_NOSYS147:   /* DONE - bad syscall */
     case S_SYSCTL:
-       i=-1; errno=EPERM; break;
-                       /* These syscalls are ignored, and */
-                       /* always return C=0 to the caller */
-    case S_OLDLOCK:                            /* DONE - ok syscall */
-    case S_OLDPHYS:                            /* DONE - ok syscall */
-    case S_FSTATFS:                            /* DONE - ok syscall */
-    case S_SIGPROCMASK:                                /* DONE - ok syscall */
-    case S_SIGRETURN:                          /* DONE - ok syscall */
-    case S_SIGALTSTACK:                                /* DONE - ok syscall */
-    case S_VHANGUP:                            /* DONE - ok syscall */
-       i=0; break;
-    case S_SIGACTION:                          /* DONE */
+        i = -1;
+        errno = EPERM;
+        break;
+    /* These syscalls are ignored, and */
+    /* always return C=0 to the caller */
+    case S_OLDLOCK:    /* DONE - ok syscall */
+    case S_OLDPHYS:    /* DONE - ok syscall */
+    case S_FSTATFS:    /* DONE - ok syscall */
+    case S_SIGPROCMASK:        /* DONE - ok syscall */
+    case S_SIGRETURN:  /* DONE - ok syscall */
+    case S_SIGALTSTACK:        /* DONE - ok syscall */
+    case S_VHANGUP:    /* DONE - ok syscall */
+        i = 0;
+        break;
+    case S_SIGACTION:  /* DONE */
 #define NO_SIGNALS_YET
 #ifdef NO_SIGNALS_YET
-       i=0;
+        i = 0;
 #else
-       i= do_sigaction(uarg1, uarg2, uarg3);
+        i = do_sigaction(uarg1, uarg2, uarg3);
 #endif
-       break;
-    case S_IOCTL:                              /* DONE a bit */
-       i=trap_ioctl(); break;
-    case S_SBRK:                               /* DONE */
-       if (uarg1<regs[SP]) {
-           i=0;
-           TrapDebug((dbg_file, "set break to %d ", uarg1));
-       } else {
-           i=-1; errno=ENOMEM;
-           TrapDebug((dbg_file, "break %d > SP %d", uarg1, regs[SP]));
-       }
-       break;
-    case S_SYNC:                               /* DONE */
-       sync(); i=0; break;
-    case S_FSYNC:                              /* DONE */
-       i= fsync(sarg1); break;
-    case S_GETDTABLESIZE:                      /* DONE */
-       i= getdtablesize(); break;
-    case S_EXIT:                               /* DONE */
+        break;
+    case S_IOCTL:              /* DONE a bit */
+        i = trap_ioctl();
+        break;
+    case S_SBRK:               /* DONE */
+        if (uarg1 < regs[SP]) {
+            i = 0;
+            TrapDebug((dbg_file, "set break to %d ", uarg1));
+        } else {
+            i = -1;
+            errno = ENOMEM;
+            TrapDebug((dbg_file, "break %d > SP %d", uarg1, regs[SP]));
+        }
+        break;
+    case S_SYNC:               /* DONE */
+        sync();
+        i = 0;
+        break;
+    case S_FSYNC:              /* DONE */
+        i = fsync(sarg1);
+        break;
+    case S_GETDTABLESIZE:      /* DONE */
+        i = getdtablesize();
+        break;
+    case S_EXIT:               /* DONE */
 #ifdef DEBUG
-        TrapDebug((dbg_file, "val %d\n",sarg1)); fflush(dbg_file);
+        TrapDebug((dbg_file, "val %d\n", sarg1));
+        fflush(dbg_file);
 #endif
-       exit(sarg1);
-    case S_DUP:                                        /* DONE */
-        TrapDebug((dbg_file, "on %d ",sarg1));
-       i = dup(sarg1);
+        exit(sarg1);
+    case S_DUP:                /* DONE */
+        TrapDebug((dbg_file, "on %d ", sarg1));
+        i = dup(sarg1);
 #ifdef STREAM_BUFFERING
-            if ((i!=-1) && ValidFD(sarg1) && stream[sarg1]) {
-                fmode= streammode[sarg1];
-                stream[i] = fdopen(i, fmode);
-                streammode[i]=fmode;
-            }
+        if ((i != -1) && ValidFD(sarg1) && stream[sarg1]) {
+            fmode = streammode[sarg1];
+            stream[i] = fdopen(i, fmode);
+            streammode[i] = fmode;
+        }
 #endif
-       break;
-    case S_DUP2:                               /* DONE */
-        TrapDebug((dbg_file, "on %d %d ",sarg1,sarg2));
-       i = dup2(sarg1,sarg2);
+        break;
+    case S_DUP2:               /* DONE */
+        TrapDebug((dbg_file, "on %d %d ", sarg1, sarg2));
+        i = dup2(sarg1, sarg2);
 #ifdef STREAM_BUFFERING
-            if ((i!=-1) && ValidFD(sarg2) && ValidFD(sarg1) && stream[sarg1]) {
-                fmode= streammode[sarg1];
-                stream[sarg2] = fdopen(sarg2, fmode);
-                streammode[sarg2]=fmode;
-            }
+        if ((i != -1) && ValidFD(sarg2) && ValidFD(sarg1)
+                && stream[sarg1]) {
+            fmode = streammode[sarg1];
+            stream[sarg2] = fdopen(sarg2, fmode);
+            streammode[sarg2] = fmode;
+        }
 #endif
-       break;
-    case S_REBOOT:                             /* DONE */
-       (void)Reboot(sarg1); break;
-    case S_UMASK:                              /* DONE */
-       i = umask((mode_t)sarg1); break;
-    case S_GETPAGESIZE:                                /* DONE */
-       i = getpagesize(); break;
-    case S_GETHOSTNAME:                                /* DONE */
-       buf = (char *)&dspace[uarg1];
-       i= gethostname(buf,sarg2); break;
-    case S_SETHOSTNAME:                                /* DONE */
-       buf = (char *)&dspace[uarg1];
-       sethostname(buf,sarg2); break;
-    case S_LSEEK:                              /* DONE */
-       larg1 = (sarg2 << 16) | uarg3;
+        break;
+    case S_REBOOT:             /* DONE */
+        (void) Reboot(sarg1);
+        break;
+    case S_UMASK:              /* DONE */
+        i = umask((mode_t) sarg1);
+        break;
+    case S_GETPAGESIZE:        /* DONE */
+        i = getpagesize();
+        break;
+    case S_GETHOSTNAME:        /* DONE */
+        buf = (char *) &dspace[uarg1];
+        i = gethostname(buf, sarg2);
+        break;
+    case S_SETHOSTNAME:        /* DONE */
+        buf = (char *) &dspace[uarg1];
+        sethostname(buf, sarg2);
+        break;
+    case S_LSEEK:              /* DONE */
+        larg1 = (sarg2 << 16) | uarg3;
 #ifdef STREAM_BUFFERING
         if (ValidFD(sarg1) && stream[sarg1]) {
             i = fseek(stream[sarg1], larg1, sarg4);
-            if (i == 0) i = ftell(stream[sarg1]);
+            if (i == 0)
+                i = ftell(stream[sarg1]);
         } else
 #endif
-       i = lseek(sarg1, larg1, sarg4);
-       if (i == -1) break;
-       else {
-           regs[1] = i & 0xffff;
-           i= (i >> 16) & 0xffff;
-           break;
-       }
-    case S_READ:                               /* DONE */
-        TrapDebug((dbg_file, "%d bytes on %d ",uarg3,sarg1));
-       buf = (char *)&dspace[uarg2];
+            i = lseek(sarg1, larg1, sarg4);
+        if (i == -1)
+            break;
+        else {
+            regs[1] = i & 0xffff;
+            i = (i >> 16) & 0xffff;
+            break;
+        }
+    case S_READ:               /* DONE */
+        TrapDebug((dbg_file, "%d bytes on %d ", uarg3, sarg1));
+        buf = (char *) &dspace[uarg2];
 #ifdef STREAM_BUFFERING
         if (ValidFD(sarg1) && stream[sarg1])
             i = fread(buf, 1, uarg3, stream[sarg1]);
         else
 #endif
-       i = read(sarg1, buf, uarg3); break;
-    case S_LINK:                               /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       buf2 = xlate_filename((char *)&dspace[uarg2]);
-       i = link(buf, buf2); break;
-    case S_SYMLINK:                            /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       buf2 = xlate_filename((char *)&dspace[uarg2]);
-       i = symlink(buf, buf2); break;
-    case S_RENAME:                             /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       buf2 = xlate_filename((char *)&dspace[uarg2]);
-       i = rename(buf, buf2); break;
-    case S_READLINK:                           /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = readlink(buf, (char *)&dspace[uarg2], sarg3); break;
-    case S_ACCESS:                             /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = access(buf, sarg2); break;
-    case S_MKDIR:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = mkdir(buf, sarg2); break;
-    case S_RMDIR:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = rmdir(buf); break;
-    case S_ACCT:                               /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = acct(buf); break;
-    case S_WRITEV:                             /* DONE */
-    case S_READV:                              /* DONE */
-       ivec= (struct iovec *)malloc(uarg3 * sizeof(struct iovec));
-       if (ivec==NULL) { i=-1; errno=EINVAL; break; }
-       trivec= (struct tr_iovec *)&dspace[uarg2];
-
-       for (j=0; j<uarg3; j++) {
-           ivec[j].iov_len= trivec[j].iov_len;
-           ivec[j].iov_base= (char *)&dspace[trivec[j].iov_base];
-       }
-       if ((ir & 0xff)==S_READV) i= readv(sarg1, ivec, uarg3);
-       else i= writev(sarg1, ivec, uarg3);
-       free(ivec);
-       break;
-    case S_WRITE:                              /* DONE */
-       buf = (char *)&dspace[uarg2];
-        TrapDebug((dbg_file, "%d bytes on %d ",uarg3,sarg1));
+            i = read(sarg1, buf, uarg3);
+        break;
+    case S_LINK:               /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        buf2 = xlate_filename((char *) &dspace[uarg2]);
+        i = link(buf, buf2);
+        break;
+    case S_SYMLINK:    /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        buf2 = xlate_filename((char *) &dspace[uarg2]);
+        i = symlink(buf, buf2);
+        break;
+    case S_RENAME:             /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        buf2 = xlate_filename((char *) &dspace[uarg2]);
+        i = rename(buf, buf2);
+        break;
+    case S_READLINK:   /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = readlink(buf, (char *) &dspace[uarg2], sarg3);
+        break;
+    case S_ACCESS:             /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = access(buf, sarg2);
+        break;
+    case S_MKDIR:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = mkdir(buf, sarg2);
+        break;
+    case S_RMDIR:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = rmdir(buf);
+        break;
+    case S_ACCT:               /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = acct(buf);
+        break;
+    case S_WRITEV:             /* DONE */
+    case S_READV:              /* DONE */
+        ivec = (struct iovec *) malloc(uarg3 * sizeof(struct iovec));
+        if (ivec == NULL) {
+            i = -1;
+            errno = EINVAL;
+            break;
+        }
+        trivec = (struct tr_iovec *) &dspace[uarg2];
+
+        for (j = 0; j < uarg3; j++) {
+            ivec[j].iov_len = trivec[j].iov_len;
+            ivec[j].iov_base = (char *) &dspace[trivec[j].iov_base];
+        }
+        if ((ir & 0xff) == S_READV)
+            i = readv(sarg1, ivec, uarg3);
+        else
+            i = writev(sarg1, ivec, uarg3);
+        free(ivec);
+        break;
+    case S_WRITE:              /* DONE */
+        buf = (char *) &dspace[uarg2];
+        TrapDebug((dbg_file, "%d bytes on %d ", uarg3, sarg1));
 #ifdef STREAM_BUFFERING
         if (ValidFD(sarg1) && stream[sarg1])
             i = fwrite(buf, 1, uarg3, stream[sarg1]);
         else
 #endif
-       i = write(sarg1, buf, uarg3); break;
-    case S_CLOSE:                              /* DONE */
+            i = write(sarg1, buf, uarg3);
+        break;
+    case S_CLOSE:              /* DONE */
 #ifdef DEBUG
-    TrapDebug((dbg_file, "on %d ",sarg1));
-    if ((dbg_file!=NULL) && (sarg1==fileno(dbg_file))) {
-       i=0; break;                     /* Don't close our debug file! */
-    }
+        TrapDebug((dbg_file, "on %d ", sarg1));
+        if ((dbg_file != NULL) && (sarg1 == fileno(dbg_file))) {
+            i = 0;
+            break;             /* Don't close our debug file! */
+        }
 #endif
 #ifdef STREAM_BUFFERING
         if (ValidFD(sarg1) && stream[sarg1]) {
@@ -261,414 +298,501 @@ bsdtrap()
             stream[sarg1] = NULL;
         } else
 #endif
-       i = close(sarg1); break;
+            i = close(sarg1);
+        break;
     case S_FCNTL:
-        TrapDebug((dbg_file, "on %d %d %d ",sarg1,sarg2, sarg3));
-       i = fcntl(sarg1,sarg2,sarg3); break;
+        TrapDebug((dbg_file, "on %d %d %d ", sarg1, sarg2, sarg3));
+        i = fcntl(sarg1, sarg2, sarg3);
+        break;
     case S_FLOCK:
-       i = flock(sarg1,sarg2); break;
-    case S_LSTAT:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       tr_stbuf = (struct tr_stat *) &dspace[uarg2];
-       i = lstat(buf, &stbuf);
-        TrapDebug((dbg_file, "on %s ",buf));
-       goto dostat;
-    case S_STAT:                               /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       tr_stbuf = (struct tr_stat *) &dspace[uarg2];
-       i = stat(buf, &stbuf);
-        TrapDebug((dbg_file, "on %s ",buf));
-       goto dostat;
-    case S_FSTAT:                              /* DONE */
-       tr_stbuf = (struct tr_stat *) &dspace[uarg2];
-       i = fstat(uarg1, &stbuf);
-        TrapDebug((dbg_file, "on fd %d ",uarg1));
+        i = flock(sarg1, sarg2);
+        break;
+    case S_LSTAT:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        tr_stbuf = (struct tr_stat *) &dspace[uarg2];
+        i = lstat(buf, &stbuf);
+        TrapDebug((dbg_file, "on %s ", buf));
+        goto dostat;
+    case S_STAT:               /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        tr_stbuf = (struct tr_stat *) &dspace[uarg2];
+        i = stat(buf, &stbuf);
+        TrapDebug((dbg_file, "on %s ", buf));
+        goto dostat;
+    case S_FSTAT:              /* DONE */
+        tr_stbuf = (struct tr_stat *) &dspace[uarg2];
+        i = fstat(uarg1, &stbuf);
+        TrapDebug((dbg_file, "on fd %d ", uarg1));
 
 dostat:
-       if (i == -1) break;
-       else {
-                       /* The following stops blksize equalling 64K,
-                        * which becomes 0 in a 16-bit int. This then
-                        * causes 2.11BSD flsbuf() to malloc(0), which
-                        * then causes malloc to go crazy - wkt.
-                        */
-           if (stbuf.st_blksize>MAX_BLKSIZE) stbuf.st_blksize=MAX_BLKSIZE;
-
-           tr_stbuf->st_dev = stbuf.st_dev;
-           tr_stbuf->st_ino = stbuf.st_ino;
-           tr_stbuf->st_mode = stbuf.st_mode;
-           tr_stbuf->st_nlink = stbuf.st_nlink;
-           tr_stbuf->st_uid = stbuf.st_uid;
-           tr_stbuf->st_gid = stbuf.st_gid;
-           tr_stbuf->st_rdev = stbuf.st_rdev;
+        if (i == -1)
+            break;
+        else {
+            /* The following stops blksize equalling 64K,
+             * which becomes 0 in a 16-bit int. This then
+             * causes 2.11BSD flsbuf() to malloc(0), which
+             * then causes malloc to go crazy - wkt.
+             */
+            if (stbuf.st_blksize > MAX_BLKSIZE)
+                stbuf.st_blksize = MAX_BLKSIZE;
+
+            tr_stbuf->st_dev = stbuf.st_dev;
+            tr_stbuf->st_ino = stbuf.st_ino;
+            tr_stbuf->st_mode = stbuf.st_mode;
+            tr_stbuf->st_nlink = stbuf.st_nlink;
+            tr_stbuf->st_uid = stbuf.st_uid;
+            tr_stbuf->st_gid = stbuf.st_gid;
+            tr_stbuf->st_rdev = stbuf.st_rdev;
 #ifndef NO_STFLAGS
-           tr_stbuf->st_flags = stbuf.st_flags;
+            tr_stbuf->st_flags = stbuf.st_flags;
 #endif
-           copylong(tr_stbuf->st_size, stbuf.st_size);
-           copylong(tr_stbuf->st_atim, stbuf.st_atime);
-           copylong(tr_stbuf->st_mtim, stbuf.st_mtime);
-           copylong(tr_stbuf->st_ctim, stbuf.st_ctime);
-           copylong(tr_stbuf->st_blksize, stbuf.st_blksize);
-           larg1= stbuf.st_blocks; copylong(tr_stbuf->st_blocks, larg1);
-       }
-       break;
-    case S_UTIMES:                             /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       tr_del = (struct tr_timeval *) &dspace[uarg2];
-       tr_oldel = (struct tr_timeval *) &dspace[uarg4];
-       i= utimes(buf, utv);
-       if (i==-1) break;
-       copylong(tr_del->tv_sec,    utv[0].tv_sec);
-       copylong(tr_del->tv_usec,   utv[0].tv_usec);
-       copylong(tr_oldel->tv_sec,  utv[1].tv_sec);
-       copylong(tr_oldel->tv_usec, utv[1].tv_usec);
-       break;
-    case S_ADJTIME:                            /* DONE */
-       tr_del = (struct tr_timeval *) &dspace[uarg1];
-                                               /* Convert tr_del to del */
-       copylong(del.tv_sec,  tr_del->tv_sec);
-       copylong(del.tv_usec, tr_del->tv_usec);
-       i= adjtime(&del, &oldel);
-
-       if (uarg2) {
-           tr_oldel = (struct tr_timeval *) &dspace[uarg2];
-           copylong(tr_oldel->tv_sec,  oldel.tv_sec);
-           copylong(tr_oldel->tv_usec, oldel.tv_usec);
-       }
-       break;
-    case S_GETTIMEOFDAY:                       /* DONE */
-       tr_del = (struct tr_timeval *)   &dspace[uarg1];
-       tr_zone = (struct tr_timezone *) &dspace[uarg2];
-       i= gettimeofday(&del, &zone);
-       copylong(tr_del->tv_sec,  del.tv_sec);
-       copylong(tr_del->tv_usec, del.tv_usec);
-       tr_zone->tz_minuteswest= zone.tz_minuteswest;
-       tr_zone->tz_dsttime= zone.tz_dsttime;
-       break;
-    case S_SETTIMEOFDAY:                       /* DONE */
-       tr_del = (struct tr_timeval *)   &dspace[uarg1];
-       tr_zone = (struct tr_timezone *) &dspace[uarg2];
-       copylong(del.tv_sec,  tr_del->tv_sec);
-       copylong(del.tv_usec, tr_del->tv_usec);
-       zone.tz_minuteswest= tr_zone->tz_minuteswest;
-       zone.tz_dsttime= tr_zone->tz_dsttime;
-       i= settimeofday(&del, &zone);
-       break;
-    case S_GETITIMER:                          /* DONE */
-       tr_tval = (struct tr_itimerval *) &dspace[uarg2];
-       i= getitimer(sarg1, &tval);
-       copylong(tr_tval->it_interval.tv_sec,  tval.it_interval.tv_sec);
-       copylong(tr_tval->it_interval.tv_usec, tval.it_interval.tv_usec);
-       copylong(tr_tval->it_value.tv_sec,  tval.it_value.tv_sec);
-       copylong(tr_tval->it_value.tv_usec, tval.it_value.tv_usec);
-       break;
-    case S_SETITIMER:                          /* DONE */
-       tr_tval = (struct tr_itimerval *) &dspace[uarg2];
-       tr_oltval = (struct tr_itimerval *) &dspace[uarg2];
-       copylong(tval.it_interval.tv_sec,  tr_tval->it_interval.tv_sec);
-       copylong(tval.it_interval.tv_usec, tr_tval->it_interval.tv_usec);
-       copylong(tval.it_value.tv_sec,     tr_tval->it_value.tv_sec);
-       copylong(tval.it_value.tv_usec,    tr_tval->it_value.tv_usec);
-       i= setitimer(sarg1, &tval, &oltval);
-       if (i == -1) break;
-       copylong(tr_oltval->it_interval.tv_sec,  oltval.it_interval.tv_sec);
-       copylong(tr_oltval->it_interval.tv_usec, oltval.it_interval.tv_usec);
-       copylong(tr_oltval->it_value.tv_sec,     oltval.it_value.tv_sec);
-       copylong(tr_oltval->it_value.tv_usec,    oltval.it_value.tv_usec);
-       break;
-    case S_UNLINK:                             /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = unlink(buf); break;
-    case S_OPEN:                               /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-
-       i = stat(buf, &stbuf);  /* If file is a directory */
-       if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
-           i = bsdopen_dir(buf);
-           fmode = "w+";
-            TrapDebug((dbg_file, "(dir) on %s ",buf));
-       } else {
+            copylong(tr_stbuf->st_size, stbuf.st_size);
+            copylong(tr_stbuf->st_atim, stbuf.st_atime);
+            copylong(tr_stbuf->st_mtim, stbuf.st_mtime);
+            copylong(tr_stbuf->st_ctim, stbuf.st_ctime);
+            copylong(tr_stbuf->st_blksize, stbuf.st_blksize);
+            larg1 = stbuf.st_blocks;
+            copylong(tr_stbuf->st_blocks, larg1);
+        }
+        break;
+    case S_UTIMES:             /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        tr_del = (struct tr_timeval *) &dspace[uarg2];
+        tr_oldel = (struct tr_timeval *) &dspace[uarg4];
+        i = utimes(buf, utv);
+        if (i == -1)
+            break;
+        copylong(tr_del->tv_sec, utv[0].tv_sec);
+        copylong(tr_del->tv_usec, utv[0].tv_usec);
+        copylong(tr_oldel->tv_sec, utv[1].tv_sec);
+        copylong(tr_oldel->tv_usec, utv[1].tv_usec);
+        break;
+    case S_ADJTIME:    /* DONE */
+        tr_del = (struct tr_timeval *) &dspace[uarg1];
+        /* Convert tr_del to del */
+        copylong(del.tv_sec, tr_del->tv_sec);
+        copylong(del.tv_usec, tr_del->tv_usec);
+        i = adjtime(&del, &oldel);
+
+        if (uarg2) {
+            tr_oldel = (struct tr_timeval *) &dspace[uarg2];
+            copylong(tr_oldel->tv_sec, oldel.tv_sec);
+            copylong(tr_oldel->tv_usec, oldel.tv_usec);
+        }
+        break;
+    case S_GETTIMEOFDAY:       /* DONE */
+        tr_del = (struct tr_timeval *) &dspace[uarg1];
+        tr_zone = (struct tr_timezone *) &dspace[uarg2];
+        i = gettimeofday(&del, &zone);
+        copylong(tr_del->tv_sec, del.tv_sec);
+        copylong(tr_del->tv_usec, del.tv_usec);
+        tr_zone->tz_minuteswest = zone.tz_minuteswest;
+        tr_zone->tz_dsttime = zone.tz_dsttime;
+        break;
+    case S_SETTIMEOFDAY:       /* DONE */
+        tr_del = (struct tr_timeval *) &dspace[uarg1];
+        tr_zone = (struct tr_timezone *) &dspace[uarg2];
+        copylong(del.tv_sec, tr_del->tv_sec);
+        copylong(del.tv_usec, tr_del->tv_usec);
+        zone.tz_minuteswest = tr_zone->tz_minuteswest;
+        zone.tz_dsttime = tr_zone->tz_dsttime;
+        i = settimeofday(&del, &zone);
+        break;
+    case S_GETITIMER:  /* DONE */
+        tr_tval = (struct tr_itimerval *) &dspace[uarg2];
+        i = getitimer(sarg1, &tval);
+        copylong(tr_tval->it_interval.tv_sec, tval.it_interval.tv_sec);
+        copylong(tr_tval->it_interval.tv_usec,
+                 tval.it_interval.tv_usec);
+        copylong(tr_tval->it_value.tv_sec, tval.it_value.tv_sec);
+        copylong(tr_tval->it_value.tv_usec, tval.it_value.tv_usec);
+        break;
+    case S_SETITIMER:  /* DONE */
+        tr_tval = (struct tr_itimerval *) &dspace[uarg2];
+        tr_oltval = (struct tr_itimerval *) &dspace[uarg2];
+        copylong(tval.it_interval.tv_sec, tr_tval->it_interval.tv_sec);
+        copylong(tval.it_interval.tv_usec,
+                 tr_tval->it_interval.tv_usec);
+        copylong(tval.it_value.tv_sec, tr_tval->it_value.tv_sec);
+        copylong(tval.it_value.tv_usec, tr_tval->it_value.tv_usec);
+        i = setitimer(sarg1, &tval, &oltval);
+        if (i == -1)
+            break;
+        copylong(tr_oltval->it_interval.tv_sec,
+                 oltval.it_interval.tv_sec);
+        copylong(tr_oltval->it_interval.tv_usec,
+                 oltval.it_interval.tv_usec);
+        copylong(tr_oltval->it_value.tv_sec, oltval.it_value.tv_sec);
+        copylong(tr_oltval->it_value.tv_usec, oltval.it_value.tv_usec);
+        break;
+    case S_UNLINK:             /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = unlink(buf);
+        break;
+    case S_OPEN:               /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+
+        i = stat(buf, &stbuf); /* If file is a directory */
+        if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
+            i = bsdopen_dir(buf);
+            fmode = "w+";
+            TrapDebug((dbg_file, "(dir) on %s ", buf));
+        } else {
 #ifdef NEED_MAP_FCNTL
-           sarg2= map_fcntl(sarg2);
+            sarg2 = map_fcntl(sarg2);
 #endif
-           switch (sarg2 & O_ACCMODE) {
-              case O_RDONLY: fmode = "r"; break;
-              case O_WRONLY: fmode = "w"; break;
-              default: fmode = "w+"; break;
+            switch (sarg2 & O_ACCMODE) {
+            case O_RDONLY:
+                fmode = "r";
+                break;
+            case O_WRONLY:
+                fmode = "w";
+                break;
+            default:
+                fmode = "w+";
+                break;
             }
-           i = open(buf, sarg2, sarg3);
-            TrapDebug((dbg_file, "on %s ",buf));
-            TrapDebug((dbg_file, "sarg2 is %d, sarg3 is 0x%x ",sarg2,sarg3));
-       }
+            i = open(buf, sarg2, sarg3);
+            TrapDebug((dbg_file, "on %s ", buf));
+            TrapDebug((dbg_file, "sarg2 is %d, sarg3 is 0x%x ", sarg2,
+                       sarg3));
+        }
 #ifdef STREAM_BUFFERING
-       if (i==-1) break;
+        if (i == -1)
+            break;
         /* Now get its stream pointer if possible */
         /* Can someone explain why fdopen doesn't work for O_RDWR? */
-# if 0
-        if (ValidFD(i) && !isatty(i) && (sarg2!=O_RDWR)) {
-            stream[i] = fdopen(i, fmode); streammode[i]=fmode;
+#if 0
+        if (ValidFD(i) && !isatty(i) && (sarg2 != O_RDWR)) {
+            stream[i] = fdopen(i, fmode);
+            streammode[i] = fmode;
         }
-# endif
-       stream[i] = fdopen(i, fmode); streammode[i]=fmode;
 #endif
-       break;
-    case S_MKNOD:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = mknod(buf, sarg2, sarg3); break;
-    case S_CHMOD:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = chmod(buf, sarg2); break;
-    case S_FCHMOD:                             /* DONE */
-       i = fchmod(sarg1, sarg2); break;
-    case S_TRUNCATE:                           /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       larg1 = (sarg2 << 16) | uarg3;
-       i = truncate(buf, larg1); break;
-    case S_FTRUNCATE:                          /* DONE */
-       larg1 = (sarg2 << 16) | uarg3;
-       i = ftruncate(sarg1, larg1); break;
-    case S_KILL:                               /* DONE */
-       i = kill(sarg1, sarg2); break;
-    case S_KILLPG:                             /* DONE */
-       i = killpg(sarg1, sarg2); break;
-    case S_CHOWN:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = chown(buf, sarg2, sarg3); break;
-    case S_PIPE:                               /* DONE */
-       i = pipe(pfd);
+        stream[i] = fdopen(i, fmode);
+        streammode[i] = fmode;
+#endif
+        break;
+    case S_MKNOD:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = mknod(buf, sarg2, sarg3);
+        break;
+    case S_CHMOD:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chmod(buf, sarg2);
+        break;
+    case S_FCHMOD:             /* DONE */
+        i = fchmod(sarg1, sarg2);
+        break;
+    case S_TRUNCATE:   /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        larg1 = (sarg2 << 16) | uarg3;
+        i = truncate(buf, larg1);
+        break;
+    case S_FTRUNCATE:  /* DONE */
+        larg1 = (sarg2 << 16) | uarg3;
+        i = ftruncate(sarg1, larg1);
+        break;
+    case S_KILL:               /* DONE */
+        i = kill(sarg1, sarg2);
+        break;
+    case S_KILLPG:             /* DONE */
+        i = killpg(sarg1, sarg2);
+        break;
+    case S_CHOWN:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chown(buf, sarg2, sarg3);
+        break;
+    case S_PIPE:               /* DONE */
+        i = pipe(pfd);
 #ifdef STREAM_BUFFERING
         if (ValidFD(pfd[0])) {
-                stream[pfd[0]] = fdopen(pfd[0], "r");
-                streammode[pfd[0]]= "r";
+            stream[pfd[0]] = fdopen(pfd[0], "r");
+            streammode[pfd[0]] = "r";
         }
         if (ValidFD(pfd[1])) {
-                stream[pfd[1]] = fdopen(pfd[1], "w");
-                streammode[pfd[1]]= "w";
+            stream[pfd[1]] = fdopen(pfd[1], "w");
+            streammode[pfd[1]] = "w";
         }
 #endif
-       if (i == -1) break;
-       i = pfd[0]; regs[1] = pfd[1]; break;
-    case S_CHROOT:                             /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       if (buf == NULL) {
-           errno=ENOENT; i=-1; break;
-       }
-       set_apout_root(buf);
-       i=0; break;
-    case S_CHDIR:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = chdir(buf); break;
-    case S_FCHDIR:                             /* DONE */
-       i = fchdir(sarg1); break;
+        if (i == -1)
+            break;
+        i = pfd[0];
+        regs[1] = pfd[1];
+        break;
+    case S_CHROOT:             /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        if (buf == NULL) {
+            errno = ENOENT;
+            i = -1;
+            break;
+        }
+        set_apout_root(buf);
+        i = 0;
+        break;
+    case S_CHDIR:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chdir(buf);
+        break;
+    case S_FCHDIR:             /* DONE */
+        i = fchdir(sarg1);
+        break;
 
 #ifndef NO_CHFLAGS
-    case S_CHFLAGS:                            /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = chflags(buf,uarg2); break;
-    case S_FCHFLAGS:                           /* DONE */
-       i = fchflags(sarg1,uarg2); break;
+    case S_CHFLAGS:    /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chflags(buf, uarg2);
+        break;
+    case S_FCHFLAGS:   /* DONE */
+        i = fchflags(sarg1, uarg2);
+        break;
 #endif
 
-    case S_CREAT:                              /* DONE */
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = creat(buf, sarg2);
+    case S_CREAT:              /* DONE */
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = creat(buf, sarg2);
 #ifdef STREAM_BUFFERING
         if (ValidFD(i)) {
-                stream[i] = fdopen(i, "w");
-                streammode[i]= "w";
+            stream[i] = fdopen(i, "w");
+            streammode[i] = "w";
         }
 #endif
-       break;
-    case S_EXECVE:                             /* DONE, I think */
-       i= trap_execve(1); break;
-    case S_EXECV:                              /* Not sure here */
-       i= trap_execve(0); break;
-    case S_WAIT:                               /* Not sure here */
-       i = wait(&pid);
-       if (i == -1) break;
-       regs[1] = pid;
-       break;
-    case S_WAIT4:                              /* Definitely incomplete */
-       TrapDebug((dbg_file, "on pid %d options %d ",sarg1,uarg3));
-       if (uarg4) TrapDebug((dbg_file, " rusage on!!! "));
-       shortptr = (int16_t *)&dspace[uarg2];
-       i= wait4(sarg1, &j, uarg3, 0);
-       *shortptr= j;
-       break;
-    case S_FORK:                               /* DONE */
-    case S_VFORK:                              /* DONE */
-       i = fork();
-       if (i!=0) { regs[PC]+=2; }              /* Took ages to find this! */
-       else ov_changes=0;
-       break;
-    case S_GETHOSTID:                          /* DONE */
-       i = gethostid();
-       regs[1] = i & 0xffff;
-       i= (i >> 16) & 0xffff;
-       break;
-    case S_SETHOSTID:                          /* DONE */
-       larg1 = (sarg2 << 16) | uarg3;
-       sethostid(larg1); i=0; break;
-    case S_GETUID:                             /* DONE */
-       i = getuid(); break;
-    case S_SETUID:                             /* DONE */
-       i = setuid(uarg1); break;
-    case S_GETEUID:                            /* DONE */
-       i = geteuid(); break;
-    case S_GETPID:                             /* DONE */
-       i = getpid(); break;
-    case S_GETPPID:                            /* DONE */
-       i = getppid(); break;
-    case S_GETGID:                             /* DONE */
-       i = getgid(); break;
-    case S_GETEGID:                            /* DONE */
-       i = getegid(); break;
+        break;
+    case S_EXECVE:             /* DONE, I think */
+        i = trap_execve(1);
+        break;
+    case S_EXECV:              /* Not sure here */
+        i = trap_execve(0);
+        break;
+    case S_WAIT:               /* Not sure here */
+        i = wait(&pid);
+        if (i == -1)
+            break;
+        regs[1] = pid;
+        break;
+    case S_WAIT4:              /* Definitely incomplete */
+        TrapDebug((dbg_file, "on pid %d options %d ", sarg1, uarg3));
+        if (uarg4)
+            TrapDebug((dbg_file, " rusage on!!! "));
+        shortptr = (int16_t *) & dspace[uarg2];
+        i = wait4(sarg1, &j, uarg3, 0);
+        *shortptr = j;
+        break;
+    case S_FORK:               /* DONE */
+    case S_VFORK:              /* DONE */
+        i = fork();
+        if (i != 0) {
+            regs[PC] += 2;
+        } /* Took ages to find this! */
+        else
+            ov_changes = 0;
+        break;
+    case S_GETHOSTID:  /* DONE */
+        i = gethostid();
+        regs[1] = i & 0xffff;
+        i = (i >> 16) & 0xffff;
+        break;
+    case S_SETHOSTID:  /* DONE */
+        larg1 = (sarg2 << 16) | uarg3;
+        sethostid(larg1);
+        i = 0;
+        break;
+    case S_GETUID:             /* DONE */
+        i = getuid();
+        break;
+    case S_SETUID:             /* DONE */
+        i = setuid(uarg1);
+        break;
+    case S_GETEUID:    /* DONE */
+        i = geteuid();
+        break;
+    case S_GETPID:             /* DONE */
+        i = getpid();
+        break;
+    case S_GETPPID:    /* DONE */
+        i = getppid();
+        break;
+    case S_GETGID:             /* DONE */
+        i = getgid();
+        break;
+    case S_GETEGID:    /* DONE */
+        i = getegid();
+        break;
 #ifndef NO_GETPGID
-    case S_GETPGRP:                            /* DONE */
-       i = getpgid(sarg1); break;
+    case S_GETPGRP:    /* DONE */
+        i = getpgid(sarg1);
+        break;
 #endif
-    case S_SETPGRP:                            /* DONE */
-       i = setpgid(sarg1,sarg2); break;
-    case S_SETREGID:                           /* DONE */
-       i = setregid(sarg1,sarg2); break;
-    case S_SETREUID:                           /* DONE */
-       i = setreuid(sarg1,sarg2); break;
-    case S_GETPRIORITY:                                /* DONE */
-       i = getpriority(sarg1,sarg2); break;
-    case S_SETPRIORITY:                                /* DONE */
-       i = setpriority(sarg1,sarg2,sarg3); break;
-    case S_LISTEN:                             /* DONE */
-       i = listen(sarg1,sarg2); break;
-    case S_SHUTDOWN:                           /* DONE */
-       i = shutdown(sarg1,sarg2); break;
-    case S_SOCKET:                             /* DONE */
-       i = socket(sarg1,sarg2,sarg3); break;
-    case S_SOCKETPAIR:                         /* DONE */
-       i = socketpair(sarg1,sarg2,sarg3, pfd); break;
-       shortptr= (int16_t *)&dspace[uarg4];
-       *shortptr= pfd[0]; shortptr+=2;
-       *shortptr= pfd[1];
-       break;
-    case S_RECV:                               /* DONE */
-       buf = (char *)&dspace[uarg2];
-       i = recv(sarg1, buf, sarg3, sarg4); break;
-    case S_SEND:                               /* DONE */
-       buf = (char *)&dspace[uarg2];
-       i = send(sarg1, buf, sarg3, sarg4); break;
-    case S_ACCEPT:                             /* DONE */
-       tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
-       sock.sa_family= tr_sock->sa_family;
-       ll_word(uarg3, len);
+    case S_SETPGRP:    /* DONE */
+        i = setpgid(sarg1, sarg2);
+        break;
+    case S_SETREGID:   /* DONE */
+        i = setregid(sarg1, sarg2);
+        break;
+    case S_SETREUID:   /* DONE */
+        i = setreuid(sarg1, sarg2);
+        break;
+    case S_GETPRIORITY:        /* DONE */
+        i = getpriority(sarg1, sarg2);
+        break;
+    case S_SETPRIORITY:        /* DONE */
+        i = setpriority(sarg1, sarg2, sarg3);
+        break;
+    case S_LISTEN:             /* DONE */
+        i = listen(sarg1, sarg2);
+        break;
+    case S_SHUTDOWN:   /* DONE */
+        i = shutdown(sarg1, sarg2);
+        break;
+    case S_SOCKET:             /* DONE */
+        i = socket(sarg1, sarg2, sarg3);
+        break;
+    case S_SOCKETPAIR: /* DONE */
+        i = socketpair(sarg1, sarg2, sarg3, pfd);
+        break;
+        shortptr = (int16_t *) & dspace[uarg4];
+        *shortptr = pfd[0];
+        shortptr += 2;
+        *shortptr = pfd[1];
+        break;
+    case S_RECV:               /* DONE */
+        buf = (char *) &dspace[uarg2];
+        i = recv(sarg1, buf, sarg3, sarg4);
+        break;
+    case S_SEND:               /* DONE */
+        buf = (char *) &dspace[uarg2];
+        i = send(sarg1, buf, sarg3, sarg4);
+        break;
+    case S_ACCEPT:             /* DONE */
+        tr_sock = (struct tr_sockaddr *) &dspace[uarg2];
+        sock.sa_family = tr_sock->sa_family;
+        ll_word(uarg3, len);
 #ifndef __linux__
-       sock.sa_len=len;
+        sock.sa_len = len;
 #endif
-       memcpy(sock.sa_data, tr_sock->sa_data, len);
-       i= accept(sarg1, &sock, (socklen_t *)&len);
-       if (i != -1) {
-           sl_word(uarg3,len);
-           memcpy(tr_sock->sa_data, sock.sa_data, len);
-       }
-       break;
-    case S_GETPEERNAME:                                /* DONE */
-       tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
-       sock.sa_family= tr_sock->sa_family;
-       ll_word(uarg3, len);
+        memcpy(sock.sa_data, tr_sock->sa_data, len);
+        i = accept(sarg1, &sock, (socklen_t *) & len);
+        if (i != -1) {
+            sl_word(uarg3, len);
+            memcpy(tr_sock->sa_data, sock.sa_data, len);
+        }
+        break;
+    case S_GETPEERNAME:        /* DONE */
+        tr_sock = (struct tr_sockaddr *) &dspace[uarg2];
+        sock.sa_family = tr_sock->sa_family;
+        ll_word(uarg3, len);
 #ifndef __linux__
-       sock.sa_len=len;
+        sock.sa_len = len;
 #endif
-       memcpy(sock.sa_data, tr_sock->sa_data, len);
-       i= getpeername(sarg1, &sock, (socklen_t *)&len);
-       if (i != -1) {
-           sl_word(uarg3,len);
-           memcpy(tr_sock->sa_data, sock.sa_data, len);
-       }
-       break;
-    case S_GETSOCKNAME:                                /* DONE */
-       tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
-       sock.sa_family= tr_sock->sa_family;
-       ll_word(uarg3, len);
+        memcpy(sock.sa_data, tr_sock->sa_data, len);
+        i = getpeername(sarg1, &sock, (socklen_t *) & len);
+        if (i != -1) {
+            sl_word(uarg3, len);
+            memcpy(tr_sock->sa_data, sock.sa_data, len);
+        }
+        break;
+    case S_GETSOCKNAME:        /* DONE */
+        tr_sock = (struct tr_sockaddr *) &dspace[uarg2];
+        sock.sa_family = tr_sock->sa_family;
+        ll_word(uarg3, len);
 #ifndef __linux__
-       sock.sa_len=len;
+        sock.sa_len = len;
 #endif
-       memcpy(sock.sa_data, tr_sock->sa_data, len);
-       i= getsockname(sarg1, &sock, (socklen_t *)&len);
-       if (i != -1) {
-           sl_word(uarg3,len);
-           memcpy(tr_sock->sa_data, sock.sa_data, len);
-       }
-       break;
-    case S_BIND:                               /* DONE */
-       tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
-       sock.sa_family= tr_sock->sa_family;
-       len= sarg3;
+        memcpy(sock.sa_data, tr_sock->sa_data, len);
+        i = getsockname(sarg1, &sock, (socklen_t *) & len);
+        if (i != -1) {
+            sl_word(uarg3, len);
+            memcpy(tr_sock->sa_data, sock.sa_data, len);
+        }
+        break;
+    case S_BIND:               /* DONE */
+        tr_sock = (struct tr_sockaddr *) &dspace[uarg2];
+        sock.sa_family = tr_sock->sa_family;
+        len = sarg3;
 #ifndef __linux__
-       sock.sa_len= sarg3;
+        sock.sa_len = sarg3;
 #endif
-       memcpy(sock.sa_data, tr_sock->sa_data, len);
-       i= bind(sarg1, &sock, len);
-       break;
-    case S_CONNECT:                            /* DONE */
-       tr_sock= (struct tr_sockaddr *)&dspace[uarg2];
-       sock.sa_family= tr_sock->sa_family;
-       len= sarg3;
+        memcpy(sock.sa_data, tr_sock->sa_data, len);
+        i = bind(sarg1, &sock, len);
+        break;
+    case S_CONNECT:    /* DONE */
+        tr_sock = (struct tr_sockaddr *) &dspace[uarg2];
+        sock.sa_family = tr_sock->sa_family;
+        len = sarg3;
 #ifndef __linux__
-       sock.sa_len= sarg3;
+        sock.sa_len = sarg3;
 #endif
-       memcpy(sock.sa_data, tr_sock->sa_data, len);
-       i= connect(sarg1, &sock, len);
-       break;
-    case S_RECVFROM:                           /* DONE I think */
-       tr_sock= (struct tr_sockaddr *)&dspace[uarg5];
-       sock.sa_family= tr_sock->sa_family;
-       ll_word(uarg6, len);
+        memcpy(sock.sa_data, tr_sock->sa_data, len);
+        i = connect(sarg1, &sock, len);
+        break;
+    case S_RECVFROM:   /* DONE I think */
+        tr_sock = (struct tr_sockaddr *) &dspace[uarg5];
+        sock.sa_family = tr_sock->sa_family;
+        ll_word(uarg6, len);
 #ifndef __linux__
-       sock.sa_len=len;
+        sock.sa_len = len;
 #endif
-       memcpy(sock.sa_data, tr_sock->sa_data, len);
-       buf = (char *)&dspace[uarg2];
-       i= recvfrom(sarg1, buf, sarg3, sarg4, &sock, (socklen_t *)&len);
-       if (i != -1) {
-           sl_word(uarg6,len);
-           memcpy(tr_sock->sa_data, sock.sa_data, len);
-       }
-       break;
+        memcpy(sock.sa_data, tr_sock->sa_data, len);
+        buf = (char *) &dspace[uarg2];
+        i = recvfrom(sarg1, buf, sarg3, sarg4, &sock,
+                     (socklen_t *) & len);
+        if (i != -1) {
+            sl_word(uarg6, len);
+            memcpy(tr_sock->sa_data, sock.sa_data, len);
+        }
+        break;
     case S_GETGROUPS:
-       len= sarg1;
-       gidset= (gid_t *)malloc(len * sizeof(gid_t));
-       if (gidset==NULL) { i=-1; errno=EINVAL; break; }
-       i= getgroups(len, gidset);
-       shortptr= (int16_t *)&dspace[uarg2];
-       for (j=0; j<i; j++) shortptr[j]= gidset[j];
-       free(gidset);
-       break;
+        len = sarg1;
+        gidset = (gid_t *) malloc(len * sizeof(gid_t));
+        if (gidset == NULL) {
+            i = -1;
+            errno = EINVAL;
+            break;
+        }
+        i = getgroups(len, gidset);
+        shortptr = (int16_t *) & dspace[uarg2];
+        for (j = 0; j < i; j++)
+            shortptr[j] = gidset[j];
+        free(gidset);
+        break;
     case S_SETGROUPS:
-       len= sarg1;
-       if (len>16) { i=-1; errno=EFAULT; break; }
-       gidset= (gid_t *)malloc(len * sizeof(gid_t));
-       if (gidset==NULL) { i=-1; errno=EINVAL; break; }
-       shortptr= (int16_t *)&dspace[uarg2];
-       for (j=0; j<len; j++) gidset[j]= shortptr[j];
-       i= setgroups(len, gidset);
-       free(gidset);
-       break;
-    case S_GETRLIMIT:                          /* DONE */
-       tr_rlp= (struct tr_rlimit *)&dspace[uarg2];
-       i= getrlimit(sarg1, &rlp);
-       if (i== -1) break;
-       copylong(tr_rlp->rlim_cur, rlp.rlim_cur);
-       copylong(tr_rlp->rlim_max, rlp.rlim_max);
-       break;
-    case S_SETRLIMIT:                          /* DONE */
-       tr_rlp= (struct tr_rlimit *)&dspace[uarg2];
-       copylong(rlp.rlim_cur, tr_rlp->rlim_cur);
-       copylong(rlp.rlim_max, tr_rlp->rlim_max);
-       i= setrlimit(sarg1, &rlp);
-       break;
+        len = sarg1;
+        if (len > 16) {
+            i = -1;
+            errno = EFAULT;
+            break;
+        }
+        gidset = (gid_t *) malloc(len * sizeof(gid_t));
+        if (gidset == NULL) {
+            i = -1;
+            errno = EINVAL;
+            break;
+        }
+        shortptr = (int16_t *) & dspace[uarg2];
+        for (j = 0; j < len; j++)
+            gidset[j] = shortptr[j];
+        i = setgroups(len, gidset);
+        free(gidset);
+        break;
+    case S_GETRLIMIT:  /* DONE */
+        tr_rlp = (struct tr_rlimit *) &dspace[uarg2];
+        i = getrlimit(sarg1, &rlp);
+        if (i == -1)
+            break;
+        copylong(tr_rlp->rlim_cur, rlp.rlim_cur);
+        copylong(tr_rlp->rlim_max, rlp.rlim_max);
+        break;
+    case S_SETRLIMIT:  /* DONE */
+        tr_rlp = (struct tr_rlimit *) &dspace[uarg2];
+        copylong(rlp.rlim_cur, tr_rlp->rlim_cur);
+        copylong(rlp.rlim_max, tr_rlp->rlim_max);
+        i = setrlimit(sarg1, &rlp);
+        break;
     case S_GETRUSAGE:
-       TrapDebug((dbg_file, "arg1 %d pointer 0%o ",sarg1,uarg2));
-       tr_use = (struct tr_rusage *) &dspace[uarg2];
-       i= getrusage(sarg1, &use);
-       if (i==-1) break;
+        TrapDebug((dbg_file, "arg1 %d pointer 0%o ", sarg1, uarg2));
+        tr_use = (struct tr_rusage *) &dspace[uarg2];
+        i = getrusage(sarg1, &use);
+        if (i == -1)
+            break;
 
         /* Should do tr_use->ru_utime;        user time used */
         /* Should do tr_use->ru_stime;        system time used */
@@ -687,82 +811,87 @@ dostat:
         copylong(tr_use->ru_nsignals, use.ru_nsignals);
         copylong(tr_use->ru_nvcsw, use.ru_nvcsw);
         copylong(tr_use->ru_nivcsw, use.ru_nivcsw);
-       break;
+        break;
     default:
-       if ((ir & 0xff)>S_GETSOCKNAME) {
-         TrapDebug((stderr,"Apout - unknown syscall %d at PC 0%o\n",
-                                                       ir & 0xff,regs[PC]));
-       } else {
-          (void)fprintf(stderr,
-               "Apout - the 2.11BSD %s syscall is not yet implemented\n",
-                                               bsdtrap_name[ir & 0xff]);
-       }
-       exit(EXIT_FAILURE);
+        if ((ir & 0xff) > S_GETSOCKNAME) {
+            TrapDebug((stderr,
+                       "Apout - unknown syscall %d at PC 0%o\n",
+                       ir & 0xff, regs[PC]));
+        } else {
+            (void) fprintf(stderr,
+                           "Apout - the 2.11BSD %s syscall is not yet implemented\n",
+                           bsdtrap_name[ir & 0xff]);
+        }
+        exit(EXIT_FAILURE);
     }
 
-       /* Set r0 to either errno or i, */
-       /* and clear/set C bit */
+    /* Set r0 to either errno or i, */
+    /* and clear/set C bit */
 
     if (i == -1) {
-       SET_CC_C(); regs[0] = errno;
-       TrapDebug((dbg_file, "errno is %s\n", strerror(errno)));
+        SET_CC_C();
+        regs[0] = errno;
+        TrapDebug((dbg_file, "errno is %s\n", strerror(errno)));
     } else {
-       CLR_CC_C(); regs[0]=i;
-       TrapDebug((dbg_file, "return %d\n", i));
+        CLR_CC_C();
+        regs[0] = i;
+        TrapDebug((dbg_file, "return %d\n", i));
     }
     return;
 }
 
 
 
-static int
-trap_execve(int want_env)
+static int trap_execve(int want_env)
 {
     u_int16_t cptr, cptr2;
     char *buf, *name, *origpath;
 
-    origpath = strdup((char *)&dspace[uarg1]);
+    origpath = strdup((char *) &dspace[uarg1]);
     name = xlate_filename(origpath);
     TrapDebug((dbg_file, "%s Execing %s (%s) ", progname, name, origpath));
 
-    set_bsdsig_dfl();  /* Set signals to default values */
+    set_bsdsig_dfl();          /* Set signals to default values */
 
-    cptr=uarg2;
-    Argc=0; Envc=0;
+    cptr = uarg2;
+    Argc = 0;
+    Envc = 0;
     while (Argc < MAX_ARGS) {
-       ll_word(cptr, cptr2);
-       if (cptr2 == 0)
-           break;
-       buf = (char *)&dspace[cptr2];
-       Argv[Argc++] = strdup(buf);
-       cptr += 2;
-       TrapDebug((dbg_file, "%s ", buf));
+        ll_word(cptr, cptr2);
+        if (cptr2 == 0)
+            break;
+        buf = (char *) &dspace[cptr2];
+        Argv[Argc++] = strdup(buf);
+        cptr += 2;
+        TrapDebug((dbg_file, "%s ", buf));
     }
     Argv[Argc] = NULL;
     TrapDebug((dbg_file, "\n"));
 
-    if (want_env)
-      { cptr=uarg3;
+    if (want_env) {
+        cptr = uarg3;
         while (Envc < MAX_ARGS) {
-         ll_word(cptr, cptr2);
-         if (cptr2 == 0)
-           break;
-         buf = (char *)&dspace[cptr2];
-         Envp[Envc++] = strdup(buf);
-         cptr += 2;
+            ll_word(cptr, cptr2);
+            if (cptr2 == 0)
+                break;
+            buf = (char *) &dspace[cptr2];
+            Envp[Envc++] = strdup(buf);
+            cptr += 2;
         }
-       Envp[Envc] = NULL;
-      }
-
-    if (load_a_out(name,origpath,want_env) == -1) {
-       for (Argc--; Argc >= 0; Argc--)
-           free(Argv[Argc]);
-       if (want_env) for (Envc--; Envc >= 0; Envc--)
-           free(Envp[Envc]);
-       errno= ENOENT; return(-1);
+        Envp[Envc] = NULL;
+    }
+
+    if (load_a_out(name, origpath, want_env) == -1) {
+        for (Argc--; Argc >= 0; Argc--)
+            free(Argv[Argc]);
+        if (want_env)
+            for (Envc--; Envc >= 0; Envc--)
+                free(Envp[Envc]);
+        errno = ENOENT;
+        return (-1);
     }
     run();                     /* Ok, so it's recursive, I dislike setjmp */
-    return(0);                 /* Just to shut the compiler up */
+    return (0);                        /* Just to shut the compiler up */
 }
 
 /* 2.11BSD reads directories as if they were ordinary files.
@@ -794,8 +923,7 @@ trap_execve(int want_env)
  * dp->d_ino set to 0.
  */
 
-static int
-bsdopen_dir(char *name)
+static int bsdopen_dir(char *name)
 {
     DIR *d;
     char *tmpname;
@@ -804,46 +932,56 @@ bsdopen_dir(char *name)
     struct tr_direct odent, empty;
 
     d = opendir(name);
-    if (d == NULL) return (-1);
-    tmpname= strdup(TMP_PLATE);
-    i= mkstemp(tmpname);
+    if (d == NULL)
+        return (-1);
+    tmpname = strdup(TMP_PLATE);
+    i = mkstemp(tmpname);
     if (i == -1) {
-       (void)fprintf(stderr,"Apout - open_dir couldn't open %s\n", tmpname);
-       exit(EXIT_FAILURE);
+        (void) fprintf(stderr, "Apout - open_dir couldn't open %s\n",
+                       tmpname);
+        exit(EXIT_FAILURE);
     }
-    unlink(tmpname); free(tmpname);
+    unlink(tmpname);
+    free(tmpname);
 
-    total_left=TR_DIRBLKSIZ;
-    empty.d_ino=0; empty.d_namlen=0; empty.d_name[0]='\0';
-    empty.d_name[1]='\0'; empty.d_name[2]='\0'; empty.d_name[3]='\0';
+    total_left = TR_DIRBLKSIZ;
+    empty.d_ino = 0;
+    empty.d_namlen = 0;
+    empty.d_name[0] = '\0';
+    empty.d_name[1] = '\0';
+    empty.d_name[2] = '\0';
+    empty.d_name[3] = '\0';
 
     while ((dent = readdir(d)) != NULL) {
-       memset(odent.d_name, 0, TR_MAXNAMLEN+1);        /* Null name */
-       nlen= strlen(dent->d_name) +1;                  /* Name length */
-       if (nlen>TR_MAXNAMLEN+1) nlen=TR_MAXNAMLEN+1;
-       strncpy(odent.d_name, dent->d_name, nlen);
-       odent.d_ino = dent->d_fileno;
-                                               /* Nasty hack: ensure inode */
-                                               /* is never 0 */
-       if (odent.d_ino==0) odent.d_ino=1;
-       odent.d_namlen= nlen;
-       nlen+= (nlen & 3);                      /* Round up to mult of 4 */
-       odent.d_reclen=  nlen+6;                /* Name + 3 u_int16_ts */
-
-                                               /* Not enough room, write */
-                                               /* a blank entry */
-       if ( (total_left - odent.d_reclen) < 10) {
-           empty.d_reclen=total_left;
-           write(i, &empty, empty.d_reclen);
-           total_left=TR_DIRBLKSIZ;
-       }
-       write(i, &odent, odent.d_reclen);
-       total_left-= odent.d_reclen;
+        memset(odent.d_name, 0, TR_MAXNAMLEN + 1);     /* Null name */
+        nlen = strlen(dent->d_name) + 1;       /* Name length */
+        if (nlen > TR_MAXNAMLEN + 1)
+            nlen = TR_MAXNAMLEN + 1;
+        strncpy(odent.d_name, dent->d_name, nlen);
+        odent.d_ino = dent->d_fileno;
+        /* Nasty hack: ensure inode */
+        /* is never 0 */
+        if (odent.d_ino == 0)
+            odent.d_ino = 1;
+        odent.d_namlen = nlen;
+        nlen += (nlen & 3);    /* Round up to mult of 4 */
+        odent.d_reclen = nlen + 6;     /* Name + 3 u_int16_ts */
+
+        /* Not enough room, write */
+        /* a blank entry */
+        if ((total_left - odent.d_reclen) < 10) {
+            empty.d_reclen = total_left;
+            write(i, &empty, empty.d_reclen);
+            total_left = TR_DIRBLKSIZ;
+        }
+        write(i, &odent, odent.d_reclen);
+        total_left -= odent.d_reclen;
     }
     closedir(d);
 
     if (total_left) {
-           empty.d_reclen=total_left; write(i, &empty, empty.d_reclen);
+        empty.d_reclen = total_left;
+        write(i, &empty, empty.d_reclen);
     }
     lseek(i, 0, SEEK_SET);
     return (i);
@@ -855,23 +993,35 @@ bsdopen_dir(char *name)
  */
 static int16_t map_fcntl(int16_t f)
 {
-  int16_t out=0;
-
-  if (f & BSD_RDONLY)   out |= O_RDONLY;
-  if (f & BSD_WRONLY)   out |= O_WRONLY;
-  if (f & BSD_RDWR)     out |= O_RDWR;
-  if (f & BSD_NONBLOCK) out |= O_NONBLOCK;
-  if (f & BSD_APPEND)   out |= O_APPEND;
-  if (f & BSD_SHLOCK)   out |= O_SHLOCK;
-  if (f & BSD_EXLOCK)   out |= O_EXLOCK;
-  if (f & BSD_ASYNC)    out |= O_ASYNC;
-  if (f & BSD_FSYNC)    out |= O_FSYNC;
-  if (f & BSD_CREAT)    out |= O_CREAT;
-  if (f & BSD_TRUNC)    out |= O_TRUNC;
-  if (f & BSD_EXCL)     out |= O_EXCL;
-
-  TrapDebug((dbg_file, "map_fcntl: 0x%x -> 0x%x, ",f,out));
-  return(out);
+    int16_t out = 0;
+
+    if (f & BSD_RDONLY)
+        out |= O_RDONLY;
+    if (f & BSD_WRONLY)
+        out |= O_WRONLY;
+    if (f & BSD_RDWR)
+        out |= O_RDWR;
+    if (f & BSD_NONBLOCK)
+        out |= O_NONBLOCK;
+    if (f & BSD_APPEND)
+        out |= O_APPEND;
+    if (f & BSD_SHLOCK)
+        out |= O_SHLOCK;
+    if (f & BSD_EXLOCK)
+        out |= O_EXLOCK;
+    if (f & BSD_ASYNC)
+        out |= O_ASYNC;
+    if (f & BSD_FSYNC)
+        out |= O_FSYNC;
+    if (f & BSD_CREAT)
+        out |= O_CREAT;
+    if (f & BSD_TRUNC)
+        out |= O_TRUNC;
+    if (f & BSD_EXCL)
+        out |= O_EXCL;
+
+    TrapDebug((dbg_file, "map_fcntl: 0x%x -> 0x%x, ", f, out));
+    return (out);
 }
 #endif
-#endif /* EMU211 */
+#endif                         /* EMU211 */
index 3773df5..a16d3bf 100644 (file)
--- a/bsdtrap.h
+++ b/bsdtrap.h
  */
 #ifdef BSDTRAP_NAME
 char *bsdtrap_name[] = {
-       "indir",                /*   0 = indir */
-       "exit",                 /*   1 = exit */
-       "fork",                 /*   2 = fork */
-       "read",                 /*   3 = read */
-       "write",                /*   4 = write */
-       "open",                 /*   5 = open */
-       "close",                /*   6 = close */
-       "wait4",                /*   7 = wait4 */
-       "creat",                /*   8 = creat */
-       "link",                 /*   9 = link */
-       "unlink",               /*  10 = unlink */
-       "execv",                /*  11 = execv */
-       "chdir",                /*  12 = chdir */
-       "fchdir",               /*  13 = fchdir */
-       "mknod",                /*  14 = mknod */
-       "chmod",                /*  15 = chmod */
-       "chown",                /*  16 = chown; now 3 args */
-       "chflags",              /*  17 = chflags */
-       "fchflags",             /*  18 = fchflags */
-       "lseek",                /*  19 = lseek */
-       "getpid",               /*  20 = getpid */
-       "mount",                /*  21 = mount */
-       "umount",               /*  22 = umount */
-       "__sysctl",             /*  23 = __sysctl */
-       "getuid",               /*  24 = getuid */
-       "geteuid",              /*  25 = geteuid */
-       "ptrace",               /*  26 = ptrace */
-       "getppid",              /*  27 = getppid */
-       "statfs",               /*  28 = statfs */
-       "fstatfs",              /*  29 = fstatfs */
-       "getfsstat",            /*  30 = getfsstat */
-       "sigaction",            /*  31 = sigaction */
-       "sigprocmask",          /*  32 = sigprocmask */
-       "access",               /*  33 = access */
-       "sigpending",           /*  34 = sigpending */
-       "sigaltstack",          /*  35 = sigaltstack */
-       "sync",                 /*  36 = sync */
-       "kill",                 /*  37 = kill */
-       "stat",                 /*  38 = stat */
-       "getlogin",             /*  39 = getlogin */
-       "lstat",                /*  40 = lstat */
-       "dup",                  /*  41 = dup */
-       "pipe",                 /*  42 = pipe */
-       "setlogin",             /*  43 = setlogin */
-       "profil",               /*  44 = profil */
-       "setuid",               /*  45 = setuid */
-       "seteuid",              /*  46 = seteuid */
-       "getgid",               /*  47 = getgid */
-       "getegid",              /*  48 = getegid */
-       "setgid",               /*  49 = setgid */
-       "setegid",              /*  50 = setegid */
-       "acct",                 /*  51 = turn acct off/on */
-       "old phys",             /*  52 = old set phys addr */
-       "old lock",             /*  53 = old lock in core */
-       "ioctl",                /*  54 = ioctl */
-       "reboot",               /*  55 = reboot */
-       "old mpx - nosys",      /*  56 = old mpxchan */
-       "symlink",              /*  57 = symlink */
-       "readlink",             /*  58 = readlink */
-       "execve",               /*  59 = execve */
-       "umask",                /*  60 = umask */
-       "chroot",               /*  61 = chroot */
-       "fstat",                /*  62 = fstat */
-       "#63",                  /*  63 = used internally */
-       "getpagesize",          /*  64 = getpagesize */
-       "4.3 mremap - nosys",   /*  65 = mremap */
-       "vfork",                /*  66 = vfork */
-       "old vread - nosys",    /*  67 = old vread */
-       "old vwrite - nosys",   /*  68 = old vwrite */
-       "sbrk",                 /*  69 = sbrk */
-       "4.3 sstk - nosys",     /*  70 = sstk */
-       "4.3 mmap - nosys",     /*  71 = mmap */
-       "old vadvise - nosys",  /*  72 = old vadvise */
-       "4.3 munmap - nosys",   /*  73 = munmap */
-       "4.3 mprotect - nosys", /*  74 = mprotect */
-       "4.3 madvise - nosys",  /*  75 = madvise */
-       "vhangup",              /*  76 = vhangup */
-       "old vlimit - nosys",   /*  77 = old vlimit */
-       "4.3 mincore - nosys",  /*  78 = mincore */
-       "getgroups",            /*  79 = getgroups */
-       "setgroups",            /*  80 = setgroups */
-       "getpgrp",              /*  81 = getpgrp */
-       "setpgrp",              /*  82 = setpgrp */
-       "setitimer",            /*  83 = setitimer */
-       "wait",                 /*  84 = wait */
-       "4.3 swapon - nosys",   /*  85 = swapon */
-       "getitimer",            /*  86 = getitimer */
-       "gethostname",          /*  87 = gethostname */
-       "sethostname",          /*  88 = sethostname */
-       "getdtablesize",        /*  89 = getdtablesize */
-       "dup2",                 /*  90 = dup2 */
-       "nosys",                /*  91 = unused */
-       "fcntl",                /*  92 = fcntl */
-       "select",               /*  93 = select */
-       "nosys",                /*  94 = unused */
-       "fsync",                /*  95 = fsync */
-       "setpriority",          /*  96 = setpriority */
-       "socket",               /*  97 = socket */
-       "connect",              /*  98 = connect */
-       "accept",               /*  99 = accept */
-       "getpriority",          /* 100 = getpriority */
-       "send",                 /* 101 = send */
-       "recv",                 /* 102 = recv */
-       "sigreturn",            /* 103 = sigreturn */
-       "bind",                 /* 104 = bind */
-       "setsockopt",           /* 105 = setsockopt */
-       "listen",               /* 106 = listen */
-       "sigsuspend",           /* 107 = sigsuspend */
-       "sigvec",               /* 108 = sigvec */
-       "sigblock",             /* 109 = sigblock */
-       "sigsetmask",           /* 110 = sigsetmask */
-       "sigpause",             /* 111 = sigpause */
-       "sigstack",             /* 112 = sigstack */
-       "recvmsg",              /* 113 = recvmsg */
-       "sendmsg",              /* 114 = sendmsg */
-       "old vtrace - nosys",   /* 115 = old vtrace */
-       "gettimeofday",         /* 116 = gettimeofday */
-       "getrusage",            /* 117 = getrusage */
-       "getsockopt",           /* 118 = getsockopt */
-       "4.3 resuba - nosys",   /* 119 = resuba */
-       "readv",                /* 120 = readv */
-       "writev",               /* 121 = writev */
-       "settimeofday",         /* 122 = settimeofday */
-       "fchown",               /* 123 = fchown */
-       "fchmod",               /* 124 = fchmod */
-       "recvfrom",             /* 125 = recvfrom */
-       "setreuid",             /* 126 = setreuid */
-       "setregid",             /* 127 = setregid */
-       "rename",               /* 128 = rename */
-       "truncate",             /* 129 = truncate */
-       "ftruncate",            /* 130 = ftruncate */
-       "flock",                /* 131 = flock */
-       "old portal - nosys",   /* 132 = old portal */
-       "sendto",               /* 133 = sendto */
-       "shutdown",             /* 134 = shutdown */
-       "socketpair",           /* 135 = socketpair */
-       "mkdir",                /* 136 = mkdir */
-       "rmdir",                /* 137 = rmdir */
-       "utimes",               /* 138 = utimes */
-       "4.2 sigreturn - nosys",        /* 139 = old 4.2 sigreturn */
-       "adjtime",              /* 140 = adjtime */
-       "getpeername",          /* 141 = getpeername */
-       "gethostid",            /* 142 = gethostid */
-       "sethostid",            /* 143 = sethostid */
-       "getrlimit",            /* 144 = getrlimit */
-       "setrlimit",            /* 145 = setrlimit */
-       "killpg",               /* 146 = killpg */
-       "#147",                 /* 147 = nosys */
-       "setquota",             /* 148 = setquota */
-       "quota",                /* 149 = quota */
-       "getsockname",          /* 150 = getsockname */
+    "indir",                   /*   0 = indir */
+    "exit",                    /*   1 = exit */
+    "fork",                    /*   2 = fork */
+    "read",                    /*   3 = read */
+    "write",                   /*   4 = write */
+    "open",                    /*   5 = open */
+    "close",                   /*   6 = close */
+    "wait4",                   /*   7 = wait4 */
+    "creat",                   /*   8 = creat */
+    "link",                    /*   9 = link */
+    "unlink",                  /*  10 = unlink */
+    "execv",                   /*  11 = execv */
+    "chdir",                   /*  12 = chdir */
+    "fchdir",                  /*  13 = fchdir */
+    "mknod",                   /*  14 = mknod */
+    "chmod",                   /*  15 = chmod */
+    "chown",                   /*  16 = chown; now 3 args */
+    "chflags",                 /*  17 = chflags */
+    "fchflags",                        /*  18 = fchflags */
+    "lseek",                   /*  19 = lseek */
+    "getpid",                  /*  20 = getpid */
+    "mount",                   /*  21 = mount */
+    "umount",                  /*  22 = umount */
+    "__sysctl",                        /*  23 = __sysctl */
+    "getuid",                  /*  24 = getuid */
+    "geteuid",                 /*  25 = geteuid */
+    "ptrace",                  /*  26 = ptrace */
+    "getppid",                 /*  27 = getppid */
+    "statfs",                  /*  28 = statfs */
+    "fstatfs",                 /*  29 = fstatfs */
+    "getfsstat",               /*  30 = getfsstat */
+    "sigaction",               /*  31 = sigaction */
+    "sigprocmask",             /*  32 = sigprocmask */
+    "access",                  /*  33 = access */
+    "sigpending",              /*  34 = sigpending */
+    "sigaltstack",             /*  35 = sigaltstack */
+    "sync",                    /*  36 = sync */
+    "kill",                    /*  37 = kill */
+    "stat",                    /*  38 = stat */
+    "getlogin",                        /*  39 = getlogin */
+    "lstat",                   /*  40 = lstat */
+    "dup",                     /*  41 = dup */
+    "pipe",                    /*  42 = pipe */
+    "setlogin",                        /*  43 = setlogin */
+    "profil",                  /*  44 = profil */
+    "setuid",                  /*  45 = setuid */
+    "seteuid",                 /*  46 = seteuid */
+    "getgid",                  /*  47 = getgid */
+    "getegid",                 /*  48 = getegid */
+    "setgid",                  /*  49 = setgid */
+    "setegid",                 /*  50 = setegid */
+    "acct",                    /*  51 = turn acct off/on */
+    "old phys",                        /*  52 = old set phys addr */
+    "old lock",                        /*  53 = old lock in core */
+    "ioctl",                   /*  54 = ioctl */
+    "reboot",                  /*  55 = reboot */
+    "old mpx - nosys",         /*  56 = old mpxchan */
+    "symlink",                 /*  57 = symlink */
+    "readlink",                        /*  58 = readlink */
+    "execve",                  /*  59 = execve */
+    "umask",                   /*  60 = umask */
+    "chroot",                  /*  61 = chroot */
+    "fstat",                   /*  62 = fstat */
+    "#63",                     /*  63 = used internally */
+    "getpagesize",             /*  64 = getpagesize */
+    "4.3 mremap - nosys",      /*  65 = mremap */
+    "vfork",                   /*  66 = vfork */
+    "old vread - nosys",       /*  67 = old vread */
+    "old vwrite - nosys",      /*  68 = old vwrite */
+    "sbrk",                    /*  69 = sbrk */
+    "4.3 sstk - nosys",                /*  70 = sstk */
+    "4.3 mmap - nosys",                /*  71 = mmap */
+    "old vadvise - nosys",     /*  72 = old vadvise */
+    "4.3 munmap - nosys",      /*  73 = munmap */
+    "4.3 mprotect - nosys",    /*  74 = mprotect */
+    "4.3 madvise - nosys",     /*  75 = madvise */
+    "vhangup",                 /*  76 = vhangup */
+    "old vlimit - nosys",      /*  77 = old vlimit */
+    "4.3 mincore - nosys",     /*  78 = mincore */
+    "getgroups",               /*  79 = getgroups */
+    "setgroups",               /*  80 = setgroups */
+    "getpgrp",                 /*  81 = getpgrp */
+    "setpgrp",                 /*  82 = setpgrp */
+    "setitimer",               /*  83 = setitimer */
+    "wait",                    /*  84 = wait */
+    "4.3 swapon - nosys",      /*  85 = swapon */
+    "getitimer",               /*  86 = getitimer */
+    "gethostname",             /*  87 = gethostname */
+    "sethostname",             /*  88 = sethostname */
+    "getdtablesize",           /*  89 = getdtablesize */
+    "dup2",                    /*  90 = dup2 */
+    "nosys",                   /*  91 = unused */
+    "fcntl",                   /*  92 = fcntl */
+    "select",                  /*  93 = select */
+    "nosys",                   /*  94 = unused */
+    "fsync",                   /*  95 = fsync */
+    "setpriority",             /*  96 = setpriority */
+    "socket",                  /*  97 = socket */
+    "connect",                 /*  98 = connect */
+    "accept",                  /*  99 = accept */
+    "getpriority",             /* 100 = getpriority */
+    "send",                    /* 101 = send */
+    "recv",                    /* 102 = recv */
+    "sigreturn",               /* 103 = sigreturn */
+    "bind",                    /* 104 = bind */
+    "setsockopt",              /* 105 = setsockopt */
+    "listen",                  /* 106 = listen */
+    "sigsuspend",              /* 107 = sigsuspend */
+    "sigvec",                  /* 108 = sigvec */
+    "sigblock",                        /* 109 = sigblock */
+    "sigsetmask",              /* 110 = sigsetmask */
+    "sigpause",                        /* 111 = sigpause */
+    "sigstack",                        /* 112 = sigstack */
+    "recvmsg",                 /* 113 = recvmsg */
+    "sendmsg",                 /* 114 = sendmsg */
+    "old vtrace - nosys",      /* 115 = old vtrace */
+    "gettimeofday",            /* 116 = gettimeofday */
+    "getrusage",               /* 117 = getrusage */
+    "getsockopt",              /* 118 = getsockopt */
+    "4.3 resuba - nosys",      /* 119 = resuba */
+    "readv",                   /* 120 = readv */
+    "writev",                  /* 121 = writev */
+    "settimeofday",            /* 122 = settimeofday */
+    "fchown",                  /* 123 = fchown */
+    "fchmod",                  /* 124 = fchmod */
+    "recvfrom",                        /* 125 = recvfrom */
+    "setreuid",                        /* 126 = setreuid */
+    "setregid",                        /* 127 = setregid */
+    "rename",                  /* 128 = rename */
+    "truncate",                        /* 129 = truncate */
+    "ftruncate",               /* 130 = ftruncate */
+    "flock",                   /* 131 = flock */
+    "old portal - nosys",      /* 132 = old portal */
+    "sendto",                  /* 133 = sendto */
+    "shutdown",                        /* 134 = shutdown */
+    "socketpair",              /* 135 = socketpair */
+    "mkdir",                   /* 136 = mkdir */
+    "rmdir",                   /* 137 = rmdir */
+    "utimes",                  /* 138 = utimes */
+    "4.2 sigreturn - nosys",   /* 139 = old 4.2 sigreturn */
+    "adjtime",                 /* 140 = adjtime */
+    "getpeername",             /* 141 = getpeername */
+    "gethostid",               /* 142 = gethostid */
+    "sethostid",               /* 143 = sethostid */
+    "getrlimit",               /* 144 = getrlimit */
+    "setrlimit",               /* 145 = setrlimit */
+    "killpg",                  /* 146 = killpg */
+    "#147",                    /* 147 = nosys */
+    "setquota",                        /* 148 = setquota */
+    "quota",                   /* 149 = quota */
+    "getsockname",             /* 150 = getsockname */
 };
 #endif
 
 /* fcntl defines used by open */
-#define BSD_RDONLY        0x0000          /* open for reading only */
-#define BSD_WRONLY        0x0001          /* open for writing only */
-#define BSD_RDWR          0x0002          /* open for reading and writing */
-#define BSD_NONBLOCK      0x0004          /* no delay */
-#define BSD_APPEND        0x0008          /* set append mode */
-#define BSD_SHLOCK        0x0010          /* open with shared file lock */
-#define BSD_EXLOCK        0x0020          /* open with exclusive file lock */
-#define BSD_ASYNC         0x0040          /* signal pgrp when data ready */
-#define BSD_FSYNC         0x0080          /* synchronous writes */
-#define BSD_CREAT         0x0200          /* create if nonexistant */
-#define BSD_TRUNC         0x0400          /* truncate to zero length */
-#define BSD_EXCL          0x0800          /* error if already exists */
+#define BSD_RDONLY        0x0000       /* open for reading only */
+#define BSD_WRONLY        0x0001       /* open for writing only */
+#define BSD_RDWR          0x0002       /* open for reading and writing */
+#define BSD_NONBLOCK      0x0004       /* no delay */
+#define BSD_APPEND        0x0008       /* set append mode */
+#define BSD_SHLOCK        0x0010       /* open with shared file lock */
+#define BSD_EXLOCK        0x0020       /* open with exclusive file lock */
+#define BSD_ASYNC         0x0040       /* signal pgrp when data ready */
+#define BSD_FSYNC         0x0080       /* synchronous writes */
+#define BSD_CREAT         0x0200       /* create if nonexistant */
+#define BSD_TRUNC         0x0400       /* truncate to zero length */
+#define BSD_EXCL          0x0800       /* error if already exists */
 
 
 /* stat struct, used by S_STAT, S_FSTAT, S_LSTAT */
-struct tr_stat
-{
-       int16_t    st_dev;
-       u_int16_t   st_ino;
-       u_int16_t   st_mode;
-       int16_t    st_nlink;
-       u_int16_t   st_uid;
-       u_int16_t   st_gid;
-       int16_t    st_rdev;
-       int8_t     st_size[4];          /* Alignment problems */
-       int8_t     st_atim[4];          /* Alignment problems */
-       int16_t    st_spare1;
-       int8_t     st_mtim[4];          /* Alignment problems */
-       int16_t    st_spare2;
-       int8_t     st_ctim[4];          /* Alignment problems */
-       int16_t    st_spare3;
-       int8_t     st_blksize[4];       /* Alignment problems */
-       int8_t     st_blocks[4];        /* Alignment problems */
-       u_int16_t   st_flags;
-       u_int16_t   st_spare4[3];
+struct tr_stat {
+    int16_t st_dev;
+    u_int16_t st_ino;
+    u_int16_t st_mode;
+    int16_t st_nlink;
+    u_int16_t st_uid;
+    u_int16_t st_gid;
+    int16_t st_rdev;
+    int8_t st_size[4];         /* Alignment problems */
+    int8_t st_atim[4];         /* Alignment problems */
+    int16_t st_spare1;
+    int8_t st_mtim[4];         /* Alignment problems */
+    int16_t st_spare2;
+    int8_t st_ctim[4];         /* Alignment problems */
+    int16_t st_spare3;
+    int8_t st_blksize[4];      /* Alignment problems */
+    int8_t st_blocks[4];       /* Alignment problems */
+    u_int16_t st_flags;
+    u_int16_t st_spare4[3];
 };
 
 /* Directory entry */
 #define TR_DIRBLKSIZ   512
 #define TR_MAXNAMLEN   63
-struct tr_direct {
-    u_int16_t d_ino;                   /* inode number of entry */
-    u_int16_t d_reclen;                        /* length of this record */
-    u_int16_t d_namlen;                        /* length of string in d_name */
-    char d_name[TR_MAXNAMLEN+1];       /* name must be no longer than this */
+struct tr_direct {
+    u_int16_t d_ino;           /* inode number of entry */
+    u_int16_t d_reclen;                /* length of this record */
+    u_int16_t d_namlen;                /* length of string in d_name */
+    char d_name[TR_MAXNAMLEN + 1];     /* name must be no longer than this */
 };
 
 /* used by S_ADJTIME */
 struct tr_timeval {
-    u_int32_t    tv_sec;           /* seconds */
-    u_int32_t    tv_usec;          /* and microseconds */
+    u_int32_t tv_sec;          /* seconds */
+    u_int32_t tv_usec;         /* and microseconds */
 };
 /* Used by S_GETTIMEOFDAY */
 struct tr_timezone {
-    int16_t        tz_minuteswest; /* minutes west of Greenwich */
-    int16_t        tz_dsttime;     /* type of dst correction */
+    int16_t tz_minuteswest;    /* minutes west of Greenwich */
+    int16_t tz_dsttime;                /* type of dst correction */
 };
 
 /* used in itimer calls */
-struct tr_itimerval {
-    struct     tr_timeval it_interval;    /* timer interval */
-    struct     tr_timeval it_value;       /* current value */
+struct tr_itimerval {
+    struct tr_timeval it_interval;     /* timer interval */
+    struct tr_timeval it_value;        /* current value */
 };
 
 /* Used by socket calls */
 struct tr_sockaddr {
-    u_int16_t sa_family;               /* address family */
-    char        sa_data[14];           /* up to 14 bytes of direct address */
+    u_int16_t sa_family;       /* address family */
+    char sa_data[14];          /* up to 14 bytes of direct address */
 };
 
 /* used in rlimit calls */
@@ -380,30 +379,30 @@ struct tr_rlimit {
     int32_t rlim_max;          /* maximum value for rlim_cur */
 };
 
-struct  tr_rusage {
-        struct tr_timeval ru_utime;        /* user time used */
-        struct tr_timeval ru_stime;        /* system time used */
-        u_int32_t  ru_maxrss;
-        u_int32_t  ru_ixrss;               /* integral shared memory size */
-        u_int32_t  ru_idrss;               /* integral unshared data size */
-        u_int32_t  ru_isrss;               /* integral unshared stack size */
-        u_int32_t  ru_minflt;              /* page reclaims */
-        u_int32_t  ru_majflt;              /* page faults */
-        u_int32_t  ru_ovly;                /* overlay changes */
-        u_int32_t  ru_nswap;               /* swaps */
-        u_int32_t  ru_inblock;             /* block input operations */
-        u_int32_t  ru_oublock;             /* block output operations */
-        u_int32_t  ru_msgsnd;              /* messages sent */
-        u_int32_t  ru_msgrcv;              /* messages received */
-        u_int32_t  ru_nsignals;            /* signals received */
-        u_int32_t  ru_nvcsw;               /* voluntary context switches */
-        u_int32_t  ru_nivcsw;              /* involuntary context switches */
+struct tr_rusage {
+    struct tr_timeval ru_utime;        /* user time used */
+    struct tr_timeval ru_stime;        /* system time used */
+    u_int32_t ru_maxrss;
+    u_int32_t ru_ixrss;                /* integral shared memory size */
+    u_int32_t ru_idrss;                /* integral unshared data size */
+    u_int32_t ru_isrss;                /* integral unshared stack size */
+    u_int32_t ru_minflt;       /* page reclaims */
+    u_int32_t ru_majflt;       /* page faults */
+    u_int32_t ru_ovly;         /* overlay changes */
+    u_int32_t ru_nswap;                /* swaps */
+    u_int32_t ru_inblock;      /* block input operations */
+    u_int32_t ru_oublock;      /* block output operations */
+    u_int32_t ru_msgsnd;       /* messages sent */
+    u_int32_t ru_msgrcv;       /* messages received */
+    u_int32_t ru_nsignals;     /* signals received */
+    u_int32_t ru_nvcsw;                /* voluntary context switches */
+    u_int32_t ru_nivcsw;       /* involuntary context switches */
 };
 
 /* for writev, readv */
 struct tr_iovec {
-    u_int16_t   iov_base;
-    u_int16_t   iov_len;
+    u_int16_t iov_base;
+    u_int16_t iov_len;
 };
 
 
@@ -411,8 +410,8 @@ struct tr_iovec {
  * we can get at the various args of different types
  */
 typedef union {
-    int16_t   sarg[6]; /* Signed 16-bit args */
-    u_int16_t uarg[6]; /* Unsigned 16-bit args */
+    int16_t sarg[6];           /* Signed 16-bit args */
+    u_int16_t uarg[6];         /* Unsigned 16-bit args */
 } arglist;
 
 #define sarg1  A->sarg[0]
diff --git a/cpu.c b/cpu.c
index 45784e8..cefb0e2 100644 (file)
--- a/cpu.c
+++ b/cpu.c
@@ -8,17 +8,17 @@
 #include <unistd.h>
 
 u_int8_t *ispace, *dspace;     /* Instruction and Data spaces */
-u_int16_t dwrite_base=2;       /* Lowest addr where dspace writes can occur */
+u_int16_t dwrite_base = 2;     /* Lowest addr where dspace writes can occur */
 
 u_int16_t regs[8];             /* general registers */
 u_int16_t ir;                  /* current instruction register */
 u_int16_t *adptr;              /* used in memory access macros */
 u_int16_t ea_addr;             /* stored address for dest modifying insts */
 
-int CC_N=0;                    /* The processor status word is represented */
-int CC_Z=0;                    /* by these four values. On some */
-int CC_V=0;                    /* architectures, you may get a performance */
-int CC_C=0;                    /* increase by using shorts or bytes */
+int CC_N = 0;                  /* The processor status word is represented */
+int CC_Z = 0;                  /* by these four values. On some */
+int CC_V = 0;                  /* architectures, you may get a performance */
+int CC_C = 0;                  /* increase by using shorts or bytes */
 
 u_int16_t dstword;             /* These globals are used in the effective */
 u_int16_t srcword;             /* address calculations, mainly to save */
@@ -26,9 +26,9 @@ u_int16_t tmpword;            /* parameter passing overheads in */
 u_int8_t dstbyte;              /* function calls */
 u_int8_t srcbyte;
 u_int8_t tmpbyte;
-struct our_siglist *Sighead=NULL;      /* List of pending signals */
-struct our_siglist *Sigtail=NULL;      /* List of pending signals */
-void (*sigrunner)(void)= NULL;                 /* F'n that will run the signal */
+struct our_siglist *Sighead = NULL;    /* List of pending signals */
+struct our_siglist *Sigtail = NULL;    /* List of pending signals */
+void (*sigrunner) (void) = NULL;       /* F'n that will run the signal */
 
 #ifdef DEBUG
 extern char *iname[1024];
@@ -39,156 +39,237 @@ char *name;
 
 
 /* Run until told to stop. */
-void run() {
+void run()
+{
 #ifdef DEBUG
     int i;
 
     if (trap_debug) {
-       TrapDebug((dbg_file, "Just starting to run pid %d\n",(int)getpid()));
-       TrapDebug((dbg_file, "Regs are           "));
-       for (i=0;i<=PC;i++) TrapDebug((dbg_file, "%06o ",regs[i]));
-       TrapDebug((dbg_file, "\n"));
+        TrapDebug((dbg_file, "Just starting to run pid %d\n",
+                   (int) getpid()));
+        TrapDebug((dbg_file, "Regs are           "));
+        for (i = 0; i <= PC; i++)
+            TrapDebug((dbg_file, "%06o ", regs[i]));
+        TrapDebug((dbg_file, "\n"));
     }
 #endif
 
     while (1) {
 
-       /* Fetch and execute the instruction. */
+        /* Fetch and execute the instruction. */
 
 #ifdef DEBUG
-       lli_word(regs[PC], ir);
-       if (inst_debug) {
-          i= ir >> 6;
-          switch (i) {
-               case 0: name= iname0[ir & 077]; break;
-               case 2: name= iname1[ir & 077]; break;
-               default: name= iname[i];
-          }
-          TrapDebug((dbg_file, "%06o %06o %4s ", regs[7], ir, name));
-          TrapDebug((dbg_file, "%06o %06o %06o %06o %06o %06o %06o   ",
-               regs[0], regs[1], regs[2], regs[3],
-               regs[4], regs[5], regs[6]));
-          TrapDebug((dbg_file, "NZVC1 %d%d%d%d\n",CC_N,CC_Z,CC_V,CC_C));
-          fflush(dbg_file);
-       }
-       regs[PC] += 2; itab[ir >> 6] ();
-       if ((Sighead!=NULL) && (sigrunner!=NULL)) (void) (*sigrunner)();
+        lli_word(regs[PC], ir);
+        if (inst_debug) {
+            i = ir >> 6;
+            switch (i) {
+            case 0:
+                name = iname0[ir & 077];
+                break;
+            case 2:
+                name = iname1[ir & 077];
+                break;
+            default:
+                name = iname[i];
+            }
+            TrapDebug((dbg_file, "%06o %06o %4s ", regs[7], ir, name));
+            TrapDebug((dbg_file, "%06o %06o %06o %06o %06o %06o %06o   ",
+                       regs[0], regs[1], regs[2], regs[3],
+                       regs[4], regs[5], regs[6]));
+            TrapDebug((dbg_file, "NZVC1 %d%d%d%d\n", CC_N, CC_Z, CC_V,
+                       CC_C));
+            fflush(dbg_file);
+        }
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        if ((Sighead != NULL) && (sigrunner != NULL))
+            (void) (*sigrunner) ();
 #else
-       /* When not debugging, we can manually unroll this inner loop */
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       lli_word(regs[PC], ir); regs[PC] += 2; itab[ir >> 6] ();
-       if ((Sighead!=NULL) && (sigrunner!=NULL)) (void) (*sigrunner)();
+        /* When not debugging, we can manually unroll this inner loop */
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        lli_word(regs[PC], ir);
+        regs[PC] += 2;
+        itab[ir >> 6] ();
+        if ((Sighead != NULL) && (sigrunner != NULL))
+            (void) (*sigrunner) ();
 #endif
     }
 }
 
 /* sim_init() - Initialize the cpu registers. */
-void sim_init() {
+void sim_init()
+{
     int x;
 
-    for (x = 0; x < 8; ++x) { regs[x] = 0; }
-    ir = 0; CLR_CC_ALL();
+    for (x = 0; x < 8; ++x) {
+        regs[x] = 0;
+    }
+    ir = 0;
+    CLR_CC_ALL();
 }
 
 void bus_error(int signo)
 {
     TrapDebug((dbg_file, "Apout - pid %d bus error at PC 0%06o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     TrapDebug((dbg_file, "%06o  ", ir));
     TrapDebug((dbg_file, "%o %o %o %o %o %o %o %o  ",
-        regs[0], regs[1], regs[2], regs[3],
-        regs[4], regs[5], regs[6], regs[7]));
-    TrapDebug((dbg_file, "NZVC2 are %d%d%d%d\n",CC_N,CC_Z,CC_V,CC_C));
+               regs[0], regs[1], regs[2], regs[3],
+               regs[4], regs[5], regs[6], regs[7]));
+    TrapDebug((dbg_file, "NZVC2 are %d%d%d%d\n", CC_N, CC_Z, CC_V, CC_C));
     exit(EXIT_FAILURE);
 }
 
-void seg_fault() {
+void seg_fault()
+{
     TrapDebug((dbg_file, "Apout - pid %d segmentation fault at PC 0%06o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     TrapDebug((dbg_file, "%06o  ", ir));
     TrapDebug((dbg_file, "%o %o %o %o %o %o %o %o  ",
-        regs[0], regs[1], regs[2], regs[3],
-        regs[4], regs[5], regs[6], regs[7]));
-    TrapDebug((dbg_file, "NZVC3 are %d%d%d%d\n",CC_N,CC_Z,CC_V,CC_C));
+               regs[0], regs[1], regs[2], regs[3],
+               regs[4], regs[5], regs[6], regs[7]));
+    TrapDebug((dbg_file, "NZVC3 are %d%d%d%d\n", CC_N, CC_Z, CC_V, CC_C));
     exit(EXIT_FAILURE);
 }
 
-void waiti() {
+void waiti()
+{
     TrapDebug((stderr, "Apout - pid %d waiti instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void halt() {
+
+void halt()
+{
     TrapDebug((stderr, "Apout - pid %d halt instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void iot() {
+
+void iot()
+{
     TrapDebug((stderr, "Apout - pid %d iot instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void emt() {
+
+void emt()
+{
     TrapDebug((stderr, "Apout - pid %d emt instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void bpt() {
+
+void bpt()
+{
     TrapDebug((stderr, "Apout - pid %d bpt instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void illegal() {
+
+void illegal()
+{
     TrapDebug((stderr, "Apout - pid %d illegal instruction %o at PC 0%o\n",
-                                       (int)getpid(),ir, regs[PC]));
+               (int) getpid(), ir, regs[PC]));
     exit(EXIT_FAILURE);
 }
-void not_impl() {
-    TrapDebug((stderr, "Apout - pid %d unimplemented instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+
+void not_impl()
+{
+    TrapDebug((stderr,
+               "Apout - pid %d unimplemented instruction at PC 0%o\n",
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void mark() {
+
+void mark()
+{
     TrapDebug((stderr, "Apout - pid %d mark instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void mfpd() {
+
+void mfpd()
+{
     TrapDebug((stderr, "Apout - pid %d mfpd instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void mtpd() {
+
+void mtpd()
+{
     TrapDebug((stderr, "Apout - pid %d mtpd instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void trap() {
+
+void trap()
+{
     TrapDebug((stderr, "Apout - pid %d trap instruction at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
-void bad_FP_reg() {
+
+void bad_FP_reg()
+{
     TrapDebug((stderr, "Apout - pid %d bad FP register used at PC 0%o\n",
-                                       (int)getpid(), regs[PC]));
+               (int) getpid(), regs[PC]));
     exit(EXIT_FAILURE);
 }
 
@@ -197,14 +278,20 @@ void bad_FP_reg() {
  */
 void sigcatcher(int sig)
 {
- struct our_siglist *this;
   struct our_siglist *this;
 
- this= (struct our_siglist *)malloc(sizeof(struct our_siglist));
- if (this==NULL) return;
+    this = (struct our_siglist *) malloc(sizeof(struct our_siglist));
+    if (this == NULL)
+        return;
 
TrapDebug((dbg_file, "Caught signal %d\n",sig));
   TrapDebug((dbg_file, "Caught signal %d\n", sig));
 
- this->sig=sig; this->next=NULL;
- if (Sighead==NULL) { Sighead=Sigtail=this; }
- else { Sigtail->next= this; Sigtail=this; }
+    this->sig = sig;
+    this->next = NULL;
+    if (Sighead == NULL) {
+        Sighead = Sigtail = this;
+    } else {
+        Sigtail->next = this;
+        Sigtail = this;
+    }
 }
diff --git a/debug.c b/debug.c
index feb081d..19743b2 100644 (file)
--- a/debug.c
+++ b/debug.c
  */
 #ifdef DEBUG
 char *iname0[64] = {
-    "halt","waiti","illegal","bpt","iot","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal"
+    "halt", "waiti", "illegal", "bpt", "iot", "illegal", "illegal",
+    "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal"
 };
 
 char *iname1[64] = {
-    "rts","rts","rts","rts","rts","rts","rts","rts",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-    "ccc","ccc","ccc","ccc","ccc","ccc","ccc","ccc",
-    "ccc","ccc","ccc","ccc","ccc","ccc","ccc","ccc",
-    "scc","scc","scc","scc","scc","scc","scc","scc",
-    "scc","scc","scc","scc","scc","scc","scc","scc"
+    "rts", "rts", "rts", "rts", "rts", "rts", "rts", "rts",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "ccc", "ccc", "ccc", "ccc", "ccc", "ccc", "ccc", "ccc",
+    "ccc", "ccc", "ccc", "ccc", "ccc", "ccc", "ccc", "ccc",
+    "scc", "scc", "scc", "scc", "scc", "scc", "scc", "scc",
+    "scc", "scc", "scc", "scc", "scc", "scc", "scc", "scc"
 };
 
 char *iname[1024] = {
-    "dositab0","jmp","dositab1","swabi","br","br","br","br",
-    "bne","bne","bne","bne","beq","beq","beq","beq",
-    "bge","bge","bge","bge","blt","blt","blt","blt",
-    "bgt","bgt","bgt","bgt","ble","ble","ble","ble",
-    "jsr","jsr","jsr","jsr","jsr","jsr","jsr","jsr",
-    "clr","com","inc","dec","neg","adc","sbc","tst",
-    "ror","rol","asr","asl","mark","mfpi","mtpi","sxt",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "mov","mov","mov","mov","mov","mov","mov","mov",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "cmp","cmp","cmp","cmp","cmp","cmp","cmp","cmp",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bit","bit","bit","bit","bit","bit","bit","bit",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bic","bic","bic","bic","bic","bic","bic","bic",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "bis","bis","bis","bis","bis","bis","bis","bis",
-    "add","add","add","add","add","add","add","add",
-    "add","add","add","add","add","add","add","add",
-    "add","add","add","add","add","add","add","add",
-    "add","add","add","add","add","add","add","add",
-    "add","add","add","add","add","add","add","add",
-    "add","add","add","add","add","add","add","add",
-    "add","add","add","add","add","add","add","add",
-    "add","add","add","add","add","add","add","add",
-    "mul","mul","mul","mul","mul","mul","mul","mul",
-    "divide","divide","divide","divide","divide","divide","divide","divide",
-    "ash","ash","ash","ash","ash","ash","ash","ash",
-    "ashc","ashc","ashc","ashc","ashc","ashc","ashc","ashc",
-    "xor","xor","xor","xor","xor","xor","xor","xor",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-    "sob","sob","sob","sob","sob","sob","sob","sob",
-    "bpl","bpl","bpl","bpl","bmi","bmi","bmi","bmi",
-    "bhi","bhi","bhi","bhi","blos","blos","blos","blos",
-    "bvc","bvc","bvc","bvc","bvs","bvs","bvs","bvs",
-    "bcc","bcc","bcc","bcc","bcs","bcs","bcs","bcs",
-    "emt","emt","emt","emt","trap","trap","trap","trap",
-    "clrb","comb","incb","decb","negb","adcb","sbcb","tstb",
-    "rorb","rolb","asrb","aslb","mtps","mfpd","mtpd","mfps",
-"illegal","illegal","illegal","illegal","illegal","illegal","illegal","illegal",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "movb","movb","movb","movb","movb","movb","movb","movb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb","cmpb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bitb","bitb","bitb","bitb","bitb","bitb","bitb","bitb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bicb","bicb","bicb","bicb","bicb","bicb","bicb","bicb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "bisb","bisb","bisb","bisb","bisb","bisb","bisb","bisb",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "sub","sub","sub","sub","sub","sub","sub","sub",
-    "fpset","ldfps","stfps","stst","clrf","tstf","absf","negf",
-    "mulf","mulf","mulf","mulf","moddf","moddf","moddf","moddf",
-    "addf","addf","addf","addf","ldf","ldf","ldf","ldf",
-    "subf","subf","subf","subf","cmpf","cmpf","cmpf","cmpf",
-    "stf","stf","stf","stf","divf","divf","divf","divf",
-    "stexp","stexp","stexp","stexp","stcfi","stcfi","stcfi","stcfi",
-    "stcdf","stcdf","stcdf","stcdf","ldexpp","ldexpp","ldexpp","ldexpp",
-    "lcdif","lcdif","lcdif","lcdif","ldcdf","ldcdf","ldcdf","ldcdf"
+    "dositab0", "jmp", "dositab1", "swabi", "br", "br", "br", "br",
+    "bne", "bne", "bne", "bne", "beq", "beq", "beq", "beq",
+    "bge", "bge", "bge", "bge", "blt", "blt", "blt", "blt",
+    "bgt", "bgt", "bgt", "bgt", "ble", "ble", "ble", "ble",
+    "jsr", "jsr", "jsr", "jsr", "jsr", "jsr", "jsr", "jsr",
+    "clr", "com", "inc", "dec", "neg", "adc", "sbc", "tst",
+    "ror", "rol", "asr", "asl", "mark", "mfpi", "mtpi", "sxt",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "mov", "mov", "mov", "mov", "mov", "mov", "mov", "mov",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp", "cmp",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bit", "bit", "bit", "bit", "bit", "bit", "bit", "bit",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bic", "bic", "bic", "bic", "bic", "bic", "bic", "bic",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "bis", "bis", "bis", "bis", "bis", "bis", "bis", "bis",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "add", "add", "add", "add", "add", "add", "add", "add",
+    "mul", "mul", "mul", "mul", "mul", "mul", "mul", "mul",
+    "divide", "divide", "divide", "divide", "divide", "divide", "divide",
+    "divide",
+    "ash", "ash", "ash", "ash", "ash", "ash", "ash", "ash",
+    "ashc", "ashc", "ashc", "ashc", "ashc", "ashc", "ashc", "ashc",
+    "xor", "xor", "xor", "xor", "xor", "xor", "xor", "xor",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "sob", "sob", "sob", "sob", "sob", "sob", "sob", "sob",
+    "bpl", "bpl", "bpl", "bpl", "bmi", "bmi", "bmi", "bmi",
+    "bhi", "bhi", "bhi", "bhi", "blos", "blos", "blos", "blos",
+    "bvc", "bvc", "bvc", "bvc", "bvs", "bvs", "bvs", "bvs",
+    "bcc", "bcc", "bcc", "bcc", "bcs", "bcs", "bcs", "bcs",
+    "emt", "emt", "emt", "emt", "trap", "trap", "trap", "trap",
+    "clrb", "comb", "incb", "decb", "negb", "adcb", "sbcb", "tstb",
+    "rorb", "rolb", "asrb", "aslb", "mtps", "mfpd", "mtpd", "mfps",
+    "illegal", "illegal", "illegal", "illegal", "illegal", "illegal",
+    "illegal", "illegal",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "movb", "movb", "movb", "movb", "movb", "movb", "movb", "movb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb", "cmpb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb", "bitb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb", "bicb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb", "bisb",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "sub", "sub", "sub", "sub", "sub", "sub", "sub", "sub",
+    "fpset", "ldfps", "stfps", "stst", "clrf", "tstf", "absf", "negf",
+    "mulf", "mulf", "mulf", "mulf", "moddf", "moddf", "moddf", "moddf",
+    "addf", "addf", "addf", "addf", "ldf", "ldf", "ldf", "ldf",
+    "subf", "subf", "subf", "subf", "cmpf", "cmpf", "cmpf", "cmpf",
+    "stf", "stf", "stf", "stf", "divf", "divf", "divf", "divf",
+    "stexp", "stexp", "stexp", "stexp", "stcfi", "stcfi", "stcfi", "stcfi",
+    "stcdf", "stcdf", "stcdf", "stcdf", "ldexpp", "ldexpp", "ldexpp",
+    "ldexpp",
+    "lcdif", "lcdif", "lcdif", "lcdif", "ldcdf", "ldcdf", "ldcdf", "ldcdf"
 };
 #endif
index 0d04f95..25951e1 100644 (file)
--- a/defines.h
+++ b/defines.h
 /* #define EMU211                      add 2.11BSD emulation */
 /* #define EMUV1                       add 1st Edition emulation */
 /* #define INLINE inline               inlines some functions (needs gcc) */
-                                       
+
 
 /* Optimisation defines */
 #ifndef INLINE
-# define INLINE
+#define INLINE
 #endif
 
 /* Special defines to enable/disable certain
  */
 
 #if defined(__FreeBSD__) && __FreeBSD__ < 3
-# define NO_GETPGID
+#define NO_GETPGID
 #endif
 
 #ifdef __FreeBSD__
-# define Reboot(x) reboot(x)
+#define Reboot(x) reboot(x)
 #endif
 
 #ifdef __linux__
-# define NO_CHFLAGS
-# define NO_STFLAGS
-# define NO_GETPGID
-# define NEED_MAP_FCNTL
-# define SIGEMT 0
-# ifndef SIGSYS
-#  define SIGSYS 0
-# endif
-# define OXTABS XTABS
-# define VDSUSP VSUSP          /* I don't think these are equivalent */
-# define O_SHLOCK 0
-# define O_EXLOCK 0
+#define NO_CHFLAGS
+#define NO_STFLAGS
+#define NO_GETPGID
+#define NEED_MAP_FCNTL
+#define SIGEMT 0
+#ifndef SIGSYS
+#define SIGSYS 0
+#endif
+#define OXTABS XTABS
+#define VDSUSP VSUSP           /* I don't think these are equivalent */
+#define O_SHLOCK 0
+#define O_EXLOCK 0
 #endif
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
-# define Reboot(x) reboot(x,NULL)
+#define Reboot(x) reboot(x,NULL)
 #endif
 
 #ifndef Reboot
-# define Reboot(x) exit(0)
+#define Reboot(x) exit(0)
 #endif
 
 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && \
     !defined(__OpenBSD__) && !defined(__linux__) && !defined(__APPLE__)
-# define NEED_INT_N
+#define NEED_INT_N
 #endif
 
 /* Type definitions for PDP data types. You may need to
@@ -98,25 +98,25 @@ typedef unsigned long u_int32_t;
  */
 
 #ifdef DEBUG
-# define TrapDebug(x) if (trap_debug) (void)fprintf x
-# define InstDebug(x) if (inst_debug) (void)fprintf x
-# define JsrDebug(x)  if (jsr_debug)  (void)fprintf x
-# define FpDebug(x)   if (fp_debug)   (void)fprintf x
+#define TrapDebug(x) if (trap_debug) (void)fprintf x
+#define InstDebug(x) if (inst_debug) (void)fprintf x
+#define JsrDebug(x)  if (jsr_debug)  (void)fprintf x
+#define FpDebug(x)   if (fp_debug)   (void)fprintf x
 #else
-# define TrapDebug(x)
-# define InstDebug(x)
-# define JsrDebug(x)
-# define FpDebug(x)
+#define TrapDebug(x)
+#define InstDebug(x)
+#define JsrDebug(x)
+#define FpDebug(x)
 #endif
 
-                               /* Defines for -DSTREAM_BUFFERING */
+/* Defines for -DSTREAM_BUFFERING */
 #define NFILE   40             /* Number of file pointers we can buffer */
 #define ValidFD(x) ((x>=0) && (x<NFILE))
-                               /* Used for opening on directories */
+/* Used for opening on directories */
 #define TMP_PLATE       "/tmp/apout_tmp_dir.XXXXXX"
 
 
-/* Set up prototype macro for 
+/* Set up prototype macro for
  * both K&R and ANSI C platforms
  */
 #ifdef __STDC__
@@ -128,7 +128,7 @@ typedef unsigned long u_int32_t;
 typedef void (*_itab) P((void));
 extern _itab itab[];           /* Instruction Table for Fast Decode. */
 
-typedef float  FLOAT;          /* For now, we use floats to do FP */
+typedef float FLOAT;           /* For now, we use floats to do FP */
 
 /* PDP processor defines. */
 
@@ -152,7 +152,7 @@ extern int CC_Z;            /* by these four values. On some */
 extern int CC_V;               /* architectures, you may get a performance */
 extern int CC_C;               /* increase by changing the size of the vars */
 
-extern FLOAT  fregs[8];                /* FP registers */
+extern FLOAT fregs[8];         /* FP registers */
 extern int FPC;                        /* FP Status flags */
 extern int FPZ;
 extern int FPN;
@@ -171,11 +171,11 @@ extern u_int8_t dstbyte;  /* function calls */
 extern u_int8_t srcbyte;
 extern u_int8_t tmpbyte;
 
-                               /* The following array holds the FILE pointers
                               * that correspond to open file descriptors.
                               * Only fds which are not ttys have
                               * FILE * pointers
                               */
+/* The following array holds the FILE pointers
+ * that correspond to open file descriptors.
+ * Only fds which are not ttys have
+ * FILE * pointers
+ */
 extern FILE *stream[NFILE];
 extern char *streammode[NFILE];
 
@@ -195,24 +195,24 @@ extern int Binary;                /* Type of binary this a.out is. One of: */
 #define IS_29BSD       29
 #define IS_211BSD      211
 
-                               /* 2.11BSD overlay stuff */
+/* 2.11BSD overlay stuff */
 extern u_int32_t ov_changes;   /* Number of overlay changes */
 extern u_int8_t current_ov;    /* Current overlay number */
 
 #ifdef DEBUG
-                               /* Debugging flags */
+/* Debugging flags */
 extern int inst_debug,         /* Print a line before each instruction */
-    trap_debug,                        /* Print details of each trap */
-    jsr_debug,                 /* Print out each jsr */
-    fp_debug;                  /* Print out each floating-point instruction */
+       trap_debug,                     /* Print details of each trap */
+       jsr_debug,                      /* Print out each jsr */
+       fp_debug;                       /* Print out each floating-point instruction */
 extern FILE *dbg_file;         /* Debugging output file */
 extern char *progname;         /* The program's name - used in debugging */
 #endif
 
-                               /* We keep a list of signals that are pending */
+/* We keep a list of signals that are pending */
 struct our_siglist {
-        int sig;               /* Number of the signal */
-        struct our_siglist *next;
+    int sig;                   /* Number of the signal */
+    struct our_siglist *next;
 };
 extern struct our_siglist *Sighead;    /* Head of the list */
 extern struct our_siglist *Sigtail;    /* Tail of the list */
@@ -379,9 +379,9 @@ extern u_int16_t *adptr;
        { dspace[addr]= byte; }
 #endif
 #else
-                               /* These versions of the macros are required */
-                               /* because the KE11-A module is mapped into */
-                               /* a process' memory space in 1st Edition */
+/* These versions of the macros are required */
+/* because the KE11-A module is mapped into */
+/* a process' memory space in 1st Edition */
 #define KE11LO 0177300
 #define KE11HI 0177317
 
@@ -442,7 +442,7 @@ extern u_int16_t *adptr;
        }
 #endif
 #endif
-                               
+
 
 
 
@@ -450,7 +450,7 @@ extern u_int16_t *adptr;
 
 /* aout.c */
 int load_a_out P((const char *file, const char *origpath, int want_env))
-                                       /*@globals errno,stdout,stderr; @*/ ;
+/*@globals errno,stdout,stderr; @ */ ;
 #ifdef EMU211
 void do_bsd_overlay P((void));
 #endif
@@ -570,11 +570,11 @@ void dositab1 P((void));
 /* main.c */
 int main P((int argc, char **argv));
 void usage P((void));
-char * xlate_filename P((char *name));
+char *xlate_filename P((char *name));
 void set_apout_root P((char *dirname));
 
 /* magic.c */
-int special_magic P((u_int16_t *cptr));
+int special_magic P((u_int16_t * cptr));
 
 /* single.c */
 void adc P((void));
@@ -615,7 +615,7 @@ void v1trap P((void));
 
 /* bsdtrap.c */
 #ifdef EMU211
-void bsdtrap P((void))                 /*@globals errno,stdout,stderr; @*/ ;
+void bsdtrap P((void)) /*@globals errno,stdout,stderr; @ */ ;
 
 /* bsd_ioctl.h */
 int trap_ioctl P((void));
index 4650406..95cd0b3 100644 (file)
--- a/double.c
+++ b/double.c
@@ -10,14 +10,14 @@ static u_int32_t templong;
 
 /* mov() - Move Instruction.  Move operations with registers as the source
  * and/or destination have been inlined. */
-void
-mov()
+void mov()
 {
 
     if (SRC_MODE) {
-       load_src(); dstword=srcword;
+        load_src();
+        dstword = srcword;
     } else {
-       dstword = regs[SRC_REG];
+        dstword = regs[SRC_REG];
     }
 
     CHG_CC_N(dstword);
@@ -25,9 +25,9 @@ mov()
     CLR_CC_V();
 
     if (DST_MODE) {
-       store_dst();
+        store_dst();
     } else {
-       regs[DST_REG] = dstword;
+        regs[DST_REG] = dstword;
     }
 }
 
@@ -35,8 +35,7 @@ mov()
  * mov() above. I've broken them out in an attempt to improve
  * performance.
  */
-void
-movsreg()
+void movsreg()
 {
     dstword = regs[SRC_REG];
     CHG_CC_N(dstword);
@@ -44,14 +43,13 @@ movsreg()
     CLR_CC_V();
 
     if (DST_MODE) {
-       store_dst();
+        store_dst();
     } else {
-       regs[DST_REG] = dstword;
+        regs[DST_REG] = dstword;
     }
 }
 
-void
-movsreg1()
+void movsreg1()
 {
     ll_word(regs[SRC_REG], dstword);
     CHG_CC_N(dstword);
@@ -59,14 +57,13 @@ movsreg1()
     CLR_CC_V();
 
     if (DST_MODE) {
-       store_dst();
+        store_dst();
     } else {
-       regs[DST_REG] = dstword;
+        regs[DST_REG] = dstword;
     }
 }
 
-void
-movsreg1pc()
+void movsreg1pc()
 {
     lli_word(regs[PC], dstword)
     CHG_CC_N(dstword);
@@ -74,17 +71,16 @@ movsreg1pc()
     CLR_CC_V();
 
     if (DST_MODE) {
-       store_dst();
+        store_dst();
     } else {
-       regs[DST_REG] = dstword;
+        regs[DST_REG] = dstword;
     }
 }
 
 
 
 /* cmp() - Compare Instruction. */
-void
-cmp()
+void cmp()
 {
     load_src();
     load_dst();
@@ -101,8 +97,7 @@ cmp()
 
 
 /* add() - Add Instruction. */
-void
-add()
+void add()
 {
     load_src();
     load_dst();
@@ -115,12 +110,12 @@ add()
     CHG_CC_V(srcword, dstword, tmpword);
     CHG_CC_C(templong);
 
-    dstword=tmpword; store_dst_2();
+    dstword = tmpword;
+    store_dst_2();
 }
 
 /* Subtract Instruction. */
-void
-sub()
+void sub()
 {
     load_src();
     load_dst();
@@ -134,13 +129,13 @@ sub()
     CHG_CC_VS(srcword, dstword, tmpword);      /* was CHG_CC_V */
     CHG_CC_IC(templong);
 
-    dstword=tmpword; store_dst_2();
+    dstword = tmpword;
+    store_dst_2();
 }
 
 
 /* bit() - Bit Test Instruction. */
-void
-bit()
+void bit()
 {
     load_src();
     load_dst();
@@ -153,8 +148,7 @@ bit()
 }
 
 /* bic() - Bit Clear Instruction. */
-void
-bic()
+void bic()
 {
     load_src();
     load_dst();
@@ -169,8 +163,7 @@ bic()
 
 
 /* bis() - Bit Set Instruction. */
-void
-bis()
+void bis()
 {
     load_src();
     load_dst();
@@ -186,13 +179,12 @@ bis()
 
 /* movb() - Move Byte Instruction.  Move operations with registers as the
  * source and/or destination have been inlined. */
-void
-movb()
+void movb()
 {
     if (SRC_MODE) {
-       loadb_src();
+        loadb_src();
     } else {
-       srcbyte = LOW8(regs[SRC_REG]);
+        srcbyte = LOW8(regs[SRC_REG]);
     }
 
     CHGB_CC_N(srcbyte);
@@ -202,25 +194,24 @@ movb()
     /* move byte to a register causes sign extension */
 
     if (DST_MODE) {
-       storeb_dst();
+        storeb_dst();
     } else {
-       if (srcbyte & SIGN_B)
-           regs[DST_REG] = (u_int16_t)0177400 + (u_int16_t)srcbyte;
-       else
-           regs[DST_REG] = (u_int16_t)srcbyte;
+        if (srcbyte & SIGN_B)
+            regs[DST_REG] = (u_int16_t) 0177400 + (u_int16_t) srcbyte;
+        else
+            regs[DST_REG] = (u_int16_t) srcbyte;
     }
 }
 
 /* cmpb() - Compare Byte Instruction. */
-void
-cmpb()
+void cmpb()
 {
     u_int8_t data3;
 
     loadb_src();
     loadb_dst();
 
-    data3 = (u_int8_t)~dstbyte;
+    data3 = (u_int8_t) ~ dstbyte;
     tmpword = ((u_int16_t) srcbyte) + ((u_int16_t) (data3)) + 1;
     data3 = LOW8(tmpword);
 
@@ -232,8 +223,7 @@ cmpb()
 
 
 /* bitb() - Bit Test Byte Instruction. */
-void
-bitb()
+void bitb()
 {
     loadb_src();
     loadb_dst();
@@ -246,13 +236,12 @@ bitb()
 }
 
 /* bicb() - Bit Clear Byte Instruction. */
-void
-bicb()
+void bicb()
 {
     loadb_src();
     loadb_dst();
 
-    dstbyte = (u_int8_t)((~srcbyte) & dstbyte);
+    dstbyte = (u_int8_t) ((~srcbyte) & dstbyte);
 
     CHGB_CC_N(dstbyte);
     CHGB_CC_Z(dstbyte);
@@ -264,8 +253,7 @@ bicb()
 
 /* bisb() - Bit Set Byte Instruction. */
 
-void
-bisb()
+void bisb()
 {
     loadb_src();
     loadb_dst();
diff --git a/ea.c b/ea.c
index 31c9587..c9360a9 100644 (file)
--- a/ea.c
+++ b/ea.c
  */
 #include "defines.h"
 
-void 
-load_ea(void)
+void load_ea(void)
 {
     u_int16_t indirect;
 
     switch (DST_MODE) {
     case 0:
-       illegal();
-       return;
+        illegal();
+        return;
     case 1:
-       dstword = regs[DST_REG];
-       return;
+        dstword = regs[DST_REG];
+        return;
     case 2:
-       dstword = regs[DST_REG];        /* this is wrong for 11/34 */
-       regs[DST_REG] += 2;
-       return;
+        dstword = regs[DST_REG];       /* this is wrong for 11/34 */
+        regs[DST_REG] += 2;
+        return;
     case 3:
-       indirect = regs[DST_REG];       /* this is wrong for 11/34 */
-       regs[DST_REG] += 2;
-       lli_word(indirect, dstword);
-       return;
+        indirect = regs[DST_REG];      /* this is wrong for 11/34 */
+        regs[DST_REG] += 2;
+        lli_word(indirect, dstword);
+        return;
     case 4:
-       regs[DST_REG] -= 2;
-       dstword = regs[DST_REG];
-       return;
+        regs[DST_REG] -= 2;
+        dstword = regs[DST_REG];
+        return;
     case 5:
-       regs[DST_REG] -= 2;
-       indirect = regs[DST_REG];
-       lli_word(indirect, dstword);
-       return;
+        regs[DST_REG] -= 2;
+        indirect = regs[DST_REG];
+        lli_word(indirect, dstword);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       dstword = regs[DST_REG] + indirect;
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        dstword = regs[DST_REG] + indirect;
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-           ll_word(indirect, dstword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, dstword);
+        return;
     }
     illegal();
 }
 
 
-INLINE void 
-pop(void)
+INLINE void pop(void)
 {
     ll_word(regs[SP], dstword);
     regs[SP] += 2;
 }
 
 
-INLINE void 
-push(void)
+INLINE void push(void)
 {
     regs[SP] -= 2;
     sl_word(regs[SP], srcword);
 }
 
 
-void 
-loadb_dst(void)
+void loadb_dst(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       dstbyte = (u_int8_t)(regs[DST_REG] & 0377);
-       return;
+        dstbyte = (u_int8_t) (regs[DST_REG] & 0377);
+        return;
     case 1:
-       addr = regs[DST_REG];
-       ea_addr = addr;
-       if (DST_REG == PC) {
-           lli_byte(addr, dstbyte)
-       } else {
-           ll_byte(addr, dstbyte);
-       }
-       return;
+        addr = regs[DST_REG];
+        ea_addr = addr;
+        if (DST_REG == PC) {
+            lli_byte(addr, dstbyte)
+        } else {
+            ll_byte(addr, dstbyte);
+        }
+        return;
     case 2:
-       addr = regs[DST_REG];
-       ea_addr = addr;
-       if (DST_REG == PC) {
-           lli_byte(addr, dstbyte)
-       } else {
-           ll_byte(addr, dstbyte);
-       }
-       if (DST_REG >= 6)
-           regs[DST_REG] += 2;
-       else
-           regs[DST_REG] += 1;
-       return;
+        addr = regs[DST_REG];
+        ea_addr = addr;
+        if (DST_REG == PC) {
+            lli_byte(addr, dstbyte)
+        } else {
+            ll_byte(addr, dstbyte);
+        }
+        if (DST_REG >= 6)
+            regs[DST_REG] += 2;
+        else
+            regs[DST_REG] += 1;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       if (DST_REG == PC) {
-           lli_word(indirect, addr)
-       } else {
-           ll_word(indirect, addr);
-       }
-       ea_addr = addr;
-       ll_byte(addr, dstbyte);
-       regs[DST_REG] += 2;
-       return;
+        indirect = regs[DST_REG];
+        if (DST_REG == PC) {
+            lli_word(indirect, addr)
+        } else {
+            ll_word(indirect, addr);
+        }
+        ea_addr = addr;
+        ll_byte(addr, dstbyte);
+        regs[DST_REG] += 2;
+        return;
     case 4:
-       if (DST_REG >= 6)
-           regs[DST_REG] -= 2;
-       else
-           regs[DST_REG] -= 1;
-       addr = regs[DST_REG];
-       ea_addr = addr;
-       ll_byte(addr, dstbyte);
-       return;
+        if (DST_REG >= 6)
+            regs[DST_REG] -= 2;
+        else
+            regs[DST_REG] -= 1;
+        addr = regs[DST_REG];
+        ea_addr = addr;
+        ll_byte(addr, dstbyte);
+        return;
     case 5:
-       regs[DST_REG] -= 2;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       ea_addr = addr;
-       ll_byte(addr, dstbyte);
-       return;
+        regs[DST_REG] -= 2;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        ea_addr = addr;
+        ll_byte(addr, dstbyte);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       ea_addr = addr;
-       ll_byte(addr, dstbyte);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        ea_addr = addr;
+        ll_byte(addr, dstbyte);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-           ll_word(indirect, addr);
-       ea_addr = addr;
-       ll_byte(addr, dstbyte);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        ea_addr = addr;
+        ll_byte(addr, dstbyte);
+        return;
     }
     illegal();
 }
 
 
-void 
-loadb_src(void)
+void loadb_src(void)
 {
     u_int16_t addr, indirect;
 
     switch (SRC_MODE) {
     case 0:
-       srcbyte = (u_int8_t)(regs[SRC_REG] & 0377);
-       return;
+        srcbyte = (u_int8_t) (regs[SRC_REG] & 0377);
+        return;
     case 1:
-       addr = regs[SRC_REG];
-       if (SRC_REG == PC) {
-           lli_byte(addr, srcbyte);
-       } else {
-           ll_byte(addr, srcbyte);
-       }
-       return;
+        addr = regs[SRC_REG];
+        if (SRC_REG == PC) {
+            lli_byte(addr, srcbyte);
+        } else {
+            ll_byte(addr, srcbyte);
+        }
+        return;
     case 2:
-       addr = regs[SRC_REG];
-       if (SRC_REG == PC) {
-           lli_byte(addr, srcbyte);
-       } else {
-           ll_byte(addr, srcbyte);
-       }
-       if (SRC_REG >= 6)
-           regs[SRC_REG] += 2;
-       else
-           regs[SRC_REG] += 1;
-       return;
+        addr = regs[SRC_REG];
+        if (SRC_REG == PC) {
+            lli_byte(addr, srcbyte);
+        } else {
+            ll_byte(addr, srcbyte);
+        }
+        if (SRC_REG >= 6)
+            regs[SRC_REG] += 2;
+        else
+            regs[SRC_REG] += 1;
+        return;
     case 3:
-       indirect = regs[SRC_REG];
-       if (SRC_REG == PC) {
-           lli_word(indirect, addr)
-       } else {
-           ll_word(indirect, addr);
-       }
-       ll_byte(addr, srcbyte);
-       regs[SRC_REG] += 2;
-       return;
+        indirect = regs[SRC_REG];
+        if (SRC_REG == PC) {
+            lli_word(indirect, addr)
+        } else {
+            ll_word(indirect, addr);
+        }
+        ll_byte(addr, srcbyte);
+        regs[SRC_REG] += 2;
+        return;
     case 4:
-       if (SRC_REG >= 6)
-           regs[SRC_REG] -= 2;
-       else
-           regs[SRC_REG] -= 1;
-       addr = regs[SRC_REG];
-       ll_byte(addr, srcbyte);
-       return;
+        if (SRC_REG >= 6)
+            regs[SRC_REG] -= 2;
+        else
+            regs[SRC_REG] -= 1;
+        addr = regs[SRC_REG];
+        ll_byte(addr, srcbyte);
+        return;
     case 5:
-       regs[SRC_REG] -= 2;
-       indirect = regs[SRC_REG];
-       ll_word(indirect, addr);
-       ll_byte(addr, srcbyte);
-       return;
+        regs[SRC_REG] -= 2;
+        indirect = regs[SRC_REG];
+        ll_word(indirect, addr);
+        ll_byte(addr, srcbyte);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[SRC_REG] + indirect;
-       ll_byte(addr, srcbyte);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[SRC_REG] + indirect;
+        ll_byte(addr, srcbyte);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[SRC_REG] + indirect;
-           ll_word(indirect, addr);
-       ll_byte(addr, srcbyte);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[SRC_REG] + indirect;
+        ll_word(indirect, addr);
+        ll_byte(addr, srcbyte);
+        return;
     }
     illegal();
 }
 
-void 
-storeb_dst(void)
+void storeb_dst(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       regs[DST_REG]&= 0xff00;
-       regs[DST_REG]|= srcbyte;
-       return;
+        regs[DST_REG] &= 0xff00;
+        regs[DST_REG] |= srcbyte;
+        return;
     case 1:
-       addr = regs[DST_REG];
-       sl_byte(addr, srcbyte);
-       return;
+        addr = regs[DST_REG];
+        sl_byte(addr, srcbyte);
+        return;
     case 2:
-       addr = regs[DST_REG];
-       sl_byte(addr, srcbyte);
-       if (DST_REG >= 6)
-           regs[DST_REG] += 2;
-       else
-           regs[DST_REG] += 1;
-       return;
+        addr = regs[DST_REG];
+        sl_byte(addr, srcbyte);
+        if (DST_REG >= 6)
+            regs[DST_REG] += 2;
+        else
+            regs[DST_REG] += 1;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       sl_byte(addr, srcbyte);
-       regs[DST_REG] += 2;
-       return;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        sl_byte(addr, srcbyte);
+        regs[DST_REG] += 2;
+        return;
     case 4:
-       if (DST_REG >= 6)               /* xyz */
-           regs[DST_REG] -= 2;
-       else
-           regs[DST_REG] -= 1;
-       addr = regs[DST_REG];
-       sl_byte(addr, srcbyte);
-       return;
+        if (DST_REG >= 6)      /* xyz */
+            regs[DST_REG] -= 2;
+        else
+            regs[DST_REG] -= 1;
+        addr = regs[DST_REG];
+        sl_byte(addr, srcbyte);
+        return;
     case 5:
-       regs[DST_REG] -= 2;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       sl_byte(addr, srcbyte);
-       return;
+        regs[DST_REG] -= 2;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        sl_byte(addr, srcbyte);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       sl_byte(addr, srcbyte);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        sl_byte(addr, srcbyte);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-           ll_word(indirect, addr);
-       sl_byte(addr, srcbyte);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        sl_byte(addr, srcbyte);
+        return;
     }
     illegal();
 }
 
 
-INLINE void 
-storeb_dst_2(void)
+INLINE void storeb_dst_2(void)
 {
     if (DST_MODE == 0) {
-       regs[DST_REG]&= 0xff00;
-       regs[DST_REG]|= dstbyte;
-       return;
+        regs[DST_REG] &= 0xff00;
+        regs[DST_REG] |= dstbyte;
+        return;
     }
     sl_byte(ea_addr, dstbyte);
 }
 
 
-void 
-loadp_dst(void)
+void loadp_dst(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       srcword = regs[DST_REG];
-       return;
+        srcword = regs[DST_REG];
+        return;
     case 1:
-       addr = regs[DST_REG];
-       ll_word(addr, srcword);
-       return;
+        addr = regs[DST_REG];
+        ll_word(addr, srcword);
+        return;
     case 2:
-       addr = regs[DST_REG];
-       ll_word(addr, srcword);
-       regs[DST_REG] += 2;
-       return;
+        addr = regs[DST_REG];
+        ll_word(addr, srcword);
+        regs[DST_REG] += 2;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       ll_word(addr, srcword);
-       regs[DST_REG] += 2;
-       return;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        ll_word(addr, srcword);
+        regs[DST_REG] += 2;
+        return;
     case 4:
-       regs[DST_REG] -= 2;
-       addr = regs[DST_REG];
-       ll_word(addr, srcword);
-       return;
+        regs[DST_REG] -= 2;
+        addr = regs[DST_REG];
+        ll_word(addr, srcword);
+        return;
     case 5:
-       regs[DST_REG] -= 2;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       ll_word(addr, srcword);
-       return;
+        regs[DST_REG] -= 2;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        ll_word(addr, srcword);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       if (DST_REG == PC)
-           lli_word(addr, srcword)
-       else
-           ll_word(addr, srcword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        if (DST_REG == PC)
+            lli_word(addr, srcword)
+            else
+                ll_word(addr, srcword);
+        return;
     case 7:
-       not_impl();
+        not_impl();
     }
     illegal();
 }
 
 
-void 
-storep_dst(void)
+void storep_dst(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       regs[DST_REG] = dstword;
-       return;
+        regs[DST_REG] = dstword;
+        return;
     case 1:
-       addr = regs[DST_REG];
-       sl_word(addr, dstword);
-       return;
+        addr = regs[DST_REG];
+        sl_word(addr, dstword);
+        return;
     case 2:
-       addr = regs[DST_REG];
-       sl_word(addr, dstword);
-       regs[DST_REG] += 2;
-       return;
+        addr = regs[DST_REG];
+        sl_word(addr, dstword);
+        regs[DST_REG] += 2;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       sl_word(addr, dstword);
-       regs[DST_REG] += 2;
-       return;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        sl_word(addr, dstword);
+        regs[DST_REG] += 2;
+        return;
     case 4:
-       regs[DST_REG] -= 2;
-       addr = regs[DST_REG];
-       sl_word(addr, dstword);
-       return;
+        regs[DST_REG] -= 2;
+        addr = regs[DST_REG];
+        sl_word(addr, dstword);
+        return;
     case 5:
-       regs[DST_REG] -= 2;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       sl_word(addr, dstword);
-       return;
+        regs[DST_REG] -= 2;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        sl_word(addr, dstword);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       sl_word(addr, dstword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        sl_word(addr, dstword);
+        return;
     case 7:
-       not_impl();
+        not_impl();
     }
     illegal();
 }
 
 
-void 
-load_src(void)
+void load_src(void)
 {
     u_int16_t addr, indirect;
 
     switch (SRC_MODE) {
     case 0:
-       srcword = regs[SRC_REG];
-       return;
+        srcword = regs[SRC_REG];
+        return;
     case 1:
-       addr = regs[SRC_REG];
-       if (SRC_REG == PC) {
-           lli_word(addr, srcword)
-       } else {
-           ll_word(addr, srcword);
-       }
-       return;
+        addr = regs[SRC_REG];
+        if (SRC_REG == PC) {
+            lli_word(addr, srcword)
+        } else {
+            ll_word(addr, srcword);
+        }
+        return;
     case 2:
-       addr = regs[SRC_REG];
-       if (SRC_REG == PC) {
-           lli_word(addr, srcword)
-       } else {
-           ll_word(addr, srcword);
-       }
-       regs[SRC_REG] += 2;
-       return;
+        addr = regs[SRC_REG];
+        if (SRC_REG == PC) {
+            lli_word(addr, srcword)
+        } else {
+            ll_word(addr, srcword);
+        }
+        regs[SRC_REG] += 2;
+        return;
     case 3:
-       indirect = regs[SRC_REG];
-       if (SRC_REG == PC) {
-           lli_word(indirect, addr)
-       } else {
-           ll_word(indirect, addr);
-       }
-       regs[SRC_REG] += 2;     /* is this right ? */
-       ll_word(addr, srcword);
-       return;
+        indirect = regs[SRC_REG];
+        if (SRC_REG == PC) {
+            lli_word(indirect, addr)
+        } else {
+            ll_word(indirect, addr);
+        }
+        regs[SRC_REG] += 2;    /* is this right ? */
+        ll_word(addr, srcword);
+        return;
     case 4:
-       regs[SRC_REG] -= 2;
-       addr = regs[SRC_REG];
-       ll_word(addr, srcword);
-       return;
+        regs[SRC_REG] -= 2;
+        addr = regs[SRC_REG];
+        ll_word(addr, srcword);
+        return;
     case 5:
-       regs[SRC_REG] -= 2;
-       indirect = regs[SRC_REG];
-       ll_word(indirect, addr);
-       ll_word(addr, srcword);
-       return;
+        regs[SRC_REG] -= 2;
+        indirect = regs[SRC_REG];
+        ll_word(indirect, addr);
+        ll_word(addr, srcword);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[SRC_REG] + indirect;
-       ll_word(addr, srcword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[SRC_REG] + indirect;
+        ll_word(addr, srcword);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[SRC_REG] + indirect;
-           ll_word(indirect, addr);
-       ll_word(addr, srcword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[SRC_REG] + indirect;
+        ll_word(indirect, addr);
+        ll_word(addr, srcword);
+        return;
     }
     illegal();
 }
 
 
-void 
-store_dst(void)
+void store_dst(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       regs[DST_REG] = dstword;
-       return;
+        regs[DST_REG] = dstword;
+        return;
     case 1:
-       addr = regs[DST_REG];
-       sl_word(addr, dstword);
-       return;
+        addr = regs[DST_REG];
+        sl_word(addr, dstword);
+        return;
     case 2:
-       addr = regs[DST_REG];
-       sl_word(addr, dstword);
-       regs[DST_REG] += 2;
-       return;
+        addr = regs[DST_REG];
+        sl_word(addr, dstword);
+        regs[DST_REG] += 2;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       regs[DST_REG] += 2;     /* is this right ? */
-       sl_word(addr, dstword);
-       return;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        regs[DST_REG] += 2;    /* is this right ? */
+        sl_word(addr, dstword);
+        return;
     case 4:
-       regs[DST_REG] -= 2;
-       addr = regs[DST_REG];
-       sl_word(addr, dstword);
-       return;
+        regs[DST_REG] -= 2;
+        addr = regs[DST_REG];
+        sl_word(addr, dstword);
+        return;
     case 5:
-       regs[DST_REG] -= 2;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       sl_word(addr, dstword);
-       return;
+        regs[DST_REG] -= 2;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        sl_word(addr, dstword);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       sl_word(addr, dstword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        sl_word(addr, dstword);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-           ll_word(indirect, addr);
-       sl_word(addr, dstword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        sl_word(addr, dstword);
+        return;
     }
     illegal();
 }
 
 
-void 
-load_dst(void)
+void load_dst(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       dstword = regs[DST_REG];
-       return;
+        dstword = regs[DST_REG];
+        return;
     case 1:
-       addr = regs[DST_REG];
-       ea_addr = addr;
-       if (DST_REG == PC) {
-           lli_word(addr, dstword)
-       } else {
-           ll_word(addr, dstword);
-       }
-       return;
+        addr = regs[DST_REG];
+        ea_addr = addr;
+        if (DST_REG == PC) {
+            lli_word(addr, dstword)
+        } else {
+            ll_word(addr, dstword);
+        }
+        return;
     case 2:
-       addr = regs[DST_REG];
-       ea_addr = addr;
-       if (DST_REG == PC) {
-           lli_word(addr, dstword)
-       } else {
-           ll_word(addr, dstword);
-       }
-       regs[DST_REG] += 2;
-       return;
+        addr = regs[DST_REG];
+        ea_addr = addr;
+        if (DST_REG == PC) {
+            lli_word(addr, dstword)
+        } else {
+            ll_word(addr, dstword);
+        }
+        regs[DST_REG] += 2;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       if (DST_REG == PC) {
-           lli_word(indirect, addr)
-       } else {
-           ll_word(indirect, addr);
-       }
-       ea_addr = addr;
-       ll_word(addr, dstword);
-       regs[DST_REG] += 2;
-       return;
+        indirect = regs[DST_REG];
+        if (DST_REG == PC) {
+            lli_word(indirect, addr)
+        } else {
+            ll_word(indirect, addr);
+        }
+        ea_addr = addr;
+        ll_word(addr, dstword);
+        regs[DST_REG] += 2;
+        return;
     case 4:
-       regs[DST_REG] -= 2;
-       addr = regs[DST_REG];
-       ea_addr = addr;
-       ll_word(addr, dstword);
-       return;
+        regs[DST_REG] -= 2;
+        addr = regs[DST_REG];
+        ea_addr = addr;
+        ll_word(addr, dstword);
+        return;
     case 5:
-       regs[DST_REG] -= 2;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       ea_addr = addr;
-       ll_word(addr, dstword);
-       return;
+        regs[DST_REG] -= 2;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        ea_addr = addr;
+        ll_word(addr, dstword);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       ea_addr = addr;
-       ll_word(addr, dstword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        ea_addr = addr;
+        ll_word(addr, dstword);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-           ll_word(indirect, addr);
-       ea_addr = addr;
-       ll_word(addr, dstword);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        ea_addr = addr;
+        ll_word(addr, dstword);
+        return;
     }
     illegal();
 }
 
 
-INLINE void 
-store_dst_2(void)
+INLINE void store_dst_2(void)
 {
     if (DST_MODE == 0) {
-       regs[DST_REG] = dstword;
-       return;
+        regs[DST_REG] = dstword;
+        return;
     }
     sl_word(ea_addr, dstword);
 }
diff --git a/fp.c b/fp.c
index 3b69cb3..bcb47f1 100644 (file)
--- a/fp.c
+++ b/fp.c
 #ifdef HAVE_POWF
 float powf(float x, float y);  /* FreeBSD 3.X no longer defines this */
 #else
-# define powf(x,y) (float)pow((double)x, (double)y)
+#define powf(x,y) (float)pow((double)x, (double)y)
 #endif
 
-#define XUL    170141163178059628080016879768632819712.0 /* Biggest float */
+#define XUL    170141163178059628080016879768632819712.0       /* Biggest float */
 
 typedef struct {
-   unsigned frac1:7;   /* Fractional part of number */
-   unsigned exp:  8;   /* Excess 128 notation: exponenents -128 to +127 */
-                       /* become 0 to 255 */
-   unsigned sign: 1;   /* If 1, float is negative */
-   unsigned frac2: 16; /* Fractional part of number */
+    unsigned frac1:7;          /* Fractional part of number */
+    unsigned exp:8;            /* Excess 128 notation: exponenents -128 to +127 */
+    /* become 0 to 255 */
+    unsigned sign:1;           /* If 1, float is negative */
+    unsigned frac2:16;         /* Fractional part of number */
 } pdpfloat;
 
 
 /* Internal variables */
-FLOAT  fregs[8];       /* Yes, I know there are only 6, it makes it easier */
-int FPC=0;             /* Status flags */
-int FPZ=0;
-int FPN=0;
-int FPV=0;
-int FPMODE=0;          /* 0 = float, 1 = doubles */
-int INTMODE=0;         /* 0 = integers, 1 = longs */
+FLOAT fregs[8];                        /* Yes, I know there are only 6, it makes it easier */
+int FPC = 0;                   /* Status flags */
+int FPZ = 0;
+int FPN = 0;
+int FPV = 0;
+int FPMODE = 0;                        /* 0 = float, 1 = doubles */
+int INTMODE = 0;               /* 0 = integers, 1 = longs */
 
 /* Temporary variables */
-FLOAT Srcflt;          /* Float specified by FSRC field */
-pdpfloat *fladdr;      /* Address of float  in dspace */
-int   AC;              /* Accumulator field in ir */
-int32_t srclong;       /* Longword from source address */
-int32_t dstlong;       /* Longword for destination address */
-static char *buf, *buf2; /* for copylong */
+FLOAT Srcflt;                  /* Float specified by FSRC field */
+pdpfloat *fladdr;              /* Address of float  in dspace */
+int AC;                                /* Accumulator field in ir */
+int32_t srclong;               /* Longword from source address */
+int32_t dstlong;               /* Longword for destination address */
+static char *buf, *buf2;       /* for copylong */
 
 
 
 
 /* Convert from PDP-11 float representation to native representation */
-static void from11float(FLOAT *out, pdpfloat *in)
+static void from11float(FLOAT * out, pdpfloat * in)
 {
- int32_t  exponent;
- u_int32_t fraction;
- FLOAT z;
-
- exponent= in->exp - 128 - 24; /* 24 so as to shift the radix point left */
-                                   /* Add in the missing significant bit */
- fraction= (in->frac1 << 16) + in->frac2 + 8388608;
-
- z= powf(2.0, (float)exponent);
- *out= (float)fraction * z;
- if (in->sign) *out= -(*out);
- FpDebug((dbg_file, "\t0%o from11float out is %f\n",regs[7], *out));
+    int32_t exponent;
+    u_int32_t fraction;
+    FLOAT z;
+
+    exponent = in->exp - 128 - 24;     /* 24 so as to shift the radix point left */
+    /* Add in the missing significant bit */
+    fraction = (in->frac1 << 16) + in->frac2 + 8388608;
+
+    z = powf(2.0, (float) exponent);
+    *out = (float) fraction *z;
+    if (in->sign)
+        *out = -(*out);
+    FpDebug((dbg_file, "\t0%o from11float out is %f\n", regs[7], *out));
 }
 
 /* Convert from native representation to PDP-11 float representation */
-static void to11float(FLOAT *in, pdpfloat *out)
+static void to11float(FLOAT * in, pdpfloat * out)
 {
-  int32_t  exponent=129;
-  u_int32_t fraction;
-  FLOAT infloat= *in;
-
-  FpDebug((dbg_file, "\t0%o to11float in is %f\n",regs[7], infloat));
-  if (infloat < 0.0) { out->sign=1; infloat= -infloat; } 
-  else out->sign=0;
-
-  if (infloat==0.0) { out->frac1=0; out->frac2=0; out->exp=0; return; }
-
-  /* We want the float's fraction to start with 1.0 (in binary) */
-  /* Therefore it must be < 2.0 and >= 1.0 */
-  while (infloat >= 2.0) { infloat *= 0.5; exponent++; }
-  while (infloat < 1.0)         { infloat *= 2.0; exponent--; }
-
-  infloat= infloat - 1.0;              /* Remove significant bit */
-  fraction= (int)(infloat * 8388608.0); /* Multiply fraction by 2^24 */
-  out->frac2= fraction & 0xffff;
-  out->frac1= (fraction>>16);
-  out->exp= exponent;
+    int32_t exponent = 129;
+    u_int32_t fraction;
+    FLOAT infloat = *in;
+
+    FpDebug((dbg_file, "\t0%o to11float in is %f\n", regs[7], infloat));
+    if (infloat < 0.0) {
+        out->sign = 1;
+        infloat = -infloat;
+    } else
+        out->sign = 0;
+
+    if (infloat == 0.0) {
+        out->frac1 = 0;
+        out->frac2 = 0;
+        out->exp = 0;
+        return;
+    }
+
+    /* We want the float's fraction to start with 1.0 (in binary) */
+    /* Therefore it must be < 2.0 and >= 1.0 */
+    while (infloat >= 2.0) {
+        infloat *= 0.5;
+        exponent++;
+    }
+    while (infloat < 1.0) {
+        infloat *= 2.0;
+        exponent--;
+    }
+
+    infloat = infloat - 1.0;   /* Remove significant bit */
+    fraction = (int) (infloat * 8388608.0);    /* Multiply fraction by 2^24 */
+    out->frac2 = fraction & 0xffff;
+    out->frac1 = (fraction >> 16);
+    out->exp = exponent;
 }
 
-static struct { u_int16_t lo; u_int16_t hi; } intpair;
+static struct {
+    u_int16_t lo;
+    u_int16_t hi;
+} intpair;
 /* Load (and convert if necessary) the float described by the source */
 /* address into Srcflt. */
-static void 
-load_flt(void)
+static void load_flt(void)
 {
-    u_int16_t indirect,addr;
+    u_int16_t indirect, addr;
     u_int16_t *intptr;
 
     FpDebug((dbg_file, "\tload_flt mode %d\n", DST_MODE));
     switch (DST_MODE) {
     case 0:
-       Srcflt = fregs[DST_REG];
-       fladdr=NULL; return;
+        Srcflt = fregs[DST_REG];
+        fladdr = NULL;
+        return;
     case 1:
-       if (DST_REG == PC) {
-           intptr = (u_int16_t *)&ispace[regs[DST_REG]];
-           intpair.lo= *intptr;
-           intpair.hi=0;
-           fladdr= (pdpfloat *)&intpair;
-       } else fladdr = (pdpfloat *)&dspace[regs[DST_REG]];
-       from11float(&Srcflt, fladdr);
-       return;
+        if (DST_REG == PC) {
+            intptr = (u_int16_t *) & ispace[regs[DST_REG]];
+            intpair.lo = *intptr;
+            intpair.hi = 0;
+            fladdr = (pdpfloat *) & intpair;
+        } else
+            fladdr = (pdpfloat *) & dspace[regs[DST_REG]];
+        from11float(&Srcflt, fladdr);
+        return;
     case 2:
-       if (DST_REG == PC) {
-           intptr = (u_int16_t *)&ispace[regs[DST_REG]];
-           intpair.lo= *intptr;
-           intpair.hi=0;
-           fladdr= (pdpfloat *)&intpair;
-           from11float(&Srcflt, fladdr);
-           regs[DST_REG] += 2;
-       } else {
-           fladdr = (pdpfloat *)&dspace[regs[DST_REG]];
-           from11float(&Srcflt, fladdr);
-           if (FPMODE) regs[DST_REG] += 8;
-           else regs[DST_REG] += 4;
-       }
-       return;
+        if (DST_REG == PC) {
+            intptr = (u_int16_t *) & ispace[regs[DST_REG]];
+            intpair.lo = *intptr;
+            intpair.hi = 0;
+            fladdr = (pdpfloat *) & intpair;
+            from11float(&Srcflt, fladdr);
+            regs[DST_REG] += 2;
+        } else {
+            fladdr = (pdpfloat *) & dspace[regs[DST_REG]];
+            from11float(&Srcflt, fladdr);
+            if (FPMODE)
+                regs[DST_REG] += 8;
+            else
+                regs[DST_REG] += 4;
+        }
+        return;
     case 3:
-       ll_word(regs[DST_REG], indirect);
-       if (DST_REG == PC) {
-           intptr = (u_int16_t *)&ispace[indirect];
-           intpair.lo= *intptr;
-           intpair.hi=0;
-           fladdr= (pdpfloat *)&intpair;
-           from11float(&Srcflt, fladdr);
-           regs[DST_REG] += 2;
-       } else {
-           fladdr = (pdpfloat *)&dspace[indirect];
-           from11float(&Srcflt, fladdr);
-           if (FPMODE) regs[DST_REG] += 8;
-           else regs[DST_REG] += 4;
-       }
-       return;
+        ll_word(regs[DST_REG], indirect);
+        if (DST_REG == PC) {
+            intptr = (u_int16_t *) & ispace[indirect];
+            intpair.lo = *intptr;
+            intpair.hi = 0;
+            fladdr = (pdpfloat *) & intpair;
+            from11float(&Srcflt, fladdr);
+            regs[DST_REG] += 2;
+        } else {
+            fladdr = (pdpfloat *) & dspace[indirect];
+            from11float(&Srcflt, fladdr);
+            if (FPMODE)
+                regs[DST_REG] += 8;
+            else
+                regs[DST_REG] += 4;
+        }
+        return;
     case 4:
-       if (FPMODE) regs[DST_REG] -= 8;
-       else regs[DST_REG] -= 4;
-       fladdr = (pdpfloat *)&dspace[regs[DST_REG]];
-       from11float(&Srcflt, fladdr);
-       return;
+        if (FPMODE)
+            regs[DST_REG] -= 8;
+        else
+            regs[DST_REG] -= 4;
+        fladdr = (pdpfloat *) & dspace[regs[DST_REG]];
+        from11float(&Srcflt, fladdr);
+        return;
     case 5:
-       if (FPMODE) regs[DST_REG] -= 8;
-       else regs[DST_REG] -= 4;
-       ll_word(regs[DST_REG], indirect);
-       fladdr = (pdpfloat *)&dspace[indirect];
-       from11float(&Srcflt, fladdr);
-       return;
+        if (FPMODE)
+            regs[DST_REG] -= 8;
+        else
+            regs[DST_REG] -= 4;
+        ll_word(regs[DST_REG], indirect);
+        fladdr = (pdpfloat *) & dspace[indirect];
+        from11float(&Srcflt, fladdr);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect= regs[DST_REG] + indirect;
-       fladdr = (pdpfloat *)&dspace[indirect];
-       from11float(&Srcflt, fladdr);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        fladdr = (pdpfloat *) & dspace[indirect];
+        from11float(&Srcflt, fladdr);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-       ll_word(indirect, addr);
-       fladdr = (pdpfloat *)&dspace[addr];
-       from11float(&Srcflt, fladdr);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        fladdr = (pdpfloat *) & dspace[addr];
+        from11float(&Srcflt, fladdr);
+        return;
     }
     illegal();
 }
 
 /* Save (and convert if necessary) Srcflt into the float described by the
  * destination address */
-static void 
-save_flt(void)
+static void save_flt(void)
 {
     u_int16_t indirect;
     u_int16_t addr;
@@ -190,55 +216,65 @@ save_flt(void)
     FpDebug((dbg_file, "\tsave_flt mode %d\n", DST_MODE));
     switch (DST_MODE) {
     case 0:
-       fregs[DST_REG] = Srcflt;
-       return;
+        fregs[DST_REG] = Srcflt;
+        return;
     case 1:
-       fladdr = (pdpfloat *)&dspace[regs[DST_REG]];
-       to11float(&Srcflt, fladdr);
-       return;
+        fladdr = (pdpfloat *) & dspace[regs[DST_REG]];
+        to11float(&Srcflt, fladdr);
+        return;
     case 2:
-       fladdr = (pdpfloat *)&dspace[regs[DST_REG]];
-       to11float(&Srcflt, fladdr);
-       if (DST_REG == PC) regs[DST_REG] += 2;
-       else if (FPMODE) regs[DST_REG] += 8;
-       else regs[DST_REG] += 4;
-       return;
+        fladdr = (pdpfloat *) & dspace[regs[DST_REG]];
+        to11float(&Srcflt, fladdr);
+        if (DST_REG == PC)
+            regs[DST_REG] += 2;
+        else if (FPMODE)
+            regs[DST_REG] += 8;
+        else
+            regs[DST_REG] += 4;
+        return;
     case 3:
-       ll_word(regs[DST_REG], indirect);
-       fladdr = (pdpfloat *)&dspace[indirect];
-       to11float(&Srcflt, fladdr);
-       if (DST_REG == PC) regs[DST_REG] += 2;
-       else if (FPMODE) regs[DST_REG] += 8;
-       else regs[DST_REG] += 4;
-       return;
+        ll_word(regs[DST_REG], indirect);
+        fladdr = (pdpfloat *) & dspace[indirect];
+        to11float(&Srcflt, fladdr);
+        if (DST_REG == PC)
+            regs[DST_REG] += 2;
+        else if (FPMODE)
+            regs[DST_REG] += 8;
+        else
+            regs[DST_REG] += 4;
+        return;
     case 4:
-       if (FPMODE) regs[DST_REG] -= 8;
-       else regs[DST_REG] -= 4;
-       fladdr = (pdpfloat *)&dspace[regs[DST_REG]];
-       to11float(&Srcflt, fladdr);
-       return;
+        if (FPMODE)
+            regs[DST_REG] -= 8;
+        else
+            regs[DST_REG] -= 4;
+        fladdr = (pdpfloat *) & dspace[regs[DST_REG]];
+        to11float(&Srcflt, fladdr);
+        return;
     case 5:
-       if (FPMODE) regs[DST_REG] -= 8;
-       else regs[DST_REG] -= 4;
-       ll_word(regs[DST_REG], indirect);
-       fladdr = (pdpfloat *)&dspace[indirect];
-       to11float(&Srcflt, fladdr);
-       return;
+        if (FPMODE)
+            regs[DST_REG] -= 8;
+        else
+            regs[DST_REG] -= 4;
+        ll_word(regs[DST_REG], indirect);
+        fladdr = (pdpfloat *) & dspace[indirect];
+        to11float(&Srcflt, fladdr);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-       fladdr = (pdpfloat *)&dspace[indirect];
-       to11float(&Srcflt, fladdr);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        fladdr = (pdpfloat *) & dspace[indirect];
+        to11float(&Srcflt, fladdr);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-       ll_word(indirect, addr);
-       fladdr = (pdpfloat *)&dspace[addr];
-       to11float(&Srcflt, fladdr);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        fladdr = (pdpfloat *) & dspace[addr];
+        to11float(&Srcflt, fladdr);
+        return;
     }
     illegal();
 }
@@ -255,366 +291,463 @@ save_flt(void)
 #define sl_long(addr, word) \
        { adptr= (u_int16_t *)&(dspace[addr]); copylong(*adptr, word); } \
 
-static void 
-load_long(void)
+static void load_long(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       srclong = regs[DST_REG];
-       return;
+        srclong = regs[DST_REG];
+        return;
     case 1:
-       addr = regs[DST_REG];
-       if (DST_REG == PC) {
-           lli_long(addr, srclong)
-       } else {
-           ll_long(addr, srclong);
-       }
-       return;
+        addr = regs[DST_REG];
+        if (DST_REG == PC) {
+            lli_long(addr, srclong)
+        } else {
+            ll_long(addr, srclong);
+        }
+        return;
     case 2:
-       addr = regs[DST_REG];
-       if (DST_REG == PC) {
-           lli_long(addr, srclong)
-       } else {
-           ll_long(addr, srclong);
-       }
-       regs[DST_REG] += 4;
-       return;
+        addr = regs[DST_REG];
+        if (DST_REG == PC) {
+            lli_long(addr, srclong)
+        } else {
+            ll_long(addr, srclong);
+        }
+        regs[DST_REG] += 4;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       if (DST_REG == PC) {
-           lli_word(indirect, addr)
-       } else {
-           ll_word(indirect, addr);
-       }
-       regs[DST_REG] += 4;
-       ll_long(addr, srclong);
-       return;
+        indirect = regs[DST_REG];
+        if (DST_REG == PC) {
+            lli_word(indirect, addr)
+        } else {
+            ll_word(indirect, addr);
+        }
+        regs[DST_REG] += 4;
+        ll_long(addr, srclong);
+        return;
     case 4:
-       regs[DST_REG] -= 4;
-       addr = regs[DST_REG];
-       ll_long(addr, srclong);
-       return;
+        regs[DST_REG] -= 4;
+        addr = regs[DST_REG];
+        ll_long(addr, srclong);
+        return;
     case 5:
-       regs[DST_REG] -= 4;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       ll_long(addr, srclong);
-       return;
+        regs[DST_REG] -= 4;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        ll_long(addr, srclong);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       ll_long(addr, srclong);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        ll_long(addr, srclong);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-           ll_word(indirect, addr);
-       ll_long(addr, srclong);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        ll_long(addr, srclong);
+        return;
     }
     illegal();
 }
 
 
-static void 
-store_long(void)
+static void store_long(void)
 {
     u_int16_t addr, indirect;
 
     switch (DST_MODE) {
     case 0:
-       regs[DST_REG]= dstlong;
-       return;
+        regs[DST_REG] = dstlong;
+        return;
     case 1:
-       addr = regs[DST_REG];
-       sl_long(addr, dstlong)
-       return;
+        addr = regs[DST_REG];
+        sl_long(addr, dstlong)
+        return;
     case 2:
-       addr = regs[DST_REG];
-       sl_long(addr, dstlong)
-       regs[DST_REG] += 4;
-       return;
+        addr = regs[DST_REG];
+        sl_long(addr, dstlong)
+        regs[DST_REG] += 4;
+        return;
     case 3:
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       regs[DST_REG] += 4;
-       sl_long(addr, dstlong);
-       return;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        regs[DST_REG] += 4;
+        sl_long(addr, dstlong);
+        return;
     case 4:
-       regs[DST_REG] -= 4;
-       addr = regs[DST_REG];
-       sl_long(addr, dstlong);
-       return;
+        regs[DST_REG] -= 4;
+        addr = regs[DST_REG];
+        sl_long(addr, dstlong);
+        return;
     case 5:
-       regs[DST_REG] -= 4;
-       indirect = regs[DST_REG];
-       ll_word(indirect, addr);
-       sl_long(addr, dstlong);
-       return;
+        regs[DST_REG] -= 4;
+        indirect = regs[DST_REG];
+        ll_word(indirect, addr);
+        sl_long(addr, dstlong);
+        return;
     case 6:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       addr = regs[DST_REG] + indirect;
-       sl_long(addr, dstlong);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        addr = regs[DST_REG] + indirect;
+        sl_long(addr, dstlong);
+        return;
     case 7:
-       lli_word(regs[PC], indirect);
-       regs[PC] += 2;
-       indirect = regs[DST_REG] + indirect;
-       ll_word(indirect, addr);
-       sl_long(addr, dstlong);
-       return;
+        lli_word(regs[PC], indirect);
+        regs[PC] += 2;
+        indirect = regs[DST_REG] + indirect;
+        ll_word(indirect, addr);
+        sl_long(addr, dstlong);
+        return;
     }
     illegal();
 }
 
 
 /* Instruction handlers */
-void
-fpset()
+void fpset()
 {
     switch (ir) {
-       case 0170000:           /* CFCC */
-       CC_C= FPC; CC_V= FPV;
-       CC_Z= FPZ; CC_N= FPN;
-       return;
+    case 0170000:              /* CFCC */
+        CC_C = FPC;
+        CC_V = FPV;
+        CC_Z = FPZ;
+        CC_N = FPN;
+        return;
     case 0170001:              /* SETF */
-       FPMODE=0; return;
+        FPMODE = 0;
+        return;
     case 0170002:              /* SETI */
-       INTMODE=0; return;
+        INTMODE = 0;
+        return;
     case 0170011:              /* SETD */
-       FPMODE=1; return;
+        FPMODE = 1;
+        return;
     case 0170012:              /* SETL */
-       INTMODE=1; return;
+        INTMODE = 1;
+        return;
     default:
-       not_impl();
+        not_impl();
     }
 }
 
-void
-ldf()  /* Load float */
+void ldf()
 {
-  AC= (ir >> 6) & 3;
-  load_flt();
-  fregs[AC]= Srcflt;
-  FPC=0; FPV=0; 
-  if (fregs[AC]==0.0) FPZ=1; else FPZ=0;
-  if (fregs[AC]<0.0)  FPN=1; else FPN=0;
+    /* Load float */
+    AC = (ir >> 6) & 3;
+    load_flt();
+    fregs[AC] = Srcflt;
+    FPC = 0;
+    FPV = 0;
+    if (fregs[AC] == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
+    if (fregs[AC] < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
 }
 
-void
-stf()  /* Store float */
+void stf()
 {
-  AC= (ir >> 6) & 3;
-  Srcflt= fregs[AC];
-  save_flt();
+    /* Store float */
+    AC = (ir >> 6) & 3;
+    Srcflt = fregs[AC];
+    save_flt();
 }
 
 
-void
-clrf() /* Store float */
+void clrf()
 {
-  AC= (ir >> 6) & 3;
-  Srcflt= 0.0;
-  save_flt();
-  FPC= FPZ= FPV= 0; FPZ=1;
+    /* Store float */
+    AC = (ir >> 6) & 3;
+    Srcflt = 0.0;
+    save_flt();
+    FPC = FPZ = FPV = 0;
+    FPZ = 1;
 }
-void
-addf() /* Add float */
+
+void addf()
 {
-  AC= (ir >> 6) & 3;
-  load_flt();
-  fregs[AC]+= Srcflt;
-  FPC=0;
-  if (fregs[AC]>XUL)  FPV=1; else FPV=0;
-  if (fregs[AC]==0.0) FPZ=1; else FPZ=0;
-  if (fregs[AC]<0.0)  FPN=1; else FPN=0;
+    /* Add float */
+    AC = (ir >> 6) & 3;
+    load_flt();
+    fregs[AC] += Srcflt;
+    FPC = 0;
+    if (fregs[AC] > XUL)
+        FPV = 1;
+    else
+        FPV = 0;
+    if (fregs[AC] == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
+    if (fregs[AC] < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
 }
 
-void
-subf() /* Subtract float */
+void subf()
 {
-  AC= (ir >> 6) & 3;
-  load_flt();
-  fregs[AC]-= Srcflt;
-  FPC=0;
-  if (fregs[AC]>XUL)  FPV=1; else FPV=0;
-  if (fregs[AC]==0.0) FPZ=1; else FPZ=0;
-  if (fregs[AC]<0.0)  FPN=1; else FPN=0;
+    /* Subtract float */
+    AC = (ir >> 6) & 3;
+    load_flt();
+    fregs[AC] -= Srcflt;
+    FPC = 0;
+    if (fregs[AC] > XUL)
+        FPV = 1;
+    else
+        FPV = 0;
+    if (fregs[AC] == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
+    if (fregs[AC] < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
 }
 
-void
-negf() /* Negate float */
+void negf()
 {
-  load_flt();
-  fladdr->sign= -(fladdr->sign);
-  FPC=0; FPV=0; 
-  if (Srcflt==0.0) FPZ=1; else FPZ=0;
-  if (Srcflt<0.0)  FPN=1; else FPN=0;
+    /* Negate float */
+    load_flt();
+    fladdr->sign = -(fladdr->sign);
+    FPC = 0;
+    FPV = 0;
+    if (Srcflt == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
+    if (Srcflt < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
 }
 
 
-void
-absf() /* Absolute float */
+void absf()
 {
-  load_flt();
-  fladdr->sign= 0;
-  FPC=0; FPV=0; FPN=0;
-  if (Srcflt==0.0) FPZ=1; else FPZ=0;
+    /* Absolute float */
+    load_flt();
+    fladdr->sign = 0;
+    FPC = 0;
+    FPV = 0;
+    FPN = 0;
+    if (Srcflt == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
 }
 
-void
-mulf() /* Multiply float */
+void mulf()
 {
-  AC= (ir >> 6) & 3;
-  load_flt();
-  fregs[AC]*= Srcflt;
-  FPC=0;
-  if (fregs[AC]>XUL)  FPV=1; else FPV=0;
-  if (fregs[AC]==0.0) FPZ=1; else FPZ=0;
-  if (fregs[AC]<0.0)  FPN=1; else FPN=0;
+    /* Multiply float */
+    AC = (ir >> 6) & 3;
+    load_flt();
+    fregs[AC] *= Srcflt;
+    FPC = 0;
+    if (fregs[AC] > XUL)
+        FPV = 1;
+    else
+        FPV = 0;
+    if (fregs[AC] == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
+    if (fregs[AC] < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
 }
 
 
-void
-moddf() /* Multiply and integerise float */
+void moddf()
 {
-  FLOAT x,y;
-
-  AC= (ir >> 6) & 3;
-  load_flt();
-  fregs[AC]*= Srcflt; y= fregs[AC];
-  if (y>0.0) x= (FLOAT) floor((double)y);
-  else x= (FLOAT) ceil((double)y);
-  fregs[AC|1]= x;
-
-  y=y-x;  fregs[AC]=y;
-
-  FPC=0;
-  if (fregs[AC]>XUL)  FPV=1; else FPV=0;
-  if (fregs[AC]==0.0) FPZ=1; else FPZ=0;
-  if (fregs[AC]<0.0)  FPN=1; else FPN=0;
+    /* Multiply and integerise float */
+    FLOAT x, y;
+
+    AC = (ir >> 6) & 3;
+    load_flt();
+    fregs[AC] *= Srcflt;
+    y = fregs[AC];
+    if (y > 0.0)
+        x = (FLOAT) floor((double) y);
+    else
+        x = (FLOAT) ceil((double) y);
+    fregs[AC | 1] = x;
+
+    y = y - x;
+    fregs[AC] = y;
+
+    FPC = 0;
+    if (fregs[AC] > XUL)
+        FPV = 1;
+    else
+        FPV = 0;
+    if (fregs[AC] == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
+    if (fregs[AC] < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
 }
 
-void
-divf() /* Divide float */
+void divf()
 {
-  AC= (ir >> 6) & 3;
-  load_flt();
-  fregs[AC]/= Srcflt;
-  FPC=0;
-  if (fregs[AC]>XUL)  FPV=1; else FPV=0;
-  if (fregs[AC]==0.0) FPZ=1; else FPZ=0;
-  if (fregs[AC]<0.0)  FPN=1; else FPN=0;
+    /* Divide float */
+    AC = (ir >> 6) & 3;
+    load_flt();
+    fregs[AC] /= Srcflt;
+    FPC = 0;
+    if (fregs[AC] > XUL)
+        FPV = 1;
+    else
+        FPV = 0;
+    if (fregs[AC] == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
+    if (fregs[AC] < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
 }
 
-void
-cmpf() /* Compare float */
+void cmpf()
 {
-  AC= (ir >> 6) & 3;
-  load_flt();
-  FPC=0; FPV=0;
-  if (fregs[AC]>Srcflt)         FPN=1; else FPN=0;
-  if (fregs[AC]==Srcflt) FPZ=1; else FPZ=0;
+    /* Compare float */
+    AC = (ir >> 6) & 3;
+    load_flt();
+    FPC = 0;
+    FPV = 0;
+    if (fregs[AC] > Srcflt)
+        FPN = 1;
+    else
+        FPN = 0;
+    if (fregs[AC] == Srcflt)
+        FPZ = 1;
+    else
+        FPZ = 0;
 }
 
-void
-tstf() /* Test float */
+void tstf()
 {
-  AC= (ir >> 6) & 3;
-  load_flt();
-  FPC=0; FPV=0;
-  if (Srcflt<0.0)  FPN=1; else FPN=0;
-  if (Srcflt==0.0) FPZ=1; else FPZ=0;
+    /* Test float */
+    AC = (ir >> 6) & 3;
+    load_flt();
+    FPC = 0;
+    FPV = 0;
+    if (Srcflt < 0.0)
+        FPN = 1;
+    else
+        FPN = 0;
+    if (Srcflt == 0.0)
+        FPZ = 1;
+    else
+        FPZ = 0;
 }
 
-void
-ldfps() /* Load FPP status */
+void ldfps()
 {
+    /* Load FPP status */
     load_dst();
-    if (dstword & CC_NBIT) CC_N=1;
-    if (dstword & CC_ZBIT) CC_Z=1;
-    if (dstword & CC_VBIT) CC_V=1;
-    if (dstword & CC_CBIT) CC_C=1;
+    if (dstword & CC_NBIT)
+        CC_N = 1;
+    if (dstword & CC_ZBIT)
+        CC_Z = 1;
+    if (dstword & CC_VBIT)
+        CC_V = 1;
+    if (dstword & CC_CBIT)
+        CC_C = 1;
 }
 
-void
-stfps() /* Store FPP status */
+void stfps()
 {
-    srcword=0;
-    if (CC_N) srcword|= CC_NBIT;
-    if (CC_Z) srcword|= CC_ZBIT;
-    if (CC_V) srcword|= CC_VBIT;
-    if (CC_C) srcword|= CC_CBIT;
+    /* Store FPP status */
+    srcword = 0;
+    if (CC_N)
+        srcword |= CC_NBIT;
+    if (CC_Z)
+        srcword |= CC_ZBIT;
+    if (CC_V)
+        srcword |= CC_VBIT;
+    if (CC_C)
+        srcword |= CC_CBIT;
     store_dst();
 }
 
-void
-lcdif() /* Convert int to float */
+void lcdif()
 {
-  AC= (ir >> 6) & 3;
-  if (INTMODE==0) {    /* ints */
-       load_src();
-       fregs[AC]= (float) srcword;
-  } else {
-       load_long();
-       fregs[AC]= (float) srclong;
-  }
+    /* Convert int to float */
+    AC = (ir >> 6) & 3;
+    if (INTMODE == 0) {                /* ints */
+        load_src();
+        fregs[AC] = (float) srcword;
+    } else {
+        load_long();
+        fregs[AC] = (float) srclong;
+    }
 }
 
-void
-stcfi() /* Convert int to float */
+void stcfi()
 {
-  AC= (ir >> 6) & 3;
-  if (INTMODE==0) {    /* ints */
-       dstword= (int16_t) fregs[AC];
-       store_dst();
-  } else {
-       dstlong= (int32_t) fregs[AC];
-       store_long();
-  }
+    /* Convert int to float */
+    AC = (ir >> 6) & 3;
+    if (INTMODE == 0) {                /* ints */
+        dstword = (int16_t) fregs[AC];
+        store_dst();
+    } else {
+        dstlong = (int32_t) fregs[AC];
+        store_long();
+    }
 }
 
-void
-stexp() /* Store exponent */
+void stexp()
 {
- pdpfloat pdptmp;
+    /* Store exponent */
+    pdpfloat pdptmp;
 
AC= (ir >> 6) & 3;
- to11float(&fregs[AC], &pdptmp);
dstword= pdptmp.exp - 128;
- store_dst();
   AC = (ir >> 6) & 3;
   to11float(&fregs[AC], &pdptmp);
   dstword = pdptmp.exp - 128;
   store_dst();
 }
 
 void stcdf()
 {
-       /* Switch FPMODE just while we're saving */
- FPMODE=1 - FPMODE; stf(); FPMODE=1 - FPMODE;
+    /* Switch FPMODE just while we're saving */
+    FPMODE = 1 - FPMODE;
+    stf();
+    FPMODE = 1 - FPMODE;
 }
 
 void ldcdf()
 {
- ldf();
   ldf();
 }
 
 void stst()
 {
-       /* For now */
+    /* For now */
 }
 
 void ldexpp()
 {
- pdpfloat pdptmp;
-
AC= (ir >> 6) & 3;
- to11float(&fregs[AC], &pdptmp);
load_src();                   /* srcword now holds new exponent */
srcword +=128;                        /* Convert to required exponent */
- srcword &= 0xff;
pdptmp.exp= srcword;
- from11float(&fregs[AC], &pdptmp);
   pdpfloat pdptmp;
+
   AC = (ir >> 6) & 3;
   to11float(&fregs[AC], &pdptmp);
   load_src();                        /* srcword now holds new exponent */
   srcword += 128;            /* Convert to required exponent */
   srcword &= 0xff;
   pdptmp.exp = srcword;
   from11float(&fregs[AC], &pdptmp);
 }
diff --git a/itab.c b/itab.c
index 1961f5e..dac8fe8 100644 (file)
--- a/itab.c
+++ b/itab.c
@@ -28,14 +28,12 @@ static _itab sitab1[64] = {
     scc, scc, scc, scc, scc, scc, scc, scc
 };
 
-void 
-dositab0(void)
+void dositab0(void)
 {
     sitab0[ir & 077] ();
 }
 
-void 
-dositab1(void)
+void dositab1(void)
 {
     sitab1[ir & 077] ();
 }
@@ -49,8 +47,9 @@ _itab itab[1024] = {
     clr, com, inc, dec, neg, adc, sbc, tst,
     ror, rol, asr, asl, mark, mfpi, mtpi, sxt,
     illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal,
-    movsreg,movsreg,movsreg,movsreg,movsreg,movsreg,movsreg,movsreg,
-    movsreg1,movsreg1,movsreg1,movsreg1,movsreg1,movsreg1,movsreg1,movsreg1pc,
+    movsreg, movsreg, movsreg, movsreg, movsreg, movsreg, movsreg, movsreg,
+    movsreg1, movsreg1, movsreg1, movsreg1, movsreg1, movsreg1, movsreg1,
+    movsreg1pc,
     mov, mov, mov, mov, mov, mov, mov, mov,
     mov, mov, mov, mov, mov, mov, mov, mov,
     mov, mov, mov, mov, mov, mov, mov, mov,
@@ -110,8 +109,8 @@ _itab itab[1024] = {
     bvc, bvc, bvc, bvc, bvs, bvs, bvs, bvs,
     bcc, bcc, bcc, bcc, bcs, bcs, bcs, bcs,
 
-                       /* emt  at itab[544] to itab[547] */
-                       /* trap at itab[548] to itab[551] */
+    /* emt  at itab[544] to itab[547] */
+    /* trap at itab[548] to itab[551] */
 
     emt, emt, emt, emt, trap, trap, trap, trap,
     clrb, comb, incb, decb, negb, adcb, sbcb, tstb,
diff --git a/ke11a.c b/ke11a.c
index d1db07e..9629888 100644 (file)
--- a/ke11a.c
+++ b/ke11a.c
@@ -31,200 +31,233 @@ void set_SR(void);
 /* Here we define them as int32's, though in real life the MQ and AC */
 /* are 16 bits and the SC and SR are 8 bits */
 
-int32_t MQ;                            /* Multiply quotient */
-int32_t AC;                            /* Accumulator */
-int32_t SC = 0;                                /* Shift counter */
-int32_t SR;                            /* Status register */
+int32_t MQ;                    /* Multiply quotient */
+int32_t AC;                    /* Accumulator */
+int32_t SC = 0;                        /* Shift counter */
+int32_t SR;                    /* Status register */
 
 
 /* Load a word from one of the KE11 registers */
 int16_t kell_word(u_int16_t addr)
 {
-  int16_t data;
-  int pid;
+    int16_t data;
+    int pid;
 
-  switch (addr) {
+    switch (addr) {
     case eae_DIV:
-      data = 0; break;
+        data = 0;
+        break;
     case eae_MQ:
-      data = MQ; break;
-    case eae_AC:                       /* high 16 bits of MQ */
-      data = AC; break;
+        data = MQ;
+        break;
+    case eae_AC:               /* high 16 bits of MQ */
+        data = AC;
+        break;
     case eae_SC:
-      set_SR();
-      data = (SR << 8) | SC; break;
+        set_SR();
+        data = (SR << 8) | SC;
+        break;
     case eae_SR:
-      set_SR();
-      data = (SR << 8); break;
+        set_SR();
+        data = (SR << 8);
+        break;
     case eae_NOR:
-      data = SC; break;
+        data = SC;
+        break;
     case eae_LSH:
     case eae_ASH:
     case eae_MUL:
-      data = 0; break;
+        data = 0;
+        break;
     default:
-      pid = getpid();
-      (void) fprintf(stderr, "Apout - pid %d unknown KE11 register 0%o\n",
-                    pid, addr);
-      exit(EXIT_FAILURE);
-  }
-  return data;
+        pid = getpid();
+        (void) fprintf(stderr,
+                       "Apout - pid %d unknown KE11 register 0%o\n",
+                       pid, addr);
+        exit(EXIT_FAILURE);
+    }
+    return data;
 }
 
 /* Load a byte from one of the KE11 registers */
 int8_t kell_byte(u_int16_t addr)
 {
-  if (addr&1) printf("Hmm, KE11 access on 0%o\n",addr);
-  return ((int8_t) kell_word(addr));
+    if (addr & 1)
+        printf("Hmm, KE11 access on 0%o\n", addr);
+    return ((int8_t) kell_word(addr));
 }
 
 /* Save a word to one of the KE11 registers */
 void kesl_word(u_int16_t addr, u_int16_t word)
 {
-  eae_wr(word, addr, WRITEW);
+    eae_wr(word, addr, WRITEW);
 }
 
 /* Save a byte to one of the KE11 registers */
 void kesl_byte(u_int16_t addr, u_int8_t byte)
 {
-  eae_wr(byte, addr, WRITEB);
+    eae_wr(byte, addr, WRITEB);
 }
 
 void eae_wr(u_int16_t data, u_int16_t PA, int32_t access)
 {
-  int32_t divisor, quotient, remainder;
-  int32_t dividend, product;
-  int32_t oldMQ;
-  int pid;
+    int32_t divisor, quotient, remainder;
+    int32_t dividend, product;
+    int32_t oldMQ;
+    int pid;
 
-  switch (PA) {
+    switch (PA) {
     case eae_DIV:
-      SC = 0;
-      dividend = (AC << 16) | MQ;
-      divisor = data;
-      if (divisor >> 15) divisor = divisor | ~077777;
-      quotient = dividend / divisor;
-      MQ = quotient & 0177777;
-      remainder = dividend % divisor;
-      AC = remainder & 0177777;
-      SR = SR & 076;
-      if ((quotient > 32767) || (quotient < -32768)) { /* did we overflow? */
-       if (dividend < 0) SR = SR | 0100;
-       else SR = SR | 0200;
-      } else {
-       if (quotient < 0) SR = SR | 0300;
-      }
-      return;
+        SC = 0;
+        dividend = (AC << 16) | MQ;
+        divisor = data;
+        if (divisor >> 15)
+            divisor = divisor | ~077777;
+        quotient = dividend / divisor;
+        MQ = quotient & 0177777;
+        remainder = dividend % divisor;
+        AC = remainder & 0177777;
+        SR = SR & 076;
+        if ((quotient > 32767) || (quotient < -32768)) {       /* did we overflow? */
+            if (dividend < 0)
+                SR = SR | 0100;
+            else
+                SR = SR | 0200;
+        } else {
+            if (quotient < 0)
+                SR = SR | 0300;
+        }
+        return;
     case eae_AC:
-      AC = data;
-      if ((access == WRITEB) & (data >> 7))
-       AC = AC | 0177400;
-      return;
+        AC = data;
+        if ((access == WRITEB) & (data >> 7))
+            AC = AC | 0177400;
+        return;
     case eae_AC + 1:
-      printf("write to AC+1; data=%o", data);
-      AC = (AC & 0377) | (data << 8);
-      return;
+        printf("write to AC+1; data=%o", data);
+        AC = (AC & 0377) | (data << 8);
+        return;
     case eae_MQ:
-      MQ = data;
-      if ((access == WRITEB) & (data >> 7)) MQ = MQ | 0177400;
-      if (MQ >> 15) AC = 0177777;
-      else AC = 0;
-      return;
+        MQ = data;
+        if ((access == WRITEB) & (data >> 7))
+            MQ = MQ | 0177400;
+        if (MQ >> 15)
+            AC = 0177777;
+        else
+            AC = 0;
+        return;
     case eae_MQ + 1:
-      printf("write to MQ+1; data=%o", data);
-      MQ = (MQ & 0377) | (data << 8);
-      if (MQ >> 15) AC = 0177777;
-      else AC = 0;
-      return;
+        printf("write to MQ+1; data=%o", data);
+        MQ = (MQ & 0377) | (data << 8);
+        if (MQ >> 15)
+            AC = 0177777;
+        else
+            AC = 0;
+        return;
     case eae_MUL:
-      SC = 0;
-      if (data >> 15) data = data | ~077777;
-      if (MQ >> 15) MQ = MQ | ~077777;
-      product = MQ * data;
-      MQ = product & 0177777;
-      AC = (product >> 16) & 0177777;
-      SR = SR & 076;
-      if (AC >> 15) SR = SR | 0300;    /* set sign bit if necessary */
-      return;
+        SC = 0;
+        if (data >> 15)
+            data = data | ~077777;
+        if (MQ >> 15)
+            MQ = MQ | ~077777;
+        product = MQ * data;
+        MQ = product & 0177777;
+        AC = (product >> 16) & 0177777;
+        SR = SR & 076;
+        if (AC >> 15)
+            SR = SR | 0300;    /* set sign bit if necessary */
+        return;
     case eae_SC:
-      if (access == WRITEB) return;    /* byte writes are no-ops */
-      SR = (data >> 8) & 0177777;
-      SC = data & 0000077;
-      return;
+        if (access == WRITEB)
+            return;            /* byte writes are no-ops */
+        SR = (data >> 8) & 0177777;
+        SC = data & 0000077;
+        return;
     case eae_SR:
-      return;                          /* this is a No-op */
-    case eae_NOR:                      /* Normalize */
-      MQ = (AC << 16) | MQ;            /* 32-bit number to normalize in MQ */
-      for (SC = 0; SC < 31; SC++) {
-       if (MQ == (0140000 << 16))
-         break;
-       if ((((MQ >> 30) & 3) == 1) || (((MQ >> 30) & 3) == 2))
-         break;
-       MQ = MQ << 1;
-      }
-      printf("SC = %o\r\n", SC);
-      AC = (MQ >> 16) & 0177777;
-      MQ = MQ & 0177777;
-      return;
-    case eae_LSH:                      /* Logical shift */
-       MQ=(AC<<16)|MQ;                         /* Form a temporary 32-bit entity */
-       oldMQ=MQ & 0x80000000;          /* Save the sign bit for later */
-       SR=SR&0176;                     /* Clear overflow & carry bits */
-       data=data & 077;                        /* Convert data from 6-bit */
-       if (data>31) {          
-        data=64-data;                  /* Shift in a -ve direction */
-         SR=SR|((MQ>>(data-1))&1);     /* Get the bit that went off the end */
-         MQ=MQ>>data;                  /* and do the right shift */
-       } else {                                /* Else left shift */
-        if ((MQ<<(data-1))&0x80000000) SR|=1; /* Get the bit off the end */
-        MQ=MQ<<data;                   /* and do the left shift */
-       }
-       oldMQ= oldMQ ^ MQ;              /* Any difference in sign bit? */
-       if (oldMQ & 0x80000000) SR|=0200;/* Yes, set the overflow bit */
-       AC=(MQ>>16)&0177777;            /* Save result in AC and MQ */
-       MQ=MQ&0177777;
-       set_SR();
-       return;
-
-    case eae_ASH:                      /* Arithmetic shift */
-       MQ=(AC<<16)|MQ;                         /* Form a temporary 32-bit entity */
-       oldMQ=MQ & 0x80000000;          /* Save the sign bit for later */
-       SR=SR&0176;                     /* Clear overflow & carry bits */
-       data=data & 077;                        /* Convert data from 6-bit */
-       if (data>31) {          
-        data=64-data;                  /* Shift in a -ve direction */
-        divisor=1 << data;             /* Work out the dividing factor */
-         SR=SR|((MQ>>(data-1))&1);     /* Get the bit that went off the end */
-         MQ=MQ/divisor;                /* and do the right shift */
-       } else {                                /* Else left shift */
-        product=1 << data;             /* Work out the multiplying factor */
-        if ((MQ<<(data-1))&0x80000000) SR|=1; /* Get the bit off the end */
-        MQ=MQ*product;                 /* and do the left shift */
-       }
-       oldMQ= oldMQ ^ MQ;              /* Any difference in sign bit? */
-       if (oldMQ & 0x80000000) SR|=0200;/* Yes, set the overflow bit */
-       AC=(MQ>>16)&0177777;            /* Save result in AC and MQ */
-       MQ=MQ&0177777;
-       set_SR();
-       return;
+        return;                /* this is a No-op */
+    case eae_NOR:              /* Normalize */
+        MQ = (AC << 16) | MQ;  /* 32-bit number to normalize in MQ */
+        for (SC = 0; SC < 31; SC++) {
+            if (MQ == (0140000 << 16))
+                break;
+            if ((((MQ >> 30) & 3) == 1) || (((MQ >> 30) & 3) == 2))
+                break;
+            MQ = MQ << 1;
+        }
+        printf("SC = %o\r\n", SC);
+        AC = (MQ >> 16) & 0177777;
+        MQ = MQ & 0177777;
+        return;
+    case eae_LSH:              /* Logical shift */
+        MQ = (AC << 16) | MQ;  /* Form a temporary 32-bit entity */
+        oldMQ = MQ & 0x80000000;       /* Save the sign bit for later */
+        SR = SR & 0176;        /* Clear overflow & carry bits */
+        data = data & 077;     /* Convert data from 6-bit */
+        if (data > 31) {
+            data = 64 - data;  /* Shift in a -ve direction */
+            SR = SR | ((MQ >> (data - 1)) & 1);        /* Get the bit that went off the end */
+            MQ = MQ >> data;   /* and do the right shift */
+        } else {               /* Else left shift */
+            if ((MQ << (data - 1)) & 0x80000000)
+                SR |= 1;       /* Get the bit off the end */
+            MQ = MQ << data;   /* and do the left shift */
+        }
+        oldMQ = oldMQ ^ MQ;    /* Any difference in sign bit? */
+        if (oldMQ & 0x80000000)
+            SR |= 0200;        /* Yes, set the overflow bit */
+        AC = (MQ >> 16) & 0177777;     /* Save result in AC and MQ */
+        MQ = MQ & 0177777;
+        set_SR();
+        return;
+
+    case eae_ASH:              /* Arithmetic shift */
+        MQ = (AC << 16) | MQ;  /* Form a temporary 32-bit entity */
+        oldMQ = MQ & 0x80000000;       /* Save the sign bit for later */
+        SR = SR & 0176;        /* Clear overflow & carry bits */
+        data = data & 077;     /* Convert data from 6-bit */
+        if (data > 31) {
+            data = 64 - data;  /* Shift in a -ve direction */
+            divisor = 1 << data;       /* Work out the dividing factor */
+            SR = SR | ((MQ >> (data - 1)) & 1);        /* Get the bit that went off the end */
+            MQ = MQ / divisor; /* and do the right shift */
+        } else {               /* Else left shift */
+            product = 1 << data;       /* Work out the multiplying factor */
+            if ((MQ << (data - 1)) & 0x80000000)
+                SR |= 1;       /* Get the bit off the end */
+            MQ = MQ * product; /* and do the left shift */
+        }
+        oldMQ = oldMQ ^ MQ;    /* Any difference in sign bit? */
+        if (oldMQ & 0x80000000)
+            SR |= 0200;        /* Yes, set the overflow bit */
+        AC = (MQ >> 16) & 0177777;     /* Save result in AC and MQ */
+        MQ = MQ & 0177777;
+        set_SR();
+        return;
 
     default:
-      pid = getpid();
-      (void) fprintf(stderr, "Apout - pid %d unknown KE11 register 0%o\n",
-                    pid, PA);
-      exit(EXIT_FAILURE);
-  }
+        pid = getpid();
+        (void) fprintf(stderr,
+                       "Apout - pid %d unknown KE11 register 0%o\n",
+                       pid, PA);
+        exit(EXIT_FAILURE);
+    }
 }
 
 void set_SR(void)
 {
-  SR = SR & 0301;              /* clear the result bits we can set here */
-  if (((MQ & 0100000) == 0) && (AC == 0)) SR = SR | 002;
-  if (((MQ & 0100000) == 0100000) && (AC == 0177777)) SR = SR | 002;
-
-  if ((AC == 0) && (MQ == 0)) SR = SR | 0004;
-  if (MQ == 0) SR = SR | 0010;
-  if (AC == 0) SR = SR | 0020;
-  if (AC == 0177777) SR = SR | 0040;
+    SR = SR & 0301;            /* clear the result bits we can set here */
+    if (((MQ & 0100000) == 0) && (AC == 0))
+        SR = SR | 002;
+    if (((MQ & 0100000) == 0100000) && (AC == 0177777))
+        SR = SR | 002;
+
+    if ((AC == 0) && (MQ == 0))
+        SR = SR | 0004;
+    if (MQ == 0)
+        SR = SR | 0010;
+    if (AC == 0)
+        SR = SR | 0020;
+    if (AC == 0177777)
+        SR = SR | 0040;
 }
-#endif /* EMUV1 */
+#endif                         /* EMUV1 */
diff --git a/magic.c b/magic.c
index 7368240..d5bb97a 100644 (file)
--- a/magic.c
+++ b/magic.c
 #include "defines.h"
 
 struct spec_aout {
-       u_int32_t cksum;
-       int environment;
+    u_int32_t cksum;
+    int environment;
 };
 
-static struct spec_aout S[]= {
-       { 0x1042c2, IS_V6 },    /* V6 bin/dc */
-       { 0x10f02, IS_V5 },     /* V5 etc/update */
-       { 0x11002, IS_V5 },     /* V5 bin/clri */
-       { 0x1117c2, IS_V7 },    /* V7 bin/roff */
-       { 0x11702, IS_V6 },     /* V6 etc/update */
-       { 0x11a82, IS_V5 },     /* V5 bin/sum */
-       { 0x1319c2, IS_V5 },    /* V5 usr/fort/fc1 */
-       { 0x1332c2, IS_V2 },    /* /lib/c0 dated Jun 30 1973 from s2 tape */
-       { 0x13642, IS_V5 },     /* V5 bin/rew */
-       { 0x139e02, IS_V5 },    /* V5 bin/dc */
-       { 0x13c0, IS_V6 },      /* V6 usr/lib/tmgc */
-       { 0x14042, IS_V6 },     /* V6 bin/tty */
-       { 0x143c2, IS_V5 },     /* V5 bin/tty */
-       { 0x152ac2, IS_V6 },    /* V6 usr/lib/tmg */
-       { 0x15f42, IS_V5 },     /* V5 bin/kill */
-       { 0x16802, IS_V5 },     /* V5 bin/dsw */
-       { 0x16902, IS_V5 },     /* V5 bin/mkdir */
-       { 0x1720c2, IS_V6 },    /* V6 bin/cdb */
-       { 0x17742, IS_V5 },     /* V5 usr/bin/pfe */
-       { 0x17cc2, IS_V5 },     /* V5 usr/bin/mesg */
-       { 0x18702, IS_V5 },     /* V5 bin/rmdir */
-       { 0x194c2, IS_V6 },     /* V6 bin/chgrp */
-       { 0x197c2, IS_V6 },     /* V6 bin/chown */
-       { 0x19a42, IS_V5 },     /* V5 bin/chown */
-       { 0x19b342, IS_V6 },    /* V6 usr/bin/nroff */
-       { 0x19f682, IS_V6 },    /* V6 usr/fort/fc1 */
-       { 0x1ae00,  IS_V2 },    /* V2 bin/strip */
-       { 0x1b102, IS_V5 },     /* V5 bin/strip */
-       { 0x1ba02, IS_V6 },     /* V6 bin/strip */
-       { 0x1c342, IS_V5 },     /* V5 bin/cat */
-       { 0x1c8442, IS_V7 },    /* V7 usr/games/maze */
-       { 0x1cc782, IS_V6 },    /* V6 lib/fc0 */
-       { 0x1dfc2, IS_V5 },     /* V5 etc/getty */
-       { 0x1f9c2, IS_V2 },     /* /bin/nm dated Jun 30 1973 from s2 tape */
-       { 0x20202, IS_V5 },     /* V5 usr/games/bj */
-       { 0x21e42, IS_V6 },     /* V6 usr/bin/units */
-       { 0x23f82, IS_V5 },     /* V5 usr/bin/passwd */
-       { 0x260642, IS_V6 },    /* V6 lib/fc1 */
-       { 0x262a82, IS_211BSD }, /* 2.11 usr/new/m11 */
-       { 0x27e82, IS_V5 },     /* V5 usr/bin/grep */
-       { 0x290c2, IS_V7 },     /* V7 usr/games/cubic */
-       { 0x299c2, IS_V5 },     /* V5 usr/games/cubic */
-       { 0x2f482, IS_V5 },     /* V5 usr/bin/form */
-       { 0x3382, IS_V6 },      /* V6 bin/write */
-       { 0x326642, IS_V7 },    /* 2.9 awk */
-       { 0x33c42, IS_211BSD }, /* 2.11 usr/games/moo */
-       { 0x351382, IS_211BSD }, /* 2.11 usr/games/lib/zork */
-       { 0x3702, IS_V5 },      /* V5 usr/games/moo */
-       { 0x3b402, IS_V5 },     /* V5 bin/ar */
-       { 0x3cc02, IS_V2 },     /* /bin/size from from s2 tape */
-       { 0x4382, IS_V5 },      /* V5 bin/write */
-       { 0x451f42, IS_V7 },    /* 2.9 /lib/c1 */
-       { 0x47042, IS_211BSD }, /* 2.11 usr/games/ttt */
-       { 0x4fa02, IS_V5 },     /* V5 bin/ld */
-       { 0x51342, IS_211BSD }, /* 2.11 usr/games/bj */
-       { 0x53302, IS_V6 },     /* V6 usr/lib/suftab */
-       { 0x55882, IS_V7 },     /* 2.9 /bin/as */
-       { 0x54702, IS_V5 },     /* V5 usr/games/ttt */
-       { 0x55702, IS_V7 },     /* V7 bin/as */
-       { 0x5c342, IS_V2 },    /* /bin/cc dated Jun 30 1973 from s2 tape */
-       { 0x6f742, IS_V6 },     /* V6 usr/bin/sa */
-       { 0x7042, IS_V7 },      /* V7 bin/factor */
-       { 0x71702, IS_V7 },     /* V7 lib/as2 */
-       { 0x7342, IS_V5 },      /* V5 bin/du */
-       { 0x73782, IS_V7},      /* 2.9 /lib/as2 */
-       { 0x73e00, IS_V2 },     /* /bin/ld from s2 tape */
-       { 0x7a242, IS_V6 },     /* V6 lib/as2 */
-       { 0x7b102, IS_V6 },     /* V6 bin/as */
-       { 0x7d082, IS_V5 },     /* V5 bin/as */
-       { 0x7d6844, IS_V1 },    /* bin/cal from s2 tape */
-       { 0x7d942, IS_V5 },     /* V5 lib/as2 */
-       { 0x8002, IS_V5 },      /* V5 etc/lpd */
-       { 0x85842, IS_V5 },     /* V5 bin/ed */
-       { 0x8f00, IS_V6 },      /* V6 usr/lib/tmga */
-       { 0x915c2, IS_V6 },     /* V6 bin/bas */
-       { 0x94542, IS_V5 },     /* V5 bin/db */
-       { 0x98442, IS_V6 },     /* V6 usr/bin/ac */
-       { 0x9adc2, IS_V6 },     /* V6 bin/db */
-       { 0xa242, IS_V7 },      /* V7 bin/primes */
-       { 0xa4602, IS_V2 },     /* /bin/as from s2 tape */
-       { 0xa702, IS_V5 },      /* V5 bin/time */
-       { 0xad882, IS_V7 },     /* V7 bin/bas */
-       { 0xadc42, IS_V2 },     /* /usr/lib/c1 from s2 tape */
-       { 0xb5a82, IS_V6 },     /* V6 usr/bin/prof */
-       { 0xc1e42, IS_V5 },     /* V5 usr/bin/fed */
-       { 0xc3102, IS_V6 },     /* V6 bin/tp */
-       { 0xc8bc2, IS_V5 },     /* V5 bin/tp */
-       { 0xe1642, IS_V6 },     /* V6 usr/bin/roff */
-       { 0xe1f42, IS_V5 },     /* V5 usr/bin/roff */
-       { 0xec582, IS_V5 },     /* V5 bin/bas */
-       { 0xfc2, IS_V6 },       /* V6 usr/bin/typo */
-       { 0xfc002, IS_V2 },     /* /bin/as dated Jun 30 1973 from s2 tape */
-       { 0x38ec0, IS_V5 },     /* V5 bin/ar, Warrens */
-       { 0, 0 }
+static struct spec_aout S[] = {
+    {0x1042c2, IS_V6},         /* V6 bin/dc */
+    {0x10f02, IS_V5},          /* V5 etc/update */
+    {0x11002, IS_V5},          /* V5 bin/clri */
+    {0x1117c2, IS_V7},         /* V7 bin/roff */
+    {0x11702, IS_V6},          /* V6 etc/update */
+    {0x11a82, IS_V5},          /* V5 bin/sum */
+    {0x1319c2, IS_V5},         /* V5 usr/fort/fc1 */
+    {0x1332c2, IS_V2},         /* /lib/c0 dated Jun 30 1973 from s2 tape */
+    {0x13642, IS_V5},          /* V5 bin/rew */
+    {0x139e02, IS_V5},         /* V5 bin/dc */
+    {0x13c0, IS_V6},           /* V6 usr/lib/tmgc */
+    {0x14042, IS_V6},          /* V6 bin/tty */
+    {0x143c2, IS_V5},          /* V5 bin/tty */
+    {0x152ac2, IS_V6},         /* V6 usr/lib/tmg */
+    {0x15f42, IS_V5},          /* V5 bin/kill */
+    {0x16802, IS_V5},          /* V5 bin/dsw */
+    {0x16902, IS_V5},          /* V5 bin/mkdir */
+    {0x1720c2, IS_V6},         /* V6 bin/cdb */
+    {0x17742, IS_V5},          /* V5 usr/bin/pfe */
+    {0x17cc2, IS_V5},          /* V5 usr/bin/mesg */
+    {0x18702, IS_V5},          /* V5 bin/rmdir */
+    {0x194c2, IS_V6},          /* V6 bin/chgrp */
+    {0x197c2, IS_V6},          /* V6 bin/chown */
+    {0x19a42, IS_V5},          /* V5 bin/chown */
+    {0x19b342, IS_V6},         /* V6 usr/bin/nroff */
+    {0x19f682, IS_V6},         /* V6 usr/fort/fc1 */
+    {0x1ae00, IS_V2},          /* V2 bin/strip */
+    {0x1b102, IS_V5},          /* V5 bin/strip */
+    {0x1ba02, IS_V6},          /* V6 bin/strip */
+    {0x1c342, IS_V5},          /* V5 bin/cat */
+    {0x1c8442, IS_V7},         /* V7 usr/games/maze */
+    {0x1cc782, IS_V6},         /* V6 lib/fc0 */
+    {0x1dfc2, IS_V5},          /* V5 etc/getty */
+    {0x1f9c2, IS_V2},          /* /bin/nm dated Jun 30 1973 from s2 tape */
+    {0x20202, IS_V5},          /* V5 usr/games/bj */
+    {0x21e42, IS_V6},          /* V6 usr/bin/units */
+    {0x23f82, IS_V5},          /* V5 usr/bin/passwd */
+    {0x260642, IS_V6},         /* V6 lib/fc1 */
+    {0x262a82, IS_211BSD},     /* 2.11 usr/new/m11 */
+    {0x27e82, IS_V5},          /* V5 usr/bin/grep */
+    {0x290c2, IS_V7},          /* V7 usr/games/cubic */
+    {0x299c2, IS_V5},          /* V5 usr/games/cubic */
+    {0x2f482, IS_V5},          /* V5 usr/bin/form */
+    {0x3382, IS_V6},           /* V6 bin/write */
+    {0x326642, IS_V7},         /* 2.9 awk */
+    {0x33c42, IS_211BSD},      /* 2.11 usr/games/moo */
+    {0x351382, IS_211BSD},     /* 2.11 usr/games/lib/zork */
+    {0x3702, IS_V5},           /* V5 usr/games/moo */
+    {0x3b402, IS_V5},          /* V5 bin/ar */
+    {0x3cc02, IS_V2},          /* /bin/size from from s2 tape */
+    {0x4382, IS_V5},           /* V5 bin/write */
+    {0x451f42, IS_V7},         /* 2.9 /lib/c1 */
+    {0x47042, IS_211BSD},      /* 2.11 usr/games/ttt */
+    {0x4fa02, IS_V5},          /* V5 bin/ld */
+    {0x51342, IS_211BSD},      /* 2.11 usr/games/bj */
+    {0x53302, IS_V6},          /* V6 usr/lib/suftab */
+    {0x55882, IS_V7},          /* 2.9 /bin/as */
+    {0x54702, IS_V5},          /* V5 usr/games/ttt */
+    {0x55702, IS_V7},          /* V7 bin/as */
+    {0x5c342, IS_V2},          /* /bin/cc dated Jun 30 1973 from s2 tape */
+    {0x6f742, IS_V6},          /* V6 usr/bin/sa */
+    {0x7042, IS_V7},           /* V7 bin/factor */
+    {0x71702, IS_V7},          /* V7 lib/as2 */
+    {0x7342, IS_V5},           /* V5 bin/du */
+    {0x73782, IS_V7},          /* 2.9 /lib/as2 */
+    {0x73e00, IS_V2},          /* /bin/ld from s2 tape */
+    {0x7a242, IS_V6},          /* V6 lib/as2 */
+    {0x7b102, IS_V6},          /* V6 bin/as */
+    {0x7d082, IS_V5},          /* V5 bin/as */
+    {0x7d6844, IS_V1},         /* bin/cal from s2 tape */
+    {0x7d942, IS_V5},          /* V5 lib/as2 */
+    {0x8002, IS_V5},           /* V5 etc/lpd */
+    {0x85842, IS_V5},          /* V5 bin/ed */
+    {0x8f00, IS_V6},           /* V6 usr/lib/tmga */
+    {0x915c2, IS_V6},          /* V6 bin/bas */
+    {0x94542, IS_V5},          /* V5 bin/db */
+    {0x98442, IS_V6},          /* V6 usr/bin/ac */
+    {0x9adc2, IS_V6},          /* V6 bin/db */
+    {0xa242, IS_V7},           /* V7 bin/primes */
+    {0xa4602, IS_V2},          /* /bin/as from s2 tape */
+    {0xa702, IS_V5},           /* V5 bin/time */
+    {0xad882, IS_V7},          /* V7 bin/bas */
+    {0xadc42, IS_V2},          /* /usr/lib/c1 from s2 tape */
+    {0xb5a82, IS_V6},          /* V6 usr/bin/prof */
+    {0xc1e42, IS_V5},          /* V5 usr/bin/fed */
+    {0xc3102, IS_V6},          /* V6 bin/tp */
+    {0xc8bc2, IS_V5},          /* V5 bin/tp */
+    {0xe1642, IS_V6},          /* V6 usr/bin/roff */
+    {0xe1f42, IS_V5},          /* V5 usr/bin/roff */
+    {0xec582, IS_V5},          /* V5 bin/bas */
+    {0xfc2, IS_V6},            /* V6 usr/bin/typo */
+    {0xfc002, IS_V2},          /* /bin/as dated Jun 30 1973 from s2 tape */
+    {0x38ec0, IS_V5},          /* V5 bin/ar, Warrens */
+    {0, 0}
 };
 
 /* cptr points at the start of the a.out header */
-int special_magic(u_int16_t *cptr)
+int special_magic(u_int16_t * cptr)
 {
-    u_int32_t cksum=0;
+    u_int32_t cksum = 0;
     int i;
     char *unix_version;
 
-    if (cptr==NULL) return(IS_UNKNOWN);
-                               /* Calculate the checksum */
-    for (i=0;i<8; i++) { cksum ^= cptr[i]; cksum = cksum<<1; }
-
-                               /* Try and find a match */
-    for (i=0; S[i].cksum!=0; i++) if (S[i].cksum==cksum) {
-      TrapDebug((dbg_file, "This a.out has special magic %d\n",i));
-      return(S[i].environment);
+    if (cptr == NULL)
+        return (IS_UNKNOWN);
+    /* Calculate the checksum */
+    for (i = 0; i < 8; i++) {
+        cksum ^= cptr[i];
+        cksum = cksum << 1;
     }
 
-                               /* See if user tells us what version to use */
+    /* Try and find a match */
+    for (i = 0; S[i].cksum != 0; i++)
+        if (S[i].cksum == cksum) {
+            TrapDebug((dbg_file, "This a.out has special magic %d\n", i));
+            return (S[i].environment);
+        }
+
+    /* See if user tells us what version to use */
     if ((unix_version = getenv("APOUT_UNIX_VERSION"))) {
-       if (!strcmp(unix_version, "V1")) return(IS_V1);
-       if (!strcmp(unix_version, "V2")) return(IS_V2);
-       if (!strcmp(unix_version, "V3")) return(IS_V3);
-       if (!strcmp(unix_version, "V4")) return(IS_V4);
-       if (!strcmp(unix_version, "V5")) return(IS_V5);
-       if (!strcmp(unix_version, "V6")) return(IS_V6);
-       if (!strcmp(unix_version, "V7")) return(IS_V7);
-       if (!strcmp(unix_version, "2.9BSD")) return(IS_29BSD);
-       if (!strcmp(unix_version, "2.11BSD")) return(IS_211BSD);
+        if (!strcmp(unix_version, "V1"))
+            return (IS_V1);
+        if (!strcmp(unix_version, "V2"))
+            return (IS_V2);
+        if (!strcmp(unix_version, "V3"))
+            return (IS_V3);
+        if (!strcmp(unix_version, "V4"))
+            return (IS_V4);
+        if (!strcmp(unix_version, "V5"))
+            return (IS_V5);
+        if (!strcmp(unix_version, "V6"))
+            return (IS_V6);
+        if (!strcmp(unix_version, "V7"))
+            return (IS_V7);
+        if (!strcmp(unix_version, "2.9BSD"))
+            return (IS_29BSD);
+        if (!strcmp(unix_version, "2.11BSD"))
+            return (IS_211BSD);
     }
 
-                       /* We can't tell what version of Unix, give up */
-    (void)printf("Apout - unknown magic in header: 0x%x\n",cksum);
-    return(IS_UNKNOWN);
+    /* We can't tell what version of Unix, give up */
+    (void) printf("Apout - unknown magic in header: 0x%x\n", cksum);
+    return (IS_UNKNOWN);
 }
diff --git a/main.c b/main.c
index 1d1fc72..4af50b3 100644 (file)
--- a/main.c
+++ b/main.c
  * descriptors. Only fds which are not ttys have FILE * pointers
  */
 FILE *stream[NFILE];
-char *streammode[NFILE]; /* Mode for each file - used for dup */
-
-                               /* The following two buffers are used as */
-                               /* part of the translation from virtal */
-                               /* absolute filenames to native ones. We */
-                               /* only have 2 buffers, so if you call */
-                               /* xlate_filename() 3 times, the 1st return */
-                               /* value will be destroyed. */
+char *streammode[NFILE];       /* Mode for each file - used for dup */
+
+/* The following two buffers are used as */
+/* part of the translation from virtal */
+/* absolute filenames to native ones. We */
+/* only have 2 buffers, so if you call */
+/* xlate_filename() 3 times, the 1st return */
+/* value will be destroyed. */
 static char realfilename[2][2 * MAXPATHLEN];
 static char *rfn[2];
-static int whichrfn=0;
-char *apout_root=NULL;         /* Root dir for simulated a.out */
+static int whichrfn = 0;
+char *apout_root = NULL;       /* Root dir for simulated a.out */
 
 #ifdef DEBUG
-                               /* Debugging flags */
-int inst_debug= 0,             /* Print a line before each instruction */
-    trap_debug= 0,             /* Print details of each trap */
-    jsr_debug= 0,              /* Print out each jsr */
-    fp_debug 0;              /* Print out each floating-point instruction */
+/* Debugging flags */
+int inst_debug = 0,            /* Print a line before each instruction */
+    trap_debug = 0,            /* Print details of each trap */
+    jsr_debug = 0,             /* Print out each jsr */
+    fp_debug = 0;              /* Print out each floating-point instruction */
 FILE *dbg_file = NULL;         /* Debugging output file */
 char *progname = NULL;         /* The program's name - used in debugging */
 #endif
 
 void usage()
 {
-  fprintf(stderr, "Usage: apout");
+    fprintf(stderr, "Usage: apout");
 #ifdef DEBUG
-  fprintf(stderr, " [-inst] [-trap] [-jsr] [-fp]");
+    fprintf(stderr, " [-inst] [-trap] [-jsr] [-fp]");
 #endif
-  fprintf(stderr, " pdp11_binary\n");
-  exit(1);
+    fprintf(stderr, " pdp11_binary\n");
+    exit(1);
 }
 
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
 {
     int i;
 
     /* Ensure, before we start, that certain types are right */
-    assert(sizeof(int8_t)==1);  assert(sizeof(u_int8_t)==1);
-    assert(sizeof(int16_t)==2); assert(sizeof(u_int16_t)==2);
-    assert(sizeof(int32_t)==4); assert(sizeof(u_int32_t)==4);
-
-    if (argc < 2) usage();
-    if (!strcmp(argv[1], "-help")) usage();
-    if (!strcmp(argv[1], "--help")) usage();
+    assert(sizeof(int8_t) == 1);
+    assert(sizeof(u_int8_t) == 1);
+    assert(sizeof(int16_t) == 2);
+    assert(sizeof(u_int16_t) == 2);
+    assert(sizeof(int32_t) == 4);
+    assert(sizeof(u_int32_t) == 4);
+
+    if (argc < 2)
+        usage();
+    if (!strcmp(argv[1], "-help"))
+        usage();
+    if (!strcmp(argv[1], "--help"))
+        usage();
 
 #ifdef DEBUG
     while (1) {
-      if (!strcmp(argv[1], "-inst"))
-               { inst_debug = 1; argc--; argv++; continue; }
-      if (!strcmp(argv[1], "-trap"))
-               { trap_debug = 1; argc--; argv++; continue; }
-      if (!strcmp(argv[1], "-jsr"))
-               { jsr_debug = 1; argc--; argv++; continue; }
-      if (!strcmp(argv[1], "-fp"))
-               { fp_debug = 1; argc--; argv++; continue; }
-      break;
+        if (!strcmp(argv[1], "-inst")) {
+            inst_debug = 1;
+            argc--;
+            argv++;
+            continue;
+        }
+        if (!strcmp(argv[1], "-trap")) {
+            trap_debug = 1;
+            argc--;
+            argv++;
+            continue;
+        }
+        if (!strcmp(argv[1], "-jsr")) {
+            jsr_debug = 1;
+            argc--;
+            argv++;
+            continue;
+        }
+        if (!strcmp(argv[1], "-fp")) {
+            fp_debug = 1;
+            argc--;
+            argv++;
+            continue;
+        }
+        break;
     }
-    if (inst_debug|trap_debug|jsr_debug|fp_debug)
-                               dbg_file = fopen("apout.dbg", "w");
+    if (inst_debug | trap_debug | jsr_debug | fp_debug)
+        dbg_file = fopen("apout.dbg", "w");
 #endif
 
-                               /* Prepare arg list for emulated environment */
-    argc--; argv++;
-    Argc= argc; Envp[0]=NULL;
-    for (i=0; i<argc; i++) Argv[i]= argv[i];
-
-                               /* Initialise the stream pointers */
-    for (i=3; i<NFILE; i++) { stream[i]=NULL; streammode[i]=NULL; }
-    stream[0]=stdin;  streammode[0]="r";
-    stream[1]=stdout; streammode[1]="w";
-    stream[2]=stderr; streammode[2]="w";
-
-                                /* Set the translation to a fictitious */
-                                /* root filesystem */
-    if ((apout_root = getenv("APOUT_ROOT"))) {  
-       set_apout_root(apout_root);
+    /* Prepare arg list for emulated environment */
+    argc--;
+    argv++;
+    Argc = argc;
+    Envp[0] = NULL;
+    for (i = 0; i < argc; i++)
+        Argv[i] = argv[i];
+
+    /* Initialise the stream pointers */
+    for (i = 3; i < NFILE; i++) {
+        stream[i] = NULL;
+        streammode[i] = NULL;
+    }
+    stream[0] = stdin;
+    streammode[0] = "r";
+    stream[1] = stdout;
+    streammode[1] = "w";
+    stream[2] = stderr;
+    streammode[2] = "w";
+
+    /* Set the translation to a fictitious */
+    /* root filesystem */
+    if ((apout_root = getenv("APOUT_ROOT"))) {
+        set_apout_root(apout_root);
     } else {
 #ifdef APOUT_DONT_ASSUME_ROOT
-        fprintf(stderr,                 
+        fprintf(stderr,
                 "APOUT_ROOT env variable not set before running apout\n");
         exit(1);
 #else
-                               set_apout_root("/");
+        set_apout_root("/");
 #endif
-               }   
+    }
 
-                               /* Try to load the binary as an a.out */
-    if (load_a_out(argv[0],NULL,1) == -1) {
-       fprintf(stderr, "Apout - couldn't load %s\n", argv[0]);
-       exit(1);
+    /* Try to load the binary as an a.out */
+    if (load_a_out(argv[0], NULL, 1) == -1) {
+        fprintf(stderr, "Apout - couldn't load %s\n", argv[0]);
+        exit(1);
     }
 
-                               /* Other emulated systems (RT-11) can go here */
+    /* Other emulated systems (RT-11) can go here */
 
     run();                     /* Now run the binary */
     exit(0);
@@ -115,22 +145,27 @@ main(int argc, char **argv)
  * have to free the returned pointer, but successive calls will destroy
  * calls from >2 calls earlier.
  */
-char * xlate_filename(char *name)
+char *xlate_filename(char *name)
 {
-    int i=whichrfn;
-
-    if (name == NULL) return (NULL);
-    if (name[0] == '\0') return(".");  /* Undocumented, but used in V7 */
-    if (name[0] != '/') return (name); /* Relative, keep it relative */
-    strcpy(rfn[i], name);              /* Copy name into buffer */
-    whichrfn= 1 - whichrfn;            /* Switch to other buffer next time */
+    int i = whichrfn;
+
+    if (name == NULL)
+        return (NULL);
+    if (name[0] == '\0')
+        return (".");          /* Undocumented, but used in V7 */
+    if (name[0] != '/')
+        return (name);         /* Relative, keep it relative */
+    strcpy(rfn[i], name);      /* Copy name into buffer */
+    whichrfn = 1 - whichrfn;   /* Switch to other buffer next time */
     return (realfilename[i]);
 }
 
 void set_apout_root(char *dirname)
 {
-        strcpy(realfilename[0], dirname);      
-        strcpy(realfilename[1], dirname);      
-        rfn[0] = realfilename[0]; rfn[0] += strlen(realfilename[0]);
-        rfn[1] = realfilename[1]; rfn[1] += strlen(realfilename[1]);
+    strcpy(realfilename[0], dirname);
+    strcpy(realfilename[1], dirname);
+    rfn[0] = realfilename[0];
+    rfn[0] += strlen(realfilename[0]);
+    rfn[1] = realfilename[1];
+    rfn[1] += strlen(realfilename[1]);
 }
index de7e334..80b33a6 100644 (file)
--- a/single.c
+++ b/single.c
@@ -6,24 +6,23 @@
 #include "defines.h"
 
 /* adc() - Add Carry Instruction. */
-void 
-adc()
+void adc()
 {
     load_dst();
 
-    if (CC_C) {                /* do if carry is set */
-       if (dstword == MPI)
-           SET_CC_V();
-       else
-           CLR_CC_V();
-       if (dstword == NEG_1)
-           SET_CC_C();
-       else
-           CLR_CC_C();
-       dstword++;                      /* add the carry */
+    if (CC_C) {                        /* do if carry is set */
+        if (dstword == MPI)
+            SET_CC_V();
+        else
+            CLR_CC_V();
+        if (dstword == NEG_1)
+            SET_CC_C();
+        else
+            CLR_CC_C();
+        dstword++;             /* add the carry */
     } else {
-       CLR_CC_V();
-       CLR_CC_C();
+        CLR_CC_V();
+        CLR_CC_C();
     }
 
     CHG_CC_N(dstword);
@@ -34,15 +33,14 @@ adc()
 
 
 /* asl() - Arithmetic Shift Left Instruction. */
-void 
-asl()
+void asl()
 {
     load_dst();
 
     if (dstword & SIGN)
-       SET_CC_C();
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
     dstword <<= 1;
 
@@ -54,17 +52,16 @@ asl()
 }
 
 /* asr() - Arithmetic Shift Right Instruction. */
-void 
-asr()
+void asr()
 {
     load_dst();
 
     if (dstword & LSBIT)
-       SET_CC_C();
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
-    dstword = (dstword >> 1) + (dstword & SIGN);     /* shift and replicate */
+    dstword = (dstword >> 1) + (dstword & SIGN);       /* shift and replicate */
 
     CHG_CC_N(dstword);
     CHG_CC_Z(dstword);
@@ -75,16 +72,16 @@ asr()
 }
 
 /* clr() - Clear Instruction. */
-void 
-clr()
+void clr()
 {
-    CLR_CC_ALL(); SET_CC_Z();
-    dstword=0; store_dst();
+    CLR_CC_ALL();
+    SET_CC_Z();
+    dstword = 0;
+    store_dst();
 }
 
 /* com() - Complement Instruction. */
-void 
-com()
+void com()
 {
     load_dst();
 
@@ -99,15 +96,14 @@ com()
 }
 
 /* dec() - Decrement Instruction. */
-void 
-dec()
+void dec()
 {
     load_dst();
 
     if (dstword == MNI)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     --dstword;
 
@@ -118,15 +114,14 @@ dec()
 }
 
 /* inc() - Increment Instruction. */
-void 
-inc()
+void inc()
 {
     load_dst();
 
     if (dstword == MPI)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     ++dstword;
 
@@ -138,8 +133,7 @@ inc()
 
 /* neg() - Negate Instruction. */
 
-void 
-neg()
+void neg()
 {
     load_dst();
 
@@ -149,34 +143,33 @@ neg()
     CHG_CC_Z(dstword);
 
     if (dstword == MNI)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     if (dstword == 0)
-       CLR_CC_C();
+        CLR_CC_C();
     else
-       SET_CC_C();
+        SET_CC_C();
 
     store_dst_2();
 }
 
 /* rol() - Rotate Left Instruction. */
-void 
-rol()
+void rol()
 {
     load_dst();
 
-    tmpword = dstword & SIGN;          /* get sign bit */
-    dstword <<= 1;                     /* shift */
+    tmpword = dstword & SIGN;  /* get sign bit */
+    dstword <<= 1;             /* shift */
 
-    if (CC_C)          /* roll in carry */
-       dstword += LSBIT;
+    if (CC_C)                  /* roll in carry */
+        dstword += LSBIT;
 
-    if (tmpword)                       /* roll out to carry */
-       SET_CC_C();
+    if (tmpword)               /* roll out to carry */
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
     CHG_CC_N(dstword);
     CHG_CC_Z(dstword);
@@ -187,21 +180,20 @@ rol()
 
 
 /* ror() - Rotate Right Instruction. */
-void 
-ror()
+void ror()
 {
     load_dst();
 
     tmpword = dstword & LSBIT; /* get low bit */
-    dstword >>= 1;                     /* shift */
+    dstword >>= 1;             /* shift */
 
-    if (CC_C)          /* roll in carry */
-       dstword += SIGN;
+    if (CC_C)                  /* roll in carry */
+        dstword += SIGN;
 
-    if (tmpword)                       /* roll out to carry */
-       SET_CC_C();
+    if (tmpword)               /* roll out to carry */
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
     CHG_CC_N(dstword);
     CHG_CC_Z(dstword);
@@ -211,24 +203,23 @@ ror()
 }
 
 /* sbc() - Subtract Carry Instruction. */
-void 
-sbc()
+void sbc()
 {
     load_dst();
 
     if (dstword == MNI)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
-
-    if (CC_C) {                /* do if carry is set */
-       if (dstword)
-           CLR_CC_C();
-       else
-           SET_CC_C();
-       --dstword;                      /* subtract carry */
+        CLR_CC_V();
+
+    if (CC_C) {                        /* do if carry is set */
+        if (dstword)
+            CLR_CC_C();
+        else
+            SET_CC_C();
+        --dstword;             /* subtract carry */
     } else {
-       CLR_CC_C();
+        CLR_CC_C();
     }
 
     CHG_CC_N(dstword);
@@ -238,8 +229,7 @@ sbc()
 }
 
 /* swabi() - Swap Bytes Instruction. */
-void 
-swabi()
+void swabi()
 {
     u_int16_t data2;
     u_int16_t data3;
@@ -258,15 +248,14 @@ swabi()
 }
 
 /* sxt() - Sign Extend Instruction. */
-void 
-sxt()
+void sxt()
 {
     if (CC_N) {
-       dstword = NEG_1;
-       CLR_CC_Z();
+        dstword = NEG_1;
+        CLR_CC_Z();
     } else {
-       dstword = 0;
-       SET_CC_Z();
+        dstword = 0;
+        SET_CC_Z();
     }
     CLR_CC_V();
 
@@ -274,8 +263,7 @@ sxt()
 }
 
 /* tst() - Test Instruction. */
-void 
-tst()
+void tst()
 {
     load_dst();
 
@@ -285,8 +273,7 @@ tst()
 }
 
 /* tstb() - Test Byte Instruction. */
-void 
-tstb()
+void tstb()
 {
     loadb_dst();
 
@@ -298,15 +285,14 @@ tstb()
 }
 
 /* aslb() - Arithmetic Shift Left Byte Instruction. */
-void 
-aslb()
+void aslb()
 {
     loadb_dst();
 
     if (dstbyte & SIGN_B)
-       SET_CC_C();
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
     dstbyte <<= 1;
 
@@ -318,17 +304,16 @@ aslb()
 }
 
 /* asrb() - Arithmetic Shift Right Byte Instruction. */
-void 
-asrb()
+void asrb()
 {
     loadb_dst();
 
     if (dstbyte & LSBIT)
-       SET_CC_C();
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
-    dstbyte = (dstbyte >> 1) + (dstbyte & SIGN_B);    /* shift and replicate */
+    dstbyte = (dstbyte >> 1) + (dstbyte & SIGN_B);     /* shift and replicate */
 
     CHGB_CC_N(dstbyte);
     CHGB_CC_Z(dstbyte);
@@ -338,17 +323,17 @@ asrb()
 }
 
 /* clrb() - Clear Byte Instruction. */
-void 
-clrb()
+void clrb()
 {
-    CLR_CC_ALL(); SET_CC_Z();
-    srcbyte=0; storeb_dst();
+    CLR_CC_ALL();
+    SET_CC_Z();
+    srcbyte = 0;
+    storeb_dst();
 }
 
 
 /* comb() - Complement Byte Instruction. */
-void 
-comb()
+void comb()
 {
     loadb_dst();
 
@@ -363,15 +348,14 @@ comb()
 }
 
 /* decb() - Decrement Byte Instruction. */
-void 
-decb()
+void decb()
 {
     loadb_dst();
 
     if (dstbyte == MNI_B)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     --dstbyte;
 
@@ -382,15 +366,14 @@ decb()
 }
 
 /* incb() - Increment Byte Instruction. */
-void 
-incb()
+void incb()
 {
     loadb_dst();
 
     if (dstbyte == MPI_B)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     ++dstbyte;
 
@@ -401,45 +384,43 @@ incb()
 }
 
 /* negb() - Negate Byte Instruction. */
-void 
-negb()
+void negb()
 {
     loadb_dst();
 
-    dstbyte = (NEG_1_B - dstbyte) + 1;/* hope this is right */
+    dstbyte = (NEG_1_B - dstbyte) + 1; /* hope this is right */
 
     CHGB_CC_N(dstbyte);
     CHGB_CC_Z(dstbyte);
 
     if (dstbyte == MNI_B)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     if (dstbyte)
-       SET_CC_C();
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
     storeb_dst_2();
 }
 
 /* rolb() - Rotate Left Byte Instruction. */
-void 
-rolb()
+void rolb()
 {
     loadb_dst();
 
-    tmpbyte = dstbyte & SIGN_B; /* get top bit */
-    dstbyte <<= 1;                     /* shift */
+    tmpbyte = dstbyte & SIGN_B;        /* get top bit */
+    dstbyte <<= 1;             /* shift */
 
-    if (CC_C)          /* roll in carry */
-       dstbyte = dstbyte + LSBIT;
+    if (CC_C)                  /* roll in carry */
+        dstbyte = dstbyte + LSBIT;
 
-    if (tmpbyte)                       /* roll out to carry */
-       SET_CC_C();
+    if (tmpbyte)               /* roll out to carry */
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
     CHGB_CC_N(dstbyte);
     CHGB_CC_Z(dstbyte);
@@ -449,21 +430,20 @@ rolb()
 }
 
 /* rorb() - Rotate Right Byte Instruction. */
-void 
-rorb()
+void rorb()
 {
     loadb_dst();
 
     tmpbyte = dstbyte & LSBIT; /* get low bit */
-    dstbyte >>= 1;                     /* shift */
+    dstbyte >>= 1;             /* shift */
 
-    if (CC_C)          /* roll in carry */
-       dstbyte += SIGN_B;
+    if (CC_C)                  /* roll in carry */
+        dstbyte += SIGN_B;
 
-    if (tmpbyte)                       /* roll out to carry */
-       SET_CC_C();
+    if (tmpbyte)               /* roll out to carry */
+        SET_CC_C();
     else
-       CLR_CC_C();
+        CLR_CC_C();
 
     CHGB_CC_N(dstbyte);
     CHGB_CC_Z(dstbyte);
@@ -473,24 +453,23 @@ rorb()
 }
 
 /* adcb() - Add Carry Byte Instruction. */
-void 
-adcb()
+void adcb()
 {
     loadb_dst();
 
-    if (CC_C) {                /* do if carry is set */
-       if (dstbyte == MPI_B)
-           SET_CC_V();
-       else
-           CLR_CC_V();
-       if (dstbyte == NEG_1_B)
-           SET_CC_C();
-       else
-           CLR_CC_C();
-       ++dstbyte;                      /* add the carry */
+    if (CC_C) {                        /* do if carry is set */
+        if (dstbyte == MPI_B)
+            SET_CC_V();
+        else
+            CLR_CC_V();
+        if (dstbyte == NEG_1_B)
+            SET_CC_C();
+        else
+            CLR_CC_C();
+        ++dstbyte;             /* add the carry */
     } else {
-       CLR_CC_V();
-       CLR_CC_C();
+        CLR_CC_V();
+        CLR_CC_C();
     }
 
     CHGB_CC_N(dstbyte);
@@ -500,26 +479,25 @@ adcb()
 }
 
 /* sbcb() - Subtract Carry Byte Instruction. */
-void 
-sbcb()
+void sbcb()
 {
     loadb_dst();
 
-    if (CC_C) {                /* do if carry is set */
-       if (dstbyte)
-           CLR_CC_C();
-       else
-           SET_CC_C();
+    if (CC_C) {                        /* do if carry is set */
+        if (dstbyte)
+            CLR_CC_C();
+        else
+            SET_CC_C();
 
-       --dstbyte;                      /* subtract carry */
+        --dstbyte;             /* subtract carry */
     } else {
-       CLR_CC_C();
+        CLR_CC_C();
     }
 
     if (dstbyte == MNI_B)
-       SET_CC_V();
+        SET_CC_V();
     else
-       CLR_CC_V();
+        CLR_CC_V();
 
     CHGB_CC_N(dstbyte);
     CHGB_CC_Z(dstbyte);
index 7443f4d..5fd9ed7 100644 (file)
--- a/v1trap.c
+++ b/v1trap.c
@@ -19,9 +19,9 @@
 #include "v1trap.h"
 
 #ifdef __linux__
-# undef STREAM_BUFFERING                       /* It seems to work */
+#undef STREAM_BUFFERING                /* It seems to work */
 #else
-# define STREAM_BUFFERING                      /* but not for Linux */
+#define STREAM_BUFFERING       /* but not for Linux */
 #endif
 
 
@@ -43,421 +43,515 @@ static u_int32_t sectosixty P((time_t tim));
  * of words, and the number in registers.
  */
 struct v1sysent {
-  int nwords;
-  int nregs;
+    int nwords;
+    int nregs;
 };
 static struct v1sysent v1arg[] = {
-  {0, 0}, {0, 0}, {0, 0}, {3, 1}, {3, 1}, {2, 0}, {1, 1}, {1, 1},
-  {2, 0}, {2, 0}, {1, 0}, {2, 0}, {1, 0}, {0, 0}, {2, 0}, {2, 0},
-  {2, 0}, {1, 0}, {2, 0}, {3, 1}, {3, 1}, {2, 0}, {1, 0}, {1, 1},
-  {1, 1}, {0, 0}, {1, 0}, {1, 0}, {2, 1}, {1, 0}, {1, 0}, {2, 1},
-  {2, 1}, {1, 0}
+    {0, 0}, {0, 0}, {0, 0}, {3, 1}, {3, 1}, {2, 0}, {1, 1}, {1, 1},
+    {2, 0}, {2, 0}, {1, 0}, {2, 0}, {1, 0}, {0, 0}, {2, 0}, {2, 0},
+    {2, 0}, {1, 0}, {2, 0}, {3, 1}, {3, 1}, {2, 0}, {1, 0}, {1, 1},
+    {1, 1}, {0, 0}, {1, 0}, {1, 0}, {2, 1}, {1, 0}, {1, 0}, {2, 1},
+    {2, 1}, {1, 0}
 };
 
 /* Seeks on files in /dev are done in 512-byte blocks, not bytes.
  * If a fd's entry in the following table is 1, then it's a device
  * and not a file.
  */
-int8_t isdev[NFILE]= {
-       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+int8_t isdev[NFILE] = {
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
 static arglist V1A;
 
 void v1trap()
 {
-  extern int32_t AC, MQ;       /* in ke11a.c */
-  int i, mode, pid;
-  int status, exitval, errval; /* used in V2 wait */
-  int whence;
-  u_int16_t argbase;
-  int trapnum;
-  long larg;
-  char *buf, *buf2;
-  char *fmode;                 /* used with fdopen only */
+    extern int32_t AC, MQ;     /* in ke11a.c */
+    int i, mode, pid;
+    int status, exitval, errval;       /* used in V2 wait */
+    int whence;
+    u_int16_t argbase;
+    int trapnum;
+    long larg;
+    char *buf, *buf2;
+    char *fmode;               /* used with fdopen only */
 
-  struct stat stbuf;           /* used in STAT */
-  struct tr_v1stat *t1;                /* used in STAT */
-  struct timeval tval[2];      /* used in SMTIME */
+    struct stat stbuf;         /* used in STAT */
+    struct tr_v1stat *t1;      /* used in STAT */
+    struct timeval tval[2];    /* used in SMTIME */
 
 
 
-  /* Work out the actual trap number, and */
-  /* shift the PC up past any arguments */
-  /* to the syscall. Calculate base of args */
-  trapnum = ir & 077;
-  argbase = regs[PC];
-  regs[PC] += 2 * (v1arg[trapnum].nwords - v1arg[trapnum].nregs);
+    /* Work out the actual trap number, and */
+    /* shift the PC up past any arguments */
+    /* to the syscall. Calculate base of args */
+    trapnum = ir & 077;
+    argbase = regs[PC];
+    regs[PC] += 2 * (v1arg[trapnum].nwords - v1arg[trapnum].nregs);
 
-  /* Move arguments into V1A so we can use them */
-  for (i = 0; i < v1arg[trapnum].nregs; i++) V1A.uarg[i] = regs[i];
-  for (; i < v1arg[trapnum].nwords; i++, argbase += 2)
-    ll_word(argbase, V1A.uarg[i]);
+    /* Move arguments into V1A so we can use them */
+    for (i = 0; i < v1arg[trapnum].nregs; i++)
+        V1A.uarg[i] = regs[i];
+    for (; i < v1arg[trapnum].nwords; i++, argbase += 2)
+        ll_word(argbase, V1A.uarg[i]);
 
-  TrapDebug((dbg_file, "pid %d %s: ", (int) getpid(), v1trap_name[trapnum]));
+    TrapDebug((dbg_file, "pid %d %s: ", (int) getpid(),
+               v1trap_name[trapnum]));
 
-  switch (trapnum) {
+    switch (trapnum) {
 
-      /* XXX STILL TO DO: V1_GTTY, V1_STTY, V1_TELL */
+    /* XXX STILL TO DO: V1_GTTY, V1_STTY, V1_TELL */
 
-                       /* These syscalls are ignored, and return */
-                       /* with no effect on the caller */
+    /* These syscalls are ignored, and return */
+    /* with no effect on the caller */
     case V1_BREAK:
     case V1_CEMT:
     case V1_ILGINS:
     case V1_INTR:
     case V1_QUIT:
-    case V1_RELE: return;
+    case V1_RELE:
+        return;
 
-                       /* These syscalls are not implemented, and */
-                       /* always return no error to the caller */
+    /* These syscalls are not implemented, and */
+    /* always return no error to the caller */
     case V1_GTTY:
-    case V1_STTY: i=0; break;
-                       /* These syscalls are not implemented, and */
-                       /* always return an error to the caller */
+    case V1_STTY:
+        i = 0;
+        break;
+    /* These syscalls are not implemented, and */
+    /* always return an error to the caller */
     case V1_MOUNT:
-    case V1_UMOUNT: i = -1; break;
+    case V1_UMOUNT:
+        i = -1;
+        break;
 
     case V1_EXIT:
-      if (Binary==IS_V1) exit(0);
-      if (Binary==IS_V2) {
-       exitval=regs[0] & 0xff;
-       if (regs[PC]==16790) exitval=0; /* s2-tape /bin/as doesn't set r0 */
-       TrapDebug((dbg_file, " with exitval %d\n", exitval));
-       exit(exitval);
-      }
-      i = -1;
-      break;
-
-#define EPOCH71        31536000                /* # seconds from 1970 to 1971 */
-#define EPOCH72        63072000                /* # seconds from 1970 to 1972 */
+        if (Binary == IS_V1)
+            exit(0);
+        if (Binary == IS_V2) {
+            exitval = regs[0] & 0xff;
+            if (regs[PC] == 16790)
+                exitval = 0;   /* s2-tape /bin/as doesn't set r0 */
+            TrapDebug((dbg_file, " with exitval %d\n", exitval));
+            exit(exitval);
+        }
+        i = -1;
+        break;
+
+#define EPOCH71        31536000        /* # seconds from 1970 to 1971 */
+#define EPOCH72        63072000        /* # seconds from 1970 to 1972 */
     case V1_SMDATE:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      if (buf[0] == '\0') buf = ".";   /* Not documented anywhere */
-      if (uarg1 == 0) buf = ".";       /* Who knows? for V1 */
-      i = stat(buf, &stbuf);
-      TrapDebug((dbg_file, " on %s (stat %d) ", buf, i));
-      if (i == -1) break;
-
-                                       /* Copy access time to preserve it */
-      tval[0].tv_sec= stbuf.st_atime; tval[0].tv_usec=0;
-      larg= (AC << 16) | (MQ & 0xffff); /* Get mod time in 60ths of a second */
-      TrapDebug((dbg_file, " %ld -> ", larg));
-      larg= larg/60 + EPOCH72;         /* Convert to seconds since 1970 */
-      TrapDebug((dbg_file, " 0x%lx ", larg));
-      tval[1].tv_sec= larg; tval[1].tv_usec=0;
-      i=utimes(buf, tval);
-      TrapDebug((dbg_file, " and %d for utimes ", i));
-      break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        if (buf[0] == '\0')
+            buf = "."; /* Not documented anywhere */
+        if (uarg1 == 0)
+            buf = "."; /* Who knows? for V1 */
+        i = stat(buf, &stbuf);
+        TrapDebug((dbg_file, " on %s (stat %d) ", buf, i));
+        if (i == -1)
+            break;
+
+        /* Copy access time to preserve it */
+        tval[0].tv_sec = stbuf.st_atime;
+        tval[0].tv_usec = 0;
+        larg = (AC << 16) | (MQ & 0xffff);     /* Get mod time in 60ths of a second */
+        TrapDebug((dbg_file, " %ld -> ", larg));
+        larg = larg / 60 + EPOCH72;    /* Convert to seconds since 1970 */
+        TrapDebug((dbg_file, " 0x%lx ", larg));
+        tval[1].tv_sec = larg;
+        tval[1].tv_usec = 0;
+        i = utimes(buf, tval);
+        TrapDebug((dbg_file, " and %d for utimes ", i));
+        break;
 
     case V1_TIME:
-                       /* Kludge: treat start of this year as the epoch. */
-                       /* Find #seconds from yearstart to now, multiply */
-                       /* by 60 so as to be in V1 units */
-      larg = sectosixty(time(NULL));
-      MQ = (int) larg & 0xffff;
-      AC = ((int) larg >> 16) & 0xffff;
-      i = 0; break;
+        /* Kludge: treat start of this year as the epoch. */
+        /* Find #seconds from yearstart to now, multiply */
+        /* by 60 so as to be in V1 units */
+        larg = sectosixty(time(NULL));
+        MQ = (int) larg & 0xffff;
+        AC = ((int) larg >> 16) & 0xffff;
+        i = 0;
+        break;
     case V1_SEEK:
-      /* Work out the args before we do the lseek */
-      whence = uarg3;
-      switch (uarg3) {
-       case 0:
-         larg = uarg2; break;
-       case 1:
-       case 2:
-         larg = sarg2; break;
-      }
-
-      if (ValidFD(sarg1) && isdev[sarg1]) larg*= 512;
+        /* Work out the args before we do the lseek */
+        whence = uarg3;
+        switch (uarg3) {
+        case 0:
+            larg = uarg2;
+            break;
+        case 1:
+        case 2:
+            larg = sarg2;
+            break;
+        }
+
+        if (ValidFD(sarg1) && isdev[sarg1])
+            larg *= 512;
 
 #ifdef STREAM_BUFFERING
-      if (ValidFD(sarg1) && stream[sarg1]) {
-       i = fseek(stream[sarg1], larg, whence);
-       if (i == 0)
-         i = ftell(stream[sarg1]);
-      } else
+        if (ValidFD(sarg1) && stream[sarg1]) {
+            i = fseek(stream[sarg1], larg, whence);
+            if (i == 0)
+                i = ftell(stream[sarg1]);
+        } else
 #endif
-       i = lseek(sarg1, larg, whence);
-
-      TrapDebug((dbg_file, " on fd %d amt %ld whence %d return %d ",
-                                               sarg1, larg, whence, i));
-      if (i != -1) i = 0;
-      regs[0] = i;
-      break;
+            i = lseek(sarg1, larg, whence);
+
+        TrapDebug((dbg_file, " on fd %d amt %ld whence %d return %d ",
+                   sarg1, larg, whence, i));
+        if (i != -1)
+            i = 0;
+        regs[0] = i;
+        break;
     case V1_READ:
-      buf = (char *)&dspace[uarg2];
+        buf = (char *) &dspace[uarg2];
 #ifdef STREAM_BUFFERING
-      if (ValidFD(sarg1) && stream[sarg1])
-       i = fread(buf, 1, sarg3, stream[sarg1]);
-      else
+        if (ValidFD(sarg1) && stream[sarg1])
+            i = fread(buf, 1, sarg3, stream[sarg1]);
+        else
 #endif
-       i = read(sarg1, buf, sarg3);
-      TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
-      regs[0] = i; break;
+            i = read(sarg1, buf, sarg3);
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
+        regs[0] = i;
+        break;
     case V1_LINK:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      buf2 = xlate_filename((char *)&dspace[uarg2]);
-      i = link(buf, buf2);
-      regs[0] = i; break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        buf2 = xlate_filename((char *) &dspace[uarg2]);
+        i = link(buf, buf2);
+        regs[0] = i;
+        break;
     case V1_WRITE:
-      buf = (char *)&dspace[uarg2];
+        buf = (char *) &dspace[uarg2];
 #ifdef STREAM_BUFFERING
-      if (ValidFD(sarg1) && stream[sarg1])
-       i = fwrite(buf, 1, sarg3, stream[sarg1]);
-      else
+        if (ValidFD(sarg1) && stream[sarg1])
+            i = fwrite(buf, 1, sarg3, stream[sarg1]);
+        else
 #endif
-       i = write(sarg1, buf, sarg3);
-      TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
-      regs[0] = i; break;
+            i = write(sarg1, buf, sarg3);
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
+        regs[0] = i;
+        break;
     case V1_CLOSE:
 #ifdef STREAM_BUFFERING
-      if (ValidFD(sarg1) && stream[sarg1]) {
-       i = fclose(stream[sarg1]);
-       stream[sarg1] = NULL;
-      } else
+        if (ValidFD(sarg1) && stream[sarg1]) {
+            i = fclose(stream[sarg1]);
+            stream[sarg1] = NULL;
+        } else
 #endif
-       i = close(sarg1);
-      if ((i==0) && ValidFD(sarg1)) isdev[sarg1]=0;
-      TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
-      break;
+            i = close(sarg1);
+        if ((i == 0) && ValidFD(sarg1))
+            isdev[sarg1] = 0;
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
+        break;
     case V1_STAT:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      if (buf[0] == '\0') buf = ".";   /* Not documented anywhere */
-      if (uarg1 == 0) buf = ".";       /* Who knows? for V1 */
-      buf2 = (char *)&dspace[uarg2];
-      i = stat(buf, &stbuf);
-      TrapDebug((dbg_file, " on %s return %d ", buf, i));
-      goto dostat;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        if (buf[0] == '\0')
+            buf = "."; /* Not documented anywhere */
+        if (uarg1 == 0)
+            buf = "."; /* Who knows? for V1 */
+        buf2 = (char *) &dspace[uarg2];
+        i = stat(buf, &stbuf);
+        TrapDebug((dbg_file, " on %s return %d ", buf, i));
+        goto dostat;
     case V1_FSTAT:
-      buf2 = (char *)&dspace[uarg2];
-      i = fstat(sarg1, &stbuf);
-      TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
-
-  dostat:
-      if (i == -1) break;
-      t1 = (struct tr_v1stat *) buf2;
-                               /* Inode numbers <41 are reserved for */
-                               /* device files. Ensure we don't use them */
-      t1->inum = stbuf.st_ino & 0x7fff; if (t1->inum<41) t1->inum+=100;
-      t1->inl = stbuf.st_nlink;
-      t1->iuid = stbuf.st_uid;
-      t1->isize = (u_int16_t) (stbuf.st_size & 0xffff);
-      t1->iflags = (u_int16_t) (V1_ST_USED | V1_ST_MODIFIED);
-      if (stbuf.st_size > 4095)    t1->iflags |= V1_ST_LARGE;
-      if (stbuf.st_mode & S_IFDIR) t1->iflags |= V1_ST_ISDIR;
-      if (stbuf.st_mode & S_ISUID) t1->iflags |= V1_ST_SETUID;
-      if (stbuf.st_mode & S_IXUSR) t1->iflags |= V1_ST_EXEC;
-      if (stbuf.st_mode & S_IRUSR) t1->iflags |= V1_ST_OWNREAD;
-      if (stbuf.st_mode & S_IWUSR) t1->iflags |= V1_ST_OWNWRITE;
-      if (stbuf.st_mode & S_IROTH) t1->iflags |= V1_ST_WRLDREAD;
-      if (stbuf.st_mode & S_IWOTH) t1->iflags |= V1_ST_WRLDWRITE;
-
-      larg = sectosixty(stbuf.st_ctime); copylong(t1->ctime, larg);
-      larg = sectosixty(stbuf.st_mtime); copylong(t1->mtime, larg);
-      break;
+        buf2 = (char *) &dspace[uarg2];
+        i = fstat(sarg1, &stbuf);
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
+
+dostat:
+        if (i == -1)
+            break;
+        t1 = (struct tr_v1stat *) buf2;
+        /* Inode numbers <41 are reserved for */
+        /* device files. Ensure we don't use them */
+        t1->inum = stbuf.st_ino & 0x7fff;
+        if (t1->inum < 41)
+            t1->inum += 100;
+        t1->inl = stbuf.st_nlink;
+        t1->iuid = stbuf.st_uid;
+        t1->isize = (u_int16_t) (stbuf.st_size & 0xffff);
+        t1->iflags = (u_int16_t) (V1_ST_USED | V1_ST_MODIFIED);
+        if (stbuf.st_size > 4095)
+            t1->iflags |= V1_ST_LARGE;
+        if (stbuf.st_mode & S_IFDIR)
+            t1->iflags |= V1_ST_ISDIR;
+        if (stbuf.st_mode & S_ISUID)
+            t1->iflags |= V1_ST_SETUID;
+        if (stbuf.st_mode & S_IXUSR)
+            t1->iflags |= V1_ST_EXEC;
+        if (stbuf.st_mode & S_IRUSR)
+            t1->iflags |= V1_ST_OWNREAD;
+        if (stbuf.st_mode & S_IWUSR)
+            t1->iflags |= V1_ST_OWNWRITE;
+        if (stbuf.st_mode & S_IROTH)
+            t1->iflags |= V1_ST_WRLDREAD;
+        if (stbuf.st_mode & S_IWOTH)
+            t1->iflags |= V1_ST_WRLDWRITE;
+
+        larg = sectosixty(stbuf.st_ctime);
+        copylong(t1->ctime, larg);
+        larg = sectosixty(stbuf.st_mtime);
+        copylong(t1->mtime, larg);
+        break;
     case V1_UNLINK:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      i = unlink(buf);
-      break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = unlink(buf);
+        break;
     case V1_OPEN:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-
-      i = stat(buf, &stbuf);   /* If file is a directory */
-      if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
-       i = v1open_dir(buf);
-       fmode = "w+";
-       TrapDebug((dbg_file, "(dir) on %s return %d ", buf, i));
-      } else {
-       switch (sarg2) {
-         case 0:
-           sarg2 = O_RDONLY; fmode = "r"; break;
-         case 1:
-           sarg2 = O_WRONLY; fmode = "w"; break;
-         default:
-           sarg2 = O_RDWR; fmode = "w+"; break;
-       }
-       i = open(buf, sarg2);
-       TrapDebug((dbg_file, " on %s return %d ", buf, i));
-      }
-      regs[0] = i;
-
-      if (ValidFD(i) && !strncmp((char *)&dspace[uarg1],"/dev/",5)) {
-       TrapDebug((dbg_file, " (device file) "));
-       isdev[i]=1;
-      }
-
+        buf = xlate_filename((char *) &dspace[uarg1]);
+
+        i = stat(buf, &stbuf); /* If file is a directory */
+        if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
+            i = v1open_dir(buf);
+            fmode = "w+";
+            TrapDebug((dbg_file, "(dir) on %s return %d ", buf, i));
+        } else {
+            switch (sarg2) {
+            case 0:
+                sarg2 = O_RDONLY;
+                fmode = "r";
+                break;
+            case 1:
+                sarg2 = O_WRONLY;
+                fmode = "w";
+                break;
+            default:
+                sarg2 = O_RDWR;
+                fmode = "w+";
+                break;
+            }
+            i = open(buf, sarg2);
+            TrapDebug((dbg_file, " on %s return %d ", buf, i));
+        }
+        regs[0] = i;
+
+        if (ValidFD(i)
+                && !strncmp((char *) &dspace[uarg1], "/dev/", 5)) {
+            TrapDebug((dbg_file, " (device file) "));
+            isdev[i] = 1;
+        }
 #ifdef STREAM_BUFFERING
-      if (i==-1) break;
+        if (i == -1)
+            break;
 #if 0
-      /* Now get its stream pointer if possible */
-      /* Can someone explain why fdopen doesn't work for O_RDWR? */
-      if (ValidFD(i) && !isatty(i) && (sarg2 != O_RDWR)) {
-       stream[i] = fdopen(i, fmode); streammode[i] = fmode;
-      }
+        /* Now get its stream pointer if possible */
+        /* Can someone explain why fdopen doesn't work for O_RDWR? */
+        if (ValidFD(i) && !isatty(i) && (sarg2 != O_RDWR)) {
+            stream[i] = fdopen(i, fmode);
+            streammode[i] = fmode;
+        }
 #endif
-       stream[i] = fdopen(i, fmode); streammode[i] = fmode;
+        stream[i] = fdopen(i, fmode);
+        streammode[i] = fmode;
 #endif
-      break;
+        break;
     case V1_CHMOD:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      mode = 0;
-      if (uarg2 & V1_ST_SETUID)    mode |= S_ISUID;
-      if (uarg2 & V1_ST_EXEC)      mode |= S_IXUSR | S_IXGRP | S_IXOTH;
-      if (uarg2 & V1_ST_OWNREAD)   mode |= S_IRUSR;
-      if (uarg2 & V1_ST_OWNWRITE)  mode |= S_IWUSR;
-      if (uarg2 & V1_ST_WRLDREAD)  mode |= S_IRGRP | S_IROTH;
-      if (uarg2 & V1_ST_WRLDWRITE) mode |= S_IWGRP | S_IWOTH;
-      i = chmod(buf, mode);
-      break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        mode = 0;
+        if (uarg2 & V1_ST_SETUID)
+            mode |= S_ISUID;
+        if (uarg2 & V1_ST_EXEC)
+            mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+        if (uarg2 & V1_ST_OWNREAD)
+            mode |= S_IRUSR;
+        if (uarg2 & V1_ST_OWNWRITE)
+            mode |= S_IWUSR;
+        if (uarg2 & V1_ST_WRLDREAD)
+            mode |= S_IRGRP | S_IROTH;
+        if (uarg2 & V1_ST_WRLDWRITE)
+            mode |= S_IWGRP | S_IWOTH;
+        i = chmod(buf, mode);
+        break;
     case V1_MKDIR:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      mode = 0;
-      if (uarg2 & V1_ST_SETUID)    mode |= S_ISUID;
-      if (uarg2 & V1_ST_EXEC)      mode |= S_IXUSR | S_IXGRP | S_IXOTH;
-      if (uarg2 & V1_ST_OWNREAD)   mode |= S_IRUSR;
-      if (uarg2 & V1_ST_OWNWRITE)  mode |= S_IWUSR;
-      if (uarg2 & V1_ST_WRLDREAD)  mode |= S_IRGRP | S_IROTH;
-      if (uarg2 & V1_ST_WRLDWRITE) mode |= S_IWGRP | S_IWOTH;
-      i = mkdir(buf, mode);
-      break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        mode = 0;
+        if (uarg2 & V1_ST_SETUID)
+            mode |= S_ISUID;
+        if (uarg2 & V1_ST_EXEC)
+            mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+        if (uarg2 & V1_ST_OWNREAD)
+            mode |= S_IRUSR;
+        if (uarg2 & V1_ST_OWNWRITE)
+            mode |= S_IWUSR;
+        if (uarg2 & V1_ST_WRLDREAD)
+            mode |= S_IRGRP | S_IROTH;
+        if (uarg2 & V1_ST_WRLDWRITE)
+            mode |= S_IWGRP | S_IWOTH;
+        i = mkdir(buf, mode);
+        break;
     case V1_CHOWN:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      uarg2&= 0x3fff;                  /* Why are uids > 16384? */
-      i = chown(buf, uarg2, 0);
-      TrapDebug((dbg_file, " %d on %s return %d",uarg2,buf,i));
-      break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        uarg2 &= 0x3fff;       /* Why are uids > 16384? */
+        i = chown(buf, uarg2, 0);
+        TrapDebug((dbg_file, " %d on %s return %d", uarg2, buf, i));
+        break;
     case V1_CHDIR:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      i = chdir(buf);
-      break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chdir(buf);
+        break;
     case V1_CREAT:
-      buf = xlate_filename((char *)&dspace[uarg1]);
-      mode = 0;
-      if (uarg2 & V1_ST_SETUID)    mode |= S_ISUID;
-      if (uarg2 & V1_ST_EXEC)      mode |= S_IXUSR | S_IXGRP | S_IXOTH;
-      if (uarg2 & V1_ST_OWNREAD)   mode |= S_IRUSR;
-      if (uarg2 & V1_ST_OWNWRITE)  mode |= S_IWUSR;
-      if (uarg2 & V1_ST_WRLDREAD)  mode |= S_IRGRP | S_IROTH;
-      if (uarg2 & V1_ST_WRLDWRITE) mode |= S_IWGRP | S_IWOTH;
-      i = creat(buf, mode);
-      TrapDebug((dbg_file, " on %s return %d ", buf, i));
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        mode = 0;
+        if (uarg2 & V1_ST_SETUID)
+            mode |= S_ISUID;
+        if (uarg2 & V1_ST_EXEC)
+            mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+        if (uarg2 & V1_ST_OWNREAD)
+            mode |= S_IRUSR;
+        if (uarg2 & V1_ST_OWNWRITE)
+            mode |= S_IWUSR;
+        if (uarg2 & V1_ST_WRLDREAD)
+            mode |= S_IRGRP | S_IROTH;
+        if (uarg2 & V1_ST_WRLDWRITE)
+            mode |= S_IWGRP | S_IWOTH;
+        i = creat(buf, mode);
+        TrapDebug((dbg_file, " on %s return %d ", buf, i));
 #ifdef STREAM_BUFFERING
-      if (ValidFD(i)) {
-       stream[i] = fdopen(i, "w");
-       streammode[i] = "w";
-      }
+        if (ValidFD(i)) {
+            stream[i] = fdopen(i, "w");
+            streammode[i] = "w";
+        }
 #endif
-      regs[0] = i; break;
+        regs[0] = i;
+        break;
     case V1_EXEC:
-      i = v1trap_exec();
-      break;
+        i = v1trap_exec();
+        break;
     case V1_WAIT:
-      i = wait(&status);
-      if (Binary==IS_V1) break;
-                                       /* 2nd Edition wait is different */
-      regs[0] = i;                     /* Save pid found in r0 */
-      if (i==-1) { MQ=0; break; }
-      exitval=WEXITSTATUS(status);
-      TrapDebug((dbg_file, "exitval %d ",exitval));
-      errval=0;
-      if (WIFSIGNALED(status)) {
-       switch(WTERMSIG(status)) {
-         case SIGBUS: errval=1; break;
-         case SIGTRAP: errval=2; break;
-         case SIGILL: errval=3; break;
-         case SIGIOT: errval=4; break;
-         case SIGEMT: errval=6; break;
-         case SIGQUIT: errval=8; break;
-         case SIGINT: errval=9; break;
-         case SIGKILL: errval=10; break;
-       }
-       if (WCOREDUMP(status)) errval+=16;
-      }
-        TrapDebug((dbg_file, "errval %d ",errval));
-      MQ= (exitval & 0xff) | (errval<<16);
-      TrapDebug((dbg_file, "v2 return pid is %d, MQ is 0x%x ",i,MQ));
-      break;
+        i = wait(&status);
+        if (Binary == IS_V1)
+            break;
+        /* 2nd Edition wait is different */
+        regs[0] = i;   /* Save pid found in r0 */
+        if (i == -1) {
+            MQ = 0;
+            break;
+        }
+        exitval = WEXITSTATUS(status);
+        TrapDebug((dbg_file, "exitval %d ", exitval));
+        errval = 0;
+        if (WIFSIGNALED(status)) {
+            switch (WTERMSIG(status)) {
+            case SIGBUS:
+                errval = 1;
+                break;
+            case SIGTRAP:
+                errval = 2;
+                break;
+            case SIGILL:
+                errval = 3;
+                break;
+            case SIGIOT:
+                errval = 4;
+                break;
+            case SIGEMT:
+                errval = 6;
+                break;
+            case SIGQUIT:
+                errval = 8;
+                break;
+            case SIGINT:
+                errval = 9;
+                break;
+            case SIGKILL:
+                errval = 10;
+                break;
+            }
+            if (WCOREDUMP(status))
+                errval += 16;
+        }
+        TrapDebug((dbg_file, "errval %d ", errval));
+        MQ = (exitval & 0xff) | (errval << 16);
+        TrapDebug((dbg_file, "v2 return pid is %d, MQ is 0x%x ", i,
+                   MQ));
+        break;
     case V1_FORK:
-      pid = getpid();
-      i = fork();
-      switch (i) {
-                                       /* Error, inform the parent */
-       case -1: break;
-                                       /* Child gets ppid in r0 */
-       case 0:
-         i = pid; break;
-                               /* Parent: Skip child `bf', pid into r0 */
-       default:
-         regs[PC] += 2;
-         if (Binary==IS_V2) regs[0]=i;
-      }
-      break;
+        pid = getpid();
+        i = fork();
+        switch (i) {
+        /* Error, inform the parent */
+        case -1:
+            break;
+        /* Child gets ppid in r0 */
+        case 0:
+            i = pid;
+            break;
+        /* Parent: Skip child `bf', pid into r0 */
+        default:
+            regs[PC] += 2;
+            if (Binary == IS_V2)
+                regs[0] = i;
+        }
+        break;
     case V1_GETUID:
-      i = getuid();
-      break;
-      regs[0] = i;
+        i = getuid();
+        break;
+        regs[0] = i;
     case V1_SETUID:
-      i = setuid(sarg1);
-      break;
+        i = setuid(sarg1);
+        break;
     default:
-      if (trapnum > V1_ILGINS) {
-       fprintf(stderr, "Apout - unknown syscall %d at PC 0%o\n",
-                                                       trapnum, regs[PC]);
-      } else {
-       fprintf(stderr, "Apout - the %s syscall is not yet implemented\n",
-                                                       v1trap_name[trapnum]);
-      }
-      exit(1);
-  }
-
-  /* Clear C bit if no error, or */
-  /* set C bit as there was an error */
-
-  if (i == -1) {
-    SET_CC_C(); TrapDebug((dbg_file, "errno is %s\n", strerror(errno)));
-  } else {
-    CLR_CC_C(); TrapDebug((dbg_file, "return %d\n", i));
-  }
+        if (trapnum > V1_ILGINS) {
+            fprintf(stderr, "Apout - unknown syscall %d at PC 0%o\n",
+                    trapnum, regs[PC]);
+        } else {
+            fprintf(stderr,
+                    "Apout - the %s syscall is not yet implemented\n",
+                    v1trap_name[trapnum]);
+        }
+        exit(1);
+    }
+
+    /* Clear C bit if no error, or */
+    /* set C bit as there was an error */
+
+    if (i == -1) {
+        SET_CC_C();
+        TrapDebug((dbg_file, "errno is %s\n", strerror(errno)));
+    } else {
+        CLR_CC_C();
+        TrapDebug((dbg_file, "return %d\n", i));
+    }
 #ifdef DEBUG
-  fflush(dbg_file);
+    fflush(dbg_file);
 #endif
-  return;
+    return;
 }
 
 
 static int v1trap_exec(void)
 {
-  u_int16_t cptr, cptr2;
-  char *buf, *name, *origpath;
-
-  origpath = strdup((char *)&dspace[uarg1]);
-  name = xlate_filename(origpath);
-  TrapDebug((dbg_file, "%s Execing %s ", progname, name));
-
-  cptr = uarg2;
-
-  Argc = 0;
-  while (Argc < MAX_ARGS) {
-    ll_word(cptr, cptr2);
-    if (cptr2 == 0)
-      break;
-    buf = (char *)&dspace[cptr2];
-    Argv[Argc++] = strdup(buf);
-    cptr += 2;
-    TrapDebug((dbg_file, "%s ", buf));
-  }
-  Argv[Argc] = NULL;
-  TrapDebug((dbg_file, "\n"));
-
-  if (load_a_out(name, origpath, 0) == -1) {
-    for (Argc--; Argc >= 0; Argc--)
-      free(Argv[Argc]);
-    return (-1);
-  }
-  run();                       /* Ok, so it's recursive, I dislike setjmp */
-  return (0);
+    u_int16_t cptr, cptr2;
+    char *buf, *name, *origpath;
+
+    origpath = strdup((char *) &dspace[uarg1]);
+    name = xlate_filename(origpath);
+    TrapDebug((dbg_file, "%s Execing %s ", progname, name));
+
+    cptr = uarg2;
+
+    Argc = 0;
+    while (Argc < MAX_ARGS) {
+        ll_word(cptr, cptr2);
+        if (cptr2 == 0)
+            break;
+        buf = (char *) &dspace[cptr2];
+        Argv[Argc++] = strdup(buf);
+        cptr += 2;
+        TrapDebug((dbg_file, "%s ", buf));
+    }
+    Argv[Argc] = NULL;
+    TrapDebug((dbg_file, "\n"));
+
+    if (load_a_out(name, origpath, 0) == -1) {
+        for (Argc--; Argc >= 0; Argc--)
+            free(Argv[Argc]);
+        return (-1);
+    }
+    run();                     /* Ok, so it's recursive, I dislike setjmp */
+    return (0);
 }
 
 /* 1st Edition reads directories as if they were ordinary files.
@@ -467,36 +561,38 @@ static int v1trap_exec(void)
  */
 static int v1open_dir(char *name)
 {
-  DIR *d;
-  char *tmpname;
-  int i;
-  struct dirent *dent;
-
-  struct v1_direct {
-    int16_t d_ino;
-    int8_t d_name[8];
-  } v1dent;
-
-  d = opendir(name);
-  if (d == NULL) return (-1);
-  tmpname = strdup(TMP_PLATE);
-  i = mkstemp(tmpname);
-  if (i == -1) {
-    fprintf(stderr, "Apout - open_dir couldn't open %s\n", tmpname);
-    exit(1);
-  }
-  unlink(tmpname);
-  free(tmpname);
-
-  while ((dent = readdir(d)) != NULL) {
-    v1dent.d_ino = dent->d_fileno & 0x7fff;
-    if (v1dent.d_ino<41) v1dent.d_ino+=100;
-    strncpy((char *)v1dent.d_name, dent->d_name, 8);
-    write(i, &v1dent, 10);
-  }
-  closedir(d);
-  lseek(i, 0, SEEK_SET);
-  return (i);
+    DIR *d;
+    char *tmpname;
+    int i;
+    struct dirent *dent;
+
+    struct v1_direct {
+        int16_t d_ino;
+        int8_t d_name[8];
+    } v1dent;
+
+    d = opendir(name);
+    if (d == NULL)
+        return (-1);
+    tmpname = strdup(TMP_PLATE);
+    i = mkstemp(tmpname);
+    if (i == -1) {
+        fprintf(stderr, "Apout - open_dir couldn't open %s\n", tmpname);
+        exit(1);
+    }
+    unlink(tmpname);
+    free(tmpname);
+
+    while ((dent = readdir(d)) != NULL) {
+        v1dent.d_ino = dent->d_fileno & 0x7fff;
+        if (v1dent.d_ino < 41)
+            v1dent.d_ino += 100;
+        strncpy((char *) v1dent.d_name, dent->d_name, 8);
+        write(i, &v1dent, 10);
+    }
+    closedir(d);
+    lseek(i, 0, SEEK_SET);
+    return (i);
 }
 
 /* Given a time, work out the number of 1/60ths of seconds since
@@ -504,19 +600,20 @@ static int v1open_dir(char *name)
  */
 u_int32_t sectosixty(time_t tim)
 {
-  time_t epoch;
-  u_int32_t diff;
-  struct tm *T;
-
-  T = gmtime(&tim);
-  T->tm_sec = T->tm_min = T->tm_hour = T->tm_mon = 0;
-  T->tm_mday = 1;
-
-  epoch = timegm(T);           /* Find time at start of year */
-  diff = 60 * (tim - epoch);
-  if (diff > 0x71172C00) {
-    fprintf(stderr, "Apout - V1 sectosixty too big by %d\n",diff-0x71172C00);
-  }
-  return (diff);
+    time_t epoch;
+    u_int32_t diff;
+    struct tm *T;
+
+    T = gmtime(&tim);
+    T->tm_sec = T->tm_min = T->tm_hour = T->tm_mon = 0;
+    T->tm_mday = 1;
+
+    epoch = timegm(T);         /* Find time at start of year */
+    diff = 60 * (tim - epoch);
+    if (diff > 0x71172C00) {
+        fprintf(stderr, "Apout - V1 sectosixty too big by %d\n",
+                diff - 0x71172C00);
+    }
+    return (diff);
 }
 #endif                         /* EMUV1 */
index 717efad..e38861c 100644 (file)
--- a/v1trap.h
+++ b/v1trap.h
 #define V1_ILGINS  33
 
 
-char *v1trap_name[]= {
-       "rele",
-       "exit",
-       "fork",
-       "read",
-       "write",
-       "open",
-       "close",
-       "wait",
-       "creat",
-       "link",
-       "unlink",
-       "exec",
-       "chdir",
-       "time",
-       "mkdir",
-       "chmod",
-       "chown",
-       "break",
-       "stat",
-       "seek",
-       "tell",
-       "mount",
-       "umount",
-       "setuid",
-       "getuid",
-       "stime",
-       "quit",
-       "intr",
-       "fstat",
-       "cemt",
-       "smdate",
-       "stty",
-       "gtty",
-       "ilgins"
+char *v1trap_name[] = {
+    "rele",
+    "exit",
+    "fork",
+    "read",
+    "write",
+    "open",
+    "close",
+    "wait",
+    "creat",
+    "link",
+    "unlink",
+    "exec",
+    "chdir",
+    "time",
+    "mkdir",
+    "chmod",
+    "chown",
+    "break",
+    "stat",
+    "seek",
+    "tell",
+    "mount",
+    "umount",
+    "setuid",
+    "getuid",
+    "stime",
+    "quit",
+    "intr",
+    "fstat",
+    "cemt",
+    "smdate",
+    "stty",
+    "gtty",
+    "ilgins"
 };
 
 
 struct tr_v1stat {
-       u_int16_t       inum;
-       u_int16_t       iflags;         /* Mode */
-       u_int8_t        inl;            /* Links */
-       u_int8_t        iuid;
-       u_int16_t       isize;
-       int16_t         iaddr[8];       /* Not used, I hope! */
-       u_int32_t       ctime;
-       u_int32_t       mtime;
-       u_int16_t       unused;
+    u_int16_t inum;
+    u_int16_t iflags;          /* Mode */
+    u_int8_t inl;              /* Links */
+    u_int8_t iuid;
+    u_int16_t isize;
+    int16_t iaddr[8];          /* Not used, I hope! */
+    u_int32_t ctime;
+    u_int32_t mtime;
+    u_int16_t unused;
 };
 
 /* Values for v1stat iflags */
@@ -111,7 +111,7 @@ struct tr_v1stat {
  * we can get at the various args of different types
  */
 typedef union {
-    int16_t   sarg[4];         /* Signed 16-bit args */
+    int16_t sarg[4];           /* Signed 16-bit args */
     u_int16_t uarg[4];         /* Unsigned 16-bit args */
 } arglist;
 
index 00a2f31..e7df4ac 100644 (file)
--- a/v7trap.c
+++ b/v7trap.c
@@ -19,9 +19,9 @@
 #include "v7trap.h"
 
 #ifdef __linux__
-# undef STREAM_BUFFERING               /* It seems to work */
+#undef STREAM_BUFFERING                /* It seems to work */
 #else
-# define STREAM_BUFFERING              /* but not for Linux */
+#define STREAM_BUFFERING       /* but not for Linux */
 #endif
 
 /* Forward prototypes */
@@ -35,7 +35,7 @@ static int open_dir P((char *name));
 static int trap_gtty P((u_int16_t fd, u_int16_t ucnt));
 static int trap_stty P((u_int16_t fd, u_int16_t ucnt));
 static int v7signal P((int sig, int val));
-static void fixv6time P((time_t *t));
+static void fixv6time P((time_t * t));
 #undef P
 
 
@@ -44,25 +44,24 @@ static void fixv6time P((time_t *t));
  * of words, and the number in registers.
  */
 struct v7sysent {
-       int nwords;
-       int nregs;
+    int nwords;
+    int nregs;
 };
 static struct v7sysent v7arg[] = {
-       {0, 0}, {1, 1}, {0, 0}, {3, 1}, {3, 1}, {2, 0}, {1, 1}, {0, 0},
-       {2, 0}, {2, 0}, {1, 0}, {2, 0}, {1, 0}, {0, 0}, {3, 0}, {2, 0},
-       {3, 0}, {1, 0}, {2, 0}, {4, 1}, {0, 0}, {3, 0}, {1, 0}, {1, 1},
-       {0, 0}, {2, 2}, {4, 1}, {1, 1}, {2, 1}, {0, 0}, {2, 0}, {2, 1},
-       {2, 1}, {2, 0}, {1, 1}, {1, 0}, {0, 0}, {2, 1}, {0, 0}, {0, 0},
-       {1, 1}, {2, 2}, {0, 0}, {1, 0}, {4, 0}, {0, 0}, {1, 1}, {0, 0},
-       {2, 0}, {0, 0}, {0, 0}, {1, 0}, {3, 0}, {1, 0}, {3, 0}, {0, 0},
-       {4, 0}, {0, 0}, {0, 0}, {3, 0}, {1, 0}, {1, 0}, {0, 0}, {0, 0}
+    {0, 0}, {1, 1}, {0, 0}, {3, 1}, {3, 1}, {2, 0}, {1, 1}, {0, 0},
+    {2, 0}, {2, 0}, {1, 0}, {2, 0}, {1, 0}, {0, 0}, {3, 0}, {2, 0},
+    {3, 0}, {1, 0}, {2, 0}, {4, 1}, {0, 0}, {3, 0}, {1, 0}, {1, 1},
+    {0, 0}, {2, 2}, {4, 1}, {1, 1}, {2, 1}, {0, 0}, {2, 0}, {2, 1},
+    {2, 1}, {2, 0}, {1, 1}, {1, 0}, {0, 0}, {2, 1}, {0, 0}, {0, 0},
+    {1, 1}, {2, 2}, {0, 0}, {1, 0}, {4, 0}, {0, 0}, {1, 1}, {0, 0},
+    {2, 0}, {0, 0}, {0, 0}, {1, 0}, {3, 0}, {1, 0}, {3, 0}, {0, 0},
+    {4, 0}, {0, 0}, {0, 0}, {3, 0}, {1, 0}, {1, 0}, {0, 0}, {0, 0}
 };
 
 static arglist V7A;
 
 
-void
-v7trap()
+void v7trap()
 {
     int i, pid, pfd[2];
     int whence;
@@ -83,34 +82,39 @@ v7trap()
 
 
 
-                               /* Work out the actual trap number, and */
-                               /* shift the PC up past any arguments */
-                               /* to the syscall. Calculate base of args */
-    trapnum= ir & 077;
-    if (trapnum==S_INDIR) {
-       lli_word(regs[PC], argbase);
-       ll_word(argbase, ir);
-        trapnum= ir & 077; argbase+=2; regs[PC]+=2;
+    /* Work out the actual trap number, and */
+    /* shift the PC up past any arguments */
+    /* to the syscall. Calculate base of args */
+    trapnum = ir & 077;
+    if (trapnum == S_INDIR) {
+        lli_word(regs[PC], argbase);
+        ll_word(argbase, ir);
+        trapnum = ir & 077;
+        argbase += 2;
+        regs[PC] += 2;
     } else {
-       argbase=regs[PC];
-       regs[PC]+= 2* (v7arg[trapnum].nwords - v7arg[trapnum].nregs);
-
-                               /* However, V6 seek() has 1 less arg */
-       if ((Binary==IS_A68 || Binary==IS_V6) || (Binary==IS_V5)) {
-           if (trapnum==S_LSEEK) regs[PC]-=2;
-       }
+        argbase = regs[PC];
+        regs[PC] += 2 * (v7arg[trapnum].nwords - v7arg[trapnum].nregs);
+
+        /* However, V6 seek() has 1 less arg */
+        if ((Binary == IS_A68 || Binary == IS_V6) || (Binary == IS_V5)) {
+            if (trapnum == S_LSEEK)
+                regs[PC] -= 2;
+        }
     }
 
-                       /* Move arguments into V7A so we can use them */
-    for (i=0; i<v7arg[trapnum].nregs; i++) V7A.uarg[i]= regs[i];
-    for (;i<v7arg[trapnum].nwords; i++,argbase+=2)
-                                       ll_word(argbase, V7A.uarg[i]);
-    TrapDebug((dbg_file, "pid %d %s: ", (int)getpid(),v7trap_name[trapnum]));
+    /* Move arguments into V7A so we can use them */
+    for (i = 0; i < v7arg[trapnum].nregs; i++)
+        V7A.uarg[i] = regs[i];
+    for (; i < v7arg[trapnum].nwords; i++, argbase += 2)
+        ll_word(argbase, V7A.uarg[i]);
+
+    TrapDebug((dbg_file, "pid %d %s: ", (int) getpid(),
+               v7trap_name[trapnum]));
 
     switch (trapnum) {
-                       /* These syscalls are not implemented, and */
-                       /* always return EPERM to the caller */
+    /* These syscalls are not implemented, and */
+    /* always return EPERM to the caller */
     case S_PHYS:
     case S_PROF:
     case S_PTRACE:
@@ -118,388 +122,496 @@ v7trap()
     case S_MOUNT:
     case S_UMOUNT:
     case S_TIMES:
-       i=-1; errno=EPERM; break;
+        i = -1;
+        errno = EPERM;
+        break;
 
-                       /* These syscalls are ignored, and */
-                       /* always return C=0 to the caller */
+    /* These syscalls are ignored, and */
+    /* always return C=0 to the caller */
     case S_LOCK:
     case S_STIME:
     case S_BREAK:
-       i=sarg1; break;
+        i = sarg1;
+        break;
     case S_SYNC:
-       sync(); i=0; break;
+        sync();
+        i = 0;
+        break;
 
     case S_SIGNAL:
-       i= v7signal(uarg1, uarg2);
-       break;
+        i = v7signal(uarg1, uarg2);
+        break;
     case S_EXIT:
-       exit(regs[0]);
-       i=-1; errno=EPERM; break;
+        exit(regs[0]);
+        i = -1;
+        errno = EPERM;
+        break;
     case S_NICE:
-       i= nice(regs[0]); break;
+        i = nice(regs[0]);
+        break;
     case S_PAUSE:
-       i = pause(); break;
+        i = pause();
+        break;
     case S_DUP:
-       if (sarg1 > 0100) {
-           sarg1 -= 0100;
-           i = dup2(sarg1, sarg2);     /* Check that sarg2, not r1, holds */
+        if (sarg1 > 0100) {
+            sarg1 -= 0100;
+            i = dup2(sarg1, sarg2);    /* Check that sarg2, not r1, holds */
 #ifdef STREAM_BUFFERING
-           if ((i!=-1) && ValidFD(sarg2) && ValidFD(sarg1) && stream[sarg1]) {
-               fmode= streammode[sarg1];
-               stream[sarg2] = fdopen(sarg2, fmode);
-               streammode[sarg2]=fmode;
-           }
+            if ((i != -1) && ValidFD(sarg2) && ValidFD(sarg1)
+                    && stream[sarg1]) {
+                fmode = streammode[sarg1];
+                stream[sarg2] = fdopen(sarg2, fmode);
+                streammode[sarg2] = fmode;
+            }
 #endif
-       } else
-           i = dup(sarg1);
+        } else
+            i = dup(sarg1);
 #ifdef STREAM_BUFFERING
-           if ((i!=-1) && ValidFD(i)&& ValidFD(sarg1) && stream[sarg1]) {
-               fmode= streammode[sarg1];
-               stream[i] = fdopen(i, fmode);
-               streammode[i]=fmode;
-           }
+        if ((i != -1) && ValidFD(i) && ValidFD(sarg1) && stream[sarg1]) {
+            fmode = streammode[sarg1];
+            stream[i] = fdopen(i, fmode);
+            streammode[i] = fmode;
+        }
 #endif
-       break;
+        break;
     case S_TIME:
-       tim= larg;
-       i = time(&tim);
-       
-       if ((Binary==IS_A68 || Binary==IS_V6) || (Binary==IS_V5)) {
-         fixv6time(&tim);      /* Fix annoying bug in V5/V6 ctime() */
-       }
-       regs[1] = tim & 0xffff;
-       i = tim >> 16;
-       break;
+        tim = larg;
+        i = time(&tim);
+
+        if ((Binary == IS_A68 || Binary == IS_V6) || (Binary == IS_V5)) {
+            fixv6time(&tim);   /* Fix annoying bug in V5/V6 ctime() */
+        }
+        regs[1] = tim & 0xffff;
+        i = tim >> 16;
+        break;
     case S_ALARM:
-       i = alarm(uarg1); break;
+        i = alarm(uarg1);
+        break;
     case S_UMASK:
-       i = umask(uarg1); break;
+        i = umask(uarg1);
+        break;
     case S_LSEEK:
-                               /* Work out the args before we do the lseek */
-       if ((Binary==IS_A68 || Binary==IS_V6) || (Binary==IS_V5)) {
-           whence=uarg3;
-           switch (uarg3) {
-               case 0: larg= uarg2; break;
-               case 1: 
-               case 2: larg= sarg2; break;
-               case 3: whence=0; larg= 512 * uarg2; break;
-               case 4: whence=1; larg= 512 * sarg2; break;
-               case 5: whence=2; larg= 512 * sarg2; break;
-           }
-       } else {
-           larg = (uarg2 << 16) | uarg3;
-           whence= uarg4;
-       }
+        /* Work out the args before we do the lseek */
+        if ((Binary == IS_A68 || Binary == IS_V6) || (Binary == IS_V5)) {
+            whence = uarg3;
+            switch (uarg3) {
+            case 0:
+                larg = uarg2;
+                break;
+            case 1:
+            case 2:
+                larg = sarg2;
+                break;
+            case 3:
+                whence = 0;
+                larg = 512 * uarg2;
+                break;
+            case 4:
+                whence = 1;
+                larg = 512 * sarg2;
+                break;
+            case 5:
+                whence = 2;
+                larg = 512 * sarg2;
+                break;
+            }
+        } else {
+            larg = (uarg2 << 16) | uarg3;
+            whence = uarg4;
+        }
 #ifdef STREAM_BUFFERING
-       if (ValidFD(sarg1) && stream[sarg1]) {
-           i = fseek(stream[sarg1], larg, whence);
-           if (i == 0) i = ftell(stream[sarg1]);
-       } else
+        if (ValidFD(sarg1) && stream[sarg1]) {
+            i = fseek(stream[sarg1], larg, whence);
+            if (i == 0)
+                i = ftell(stream[sarg1]);
+        } else
 #endif
-           i = lseek(sarg1, larg, whence);
+            i = lseek(sarg1, larg, whence);
 
         TrapDebug((dbg_file, " on fd %d amt %ld whence %d return %d ",
-                                       sarg1, larg, whence, i));
-       if ((Binary==IS_A68 || Binary==IS_V6) || (Binary==IS_V5)) {
-          if (i!=-1) i=0;
-          break;
-       }
-       regs[1] = i & 0xffff;
-       i = i >> 16;
-       break;
+                   sarg1, larg, whence, i));
+        if ((Binary == IS_A68 || Binary == IS_V6) || (Binary == IS_V5)) {
+            if (i != -1)
+                i = 0;
+            break;
+        }
+        regs[1] = i & 0xffff;
+        i = i >> 16;
+        break;
     case S_READ:
-       buf = (char *)&dspace[uarg2];
+        buf = (char *) &dspace[uarg2];
 #ifdef STREAM_BUFFERING
-       if (ValidFD(sarg1) && stream[sarg1])
-           i = fread(buf, 1, uarg3, stream[sarg1]);
-       else
+        if (ValidFD(sarg1) && stream[sarg1])
+            i = fread(buf, 1, uarg3, stream[sarg1]);
+        else
 #endif
-           i = read(sarg1, buf, uarg3);
-        TrapDebug((dbg_file, " on fd %d return %d ",sarg1,i)); 
-       break;
+            i = read(sarg1, buf, uarg3);
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
+        break;
     case S_LINK:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       buf2 = xlate_filename((char *)&dspace[uarg2]);
-       if (!strcmp(buf, buf2)) i=0;    /* Happens on mkdir(1) */
-       else i = link(buf, buf2);
-       break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        buf2 = xlate_filename((char *) &dspace[uarg2]);
+        if (!strcmp(buf, buf2))
+            i = 0;             /* Happens on mkdir(1) */
+        else
+            i = link(buf, buf2);
+        break;
     case S_ACCESS:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = access(buf, sarg2);
-       break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = access(buf, sarg2);
+        break;
     case S_WRITE:
-       buf = (char *)&dspace[uarg2];
+        buf = (char *) &dspace[uarg2];
 #ifdef STREAM_BUFFERING
-       if (ValidFD(sarg1) && stream[sarg1])
-           i = fwrite(buf, 1, uarg3, stream[sarg1]);
-       else
+        if (ValidFD(sarg1) && stream[sarg1])
+            i = fwrite(buf, 1, uarg3, stream[sarg1]);
+        else
 #endif
-           i = write(sarg1, buf, uarg3);
-        TrapDebug((dbg_file, " on fd %d return %d ",sarg1,i));
-       break;
+            i = write(sarg1, buf, uarg3);
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
+        break;
     case S_CLOSE:
 #ifdef STREAM_BUFFERING
-       if (ValidFD(sarg1) && stream[sarg1]) {
-           i = fclose(stream[sarg1]);
-           stream[sarg1] = NULL;
-       } else
+        if (ValidFD(sarg1) && stream[sarg1]) {
+            i = fclose(stream[sarg1]);
+            stream[sarg1] = NULL;
+        } else
 #endif
-           i = close(sarg1);
-        TrapDebug((dbg_file, " on fd %d return %d ",sarg1,i));
-       break;
+            i = close(sarg1);
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
+        break;
     case S_GTTY:
-       i = trap_gtty(uarg1, uarg2); break;
+        i = trap_gtty(uarg1, uarg2);
+        break;
     case S_STTY:
-       i = trap_stty(uarg1, uarg2); break;
+        i = trap_stty(uarg1, uarg2);
+        break;
     case S_IOCTL:
-       switch (uarg2) {
-       case (('t' << 8) + 8):  /* GTTY */
-           i = trap_gtty(uarg1, uarg3); break;
-       case (('t' << 8) + 9):  /* STTY */
-           i = trap_stty(uarg1, uarg3); break;
-       default:
-           i=0;
-       }
-       break;
+        switch (uarg2) {
+        case (('t' << 8) + 8): /* GTTY */
+            i = trap_gtty(uarg1, uarg3);
+            break;
+        case (('t' << 8) + 9): /* STTY */
+            i = trap_stty(uarg1, uarg3);
+            break;
+        default:
+            i = 0;
+        }
+        break;
     case S_FTIME:
-       buf = (char *)&dspace[uarg1];
-       tb = (struct tr_timeb *) buf;
-       i = gettimeofday(&tv, &tz);
-       if (i == -1) break;
-       copylong(tb->time, tv.tv_sec);
+        buf = (char *) &dspace[uarg1];
+        tb = (struct tr_timeb *) buf;
+        i = gettimeofday(&tv, &tz);
+        if (i == -1)
+            break;
+        copylong(tb->time, tv.tv_sec);
 #if 0
-       buf = (char *) &(tb->time);
-       buf2 = (char *) &(tv.tv_sec);
-       buf[0] = buf2[2]; buf[1] = buf2[3]; buf[2] = buf2[0]; buf[3] = buf2[1];
+        buf = (char *) &(tb->time);
+        buf2 = (char *) &(tv.tv_sec);
+        buf[0] = buf2[2];
+        buf[1] = buf2[3];
+        buf[2] = buf2[0];
+        buf[3] = buf2[1];
 #endif
-       tb->millitm = tv.tv_usec / 1000;
-       tb->timezone = tz.tz_minuteswest;
-       tb->dstflag = tz.tz_dsttime;
-       break;
+        tb->millitm = tv.tv_usec / 1000;
+        tb->timezone = tz.tz_minuteswest;
+        tb->dstflag = tz.tz_dsttime;
+        break;
     case S_STAT:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       if (buf[0]=='\0') buf=".";              /* Not documented anywhere */
-       if (uarg1==0) buf=".";
-       buf2 = (char *)&dspace[uarg2];
-       i = stat(buf, &stbuf);
-        TrapDebug((dbg_file, " on %s return %d ",buf,i));
-       goto dostat;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        if (buf[0] == '\0')
+            buf = "."; /* Not documented anywhere */
+        if (uarg1 == 0)
+            buf = ".";
+        buf2 = (char *) &dspace[uarg2];
+        i = stat(buf, &stbuf);
+        TrapDebug((dbg_file, " on %s return %d ", buf, i));
+        goto dostat;
     case S_FSTAT:
-       buf2 = (char *)&dspace[uarg2];
-       i = fstat(sarg1, &stbuf);
-        TrapDebug((dbg_file, " on fd %d return %d ",sarg1,i));
+        buf2 = (char *) &dspace[uarg2];
+        i = fstat(sarg1, &stbuf);
+        TrapDebug((dbg_file, " on fd %d return %d ", sarg1, i));
 
 dostat:
-       if (i == -1) break;
-                                       /* V6 and V7 have different stats */
-       if ((Binary==IS_A68 || Binary==IS_V6) || (Binary==IS_V5)) {
-           t6 = (struct tr_v6stat *) buf2;
-           t6->idev = stbuf.st_dev;
-           t6->inum = stbuf.st_ino;
-           t6->iflags = stbuf.st_mode;
-           t6->inl = stbuf.st_nlink;
-           t6->iuid = stbuf.st_uid;
-           t6->igid = stbuf.st_gid;
-           t6->isize = (u_int16_t) (stbuf.st_size & 0xffff);
-           t6->isize0 = (u_int8_t) ((stbuf.st_size>>16) & 0xff);
-                                       /* Fix annoying bug in V5/V6 ctime() */
-           fixv6time(&(stbuf.st_atime));
-           fixv6time(&(stbuf.st_mtime));
-           copylong(t6->atime, stbuf.st_atime);
-           copylong(t6->mtime, stbuf.st_mtime);
+        if (i == -1)
+            break;
+        /* V6 and V7 have different stats */
+        if ((Binary == IS_A68 || Binary == IS_V6) || (Binary == IS_V5)) {
+            t6 = (struct tr_v6stat *) buf2;
+            t6->idev = stbuf.st_dev;
+            t6->inum = stbuf.st_ino;
+            t6->iflags = stbuf.st_mode;
+            t6->inl = stbuf.st_nlink;
+            t6->iuid = stbuf.st_uid;
+            t6->igid = stbuf.st_gid;
+            t6->isize = (u_int16_t) (stbuf.st_size & 0xffff);
+            t6->isize0 = (u_int8_t) ((stbuf.st_size >> 16) & 0xff);
+            /* Fix annoying bug in V5/V6 ctime() */
+            fixv6time(&(stbuf.st_atime));
+            fixv6time(&(stbuf.st_mtime));
+            copylong(t6->atime, stbuf.st_atime);
+            copylong(t6->mtime, stbuf.st_mtime);
 #if 0
-           buf = (char *) &(t6->atime);
-           buf2 = (char *) &(stbuf.st_atime);
-           buf[0]= buf2[2]; buf[1]= buf2[3]; buf[2]= buf2[0]; buf[3]= buf2[1];
-           buf = (char *) &(t6->mtime);
-           buf2 = (char *) &(stbuf.st_mtime);
-           buf[0]= buf2[2]; buf[1]= buf2[3]; buf[2]= buf2[0]; buf[3]= buf2[1];
+            buf = (char *) &(t6->atime);
+            buf2 = (char *) &(stbuf.st_atime);
+            buf[0] = buf2[2];
+            buf[1] = buf2[3];
+            buf[2] = buf2[0];
+            buf[3] = buf2[1];
+            buf = (char *) &(t6->mtime);
+            buf2 = (char *) &(stbuf.st_mtime);
+            buf[0] = buf2[2];
+            buf[1] = buf2[3];
+            buf[2] = buf2[0];
+            buf[3] = buf2[1];
 #endif
-       } else {
-           t = (struct tr_v7stat *) buf2;
-           t->st_dev = stbuf.st_dev;
-           t->st_ino = stbuf.st_ino;
-           t->st_mode = stbuf.st_mode;
-           t->st_nlink = stbuf.st_nlink;
-           t->st_uid = stbuf.st_uid;
-           t->st_gid = stbuf.st_gid;
-           t->st_rdev = stbuf.st_rdev;
-           copylong(t->st_size, stbuf.st_size);
-           copylong(t->st_atim, stbuf.st_atime);
-           copylong(t->st_mtim, stbuf.st_mtime);
-           copylong(t->st_ctim, stbuf.st_ctime);
+        } else {
+            t = (struct tr_v7stat *) buf2;
+            t->st_dev = stbuf.st_dev;
+            t->st_ino = stbuf.st_ino;
+            t->st_mode = stbuf.st_mode;
+            t->st_nlink = stbuf.st_nlink;
+            t->st_uid = stbuf.st_uid;
+            t->st_gid = stbuf.st_gid;
+            t->st_rdev = stbuf.st_rdev;
+            copylong(t->st_size, stbuf.st_size);
+            copylong(t->st_atim, stbuf.st_atime);
+            copylong(t->st_mtim, stbuf.st_mtime);
+            copylong(t->st_ctim, stbuf.st_ctime);
 #if 0
-           buf = (char *) &(t->st_size);
-           buf2 = (char *) &(stbuf.st_size);
-           buf[0]= buf2[2]; buf[1]= buf2[3]; buf[2]= buf2[0]; buf[3]= buf2[1];
-           buf = (char *) &(t->st_atim);
-           buf2 = (char *) &(stbuf.st_atime);
-           buf[0]= buf2[2]; buf[1]= buf2[3]; buf[2]= buf2[0]; buf[3]= buf2[1];
-           buf = (char *) &(t->st_mtim);
-           buf2 = (char *) &(stbuf.st_mtime);
-           buf[0]= buf2[2]; buf[1]= buf2[3]; buf[2]= buf2[0]; buf[3]= buf2[1];
-           buf = (char *) &(t->st_ctim);
-           buf2 = (char *) &(stbuf.st_ctime);
-           buf[0]= buf2[2]; buf[1]= buf2[3]; buf[2]= buf2[0]; buf[3]= buf2[1];
+            buf = (char *) &(t->st_size);
+            buf2 = (char *) &(stbuf.st_size);
+            buf[0] = buf2[2];
+            buf[1] = buf2[3];
+            buf[2] = buf2[0];
+            buf[3] = buf2[1];
+            buf = (char *) &(t->st_atim);
+            buf2 = (char *) &(stbuf.st_atime);
+            buf[0] = buf2[2];
+            buf[1] = buf2[3];
+            buf[2] = buf2[0];
+            buf[3] = buf2[1];
+            buf = (char *) &(t->st_mtim);
+            buf2 = (char *) &(stbuf.st_mtime);
+            buf[0] = buf2[2];
+            buf[1] = buf2[3];
+            buf[2] = buf2[0];
+            buf[3] = buf2[1];
+            buf = (char *) &(t->st_ctim);
+            buf2 = (char *) &(stbuf.st_ctime);
+            buf[0] = buf2[2];
+            buf[1] = buf2[3];
+            buf[2] = buf2[0];
+            buf[3] = buf2[1];
 #endif
-       }
-       break;
+        }
+        break;
     case S_UTIME:
-       utv[0].tv_usec = utv[1].tv_usec = 0;
-       copylong(dspace[uarg2], utv[0].tv_sec);
-       copylong(dspace[uarg2+4], utv[1].tv_sec);
-       buf = xlate_filename((char *)&dspace[uarg1]);
+        utv[0].tv_usec = utv[1].tv_usec = 0;
+        copylong(dspace[uarg2], utv[0].tv_sec);
+        copylong(dspace[uarg2 + 4], utv[1].tv_sec);
+        buf = xlate_filename((char *) &dspace[uarg1]);
 #if 0
-       buf2 = &dspace[uarg2];
-       buf3 = (char *) &(utv[0].tv_sec);
-       buf3[0]= buf2[2]; buf3[1]= buf2[3]; buf3[2]= buf2[0]; buf3[3]= buf2[1];
-
-       buf2 += 4;
-       buf3 = (char *) &(utv[1].tv_sec);
-       buf3[0]= buf2[2]; buf3[1]= buf2[3]; buf3[2]= buf2[0]; buf3[3]= buf2[1];
+        buf2 = &dspace[uarg2];
+        buf3 = (char *) &(utv[0].tv_sec);
+        buf3[0] = buf2[2];
+        buf3[1] = buf2[3];
+        buf3[2] = buf2[0];
+        buf3[3] = buf2[1];
+
+        buf2 += 4;
+        buf3 = (char *) &(utv[1].tv_sec);
+        buf3[0] = buf2[2];
+        buf3[1] = buf2[3];
+        buf3[2] = buf2[0];
+        buf3[3] = buf2[1];
 #endif
 
-       i = utimes(buf, utv); break;
+        i = utimes(buf, utv);
+        break;
     case S_UNLINK:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = unlink(buf); break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = unlink(buf);
+        break;
     case S_OPEN:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-
-       i = stat(buf, &stbuf);  /* If file is a directory */
-       if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
-           i = open_dir(buf);
-           fmode = "w+";
-            TrapDebug((dbg_file, "(dir) on %s return %d ",buf,i));
-       } else {
-           switch (sarg2) {
-             case 0: sarg2 = O_RDONLY; fmode = "r"; break;
-             case 1: sarg2 = O_WRONLY; fmode = "w"; break;
-             default: sarg2 = O_RDWR; fmode = "w+"; break;
-           }
-           i = open(buf, sarg2);
-            TrapDebug((dbg_file, " on %s return %d ",buf,i));
-       }
+        buf = xlate_filename((char *) &dspace[uarg1]);
+
+        i = stat(buf, &stbuf); /* If file is a directory */
+        if (i == 0 && (stbuf.st_mode & S_IFDIR)) {
+            i = open_dir(buf);
+            fmode = "w+";
+            TrapDebug((dbg_file, "(dir) on %s return %d ", buf, i));
+        } else {
+            switch (sarg2) {
+            case 0:
+                sarg2 = O_RDONLY;
+                fmode = "r";
+                break;
+            case 1:
+                sarg2 = O_WRONLY;
+                fmode = "w";
+                break;
+            default:
+                sarg2 = O_RDWR;
+                fmode = "w+";
+                break;
+            }
+            i = open(buf, sarg2);
+            TrapDebug((dbg_file, " on %s return %d ", buf, i));
+        }
 
 #ifdef STREAM_BUFFERING
-       if (i==-1) break;
+        if (i == -1)
+            break;
 #if 0
-       /* Now get its stream pointer if possible */
-       /* Can someone explain why fdopen doesn't work for O_RDWR? */
-       if (ValidFD(i) && !isatty(i) && (sarg2!=O_RDWR)) {
-           stream[i] = fdopen(i, fmode); streammode[i]=fmode;
-       }
+        /* Now get its stream pointer if possible */
+        /* Can someone explain why fdopen doesn't work for O_RDWR? */
+        if (ValidFD(i) && !isatty(i) && (sarg2 != O_RDWR)) {
+            stream[i] = fdopen(i, fmode);
+            streammode[i] = fmode;
+        }
 #endif
-       stream[i] = fdopen(i, fmode); streammode[i]=fmode;
+        stream[i] = fdopen(i, fmode);
+        streammode[i] = fmode;
 #endif
-       break;
+        break;
     case S_MKNOD:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-
-       if ((uarg2 & 077000) == 040000) {
-               /* It's a directory creation */
-               i= mkdir(buf, uarg2 & 0777);
-       } else
-               i = mknod(buf, uarg2, sarg3);
-       break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+
+        if ((uarg2 & 077000) == 040000) {
+            /* It's a directory creation */
+            = mkdir(buf, uarg2 & 0777);
+        } else
+            i = mknod(buf, uarg2, sarg3);
+        break;
     case S_CHMOD:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = chmod(buf, uarg2); break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chmod(buf, uarg2);
+        break;
     case S_KILL:
-       i = kill(sarg1, sarg2); break;
+        i = kill(sarg1, sarg2);
+        break;
     case S_CHOWN:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = chown(buf, sarg2, sarg3); break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chown(buf, sarg2, sarg3);
+        break;
     case S_PIPE:
-       i = pipe(pfd);
-       if (i == -1) break;
+        i = pipe(pfd);
+        if (i == -1)
+            break;
 #ifdef STREAM_BUFFERING
-       if (ValidFD(pfd[0])) {
-               stream[pfd[0]] = fdopen(pfd[0], "r");
-               streammode[pfd[0]]= "r";
-       }
-       if (ValidFD(pfd[1])) {
-               stream[pfd[1]] = fdopen(pfd[1], "w");
-               streammode[pfd[1]]= "w";
-       }
+        if (ValidFD(pfd[0])) {
+            stream[pfd[0]] = fdopen(pfd[0], "r");
+            streammode[pfd[0]] = "r";
+        }
+        if (ValidFD(pfd[1])) {
+            stream[pfd[1]] = fdopen(pfd[1], "w");
+            streammode[pfd[1]] = "w";
+        }
 #endif
-       i = pfd[0]; regs[1] = pfd[1]; break;
+        i = pfd[0];
+        regs[1] = pfd[1];
+        break;
     case S_CHROOT:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       if (buf == NULL) { i=-1; errno=ENOENT; break; }
-       set_apout_root(buf);
-       i=0; break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        if (buf == NULL) {
+            i = -1;
+            errno = ENOENT;
+            break;
+        }
+        set_apout_root(buf);
+        i = 0;
+        break;
     case S_CHDIR:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = chdir(buf); break;
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = chdir(buf);
+        break;
     case S_CREAT:
-       buf = xlate_filename((char *)&dspace[uarg1]);
-       i = creat(buf, sarg2);
+        buf = xlate_filename((char *) &dspace[uarg1]);
+        i = creat(buf, sarg2);
 #ifdef STREAM_BUFFERING
-       if (i==-1) break;
-       if (ValidFD(i)) {
-               stream[i] = fdopen(i, "w");
-               streammode[i]= "w";
-       }
+        if (i == -1)
+            break;
+        if (ValidFD(i)) {
+            stream[i] = fdopen(i, "w");
+            streammode[i] = "w";
+        }
 #endif
-       break;
+        break;
     case S_EXECE:
-       i= trap_exec(1); break;
-       
+        i = trap_exec(1);
+        break;
+
     case S_EXEC:
-       i= trap_exec(0); break;
+        i = trap_exec(0);
+        break;
     case S_WAIT:
-       i = wait(&pid);
-       if (i == -1) break;
-       regs[1] = pid; break;
+        i = wait(&pid);
+        if (i == -1)
+            break;
+        regs[1] = pid;
+        break;
     case S_FORK:
-       pid = getpid();
-       i = fork();
-       switch (i) {
-           /* Error, inform the parent */
-       case -1: break;
-           /* Child gets ppid in r0 */
-       case 0: i = pid; break;
-           /* Parent: Skip child `bf', pid into r0 */
-       default: regs[PC] += 2; 
-       }
-       break;
+        pid = getpid();
+        i = fork();
+        switch (i) {
+        /* Error, inform the parent */
+        case -1:
+            break;
+        /* Child gets ppid in r0 */
+        case 0:
+            i = pid;
+            break;
+        /* Parent: Skip child `bf', pid into r0 */
+        default:
+            regs[PC] += 2;
+        }
+        break;
     case S_GETUID:
-       i = geteuid(); regs[1] = i;
-       i = getuid(); break;
+        i = geteuid();
+        regs[1] = i;
+        i = getuid();
+        break;
     case S_GETPID:
-       i = getpid(); break;
+        i = getpid();
+        break;
     case S_GETGID:
-       i = getegid(); regs[1] = i;
-       i = getgid(); break;
+        i = getegid();
+        regs[1] = i;
+        i = getgid();
+        break;
     case S_SETUID:
-       i = setuid(sarg1); break;
+        i = setuid(sarg1);
+        break;
     case S_SETGID:
-       i = setgid(sarg1); break;
+        i = setgid(sarg1);
+        break;
     default:
-       if (trapnum>S_CHROOT) {
-         fprintf(stderr,"Apout - unknown syscall %d at PC 0%o\n",
-                                                       trapnum,regs[PC]);
-       } else {
-         fprintf(stderr,"Apout - the %s syscall is not yet implemented\n",
-                                               v7trap_name[trapnum]);
-       }
-       exit(1);
+        if (trapnum > S_CHROOT) {
+            fprintf(stderr, "Apout - unknown syscall %d at PC 0%o\n",
+                    trapnum, regs[PC]);
+        } else {
+            fprintf(stderr,
+                    "Apout - the %s syscall is not yet implemented\n",
+                    v7trap_name[trapnum]);
+        }
+        exit(1);
     }
 
-       /* Set r0 to either errno or i, */
-       /* and clear/set C bit */
+    /* Set r0 to either errno or i, */
+    /* and clear/set C bit */
 
     if (i == -1) {
-       SET_CC_C();
-       TrapDebug((dbg_file, "errno is %s\n", strerror(errno)));
+        SET_CC_C();
+        TrapDebug((dbg_file, "errno is %s\n", strerror(errno)));
     } else {
-       CLR_CC_C(); regs[0]=i;
+        CLR_CC_C();
+        regs[0] = i;
 #ifdef DEBUG
-       if (trap_debug) {
-         fprintf(dbg_file, "return %d\n", i);
-         fflush(dbg_file);
-       }
+        if (trap_debug) {
+            fprintf(dbg_file, "return %d\n", i);
+            fflush(dbg_file);
+        }
 #endif
     }
     return;
@@ -508,58 +620,62 @@ dostat:
 
 /* Translate V7 signal value to our value. */
 static int v7sig[] = {
-      0, SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGIOT, SIGEMT,
-      SIGFPE, SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGALRM, SIGTERM
+    0, SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGIOT, SIGEMT,
+    SIGFPE, SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGALRM, SIGTERM
 };
 
-static int
-trap_exec(int want_env)
+static int trap_exec(int want_env)
 {
     int i;
     u_int16_t cptr, cptr2;
     char *buf, *name, *origpath;
 
-    origpath = strdup((char *)&dspace[uarg1]);
+    origpath = strdup((char *) &dspace[uarg1]);
     name = xlate_filename(origpath);
     TrapDebug((dbg_file, "%s Execing %s ", progname, name));
 
-    for (i=0;i<V7_NSIG;i++) signal(v7sig[i], SIG_DFL);
+    for (i = 0; i < V7_NSIG; i++)
+        signal(v7sig[i], SIG_DFL);
 
-    cptr=uarg2;
+    cptr = uarg2;
 
-    Argc=0; Envc=0;
+    Argc = 0;
+    Envc = 0;
     while (Argc < MAX_ARGS) {
-       ll_word(cptr, cptr2);
-       if (cptr2 == 0)
-           break;
-       buf = (char *)&dspace[cptr2];
-       Argv[Argc++] = strdup(buf);
-       cptr += 2;
-       TrapDebug((dbg_file, "%s ", buf));
+        ll_word(cptr, cptr2);
+        if (cptr2 == 0)
+            break;
+        buf = (char *) &dspace[cptr2];
+        Argv[Argc++] = strdup(buf);
+        cptr += 2;
+        TrapDebug((dbg_file, "%s ", buf));
     }
     Argv[Argc] = NULL;
     TrapDebug((dbg_file, "\n"));
 
     if (want_env) {
-       cptr=uarg3;
-       while (Envc < MAX_ARGS) {
-           ll_word(cptr, cptr2);
-           if (cptr2 == 0)
-               break;
-           buf = (char *)&dspace[cptr2];
-           Envp[Envc++] = strdup(buf);
-           cptr += 2;
-       }
+        cptr = uarg3;
+        while (Envc < MAX_ARGS) {
+            ll_word(cptr, cptr2);
+            if (cptr2 == 0)
+                break;
+            buf = (char *) &dspace[cptr2];
+            Envp[Envc++] = strdup(buf);
+            cptr += 2;
+        }
     }
     Envp[Envc] = NULL;
 
     if (load_a_out(name, origpath, want_env) == -1) {
-       for (Argc--; Argc >= 0; Argc--) free(Argv[Argc]);
-       for (Envc--; Envc >= 0; Envc--) free(Envp[Envc]);
-       errno= ENOENT; return(-1);
+        for (Argc--; Argc >= 0; Argc--)
+            free(Argv[Argc]);
+        for (Envc--; Envc >= 0; Envc--)
+            free(Envp[Envc]);
+        errno = ENOENT;
+        return (-1);
     }
     run();                     /* Ok, so it's recursive, I dislike setjmp */
-    return(0);
+    return (0);
 }
 
 /* 7th Edition reads directories as if they were ordinary files.
@@ -567,8 +683,7 @@ trap_exec(int want_env)
  * real file, which is passed back to the open call.
  * Limitation: 32-bit inode numbers are truncated to 16-bit ones.
  */
-static int
-open_dir(char *name)
+static int open_dir(char *name)
 {
     DIR *d;
     char *tmpname;
@@ -576,31 +691,33 @@ open_dir(char *name)
     struct dirent *dent;
 
     struct old_direct {
-       int16_t d_ino;
-       int8_t d_name[14];
+        int16_t d_ino;
+        int8_t d_name[14];
     } odent;
 
     d = opendir(name);
-    if (d == NULL) return (-1);
-    tmpname= strdup(TMP_PLATE);
-    i= mkstemp(tmpname);
+    if (d == NULL)
+        return (-1);
+    tmpname = strdup(TMP_PLATE);
+    i = mkstemp(tmpname);
     if (i == -1) {
-       fprintf(stderr,"Apout - open_dir couldn't open %s\n", tmpname); exit(1);
+        fprintf(stderr, "Apout - open_dir couldn't open %s\n", tmpname);
+        exit(1);
     }
-    unlink(tmpname); free(tmpname);
+    unlink(tmpname);
+    free(tmpname);
 
     while ((dent = readdir(d)) != NULL) {
-       odent.d_ino = dent->d_fileno;
-       strncpy((char *)odent.d_name, dent->d_name, 14);
-       write(i, &odent, 16);
+        odent.d_ino = dent->d_fileno;
+        strncpy((char *) odent.d_name, dent->d_name, 14);
+        write(i, &odent, 16);
     }
     closedir(d);
     lseek(i, 0, SEEK_SET);
     return (i);
 }
 
-static int
-trap_gtty(u_int16_t fd, u_int16_t ucnt)
+static int trap_gtty(u_int16_t fd, u_int16_t ucnt)
 {
     struct tr_sgttyb *sgtb;    /* used in GTTY/STTY */
     struct termios tios;       /* used in GTTY/STTY */
@@ -608,104 +725,109 @@ trap_gtty(u_int16_t fd, u_int16_t ucnt)
 
     i = tcgetattr(fd, &tios);
     if (i == -1)
-       return i;
+        return i;
     CLR_CC_C();
-    sgtb = (struct tr_sgttyb *) & dspace[ucnt];
-    sgtb->sg_ispeed = cfgetispeed(&tios); /* tios.c_ispeed; --gray */
-    sgtb->sg_ospeed = cfgetospeed(&tios); /* tios.c_ospeed; --gray */
+    sgtb = (struct tr_sgttyb *) &dspace[ucnt];
+    sgtb->sg_ispeed = cfgetispeed(&tios);      /* tios.c_ispeed; --gray */
+    sgtb->sg_ospeed = cfgetospeed(&tios);      /* tios.c_ospeed; --gray */
     sgtb->sg_erase = tios.c_cc[VERASE];
     sgtb->sg_kill = tios.c_cc[VKILL];
     sgtb->sg_flags = 0;
     if (tios.c_oflag & OXTABS)
-       sgtb->sg_flags |= TR_XTABS;
+        sgtb->sg_flags |= TR_XTABS;
     if (tios.c_cflag & PARENB) {
-       if (tios.c_cflag & PARODD)
-           sgtb->sg_flags |= TR_ODDP;
-       else
-           sgtb->sg_flags |= TR_EVENP;
+        if (tios.c_cflag & PARODD)
+            sgtb->sg_flags |= TR_ODDP;
+        else
+            sgtb->sg_flags |= TR_EVENP;
     } else
-       sgtb->sg_flags |= TR_ANYP;
+        sgtb->sg_flags |= TR_ANYP;
     if (tios.c_oflag & ONLCR)
-       sgtb->sg_flags |= TR_CRMOD;
+        sgtb->sg_flags |= TR_CRMOD;
     if (tios.c_lflag & ECHO)
-       sgtb->sg_flags |= TR_ECHO;
+        sgtb->sg_flags |= TR_ECHO;
     if (!(tios.c_lflag & ICANON)) {
-       if (!(tios.c_lflag & ECHO))
-           sgtb->sg_flags |= TR_CBREAK;
-       else
-           sgtb->sg_flags |= TR_RAW;
+        if (!(tios.c_lflag & ECHO))
+            sgtb->sg_flags |= TR_CBREAK;
+        else
+            sgtb->sg_flags |= TR_RAW;
     }
     return 0;
 }
-static int
-trap_stty(u_int16_t fd, u_int16_t ucnt)
+
+static int trap_stty(u_int16_t fd, u_int16_t ucnt)
 {
     struct tr_sgttyb *sgtb;    /* used in GTTY/STTY */
     struct termios tios;       /* used in GTTY/STTY */
     int i;
 
     if (ucnt != 0) {
-       sgtb = (struct tr_sgttyb *) & dspace[ucnt];
-       cfsetispeed(&tios, sgtb->sg_ispeed); 
-       cfsetospeed(&tios, sgtb->sg_ospeed);
-       tios.c_cc[VERASE] = sgtb->sg_erase;
-       tios.c_cc[VKILL] = sgtb->sg_kill;
-       if (sgtb->sg_flags & TR_XTABS)
-           tios.c_oflag |= OXTABS;
-       if (sgtb->sg_flags & TR_ODDP) {
-           tios.c_cflag |= PARENB;
-           tios.c_cflag &= ~PARODD;
-       }
-       if (sgtb->sg_flags & TR_EVENP)
-           tios.c_cflag |= PARENB | PARODD;
-       if (sgtb->sg_flags & TR_ANYP)
-           tios.c_cflag &= ~PARENB;
-       if (sgtb->sg_flags & TR_CRMOD)
-           tios.c_oflag |= ONLCR;
-       if (sgtb->sg_flags & TR_ECHO)
-           tios.c_lflag |= ECHO;
-       if (sgtb->sg_flags & TR_RAW) {
-           tios.c_lflag &= (~ICANON) & (~ECHO);
-           for (i = 0; i < NCCS; i++)
-               tios.c_cc[i] = 0;
-           tios.c_cc[VMIN] = 1;
-       }
-       if (sgtb->sg_flags & TR_CBREAK) {
-           tios.c_lflag &= (~ICANON);
-           tios.c_lflag |= ECHO;
-           for (i = 0; i < NCCS; i++)
-               tios.c_cc[i] = 0;
-           tios.c_cc[VMIN] = 1;
-       }
-       i = tcsetattr(fd, TCSANOW, &tios);
-       return (i);
+        sgtb = (struct tr_sgttyb *) &dspace[ucnt];
+        cfsetispeed(&tios, sgtb->sg_ispeed);
+        cfsetospeed(&tios, sgtb->sg_ospeed);
+        tios.c_cc[VERASE] = sgtb->sg_erase;
+        tios.c_cc[VKILL] = sgtb->sg_kill;
+        if (sgtb->sg_flags & TR_XTABS)
+            tios.c_oflag |= OXTABS;
+        if (sgtb->sg_flags & TR_ODDP) {
+            tios.c_cflag |= PARENB;
+            tios.c_cflag &= ~PARODD;
+        }
+        if (sgtb->sg_flags & TR_EVENP)
+            tios.c_cflag |= PARENB | PARODD;
+        if (sgtb->sg_flags & TR_ANYP)
+            tios.c_cflag &= ~PARENB;
+        if (sgtb->sg_flags & TR_CRMOD)
+            tios.c_oflag |= ONLCR;
+        if (sgtb->sg_flags & TR_ECHO)
+            tios.c_lflag |= ECHO;
+        if (sgtb->sg_flags & TR_RAW) {
+            tios.c_lflag &= (~ICANON) & (~ECHO);
+            for (i = 0; i < NCCS; i++)
+                tios.c_cc[i] = 0;
+            tios.c_cc[VMIN] = 1;
+        }
+        if (sgtb->sg_flags & TR_CBREAK) {
+            tios.c_lflag &= (~ICANON);
+            tios.c_lflag |= ECHO;
+            for (i = 0; i < NCCS; i++)
+                tios.c_cc[i] = 0;
+            tios.c_cc[VMIN] = 1;
+        }
+        i = tcsetattr(fd, TCSANOW, &tios);
+        return (i);
     } else
-       return (-1);
+        return (-1);
 }
 
 
 /* Where possible, deal with signals */
 static int v7signal(int sig, int val)
 {
-  if (sig>V7_NSIG) { errno=EINVAL; return(-1); }
-  if (v7sig[sig]==0) return(0);
+    if (sig > V7_NSIG) {
+        errno = EINVAL;
+        return (-1);
+    }
+    if (v7sig[sig] == 0)
+        return (0);
 
-  switch(val) {
+    switch (val) {
     case V7_SIG_IGN:
-      return((int)signal(v7sig[sig], SIG_IGN));
+        return ((int) signal(v7sig[sig], SIG_IGN));
     case V7_SIG_DFL:
-      return((int)signal(v7sig[sig], SIG_DFL));
+        return ((int) signal(v7sig[sig], SIG_DFL));
     default:
-      return(0);      /* No handling of this as yet */
-  }
+        return (0);            /* No handling of this as yet */
+    }
 }
 
 /* Workaround for bug in V5/V6 ctime() */
-static void fixv6time(time_t *t)
+static void fixv6time(time_t * t)
 {
- struct tm *T;
   struct tm *T;
 
- T=gmtime(t);
- if (T->tm_year>98) T->tm_year=98;
- *t=timegm(T);
+    T = gmtime(t);
+    if (T->tm_year > 98)
+        T->tm_year = 98;
+    *t = timegm(T);
 }
index f8314b9..d47f31e 100644 (file)
--- a/v7trap.h
+++ b/v7trap.h
 #define S_CHROOT       61
 
 
-char *v7trap_name[]= {
-       "indir",
-       "exit",
-       "fork",
-       "read",
-       "write",
-       "open",
-       "close",
-       "wait",
-       "creat",
-       "link",
-       "unlink",
-       "exec",
-       "chdir",
-       "time",
-       "mknod",
-       "chmod",
-       "chown",
-       "break",
-       "stat",
-       "lseek",
-       "getpid",
-       "mount",
-       "umount",
-       "setuid",
-       "getuid",
-       "stime",
-       "ptrace",
-       "alarm",
-       "fstat",
-       "pause",
-       "utime",
-       "stty",
-       "gtty",
-       "access",
-       "nice",
-       "ftime",
-       "sync",
-       "kill",
-       "unknown",
-       "unknown",
-       "unknown",
-       "dup",
-       "pipe",
-       "times",
-       "prof",
-       "unknown",
-       "setgid",
-       "getgid",
-       "signal",
-       "unknown",
-       "unknown",
-       "acct",
-       "phys",
-       "lock",
-       "ioctl",
-       "unknown",
-       "unknown",
-       "unknown",
-       "unknown",
-       "exece",
-       "umask",
-       "chroot"
+char *v7trap_name[] = {
+    "indir",
+    "exit",
+    "fork",
+    "read",
+    "write",
+    "open",
+    "close",
+    "wait",
+    "creat",
+    "link",
+    "unlink",
+    "exec",
+    "chdir",
+    "time",
+    "mknod",
+    "chmod",
+    "chown",
+    "break",
+    "stat",
+    "lseek",
+    "getpid",
+    "mount",
+    "umount",
+    "setuid",
+    "getuid",
+    "stime",
+    "ptrace",
+    "alarm",
+    "fstat",
+    "pause",
+    "utime",
+    "stty",
+    "gtty",
+    "access",
+    "nice",
+    "ftime",
+    "sync",
+    "kill",
+    "unknown",
+    "unknown",
+    "unknown",
+    "dup",
+    "pipe",
+    "times",
+    "prof",
+    "unknown",
+    "setgid",
+    "getgid",
+    "signal",
+    "unknown",
+    "unknown",
+    "acct",
+    "phys",
+    "lock",
+    "ioctl",
+    "unknown",
+    "unknown",
+    "unknown",
+    "unknown",
+    "exece",
+    "umask",
+    "chroot"
 };
 
 
@@ -144,32 +144,32 @@ struct tr_v7stat {
 };
 
 struct tr_v6stat {
-       int16_t idev;           /* Device */
-       int16_t inum;
-       int16_t iflags;         /* Mode */
-       int8_t  inl;            /* Links */
-       int8_t  iuid;
-       int8_t  igid;
-       u_int8_t isize0;        /* Most significant 8 bits */
-       u_int16_t isize;
-       int16_t iaddr[8];       /* Not used, I hope! */
-       u_int32_t atime;        /* Alignment problems */
-       u_int32_t mtime;        /* Alignment problems */
+    int16_t idev;              /* Device */
+    int16_t inum;
+    int16_t iflags;            /* Mode */
+    int8_t inl;                        /* Links */
+    int8_t iuid;
+    int8_t igid;
+    u_int8_t isize0;           /* Most significant 8 bits */
+    u_int16_t isize;
+    int16_t iaddr[8];          /* Not used, I hope! */
+    u_int32_t atime;           /* Alignment problems */
+    u_int32_t mtime;           /* Alignment problems */
 };
 
 struct tr_timeb {
-       u_int32_t time;
-       u_int16_t millitm;
-       int16_t  timezone;
-       int16_t  dstflag;
+    u_int32_t time;
+    u_int16_t millitm;
+    int16_t timezone;
+    int16_t dstflag;
 };
 
 struct tr_sgttyb {
-       int8_t    sg_ispeed;              /* input speed */
-       int8_t    sg_ospeed;              /* output speed */
-       int8_t    sg_erase;               /* erase character */
-       int8_t    sg_kill;                /* kill character */
-       int16_t   sg_flags;               /* mode flags */
+    int8_t sg_ispeed;          /* input speed */
+    int8_t sg_ospeed;          /* output speed */
+    int8_t sg_erase;           /* erase character */
+    int8_t sg_kill;            /* kill character */
+    int16_t sg_flags;          /* mode flags */
 };
 
 /*
@@ -194,28 +194,28 @@ struct tr_sgttyb {
 
 #define V7_NSIG 15
 
-#define V7_SIGHUP  1   /* hangup */
-#define V7_SIGINT  2   /* interrupt */
-#define V7_SIGQUIT 3   /* quit */
-#define V7_SIGILL  4   /* illegal instruction (not reset when caught) */
-#define V7_SIGTRAP 5   /* trace trap (not reset when caught) */
-#define V7_SIGIOT  6   /* IOT instruction */
-#define V7_SIGEMT  7   /* EMT instruction */
-#define V7_SIGFPE  8   /* floating point exception */
-#define V7_SIGKILL 9   /* kill (cannot be caught or ignored) */
-#define V7_SIGBUS  10  /* bus error */
-#define V7_SIGSEGV 11  /* segmentation violation */
-#define V7_SIGSYS  12  /* bad argument to system call */
-#define V7_SIGPIPE 13  /* write on a pipe with no one to read it */
-#define V7_SIGALRM 14  /* alarm clock */
-#define V7_SIGTERM 15  /* software termination signal from kill */
+#define V7_SIGHUP  1           /* hangup */
+#define V7_SIGINT  2           /* interrupt */
+#define V7_SIGQUIT 3           /* quit */
+#define V7_SIGILL  4           /* illegal instruction (not reset when caught) */
+#define V7_SIGTRAP 5           /* trace trap (not reset when caught) */
+#define V7_SIGIOT  6           /* IOT instruction */
+#define V7_SIGEMT  7           /* EMT instruction */
+#define V7_SIGFPE  8           /* floating point exception */
+#define V7_SIGKILL 9           /* kill (cannot be caught or ignored) */
+#define V7_SIGBUS  10          /* bus error */
+#define V7_SIGSEGV 11          /* segmentation violation */
+#define V7_SIGSYS  12          /* bad argument to system call */
+#define V7_SIGPIPE 13          /* write on a pipe with no one to read it */
+#define V7_SIGALRM 14          /* alarm clock */
+#define V7_SIGTERM 15          /* software termination signal from kill */
 
 
 /* A union which will point at the trap args, so that
  * we can get at the various args of different types
  */
 typedef union {
-    int16_t   sarg[4];         /* Signed 16-bit args */
+    int16_t sarg[4];           /* Signed 16-bit args */
     u_int16_t uarg[4];         /* Unsigned 16-bit args */
 } arglist;