home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l200 / 6.ddi / TOOL / START.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-11  |  2.3 KB  |  92 lines

  1. /* startprog - driver program for CHAINed programs under PC-DOS 2.0
  2.  
  3.     Copyright (c) 1984 by JMI Software Consultants, Inc.
  4.  */
  5.  
  6. #include "acom.h"
  7. #include "host.h"
  8.  
  9. /*
  10.     Use this program until you have fully debugged your application programs,
  11.     then modify the program to start the first of your application programs.
  12.     For example: to start the program MAINMENU.EXE, change the function main
  13.     to:
  14.  
  15.         VOID main()
  16.             {
  17.             start_chain("MAINMENU.EXE");
  18.             }
  19.  
  20.     After compiling and linking this new program, you can rename the 
  21.     executable file to be consistant with your application.  Note that
  22.     this program will only work with the small memory model, and that the
  23.     BASTOC run-time is not needed by this progam.
  24.  
  25.     Usage:
  26.         STARTPROG filename
  27.  
  28.     Where:
  29.         filename is the name of the first program in the series of programs
  30.         to be CHAINed to.  If filename is not found in the current directory
  31.         and there is a PATH variable in the environment, then each directory
  32.         in the PATH string will be searched until filename is found or until
  33.         all directories have been exhausted.  If filename does not contain
  34.         an extension then filename.COM and filename.EXE will be tried also
  35.         in each directory.
  36.  */
  37.  
  38.  
  39. VOID main(ac, av)
  40.     INT ac;
  41.     TEXT **av;
  42.     {
  43.     if (ac > 1)
  44.         start_chain(av[1]);
  45.     }
  46.  
  47. SEGREG seg;
  48.  
  49. VOID start_chain(progname)
  50.     TEXT *progname;
  51.     {
  52.     INTERN BOOL first_time = YES;
  53.     INTERN TEXT nextprog[128];    /* name of next program to execute */
  54.     INTERN TEXT currprog[128];    /* name of program to execute */
  55.     INTERN TEXT chainline[64] = /* command line for CHAINed programs */
  56.         "CHAIN=xxxxyyyy";
  57.     INTERN TEXT comline[64] =    /* command line for CHAINed programs */
  58.         "COMMON=B2COM.DAT";
  59.  
  60.     if (first_time)
  61.         {
  62.         first_time = NO;
  63.         segread(&seg);
  64.         htoa(&chainline[6], 4, seg.s_ds);
  65.         htoa(&chainline[10], 4, nextprog);
  66.         unlink(comline + 7);    /* name of COMMON file */
  67.         }
  68.     nextprog[0] = NULLCH;
  69.     strcpy(currprog, progname);
  70.     while (spawnlp(0, currprog, "", chainline, comline, 0) == 0)
  71.         {
  72.         strcpy(currprog, nextprog);
  73.         nextprog[0] = NULLCH;
  74.         }
  75.     }
  76.  
  77.  
  78. INT htoa(a, n, h)
  79.     TEXT *a;     /* ASCII output buffer */
  80.     COUNT n;    /* number of characters to convert */
  81.     INT h;        /* integer input number */
  82.     {
  83.     INTERN INT x;
  84.  
  85.     while (n-- > 0)
  86.         {
  87.         x = (h >> (n << 2)) & 0xF;
  88.         *a++ = x < 10 ? ('0' + x) : ('A' + x - 10);
  89.         }
  90.      }
  91.  
  92.