File:  [Research Unix] / researchv10no / cmd / cbt / btcreat.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

#include "stdio.h"
#include "cbt.h"
#define error(x, y) {fprintf(stderr, x, y); exit(1); }

int iflag, rflag;
char node[NDSZ];
char buf[FNAMELEN];
extern char *malloc();

main(argc, argv)
char **argv;
{	int i, fd;
	hdr *b;
	char *p;
	for(i = 1; i < argc; i++) {
		if(argv[i][0] == '-') {
			for(p = argv[i] + 1; *p; p++)
				if(*p == 'i')
					iflag = 1;
				else if(*p == 'r')
					rflag = 1;
				else
					error("unknown flag %c\n", *p);
			if(i >= argc - 1)
				error("file name?", 0);
			continue;
		}
		if(!iflag) {
			sprintf(buf, "%s.F", argv[i]);
			if((fd = creat(buf, 0666)) < 0) {
				perror(buf);
				exit(1);
			}
			close(fd);
		}
		sprintf(buf, "%s.T", argv[i]);
		if((fd = creat(buf, 0666)) < 0) {
			perror(buf);
			if(!iflag) {
				sprintf(buf, "%s.F", argv[i]);
				unlink(buf);
			}
			exit(1);
		}
		b = (hdr *)node;
		b->kcnt = 0;
		if(iflag)
			b->htype |= INDEX;
		if(rflag)
			b->htype |= READONLY;
		nfree(b) = NDSZ - sizeof(hdr) - sizeof(trailer);
		if(write(fd, node, NDSZ) != NDSZ)
			perror("failed");
		close(fd);
	}
	exit(0);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.