/* Dice: dcc -l0 -mD dpk.o Files.c -o Files
**
** Run this demo with the IceBreaker debug program and observe the output.
*/

#include <proto/dpkernel.h>
#include <misc/time.h>
#include <system/debug.h>

extern APTR FILBase;

BYTE *ProgName      = "Files";
BYTE *ProgAuthor    = "Paul Manias";
BYTE *ProgDate      = "10 October 1997";
BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1997.  Freely distributable.";
BYTE *ProgShort     = "File demo.";

void main(void)
{
  struct Directory *dir = NULL;
  struct FileName  loc  = { ID_FILENAME, "GMS:System/" };
  struct Directory *tdir;
  struct File      *tfile;

   if (dir = InitTags(NULL,
       TAGS_DIRECTORY, NULL,
       DIRA_Source,     &loc,
       TAGEND)) {

      if (Activate(dir) IS ERR_OK) {
         DPrintF("Directory activated, now printing dir/file list.");

         /* WriteComment(dir,"Testing WriteComment() in GMS."); */

         tdir = dir->ChildDir;
         while (tdir) {
            DPrintF("Dir:  %s  Date: %d/%d/%d", tdir->Source->Name, tdir->Date->Day, tdir->Date->Month, tdir->Date->Year);
            tdir = tdir->Next;
         }

         tfile = dir->ChildFile;
         while (tfile) {
            DPrintF("File: %s Date: %d/%d/%d", ((struct FileName *)tfile->Source)->Name, tfile->Date->Day, tfile->Date->Month, tfile->Date->Year);
            if (tfile->Comment) {
               DPrintF("Comment: %s  Permission Flags: $%x", tfile->Comment, tfile->Permissions);
            }
            else {
               DPrintF("Permission Flags: $%x", tfile->Permissions);
            }
            tfile = tfile->Next;
         }
      }
      else EMsg("Sorry, could not successfully activate the directory.");
   }
   else EMsg("Could not initialise directory object.");

   Free(dir);
}

