home *** CD-ROM | disk | FTP | other *** search
- /* startprog - driver program for CHAINed programs under PC-DOS 2.0
-
- Copyright (c) 1984 by JMI Software Consultants, Inc.
- */
-
- #include "acom.h"
- #include "host.h"
-
- /*
- Use this program until you have fully debugged your application programs,
- then modify the program to start the first of your application programs.
- For example: to start the program MAINMENU.EXE, change the function main
- to:
-
- VOID main()
- {
- start_chain("MAINMENU.EXE");
- }
-
- After compiling and linking this new program, you can rename the
- executable file to be consistant with your application. Note that
- this program will only work with the small memory model, and that the
- BASTOC run-time is not needed by this progam.
-
- Usage:
- STARTPROG filename
-
- Where:
- filename is the name of the first program in the series of programs
- to be CHAINed to. If filename is not found in the current directory
- and there is a PATH variable in the environment, then each directory
- in the PATH string will be searched until filename is found or until
- all directories have been exhausted. If filename does not contain
- an extension then filename.COM and filename.EXE will be tried also
- in each directory.
- */
-
-
- VOID main(ac, av)
- INT ac;
- TEXT **av;
- {
- if (ac > 1)
- start_chain(av[1]);
- }
-
- SEGREG seg;
-
- VOID start_chain(progname)
- TEXT *progname;
- {
- INTERN BOOL first_time = YES;
- INTERN TEXT nextprog[128]; /* name of next program to execute */
- INTERN TEXT currprog[128]; /* name of program to execute */
- INTERN TEXT chainline[64] = /* command line for CHAINed programs */
- "CHAIN=xxxxyyyy";
- INTERN TEXT comline[64] = /* command line for CHAINed programs */
- "COMMON=B2COM.DAT";
-
- if (first_time)
- {
- first_time = NO;
- segread(&seg);
- htoa(&chainline[6], 4, seg.s_ds);
- htoa(&chainline[10], 4, nextprog);
- unlink(comline + 7); /* name of COMMON file */
- }
- nextprog[0] = NULLCH;
- strcpy(currprog, progname);
- while (spawnlp(0, currprog, "", chainline, comline, 0) == 0)
- {
- strcpy(currprog, nextprog);
- nextprog[0] = NULLCH;
- }
- }
-
-
- INT htoa(a, n, h)
- TEXT *a; /* ASCII output buffer */
- COUNT n; /* number of characters to convert */
- INT h; /* integer input number */
- {
- INTERN INT x;
-
- while (n-- > 0)
- {
- x = (h >> (n << 2)) & 0xF;
- *a++ = x < 10 ? ('0' + x) : ('A' + x - 10);
- }
- }
-