/* ========================================================================= */

/*                    Argument Test Program by Dave Haynie                   */

/*
   This program is a simple demo program designed to display arguments 
   passed from the CLI or from WorkBench.  The CLI arguments are those
   normally passed from the CLI command line, and implemented as a
   standard part of Lattice C.  The WorkBench arguments are passed by
   Intuition as an external structure called WBenchMsg.  For those
   unfamiliar with these passing methods, I'll detail them below:

   [1]  Parameters passed via CLI:

      Parameter passing via a CLI type interface is a standard option in
   most C compilers.  When a C program is invoked, as in:

   1> ArgTest Arg1 Arg2 Arg3

   the main program, if defined as:

   main(argc,argv)
   int argc;
   char *argv[];
   { ... }
   
   will receive each command line argument as a part of argv[].  The value
   of argc will be the number of arguments passed, plus one.  This in the 
   above example, parameter argc should be 4, and the elements of argv
   are argv[0] = "ArgTest", argv[1] = "Arg1", argv[2] = "Arg2", and
   argv[3] = "Arg3".

   [2]  Parameters passed via WorkBench:

      The method of selecting and passing arguments from the WorkBench is
   unique to Intuition.  Using the standard command line interface, a program
   can tell if it was invoked by the WorkBench if the argc parameter is 
   zero.  The items to pass are selected using the WorkBench "extended
   select", in which you select your program via icon, then all other icons
   to pass to that program, with a shift key held down.  Double-clicking on
   the last icon will run the program.  These parameters are all available in
   the Workbench Startup structure.  This structure contains various pointers,
   among which is a number of passed parameters, "sm_NumArgs", and a list
   of WBArg structures containing locks and names for each argument.
*/


#include <exec/types.h>
#include <workbench/startup.h>
#include <stdio.h>

extern struct WBStartup *WBenchMsg;

/* This is the main program.  Here we'll examine the standard "argc"
   parameter.  If zero, we were called from WorkBench, otherwise, from
   CLI.  */

main(argc,argv)
int argc;
char *argv[];
{
   int i;

   if (argc != 0) {
      printf("Called from CLI...\n");
      for (i=0; i<argc; i++)
         printf("  (Arg %2d) %s\n", i, argv[i]);
   } else {
      printf("Called from WorkBench...\n");
      for (i=0; i<WBenchMsg->sm_NumArgs; i++)
         printf("  (Arg %2d) %s, Lock = 0x%lx\n", i, 
                WBenchMsg->sm_ArgList[i].wa_Name, 
                WBenchMsg->sm_ArgList[i].wa_Lock);
   }
   printf("Type <RETURN> to continue");
   getchar();
}
