\input texinfo 						@c -*-texinfo-*-
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename swaplib.info
@settitle swaplib
@setchapternewpage odd
@comment %**end of header (This is for running Texinfo on a region.)

@synindex tp fn
@synindex vr fn

@ifinfo
This file documents the swapping library.

Copyright @copyright{} 1990 Thorsten Ohl, <td12@@ddagsi3.bitnet>
$Header: e:/gnu/swaplib/RCS/swaplib.t'v 0.9 90/09/09 23:10:04 tho Exp $

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).

@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that
the section entitled ``GNU General Public License'' is included exactly as in
the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this
one.

Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the text of the translations of the section
entitled ``GNU General Public License'' must be approved for accuracy by the
Foundation.
@end ifinfo

@comment --------------------------------------------------------------

@titlepage
@sp 10
@center @titlefont{The swaplib manual}
@sp 2
@center by Thorsten Ohl
@sp 3
@center Edition 0.0 pre-alpha,
@sp 1
@center last updated Thu Sep 06 02:40:54 1990
@sp 1
@center for @code{swaplib}, Version 0.1 Beta.
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1990 Thorsten Ohl
@sp 2

This is Edition 0.0 pre-alpha the @cite{swaplib Manual}, @*
last updated Thu Sep 06 02:42:11 1990, @*
for @code{swaplib} Version 0.1 Beta.

@sp 2

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that
the section entitled ``GNU General Public License'' is included exactly as in
the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this
one.

Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the text of the translation of the section
entitled ``GNU General Public License'' must be approved for accuracy by the
Foundation.
@end titlepage
@page

@comment --------------------------------------------------------------

@node Top,,,(Dir)

@menu
* Features::		What @code{swaplib} can do for you.
* Copying::		Legal matters
* Introduction::	General introduction to @code{swaplib}
* Installation::	How to make @code{swaplib}
* Usage::		How to use @code{swaplib} in your programs
* Customization::	How to adapt @code{swaplib} to your needs
* Bugs::		Things left to do about @code{swaplib}
* Concept Index::	A hitchhiker's guide to @code{swaplib}
* Programming Index::	Functions and variables in @code{swaplib}
@end menu

@comment --------------------------------------------------------------

@node Features
@unnumbered What @code{swaplib} can do for you

@enumerate
@item
@xref{Functions} for details.

@item
@code{swaplib} is Free Software!
@xref{Copying} for details.
@end enumerate


@comment --------------------------------------------------------------

@node Copying
@unnumbered GNU GENERAL PUBLIC LICENSE
@center Version 1, February 1989

@display
Copyright @copyright{} 1989 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display

@unnumberedsec Preamble

  The license agreements of most software companies try to keep users
at the mercy of those companies.  By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software---to make sure the software is free for all its users.  The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must tell them their rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  The precise terms and conditions for copying, distribution and
modification follow.

@iftex
@unnumberedsec TERMS AND CONDITIONS
@end iftex
@ifinfo
@center TERMS AND CONDITIONS
@end ifinfo

@enumerate
@item
This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License.  The
``Program'', below, refers to any such program or work, and a ``work based
on the Program'' means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications.  Each
licensee is addressed as ``you''.

@item
You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program.  You may charge a fee for the physical act of
transferring a copy.

@item
You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:

@itemize @bullet
@item
cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and

@item
cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).

@item
If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.

@item
You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
@end itemize

Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.

@item
You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:

@itemize @bullet
@item
accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,

@item
accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,

