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

  1. ;/* ListPattern.c - AmigaMail MatchFirst()/MatchNext() example.
  2. sc NMINC STRMERGE NOSTKCHK NODEBUG DATA=FAR IGNORE=73 ListPattern.c
  3. slink from ListPattern.o to ListPattern lib lib:amiga.lib ;if you don't have pragmas
  4. quit
  5.  */
  6. /*
  7. Copyright (c) 1991 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga,
  10. Inc. for use with the Amiga Mail Volume II technical publication.
  11. Amiga Mail Volume II contains additional information on the correct
  12. usage of the techniques and operating system functions presented in
  13. these examples.  The source and executable code of these examples may
  14. only be distributed in free electronic form, via bulletin board or
  15. as part of a fully non-commercial and freely redistributable
  16. diskette.  Both the source and executable code (including comments)
  17. must be included, without modification, in any copy.  This example
  18. may not be published in printed form or distributed with any
  19. commercial product. However, the programming techniques and support
  20. routines set forth in these examples may be used in the development
  21. of original executable software products for Commodore Amiga
  22. computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31. #include <exec/memory.h>
  32. #include <dos/dosextens.h>
  33. #include <dos/rdargs.h>
  34. #include <clib/exec_protos.h>
  35. #include <clib/dos_protos.h>
  36.  
  37. /* undef PRAGMAS if you don't have them */
  38. #define PRAGMAS
  39. #undef PRAGMAS
  40. #ifdef PRAGMAS
  41. #include <pragmas/exec_pragmas.h>
  42. #include <pragmas/dos_pragmas.h>
  43. #else
  44.  
  45. struct ExecBase *SysBase;
  46. struct DosLibrary *DOSBase;
  47. #endif
  48.  
  49. VOID            main(VOID);
  50. UWORD           StrLen(UBYTE *);
  51.  
  52. VOID
  53. main(VOID)
  54. {
  55.  
  56. #ifdef PRAGMAS
  57.     struct DosLibrary *DOSBase;
  58. #endif
  59.  
  60.     struct RDArgs  *readargs;
  61.     LONG            rargs[1];
  62.     LONG            vargs[4];
  63.     UBYTE          *pattern;
  64.     struct AnchorPath *anchorpath;
  65.     LONG            error;
  66.  
  67. #ifndef PRAGMAS
  68.     /* set up SysBase */
  69.     SysBase = (*((struct Library **) 4));
  70. #endif
  71.  
  72.     /* Fail silently if < 37 */
  73.     if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37))
  74.     {
  75.         /* See the DOS Autodocs for more information about ReadArgs() */
  76.         if (readargs = ReadArgs("PATTERN/A", rargs, NULL))
  77.         {
  78.             pattern = (UBYTE *) rargs[0];
  79.             if (anchorpath = AllocMem(sizeof(struct AnchorPath) + 512, MEMF_CLEAR))
  80.             {
  81.                 anchorpath->ap_Strlen = 512;
  82.                 anchorpath->ap_BreakBits = SIGBREAKF_CTRL_C;
  83.  
  84.                 if ((error = MatchFirst(pattern, anchorpath)) == 0)
  85.                 {
  86.                     do
  87.                     {
  88.                         vargs[0] = (LONG) anchorpath->ap_Buf;
  89.                         VFPrintf(Output(), "%s\n", vargs);
  90.                     } while ((error = MatchNext(anchorpath)) == 0);
  91.                 }
  92.  
  93.                 MatchEnd(anchorpath);
  94.  
  95.                 if (error != ERROR_NO_MORE_ENTRIES)
  96.                     PrintFault(error, NULL);
  97.  
  98.                 FreeMem(anchorpath, sizeof(struct AnchorPath) + 512);
  99.             }
  100.             FreeArgs(readargs);
  101.         }
  102.         else
  103.             PrintFault(IoErr(), NULL);
  104.         CloseLibrary((struct Library *) DOSBase);
  105.     }
  106. }
  107.