#include <exec/exec.h>
#include <stdio.h>
#include <stdlib.h>
char FileName[200];
void sr(char *s);
main(int argc,char *argv[])
{
   FILE *fi,*fo;
   long count=0L;
   char temp[200];
   if(argc<2)
   {
     printf("ZEROBYTE version 1.2, written by Joseph Hodge\n");
     printf("Usage: ZEROBYTE <filename> [-L]\n");
     printf("   ie: ZEROBYTE FileName\n");
     printf("   ie: ZEROBYTE FileList -L\n");
     printf("\n");
     exit(0);
   }

   
   strcpy(FileName,argv[1]);
   sr(FileName);
   if(argc==3)
   {
   fi=fopen(FileName,"r");
   if(fi==NULL)
   {
      printf("File %d not found or is in use\n");
      printf("\n");
      exit(0);
   }
   while(fgets(temp,80,fi)!=NULL)
   {
     sprintf(FileName,"RAM:%s",temp);
     sr(FileName);
     fo=fopen(FileName,"w");
     if(fo==NULL)
     {
       printf("Error, can't create file %s\n",FileName);
     }else
     {
     fclose(fo); count +=1L; }
   }
   fclose(fi);
   printf("\n");
   printf("%d ZEROBYTE files created\n",count);
   printf("\n");
  }
  else
  {
    strcpy(temp,FileName);
    strcpy(FileName,FilePart(temp));
    sprintf(temp,"RAM:%s",FileName);
    while(1)
    {
      fi=fopen(temp,"r");
      if(fi) { fclose(fi);strcat(temp,"_");
               if(strlen(temp)>30) { printf("ZEROBYTE Error on File %s\n",temp); exit(0); } continue; }
      break;
    }  
    fi=fopen(temp,"w");
    fclose(fi);
    printf("ZEROBYTE of %s complete\n",temp);
  }
  exit(0);
}

void sr(char *s)
{
  register int i;
  i=strlen(s)-1;
  while(i>-1)
  {
    if(*(s+i)<=32) *(s+i)=0; else break;
    i--;
  }
}