@item
accompany it with the information you received as to where the
corresponding source code may be obtained.  (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
@end itemize

Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.

@item
You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License.  However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.

@item
By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.

@item
Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions.  You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.

@item
The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of the license which applies to it and ``any
later version'', you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.

@item
If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

@iftex
@heading NO WARRANTY
@end iftex
@ifinfo
@center NO WARRANTY
@end ifinfo

@item
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

@item
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
@end enumerate

@iftex
@heading END OF TERMS AND CONDITIONS
@end iftex
@ifinfo
@center END OF TERMS AND CONDITIONS
@end ifinfo

@page
@unnumberedsec Appendix: How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.

  To do so, attach the following notices to the program.  It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
``copyright'' line and a pointer to where the full notice is found.

@smallexample
@var{one line to give the program's name and a brief idea of what it does.}
Copyright (C) 19@var{yy}  @var{name of author}

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@end smallexample

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

@smallexample
Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@end smallexample

The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License.  Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items---whatever suits your
program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a ``copyright disclaimer'' for the program, if
necessary.  Here a sample; alter the names:

@example
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.

@var{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
@end example

That's all there is to it!


@comment --------------------------------------------------------------

@node Introduction
@chapter General introduction to @code{swaplib}


@menu
* Overview::		What @code{swaplib} does for you
* Description::		How @code{swaplib} works
* Author::		Who wrote it?
@end menu


@node Overview
@section What @code{swaplib} does for you


Porting software from GNU (or UNIX) to small computers often confronts
you with the limitations of these small computers.

This library have been designed to help you with two of these problems
when your target machine is an @code{IBM PC} (or compatible), running
@cindex MS-DOS
@code{MS-DOS}:

@enumerate
@item
Computers running @code{MS-DOS} can only address 1 Megabyte of
memory (moreover almost 400K of this are consumed by the addressspace
of I/O devices). Thus starting a sizeable program from another one will
soon face memory problems.  One way of working around this problem is
to @dfn{swap} the calling program to another storage medium while the
called program executes.

@item
A design deficiency of @code{MS-DOS} is its inability to pass reasonably
sized @dfn{commandlines} to the called program.
@end enumerate

@code{swaplib} addresses both of these problems.  For the first (swapping)
a self-contained solution is presented.  The solution to the second problem
requires some collaboration of the called programs.

As a byproduct, we have an improved simulation of the @samp{**IX}
@code{popen ()} and @code{pclose ()} functions for MS-DOS.

@node Description
@section How @code{swaplib} works


@menu
* Swapping::			Basic principles.
* Memory management::		How @code{swaplib} uses MS-DOS's memory.
@end menu


@node Swapping
@subsection Basic principles

@code{swaplib} is @emph{not} a @code{DOS-Extender}!


@node Memory management
@subsection How @code{swaplib} uses MS-DOS's memory

We would like to stress that @code{swaplib} does @emph{not} use any
undocumented @code{MS-DOS} interrupts.  Also @code{swaplib} does
@emph{not} @emph{modify} undocumented data structures of @code{MS-DOS}.

But it is convenient to use some information from @code{MS-DOS}' private
data to determine the size of the swapped program.

By now it is widely known how the @code{MS-DOS} does it's memory
management.  Therefore we will only discuss it here to the extent needed
for a basic understanding of @code{swaplib}.

@example
@tindex mcb_info
struct mcb_info
@{
  char		 id_byte;	/* 'M': not, 'Z': last MCB	*/
  unsigned short owner;		/* PSP of owner			*/
  unsigned short length;	/* length (in paragraphs = 16b)	*/
@};
@end example


@node Author
@section Who wrote it?

Please send bug reports (preferably with fixes (@emph{context}
@code{diff}s!), comments and enhancements to the author:

@display
      Thorsten Ohl
      <td12@@ddagsi3.bitnet>
@end display

I can make no promises to fix it immediately, but I might want to!

(@xref{Bugs} for known bugs.)

@comment --------------------------------------------------------------

@node Installation
@chapter How to install @code{swaplib}

@menu
* Makefile::		What you might want to change in the makefile.
* System dependencies::	What your Compiler has to provide.
@end menu


@node Makefile
@section Editing the makefile

The makefile was designed for GNU @code{make} and will need some
changes to be acceptable for loosing @code{make}s.

@enumerate
@item
Edit the following variables in the makefile

@table @code
@item SWAPCFG
This is for configuring the swapper:
@table @code
@item -DUSE_XMS
Use extended memory (requires @code{XMS} driver, Version 2.0 or above).

@item -DUSE_EMS
Use expanded memory (requires @code{EMS} manager, Version 4.0 features are
not used).
@end table

@item CFLAGS, LDFLAGS
These are for the Microsoft C compiler Version 6.0, edit them for your
system:

@table @code
@item -W4
Full warnings!

@item -Ox
Enable maximal optimization.  But note that disabling the optmization
@code{-Od} is currently recommended for @file{swap.c}.  The inline
assembler doesn't blend nicely with the optimizer.
@end table
@end table

@item
Say @code{make}.
@end enumerate

That's all.


@node System dependencies
@section What your Compiler has to provide

@enumerate
@item
The code assumes an ANSI C compiler.  If you want to use old-style C,
you will have to change all function declarations.  You will also have
to replace the variable argument macros from @file{<stdarg.h>} by
something suitable for your compiler.

@item
The most severe limitation for portability is the code from @file{swap.c},
since it uses features currently unique to Version 6.0 of Microsoft C.
@display
You are strongly encouraged to provide different
implementations which help to make this library
available to non Microsoft Compilers.
@end display

The problem with @file{swap.c} is that you have to force the compiler to
allocate all @emph{variables} beginning with @code{_swap_kernel_} in the
@emph{code} segment!  @code{MSC 6.0} provides this through the
@code{_based} pointers. (See the macro @code{CODE} in file @file{swap.c}).
@tindex CODE

@display
Note that Microsoft's @code{Quick C} (Version 2.5) is reported to accept
the @code{_based} attribute, but the generated code is @emph{unusable}
because the address of these pointers is still stored in a @emph{data}
segment (I will not comment on this "feature" @dots{}).
@end display

The included assembler code @file{_swap_l.asm} might be useful
for compiling @code{swaplib} with other compilers.  Please note that it
work for the @emph{large} memory model only.

Maybe it would increase portability to turn @file{swap.c} into assembler
code, but @emph{I} will not be able to maintain it, since Intel assembler is
just beyond me.  Sorry for that, but volunteers are welcome.  What is
needed is firstly a set of @code{masm} and @code{tasm} macros that allow
compilation for all memory models.

@item
The inline assembly code from @file{swap.c} should be digestable by
several other C compilers.

@item
Some library functions will have other names with other compilers, but it
should be obvious what they do.
@end enumerate




@comment --------------------------------------------------------------

@node Usage
@chapter How to use @code{swaplib} in your programs.


@menu
* Linking::			How to include the functions of @code{swaplib}
* Functions::			Entry points in the library
* Errors::			How errors are reported
@end menu


@node Linking
@section How to include the functions of @code{swaplib}

You have to link your program with @file{swap.obj} and @file{swaplib?.lib}.
Please note that it is essential to link @file{swap.obj} as the @emph{first}
object module, since only code and data @emph{after} the swap kernel can
be swapped.


@node Functions
@section Entry points in the library

@menu
* spawnl::
* spawnle::
* spawnlp::
* spawnlpe::
* spawnv::
* spawnve::
* spawnvp::
* spawnvpe::
* system::
* popen::
* pclose::
* kernel::
@end menu


@node spawnl
@subsection @code{spawnl}
@findex spawnl
@findex swap_spawnl

@unnumberedsubsubsec Prototype

@example
int swap_spawnl (char *cmd, char *argv0, @dots{}, NULL);
@end example

@unnumberedsubsubsec Arguments

@table @code
@item cmd
Fully qualified path of command to run.

@item argv0, @dots{}, NULL
@code{NULL}-terminated list of arguments for @code{cmd}.
@end table


@node spawnle
@subsection @code{spawnle}
@findex spawnle
@findex swap_spawnle

@unnumberedsubsubsec Prototype

@example
int swap_spawnle (char *cmd, char *argv0, @dots{}, NULL, char **envv);
@end example

@unnumberedsubsubsec Arguments

@table @code
@item cmd
Fully qualified path of command to run.

@item argv0, @dots{}, NULL
@code{NULL}-terminated list of arguments for @code{cmd}.

@item envv
Evironment for child process.
@end table


@node spawnlp
@subsection @code{spawnlp}
@findex spawnlp
@findex swap_spawnlp

@unnumberedsubsubsec Prototype

@example
int swap_spawnlp (char *cmd, char *argv0, @dots{}, NULL);
@end example

@unnumberedsubsubsec Arguments

@table @code
@item cmd
Fully qualified path of command to run.

@item argv0, @dots{}, NULL
@code{NULL}-terminated list of arguments for @code{cmd}.
@end table


@node spawnlpe
@subsection @code{spawnlpe}
@findex spawnlpe
@findex swap_spawnlpe

@unnumberedsubsubsec Prototype

@example
int swap_spawnlpe (char *cmd, char *argv0, @dots{}, NULL, char **envv);
@end example

@unnumberedsubsubsec Arguments

@table @code
@item cmd
Fully qualified path of command to run.

@item argv0, @dots{}, NULL
@code{NULL}-terminated list of arguments for @code{cmd}.

@item envv
Evironment for child process.
@end table


@node spawnv
@subsection @code{spawnv}
@findex spawnv
@findex swap_spawnv

@unnumberedsubsubsec Prototype

@example
int swap_spawnv (char *cmd, char **argv);
@end example

@unnumberedsubsubsec Arguments


@node spawnve
@subsection @code{spawnve}
@findex spawnve
@findex swap_spawnve

@unnumberedsubsubsec Prototype

@example
int swap_spawnve (char *cmd, char **argv, char **envv);
@end example

@unnumberedsubsubsec Arguments


@node spawnvp
@subsection @code{spawnvp}
@findex spawnvp
@findex swap_spawnvp

@unnumberedsubsubsec Prototype

@example
int swap_spawnvp (char *cmd, char **argv);
@end example

@unnumberedsubsubsec Arguments


@node spawnvpe
@subsection @code{spawnvpe}
@findex spawnvpe
@findex swap_spawnvpe

@unnumberedsubsubsec Prototype

@example
int swap_spawnvpe (char *cmd, char **argv, char **envv);
@end example

@unnumberedsubsubsec Arguments


@node system
@subsection @code{system}
@findex system
@findex swap_system

@unnumberedsubsubsec Prototype

@example
int swap_system (char *command);
@end example

@unnumberedsubsubsec Arguments


@node popen
@subsection @code{popen}
@findex popen
@findex swap_popen

@unnumberedsubsubsec Prototype

@example
FILE *swap_popen (char *command, char *mode);
@end example

@unnumberedsubsubsec Arguments


@node pclose
@subsection @code{pclose}
@findex pclose
@findex swap_pclose

@unnumberedsubsubsec Prototype

@example
int swap_pclose (FILE *pipe);
@end example

@unnumberedsubsubsec Arguments


@node kernel
@subsection The kernel call
@findex _swap_spawn_child

@unnumberedsubsubsec Prototype

@example
int _swap_spawn_child (enum swapping_mode mode, char *path, char *cmdline,
char *env, int len, char *swap_file);
@end example

@unnumberedsubsubsec Arguments

You are not supposed to use this call to the @code{swaplib} kernel, so figure
out the arguments yourself, if you think you need to.


@node Errors
@section How errors are reported


@menu
* Exit codes::			How @code{swaplib} reports success.
* Error messages::		How fatal errors are handled.
@end menu


@node Exit codes
@subsection How @code{swaplib} reports success and failure


@example
	   @code{swaplib}'s return code:

	*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
	|     Signal      |  DOS Exit Code  |
	*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
	      High Byte        Low Byte
@end example

Note: this byte order is different from the System V convention!  If you
want use @code{swaplib} in a UNIX program, be sure to swap the bytes
before feeding this status word into your homebrew @code{wait ()} stub!

This particular format has been chosen anyway to conform to the
@code{MS-DOS} convention, that the @code{spawn[vl]p?e? ()} functions
return the @code{DOS} exit code.

At the moment only @code{SIGINT} is generated (when the user has hit
@ctrl{C} during execution of the child).


@node Error messages
@subsection How fatal errors are handled

@cindex Fatal errors
@cindex Panic

@example
Fatal error in memory management. Aborting.
Reason: @samp{Explanation}
@end example

Where @samp{Explanation} is one of the following:

@table @samp
@item Can't reallocate core.
Calling the @code{MS-DOS} function @code{0x40} (@code{Allocate Memory})
failed.  Either an internal error of @code{swaplib} or @code{MS-DOS} occured,
or (more likely) a child has left some TSR (virus?) behind.

@item Can't swap code back.
Somebody has stolen our swap file @dots{}.

@item Can't release core.
@code{MS-DOS} function @code{0x49} (@code{Free Allocated Memory}) failed.
This signals a severe internal @code{cswaplib} or @code{MS-DOS} error.
Save your data from RAM-disks and reboot.

@item Too many MCBs.
Your program uses too many @samp{Memory Control Blocks}
(@pxref{Memory management}).
You can increase the number @code{swaplib} can handle by
increasing @code{MAX_MSDOS_MCBS}
@vindex MAX_MSDOS_MCBS
in @file{swap.c}.  But this error is very unlikely and its
apparition most probably signals a severe problem in your
program's memory management.
@end table


@comment --------------------------------------------------------------

@node Customization
@chapter How to adapt @code{swaplib} to your needs.


@menu
* Swapping mode::	Setting the swapping mode
* Respondfiles::	Generating a respondfile for a command
* Scripts::		How to invoke a shell for processing a command
* Smart programs::	How to pass long commandlines
@end menu


@node Swapping mode
@section Setting the swapping mode


@example
@tindex swap_swapping_mode
enum swap_swapping_mode
@{
  none, disk, ems, xms
@};

@findex swap_set_swapping_mode
enum swap_swapping_mode swap_set_swapping_mode (char *cmd, char **argv);
@end example

The default function looks for @code{$SWAPPING}, which must be
one of @code{"xms"}, @code{"ems"}, @code{"disk"}, @code{"none"} (the last
alternative is not implemented yet, @pxref{Bugs}).

Another possibility would be to let the retrun value of
@code{swap_set_swapping_mode} depend on a command line switch.  That's also
trivial to implement.

Here is an example from @code{Bash}:

@example
enum swap_swapping_mode
swap_set_swapping_mode (char *cmd, char **argv)
@{
  /* Default to XMS.  */

  enum swap_swapping_mode mode = xms;

  SHELL_VAR *swapping = find_variable ("SWAPPING");

  if (!swapping || !(swapping->value))
    return mode;

  if (strcmp ("xms", swapping->value) == 0)
    mode = xms;
  else if (strcmp ("ems", swapping->value) == 0)
    mode = ems;
  else if (strcmp ("disk", swapping->value) == 0)
    mode = disk;
  else if (strcmp ("none", swapping->value) == 0)
    mode = none;

  return mode;
@}
@end example


@node Respondfiles
@section Generating a respondfile for a command.


@example
@tindex swap_respondfile_action
struct swap_respondfile_action
@{
  char *prog;
  int (*action) (char **argv, char **envv);
@};

@findex swap_set_respondfile_actions
struct swap_respondfile_action *swap_set_respondfile_actions (void);
@end example

This is the hook for your new respondfiles.

The following global variables can be accessed for customizing the way
in which @code{swaplib} makes the commandline arguments digestable for
@code{MS-DOS}.

@example
@vindex _swap_cmdline_buf
extern char _swap_cmdline_buf[];
@vindex _swap_environ_buf
extern char *_swap_environ_buf;
@vindex _swap_respond_file_name
extern char *_swap_respond_file_name;
@end example


@node Scripts
@section How to invoke a shell for processing a command

@cindex shell

@example
@findex swap_invoke_shell
char *swap_invoke_shell (char *cmd, char ***argvp);
@end example


@node Smart programs
@section Passing long commandlines


@example
@findex swap_smart_p
int swap_smart_p (char *name);
@end example

Here's an example from GNU @code{make}:

@example
#define DELIMITER ":"
static char *smart_programs (void);

int
swap_smart_p (char *name)
@{
  char *list = smart_programs ();
  char *tok;

  tok = strtok (list, DELIMITER);

  while (tok && strcmp (tok, name))
    tok = strtok (NULL, DELIMITER);

  free (list);
  return (tok != NULL);
@}

char *
smart_programs (void)
@{
  struct variable *smart
    = lookup_variable ("LONGARGS", sizeof ("LONGARGS") - 1);
  char *string;

  if (smart && smart->value)
    @{
      string = (char *) xmalloc (strlen (smart->value) + 1);
      strcpy (string, smart->value);
    @}
  else
    @{
      string = (char *) xmalloc (1);
      strcpy (string, "");
    @}

  return string;
@}
@end example


@comment --------------------------------------------------------------

@node Bugs
@chapter Things to do about @code{swaplib}

These are the bugs which are known to me.  They are listed in
decreasing order of importance.

@enumerate
@item
@code{swaplib} can only be compiled with Version 6.0 of the
Microsoft C Optimizing Compiler.
@emph{This is a bug and not a feature.}
(@xref{System dependencies}.)

@item
(No longer a real bug.)
Swapping to expanded memory (@code{EMS}) is now supported, but
has not been tested extensively.

@item
Swapping can't be disabled.

@item
It's possible that some errors will not produce a correct error
code.

@item
The library needs more complete documentation.

@item
Microsoft's way of passing the information about open files to
the child is not supported yet.
@end enumerate

(@xref{Author} for where to report bugs.)


@comment --------------------------------------------------------------

@node Concept Index
@unnumbered Concept Index
@printindex cp


@comment --------------------------------------------------------------

@node Programming Index
@unnumbered Programmer's Index
@printindex fn

@comment --------------------------------------------------------------

@contents

@bye
