home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / programming / arpprog / examples / exprg.arc / Startup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-22  |  3.9 KB  |  128 lines

  1. /* Startup.c -- Example program for using the ARP supplied startup
  2.  *        code for argument parsing.
  3.  *        -=+SDB+=-
  4.  *
  5.  * Copyright (c) 1987, Scott Ballantyne,
  6.  * Use and abuse as you please.
  7.  *
  8.  * Compile normally (whatever that means) and then link with
  9.  * arp.lib and c.lib.
  10.  *
  11.  * Manx:
  12.  * cc startup.c
  13.  * ln startup.o -larp -lc ; link with arp.lib
  14.  *
  15.  * Lattice:
  16.  * lc startup.c
  17.  * blink lib:c.o startup.o to startup lib lib:arp.lib lib:lc.lib lib:amiga.lib
  18.  *
  19.  * Note that when using the supplied C startup code, you do not need to
  20.  * open or close arplibrary.
  21.  *
  22.  * More significant, you also get IntuitionBase and GfxBase initialized for
  23.  * you - no need to open or close these libraries either.
  24.  *
  25.  */
  26.  
  27. #include <exec/types.h>
  28. #include "libraries/arpbase.h"    /* Get our standard header */
  29. #include "arpfunctions.h"    /* Pre declared functions */
  30.  
  31. /* Set CLI_Template to the command line template you wish parsed
  32.  * If you don't, then you will get a default command line template.
  33.  * Note: You will get a linker warning when you do this, to the
  34.  * effect that "_CLI_Template is multiply defined". That just
  35.  * means you are overriding the startup codes defaults. Not to
  36.  * worry.
  37.  */
  38.  
  39. char *CLI_Template = "FROM/A,TO,OPT/K,COSMIC/S";
  40.  
  41. /* The arp.librarary argument parser (GADS) will stuff these in
  42.  * the appropriate spots in the argv array for you.  The startup
  43.  * code cleverly figures out how big to make that array.
  44.  *
  45.  * Here is one way to access the args.  The most efficient depends
  46.  * on the template, of course.
  47.  */
  48.  
  49. #define ARG_FROM    1
  50. #define ARG_TO        2
  51. #define ARG_OPT        3
  52. #define ARG_COSMIC    4
  53.  
  54. /* Note that GADS() style argument parsing will always stuff the approriate
  55.  * argument in the correct spot in the array.  As examples, you might try
  56.  * the following inputs to Startup:
  57.  *
  58.  *    1> Startup FROM file1 TO file2 OPT abc COSMIC
  59.  *    1> Startup From File1 file2 COSMIC
  60.  *    1> Startup Cosmic opt abc TO FILE1 FROM FILE2
  61.  *
  62.  * And, as an example of what happens on a command line error, you might
  63.  * try the following:
  64.  *
  65.  *    1> Startup TO File2
  66.  *    1> Startup From File1 File2 Opt
  67.  *    1> Startup From File1 File2 Opt abc Cosmic karmic
  68.  *
  69.  */
  70.  
  71. /* Set CLI_Help to the extra help string you wish to provide, if you
  72.  * don't provide any, then you get the default.  This will be displayed
  73.  * if a user types a question mark after getting the command line template.
  74.  *
  75.  *    1> Startup ?
  76.  *    FROM/A,TO,OPT/K,COMIC/S: ? <- will display the CLI_Help string.
  77.  */
  78.  
  79. char *CLI_Help = "This is just a demo, relax already.";
  80.  
  81. /*
  82.  * The startup code will detect an error return from GADS(), and display
  83.  * the appropriate error message (try a few mistakes and see what you get).
  84.  *
  85.  * The instances of /A arguments are handled this way:
  86.  *
  87.  *   If NO arguments were supplied by the user, then it is up to
  88.  *   you to detect the missing arguments.
  89.  *
  90.  *   If a user supplied arguments, but omitted a required one (/A), then
  91.  *   GADS() will detect this, and the startup code will abort.
  92.  *
  93.  * Finally, the capital P Printf() and FPrintf() are arp.libraries formatting
  94.  * functions, they work just like normal 'C'.  They keep programs much smaller.
  95.  */
  96.  
  97.  
  98. VOID main(argc, argv)
  99. int argc;
  100. char **argv;
  101. {
  102.     if (argc < 2)    /* Check for absence of required argument */
  103.     {
  104.         Puts("Usage: FROM <this> TO <that> OPT <abc> COSMIC<ally>");
  105.         exit(20);
  106.     }
  107.     /* We know we have the next one, since is a /A argument */
  108.     Printf("FROM argument is \"%s\"\n", argv[ARG_FROM]);
  109.     /* Check for others */
  110.     if ( argv[ARG_TO] )
  111.         Printf("TO argument is \"%s\"\n", argv[ARG_TO]);
  112.  
  113.     if ( argv[ARG_OPT] )
  114.         Printf("OPTions specified are \"%s\"\n", argv[ARG_OPT]);
  115.  
  116.     /* Arguments specified as switches are not meaningful as strings,
  117.      * if the switch was specified by the user, it's position in the
  118.      * pointer array is occupied by -1L, otherwise, it is 0L.
  119.      */
  120.  
  121.     if ( argv[ARG_COSMIC] )
  122.         Puts("Program to progress cosmically");
  123.     else
  124.         Puts("Cosmic switch not in effect");
  125.  
  126.     /* Continue with rest of program here. */
  127. }
  128.