home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / libraries / workbench / prargs.c next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  4.1 KB  |  125 lines

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