jmlang@water.UUCP (Jerome Lang) (05/22/86)
Somebody requested a copy.ttp in a recent ST Wish list. Here's mine. usage is : copy infile1 outfile1 [ infile2 outfile2 ...] In case of an error, the error message is displayed and then the program waits for any key to be struck. This is because of the failure of the desktop to have a little patience ... error messages usually disappear.... Je'ro^me M. Lang || jmlang@water.uucp Dept of Applied Math || jmlang%water@waterloo.csnet U of Waterloo || jmlang%water%waterloo.csnet@csnet-relay.arpa Waterloo, Ont, CANADA N2L 3G1 || ======== cut here ============ : This is a shar archive. Extract with sh, not csh. : The rest of this file will extract: : copy.inp copy.c echo Extracting copy.inp sed 's/^X//' > copy.inp << 'e-o-f' X[u] COPY.68K=gemstart,COPY,osbind,gemlib e-o-f echo Extracting copy.c sed 's/^X//' > copy.c << 'e-o-f' X/* X * X * Copy.c copies files from source to destination X * usage : copy infile outfile [ infile outfile ...] X * Jerome M. Lang X * February 12, 1986 X */ X X#include <osbind.h> X X#define F_READ 0 X#define F_WRITE 1 X X#define BUF_LEN 16384 X Xtypedef int FDESC; X Xchar buffer[ BUF_LEN ]; X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X X FDESC infile, outfile; X FDESC openwr(); X X if( 1 == argc ) X usage(); X X while( --argc > 0 ) X { X if( 0 > (infile = (FDESC)Fopen(*++argv,F_READ)) ) X { X erreur(" Can't open infile ",*argv); X break; X } X Cconws(*argv); X Cconws("->"); X X if( 0 == --argc) X { X usage(); X break; X } X X if( 0 > (outfile = openwr(*++argv)) ) X { X erreur(" Can't create outfile ", *argv); X fclose(infile); X break; X } X X Cconws(*argv); X Cconws("\r\n"); X X copyfile(infile, outfile); X X Fclose(infile); X Fclose(outfile); X } X} X Xerreur(a,b) Xchar *a, *b; X{ X Cconws(a); X Cconws(b); X Cconws("\r\n"); X Cconout('\007'); X Cconin(); X} X Xusage() X{ X erreur("usage: copy infile outfile [ infile outfile ..]",""); X} X Xcopyfile(in, out) XFDESC in,out; X{ X long howmany; X X while( ( howmany = Fread(in,(long) BUF_LEN, buffer)) > 0 ) X if(howmany != Fwrite(out, howmany, buffer)) X { X erreur("Error in writing",""); X break; X } X} X XFDESC Xopenwr(file) Xchar *file; X{ X FDESC handle; X X if( (handle = (FDESC)Fcreate(file, 0)) < 0) X return( (FDESC)Fopen(file, F_WRITE) ); X else X return( handle ); X} e-o-f exit 0 -- Je'ro^me M. Lang || jmlang@water.uucp Dept of Applied Math || jmlang%water@waterloo.csnet U of Waterloo || jmlang%water%waterloo.csnet@csnet-relay.arpa