🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #2866

Re: Porting UNIX apps. to MS-DOS

#2866
From: Rhys Weatherley
Date: Wed, 31 Oct 1990 07:33
45 lines
2536 bytes
dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes:

>In article <1990Oct26.223541.26634@NCoast.ORG> catfood@NCoast.ORG (Mark W. Schumann) writes:
>>DLV101@psuvm.psu.edu (Dwaine VanBibber) writes:
>>>Does anyone have some general rules for porting C programs developed under
>>>UNIX to MS-DOS?  [ ... etc ... ]

>Although this is generally true in "nice" programs, there may be a somewhat
>kludgy workaround for this.
>	[ ... code to swap stacks, and do other ugly things ... ]

EEK!!  This solution should be applied with "fingers crossed"!  I won't
go into the code.  Answering the original question, looking at lots of
Unix programs, you find that many of them allocate big buffers and things
on the stack.  For example:

	char	buffer[BUFSIZ];

This is "plenty fine" on Unix boxes where most everything is 32 bit, with
HUGE stacks.  However on MS-DOS machines, you of course (as pointed out
earlier) only have 64K of stack, at best.  However, just change the
above line to:

	static	char	buffer[BUFSIZ];

And "hey presto", you've decreased the stack usage in a big way, by
putting the buffer into the global data space.  Also, with recursive 
functions (as usually present in parsers), the buffers soon mount up.  
Using this (which authors should do anyway for portability) is 
much "cleaner" than swapping stacks and stuff.  There is one caveat: 
you must be aware that you DON'T have a new copy of the buffer each time 
in a recursive routine (it's always the same one).  Careful inspection 
of the code can help you out greatly.

This is not a "total" solution, but preferred to stack swaps wherever
possible.

Rhys.

P.S. Derek, you changed _SS, but forgot about _SP.  Weird things could happen!

+===============================+==============================+
||  Rhys Weatherley             |  University of Queensland,  ||
||  rhys@batserver.cs.uq.oz.au  |  Australia.  G'day!!        ||
+===============================+==============================+
Technical Details
Message-ID: <5497@uqcspe.cs.uq.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!munnari.oz.au!brolga!uqcspe!batserver.cs.uq.oz.au!rhys
References: <90296.205211DLV101@psuvm.psu.edu> <1990Oct26.223541.26634@NCoast.ORG> <9449@jarthur.Claremont.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!munnari.oz.au!brolga!uqcspe!batserver.cs.uq.oz.au!rhys
From: rhys@batserver.cs.uq.oz.au (Rhys Weatherley)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Porting UNIX apps. to MS-DOS
Message-ID: <5497@uqcspe.cs.uq.oz.au>
Date: 31 Oct 90 07:33:55 GMT
References: <90296.205211DLV101@psuvm.psu.edu> <1990Oct26.223541.26634@NCoast.ORG> <9449@jarthur.Claremont.EDU>
Sender: news@uqcspe.cs.uq.oz.au
Reply-To: rhys@batserver.cs.uq.oz.au
Lines: 45