The swaplib manual



by Thorsten Ohl




Edition 0.0 pre-alpha,


last updated Thu Sep 06 02:40:54 1990


for swaplib, Version 0.1 Beta.

Copyright © 1990 Thorsten Ohl



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



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.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

What swaplib can do for you

  1. See section Entry points in the library for details.
  2. swaplib is Free Software! See section GNU GENERAL PUBLIC LICENSE for details.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

GNU GENERAL PUBLIC LICENSE

Version 1, February 1989

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.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

  1. 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”.
  2. 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.
  3. 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:

    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.

  4. 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:

    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.

  5. 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.
  6. 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.
  7. 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.
  8. 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.

  9. 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.
  10. 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.
  11. 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.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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.

one line to give the program's name and a brief idea of what it does.
Copyright (C) 19yy  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.

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:

Gnomovision version 69, Copyright (C) 19yy 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.

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:

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.

signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice

That’s all there is to it!


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1 General introduction to swaplib


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 What 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 IBM PC (or compatible), running MS-DOS:

  1. Computers running 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 swap the calling program to another storage medium while the called program executes.
  2. A design deficiency of MS-DOS is its inability to pass reasonably sized commandlines to the called program.

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 ‘**IXpopen () and pclose () functions for MS-DOS.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 How swaplib works


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.1 Basic principles

swaplib is not a DOS-Extender!


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.2 How swaplib uses MS-DOS’s memory

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

But it is convenient to use some information from MS-DOS’ private data to determine the size of the swapped program.

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

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

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Who wrote it?

Please send bug reports (preferably with fixes (context diffs!), comments and enhancements to the author:

      Thorsten Ohl
      <td12@ddagsi3.bitnet>

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

(See section Things to do about swaplib for known bugs.)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2 How to install swaplib


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 Editing the makefile

The makefile was designed for GNU make and will need some changes to be acceptable for loosing makes.

  1. Edit the following variables in the makefile
    SWAPCFG

    This is for configuring the swapper:

    -DUSE_XMS

    Use extended memory (requires XMS driver, Version 2.0 or above).

    -DUSE_EMS

    Use expanded memory (requires EMS manager, Version 4.0 features are not used).

    CFLAGS, LDFLAGS

    These are for the Microsoft C compiler Version 6.0, edit them for your system:

    -W4

    Full warnings!

    -Ox

    Enable maximal optimization. But note that disabling the optmization -Od is currently recommended for ‘swap.c’. The inline assembler doesn’t blend nicely with the optimizer.

  2. Say make.

That’s all.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 What your Compiler has to provide

  1. 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 ‘<stdarg.h>’ by something suitable for your compiler.
  2. The most severe limitation for portability is the code from ‘swap.c’, since it uses features currently unique to Version 6.0 of Microsoft C.
    You are strongly encouraged to provide different
    implementations which help to make this library
    available to non Microsoft Compilers.
    

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

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

    The included assembler code ‘_swap_l.asm’ might be useful for compiling swaplib with other compilers. Please note that it work for the large memory model only.

    Maybe it would increase portability to turn ‘swap.c’ into assembler code, but 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 masm and tasm macros that allow compilation for all memory models.

  3. The inline assembly code from ‘swap.c’ should be digestable by several other C compilers.
  4. Some library functions will have other names with other compilers, but it should be obvious what they do.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3 How to use swaplib in your programs.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 How to include the functions of swaplib

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


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Entry points in the library


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.1 spawnl


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnl (char *cmd, char *argv0, …, NULL);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments

cmd

Fully qualified path of command to run.

argv0, …, NULL

NULL-terminated list of arguments for cmd.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.2 spawnle


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnle (char *cmd, char *argv0, …, NULL, char **envv);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments

cmd

Fully qualified path of command to run.

argv0, …, NULL

NULL-terminated list of arguments for cmd.

envv

Evironment for child process.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.3 spawnlp


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnlp (char *cmd, char *argv0, …, NULL);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments

cmd

Fully qualified path of command to run.

argv0, …, NULL

NULL-terminated list of arguments for cmd.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.4 spawnlpe


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnlpe (char *cmd, char *argv0, …, NULL, char **envv);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments

cmd

Fully qualified path of command to run.

argv0, …, NULL

NULL-terminated list of arguments for cmd.

envv

Evironment for child process.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.5 spawnv


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnv (char *cmd, char **argv);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.6 spawnve


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnve (char *cmd, char **argv, char **envv);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.7 spawnvp


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnvp (char *cmd, char **argv);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.8 spawnvpe


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_spawnvpe (char *cmd, char **argv, char **envv);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.9 system


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_system (char *command);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.10 popen


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

FILE *swap_popen (char *command, char *mode);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.11 pclose


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

int swap_pclose (FILE *pipe);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.12 The kernel call


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Prototype

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

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Arguments

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


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 How errors are reported


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.1 How swaplib reports success and failure

	   swaplib's return code:

	*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
	|     Signal      |  DOS Exit Code  |
	*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
	      High Byte        Low Byte

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

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

At the moment only SIGINT is generated (when the user has hit C during execution of the child).


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.2 How fatal errors are handled

Fatal error in memory management. Aborting.
Reason: ‘Explanation

Where ‘Explanation’ is one of the following:

Can't reallocate core.

Calling the MS-DOS function 0x40 (Allocate Memory) failed. Either an internal error of swaplib or MS-DOS occured, or (more likely) a child has left some TSR (virus?) behind.

Can't swap code back.

Somebody has stolen our swap file ….

Can't release core.

MS-DOS function 0x49 (Free Allocated Memory) failed. This signals a severe internal cswaplib or MS-DOS error. Save your data from RAM-disks and reboot.

Too many MCBs.

Your program uses too many ‘Memory Control Blocks’ (see section How swaplib uses MS-DOS’s memory). You can increase the number swaplib can handle by increasing MAX_MSDOS_MCBS in ‘swap.c’. But this error is very unlikely and its apparition most probably signals a severe problem in your program’s memory management.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4 How to adapt swaplib to your needs.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Setting the swapping mode

enum swap_swapping_mode
{
  none, disk, ems, xms
};

enum swap_swapping_mode swap_set_swapping_mode (char *cmd, char **argv);

The default function looks for $SWAPPING, which must be one of "xms", "ems", "disk", "none" (the last alternative is not implemented yet, see section Things to do about swaplib).

Another possibility would be to let the retrun value of swap_set_swapping_mode depend on a command line switch. That’s also trivial to implement.

Here is an example from Bash:

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;
}

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Generating a respondfile for a command.

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

