/*  This will send all files in the directory in ARG[1] to the standard 
    output.  */


#define Msg Message

#include <libraries/dos.h>
#include <libraries/dosextens.h>

struct FileLock * Lock(char *, int);

void walk(flock, name)
struct FileLock * flock;
char * name;
{
   int success;
   struct FileInfoBlock * fib;
   char newname[256];
   struct FileLock * newlock;

   fib = (struct FileInfoBlock *) AllocMem(sizeof(struct FileInfoBlock), 0);

   success = Examine(flock, fib);
   if (success == 0) {
      printf("Error %d on \"%s\"\n", IoErr(), name);
      FreeMem(fib, sizeof(struct FileInfoBlock));
      return;
      }
   if (fib->fib_EntryType > 0) {    /* directory */
      Write(Output(), "list >ram:y ", 12);
      Write(Output(), name, strlen(name));
      Write(Output(), "\nprintit @ram:y ", 16);
      Write(Output(), name, strlen(name));
      Write(Output(), "\n", 1);
      do {
         success = ExNext(flock, fib);
         if (success) {
            strcpy(newname, name);
            strcat(newname, "/");
            strcat(newname, fib->fib_FileName);
            newlock = Lock(newname, ACCESS_READ);
            if (newlock == 0) Exit(RETURN_FAIL);
            walk(newlock, newname);
            UnLock(newlock);
            }
         } while (success);
      }
   else {                        /* not a directory */
      Write(Output(), "printit ", 8);
      Write(Output(), name, strlen(name));
      Write(Output(), "\n", 1);
      }
   FreeMem(fib, sizeof(struct FileInfoBlock));
   }


void main(argc, argv)
int argc; char * argv[];
{
   struct FileLock * flock;

   flock = Lock(argv[1], ACCESS_READ);

   if (flock == 0) exit(RETURN_FAIL);

   walk(flock, argv[1]);

   UnLock(flock);

   Exit(RETURN_OK);

   }




