main( argc, arcv )
int argc;
char *argv[]
{
#include <stdio.h>
#include <exec/types.h>
#include <exec/libraries/dos.h>
#include <exec/memory.h>
#include <functions.h>

#define CHAR unsigned char

/*  Z C H K I  --  Check if input file exists and is readable  */

/*
  Returns:
   >= 0 if the file can be read (returns the size).
     -1 if file doesn't exist or can't be accessed,
     -2 if file exists but is not readable (e.g. a directory file).
     -3 if file exists but protected against read access.
*/
/*
 Directory files, special files, and symbolic links are not readable.
*/
long zchki(name) 
CHAR *name; 
{
   struct FileInfoBlock *FBlock;
   long 		*FLock;
   long 		result;

   if ( (FLock = (struct FileLock *) Lock(name, ACCESS_READ)) == NULL)
      return -1;

   if ( (FBlock = (struct FileInfoBlock *)
     AllocMem( (long)sizeof(struct FileInfoBlock), (long)(MEMF_CHIP))) != NULL)
   if ( FBlock == NULL )
      result = -1;
   else
     {
	if ( !Examine( FLock, FBlock) )
	   result = -1;
	else
	  {
	     if ( FBlock->fib_DirEntryType > 0 )
		result = -2; /* It's a directory */
	     else
		result = FBlock->fib_Size;
	  }
	FreeMem( FBlock, (long)sizeof(struct FileInfoBlock) );
      }

   UnLock( FLock );
   return result;

}


/*  Z L T O R  --  Convert filename from local format to common form.	*/

zltor(name,name2) 
CHAR *name; 
CHAR *name2; 
{
    CHAR work[100]; 
    register CHAR *cp;
    register CHAR *pp;
    register int dc = 0;

    strcpy(work,name);
    for (cp = pp = work; *cp != '\0'; cp++) 
      {   /* strip path name */
	if (*cp == '/' || *cp == ':') 
	  {
	     pp = cp;
	     pp++;
	   }
	else if (islower(*cp)) *cp = toupper(*cp); /* Uppercase letters */
	else if (*cp == '~') *cp = 'X'; /* Change tilde to 'X' */
	else if ((*cp == '.') && (++dc > 1)) *cp = 'X'; /* & extra dots */
      }
    cp = name2; 			/* If nothing before dot, */
    if (*pp == '.') *cp++ = 'X';        /* insert 'X' */
    strcpy(cp,pp);
}

/*  Z F C D A T  --  Put file creation date/time in str.	 */
/*		     returns 1 if able to get date, 0 otherwise. */

zfcdat(fname,str) 
CHAR *fname,
*str; 
{
   strcpy( str, "<zfcdat: Not Implemented>" );
   return 0;
}


/* Z F R E E -- Return total number of free bytes on drive specified */

long zfree(drive)
CHAR *drive;
{
   register struct InfoData *id;
   long 	    FLock;
   LONG		    result;

   if ( (FLock = (struct InfoData *) Lock(drive, ACCESS_READ)) == NULL)
      return 0;

   if ( (id = (struct InfoData *)
     AllocMem( (long)sizeof(struct InfoData), (long)(MEMF_CHIP))) != NULL)
   if ( id == NULL )
      result = 0;
   else
     {
	if ( !Info( FLock, id) )
	   result = 0;
	else
	   result = (id->id_NumBlocks - id->id_NumBlocksUsed )
		  * id->id_BytesPerBlock;
	FreeMem( id, (long)sizeof(struct InfoData) );
      }

   UnLock( FLock );
   return result;

}

/*-----------------Start of Main--------------------*/

char *filename;

if ( argc != 2 )
   {	
      printf("Woops, argc= %d\n", argc );
      exit( 2 );
   }

filename = argv[ 1 ];
printf( "Examining '%s'\n", filename );
printf( "File size is %ld\n", zchki( filename ) );
printf( "Free Bytes are %ld\n", zfree( filename );
printf( "Th Th That's all Folks!\n" );
exit( 0 );
}