Пример #1
0
interact()

{

	int	i, intrpt();
	char	cmd[80], *rest, *index();

	for (;;) {
		if (firsttime++ == 0) {
			signal(SIGINT, intrpt, -1);
			 setret(env);
		}
		if (cmdinp(cmd) < 0)
			return (0);
		rest = index(cmd, ' ');
		if (rest)
			*rest++ = '\0';
		i = chkcmd(cmd);
#ifdef DEBUG
		printf("command: %s, ind: %d\n", cmd, i);
#endif

		switch (i) {
		default:
			errinp;
			break;
		case CMD_DIR:
		case CMD_LS:
			dispdir();
			break;

		case CMD_RENAME:
			rename(rest);
			break;

		case CMD_OCOPY:
			copyc(rest, 0);
			break;

		case CMD_ICOPY:
			pip(rest, 0);
			break;

		case CMD_DELETE:
		case CMD_ERASE:
			delete(rest);
			break;

		case CMD_EXIT:
		case CMD_LOGOUT:
			return(0);

		case CMD_TYPE:
			copy(rest, stdout, 0);
			break;

		case CMD_HELP:
			help();
			break;

		case CMD_OCCOPY:
			copyc(rest, 1);
			break;

		case CMD_ICCOPY:
			pip(rest,1);
			break;

		case CMD_DUMP:
			dump(rest);
			break;

		case CMD_UNIX:
			system(rest);
			break;

		case CMD_DISK:
			disk();
			break;

		}
	}
}
Пример #2
0
int main(int argc, char *argv[])
{

	char *cpmname = NULL, *unixname = NULL ;
	int xflag = 0, stat = 0, Cflag = 0, Iflag = 0, Bflag = 0;

	if (argc == 1)
		usage();
	for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
		switch (argv[1][1]) {

		case 0:
			break;

		case 'B':
			Bflag++;
			continue;

		case 'd':
			dflag++;
			continue;

		case 'c':
			if (Cflag)
				stat++;
			cpmname = argv[2];
			unixname = argv[3];
			argc -= 2;
			argv += 2;
			cflag++;
			continue;

		case 'i':
			if (isatty(0) && isatty(1))
				iflag++;
			continue;

		case 'p':
			cpmname = argv[2];
			++argv;
			--argc;
			tflag++;
			continue;

		case 's':
			string = argv[2];
			++argv;
			skew = number(BIG);
			argc--;
			if ((skew < 1) || (skew > 10)) {
				printf("skew factor out of range\n");
				exit(1);
			}
			continue;

		case 'b':
			string = argv[2];
			++argv;
			blksiz = number(BIG);
			argc--;
			if (blksiz & 0xc3) {
				printf("illegal block size: %d\n", blksiz);
				exit(1);
			}
			continue;

		case 'm':
			string = argv[2];
			++argv;
			maxdir = number(BIG);
			argc--;
			if ((maxdir < 64) || (tracks > 1024)) {
				printf("illegal value of m-flag: %d\n", maxdir);
				exit(1);
			}
			continue;

		case 'l':
			string = argv[2];
			++argv;
			seclth = number(BIG);
			argc--;
			if ((seclth < 128) || (tracks > 1024)) {
				printf("illegal sector length: %d\n", seclth);
				exit(1);
			}
			continue;

		case 'R':
			string = argv[2];
			++argv;
			restrk = number(BIG);
			argc--;
			if (restrk < 0) {
				printf("illegal # res'd tracks: %d\n", restrk);
				exit(1);
			}
			continue;

		case 't':
			string = argv[2];
			++argv;
			tracks = number(BIG);
			argc--;
			if (tracks < 0 || tracks > 1024) {
				printf("illegal # of tracks: %d\n", tracks);
				exit(1);
			}
			continue;

		case 'r':
			string = argv[2];
			++argv;
			sectrk = number(BIG);
			argc--;
			if (sectrk > 48) {
				printf("illegal r-flag: %d\n", sectrk);
				exit(1);
			}
			continue;

		case 'C':
			if (cflag)
				stat++;
			cpmname = argv[3];
			unixname = argv[2];
			argc -= 2;
			argv += 2;
			Cflag++;
			continue;

		case 'I':
			Iflag++;
			continue;

#ifdef DEBUG
		case 'x':
			xflag++;
			continue;
#endif

		default:
			printf("Illegal flag: -%c\n", argv[1][1]);
			stat++;
		}
		break;
	}
	if (stat > 0) {
	}
	/* 16-bit pointers are used if the number of blocks exceeds 255 */
	use16bitptrs = ((tracks - restrk) * sectrk * seclth) / blksiz > 255;

	if (argc <= 1 && iflag) {
		printf("cpm: can't copy from stdin in interactive mode\n");
		exit(1);
	} else {
		if (argc <= 1)
			fid = fileno(stdin);
		else {
			int ic, mode = O_RDWR;
			argv++;
		      again:
			if ((fid = open(*argv, mode)) == -1) {
				if (errno == ENOENT) {
					/*
					 * The specified input file does not exist,
					 * does the user want to initialize a new
					 * file?
					 */

					printf("Input file \"%s\" does not exist.\n", *argv);
					printf("Initialize new floppy file? (y/n)?");
					if ((ic = getchar()) != 'y' && ic != 'Y')
						exit(1);
					fid = initcpm(*argv);
					ic = getchar();	/* get <eol> */
				} else {
					if (mode == O_RDWR) {
						fprintf(stderr, "Cannot open input file \"%s\" read/write, trying read-only\n", *argv);
						mode = O_RDONLY;
						goto again;
					}
					perror("Cannot open input file");
					exit(1);
				}
			} else {
				if (Iflag) {
					printf("Initialize floppy file? (y/n)?");
					if ((ic = getchar()) != 'y' && ic != 'Y')
						exit(1);
					fid = initcpm(*argv);
					ic = getchar();	/* get <eol> */
				}
			}
		}
	}
	/* allocate memory for the directory buffer */
	if ((dirbuf = (struct directory *) malloc(maxdir * 32)) == NULL) {
		printf("can't allocate memory for directory\n");
		exit(1);
	}
	gen_sktab();
	getdir();
	build_bmap();
#ifdef DEBUG
	if (xflag > 0) {
		int i;
		char ch;

		dbmap("current bitmap:\n");
		for (i = (int) dirbuf; i < (int) dirbuf + maxdir * 32; i++) {
			ch = *(char *) i;
			putchar((int) ch);
		}
	}
#endif

	/* ignore broken pipes (could happen if someone aborts a PAGER) */
	signal(SIGPIPE, SIG_IGN);

	if (iflag > 0) {
		interact();
		exit(0);
	}
	if (dflag > 0)
		dispdir();
	if (cflag > 0) {
		if (cpmname == NULL || unixname == NULL)
			usage();
		copy(cpmname, unixname, Bflag);
		exit(0);
	}
	if (Cflag > 0) {
		if (cpmname == NULL || unixname == NULL)
			usage();
		pipc(unixname, cpmname, Bflag);
		exit(0);
	}
	if (tflag > 0) {
		if (cpmname == NULL)
			usage();
		copy(cpmname, NULL, 0);
		exit(0);
	}
}