示例#1
0
文件: ar.c 项目: CoryXie/nix-os
void
tcmd(char *arname, int count, char **files)
{
	int fd;
	Armember *bp;
	char name[ARNAMESIZE+1];

	fd = openar(arname, OREAD, 0);
	Binit(&bar, fd, OREAD);
	Bseek(&bar,seek(fd,0,1), 1);
	while(bp = getdir(&bar)) {
		if(count == 0 || match(count, files)) {
			if(vflag)
				longt(bp);
			trim(file, name, ARNAMESIZE);
			Bprint(&bout, "%s\n", name);
		}
		skip(&bar, bp->size);
		free(bp);
	}
	close(fd);
}
示例#2
0
文件: ar.c 项目: CoryXie/nix-os
void
pcmd(char *arname, int count, char **files)
{
	int fd;
	Armember *bp;

	fd = openar(arname, OREAD, 0);
	Binit(&bar, fd, OREAD);
	Bseek(&bar,seek(fd,0,1), 1);
	while(bp = getdir(&bar)) {
		if(count == 0 || match(count, files)) {
			if(vflag)
				print("\n<%s>\n\n", file);
			arcopy(&bar, 0, bp);
			if (write(1, bp->member, bp->size) < 0)
				wrerr();
		} else
			skip(&bar, bp->size);
		free(bp);
	}
	close(fd);
}
示例#3
0
void
threadmain(int argc, char *argv[])
{
	int i;
	Index *ix;
	u32int bcmem;

	bcmem = 0;
	ARGBEGIN{
	case 'B':
		bcmem = unittoull(ARGF());
		break;
	default:
		usage();
		break;
	}ARGEND

	if(argc < 1)
		usage();

	fmtinstall('H', encodefmt);

	if(initventi(argv[0], &conf) < 0)
		sysfatal("can't init venti: %r");

	if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
		bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
	if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
	initdcache(bcmem);

	ix = mainindex;
	Binit(&bout, 1, OWRITE);
	for(i=0; i<ix->nsects; i++)
		if(shoulddump(ix->sects[i]->name, argc-1, argv+1))
			dumpisect(ix->sects[i]);
	Bterm(&bout);
	threadexitsall(0);
}
示例#4
0
文件: rules.c 项目: 99years/plan9
static void
pushinput(char *name, int fd, uchar *str)
{
	Input *in;
	int depth;

	depth = 0;
	for(in=input; in; in=in->next)
		if(depth++ >= 10)	/* prevent deep C stack in plumber and bad include structure */
			parseerror("include stack too deep; max 10");

	in = emalloc(sizeof(Input));
	in->file = estrdup(name);
	in->next = input;
	input = in;
	if(str)
		in->s = str;
	else{
		in->fd = emalloc(sizeof(Biobuf));
		if(Binit(in->fd, fd, OREAD) < 0)
			parseerror("can't initialize Bio for rules file: %r");
	}

}
示例#5
0
文件: pr.c 项目: 00001/plan9port
void
main(int argc, char *argv[])
{
	Fils fstr[NFILES];
	int nfdone = 0;

	Binit(&bout, 1, OWRITE);
	Files = fstr;
	for(argc = findopt(argc, argv); argc > 0; --argc, ++argv)
		if(Multi == 'm') {
			if(Nfiles >= NFILES - 1)
				die("too many files");
			if(mustopen(*argv, &Files[Nfiles++]) == 0)
				nfdone++; /* suppress printing */
		} else {
			if(pr(*argv))
				Bterm(Files->f_f);
			nfdone++;
		}
	if(!nfdone)			/* no files named, use stdin */
		pr(nulls);		/* on GCOS, use current file, if any */
	errprint();			/* print accumulated error reports */
	exits(error? "error": 0);
}
示例#6
0
static void
rdgeom(SDunit *unit)
{
	char *line;
	char *flds[5];
	Biobuf bb;
	Biobuf *bp;
	static char geom[] = "geometry ";

	bp = &bb;
	seek(unit->ctl, 0, 0);
	Binit(bp, unit->ctl, OREAD);
	while((line = Brdline(bp, '\n')) != nil){
		line[Blinelen(bp) - 1] = '\0';
		if (strncmp(line, geom, sizeof geom - 1) == 0)
			break;
	}
	if (line != nil && tokenize(line, flds, nelem(flds)) >= 3) {
		unit->sectors = atoll(flds[1]);
		unit->secsize = atoll(flds[2]);
	}
	Bterm(bp);
	seek(unit->ctl, 0, 0);
}
示例#7
0
文件: disk.c 项目: 00001/plan9port
static Disk*
opensd(Disk *disk)
{
	Biobuf b;
	char *p, *f[10];
	int nf;

	Binit(&b, disk->ctlfd, OREAD);
	while(p = Brdline(&b, '\n')) {
		p[Blinelen(&b)-1] = '\0';
		nf = tokenize(p, f, nelem(f));
		if(nf >= 3 && strcmp(f[0], "geometry") == 0) {
			disk->secsize = strtoll(f[2], 0, 0);
			if(nf >= 6) {
				disk->c = strtol(f[3], 0, 0);
				disk->h = strtol(f[4], 0, 0);
				disk->s = strtol(f[5], 0, 0);
			}
		}
		if(nf >= 4 && strcmp(f[0], "part") == 0 && strcmp(f[1], disk->part) == 0) {
			disk->offset = strtoll(f[2], 0, 0);
			disk->secs = strtoll(f[3], 0, 0) - disk->offset;
		}
	}

	
	disk->size = disk->secs * disk->secsize;
	if(disk->size <= 0) {
		strcpy(disk->part, "");
		disk->type = Tfile;
		return openfile(disk);
	}

	findgeometry(disk);
	return mkwidth(disk);
}
示例#8
0
void
main(int argc, char **argv)
{
	int i, ok, rcvrs;
	char *addr, *rv, *trv, *host, *domain;
	char **errs;
	char hellodomain[256];
	String *from, *fromm, *sender;

	alarmscale = 60*1000;	/* minutes */
	quotefmtinstall();
	fmtinstall('[', encodefmt);
	errs = malloc(argc*sizeof(char*));
	reply = s_new();
	host = 0;
	ARGBEGIN{
	case 'a':
		tryauth = 1;
		if(trysecure == 0)
			trysecure = 1;
		break;
	case 'A':	/* autistic: won't talk to us until we talk (Verizon) */
		autistic = 1;
		break;
	case 'b':
		if (bustedmx >= Maxbustedmx)
			sysfatal("more than %d busted mxs given", Maxbustedmx);
		bustedmxs[bustedmx++] = EARGF(usage());
		break;
	case 'd':
		debug = 1;
		break;
	case 'f':
		filter = 1;
		break;
	case 'g':
		gdomain = EARGF(usage());
		break;
	case 'h':
		host = EARGF(usage());
		break;
	case 'i':
		insecure = 1;
		break;
	case 'p':
		alarmscale = 10*1000;	/* tens of seconds */
		ping = 1;
		break;
	case 's':
		if(trysecure == 0)
			trysecure = 1;
		break;
	case 't':
		trysecure = 2;
		break;
	case 'u':
		user = EARGF(usage());
		break;
	default:
		usage();
		break;
	}ARGEND;

	Binit(&berr, 2, OWRITE);
	Binit(&bfile, 0, OREAD);

	/*
	 *  get domain and add to host name
	 */
	if(*argv && **argv=='.') {
		domain = *argv;
		argv++; argc--;
	} else
		domain = domainname_read();
	if(host == 0)
		host = sysname_read();
	strcpy(hostdomain, domainify(host, domain));
	strcpy(hellodomain, domainify(sysname_read(), domain));

	/*
	 *  get destination address
	 */
	if(*argv == 0)
		usage();
	addr = *argv++; argc--;
	farend = addr;

	/*
	 *  get sender's machine.
	 *  get sender in internet style.  domainify if necessary.
	 */
	if(*argv == 0)
		usage();
	sender = unescapespecial(s_copy(*argv++));
	argc--;
	fromm = s_clone(sender);
	rv = strrchr(s_to_c(fromm), '!');
	if(rv)
		*rv = 0;
	else
		*s_to_c(fromm) = 0;
	from = bangtoat(s_to_c(sender));

	/*
	 *  send the mail
	 */
	if(filter){
		Binit(&bout, 1, OWRITE);
		rv = data(from, &bfile);
		if(rv != 0)
			goto error;
		exits(0);
	}

	/* mxdial uses its own timeout handler */
	if((rv = connect(addr)) != 0)
		exits(rv);

	/* 10 minutes to get through the initial handshake */
	atnotify(timeout, 1);
	alarm(10*alarmscale);
	if((rv = hello(hellodomain, 0)) != 0)
		goto error;
	alarm(10*alarmscale);
	if((rv = mailfrom(s_to_c(from))) != 0)
		goto error;

	ok = 0;
	rcvrs = 0;
	/* if any rcvrs are ok, we try to send the message */
	for(i = 0; i < argc; i++){
		if((trv = rcptto(argv[i])) != 0){
			/* remember worst error */
			if(rv != Giveup)
				rv = trv;
			errs[rcvrs] = strdup(s_to_c(reply));
			removenewline(errs[rcvrs]);
		} else {
			ok++;
			errs[rcvrs] = 0;
		}
		rcvrs++;
	}

	/* if no ok rcvrs or worst error is retry, give up */
	if(ok == 0 || rv == Retry)
		goto error;

	if(ping){
		quit(0);
		exits(0);
	}

	rv = data(from, &bfile);
	if(rv != 0)
		goto error;
	quit(0);
	if(rcvrs == ok)
		exits(0);

	/*
	 *  here when some but not all rcvrs failed
	 */
	fprint(2, "%s connect to %s:\n", thedate(), addr);
	for(i = 0; i < rcvrs; i++){
		if(errs[i]){
			syslog(0, "smtp.fail", "delivery to %s at %s failed: %s", argv[i], addr, errs[i]);
			fprint(2, "  mail to %s failed: %s", argv[i], errs[i]);
		}
	}
	exits(Giveup);

	/*
	 *  here when all rcvrs failed
	 */
error:
	removenewline(s_to_c(reply));
	syslog(0, "smtp.fail", "%s to %s failed: %s",
		ping ? "ping" : "delivery",
		addr, s_to_c(reply));
	fprint(2, "%s connect to %s:\n%s\n", thedate(), addr, s_to_c(reply));
	if(!filter)
		quit(rv);
	exits(rv);
}
示例#9
0
文件: tprof.c 项目: 99years/plan9
void
main(int argc, char *argv[])
{
	int fd;
	long i, j, k, n;
	Dir *d;
	char *name;
	ulong *data;
	ulong tbase, sum;
	long delta;
	Symbol s;
	Biobuf outbuf;
	Fhdr f;
	struct COUNTER *cp;
	char filebuf[128], *file;

	if(argc != 2 && argc != 3)
		error(0, "usage: tprof pid [binary]");
	/*
	 * Read symbol table
	 */
	if(argc == 2){
		file = filebuf;
		snprint(filebuf, sizeof filebuf, "/proc/%s/text", argv[1]);
	}else
		file = argv[2];

	fd = open(file, OREAD);
	if(fd < 0)
		error(1, file);

	if (!crackhdr(fd, &f))
		error(1, "read text header");
	if (f.type == FNONE)
		error(0, "text file not an a.out");
	machbytype(f.type);
	if (syminit(fd, &f) < 0)
		error(1, "syminit");
	close(fd);
	/*
	 * Read timing data
	 */
	file = smprint("/proc/%s/profile", argv[1]);
	fd = open(file, OREAD);
	if(fd < 0)
		error(1, file);
	free(file);
	d = dirfstat(fd);
	if(d == nil)
		error(1, "stat");
	n = d->length/sizeof(data[0]);
	if(n < 2)
		error(0, "data file too short");
	data = malloc(d->length);
	if(data == 0)
		error(1, "malloc");
	if(read(fd, data, d->length) < 0)
		error(1, "text read");
	close(fd);

	for(i=0; i<n; i++)
		data[i] = machdata->swal(data[i]);

	delta = data[0]-data[1];
	print("total: %ld\n", data[0]);
	if(data[0] == 0)
		exits(0);
	if (!textsym(&s, 0))
		error(0, "no text symbols");
	tbase = s.value & ~(mach->pgsize-1);	/* align down to page */
	print("TEXT %.8lux\n", tbase);
	/*
	 * Accumulate counts for each function
	 */
	cp = 0;
	k = 0;
	for (i = 0, j = (s.value-tbase)/PCRES+2; j < n; i++) {
		name = s.name;		/* save name */
		if (!textsym(&s, i))	/* get next symbol */
			break;
		sum = 0;
		while (j < n && j*PCRES < s.value-tbase)
			sum += data[j++];
		if (sum) {
			cp = realloc(cp, (k+1)*sizeof(struct COUNTER));
			if (cp == 0)
				error(1, "realloc");
			cp[k].name = name;
			cp[k].time = sum;
			k++;
		}
	}
	if (!k)
		error(0, "no counts");
	cp[k].time = 0;			/* "etext" can take no time */
	/*
	 * Sort by time and print
	 */
	qsort(cp, k, sizeof(struct COUNTER), compar);
	Binit(&outbuf, 1, OWRITE);
	Bprint(&outbuf, "    ms      %%   sym\n");
	while(--k>=0)
		Bprint(&outbuf, "%6ld\t%3lld.%lld\t%s\n",
				cp[k].time,
				100LL*cp[k].time/delta,
				(1000LL*cp[k].time/delta)%10,
				cp[k].name);
	exits(0);
}
示例#10
0
文件: ar.c 项目: tusharsoni/Inferno
/*
 *	perform the 'r' and 'u' commands
 */
