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

  1. ;/* ListDir.c - Amiga Mail simple ExAll() example.
  2. sc NMINC STRMERGE NOSTKCHK NODEBUG DATA=FAR IGNORE=73 ListDir.c
  3. slink from ListDir.o to ListDir lib lib:amiga.lib ;if you don't have pragmas
  4. quit
  5.  *
  6.  * Pure code if pragmas are used.
  7.  * Tuesday, 16-Jul-91 16:21:14, Ewout
  8.  *
  9.  * Compiled with SAS/C 6.56
  10.  */
  11. /*
  12. Copyright (c) 1991 Commodore-Amiga, Inc.
  13.  
  14. This example is provided in electronic form by Commodore-Amiga,
  15. Inc. for use with the Amiga Mail Volume II technical publication.
  16. Amiga Mail Volume II contains additional information on the correct
  17. usage of the techniques and operating system functions presented in
  18. these examples.  The source and executable code of these examples may
  19. only be distributed in free electronic form, via bulletin board or
  20. as part of a fully non-commercial and freely redistributable
  21. diskette.  Both the source and executable code (including comments)
  22. must be included, without modification, in any copy.  This example
  23. may not be published in printed form or distributed with any
  24. commercial product. However, the programming techniques and support
  25. routines set forth in these examples may be used in the development
  26. of original executable software products for Commodore Amiga
  27. computers.
  28.  
  29. All other rights reserved.
  30.  
  31. This example is provided "as-is" and is subject to change; no
  32. warranties are made.  All use is at your own risk. No liability or
  33. responsibility is assumed.
  34. */
  35.  
  36. #include <exec/memory.h>
  37. #include <dos/dosextens.h>
  38. #include <dos/rdargs.h>
  39. #include <dos/exall.h>
  40.  
  41. #include <clib/exec_protos.h>
  42. #include <clib/dos_protos.h>
  43.  
  44. /* undef PRAGMAS if you don't have them */
  45. #define PRAGMAS
  46. #undef PRAGMAS
  47. #ifdef PRAGMAS
  48. #include <pragmas/exec_pragmas.h>
  49. #include <pragmas/dos_pragmas.h>
  50. #else
  51. struct ExecBase *SysBase;
  52. struct DosLibrary *DOSBase;
  53.  
  54. #endif
  55.  
  56. /* Buffersize to receive filenames in */
  57. #define BUFFERSIZE 512
  58.  
  59. VOID            main(VOID);
  60.  
  61. VOID
  62. main(VOID)
  63. {
  64. #ifdef PRAGMAS
  65.     struct DosLibrary *DOSBase;
  66.  
  67. #endif
  68.     struct RDArgs  *readargs;
  69.     LONG            rargs[2];
  70.     struct ExAllControl *excontrol;
  71.     struct ExAllData *ead, *buffer;
  72.     UBYTE          *source;
  73.     BPTR            sourcelock;
  74.     BOOL            exmore;
  75.     LONG            error;
  76.  
  77. #ifndef PRAGMAS
  78.     /* set up SysBase */
  79.     SysBase = (*((struct Library **) 4));
  80. #endif
  81.  
  82.     /* Fail silently if < 37 */
  83.     if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37))
  84.     {
  85.  
  86.         if (readargs = ReadArgs("DIRECTORY/A", rargs, NULL))
  87.         {
  88.  
  89.             source = (UBYTE *) rargs[0];
  90.  
  91.             if (buffer = AllocMem(BUFFERSIZE, MEMF_CLEAR))
  92.             {
  93.  
  94.                 if (sourcelock = Lock(source, SHARED_LOCK))
  95.                 {
  96.                     if (excontrol = AllocDosObject(DOS_EXALLCONTROL, NULL))
  97.                     {
  98.                         excontrol->eac_LastKey = 0;
  99.  
  100.                         do
  101.                         {
  102.  
  103.                             exmore = ExAll(sourcelock,
  104.                                            buffer,
  105.                                            BUFFERSIZE,
  106.                                            ED_NAME,
  107.                                            excontrol);
  108.                             error = IoErr();
  109.                             if ((exmore == NULL &&
  110.                                 (error != ERROR_NO_MORE_ENTRIES)))
  111.                                 break;
  112.  
  113.                             if (excontrol->eac_Entries == 0)
  114.                                 continue;
  115.  
  116.                             ead = buffer;
  117.                             do
  118.                             {
  119.  
  120.                                 /* Check for CTRL-C */
  121.                                 if (SetSignal(0L, SIGBREAKF_CTRL_C) &
  122.                                         SIGBREAKF_CTRL_C)
  123.                                 {
  124.                                     error = ERROR_BREAK;
  125.                                     exmore = FALSE;
  126.                                     break;
  127.                                 }
  128.  
  129.                                 rargs[0] = (LONG) ead->ed_Name;
  130.                                 VFPrintf(Output(), "%s\n", rargs);
  131.  
  132.                                 ead = ead->ed_Next;
  133.                             } while (ead);
  134.                         } while (exmore);
  135.  
  136.                         if (error != ERROR_NO_MORE_ENTRIES)
  137.                             PrintFault(error, NULL);
  138.  
  139.                         FreeDosObject(DOS_EXALLCONTROL, excontrol);
  140.                     }
  141.                     else
  142.                         PrintFault(ERROR_NO_FREE_STORE, NULL);
  143.  
  144.                     UnLock(sourcelock);
  145.                 }
  146.                 else
  147.                     PrintFault(IoErr(), source);
  148.  
  149.                 FreeMem(buffer, BUFFERSIZE);
  150.             }
  151.             else
  152.                 PrintFault(ERROR_NO_FREE_STORE, NULL);
  153.             FreeArgs(readargs);
  154.  
  155.         }
  156.         else
  157.             PrintFault(IoErr(), NULL);
  158.         CloseLibrary((struct Library *) DOSBase);
  159.     }
  160. }
  161.