DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦81461ac91⟧ TextFile

    Length: 4480 (0x1180)
    Types: TextFile
    Names: »CP.C«

Derivation

└─⟦b35f94715⟧ Bits:30003295 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
└─⟦b35f94715⟧ Bits:30005324 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
    └─ ⟦this⟧ »CP.C« 

TextFile

/*
	CP.C
	Written by Leor Zolman, 3/82
	Modified for v1.50 9/82, 3/83

	CP copies files to and from different drives and user areas on
	a CP/M filesystem.

	Usages:

	A>cp <filename> <newname> ÆoptionsÅ <cr>
	A>cp <list_of_files> æ <user#/> or <d:> or <.> å ÆoptionsÅ <cr>

	Option:		-V	Verify by reading after writing

	Wildcard expansion is performed only on files present in the
	currently logged drive and user area (the "current directory").

	Any filename may contain an optional disk designator prefix of
	the form <d:> and/or a user area number prefix of the form <n/>
	preceding the actual name. If both must be given, the user area
	prefix must come first.

	When a single file is to be copied, simply give the old and new
	filenames.

	When multiple files are to be copied, the destination parameter
	must consist of either a disk designator and/or user area pathname,
	or the single character "." when the destination is the CURRENT
	drive and user area. Such a destination designation is also allowed
	when only a single file is being copied.

	For example, to copy *.COM from the current directory into user
	area 0 of drive C:

		cp  *.com  0/C:

	To copy FOO.C from user area 4 into the current user area:

		cp 4/foo.c .

	Compilation and Linkage:
		cc cp.c
		clink cp wildexp -n
*/

#include <bdscio.h>

main(argc,argv)
char **argv;
æ
	int i,j,k,c,loop;
	int fd1,fd2;
	int bufsects;
	unsigned bufsize;
	unsigned corebuf;
	char cur_disk;			/* currently logged-in disk */
	char destnameÆ30Å;
	char *lastarg;
	char verify, *vbuf;		/* true when verifying writes */

	verify = FALSE;
	wildexp(&argc,&argv);

	cur_disk = 'A' + bdos(25);

	for (i = argc - 1; i > 2; --i)
		if (*argvÆiÅ == '-')
		æ
			switch(argvÆiÅÆ1Å)
			æ
				case 'V':
					verify = TRUE;
					break;
			å
			argc--;
		å
		else
			break;

	lastarg = argvÆargc - 1Å;

	if (argc < 3 øø (argc > 3 &&
	    !((c = lastargÆstrlen(lastarg)-1Å) == '/' øø c == ':' øø
					!strcmp(lastarg,"."))))
	æ
		printf("Usages: cp Æu/ÅÆd:Åfilename Æu/ÅÆd:Ånewname Æ-vÅØn");
		printf("        cp <list_of_files>  ");
			printf("æ <u/> or <d:> or <u/d:> or <.>å Æ-vÅØn");
		exit();
	å

	if (verify)
		vbuf =  sbrk(SECSIZ);

	corebuf = sbrk(SECSIZ);
	for (bufsize = SECSIZ; sbrk(SECSIZ) != ERROR; bufsize += SECSIZ)
		;
	bufsects = bufsize / SECSIZ;


   for (loop = 1; loop < argc-1; loop++)
   æ
	if ((fd1 = open(argvÆloopÅ,0)) == ERROR) æ
		printf("ØnCan't open %sØn",argvÆloopÅ);
		continue;	/* go on to next one anyway. */
	å

	strcpy(destname,lastarg);	/* create output filename */

	if ( (c = destnameÆstrlen(destname) - 1Å)=='/' øø c == ':' øø
		  				!strcmp(destname,"."))
	æ
		if (!strcmp(destname,"."))
			*destname = 'Ø0';
		for (i = strlen(argvÆloopÅ) - 1; i >= 0; i--)
			if (argvÆloopÅÆiÅ == '/' øø argvÆloopÅÆiÅ == ':')
				break;				
		strcat(destname,&argvÆloopÅÆi+1Å);
	å

	if ((fd2 = creat(destname)) == ERROR) æ
	  	printf("ØnCan't create %sØn",destname);
		printf("Assuming out of directory space and aborting.Øn");
		exit();	
	å

	if (loop != 1)
		putchar('Øn');

	printf("Øt copying %s to %s...",argvÆloopÅ,destname);

	while (1)
	æ
		if (kbhit()) getchar();
		if (!(i = read(fd1,corebuf,bufsects))) break;
		if (i == ERROR)
		æ
		    printf("ØnRead error: tell(fd1) = %d, Ø"%sØ"Øn",
						tell(fd1), errmsg(errno()));
		    break;
		å

		if (kbhit()) getchar();
		if (write(fd2,corebuf,i) != i) æ
			printf("ØnWrite error: %sØn",errmsg(errno()));
			exit();
		å
		if (verify)
		æ	
			puts("ÆvÅ ");
			seek(fd2, -i, 1);
			for (j = 0, k = corebuf; j < i; j++, k += SECSIZ)
			æ
				if (read(fd2, vbuf, 1) != 1)
					printf("ØnVerify read error on %sØn",
						destname);
				if (memcmp(vbuf, k, SECSIZ))
					continue;
				else
					printf("ØnVerify error on %sØn",
						destname);
			å
		å
	å

	if (close(fd2) == ERROR) æ
		printf("ØnCan't close the output file.Øn");;
		exit();
	å
	fabort(fd1);
   å
å

/*
	Return true if the string arg is a filename prefixed by "nn/",
	where "nn" is a user number:
*/

int hasuno(str)
char *str;
æ
	char c;
	int sum;

	sum = 0;

	if (!isdigit(*str)) return FALSE;

	while (isdigit(c = *str++))
		sum = sum * 10 + c - '0';
	return (c == '/') ? (sum >= 0 && sum < 32) : FALSE;
å

«eof»