#include <dos/dosextens.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <proto/dos.h>
#include <proto/exec.h>

int main(void)
{
 struct FileLock *lock;
 struct FileInfoBlock *fib_ptr;
 char dirname[10], textfile[80], line[80];
 FILE *input;

 /* Change this line for path to text files */
 strcpy(textfile, "doors:incd/");

 /* Change this if you don't refer to your CD ROM as cd0: */
 strcpy(dirname, "cd0:");

 fib_ptr = (struct FileInfoBlock *)
  AllocMem( sizeof( struct FileInfoBlock ),
  MEMF_PUBLIC | MEMF_CLEAR );

 if( fib_ptr == NULL )
 {
  printf("Not enough memory!\n");
  return 1;
 }

 lock = (struct FileLock *) Lock( dirname, SHARED_LOCK );

 if( lock == NULL )
 {
  printf("\033[0mNo CD ROM online at this time\n");
  FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  return 1;
 }

 if( Examine( lock, fib_ptr ) ) {
  printf("\033[0mCD ROM online is:  %s\n", fib_ptr->fib_FileName);
  strcat(textfile, fib_ptr->fib_FileName);
  if ((input=fopen(textfile, "r"))==NULL) {
   printf("No description of this CD ROM available\n");
  } else {
   while ((fgets (line, 80, input)) != NULL)  {
    printf("%s",line);
   }
   printf("\n");
  }
 }

 UnLock( lock );
 FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
 return 0;
}

