From: David Given Date: Sat, 17 Oct 2015 22:09:04 +0000 (+0200) Subject: sh now builds and runs on modern computers. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=48b2072968830c9a4fe00233d4c2a0eb10419890;p=FUZIX.git sh now builds and runs on modern computers. --- diff --git a/Applications/V7/cmd/sh/args.c b/Applications/V7/cmd/sh/args.c index 04592bf0..f0f6c6de 100644 --- a/Applications/V7/cmd/sh/args.c +++ b/Applications/V7/cmd/sh/args.c @@ -10,8 +10,7 @@ * */ -#include -#include "defs.h" +#include "defs.h" static const char **copyargs(const char *from[], int n); static DOLPTR dolh; diff --git a/Applications/V7/cmd/sh/defs.h b/Applications/V7/cmd/sh/defs.h index dc782323..4a2fa70f 100644 --- a/Applications/V7/cmd/sh/defs.h +++ b/Applications/V7/cmd/sh/defs.h @@ -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 #include #include #include +#include #include +#include + /* * 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; diff --git a/Applications/V7/cmd/sh/expand.c b/Applications/V7/cmd/sh/expand.c index ba93010d..c2128ca5 100644 --- a/Applications/V7/cmd/sh/expand.c +++ b/Applications/V7/cmd/sh/expand.c @@ -10,13 +10,16 @@ * */ +#include "defs.h" #include #include #define DIRSIZ 31 #include -#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; diff --git a/Applications/V7/cmd/sh/fault.c b/Applications/V7/cmd/sh/fault.c index cb4c591c..d3f43868 100644 --- a/Applications/V7/cmd/sh/fault.c +++ b/Applications/V7/cmd/sh/fault.c @@ -9,7 +9,6 @@ * */ -#include #include "defs.h" diff --git a/Applications/V7/cmd/sh/io.c b/Applications/V7/cmd/sh/io.c index 707bf788..7276cfe4 100644 --- a/Applications/V7/cmd/sh/io.c +++ b/Applications/V7/cmd/sh/io.c @@ -101,7 +101,7 @@ int create(const char *s) int tmpfil(void) { itos(serial++); - movstr(numbuf, tmpnam); + movstr(numbuf, tempfile); return create(tmpout); } diff --git a/Applications/V7/cmd/sh/main.c b/Applications/V7/cmd/sh/main.c index 6735fb90..e2127d11 100644 --- a/Applications/V7/cmd/sh/main.c +++ b/Applications/V7/cmd/sh/main.c @@ -10,10 +10,10 @@ * */ +#include "defs.h" #include #include #include -#include "defs.h" #include "sym.h" #include "timeout.h" #include @@ -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) diff --git a/Applications/V7/cmd/sh/service.c b/Applications/V7/cmd/sh/service.c index 88415582..fc51695c 100644 --- a/Applications/V7/cmd/sh/service.c +++ b/Applications/V7/cmd/sh/service.c @@ -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[];