/* * RT2MS.C Program to copy RT-11 files to MS-DOS * * Copyright (c) 1991 Shal Farley * Cheshire Engineering Corporation * 650 Sierra Madre Villa Avenue, Suite 201 * Pasadena, California 91107 * (818) 351-5493 * (818) 351-8645 FAX * shal@alumni.caltech.edu * * This software may be used and distributed for any purpose without license or * royalty payments so long as the above copyright notice is preserved. If you * have any comments, bug fixes, improvements, or new programs based upon this * software I'd like to hear from you. */ #include #ifdef __STDC__ # include #else # include "stdlib.h" #endif #include "msport.h" #include "msdefs.h" #include "msfio.h" #include "msdir.h" #include "mserrn.h" #define BUFSIZE (16*512) /* Read 16 blocks (sectors) at a time */ UCHAR buf[BUFSIZE]; char sOutSpec[MSFILENAME_MAX+1]; /* Buffer for building output name */ char sInSpec[FILENAME_MAX+1]; /* Result from fgetname() */ main(argc,argv) int argc; char *argv[]; { FILE *pFin; MSFILE *pFout; MSFILE *pFn0; /* Hold the first one ransom */ char *pOutName; /* Where to store the file name */ char *pInName; int nFiles; if (argc != 3) { printf("Usage: RT2MS wildspec dev:"); exit(EXIT_FAILURE); } if ((pFin = fwild(argv[1], "rn")) == NULL) Fail(argv[1]); for (nFiles = 0; fnext(pFin) != NULL; nFiles++){ if (nFiles == 0) { strcpy(sOutSpec, argv[2]); /* Setup output device name */ pOutName = strrchr(sOutSpec, ':'); if (pOutName != NULL) pOutName++; else pOutName = sOutSpec; } /* #### * Build the output name literally from the input. It would be better * to allow renames as RT-11's COPY command does, oh well... */ fgetname(pFin, sInSpec); /* Get the input file name */ pInName = strchr(sInSpec, ':'); if (pInName != NULL) pInName++; else pInName = sInSpec; strcpy(pOutName, pInName); if ((pFout = msfopen(sOutSpec, "wb")) == NULL) Fail(sOutSpec); FCopy(pFout, pFin); if (nFiles == 0) { if (msfflush(pFout) != 0) Fail(pFout->sName); pFn0 = pFout; /* Hold 1st file ransom to keep device open */ } else { if (msfclose(pFout) != 0) Fail(pFout->sName); } } if (nFiles == 0) { fprintf(stderr, "?RT2MS-F-File not found: %s", argv[1]); exit(EXIT_FAILURE); } if (msfclose(pFn0) != 0) Fail(pFn0->sName); /* Free our captive */ } FCopy(pFout, pFin) MSFILE *pFout; FILE *pFin; { int len; int buflen; int done; int i; char busy[5]; printf("Copying %-*s to %s:%s ", FILENAME_MAX-7, pFin->io_name, ((MSDEV *)pFout->pDEV)->sName, pFout->sName); i = 0; strcpy(busy, "-\\|/"); while ( (buflen = fread(buf, 1, BUFSIZE, pFin)) != 0 ) { done = 0; do { printf("\b%c", busy[i]); i = ++i & 3; fflush(stdout); len = MIN(buflen-done,SECTOR); if (msfwrite(&buf[done], 1, len, pFout) != len) Fail(pFout->sName); done += len; } while (done < buflen); } printf("\b \n"); } Fail(s) /* Print a message and exit */ char *s; { fprintf(stderr, "?RT2MS-F-"); msperror(s); exit(EXIT_FAILURE); }