void
arcmd(char *arname, int count, char **files)
{
    int fd;
    int i;
    Arfile *ap;
    Armember *bp;
    Dir *d;
    Biobuf *bfile;

    fd = openar(arname, ORDWR, 1);
    if (fd >= 0) {
        Binit(&bar, fd, OREAD);
        Bseek(&bar,seek(fd,0,1), 1);
    }
    astart = newtempfile(artemp);
    ap = astart;
    aend = 0;
    for(i = 0; fd >= 0; i++) {
        bp = getdir(&bar);
        if (!bp)
            break;
        if (bamatch(file, poname)) {		/* check for pivot */
            aend = newtempfile(tailtemp);
            ap = aend;
        }
        /* pitch symdef file */
        if (i == 0 && strcmp(file, symdef) == 0) {
            skip(&bar, bp->size);
            continue;
        }
        if (count && !match(count, files)) {
            scanobj(&bar, ap, bp->size);
            arcopy(&bar, ap, bp);
            continue;
        }
        bfile = Bopen(file, OREAD);
        if (!bfile) {
            if (count != 0)
                fprint(2, "ar: cannot open %s\n", file);
            scanobj(&bar, ap, bp->size);
            arcopy(&bar, ap, bp);
            continue;
        }
        d = dirfstat(Bfildes(bfile));
        if (d == nil)
            fprint(2, "ar: cannot stat %s: %r\n", file);
        if (uflag && (d == nil || d->mtime <= bp->date)) {
            scanobj(&bar, ap, bp->size);
            arcopy(&bar, ap, bp);
            Bterm(bfile);
            free(d);
            continue;
        }
        mesg('r', file);
        skip(&bar, bp->size);
        scanobj(bfile, ap, d->length);
        free(d);
        armove(bfile, ap, bp);
        Bterm(bfile);
    }
    if(fd >= 0)
        close(fd);
    /* copy in remaining files named on command line */
    for (i = 0; i < count; i++) {
        file = files[i];
        if(file == 0)
            continue;
        files[i] = 0;
        bfile = Bopen(file, OREAD);
        if (!bfile)
            fprint(2, "ar: %s cannot open\n", file);
        else {
            mesg('a', file);
            d = dirfstat(Bfildes(bfile));
            if (d == nil)
                fprint(2, "ar: can't stat %s: %r\n", file);
            else {
                scanobj(bfile, astart, d->length);
                armove(bfile, astart, newmember());
                free(d);
            }
            Bterm(bfile);
        }
    }
    if(fd < 0 && !cflag)
        install(arname, astart, 0, aend, 1);	/* issue 'creating' msg */
    else
        install(arname, astart, 0, aend, 0);
}
示例#11
0
文件: testscan.c 项目: npe9/harvey
void
main(int argc, char *argv[])
{
	int i, fd, n, aflag, vflag;
	char body[Bodysize+2], *raw, *ret;
	Biobuf *bp;

	sprint(patfile, "%s/patterns", UPASLIB);
	aflag = -1;
	vflag = 0;
	ARGBEGIN {
	case 'a':
		aflag = 1;
		break;
	case 'v':
		vflag = 1;
		break;
	case 'd':
		debug++;
		break;
	case 'p':
		strcpy(patfile,ARGF());
		break;
	} ARGEND

	bp = Bopen(patfile, OREAD);
	if(bp){
		parsepats(bp);
		Bterm(bp);
	}

	if(argc >= 1){
		fd = open(*argv, OREAD);
		if(fd < 0){
			fprint(2, "can't open %s\n", *argv);
			exits("open");
		}
		Binit(&bin, fd, OREAD);
	} else 
		Binit(&bin, 0, OREAD);

	*body = 0;
	*header = 0;
	ret = 0;
	for(;;){
		raw = canon(&bin, header+1, body+1, &n);
		if(raw == 0)
			break;
		if(aflag == 0)
			continue;
		if(aflag < 0)
			aflag = 0;
		if(vflag){
			if(header[1]) {
				fprint(2, "\t**** Header ****\n\n");
				write(2, header+1, strlen(header+1));
				fprint(2, "\n");
			}
			fprint(2, "\t**** Body ****\n\n");
			if(body[1])
				write(2, body+1, strlen(body+1));
			fprint(2, "\n");
		}

		for(i = 0; patterns[i].action; i++){
			if(matchaction(&patterns[i], header+1))
				ret = patterns[i].action;
			if(i == HoldHeader)
				continue;
			if(matchaction(&patterns[i], body+1))
				ret = patterns[i].action;
		}
	}
	exits(ret);
}
示例#12
0
void
main(int argc, char **argv)
{
	int i;

	ARGBEGIN {
# ifdef DEBUG
		case 'd': debug++; break;
		case 'y': yydebug = TRUE; break;
# endif
		case 't': case 'T':
			Binit(&fout, 1, OWRITE);
			errorf= 2;
			foutopen = 1;
			break;
		case 'v': case 'V':
			report = 1;
			break;
		case 'n': case 'N':
			report = 0;
			break;
		case '9':
			nine = 1;
			break;
		default:
			warning("Unknown option %c", ARGC());
	} ARGEND
	sargc = argc;
	sargv = argv;
	if (argc > 0){
		yyfile = argv[fptr++];
		fin = Bopen(yyfile, OREAD);
		if(fin == 0)
			error ("%s - can't open file: %r", yyfile);
		sargc--;
		sargv++;
	}
	else {
		yyfile = "/fd/0";
		fin = myalloc(sizeof(Biobuf), 1);
		if(fin == 0)
			exits("core");
		Binit(fin, 0, OREAD);
	}
	if(Bgetc(fin) == Beof)		/* no input */
		exits(0);
	Bseek(fin, 0, 0);
	gch();
		/* may be gotten: def, subs, sname, stchar, ccl, dchar */
	get1core();
		/* may be gotten: name, left, right, nullstr, parent, ptr */
	strcpy((char*)sp, "INITIAL");
	sname[0] = sp;
	sp += strlen("INITIAL") + 1;
	sname[1] = 0;
	if(yyparse()) exits("error");	/* error return code */
		/* may be disposed of: def, subs, dchar */
	free1core();
		/* may be gotten: tmpstat, foll, positions, gotof, nexts, nchar, state, atable, sfall, cpackflg */
	get2core();
	ptail();
	mkmatch();
# ifdef DEBUG
	if(debug) pccl();
# endif
	sect  = ENDSECTION;
	if(tptr>0)cfoll(tptr-1);
# ifdef DEBUG
	if(debug)pfoll();
# endif
	cgoto();
# ifdef DEBUG
	if(debug){
		print("Print %d states:\n",stnum+1);
		for(i=0;i<=stnum;i++)stprt(i);
		}
# endif
		/* may be disposed of: positions, tmpstat, foll, state, name, left, right, parent, ccl, stchar, sname */
		/* may be gotten: verify, advance, stoff */
	free2core();
	get3core();
	layout();
		/* may be disposed of: verify, advance, stoff, nexts, nchar,
			gotof, atable, ccpackflg, sfall */
# ifdef DEBUG
	free3core();
# endif
	fother = Bopen(cname,OREAD);
	if(fother == 0)
		error("Lex driver missing, file %s: %r",cname);
	while ( (i=Bgetc(fother)) != Beof)
		Bputc(&fout, i);

	Bterm(fother);
	Bterm(&fout);
	if(
# ifdef DEBUG
		debug   ||
# endif
			report == 1)statistics();
	if (fin)
		Bterm(fin);
	exits(0);	/* success return code */
}
示例#13
0
文件: tune.c 项目: aahud/harvey
void
tune_in(int fd, long *x, struct convert *out)
{
	Biobuf b;
	Rune rbuf[N];
	Rune *r, *er, tr;
	int c, i;
	
	USED(x);
	r = rbuf;
	er = rbuf+N-3;
	Binit(&b, fd, OREAD);
	while((c = Bgetrune(&b)) != Beof){
		ninput += b.runesize;
		if(r >= er){
			OUT(out, rbuf, r-rbuf);
			r = rbuf;
		}
		if(c>=0xe210/**/ && c <= 0xe38c/**/ && (i = c%16) < nelem(t2)){
			if(c >= 0xe380/**/){
				*r++ = 0x0b95/*க*/;
				*r++ = 0x0bcd/*்*/;
				*r++ = 0x0bb7/*ஷ*/;
			}else
				*r++ = findbytune(t3, nelem(t3), c-i+1);
			if(i != 1)
				*r++ = t2[i];
		}else if((tr = findbytune(t1, nelem(t1), c)) != Runeerror)
			*r++ = tr;
		else switch(c){
			case 0xe3d0/**/:
				*r++ = 0x0ba3/*ண*/; *r++ = 0x0bbe/*ா*/;
				break;
			case 0xe3d1/**/:
				*r++ = 0x0bb1/*ற*/; *r++ = 0x0bbe/*ா*/;
				break;
			case 0xe3d2/**/:
				*r++ = 0x0ba9/*ன*/; *r++ = 0x0bbe/*ா*/;
				break;
			case 0xe3d4/**/:
				*r++ = 0x0ba3/*ண*/; *r++ = 0x0bc8/*ை*/;
				break;
			case 0xe3d5/**/:
				*r++ = 0x0bb2/*ல*/; *r++ = 0x0bc8/*ை*/;
				break;
			case 0xe3d6/**/:
				*r++ = 0x0bb3/*ள*/; *r++ = 0x0bc8/*ை*/;
				break;
			case 0xe3d7/**/:
				*r++ = 0x0ba9/*ன*/; *r++ = 0x0bc8/*ை*/;
				break;
			case 0xe38d/**/:
				*r++ = 0x0bb6/*ஶ*/; *r++ = 0x0bcd/*்*/; *r++ = 0x0bb0/*ர*/; *r++ = 0x0bc0/*ீ*/;
				break;
			default: 
				if(c >= 0xe200 && c <= 0xe3ff){
					if(squawk)
						EPR "%s: rune 0x%x not in output cs\n", argv0, c);
					nerrors++;
					if(clean)
						break;
					c = BADMAP;
				}
				*r++ = c;
				break;
		}
	}
	if(r > rbuf)
		OUT(out, rbuf, r-rbuf);
	OUT(out, rbuf, 0);
}
示例#14
0
文件: cdrdwr.c 项目: 00001/plan9port
/*
 * It's not strictly conforming; instead it's enough to
 * get us up and running; presumably the real CD writing
 * will take care of being conforming.
 *
 * Things not conforming include:
 *	- no path table
 *	- root directories are of length zero
 */