struct swap_respondfile_action *swap_set_respondfile_actions (void);

This is the hook for your new respondfiles.

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

extern char _swap_cmdline_buf[];
extern char *_swap_environ_buf;
extern char *_swap_respond_file_name;

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 How to invoke a shell for processing a command

char *swap_invoke_shell (char *cmd, char ***argvp);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 Passing long commandlines

int swap_smart_p (char *name);

Here’s an example from GNU make:

#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;
}

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5 Things to do about swaplib

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

  1. swaplib can only be compiled with Version 6.0 of the Microsoft C Optimizing Compiler. This is a bug and not a feature. (See section What your Compiler has to provide.)
  2. (No longer a real bug.) Swapping to expanded memory (EMS) is now supported, but has not been tested extensively.
  3. Swapping can’t be disabled.
  4. It’s possible that some errors will not produce a correct error code.
  5. The library needs more complete documentation.
  6. Microsoft’s way of passing the information about open files to the child is not supported yet.

(See section Who wrote it? for where to report bugs.)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Concept Index

Jump to:   F   M   P   S  
Index Entry  Section

F
Fatal errors 3.3.2 How fatal errors are handled

M
MS-DOS 1.1 What swaplib does for you

P
Panic 3.3.2 How fatal errors are handled

S
shell 4.3 How to invoke a shell for processing a command

Jump to:   F   M   P   S  

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Programmer’s Index

Jump to:   _  
C   M   P   S  
Index Entry  Section

_
_swap_cmdline_buf 4.2 Generating a respondfile for a command.
_swap_environ_buf 4.2 Generating a respondfile for a command.
_swap_respond_file_name 4.2 Generating a respondfile for a command.
_swap_spawn_child 3.2.12 The kernel call

C
CODE 2.2 What your Compiler has to provide

M
MAX_MSDOS_MCBS 3.3.2 How fatal errors are handled
mcb_info 1.2.2 How swaplib uses MS-DOS’s memory

P
pclose 3.2.11 pclose
popen 3.2.10 popen

S
spawnl 3.2.1 spawnl
spawnle 3.2.2 spawnle
spawnlp 3.2.3 spawnlp
spawnlpe 3.2.4 spawnlpe
spawnv 3.2.5 spawnv
spawnve 3.2.6 spawnve
spawnvp 3.2.7 spawnvp
spawnvpe 3.2.8 spawnvpe
swap_invoke_shell 4.3 How to invoke a shell for processing a command
swap_pclose 3.2.11 pclose
swap_popen 3.2.10 popen
swap_respondfile_action 4.2 Generating a respondfile for a command.
swap_set_respondfile_actions 4.2 Generating a respondfile for a command.
swap_set_swapping_mode 4.1 Setting the swapping mode
swap_smart_p 4.4 Passing long commandlines
swap_spawnl 3.2.1 spawnl
swap_spawnle 3.2.2 spawnle
swap_spawnlp 3.2.3 spawnlp
swap_spawnlpe 3.2.4 spawnlpe
swap_spawnv 3.2.5 spawnv
swap_spawnve 3.2.6 spawnve
swap_spawnvp 3.2.7 spawnvp
swap_spawnvpe 3.2.8 spawnvpe
swap_swapping_mode 4.1 Setting the swapping mode
swap_system 3.2.9 system
system 3.2.9 system

Jump to:   _  
C   M   P   S  

[Top] [Contents] [Index] [ ? ]

Table of Contents


[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated on March 28, 2025 using texi2html 5.0.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ << ] FastBack Beginning of this chapter or previous chapter 1
[ < ] Back Previous section in reading order 1.2.2
[ Up ] Up Up section 1.2
[ > ] Forward Next section in reading order 1.2.4
[ >> ] FastForward Next chapter 2
[Top] Top Cover (top) of document  
[Contents] Contents Table of contents  
[Index] Index Index  
[ ? ] About About (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:


This document was generated on March 28, 2025 using texi2html 5.0.