home *** CD-ROM | disk | FTP | other *** search
- /* Startup.c -- Example program for using the ARP supplied startup
- * code for argument parsing.
- * -=+SDB+=-
- *
- * Copyright (c) 1987, Scott Ballantyne,
- * Use and abuse as you please.
- *
- * Compile normally (whatever that means) and then link with
- * arp.lib and c.lib.
- *
- * Manx:
- * cc startup.c
- * ln startup.o -larp -lc ; link with arp.lib
- *
- * Lattice:
- * lc startup.c
- * blink lib:c.o startup.o to startup lib lib:arp.lib lib:lc.lib lib:amiga.lib
- *
- * Note that when using the supplied C startup code, you do not need to
- * open or close arplibrary.
- *
- * More significant, you also get IntuitionBase and GfxBase initialized for
- * you - no need to open or close these libraries either.
- *
- */
-
- #include <exec/types.h>
- #include "libraries/arpbase.h" /* Get our standard header */
- #include "arpfunctions.h" /* Pre declared functions */
-
- /* Set CLI_Template to the command line template you wish parsed
- * If you don't, then you will get a default command line template.
- * Note: You will get a linker warning when you do this, to the
- * effect that "_CLI_Template is multiply defined". That just
- * means you are overriding the startup codes defaults. Not to
- * worry.
- */
-
- char *CLI_Template = "FROM/A,TO,OPT/K,COSMIC/S";
-
- /* The arp.librarary argument parser (GADS) will stuff these in
- * the appropriate spots in the argv array for you. The startup
- * code cleverly figures out how big to make that array.
- *
- * Here is one way to access the args. The most efficient depends
- * on the template, of course.
- */
-
- #define ARG_FROM 1
- #define ARG_TO 2
- #define ARG_OPT 3
- #define ARG_COSMIC 4
-
- /* Note that GADS() style argument parsing will always stuff the approriate
- * argument in the correct spot in the array. As examples, you might try
- * the following inputs to Startup:
- *
- * 1> Startup FROM file1 TO file2 OPT abc COSMIC
- * 1> Startup From File1 file2 COSMIC
- * 1> Startup Cosmic opt abc TO FILE1 FROM FILE2
- *
- * And, as an example of what happens on a command line error, you might
- * try the following:
- *
- * 1> Startup TO File2
- * 1> Startup From File1 File2 Opt
- * 1> Startup From File1 File2 Opt abc Cosmic karmic
- *
- */
-
- /* Set CLI_Help to the extra help string you wish to provide, if you
- * don't provide any, then you get the default. This will be displayed
- * if a user types a question mark after getting the command line template.
- *
- * 1> Startup ?
- * FROM/A,TO,OPT/K,COMIC/S: ? <- will display the CLI_Help string.
- */
-
- char *CLI_Help = "This is just a demo, relax already.";
-
- /*
- * The startup code will detect an error return from GADS(), and display
- * the appropriate error message (try a few mistakes and see what you get).
- *
- * The instances of /A arguments are handled this way:
- *
- * If NO arguments were supplied by the user, then it is up to
- * you to detect the missing arguments.
- *
- * If a user supplied arguments, but omitted a required one (/A), then
- * GADS() will detect this, and the startup code will abort.
- *
- * Finally, the capital P Printf() and FPrintf() are arp.libraries formatting
- * functions, they work just like normal 'C'. They keep programs much smaller.
- */
-
-
- VOID main(argc, argv)
- int argc;
- char **argv;
- {
- if (argc < 2) /* Check for absence of required argument */
- {
- Puts("Usage: FROM <this> TO <that> OPT <abc> COSMIC<ally>");
- exit(20);
- }
- /* We know we have the next one, since is a /A argument */
- Printf("FROM argument is \"%s\"\n", argv[ARG_FROM]);
- /* Check for others */
- if ( argv[ARG_TO] )
- Printf("TO argument is \"%s\"\n", argv[ARG_TO]);
-
- if ( argv[ARG_OPT] )
- Printf("OPTions specified are \"%s\"\n", argv[ARG_OPT]);
-
- /* Arguments specified as switches are not meaningful as strings,
- * if the switch was specified by the user, it's position in the
- * pointer array is occupied by -1L, otherwise, it is 0L.
- */
-
- if ( argv[ARG_COSMIC] )
- Puts("Program to progress cosmically");
- else
- Puts("Cosmic switch not in effect");
-
- /* Continue with rest of program here. */
- }
-