home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / ii-27 / readargs.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  4KB  |  120 lines

  1. ;/* ReadArgs.c - Execute me to compile me with SAS/C 6.56
  2. sc DATA=NEAR NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 ReadArgs.c
  3. slink FROM LIB:c.o,ReadArgs.o TO ReadArgs LIBRARY LIB:sc.lib,LIB:amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1991 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga,
  11. Inc. for use with the Amiga Mail Volume II technical publication.
  12. Amiga Mail Volume II contains additional information on the correct
  13. usage of the techniques and operating system functions presented in
  14. these examples.  The source and executable code of these examples may
  15. only be distributed in free electronic form, via bulletin board or
  16. as part of a fully non-commercial and freely redistributable
  17. diskette.  Both the source and executable code (including comments)
  18. must be included, without modification, in any copy.  This example
  19. may not be published in printed form or distributed with any
  20. commercial product. However, the programming techniques and support
  21. routines set forth in these examples may be used in the development
  22. of original executable software products for Commodore Amiga
  23. computers.
  24.  
  25. All other rights reserved.
  26.  
  27. This example is provided "as-is" and is subject to change; no
  28. warranties are made.  All use is at your own risk. No liability or
  29. responsibility is assumed.
  30. */
  31.  
  32.  
  33. #include <dos/dos.h>
  34. #include <dos/rdargs.h>
  35. #include <clib/dos_protos.h>
  36. #include <clib/alib_stdio_protos.h>
  37.  
  38.  
  39. #ifdef LATTICE
  40. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  41. int chkabort(void) { return(0); }
  42. #endif
  43.  
  44. UBYTE *vers = "\0$VER: ReadArgs 1.0";
  45.  
  46. #define TEMPLATE "S=SourceFiles/A/M,D=DebugLevel/K/N,L=link/S"
  47. #define OPT_SOURCE  0
  48. #define OPT_DEBUG   1
  49. #define OPT_LINK    2
  50. #define OPT_COUNT   3
  51.  
  52. /* The array of LONGs where ReadArgs() will store the data from
  53. ** the command line arguments.  C guarantees that all the array
  54. ** entries will be set to zero.
  55. */
  56. LONG result[OPT_COUNT];
  57.  
  58. /* My custom RDArgs */
  59. struct RDArgs *myrda;
  60.  
  61. ULONG StrLen(UBYTE *);
  62.  
  63. void main(void)
  64. {
  65.     UWORD x;
  66.     UBYTE **sourcefiles;
  67.  
  68.     /* Need to ask DOS for a RDArgs structure */
  69.     if (myrda = (struct RDArgs *)AllocDosObject(DOS_RDARGS, NULL))
  70.     {
  71.         /* set up my parameters for ReadArgs() */
  72.  
  73.         /* use the following command line */
  74.         myrda->RDA_Source.CS_Buffer = "file1 file2 file3 D=1 Link file4 file5\n";
  75.         myrda->RDA_Source.CS_Length = (LONG)StrLen(myrda->RDA_Source.CS_Buffer);
  76.  
  77.         /* parse my command line */
  78.         if (ReadArgs(TEMPLATE, result, myrda))
  79.         {
  80.             /*start printing out the results */
  81.  
  82.             /* We don't need to check if there is a value in
  83.             ** result[OPT_SOURCE] because the ReadArgs() template
  84.             ** requires (using the /A modifier) that there be
  85.             ** file names, so ReadArgs() will either fill in a
  86.             ** value or ReadArgs() will fail.
  87.             */
  88.             sourcefiles = (UBYTE **)result[OPT_SOURCE];
  89.             /* VPrintf() is a lot like Printf() except it's in
  90.             ** ROM, and the arguments are referenced from an
  91.             ** array rather than being extracted from the stack.
  92.             */
  93.             VPrintf("Files specified:\n", NULL);
  94.             for (x=0; sourcefiles[x]; x++)
  95.                 VPrintf("\t%s\n", (LONG *)&sourcefiles[x]);
  96.  
  97.             /* Is there something in the "DebugLevel" option?
  98.             ** If there is, print it.
  99.             */
  100.             if (result[OPT_DEBUG])
  101.                 VPrintf("Debugging Level = %ld\n", (LONG *)result[OPT_DEBUG]);
  102.  
  103.             /* If the link toggle was present, say something about it. */
  104.             if (result[OPT_LINK])
  105.                 VPrintf("linking...\n", NULL);
  106.             FreeArgs(myrda);
  107.         }
  108.         FreeDosObject(DOS_RDARGS, myrda);
  109.     }
  110. }
  111.  
  112.  
  113. ULONG StrLen(UBYTE *string)
  114. {
  115.     ULONG x = 0L;
  116.  
  117.     while (string[x++]);
  118.     return(x);
  119. }
  120.