home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / workbench / prargs.c < prev   
C/C++ Source or Header  |  1992-09-03  |  5KB  |  128 lines

  1. ;/* prargs.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 prargs.c
  3. Blink FROM LIB:c.o,prargs.o LIB LIB:LC.lib,LIB:Amiga.lib TO prargs DEFINE __main=__tinymain
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1992 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga, Inc. for
  10. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  11. published by Addison-Wesley (ISBN 0-201-56774-1).
  12.  
  13. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  14. information on the correct usage of the techniques and operating system
  15. functions presented in these examples.  The source and executable code
  16. of these examples may only be distributed in free electronic form, via
  17. bulletin board or as part of a fully non-commercial and freely
  18. redistributable diskette.  Both the source and executable code (including
  19. comments) must be included, without modification, in any copy.  This
  20. example may not be published in printed form or distributed with any
  21. commercial product.  However, the programming techniques and support
  22. routines set forth in these examples may be used in the development
  23. of original executable software products for Commodore Amiga 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. ** NOTE: main and tinymain are prepended with two underscores.
  33. **
  34. ** PrArgs.c - This program prints all Workbench or Shell (CLI) arguments.
  35. */
  36. #include <exec/types.h>
  37. #include <workbench/startup.h>
  38. #include <clib/dos_protos.h>
  39. #include <clib/icon_protos.h>
  40.  
  41. #include <stdlib.h>
  42. #include <stdio.h>
  43.  
  44. #ifdef LATTICE
  45. int CXBRK(void) { return(0); }   /* Disable SAS Lattice CTRL/C handling */
  46. int chkabort(void) { return(0); }/* really */
  47. #endif
  48.  
  49. void main(int argc, char **argv)
  50. {
  51. struct WBStartup *argmsg;
  52. struct WBArg *wb_arg;
  53. LONG ktr;
  54. BPTR olddir;
  55. FILE *outFile;
  56.  
  57. /* argc is zero when run from the Workbench,
  58. **         positive when run from the CLI.
  59. */
  60. if (argc == 0)
  61.     {
  62.     /* AmigaDOS has a special facility that  allows a window  */
  63.     /* with a console and a file handle to be easily created. */
  64.     /* CON: windows allow you to use fprintf() with no hassle */
  65.     if (NULL != (outFile = fopen("CON:0/0/640/200/PrArgs","r+")))
  66.         {
  67.         /* in SAS/Lattice, argv is a pointer to the WBStartup message
  68.         ** when argc is zero.  (run under the Workbench.)
  69.         */
  70.         argmsg = (struct WBStartup *)argv ;
  71.         wb_arg = argmsg->sm_ArgList ;         /* head of the arg list */
  72.  
  73.         fprintf(outFile, "Run from the workbench, %ld args.\n",
  74.                          argmsg->sm_NumArgs);
  75.  
  76.         for (ktr = 0; ktr < argmsg->sm_NumArgs; ktr++, wb_arg++)
  77.             {
  78.             if (NULL != wb_arg->wa_Lock)
  79.                 {
  80.                 /* locks supported, change to the proper directory */
  81.                 olddir = CurrentDir(wb_arg->wa_Lock) ;
  82.  
  83.                 /* process the file.
  84.                 ** If you have done the CurrentDir() above, then you can
  85.                 ** access the file by its name.  Otherwise, you have to
  86.                 ** examine the lock to get a complete path to the file.
  87.                 */
  88.                 fprintf(outFile, "\tArg %2.2ld (w/ lock): '%s'.\n",
  89.                                  ktr, wb_arg->wa_Name);
  90.  
  91.                 /* change back to the original directory when done.
  92.                 ** be sure to change back before you exit.
  93.                 */
  94.                 CurrentDir(olddir) ;
  95.                 }
  96.             else
  97.                 {
  98.                 /* something that does not support locks */
  99.                 fprintf(outFile, "\tArg %2.2ld (no lock): '%s'.\n",
  100.                                  ktr, wb_arg->wa_Name);
  101.                 }
  102.             }
  103.         /* wait before closing down */
  104.         Delay(500L);
  105.         fclose(outFile);
  106.         }
  107.     }
  108. else
  109.     {
  110.     /* using 'tinymain' from lattice c.
  111.     ** define a place to send the output (originating CLI window = "*")
  112.     ** Note - if you open "*" and your program is RUN, the user will not
  113.     ** be able to close the CLI window until you close the "*" file.
  114.     */
  115.     if (NULL != (outFile = fopen("*","r+")))
  116.         {
  117.         fprintf(outFile, "Run from the CLI, %d args.\n", argc);
  118.  
  119.         for ( ktr = 0; ktr < argc; ktr++)
  120.             {
  121.             /* print an arg, and its number */
  122.             fprintf(outFile, "\tArg %2.2ld: '%s'.\n", ktr, argv[ktr]);
  123.             }
  124.         fclose(outFile);
  125.         }
  126.     }
  127. }
  128.