aboutsummaryrefslogtreecommitdiffstats
path: root/pc
diff options
context:
space:
mode:
Diffstat (limited to 'pc')
-rw-r--r--pc/Makefile.emx53
-rw-r--r--pc/Makefile.msc68
-rw-r--r--pc/Makefile.os2125
-rw-r--r--pc/config.h12
-rw-r--r--pc/gawk-32.def3
-rw-r--r--pc/gawk.def2
-rw-r--r--pc/getid.c69
-rw-r--r--pc/makegawk.bat (renamed from pc/make.bat)116
-rwxr-xr-xpc/mkconf.cmd31
-rwxr-xr-xpc/mungeconf.cmd15
-rw-r--r--pc/names.lnk37
-rw-r--r--pc/names2.lnk19
-rw-r--r--pc/popen.c202
-rw-r--r--pc/popen.h17
14 files changed, 601 insertions, 168 deletions
diff --git a/pc/Makefile.emx b/pc/Makefile.emx
new file mode 100644
index 00000000..622a3a30
--- /dev/null
+++ b/pc/Makefile.emx
@@ -0,0 +1,53 @@
+# Makefile for gawk (GNU awk) using EMX/gcc
+#
+# This makefile is designed to work within the limits of the DOS
+# command-line length. OS/2 users can use Makefile.os2, which
+# has additional targets.
+#
+
+
+CC=gcc -O -s
+O=.o
+CFLAGS=-DOS2 -DMSDOS
+
+LFLAGS=
+LFLAGS2=gawk-32.def
+
+#BIND=emxbind -u /emx/bin/emx.exe $@
+BIND=
+
+OBJ2=getid$O popen$O
+
+AWKOBJS = main$O eval$O builtin$O msg$O iop$O io$O field$O array$O \
+ node$O version$O missing$O re$O
+ALLOBJS = $(AWKOBJS) awktab$O
+GNUOBJS= getopt$O getopt1$O regex$O dfa$O
+
+.SUFFIXES: $O .c .y
+
+.c$O:
+ $(CC) $(CFLAGS) -DGAWK -c $<
+
+all: gawk.exe
+
+gawk.exe: $(ALLOBJS) $(GNUOBJS) $(OBJ2)
+ $(CC) -o $@ $(LFLAGS) @names2.lnk $(LFLAGS2)
+ $(BIND)
+
+$(AWKOBJS): awk.h config.h
+dfa$O: awk.h config.h dfa.h
+regex$O: awk.h config.h regex.h
+main$O: patchlev.h
+awktab$O: awk.h awktab.c
+
+awktab.c: awk.y
+ bison -o $@ awk.y
+
+clean:
+ rm -f *.o core awk.output gmon.out make.out y.output
+
+.PHONY: test
+test:
+ @echo Both dmake and GNU make require modifications to test/Makefile,
+ @echo but here we go...
+ cd test && $(MAKE) -k
diff --git a/pc/Makefile.msc b/pc/Makefile.msc
new file mode 100644
index 00000000..2821128d
--- /dev/null
+++ b/pc/Makefile.msc
@@ -0,0 +1,68 @@
+# Makefile for gawk (GNU awk) using Microsoft C
+#
+# This makefile is designed to work within the limits of the DOS
+# command-line length. OS/2 users can use Makefile.os2, which
+# has additional targets.
+#
+
+DEFS = -D_MSC_VER
+
+# For MSC 5.1
+#DEFS = -D_MSC_VER=510
+
+# MSC 6.00A has _MSC_VER predefined
+#DEFS =
+
+
+#DEBUG = -W3 -Zi -Od
+DEBUG=
+
+MODEL = L
+CC=cl -nologo -A$(MODEL)
+O=.obj
+
+# Disable MSC extensions with -Za so that __STDC__ is defined for MSC 6.00A
+# MSC 5.1 defines __STDC__=0 regardless of the ANSI flag
+CFLAGS = -Za $(DEFS) $(DEBUG)
+
+#LIBS = /NOD:$(MODEL)libce $(MODEL)libcer.lib
+LIBS =
+
+OBJ2=getid$O popen$O
+
+AWKOBJS = main$O eval$O builtin$O msg$O iop$O io$O field$O array$O \
+ node$O version$O missing$O re$O
+ALLOBJS = $(AWKOBJS) awktab$O
+GNUOBJS= getopt$O getopt1$O regex$O dfa$O
+
+.SUFFIXES: $O .c .y
+
+.c$O:
+ $(CC) $(CFLAGS) -DGAWK -c $<
+
+all: gawk.exe
+
+gawk.exe: $(ALLOBJS) $(GNUOBJS) $(OBJ2)
+ link @names.lnk, $@,,$(LIBS) /NOE /st:30000;
+
+
+$(AWKOBJS): awk.h config.h
+dfa$O: awk.h config.h dfa.h
+regex$O: awk.h config.h regex.h
+main$O: patchlev.h
+
+# A bug in ndmake requires the following rule
+awktab$O: awk.h awktab.c
+ $(CC) $(CFLAGS) -DGAWK -c awktab.c
+
+awktab.c: awk.y
+ bison -o $@ awk.y
+
+clean:
+ rm -f *.o *.obj core awk.output gmon.out make.out y.output
+
+.PHONY: test
+test:
+ @echo Both dmake and GNU make require modifications to test/Makefile,
+ @echo but here we go...
+ cd test && $(MAKE) -k
diff --git a/pc/Makefile.os2 b/pc/Makefile.os2
new file mode 100644
index 00000000..072264ec
--- /dev/null
+++ b/pc/Makefile.os2
@@ -0,0 +1,125 @@
+# Makefile for gawk (GNU awk) 17 Sep 1993
+#
+# - for GNU gcc (emx 0.8g kit) [executables for OS/2 2.x or DOS (32-bit)]
+# - for Microsoft C 6.00A [executables for OS/2 or MSDOS (16-bit)]
+# - for Microsoft C 5.1 [executable for OS/2 or DOS (16-bit)]
+
+# To use, enter "make -f Makefile.os2" (this makefile depends on its
+# name being "Makefile.os2").
+#
+# Tested with dmake 3.8 and GNU make 3.68 under OS/2
+
+default:
+ @echo "Enter $(MAKE) -f Makefile.os2 target "
+ @echo " where 'target' is chosen from "
+ @echo " msc OS/2 exe [Microsoft C 6.00a] "
+ @echo " mscbnd OS/2 and DOS exe [Microsoft C 6.00a] "
+ @echo " mscdos DOS exe [Microsoft C 6.00a] "
+ @echo " msc51bnd OS/2 and DOS exe [Microsoft C 5.1] "
+ @echo " emx OS/2 32-bit exe [EMX/gcc; uses emxlibc.dll] "
+ @echo " emxbnd OS/2 and DOS 32-bit exe [EMX/gcc] "
+
+
+# stdargv, glob, and director are from Stewartson's sh. These provide
+# globbing and enhanced argument-passing. MSC setargv.obj is a
+# more limited alternative (and it will permit a bound version).
+
+#STDARGV = stdargv.obj glob.obj director.obj
+STDARGV = setargv.obj
+
+msc:
+ $(MAKE) -f Makefile.os2 all \
+ CC="cl -nologo -AL" O=".obj" \
+ CFLAGS="-D__STDC__ -DOS2 -UMSDOS" \
+ OBJ2="" \
+ LFLAGS="-Lp" \
+ LFLAGS2="$(STDARGV) gawk.def -link /NOE /st:30000"
+
+mscbnd:
+ $(MAKE) -f Makefile.os2 all \
+ CC="cl -nologo -AL" O=".obj" \
+ CFLAGS="-D__STDC__ -DOS2" \
+ OBJ2="popen.obj" \
+ LFLAGS="-Lp" \
+ LFLAGS2="setargv.obj gawk.def -link /NOE /st:30000" \
+ BIND="bind gawk /n DOSMAKEPIPE DOSCWAIT"
+
+msc-debug:
+ $(MAKE) -f Makefile.os2 all \
+ CC="cl -nologo -AL" O=".obj" \
+ CFLAGS="-DOS2 -D__STDC__ -DDEBUG -DFUNC_TRACE -DMEMDEBUG -Zi -Od" \
+ OBJ2="popen.obj" \
+ LFLAGS="-Lp" \
+ LFLAGS2="$(STDARGV) gawk.def -link /CO /NOE /st:30000"
+
+mscdos:
+ $(MAKE) -f Makefile.os2 all \
+ CC="cl -nologo -AL" O=".obj" \
+ CFLAGS="-D__STDC__" \
+ OBJ2="popen.obj" \
+ LFLAGS="-Lr" \
+ LFLAGS2="$(STDARGV) -link /NOE /st:30000"
+
+msc51bnd:
+ $(MAKE) -f Makefile.os2 all \
+ CC="cl -AL" O=".obj" \
+ CFLAGS="-DOS2 -D_MSC_VER=510" \
+ OBJ2="popen.obj" \
+ LFLAGS="-Lp -Fb" \
+ LFLAGS2="setargv.obj gawk.def -link /NOE /NOI /st:30000"
+
+emx:
+ $(MAKE) -f Makefile.os2 all \
+ CC="gcc -Zomf -Zmtd -O -s" O=".obj" \
+ CFLAGS="-DOS2" \
+ LFLAGS="" \
+ LFLAGS2="gawk-32.def"
+
+emx-debug:
+ $(MAKE) -f Makefile.os2 all \
+ CC="gcc -g" O=".o" \
+ CFLAGS="-DOS2" \
+ LFLAGS="" \
+ LFLAGS2="gawk-32.def"
+
+emxbnd:
+ $(MAKE) -f Makefile.os2 all \
+ CC="gcc -O -s" O=".o" \
+ CFLAGS="-DOS2 -DMSDOS" \
+ OBJ2="popen.o" \
+ LFLAGS="" \
+ LFLAGS2="gawk-32.def"
+
+AWKOBJS = main$O eval$O builtin$O msg$O iop$O io$O field$O array$O \
+ node$O version$O missing$O re$O
+ALLOBJS = $(AWKOBJS) awktab$O getid$O
+GNUOBJS= getopt$O getopt1$O regex$O dfa$O
+
+.SUFFIXES: $O .c .y
+
+.c$O:
+ $(CC) $(CFLAGS) -DGAWK -c $<
+
+all: gawk.exe
+
+gawk.exe: $(ALLOBJS) $(GNUOBJS) $(OBJ2)
+ $(CC) -o $@ $(LFLAGS) $(ALLOBJS) $(GNUOBJS) $(OBJ2) $(LFLAGS2)
+ $(BIND)
+
+$(AWKOBJS): awk.h config.h
+dfa$O: awk.h config.h dfa.h
+regex$O: awk.h config.h regex.h
+main$O: patchlevel.h
+awktab$O: awk.h awktab.c
+
+awktab.c: awk.y
+ bison -o $@ awk.y
+
+clean:
+ rm -f *.o *.obj core awk.output gmon.out make.out y.output
+
+.PHONY: test
+test:
+ @echo Both dmake and GNU make require modifications to test/Makefile,
+ @echo but here we go...
+ cd test && $(MAKE) -k
diff --git a/pc/config.h b/pc/config.h
index 9311ee61..85b3c638 100644
--- a/pc/config.h
+++ b/pc/config.h
@@ -1,7 +1,7 @@
/*
* config.h -- configuration definitions for gawk.
*
- * MS-DOS systems using MSC 5.1
+ * OS/2 or MS-DOS systems using emx/gcc or MSC
*/
/*
@@ -124,7 +124,9 @@
* Your system does not have the strcasemp() and strncasecmp()
* routines that originated in Berkeley Unix.
*/
-#define STRCASE_MISSING 1
+/* #define STRCASE_MISSING 1 */
+#define strcasecmp stricmp
+#define strncasecmp strnicmp
/*
* STRCHR_MISSING
@@ -258,6 +260,7 @@
/* #define DEFPATH ".:/usr/lib/awk:/usr/local/lib/awk" */
/* #define ENVSEP ':' */
+#define ENVSEP ';'
/*
* alloca already has a prototype defined - don't redefine it
@@ -269,4 +272,9 @@
*/
/* #define SRANDOM_PROTO 1 */
+/*
+ * getpgrp() in sysvr4 and POSIX takes no argument
+ */
+/* #define GETPGRP_NOARG 0 */
+
/* anything that follows is for system-specific short-term kludges */
diff --git a/pc/gawk-32.def b/pc/gawk-32.def
new file mode 100644
index 00000000..968a0cb1
--- /dev/null
+++ b/pc/gawk-32.def
@@ -0,0 +1,3 @@
+NAME gawk WINDOWCOMPAT NEWFILES
+DESCRIPTION 'GNU awk for OS/2'
+STACKSIZE 0x100000
diff --git a/pc/gawk.def b/pc/gawk.def
new file mode 100644
index 00000000..ac1a5a2c
--- /dev/null
+++ b/pc/gawk.def
@@ -0,0 +1,2 @@
+NAME gawk WINDOWCOMPAT NEWFILES
+DESCRIPTION 'GNU awk for OS/2'
diff --git a/pc/getid.c b/pc/getid.c
new file mode 100644
index 00000000..d645b39f
--- /dev/null
+++ b/pc/getid.c
@@ -0,0 +1,69 @@
+#ifdef _MSC_VER
+
+#ifdef OS2
+# define INCL_DOSPROCESS
+# include <os2.h>
+# if _MSC_VER == 510
+# define DosGetPID DosGetPid
+# endif
+#else
+# include <process.h>
+#endif
+
+#ifdef OS2
+int getpid(void)
+{
+ PIDINFO PidInfo;
+
+ DosGetPID(&PidInfo);
+ return(PidInfo.pid);
+}
+#endif
+
+int getppid(void)
+{
+#ifdef OS2
+ PIDINFO PidInfo;
+
+ DosGetPID(&PidInfo);
+ return(PidInfo.pidParent);
+#else
+ return(0);
+#endif
+}
+
+unsigned int getuid (void)
+{
+ return (0); /* root! */
+}
+
+
+unsigned int geteuid (void)
+{
+ return (0);
+}
+
+
+unsigned int getgid (void)
+{
+ return (0);
+}
+
+
+unsigned int getegid (void)
+{
+ return (0);
+}
+
+
+char *getlogin (void)
+{
+ return ("root");
+}
+
+#endif
+
+int getpgrp(void)
+{
+ return (0);
+}
diff --git a/pc/make.bat b/pc/makegawk.bat
index a416cadc..eaf9fac2 100644
--- a/pc/make.bat
+++ b/pc/makegawk.bat
@@ -1,51 +1,65 @@
-REM Simple brute force command file for building gawk under msdos
-REM
-REM *** This has only been using MSC 5.1 ***
-REM
-REM Written by Arnold Robbins, May 1991
-REM Modified by Scott Deifik, July, 1992
-REM Based on earlier makefile for dos
-REM
-REM Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc.
-REM
-REM This file is part of GAWK, the GNU implementation of the
-REM AWK Progamming Language.
-REM
-REM GAWK is free software; you can redistribute it and/or modify
-REM it under the terms of the GNU General Public License as published by
-REM the Free Software Foundation; either version 2 of the License, or
-REM (at your option) any later version.
-REM
-REM GAWK is distributed in the hope that it will be useful,
-REM but WITHOUT ANY WARRANTY; without even the implied warranty of
-REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-REM GNU General Public License for more details.
-REM
-REM You should have received a copy of the GNU General Public License
-REM along with GAWK; see the file COPYING. If not, write to
-REM the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-REM
-REM compile debug flags: -DDEBUG -DFUNC_TRACE -DMEMDEBUG -Zi -Od
-REM
-REM
-cl -c -AL array.c
-cl -c -AL awktab.c
-cl -c -AL builtin.c
-cl -c -AL dfa.c
-cl -c -AL eval.c
-cl -c -AL field.c
-cl -c -AL io.c
-cl -c -AL iop.c
-cl -c -AL main.c
-cl -c -AL missing.c
-cl -c -AL msg.c
-cl -c -AL node.c
-cl -c -AL popen.c
-cl -c -AL re.c
-REM You can ignore the warnings you will get
-cl -c -AL regex.c
-cl -c -AL version.c
-REM
-REM link debug flags: /CO /NOE /NOI /st:30000
-REM
-link @names.lnk,gawk.exe /NOE /NOI /st:30000;
+REM Simple brute force command file for building gawk under msdos
+REM
+REM *** This has only been tested using MSC 5.1 and MSC 6.00A ***
+REM
+REM Written by Arnold Robbins, May 1991
+REM Modified by Scott Deifik, July, 1992, Sep 1993
+REM Based on earlier makefile for dos
+REM
+REM Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc.
+REM
+REM This file is part of GAWK, the GNU implementation of the
+REM AWK Progamming Language.
+REM
+REM GAWK is free software; you can redistribute it and/or modify
+REM it under the terms of the GNU General Public License as published by
+REM the Free Software Foundation; either version 2 of the License, or
+REM (at your option) any later version.
+REM
+REM GAWK is distributed in the hope that it will be useful,
+REM but WITHOUT ANY WARRANTY; without even the implied warranty of
+REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+REM GNU General Public License for more details.
+REM
+REM You should have received a copy of the GNU General Public License
+REM along with GAWK; see the file COPYING. If not, write to
+REM the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+REM
+REM compile debug flags: -DDEBUG -DFUNC_TRACE -DMEMDEBUG -Zi -Od
+REM
+
+set CFLAGS=-D_MSC_VER
+
+rem MSC 5.1 should use:
+rem set CFLAGS=-D_MSC_VER=510
+
+rem MSC 6.00A predefines _MSC_VER
+rem set CFLAGS=
+
+rem -Za sets ANSI flag so that __STDC__ is defined in MSC 6.00A
+rem (MSC 5.1 sets __STDC__=0 regardless of ANSI switch)
+
+cl -Za -c -AL %CFLAGS% -DGAWK array.c
+cl -Za -c -AL %CFLAGS% -DGAWK awktab.c
+cl -Za -c -AL %CFLAGS% -DGAWK builtin.c
+cl -Za -c -AL %CFLAGS% -DGAWK dfa.c
+cl -Za -c -AL %CFLAGS% -DGAWK eval.c
+cl -Za -c -AL %CFLAGS% -DGAWK field.c
+cl -Za -c -AL %CFLAGS% -DGAWK getid.c
+cl -Za -c -AL %CFLAGS% -DGAWK getopt.c
+cl -Za -c -AL %CFLAGS% -DGAWK getopt1.c
+cl -Za -c -AL %CFLAGS% -DGAWK io.c
+cl -Za -c -AL %CFLAGS% -DGAWK iop.c
+cl -Za -c -AL %CFLAGS% -DGAWK main.c
+cl -Za -c -AL %CFLAGS% -DGAWK missing.c
+cl -Za -c -AL %CFLAGS% -DGAWK msg.c
+cl -Za -c -AL %CFLAGS% -DGAWK node.c
+cl -Za -c -AL %CFLAGS% -DGAWK popen.c
+cl -Za -c -AL %CFLAGS% -DGAWK re.c
+REM You can ignore the warnings you will get
+cl -Za -c -AL %CFLAGS% -DGAWK regex.c
+cl -Za -c -AL %CFLAGS% -DGAWK version.c
+REM
+REM link debug flags: /CO /NOE /NOI /st:30000
+REM
+link @names.lnk,gawk.exe /NOE /NOI /st:30000;
diff --git a/pc/mkconf.cmd b/pc/mkconf.cmd
new file mode 100755
index 00000000..3d3eb3d3
--- /dev/null
+++ b/pc/mkconf.cmd
@@ -0,0 +1,31 @@
+extproc sh
+
+#! /bin/sh
+#
+# mkconf -- produce a config.h from a known configuration
+
+case "$#" in
+1) ;;
+*) echo "Usage: mkconf system_type" >&2
+ echo "Known systems: `cd config; echo ;ls -C`" >&2
+ exit 2
+ ;;
+esac
+
+if [ -f config/$1 ]; then
+ sh ./mungeconf.cmd config/$1 config.h-dist >config.h
+ sed -n '/^#echo /s///p' config/$1
+ sed -n '/^MAKE_.*/s//s,^##&## ,,/p' config/$1 >sedscr
+ if [ -s sedscr ]
+ then
+ sed -f sedscr Makefile-dist >Makefile
+ else
+ cp Makefile-dist Makefile
+ fi
+ cmd /c del sedscr
+else
+ echo "\`$1' is not a known configuration."
+ echo "Either construct one based on the examples in the config directory,"
+ echo "or copy config.h-dist to config.h and edit it."
+ exit 1
+fi
diff --git a/pc/mungeconf.cmd b/pc/mungeconf.cmd
new file mode 100755
index 00000000..cbf1d12e
--- /dev/null
+++ b/pc/mungeconf.cmd
@@ -0,0 +1,15 @@
+extproc sh
+
+#! /bin/sh
+
+case $# in
+2) ;;
+*) echo "Usage: mungeconf sysfile distfile" >&2 ; exit 2 ;;
+esac
+
+sed '/^#/d; /^MAKE_*/d' $1 |
+sed '1s:.*:s~__SYSTEM__~&~:
+2,$s:^\([^ ]*\)[ ].*:s~^/\\* #define[ ]*\1.*~#define &~:' >sedscr
+sed -f sedscr $2
+
+cmd /c del sedscr
diff --git a/pc/names.lnk b/pc/names.lnk
index 5a42d0ef..5f02ae54 100644
--- a/pc/names.lnk
+++ b/pc/names.lnk
@@ -1,17 +1,20 @@
-array.obj+
-awktab.obj+
-builtin.obj+
-dfa.obj+
-eval.obj+
-field.obj+
-io.obj+
-iop.obj+
-main.obj+
-missing.obj+
-msg.obj+
-node.obj+
-popen.obj+
-re.obj+
-version.obj+
-regex.obj+
-setargv.obj
+array.obj+
+awktab.obj+
+builtin.obj+
+dfa.obj+
+eval.obj+
+field.obj+
+getid.obj+
+getopt.obj+
+getopt1.obj+
+io.obj+
+iop.obj+
+main.obj+
+missing.obj+
+msg.obj+
+node.obj+
+popen.obj+
+re.obj+
+version.obj+
+regex.obj+
+setargv.obj
diff --git a/pc/names2.lnk b/pc/names2.lnk
new file mode 100644
index 00000000..fb9cff4f
--- /dev/null
+++ b/pc/names2.lnk
@@ -0,0 +1,19 @@
+main.o
+eval.o
+builtin.o
+msg.o
+iop.o
+io.o
+field.o
+array.o
+node.o
+version.o
+missing.o
+re.o
+awktab.o
+getopt.o
+getopt1.o
+regex.o
+dfa.o
+getid.o
+popen.o
diff --git a/pc/popen.c b/pc/popen.c
index 48952c22..cdb54a0a 100644
--- a/pc/popen.c
+++ b/pc/popen.c
@@ -1,90 +1,112 @@
-#include <stdio.h>
-#include "popen.h"
-#include <io.h>
-#include <string.h>
-#include <process.h>
-
-static char template[] = "piXXXXXX";
-typedef enum { unopened = 0, reading, writing } pipemode;
-static
-struct {
- char *command;
- char *name;
- pipemode pmode;
-} pipes[_NFILE];
-
-FILE *
-popen( char *command, char *mode ) {
- FILE *current;
- char *name;
- int cur;
- pipemode curmode;
- /*
- ** decide on mode.
- */
- if(strcmp(mode,"r") == 0)
- curmode = reading;
- else if(strcmp(mode,"w") == 0)
- curmode = writing;
- else
- return NULL;
- /*
- ** get a name to use.
- */
- if((name = tempnam(".","pip"))==NULL)
- return NULL;
- /*
- ** If we're reading, just call system to get a file filled with
- ** output.
- */
- if(curmode == reading) {
- char cmd[256];
- sprintf(cmd,"%s > %s",command,name);
- system(cmd);
- if((current = fopen(name,"r")) == NULL)
- return NULL;
- } else {
- if((current = fopen(name,"w")) == NULL)
- return NULL;
- }
- cur = fileno(current);
- pipes[cur].name = name;
- pipes[cur].pmode = curmode;
- pipes[cur].command = strdup(command);
- return current;
-}
-
-int
-pclose( FILE * current) {
- int cur = fileno(current),rval;
- /*
- ** check for an open file.
- */
- if(pipes[cur].pmode == unopened)
- return -1;
- if(pipes[cur].pmode == reading) {
- /*
- ** input pipes are just files we're done with.
- */
- rval = fclose(current);
- unlink(pipes[cur].name);
- } else {
- /*
- ** output pipes are temporary files we have
- ** to cram down the throats of programs.
- */
- char command[256];
- fclose(current);
- sprintf(command,"%s < %s",pipes[cur].command,pipes[cur].name);
- rval = system(command);
- unlink(pipes[cur].name);
- }
- /*
- ** clean up current pipe.
- */
- pipes[cur].pmode = unopened;
- free(pipes[cur].name);
- free(pipes[cur].command);
- return rval;
-}
-
+#include "popen.h"
+#include <stdlib.h>
+#include <io.h>
+#include <string.h>
+#include <process.h>
+
+#ifdef OS2
+#ifdef _MSC_VER
+#define popen(c,m) _popen(c,m)
+#define pclose(f) _pclose(f)
+#endif
+#endif
+
+#ifndef _NFILE
+#define _NFILE 40
+#endif
+
+static char template[] = "piXXXXXX";
+typedef enum { unopened = 0, reading, writing } pipemode;
+static
+struct {
+ char *command;
+ char *name;
+ pipemode pmode;
+} pipes[_NFILE];
+
+FILE *
+os_popen( char *command, char *mode ) {
+ FILE *current;
+ char *name;
+ int cur;
+ pipemode curmode;
+
+#if defined(OS2) && (_MSC_VER != 510)
+ if (_osmode == OS2_MODE)
+ return(popen(command, mode));
+#endif
+
+ /*
+ ** decide on mode.
+ */
+ if(strcmp(mode,"r") == 0)
+ curmode = reading;
+ else if(strcmp(mode,"w") == 0)
+ curmode = writing;
+ else
+ return NULL;
+ /*
+ ** get a name to use.
+ */
+ if((name = tempnam(".","pip"))==NULL)
+ return NULL;
+ /*
+ ** If we're reading, just call system to get a file filled with
+ ** output.
+ */
+ if(curmode == reading) {
+ char cmd[256];
+ sprintf(cmd,"%s > %s",command,name);
+ system(cmd);
+ if((current = fopen(name,"r")) == NULL)
+ return NULL;
+ } else {
+ if((current = fopen(name,"w")) == NULL)
+ return NULL;
+ }
+ cur = fileno(current);
+ pipes[cur].name = name;
+ pipes[cur].pmode = curmode;
+ pipes[cur].command = strdup(command);
+ return current;
+}
+
+int
+os_pclose( FILE * current) {
+ int cur = fileno(current),rval;
+
+#if defined(OS2) && (_MSC_VER != 510)
+ if (_osmode == OS2_MODE)
+ return(pclose(current));
+#endif
+
+ /*
+ ** check for an open file.
+ */
+ if(pipes[cur].pmode == unopened)
+ return -1;
+ if(pipes[cur].pmode == reading) {
+ /*
+ ** input pipes are just files we're done with.
+ */
+ rval = fclose(current);
+ unlink(pipes[cur].name);
+ } else {
+ /*
+ ** output pipes are temporary files we have
+ ** to cram down the throats of programs.
+ */
+ char command[256];
+ fclose(current);
+ sprintf(command,"%s < %s",pipes[cur].command,pipes[cur].name);
+ rval = system(command);
+ unlink(pipes[cur].name);
+ }
+ /*
+ ** clean up current pipe.
+ */
+ pipes[cur].pmode = unopened;
+ free(pipes[cur].name);
+ free(pipes[cur].command);
+ return rval;
+}
diff --git a/pc/popen.h b/pc/popen.h
index 55501324..e8cd1b9b 100644
--- a/pc/popen.h
+++ b/pc/popen.h
@@ -1,8 +1,9 @@
-/*
-** popen.h -- prototypes for pipe functions
-*/
-#if !defined(FILE)
-#include <stdio.h>
-#endif
-extern FILE *popen( char *, char * );
-
+/*
+** popen.h -- prototypes for pipe functions
+*/
+#if !defined(FILE)
+#include <stdio.h>
+#endif
+
+extern FILE *os_popen( char *, char * );
+extern int os_pclose( FILE * );