[net.micro.atari16] AUTOCOPY, Utility to copy files at system boot

TPC862@ESTEC.BITNET (10/20/86)

Here a utility I made to use in the AUTO folder on boot disks without the Micro
C-Shell or similar. It copies a number of files from e.g. floppy to ramdisk.
It is not the utmost of sophistication (no wildcarding), but it works.
Enjoy.
----------------cut here-----autocopy.doc--------------------------------------
PROGRAM
   AUTOCOPY - Auto program to copy files at system boot

FUNCTION
   This program is to be placed in the \AUTO folder on the boot disk.
   It can be used to copy your favourite files to a ramdisk (which of
   course must exist before this program is run).
   It looks for the file \AUTO\AUTOCOPY.DAT which describes the files
   to be copied. The format of a line in AUTOCOPY.DAT is:

      <source file>  <destination file>

   An example :

      a:\xemacs.tos   d:\xemacs.tos
      a:\make.prg     d:\make.prg
      a:\gemstart.o   d:\gemstart.o
      a:\osbind.o     d:\osbind.o
      a:\gemlib       d:\gemlib
      a:\aesbind      d:\aesbind
      a:\vdibind      d:\vdibind
      a:\libf         d:\libf

CAVEATS
   Source and destination files must be specified with full path names
   in AUTOCOPY.DAT. No wildcards allowed.
   AUTOCOPY will not overwrite existing files (no extra copy at reset
   when files are still in the ramdisk).
   Linelength in AUTOCOPY.DAT is limited to 80 characters, so no very
   long path names.
----------------cut here-----end of autocopy.doc-------------------------------

And now the program written with Alcyon C. Link with gemstart.o, osbind.o and
gemlib.

----------------cut here-----autocopy.c----------------------------------------
/*
 * autocopy.c - Program to copy files on startup
 */

#include <stdio.h>
#include <ctype.h>
#include <osbind.h>

int cp(linebuf)
register char *linebuf;
{
   char source[128], dest[128];
   char buf[4096];
   register char *p;
   register int fsource, fdest;
   register long count;

   while(isspace(*linebuf)) linebuf++;
   if (*linebuf == '\0') {		/* no source specified */
      return 1;
   }

   for (p = source; !isspace(*linebuf) && (*linebuf != '\0');
        *p++ = *linebuf++) /* copy */ ;
   *p = '\0';

   while (isspace(*linebuf)) linebuf++;
   if (*linebuf == '\0') {		/* no destination specified */
      fprintf(stderr,"No destination file specified\n");
      return 2;
   }

   for(p = dest; !isspace(*linebuf) && (*linebuf != '\0');
       *p++ = *linebuf++) /* copy */ ;
   *p = '\0';

   if ((fdest = Fopen(dest, 0)) > 0) {
      fprintf(stderr, "Will not overwrite %s\n", dest);
      Fclose(fdest);
      return 3;
   }

   if ((fsource = Fopen(source, 0)) < 0) {
      fprintf(stderr, "%s: no such file\n", source);
      return 4;
   }

   if ((fdest = Fcreate(dest, 0)) < 0) {
      fprintf(stderr, "%s: cannot open for write\n", dest);
      Fclose(fsource);
      return 5;
   }

   printf("Copying %s to %s\n", source, dest);
   while ((count = Fread(fsource, 4096L, buf)) > 0) {
      if (Fwrite(fdest, count, buf) != count) {
         fprintf(stderr, "Error writing %s\n", dest);
         Fclose(fsource);
         Fclose(fdest);
         return 6;
      }
   }
   if (count < 0) {
      fprintf(stderr, "Error reading %s\n", source);
   }

   Fclose(fsource);
   Fclose(fdest);

   return 0;
}

main()
{
   FILE *fsource;
   FILE *fopen();
   char buf[82];

   printf("\033E                AUTOCOPY V1.0\n\n");

   if ((fsource = fopen("\\AUTO\\AUTOCOPY.DAT", "r")) == (FILE *)0) {
      fprintf(stderr,"\\AUTO\\AUTOCOPY.DAT not found\n");
      return 3;
   }

   while (!(feof(fsource))) {
     fgets(buf, 82, fsource);
     if ferror(fsource) break ;
     else               cp(buf);
   }
   fclose(fsource);

   printf("\nAUTOCOPY finished\n");
}
----------------cut here-----end of autocopy.c---------------------------------
Ton van Overbeek
European Space Research and Technology Centre (ESTEC)
Control Systems Section
P.O.Box 299
2200 AG Noordwijk, The Netherlands.
Phone: +31 1719 83041
Email: TPC862%ESTEC.BITNET@WISCVM.WISC.EDU  (ARPA)
       ...!ucbvax!tpc862@estec.bitnet       (USENET/UUCP)
       TPC862@ESTEC                         (EARN/BITNET)