#define NULL 0#define EOF -136#define FILE intstatic int fps[] = { 0,1,2,3,4,5,6,7 };/* array for fopen */getint(iptr,unit) /* reads an integer from a file */int *iptr;FILE unit;{     int t;     t = ciov(unit,7,iptr,sizeof(int),-1,-1);     if( t < 0)          return NULL;     else return 1;}getbuf(sptr,len,unit) /* reads a buffer from a file */char *sptr;int len;FILE unit;{     return ciov(unit,7,sptr,len,-1,-1);}putint(iptr,unit) /* write integer to file */int *iptr;FILE unit;{     return ciov(unit,11,iptr,sizeof(int),-1,-1);}putbuf(sptr,len,unit) /* write a buffer to a file */char *sptr;int len;FILE unit;{     return ciov(unit,11,sptr,len,-1,-1);}strcat(s1,s2) /* copy a string onto the end of another string */char *s1, *s2;{     while(*s1)         s1++;     strcpy(s1,s2);}trunc(s,len) /* truncate a string to a certain length */char *s;int len;{     s[len] = '\0';}exist(fname) /* returns 1 if file exists, else returns NULL */char *fname;{     int iocb;     if((iocb = copen(fname,'r'))> 0)          {               close(iocb);               return 1;          }     else close(iocb);     return 0;}fopen(fname, rwmode) /* K&R standard fopen. Use quoted strings as rwmode, */                     /* not chars. i.e. "r" not 'r'. Returns a pointer to */                     /* a FILE (integer on the Atari) not an integer */                     /* also allows mode "u" for both reading and writing */                     /* (updating) */char *fname, *rwmode;{     int test;     if(rwmode[0] != 'u')         {            test = copen(fname, rwmode[0]);             if (test < 0)                    {                         close(test);                         return NULL;                    }             else return &(fps[test]);         }     test = copen(fname, 'r');     if (test < 0)          {               close(test);               return NULL;          }     close(test);     ciov(test,3,fname,strlen(fname),12,-1);     return &(fps[test]);}fclose(unit) /* K&R fclose */int *unit;{     close(*unit);}fseek(unit,offset,spos) /* not a full implementation of fseek... (does not */                        /* return values, also does not use spos (will be */                       /* fixed in next version) SpartaDOS *only*! */int unit,offset,spos;{     point(unit,offset);}point(iocb,offset) /* points offset bytens into the file. Only handles */                   /* offsets up to 32767 because of the maximum size of int */                   /* mainly useful for SpartaDOS */int iocb,offset;{          poke(846 + (16 * iocb),0);          dpoke(844 +(16 * iocb),offset);          return ciov(iocb,37,-1,-1,-1,-1);          }#define BUFSIZE 16384     /* use the biggest buffer you can get away with */fcopy(infile,outfile)/* copies files*/char *infile;char *outfile;{      char buffer[BUFSIZE];      int byte;      int inunit;      int outunit;      int done;      int test;      done=0;      inunit=copen(infile,'r');      outunit=copen(outfile,'w');      if(inunit<0||outunit<0)          {              printf("%s-could not open",inunit<0?infile:outfile);              printf("%d\n",inunit<0?inunit:outunit);              close(inunit);              close(outunit);              return(-1);          }      while (!done)          {               test=ciov(inunit,7,buffer,BUFSIZE,-1,-1);               ciov(outunit,11,buffer,dpeek(inunit*16+840),-1,-1);                  if(test<0)                    done=1;          }        close(inunit);        close(outunit);        return(1);}setdrive(fname,drivenum)/*takes a fname.ext and drive # as input, and adds "D(drive number):" to the front of it. */char *fname;char drivenum;{     bump(fname,3,0);     fname[0]='D';     fname[1]='0'+drivenum;     fname[2]=':';}bump(string,n,ptr)/*copies a string to itself,offset by n places.ptr is the position to begin copying.Recursive.*/char *string;int n;int ptr;{     if(string[ptr] != '\0' && string[ptr] != '\n')     bump(string,n,ptr+1);     string[ptr+n]=string[ptr];      }conchk()/*checks console status*/{         int waiting;         char cstatus;         waiting=25;/*need to waste a little time while the OS updates*/                    /*the console status*/                  poke(53279,0);         while(waiting)             waiting--;         cstatus=peek(53279);         switch(cstatus)                {                    case 6:return 1;/*START key */                    case 5:return 2;/*SELECT key*/                    case 3:return 3;/*OPTION key*/                    default:return 0;                }}