home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / APCOMLIN.C next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.8 KB  |  59 lines

  1. /**
  2. *
  3. * Name        apcomlin -- Return the DOS command line
  4. *
  5. * Synopsis    clen = apcomlin(pcmd);
  6. *
  7. *        int  clen      Length of the command line
  8. *        char *pcmd      Buffer in which to put command line
  9. *
  10. * Description    This function returns the command line typed at the DOS
  11. *        level when the program was invoked.  The entire command
  12. *        line (minus the program name) is returned, including all
  13. *        white space.  The length of the command line is returned
  14. *        as the value of the function.  Space for the command
  15. *        line (as much as 128 bytes, including a trailing NUL)
  16. *        must be allocated by the calling function.
  17. *
  18. * Returns    clen          Length of the command line
  19. *        *pcmd          The command line string
  20. *
  21. * Version    3.0 (C)Copyright Blaise Computing Inc. 1983,1984,1985,1986
  22. *
  23. **/
  24.  
  25. #include <bapplic.h>
  26. #include <butility.h>
  27.  
  28. int apcomlin(pcmd)
  29. char *pcmd;
  30. {
  31.     int cmdlen = 0;
  32.  
  33.     ADS cmdlen_ads;          /* Address of cmdlen              */
  34.     ADS cmd_ads;          /* Address of command line in the PSP   */
  35.     ADS cmdbuf_ads;          /* Address of caller's buffer           */
  36.  
  37.     utabsptr((char *) &cmdlen,&cmdlen_ads);
  38.  
  39.     cmd_ads.s = utpspseg;          /* Location of command line is  */
  40.     cmd_ads.r = 0x0080;           /* offset hex 80 in the          */
  41.                       /* program segment prefix.      */
  42.  
  43.     utslmove(&cmd_ads,&cmdlen_ads,1);
  44.     cmdlen &= 0x00ff;              /* The length is a single byte. */
  45.  
  46.     cmd_ads.r++;              /* Move to the next byte          */
  47.     utabsptr(pcmd,&cmdbuf_ads);
  48.     utslmove(&cmd_ads,&cmdbuf_ads,cmdlen);
  49.     pcmd[cmdlen] = '\0';              /* Terminating byte             */
  50.  
  51. #if CI201A & LDATA
  52.     for (i = 0; i < cmdlen; i++)      /* Fix bug in C86 large model - */
  53.     if (pcmd[i] == '\0')          /* it replaced blanks with nulls*/
  54.         pcmd[i] = ' ';
  55. #endif
  56.  
  57.     return(cmdlen);
  58. }
  59.