Cdimg*
createcd(char *file, Cdinfo info)
{
	int fd, xfd;
	Cdimg *cd;

	if(access(file, AEXIST) == 0){
		werrstr("file already exists");
		return nil;
	}

	if((fd = create(file, ORDWR, 0666)) < 0)
		return nil;

	cd = emalloc(sizeof *cd);
	cd->file = atom(file);

	Binit(&cd->brd, fd, OREAD);

	if((xfd = open(file, ORDWR)) < 0)
		sysfatal("can't open file again: %r");
	Binit(&cd->bwr, xfd, OWRITE);

	Crepeat(cd, 0, 16*Blocksize);
	Cputisopvd(cd, info);
	if(info.flags & CDbootable){
		cd->bootimage = info.bootimage;
		cd->flags |= CDbootable;
		Cputbootvol(cd);
	}

	if(readisodesc(cd, &cd->iso) < 0)
		assert(0);
	if(info.flags & CDplan9)
		cd->flags |= CDplan9;
	else if(info.flags & CDrockridge)
		cd->flags |= CDrockridge;
	if(info.flags & CDjoliet) {
		Cputjolietsvd(cd, info);
		if(readjolietdesc(cd, &cd->joliet) < 0)
			assert(0);
		cd->flags |= CDjoliet;
	}
	Cputendvd(cd);

	if(info.flags & CDdump){
		cd->nulldump = Cputdumpblock(cd);
		cd->flags |= CDdump;
	}
	if(cd->flags & CDbootable){
		Cputbootcat(cd);
		Cupdatebootvol(cd);
	}

	if(info.flags & CDconform)
		cd->flags |= CDconform;

	cd->flags |= CDnew;
	cd->nextblock = Cwoffset(cd) / Blocksize;
	assert(cd->nextblock != 0);

	return cd;
}
示例#15
0
void
main(int argc, char *argv[])
{
	int c;
	char *p, *name, *val;

	Binit(&bso, 1, OWRITE);
	listinit();
	nerrors = 0;
	outfile = "5.out";
	HEADTYPE = -1;
	INITTEXT = -1;
	INITDAT = -1;
	INITRND = -1;
	INITENTRY = 0;
	nuxiinit();
	
	p = getenv("GOARM");
	if(p != nil && strcmp(p, "5") == 0)
		debug['F'] = 1;

	ARGBEGIN {
	default:
		c = ARGC();
		if(c == 'l')
			usage();
 		if(c >= 0 && c < sizeof(debug))
			debug[c]++;
		break;
	case 'o':
		outfile = EARGF(usage());
		break;
	case 'E':
		INITENTRY = EARGF(usage());
		break;
	case 'I':
		debug['I'] = 1; // denote cmdline interpreter override
		interpreter = EARGF(usage());
		break;
	case 'L':
		Lflag(EARGF(usage()));
		break;
	case 'T':
		INITTEXT = atolwhex(EARGF(usage()));
		break;
	case 'D':
		INITDAT = atolwhex(EARGF(usage()));
		break;
	case 'R':
		INITRND = atolwhex(EARGF(usage()));
		break;
	case 'r':
		rpath = EARGF(usage());
		break;
	case 'H':
		HEADTYPE = headtype(EARGF(usage()));
		/* do something about setting INITTEXT */
		break;
	case 'V':
		print("%cl version %s\n", thechar, getgoversion());
		errorexit();
	case 'X':
		name = EARGF(usage());
		val = EARGF(usage());
		addstrdata(name, val);
		break;
	} ARGEND

	USED(argc);

	if(argc != 1)
		usage();

	libinit();

	if(HEADTYPE == -1)
		HEADTYPE = Hlinux;
	switch(HEADTYPE) {
	default:
		diag("unknown -H option");
		errorexit();
	case Hnoheader:	/* no header */
		HEADR = 0L;
		if(INITTEXT == -1)
			INITTEXT = 0;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	case Hrisc:	/* aif for risc os */
		HEADR = 128L;
		if(INITTEXT == -1)
			INITTEXT = 0x10005000 + HEADR;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	case Hplan9x32:	/* plan 9 */
		HEADR = 32L;
		if(INITTEXT == -1)
			INITTEXT = 4128;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	case Hnetbsd:	/* boot for NetBSD */
		HEADR = 32L;
		if(INITTEXT == -1)
			INITTEXT = 0xF0000020L;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	case Hixp1200: /* boot for IXP1200 */
		HEADR = 0L;
		if(INITTEXT == -1)
			INITTEXT = 0x0;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	case Hipaq: /* boot for ipaq */
		HEADR = 16L;
		if(INITTEXT == -1)
			INITTEXT = 0xC0008010;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 1024;
		break;
	case Hlinux:	/* arm elf */
		debug['d'] = 0;	// with dynamic linking
		tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m
		                // this number is known to ../../pkg/runtime/cgo/gcc_linux_arm.c
		elfinit();
		HEADR = ELFRESERVE;
		if(INITTEXT == -1)
			INITTEXT = 0x10000 + HEADR;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	}
	if(INITDAT != 0 && INITRND != 0)
		print("warning: -D0x%ux is ignored because of -R0x%ux\n",
			INITDAT, INITRND);
	if(debug['v'])
		Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n",
			HEADTYPE, INITTEXT, INITDAT, INITRND);
	Bflush(&bso);
	zprg.as = AGOK;
	zprg.scond = 14;
	zprg.reg = NREG;
	zprg.from.name = D_NONE;
	zprg.from.type = D_NONE;
	zprg.from.reg = NREG;
	zprg.to = zprg.from;
	buildop();
	histgen = 0;
	pc = 0;
	dtype = 4;

	version = 0;
	cbp = buf.cbuf;
	cbc = sizeof(buf.cbuf);

	addlibpath("command line", "command line", argv[0], "main");
	loadlib();

	// mark some functions that are only referenced after linker code editing
	if(debug['F'])
		mark(rlookup("_sfloat", 0));
	deadcode();
	if(textp == nil) {
		diag("no code");
		errorexit();
	}

	patch();
	if(debug['p'])
		if(debug['1'])
			doprof1();
		else
			doprof2();
	doelf();
	follow();
	softfloat();
	noops();
	dostkcheck();
	span();
	addexport();
	// textaddress() functionality is handled in span()
	pclntab();
	symtab();
	dodata();
	address();
	doweak();
	reloc();
	asmb();
	undef();

	if(debug['c'])
		print("ARM size = %d\n", armsize);
	if(debug['v']) {
		Bprint(&bso, "%5.2f cpu time\n", cputime());
		Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
		Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
	}
	Bflush(&bso);
	errorexit();
}
示例#16
0
文件: drawp.c 项目: kahrs/cda
void
main(int argc, char **argv)
{
    char *fname;
    int n;

    Binit(&out, 1, OWRITE);
    ARGBEGIN{
    case 'b':
        boxed = 1;
        break;
    case 'c':
        docpins = 1;
        break;
    case 'd':
        dodatums = 1;
        break;
    case 'H':
        noheader = 1;
        break;
    case 'k':
        chname = 1;
        break;	/* package */
    case 'l':
        landscape = 1;
        break;
    case 'p':
        dopts = 1;
        break;
    case 'r':
        nortext = 1;
        break;
    case 't':
        chname = -1;
        break;	/* type */
    case 'v':
        dovb = 1;
        break;
    case 'h':
        hfile = ARGF();		/* icon-style hole file */
        break;
    case 'w':
        wfile = ARGF();		/* icon-style wire file */
        break;
    default:
        fprint(2, "usage: %s [-cdHklprtv] [-h file] [-w file] [files...]\n", argv0);
        exits("usage");
    } ARGEND
    USED(argc);
    if(wfile || hfile)
        dodatums = 1;
    if(wfile && !hfile)
        docpins = 1;
    fizzinit();
    f_init(&b);
    if(*argv)
        fname = *argv++;
    else
        fname = "/fd/0";
    do {
        if(n = f_crack(fname, &b)) {
            fprint(2, "%s: %d errors\n", fname, n);
            exits("crack");
        }
    } while(fname = *argv++);	/* assign = */
    fizzplane(&b);
    if(n = fizzplace()) {
        fprint(2, "warning: %d chip%s unplaced\n",
               n, n==1?"":"s");
    }
    if(fizzprewrap())
        exits("prewrap");
    draw(dopts, dovb);
    exits(0);
}
示例#17
0
文件: gs.c 项目: 99years/plan9
int 
spawngs(GSInfo *g, char *safer)
{
	char *args[16];
	char tb[32], gb[32];
	int i, nargs;
	int devnull;
	int stdinout[2];
	int dataout[2];
	int errout[2];

	/*
	 * spawn gs
	 *
 	 * gs's standard input is fed from stdinout.
	 * gs output written to fd-2 (i.e. output we generate intentionally) is fed to stdinout.
	 * gs output written to fd 1 (i.e. ouptut gs generates on error) is fed to errout.
	 * gs data output is written to fd 3, which is dataout.
	 */
	if(pipe(stdinout) < 0 || pipe(dataout)<0 || pipe(errout)<0)
		return -1;

	nargs = 0;
	args[nargs++] = "gs";
	args[nargs++] = "-dNOPAUSE";
	args[nargs++] = safer;
	args[nargs++] = "-sDEVICE=plan9";
	args[nargs++] = "-sOutputFile=/fd/3";
	args[nargs++] = "-dQUIET";
	args[nargs++] = "-r100";
	sprint(tb, "-dTextAlphaBits=%d", textbits);
	sprint(gb, "-dGraphicsAlphaBits=%d", gfxbits);
	if(textbits)
		args[nargs++] = tb;
	if(gfxbits)
		args[nargs++] = gb;
	args[nargs++] = "-";
	args[nargs] = nil;

	gspid = fork();
	if(gspid == 0) {
		close(stdinout[1]);
		close(dataout[1]);
		close(errout[1]);

		/*
		 * Horrible problem: we want to dup fd's 0-4 below,
		 * but some of the source fd's might have those small numbers.
		 * So we need to reallocate those.  In order to not step on
		 * anything else, we'll dup the fd's to higher ones using
		 * dup(x, -1), but we need to use up the lower ones first.
		 */
		while((devnull = open("/dev/null", ORDWR)) < 5)
			;

		stdinout[0] = dup(stdinout[0], -1);
		errout[0] = dup(errout[0], -1);
		dataout[0] = dup(dataout[0], -1);

		dup(stdinout[0], 0);
		dup(errout[0], 1);
		dup(devnull, 2);	/* never anything useful */
		dup(dataout[0], 3);
		dup(stdinout[0], 4);
		for(i=5; i<20; i++)
			close(i);
		exec("/bin/gs", args);
		wexits("exec");
	}
	close(stdinout[0]);
	close(errout[0]);
	close(dataout[0]);
	atexit(killgs);

	if(teegs)
		stdinout[1] = spawnreader(stdinout[1]);

	gsfd = g->gsfd = stdinout[1];
	g->gsdfd = dataout[1];
	g->gspid = gspid;

	spawnmonitor(errout[1]);
	Binit(&g->gsrd, g->gsfd, OREAD);

	gscmd(g, "/PAGEOUT (/fd/4) (w) file def\n");
	gscmd(g, "/PAGE== { PAGEOUT exch write==only PAGEOUT (\\n) writestring PAGEOUT flushfile } def\n");
	waitgs(g);

	return 0;
}
示例#18
0
文件: cdrdwr.c 项目: 00001/plan9port
Cdimg*
opencd(char *file, Cdinfo info)
{
	int fd, xfd;
	Cdimg *cd;
	Dir *d;

	if((fd = open(file, ORDWR)) < 0) {
		if(access(file, AEXIST) == 0)
			return nil;
		return createcd(file, info);
	}

	if((d = dirfstat(fd)) == nil) {
		close(fd);
		return nil;
	}
	if(d->length == 0 || d->length % Blocksize) {
		werrstr("bad length %lld", d->length);
		close(fd);
		free(d);
		return nil;
	}

	cd = emalloc(sizeof *cd);
	cd->file = atom(file);
	cd->nextblock = d->length / Blocksize;
	assert(cd->nextblock != 0);
	free(d);

	Binit(&cd->brd, fd, OREAD);

	if((xfd = open(file, ORDWR)) < 0)
		sysfatal("can't open file again: %r");
	Binit(&cd->bwr, xfd, OWRITE);

	if(readisodesc(cd, &cd->iso) < 0) {
		free(cd);
		close(fd);
		close(xfd);
		return nil;
	}

	/* lowercase because of isostring */
	if(strstr(cd->iso.systemid, "iso9660") == nil 
	&& strstr(cd->iso.systemid, "utf8") == nil) {
		werrstr("unknown systemid %s", cd->iso.systemid);
		free(cd);
		close(fd);
		close(xfd);
		return nil;
	}
	
	if(strstr(cd->iso.systemid, "plan 9"))
		cd->flags |= CDplan9;
	if(strstr(cd->iso.systemid, "iso9660"))
		cd->flags |= CDconform;
	if(strstr(cd->iso.systemid, "rrip"))
		cd->flags |= CDrockridge;
	if(strstr(cd->iso.systemid, "boot"))
		cd->flags |= CDbootable;
	if(readjolietdesc(cd, &cd->joliet) == 0)
		cd->flags |= CDjoliet;
	if(hasdump(cd))
		cd->flags |= CDdump;

	return cd;
}
示例#19
0
文件: scanmail.c 项目: npe9/harvey
void
main(int argc, char *argv[])
{
    int i, n, nolines, optout;
    char **args, **a, *cp, *buf;
    char body[Bodysize+2];
    Resub match[1];
    Biobuf *bp;

    optout = 1;
    a = args = Malloc((argc+1)*sizeof(char*));
    sprint(patfile, "%s/patterns", UPASLIB);
    sprint(linefile, "%s/lines", UPASLOG);
    sprint(holdqueue, "%s/queue.hold", SPOOL);
    sprint(copydir, "%s/copy", SPOOL);

    *a++ = argv[0];
    for(argc--, argv++; argv[0] && argv[0][0] == '-'; argc--, argv++) {
        switch(argv[0][1]) {
        case 'c':			/* save copy of message */
            cflag = 1;
            break;
        case 'd':			/* debug */
            debug++;
            *a++ = argv[0];
            break;
        case 'h':			/* queue held messages by sender domain */
            hflag = 1;		/* -q flag must be set also */
            break;
        case 'n':			/* NOHOLD mode */
            nflag = 1;
            break;
        case 'p':			/* pattern file */
            if(argv[0][2] || argv[1] == 0)
                usage();
            argc--;
            argv++;
            strecpy(patfile, patfile+sizeof patfile, *argv);
            break;
        case 'q':			/* queue name */
            if(argv[0][2] ||  argv[1] == 0)
                usage();
            *a++ = argv[0];
            argc--;
            argv++;
            qname = a;
            *a++ = argv[0];
            break;
        case 's':			/* save copy of dumped message */
            sflag = 1;
            break;
        case 't':			/* test mode - don't log match
						 * and write message to /dev/null
						 */
            tflag = 1;
            break;
        case 'v':			/* vebose - print matches */
            vflag = 1;
            break;
        default:
            *a++ = argv[0];
            break;
        }
    }

    if(argc < 3)
        usage();

    Binit(&bin, 0, OREAD);
    bp = Bopen(patfile, OREAD);
    if(bp) {
        parsepats(bp);
        Bterm(bp);
    }
    qdir = a;
    sender = argv[2];

    /* copy the rest of argv, acummulating the recipients as we go */
    for(i = 0; argv[i]; i++) {
        *a++ = argv[i];
        if(i < 4)	/* skip queue, 'mail', sender, dest sys */
            continue;
        /* recipients and smtp flags - skip the latter*/
        if(strcmp(argv[i], "-g") == 0) {
            *a++ = argv[++i];
            continue;
        }
        if(recips)
            s_append(recips, ", ");
        else
            recips = s_new();
        s_append(recips, argv[i]);
        if(optout && !optoutofspamfilter(argv[i]))
            optout = 0;
    }
    *a = 0;
    /* construct a command string for matching */
    snprint(cmd, sizeof(cmd)-1, "%s %s", sender, s_to_c(recips));
    cmd[sizeof(cmd)-1] = 0;
    for(cp = cmd; *cp; cp++)
        *cp = tolower(*cp);

    /* canonicalize a copy of the header and body.
     * buf points to orginal message and n contains
     * number of bytes of original message read during
     * canonicalization.
     */
    *body = 0;
    *header = 0;
    buf = canon(&bin, header+1, body+1, &n);
    if (buf == 0)
        exits("read");

    /* if all users opt out, don't try matches */
    if(optout) {
        if(cflag)
            cout = opencopy(sender);
        exits(qmail(args, buf, n, cout));
    }

    /* Turn off line logging, if command line matches */
    nolines = matchaction(Lineoff, cmd, match);

    for(i = 0; patterns[i].action; i++) {
        /* Lineoff patterns were already done above */
        if(i == Lineoff)
            continue;
        /* don't apply "Line" patterns if excluded above */
        if(nolines && i == SaveLine)
            continue;
        /* apply patterns to the sender/recips, header and body */
        if(matchaction(i, cmd, match))
            break;
        if(matchaction(i, header+1, match))
            break;
        if(i == HoldHeader)
            continue;
        if(matchaction(i, body+1, match))
            break;
    }
    if(cflag && patterns[i].action == 0)	/* no match found - save msg */
        cout = opencopy(sender);

    exits(qmail(args, buf, n, cout));
}
示例#20
0
文件: obj.c 项目: JamesLinus/inferno
void
main(int argc, char *argv[])
{
	int c;
	char *a;
	char name[LIBNAMELEN];

	Binit(&bso, 1, OWRITE);
	cout = -1;
	listinit();
	outfile = 0;
	nerrors = 0;
	curtext = P;
	HEADTYPE = -1;
	INITTEXT = -1;
	INITTEXTP = -1;
	INITDAT = -1;
	INITRND = -1;
	INITENTRY = 0;

	ARGBEGIN {
	default:
		c = ARGC();
		if(c >= 0 && c < sizeof(debug))
			debug[c]++;
		break;
	case 'o':
		outfile = ARGF();
		break;
	case 'E':
		a = ARGF();
		if(a)
			INITENTRY = a;
		break;
	case 'L':
		addlibpath(EARGF(usage()));
		break;
	case 'T':
		a = ARGF();
		if(a)
			INITTEXT = atolwhex(a);
		break;
	case 'P':
		a = ARGF();
		if(a)
			INITTEXTP = atolwhex(a);
		break;
	case 'D':
		a = ARGF();
		if(a)
			INITDAT = atolwhex(a);
		break;
	case 'R':
		a = ARGF();
		if(a)
			INITRND = atolwhex(a);
		break;
	case 'H':
		a = ARGF();
		if(a)
			HEADTYPE = atolwhex(a);
		/* do something about setting INITTEXT */
		break;
	case 'x':	/* produce export table */
		doexp = 1;
		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
			readundefs(ARGF(), SEXPORT);
		break;
	case 'u':	/* produce dynamically loadable module */
		dlm = 1;
		if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
			readundefs(ARGF(), SIMPORT);
		break;
	} ARGEND

	USED(argc);

	if(*argv == 0)
		usage();
	if(!debug['9'] && !debug['U'] && !debug['B'])
		debug[DEFAULT] = 1;
	a = getenv("ccroot");
	if(a != nil && *a != '\0') {
		if(!fileexists(a)) {
			diag("nonexistent $ccroot: %s", a);
			errorexit();
		}
	}else
		a = "";
	snprint(name, sizeof(name), "%s/%s/lib", a, thestring);
	addlibpath(name);
	if(HEADTYPE == -1) {
		if(debug['U'])
			HEADTYPE = 0;
		if(debug['B'])
			HEADTYPE = 1;
		if(debug['9'])
			HEADTYPE = 2;
	}
	switch(HEADTYPE) {
	default:
		diag("unknown -H option");
		errorexit();
	case 0:	/* no header */
	case 6:	/* no header, padded segments */
		HEADR = 0L;
		if(INITTEXT == -1)
			INITTEXT = 0;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	case 1:	/* aif for risc os */
		HEADR = 128L;
		if(INITTEXT == -1)
			INITTEXT = 0x10005000 + HEADR;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	case 2:	/* plan 9 */
		HEADR = 32L;
		if(INITTEXT == -1)
			INITTEXT = 4128;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	case 3:	/* boot for NetBSD */
		HEADR = 32L;
		if(INITTEXT == -1)
			INITTEXT = 0xF0000020L;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	case 4: /* boot for IXP1200 */
		HEADR = 0L;
		if(INITTEXT == -1)
			INITTEXT = 0x0;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	case 5: /* boot for ipaq */
		HEADR = 16L;
		if(INITTEXT == -1)
			INITTEXT = 0xC0008010;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 1024;
		break;
	case 7:	/* elf executable */
		HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16);
		if(INITTEXT == -1)
			INITTEXT = 4096+HEADR;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	}
	if (INITTEXTP == -1)
		INITTEXTP = INITTEXT;
	if(INITDAT != 0 && INITRND != 0)
		print("warning: -D0x%lux is ignored because of -R0x%lux\n",
			INITDAT, INITRND);
	if(debug['v'])
		Bprint(&bso, "HEADER = -H0x%d -T0x%lux -D0x%lux -R0x%lux\n",
			HEADTYPE, INITTEXT, INITDAT, INITRND);
	Bflush(&bso);
	zprg.as = AGOK;
	zprg.scond = 14;
	zprg.reg = NREG;
	zprg.from.name = D_NONE;
	zprg.from.type = D_NONE;
	zprg.from.reg = NREG;
	zprg.to = zprg.from;
	buildop();
	histgen = 0;
	textp = P;
	datap = P;
	pc = 0;
	dtype = 4;
	if(outfile == 0)
		outfile = "5.out";
	cout = create(outfile, 1, 0775);
	if(cout < 0) {
		diag("cannot create %s: %r", outfile);
		errorexit();
	}
	nuxiinit();

	version = 0;
	cbp = buf.cbuf;
	cbc = sizeof(buf.cbuf);
	firstp = prg();
	lastp = firstp;

	if(INITENTRY == 0) {
		INITENTRY = "_main";
		if(debug['p'])
			INITENTRY = "_mainp";
		if(!debug['l'])
			lookup(INITENTRY, 0)->type = SXREF;
	} else if(!(*INITENTRY >= '0' && *INITENTRY <= '9'))
		lookup(INITENTRY, 0)->type = SXREF;

	while(*argv)
		objfile(*argv++);
	if(!debug['l'])
		loadlib();
	firstp = firstp->link;
	if(firstp == P)
		goto out;
	if(doexp || dlm){
		EXPTAB = "_exporttab";
		zerosig(EXPTAB);
		zerosig("etext");
		zerosig("edata");
		zerosig("end");
		if(dlm){
			initdiv();
			import();
			HEADTYPE = 2;
			INITTEXT = INITDAT = 0;
			INITRND = 8;
			INITENTRY = EXPTAB;
		}
		else
			divsig();
		export();
示例#21
0
文件: split.c 项目: 99years/plan9
void
main(int argc, char *argv[])
{
	Reprog *exp;
	char *pattern = 0;
	int n = 1000;
	char *line;
	int xflag = 0;
	int iflag = 0;
	Biobuf bin;
	Biobuf *b = &bin;
	char buf[256];

	ARGBEGIN {
	case 'l':
	case 'n':
		n=atoi(EARGF(usage()));
		break;
	case 'e':
		pattern = strdup(EARGF(usage()));
		break;
	case 'f':
		stem = strdup(EARGF(usage()));
		break;
	case 's':
		suffix = strdup(EARGF(usage()));
		break;
	case 'x':
		xflag++;
		break;
	case 'i':
		iflag++;
		break;
	default:
		usage();
		break;

	} ARGEND;

	if(argc < 0 || argc > 1)
		usage();

	if(argc != 0) {
		b = Bopen(argv[0], OREAD);
		if(b == nil) {
			fprint(2, "split: can't open %s: %r\n", argv[0]);
			exits("open");
		}
	} else
		Binit(b, 0, OREAD);

	if(pattern) {
		Resub match[2];

		if(!(exp = regcomp(iflag? fold(pattern, strlen(pattern)):
		    pattern)))
			badexp();
		memset(match, 0, sizeof match);
		matchfile(match);
		while((line=Brdline(b,'\n')) != 0) {
			memset(match, 0, sizeof match);
			line[Blinelen(b)-1] = 0;
			if(regexec(exp, iflag? fold(line, Blinelen(b)-1): line,
			    match, 2)) {
				if(matchfile(match) && xflag)
					continue;
			} else if(output == 0)
				nextfile();	/* at most once */
			Bwrite(output, line, Blinelen(b)-1);
			Bputc(output, '\n');
		}
	} else {
		int linecnt = n;

		while((line=Brdline(b,'\n')) != 0) {
			if(++linecnt > n) {
				nextfile();
				linecnt = 1;
			}
			Bwrite(output, line, Blinelen(b));
		}

		/*
		 * in case we didn't end with a newline, tack whatever's 
		 * left onto the last file
		 */
		while((n = Bread(b, buf, sizeof(buf))) > 0)
			Bwrite(output, buf, n);
	}
	if(b != nil)
		Bterm(b);
	exits(0);
}
示例#22
0
文件: netstat.c 项目: bhanug/harvey
void
main(int argc, char *argv[])
{
	int justinterfaces = 0;
	int i, tot, fd;
	Dir *d;
	char buf[128];

	ARGBEGIN{
	case 'i':
		justinterfaces = 1;
		break;
	case 'n':
		notrans = 1;
		break;
	case 'p':
		if(nproto >= nelem(proto))
			sysfatal("too many protos");
		proto[nproto++] = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND;

	netroot = "/net";
	switch(argc){
	case 0:
		break;
	case 1:
		netroot = argv[0];
		break;
	default:
		usage();
	}

	Binit(&out, 1, OWRITE);

	if(justinterfaces){
		pipifc();
		exits(0);
	}

	if(nproto){
		for(i=0; i<nproto; i++)
			nstat(proto[i], pip);
	}else{
		fd = open(netroot, OREAD);
		if(fd < 0)
			sysfatal("open %s: %r", netroot);

		tot = dirreadall(fd, &d);
		for(i=0; i<tot; i++){
			if(strcmp(d[i].name, "ipifc") == 0)
				continue;
			snprint(buf, sizeof buf, "%s/%s/0/local", netroot, d[i].name);
			if(access(buf, 0) >= 0)
				nstat(d[i].name, pip);
		}
	}
	exits(0);
}
示例#23
0
文件: ar.c 项目: tusharsoni/Inferno
void
main(int argc, char *argv[])
{
    char *cp;

    Binit(&bout, 1, OWRITE);
    if(argc < 3)
        usage();
    for (cp = argv[1]; *cp; cp++) {
        switch(*cp) {
        case 'a':
            aflag = 1;
            break;
        case 'b':
            bflag = 1;
            break;
        case 'c':
            cflag = 1;
            break;
        case 'd':
            setcom(dcmd);
            break;
        case 'i':
            bflag = 1;
            break;
        case 'l':
            strcpy(artemp, "vXXXXX");
            strcpy(movtemp, "v1XXXXX");
            strcpy(tailtemp, "v2XXXXX");
            break;
        case 'm':
            setcom(mcmd);
            break;
        case 'o':
            oflag = 1;
            break;
        case 'p':
            setcom(pcmd);
            break;
        case 'q':
            setcom(qcmd);
            break;
        case 'r':
            setcom(arcmd);
            break;
        case 't':
            setcom(tcmd);
            break;
        case 'u':
            uflag = 1;
            break;
        case 'v':
            vflag = 1;
            break;
        case 'x':
            setcom(xcmd);
            break;
        default:
            fprint(2, "ar: bad option `%c'\n", *cp);
            exits("error");
        }
    }
    if (aflag && bflag) {
        fprint(2, "ar: only one of 'a' and 'b' can be specified\n");
        usage();
    }
    if(aflag || bflag) {
        trim(argv[2], poname, sizeof(poname));
        argv++;
        argc--;
        if(argc < 3)
            usage();
    }
    if(comfun == 0) {
        if(uflag == 0) {
            fprint(2, "ar: one of [%s] must be specified\n", man);
            usage();
        }
        setcom(arcmd);
    }
    cp = argv[2];
    argc -= 3;
    argv += 3;
    (*comfun)(cp, argc, argv);	/* do the command */
    cp = 0;
    while (argc--) {
        if (*argv) {
            fprint(2, "ar: %s not found\n", *argv);
            cp = "error";
        }
        argv++;
    }
    if(allobj && dupfound)
        exits("dup found");
    exits(cp);
}
示例#24
0
文件: smtpd.c 项目: 99years/plan9
void
main(int argc, char **argv)
{
	char *netdir;
	char buf[1024];

	netdir = nil;
	quotefmtinstall();
	fmtinstall('I', eipfmt);
	starttime = time(0);
	ARGBEGIN{
	case 'a':
		authenticate = 1;
		break;
	case 'c':
		tlscert = EARGF(usage());
		break;
	case 'D':
		Dflag++;
		break;
	case 'd':
		debug++;
		break;
	case 'f':				/* disallow relaying */
		fflag = 1;
		break;
	case 'g':
		gflag = 1;
		break;
	case 'h':				/* default domain name */
		dom = EARGF(usage());
		break;
	case 'k':				/* prohibited ip address */
		addbadguy(EARGF(usage()));
		break;
	case 'm':				/* set mail command */
		mailer = mailerpath(EARGF(usage()));
		break;
	case 'n':				/* log peer ip address */
		netdir = EARGF(usage());
		break;
	case 'p':
		passwordinclear = 1;
		break;
	case 'r':
		rflag = 1;			/* verify sender's domain */
		break;
	case 's':				/* save blocked messages */
		sflag = 1;
		break;
	case 't':
		fprint(2, "%s: the -t option is no longer supported, see -c\n",
			argv0);
		tlscert = "/sys/lib/ssl/smtpd-cert.pem";
		break;
	default:
		usage();
	}ARGEND;

	nci = getnetconninfo(netdir, 0);
	if(nci == nil)
		sysfatal("can't get remote system's address: %r");
	parseip(rsysip, nci->rsys);

	if(mailer == nil)
		mailer = mailerpath("send");

	if(debug){
		snprint(buf, sizeof buf, "%s/smtpdb/%ld", UPASLOG, time(0));
		close(2);
		if (create(buf, OWRITE | OEXCL, 0662) >= 0) {
			seek(2, 0, 2);
			fprint(2, "%d smtpd %s\n", getpid(), thedate());
		} else
			debug = 0;
	}
	getconf();
	if (isbadguy())
		exits("banned");
	Binit(&bin, 0, OREAD);

	if (chdir(UPASLOG) < 0)
		syslog(0, "smtpd", "no %s: %r", UPASLOG);
	me = sysname_read();
	if(dom == 0 || dom[0] == 0)
		dom = domainname_read();
	if(dom == 0 || dom[0] == 0)
		dom = me;
	parseinit();
	sayhi();

	/* allow 45 minutes to parse the header */
	atnotify(catchalarm, 1);
	alarm(45*60*1000);
	zzparse();
	exits(0);
}
示例#25
0
文件: ed.c 项目: 00001/plan9port
void
commands(void)
{
	int *a1, c, temp;
	char lastsep;
	Dir *d;

	for(;;) {
		if(pflag) {
			pflag = 0;
			addr1 = addr2 = dot;
			printcom();
		}
		c = '\n';
		for(addr1 = 0;;) {
			lastsep = c;
			a1 = address();
			c = getchr();
			if(c != ',' && c != ';')
				break;
			if(lastsep == ',')
				error(Q);
			if(a1 == 0) {
				a1 = zero+1;
				if(a1 > dol)
					a1--;
			}
			addr1 = a1;
			if(c == ';')
				dot = a1;
		}
		if(lastsep != '\n' && a1 == 0)
			a1 = dol;
		if((addr2=a1) == 0) {
			given = 0;
			addr2 = dot;	
		} else
			given = 1;
		if(addr1 == 0)
			addr1 = addr2;
		switch(c) {

		case 'a':
			add(0);
			continue;

		case 'b':
			nonzero();
			browse();
			continue;

		case 'c':
			nonzero();
			newline();
			rdelete(addr1, addr2);
			append(gettty, addr1-1);
			continue;

		case 'd':
			nonzero();
			newline();
			rdelete(addr1, addr2);
			continue;

		case 'E':
			fchange = 0;
			c = 'e';
		case 'e':
			setnoaddr();
			if(vflag && fchange) {
				fchange = 0;
				error(Q);
			}
			filename(c);
			init();
			addr2 = zero;
			goto caseread;

		case 'f':
			setnoaddr();
			filename(c);
			putst(savedfile);
			continue;

		case 'g':
			global(1);
			continue;

		case 'i':
			add(-1);
			continue;


		case 'j':
			if(!given)
				addr2++;
			newline();
			join();
			continue;

		case 'k':
			nonzero();
			c = getchr();
			if(c < 'a' || c > 'z')
				error(Q);
			newline();
			names[c-'a'] = *addr2 & ~01;
			anymarks |= 01;
			continue;

		case 'm':
			move(0);
			continue;

		case 'n':
			listn++;
			newline();
			printcom();
			continue;

		case '\n':
			if(a1==0) {
				a1 = dot+1;
				addr2 = a1;
				addr1 = a1;
			}
			if(lastsep==';')
				addr1 = a1;
			printcom();
			continue;

		case 'l':
			listf++;
		case 'p':
		case 'P':
			newline();
			printcom();
			continue;

		case 'Q':
			fchange = 0;
		case 'q':
			setnoaddr();
			newline();
			quit();

		case 'r':
			filename(c);
		caseread:
			if((io=open(file, OREAD)) < 0) {
				lastc = '\n';
				error(file);
			}
			if((d = dirfstat(io)) != nil){
				if(d->mode & DMAPPEND)
					print("warning: %s is append only\n", file);
				free(d);
			}
			Binit(&iobuf, io, OREAD);
			setwide();
			squeeze(0);
			c = zero != dol;
			append(getfile, addr2);
			exfile(OREAD);

			fchange = c;
			continue;

		case 's':
			nonzero();
			substitute(globp != 0);
			continue;

		case 't':
			move(1);
			continue;

		case 'u':
			nonzero();
			newline();
			if((*addr2&~01) != subnewa)
				error(Q);
			*addr2 = subolda;
			dot = addr2;
			continue;

		case 'v':
			global(0);
			continue;

		case 'W':
			wrapp++;
		case 'w':
			setwide();
			squeeze(dol>zero);
			temp = getchr();
			if(temp != 'q' && temp != 'Q') {
				peekc = temp;
				temp = 0;
			}
			filename(c);
			if(!wrapp ||
			  ((io = open(file, OWRITE)) == -1) ||
			  ((seek(io, 0L, 2)) == -1))
				if((io = create(file, OWRITE, 0666)) < 0)
					error(file);
			Binit(&iobuf, io, OWRITE);
			wrapp = 0;
			if(dol > zero)
				putfile();
			exfile(OWRITE);
			if(addr1<=zero+1 && addr2==dol)
				fchange = 0;
			if(temp == 'Q')
				fchange = 0;
			if(temp)
				quit();
			continue;

		case '=':
			setwide();
			squeeze(0);
			newline();
			count = addr2 - zero;
			putd();
			putchr('\n');
			continue;

		case '!':
			callunix();
			continue;

		case EOF:
			return;

		}
		error(Q);
	}
}
示例#26
0
文件: proto.c 项目: 99years/plan9
/*
 *  call out for a data connection
 */
static int
passive(int mode, Biobuf **bpp, char *cmda, char *cmdb)
{
	char msg[1024];
	char ds[1024];
	char *f[6];
	char *p;
	int x, fd;
	TLSconn conn;

	if(nopassive)
		return Impossible;

	sendrequest("PASV", nil);
	if(getreply(&ctlin, msg, sizeof(msg), 0) != Success){
		nopassive = 1;
		return Impossible;
	}

	/* get address and port number from reply, this is AI */
	p = strchr(msg, '(');
	if(p == 0){
		for(p = msg+3; *p; p++)
			if(isdigit(*p))
				break;
	} else
		p++;
	if(getfields(p, f, 6, 0, ",") < 6){
		if(debug)
			fprint(2, "passive mode protocol botch: %s\n", msg);
		werrstr("ftp protocol botch");
		nopassive = 1;
		return Impossible;
	}
	snprint(ds, sizeof(ds), "%s!%s.%s.%s.%s!%d", net,
		f[0], f[1], f[2], f[3],
		((atoi(f[4])&0xff)<<8) + (atoi(f[5])&0xff));

	/* open data connection */
	fd = dial(ds, 0, 0, 0);
	if(fd < 0){
		if(debug)
			fprint(2, "passive mode connect to %s failed: %r\n", ds);
		nopassive = 1;
		return TempFail;
	}

	/* tell remote to send a file */
	sendrequest(cmda, cmdb);
	x = getreply(&ctlin, msg, sizeof(msg), 0);
	if(x != Extra){
		close(fd);
		if(debug)
			fprint(2, "passive mode retrieve failed: %s\n", msg);
		werrstr(msg);
		return x;
	}

	if(usetls){
		memset(&conn, 0, sizeof(conn));
		fd = tlsClient(fd, &conn);
		if(fd < 0)
			fatal("starting tls: %r");
		free(conn.cert);
	}
	Binit(&dbuf, fd, mode);

	*bpp = &dbuf;
	return Extra;
}
示例#27
0
文件: lex.c 项目: AustenConrad/plan-9
int
assemble(char *file)
{
	char ofile[100], incfile[20], *p;
	int i, of;

	strcpy(ofile, file);
	p = utfrrune(ofile, pathchar());
	if(p) {
		include[0] = ofile;
		*p++ = 0;
	} else
		p = ofile;
	if(outfile == 0) {
		outfile = p;
		if(outfile){
			p = utfrrune(outfile, '.');
			if(p)
				if(p[1] == 's' && p[2] == 0)
					p[0] = 0;
			p = utfrune(outfile, 0);
			p[0] = '.';
			p[1] = thechar;
			p[2] = 0;
		} else
			outfile = "/dev/null";
	}
	p = getenv("INCLUDE");
	if(p) {
		setinclude(p);
	} else {
		if(systemtype(Plan9)) {
			sprint(incfile,"/%s/include", thestring);
			setinclude(strdup(incfile));
		}
	}

	of = mycreat(outfile, 0664);
	if(of < 0) {
		yyerror("%ca: cannot create %s", thechar, outfile);
		errorexit();
	}
	Binit(&obuf, of, OWRITE);

	pass = 1;
	pinit(file);
	for(i=0; i<nDlist; i++)
		dodefine(Dlist[i]);
	yyparse();
	if(nerrors) {
		cclean();
		return nerrors;
	}

	pass = 2;
	outhist();
	pinit(file);
	for(i=0; i<nDlist; i++)
		dodefine(Dlist[i]);
	yyparse();
	cclean();
	return nerrors;
}
示例#28
0
文件: pslib.c 项目: 99years/plan9
int
image2psfile(int fd, Memimage *im, int dpi) {
	Rectangle r;
	Rectangle bbox;
	int e;
	int xmargin = 36;
	int ymargin = 36;
	double paperaspectratio;
	double imageaspectratio;
	Biobuf ioutb;
	Memimage *tmp;

	if(im->depth >= 8 && im->chan != CMAP8 && im->chan != GREY8){
		/*
		 * the postscript libraries can only handle [1248]-bit grey, 8-bit cmap,
		 * and 24-bit color, so convert.
		 */
		tmp = allocmemimage(im->r, strtochan("b8g8r8"));
		if(tmp == nil)
			return 1;
		memimagedraw(tmp, tmp->r, im, im->r.min, nil, ZP, S);
		freememimage(im);
		im = tmp;
	}

	Binit(&ioutb, fd, OWRITE);
 	r = im->r;
	width = Dx(r);
	height = Dy(r);
	imageaspectratio = (double) width / (double) height;
	if (landscape) {
		paperaspectratio = ((double)paperlength - (ymargin * 2)) / ((double)paperwidth - (xmargin * 2));
		if (dpi > 0) {
			iwidth = width * 72 / dpi;
			iheight = height * 72 / dpi;
		} else if (imageaspectratio > paperaspectratio) {
			iwidth = paperlength - (ymargin * 2);
			iheight = iwidth / imageaspectratio;
		} else {
			iheight = paperwidth - (xmargin * 2);
			iwidth  = iheight * imageaspectratio;
		}
		xstart = paperwidth - xmargin - (iheight * ymagnification);
		ystart = paperlength - ymargin;
		rotation = -90;
	} else {
		paperaspectratio = ((double)paperwidth - (xmargin * 2)) / ((double)paperlength - (ymargin * 2));
		if (dpi > 0) {
			iwidth = width * 72 / dpi;
			iheight = height * 72 / dpi;
		} else if (imageaspectratio > paperaspectratio) {
			iwidth = paperwidth - (xmargin * 2);
			iheight = iwidth / imageaspectratio;
		} else {
			iheight = paperlength - (ymargin * 2);
			iwidth  = iheight * imageaspectratio;
		}
		xstart = xmargin;
		ystart = paperlength - ymargin - (iheight * ymagnification);
		rotation = 0;
	}
	bbox = Rect(xstart,ystart,xstart+iwidth,ystart+iheight);
	e = preamble(&ioutb, bbox);
	if(e != 0)
		return e;
	Bprint(&ioutb, "%%%%Page: 1\n%%%%BeginPageSetup\n");
	Bprint(&ioutb, "/pgsave save def\n");
	Bprint(&ioutb, "%%%%EndPageSetup\n");
	bps = im->depth;
	Bprint(&ioutb, "%d 0 %d %d %d %d %d %d %s doimage\n", iheight, iwidth, ystart, xstart, height, width, bps, im->flags&Fgrey ? "true" : "false");
 	imagebits(&ioutb, im);
	Bprint(&ioutb, "pgsave restore\nshowpage\n");
	e = trailer(&ioutb, 1);
	if(e != 0)
		return e;
	Bterm(&ioutb);
	return 0;
}
示例#29
0
void
wikiget(Wiki *w)
{
	char *p;
	int fd, normal;
	Biobuf *bin;

	fprint(w->win->ctl, "dirty\n");

	p = emalloc(strlen(w->arg)+8+1);
	strcpy(p, w->arg);
	normal = 1;
	if(p[strlen(p)-1] == '/'){
		normal = 0;
		strcat(p, "current");
	}else if(strlen(p)>8 && strcmp(p+strlen(p)-8, "/current")==0){
		normal = 0;
		w->arg[strlen(w->arg)-7] = '\0';
	}

	if((fd = open(p, OREAD)) < 0){
		fprint(2, "Wiki: cannot read %s: %r\n", p);
		winclean(w->win);
		return;
	}
	free(p);

	winopenbody(w->win, OWRITE);
	bin = emalloc(sizeof(*bin));
	Binit(bin, fd, OREAD);

	p = nil;
	if(!normal){
		if((p = Brdline(bin, '\n')) == nil){
			fprint(2, "Wiki: cannot read title: %r\n");
			winclean(w->win);
			close(fd);
			free(bin);
			return;
		}
		p[Blinelen(bin)-1] = '\0';
	}
	/* clear window */
	if(w->win->data < 0)
		w->win->data = winopenfile(w->win, "data");
	if(winsetaddr(w->win, ",", 0))
		write(w->win->data, "", 0);

	if(!normal)
		Bprint(w->win->body, "%s\n\n", p);

	while(p = Brdline(bin, '\n')){
		p[Blinelen(bin)-1] = '\0';
		if(normal)
			Bprint(w->win->body, "%s\n", p);
		else{
			if(p[0]=='D')
				w->time = strtoul(p+1, 0, 10);
			else if(p[0]=='#')
				Bprint(w->win->body, "%s\n", p+1);
		}
	}
	winclean(w->win);
	free(bin);
	close(fd);
}
示例#30
0
文件: obj.c 项目: machinaut/go
void
main(int argc, char *argv[])
{
	int c;

	Binit(&bso, 1, OWRITE);
	cout = -1;
	listinit();
	memset(debug, 0, sizeof(debug));
	nerrors = 0;
	outfile = nil;
	HEADTYPE = -1;
	INITTEXT = -1;
	INITDAT = -1;
	INITRND = -1;
	INITENTRY = 0;

	ARGBEGIN {
	default:
		c = ARGC();
		if(c == 'l')
			usage();
 		if(c >= 0 && c < sizeof(debug))
			debug[c]++;
		break;
	case 'o': /* output to (next arg) */
		outfile = EARGF(usage());
		break;
	case 'E':
		INITENTRY = EARGF(usage());
		break;
	case 'H':
		HEADTYPE = headtype(EARGF(usage()));
		break;
	case 'I':
		interpreter = EARGF(usage());
		break;
	case 'L':
		Lflag(EARGF(usage()));
		break;
	case 'T':
		INITTEXT = atolwhex(EARGF(usage()));
		break;
	case 'D':
		INITDAT = atolwhex(EARGF(usage()));
		break;
	case 'R':
		INITRND = atolwhex(EARGF(usage()));
		break;
	case 'r':
		rpath = EARGF(usage());
		break;
	case 'V':
		print("%cl version %s\n", thechar, getgoversion());
		errorexit();
	} ARGEND

	if(argc != 1)
		usage();

	mywhatsys();	// get goos

	if(HEADTYPE == -1)
		HEADTYPE = headtype(goos);

	if(outfile == nil) {
		if(HEADTYPE == Hwindows)
			outfile = "8.out.exe";
		else
			outfile = "8.out";
	}

	libinit();

	switch(HEADTYPE) {
	default:
		diag("unknown -H option");
		errorexit();

	case Hgarbunix:	/* this is garbage */
		HEADR = 20L+56L;
		if(INITTEXT == -1)
			INITTEXT = 0x40004CL;
		if(INITDAT == -1)
			INITDAT = 0x10000000L;
		if(INITRND == -1)
			INITRND = 0;
		break;
	case Hunixcoff:	/* is unix coff */
		HEADR = 0xd0L;
		if(INITTEXT == -1)
			INITTEXT = 0xd0;
		if(INITDAT == -1)
			INITDAT = 0x400000;
		if(INITRND == -1)
			INITRND = 0;
		break;
	case Hplan9x32:	/* plan 9 */
		tlsoffset = -8;
		HEADR = 32L;
		if(INITTEXT == -1)
			INITTEXT = 4096+32;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	case Hmsdoscom:	/* MS-DOS .COM */
		HEADR = 0;
		if(INITTEXT == -1)
			INITTEXT = 0x0100;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		break;
	case Hmsdosexe:	/* fake MS-DOS .EXE */
		HEADR = 0x200;
		if(INITTEXT == -1)
			INITTEXT = 0x0100;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4;
		HEADR += (INITTEXT & 0xFFFF);
		if(debug['v'])
			Bprint(&bso, "HEADR = 0x%d\n", HEADR);
		break;
	case Hdarwin:	/* apple MACH */
		/*
		 * OS X system constant - offset from %gs to our TLS.
		 * Explained in ../../libcgo/darwin_386.c.
		 */
		tlsoffset = 0x468;
		machoinit();
		HEADR = INITIAL_MACHO_HEADR;
		if(INITTEXT == -1)
			INITTEXT = 4096+HEADR;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	case Hlinux:	/* elf32 executable */
	case Hfreebsd:
		/*
		 * ELF uses TLS offsets negative from %gs.
		 * Translate 0(GS) and 4(GS) into -8(GS) and -4(GS).
		 * Also known to ../../pkg/runtime/linux/386/sys.s
		 * and ../../libcgo/linux_386.c.
		 */
		tlsoffset = -8;
		elfinit();
		HEADR = ELFRESERVE;
		if(INITTEXT == -1)
			INITTEXT = 0x08048000+HEADR;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = 4096;
		break;
	case Hwindows: /* PE executable */
		peinit();
		HEADR = PEFILEHEADR;
		if(INITTEXT == -1)
			INITTEXT = PEBASE+PESECTHEADR;
		if(INITDAT == -1)
			INITDAT = 0;
		if(INITRND == -1)
			INITRND = PESECTALIGN;
		break;
	}
	if(INITDAT != 0 && INITRND != 0)
		print("warning: -D0x%ux is ignored because of -R0x%ux\n",
			INITDAT, INITRND);
	if(debug['v'])
		Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n",
			HEADTYPE, INITTEXT, INITDAT, INITRND);
	Bflush(&bso);

	instinit();
	zprg.link = P;
	zprg.pcond = P;
	zprg.back = 2;
	zprg.as = AGOK;
	zprg.from.type = D_NONE;
	zprg.from.index = D_NONE;
	zprg.from.scale = 1;
	zprg.to = zprg.from;

	pcstr = "%.6ux ";
	nuxiinit();
	histgen = 0;
	pc = 0;
	dtype = 4;
	version = 0;
	cbp = buf.cbuf;
	cbc = sizeof(buf.cbuf);

	addlibpath("command line", "command line", argv[0], "main");
	loadlib();
	deadcode();
	patch();
	follow();
	doelf();
	if(HEADTYPE == Hdarwin)
		domacho();
	if(HEADTYPE == Hwindows)
		dope();
	dostkoff();
	if(debug['p'])
		if(debug['1'])
			doprof1();
		else
			doprof2();
	span();
	addexport();
	textaddress();
	pclntab();
	symtab();
	dodata();
	address();
	doweak();
	reloc();
	asmb();
	undef();
	if(debug['v']) {
		Bprint(&bso, "%5.2f cpu time\n", cputime());
		Bprint(&bso, "%d symbols\n", nsymbol);
		Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
		Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
	}
	Bflush(&bso);

	errorexit();
}