home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 122.lha / Arp_v1.1 / Libraries / Manx_SRC / arpclip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  1.9 KB  |  64 lines

  1. /* Created 11/08/87 by -=+SDB+=- from cliparse.c provided by Manx */
  2. /* Copyright (C) 1987 by Scott Ballantyne */
  3. /* May be freely used by arp supporters/users */
  4.  
  5. /* This routine is called from _main() and parses the arguments passed from
  6.  * the CLI to the program.  It uses the ARP tracking functions to allocate
  7.  * memory for the argv array, and sets up _argc and _argv (using GADS)
  8.  * which will eventually be passed as parameters to main().
  9.  *
  10.  * It uses the Global variables CLI_Template and CLI_Help to set the command
  11.  * templates and extra help string for GADS() - if you don't set these up
  12.  * yourself, you get the defaults.
  13.  */
  14.  
  15. #include <libraries/dosextens.h>
  16.  
  17. extern int _argc;
  18. extern char **_argv;
  19. extern char *CLI_Template;
  20. extern char *CLI_Help;
  21.  
  22. _cli_parse(pp, alen, aptr)
  23. struct Process *pp;
  24. long alen;
  25. char *aptr;
  26. {
  27.     register char *cp;
  28.     register struct CommandLineInterface *cli;
  29.     register char *c;
  30.     register int argcount;
  31.     int length;
  32.     void *ArpAlloc();
  33.     long GADS();
  34.  
  35.     cli = (struct CommandLineInterface *) ((long)pp->pr_CLI << 2);
  36.     cp = (char *)((long)cli->cli_CommandName << 2);
  37.     length = cp[0];            /* Length of command name */
  38.     /* argcount *must* start at 3, do not change this.
  39.      * we need one for argv[0] = progname, and GADS() always
  40.      * requires one arg entry (for error messages, etc.)
  41.      * Then it is quasi standard for 'C' to have a final NULL as
  42.      * the argv array...
  43.      */
  44.     for (argcount = 3, c = CLI_Template; *c; c++ ) /* Size we need for argv */
  45.         if (*c == ',')
  46.             argcount++;
  47.  
  48.     if ((c = ArpAlloc((long)length)) == 0)    /* Get mem for name */
  49.         ArpExit(20L, ERROR_NO_FREE_STORE);
  50.     strncpy(c, cp+1, cp[0]);
  51.  
  52.     if ( (_argv = ArpAlloc( (long)(argcount * sizeof(*_argv)))) == 0)
  53.         ArpExit(20L, ERROR_NO_FREE_STORE);
  54.  
  55.     _argv[0] = c;
  56.     _argc = (int)GADS(aptr, alen, CLI_Help, (_argv+1), CLI_Template);
  57.     if (_argc < 0 )
  58.     {
  59.         Printf("Bad Args for %s: %s\n", _argv[0], _argv[1] );
  60.         ArpExit(20L, ERROR_LINE_TOO_LONG);
  61.     }
  62.     _argc++;
  63. }
  64.