sh now builds and runs on modern computers.
authorDavid Given <dg@cowlark.com>
Sat, 17 Oct 2015 22:09:04 +0000 (00:09 +0200)
committerDavid Given <dg@cowlark.com>
Sat, 17 Oct 2015 22:09:04 +0000 (00:09 +0200)
Applications/V7/cmd/sh/args.c
Applications/V7/cmd/sh/defs.h
Applications/V7/cmd/sh/expand.c
Applications/V7/cmd/sh/fault.c
Applications/V7/cmd/sh/io.c
Applications/V7/cmd/sh/main.c
Applications/V7/cmd/sh/service.c

index 04592bf..f0f6c6d 100644 (file)
@@ -10,8 +10,7 @@
  *
  */
 
-#include <stdlib.h>
-#include       "defs.h"
+#include "defs.h"
 
 static const char **copyargs(const char *from[], int n);
 static DOLPTR dolh;
index dc78232..4a2fa70 100644 (file)
@@ -1,11 +1,15 @@
 /* UNIX V7 source code: see /COPYRIGHT or www.tuhs.org for details. */
 /* Changes: Copyright (c) 1999 Robert Nordier. All rights reserved. */
 
+#define _GNU_SOURCE
 #include <stdint.h>
 #include <stddef.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <sys/times.h>
+#include <errno.h>
+
 /*
  *     UNIX shell
  */
@@ -176,7 +180,7 @@ extern const char ps2name[];
 
 /* transput */
 extern CHAR tmpout[];
-extern char * tmpnam;
+extern char *tempfile;
 extern int serial;
 #define                TMPNAM 7
 extern FILE standin;
index ba93010..c2128ca 100644 (file)
  *
  */
 
+#include       "defs.h"
 #include       <dirent.h>
 #include       <sys/types.h>
 #define DIRSIZ 31
 #include       <sys/stat.h>
-#include       "defs.h"
-
 
+/* We can't detect Fuzix yet --- this will do for now. */
+#if !defined(__gnu_linux__)
+#define FUZIX_INTERNAL_DIR_API
+#endif
 
 /* globals (file name generation)
  *
@@ -32,20 +35,28 @@ static void addg(const char *as1, char *as2, const char *as3);
 
 int expand(char *as, int rflg)
 {
-       int count, dirf;
+       int count;
        BOOL dir = 0;
        STRING rescan = 0;
-       register char *s, *cs;
+       register char *s, *cs, *fs;
        ARGPTR schain = gchain;
        STATBUF statb;
-       /* Use the internal API to avoid sucking in readdir and thus malloc */
-       struct __dirent entry;
+       #ifdef FUZIX_INTERNAL_DIR_API
+               /* Use the internal API to avoid sucking in readdir and thus malloc */
+               struct __dirent entry;
+               int dirf;
+       #else
+               struct dirent* entry;
+               DIR* dirf;
+       #endif
 
        if (trapnote & SIGSET)
                return (0);
 
        s = cs = as;
+       #ifdef FUZIX_INTERNAL_DIR_API
        entry.d_name[DIRSIZ - 1] = 0;   /* to end the string */
+       #endif
 
        /* check for meta chars */
        {
@@ -76,10 +87,24 @@ int expand(char *as, int rflg)
                        break;
                }
        }
-       if (stat(s, &statb) >= 0
-           && (statb.st_mode & S_IFMT) == S_IFDIR
-           && (dirf = open(s, 0)) > 0) {
-               dir++;
+
+       #ifdef FUZIX_INTERNAL_DIR_API
+               fs = s;
+       #else
+               fs = (s == nullstr) ? "." : s;
+       #endif
+
+       if (stat(fs, &statb) >= 0
+           && (statb.st_mode & S_IFMT) == S_IFDIR)
+       {
+               #ifdef FUZIX_INTERNAL_DIR_API
+                       if ((dirf = open(fs, 0)) > 0)
+               #else
+                       if (dirf = opendir(fs))
+               #endif
+                       {
+                               dir++;
+                       }
        }
        count = 0;
        if (*cs == 0) {
@@ -99,15 +124,27 @@ int expand(char *as, int rflg)
 
                /* We don't want to use opendir as it uses calloc and sucks in malloc so we get
                   down and dirty */
-               while (_getdirent(dirf, (void *) &entry, 32) == 32 && (trapnote & SIGSET) == 0) {
-                       if (entry.d_ino == 0 || (*entry.d_name == '.' && *cs != '.'))
-                               continue;
-                       if (gmatch(entry.d_name, cs)) {
-                               addg(s, entry.d_name, rescan);
-                               count++;
+               #ifdef FUZIX_INTERNAL_DIR_API
+                       while (_getdirent(dirf, (void *) &entry, 32) == 32 && (trapnote & SIGSET) == 0) {
+                               if (entry.d_ino == 0 || (*entry.d_name == '.' && *cs != '.'))
+                                       continue;
+                               if (gmatch(entry.d_name, cs)) {
+                                       addg(s, entry.d_name, rescan);
+                                       count++;
+                               }
                        }
-               }
-               close(dirf);
+                       close(dirf);
+               #else
+                       while ((entry = readdir(dirf)) && (trapnote & SIGSET) == 0) {
+                               if (entry->d_ino == 0 || (*entry->d_name == '.' && *cs != '.'))
+                                       continue;
+                               if (gmatch(entry->d_name, cs)) {
+                                       addg(s, entry->d_name, rescan);
+                                       count++;
+                               }
+                       }
+                       closedir(dirf);
+               #endif
 
                if (rescan) {
                        register ARGPTR rchain;
index cb4c591..d3f4386 100644 (file)
@@ -9,7 +9,6 @@
  *
  */
 
-#include       <stdlib.h>
 #include       "defs.h"
 
 
index 707bf78..7276cfe 100644 (file)
@@ -101,7 +101,7 @@ int create(const char *s)
 int tmpfil(void)
 {
        itos(serial++);
-       movstr(numbuf, tmpnam);
+       movstr(numbuf, tempfile);
        return create(tmpout);
 }
 
index 6735fb9..e2127d1 100644 (file)
  *
  */
 
+#include       "defs.h"
 #include       <stdlib.h>
 #include       <unistd.h>
 #include       <fcntl.h>
-#include       "defs.h"
 #include       "sym.h"
 #include       "timeout.h"
 #include       <sys/types.h>
@@ -25,6 +25,7 @@ static BOOL beenhere = FALSE;
 CHAR tmpout[20] = "/tmp/sh-";
 FILEBLK stdfile;
 FILE standin = &stdfile;
+char* tempfile;
 
 static void exfile(BOOL);
 
@@ -183,7 +184,7 @@ void settmp(void)
 {
        itos(getpid());
        serial = 0;
-       tmpnam = movstr(numbuf, &tmpout[TMPNAM]);
+       tempfile = movstr(numbuf, &tmpout[TMPNAM]);
 }
 
 void Ldup(register int fa, register int fb)
index 8841558..fc51695 100644 (file)
@@ -19,8 +19,6 @@ static int split(const char *s);
 
 #define ARGMK  01
 
-/* FIXME: errno from header */
-extern int errno;
 /* FIXME: put into a header */
 extern const char *sysmsg[];