home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / pcpursut / pisrc.ark / CCHAIN.C < prev    next >
Text File  |  1988-07-14  |  2KB  |  90 lines

  1. /************************************************************
  2. * cchain.c - chain to another program
  3. ***********************************************************/
  4.  
  5.  
  6. #include "stdio.h"
  7.  
  8. #define TRUE    1
  9. #define FALSE 0
  10. #define LF    10
  11.  
  12. extern chain();
  13.  
  14. int cchain(string)
  15. char *string;    /* command to execute when chaining */
  16. {
  17.     char comfile[12];    /* filename in fcb format */
  18.     char tempstr[9];    /* temp string */
  19.     int i;
  20.     char *cptr;
  21.     char *tempptr;    
  22.  
  23.     cptr = 0x80;        /* where cmnd line arguements go */
  24.     /* skip whitespace */
  25.     while (*string && iswhite(*string))
  26.         string++;
  27.  
  28.  
  29.     /* check for drive name */
  30.     if (string[1] == ':') {
  31.         comfile[0] = toupper(string[0]) - 'A' + 1;
  32.         string += 2;
  33.     }
  34.     else comfile[0] = 0;
  35.  
  36.     /******************* get and make comfile ***********************/
  37.     /* get filename alone in tempstr, assume it starts with 1st char */
  38.     i = 0;
  39.     while (*string && !iswhite(*string) && (i < 8))
  40.         tempstr[i++] = *string++;
  41.     tempstr[i] = NULL;
  42.  
  43.     /* now copy to comfile string */    
  44.     strcpy(&(comfile[1]), tempstr);
  45.     for (i = strlen(tempstr); i < 8; i++) /* fill fcb with spaces */
  46.         comfile[i+1] = ' ';
  47.     strcpy(&(comfile[9]), "COM");
  48.     /* comfile is now in fcb format */
  49.  
  50.     /* now get cmnd line arguements */
  51.     /* copy cmnd line to memory */
  52.     tempptr = string;
  53.  
  54.     /* fix up 1st fcb */
  55.     while(*string && iswhite(*string))
  56.         string++;
  57.     if (*string)
  58.         fcbinit(string, 0x5C);
  59.     else
  60.         fcbinit("    ", 0x5C);
  61.  
  62.     /* fix up 2nd fcb */
  63.     while (*string && !iswhite(*string))
  64.         string++;
  65.     while (*string && iswhite(*string))
  66.         string++;
  67.     if (*string)
  68.         fcbinit(string, 0x6C);
  69.     else
  70.         fcbinit("    ", 0x6C);
  71.  
  72.     /* fix up command line area */
  73.     *cptr = strlen(tempptr);
  74.     cptr++;
  75.     strcpy(cptr, tempptr);
  76.  
  77.  
  78.     /* now jump to assembly routine to finish chain */
  79.     chain(comfile);
  80. }
  81.  
  82. static iswhite(c)
  83. char c;
  84. {
  85.     if ((c == ' ') || (c == '\t') || (c == LF))
  86.         return(TRUE);
  87.     else
  88.         return(FALSE);
  89. }
  90.