From 333b605b2afd472b823aeda0adf0e8b1ea9843c0 Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Mon, 27 May 2019 02:41:51 +0100 Subject: initial commit from asl-1.41r8.tar.gz --- stdhandl.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 stdhandl.c (limited to 'stdhandl.c') diff --git a/stdhandl.c b/stdhandl.c new file mode 100644 index 0000000..d47c7dd --- /dev/null +++ b/stdhandl.c @@ -0,0 +1,110 @@ +/* stdhandl.c */ +/*****************************************************************************/ +/* AS-Portierung */ +/* */ +/* Bereitstellung von fuer AS benoetigten Handle-Funktionen */ +/* */ +/* Historie: 5. 4.1996 Grundsteinlegung */ +/* */ +/*****************************************************************************/ + +#include "stdinc.h" +#include +#include +#include "stdhandl.h" + +#if defined ( __EMX__ ) || defined ( __IBMC__ ) +#include +#endif + +#ifdef __TURBOC__ +#include +#endif + +#ifndef S_ISCHR +#ifdef __IBMC__ +#define S_ISCHR(m) ((m) & S_IFCHR) +#else +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#endif +#endif +#ifndef S_ISREG +#ifdef __IBMC__ +#define S_ISREG(m) ((m) & S_IFREG) +#else +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif +#endif + +TRedirected Redirected; + +/* eine Textvariable auf einen der Standardkanaele umbiegen. Die Reduzierung + der Puffergroesse auf fast Null verhindert, dass durch Pufferung evtl. Ausgaben + durcheinandergehen. */ + + static void AssignHandle(FILE **T, Word Num) +BEGIN +#ifdef NODUP + switch (Num) + BEGIN + case 0: *T=stdin; break; + case 1: *T=stdout; break; + case 2: *T=stderr; break; + default: *T=Nil; + END +#else + *T=fdopen(dup(Num),"w"); +#ifndef _WIN32t + setbuf(*T,Nil); +#endif +#endif +END + +/* Eine Datei unter Beruecksichtigung der Standardkanaele oeffnen */ + + void RewriteStandard(FILE **T, String Path) +BEGIN + if ((strlen(Path)==2) AND (Path[0]=='!') AND (Path[1]>='0') AND (Path[1]<='2')) + AssignHandle(T,Path[1]-'0'); + else *T=fopen(Path,"w"); +END + + void stdhandl_init(void) +BEGIN +#ifdef __EMX__ + ULONG HandType,DevAttr; + +#else +#ifdef __TURBOC__ + int HandErg; + +#else + struct stat stdout_stat; + +#endif +#endif + + /* wohin zeigt die Standardausgabe ? */ + +#ifdef __EMX__ + DosQueryHType(1,&HandType,&DevAttr); + if ((HandType & 0xff)==FHT_DISKFILE) Redirected=RedirToFile; + else if ((DevAttr & 2)==0) Redirected=RedirToDevice; + else Redirected=NoRedir; + +#else +#ifdef __TURBOC__ + HandErg=ioctl(1,0x00); + if ((HandErg & 2)==2) Redirected=NoRedir; + else if ((HandErg & 0x8000)==0) Redirected=RedirToFile; + else Redirected=RedirToDevice; + +#else + fstat(fileno(stdout),&stdout_stat); + if (S_ISREG(stdout_stat.st_mode)) Redirected=RedirToFile; + else if (S_ISCHR(stdout_stat.st_mode)) Redirected=RedirToDevice; + else Redirected=NoRedir; + +#endif +#endif +END -- cgit v1.2.3