home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / nrdargs / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-06  |  2.6 KB  |  110 lines

  1. /*
  2. **
  3. **    Example code for NewReadArgs and NewFreeArgs
  4. **    © 1997-1998 by Stephan Rupprecht, all rights reserved
  5. **
  6. **    Make sure that your compiler opens dos.library,
  7. **    icon.library and intuition.library on startup !!!
  8. **    
  9. **    This code has been developed under MaxonDEVELOP
  10. **
  11. **/
  12.  
  13. #include <dos/dos.h>
  14. #include <intuition/intuition.h>
  15.  
  16. #include <pragma/dos_lib.h>
  17. #include <pragma/exec_lib.h>
  18. #include <pragma/intuition_lib.h>
  19.  
  20. #include <newreadargs.h>
  21.  
  22. /****************************************************************************/
  23.  
  24. struct Library *UtilityBase;
  25.  
  26. /****************************************************************************/
  27.  
  28. void ShowDosError(LONG err, STRPTR text)
  29. {
  30.     struct Process *ThisTask = (struct Process *)FindTask(NULL);
  31.  
  32.     /*- Use PrintFault() when started from cli, otherwise EasyRequest() -*/
  33.     if(ThisTask && err) 
  34.         if(ThisTask->pr_CLI) PrintFault(err, text);
  35.       else 
  36.     {
  37.            TEXT buffer[80];
  38.            struct EasyStruct es = { 
  39.             sizeof(struct EasyStruct), 0,
  40.                 ThisTask->pr_Task.tc_Node.ln_Name,
  41.                     "%s", "Okay" };
  42.  
  43.            Fault(err, text, buffer, sizeof(buffer));
  44.  
  45.            EasyRequest(NULL, &es, NULL, buffer);
  46.       }
  47. }
  48.  
  49. /****************************************************************************/
  50.  
  51. void main(int argc, APTR argv)
  52. {
  53.      struct NewRDArgs    nrda = {}; // empty structure 
  54.     struct     {    STRPTR    *multi;
  55.                 LONG     _switch;
  56.                 LONG     toggle;
  57.             } args = { 0L, DOSFALSE, DOSFALSE };
  58.     LONG    err;
  59.  
  60.     if(!(UtilityBase = OpenLibrary("utility.library", 0L)))
  61.         return;
  62.  
  63.     /*- setup structure -*/
  64.     nrda.Template    = "MULTI/M,SWITCH/S,TOGGLE/T";
  65.     nrda.ExtHelp        = "This is an ExtHelp string!";
  66.     nrda.Window        = "CON:////NewReadArgs - example code";
  67.     nrda.Parameters     = (LONG *)&args;
  68.     nrda.FileParameter  = 0L; // we take them all
  69.     nrda.PrgToolTypesOnly = FALSE; // parse all icons 
  70.  
  71.     if(err = NewReadArgs((struct WBStartup *)(!argc  && argv) ? argv : 0L, &nrda))
  72.     {
  73.         ShowDosError(err, "NewReadArgs");    
  74.     } 
  75.     else
  76.     {        
  77.         if(args.multi)
  78.         {
  79.             STRPTR *ptr = args.multi;
  80.                 
  81.             Printf("MULTI\n");
  82.             while(*ptr) Printf(" %s\n", *ptr++);
  83.         }
  84.  
  85.         Printf("SWITCH : %s\nTOGGLE : %s\n", args._switch ? "TRUE" : "FALSE",
  86.             args.toggle ? "YES" : "NO");
  87.  
  88.         if(!argc  && argv) 
  89.         {
  90.             Printf("\nPress <RETURN>");
  91.             FGetC(Input());
  92.         }
  93.     }
  94.  
  95.     // NOTE: only call this function if you have used NewReadArgs before!
  96.     // If you use an empty structure, then you can forget this note !-)
  97.     NewFreeArgs(&nrda);
  98.  
  99.     CloseLibrary(UtilityBase);
  100. }
  101.  
  102. /****************************************************************************/
  103.  
  104. void wbmain(struct WBStartup *wbmsg)
  105. {
  106.     main(0L, (APTR)wbmsg);
  107. }
  108.  
  109. /****************************************************************************/
  110.