Exemple #1
0
/*
 *  Output the message body with '^From ' escapes.
 *  Ensures that any line starting with a 'From ' gets a ' ' stuck
 *  in front of it.
 */
static int
m_escape(message *mp, Biobuf *fp)
{
	char *p, *np;
	char *end;
	long offset;
	int m, n;
	char *start;

	for(offset = 0; offset < mp->size; offset += n){
		n = m_get(mp, offset, &start);
		if(n < 0){
			Bflush(fp);
			return -1;
		}

		p = start;
		for(end = p+n; p < end; p += m){
			np = memchr(p, '\n', end-p);
			if(np == 0){
				Bwrite(fp, p, end-p);
				break;
			}
			m = np - p + 1;
			if(m > 5 && strncmp(p, "From ", 5) == 0)
				Bputc(fp, ' ');
			Bwrite(fp, p, m);
		}
	}
	Bflush(fp);
	return 0;
}
Exemple #2
0
void
threadmain(int argc, char *argv[])
{
	int i;
	int lineset;
	int ifd;

	lineset = 0;
	Binit(&bout, 1, OWRITE);
	while(argc > 1 && argv[1][0] == '-'){
		--argc; argv++;
		switch(argv[0][1]){
		case '\0':
			colonflag = 1;
			break;
		case 't':
			tabflag = 0;
			break;
		default:
			linewidth = atoi(&argv[0][1]);
			if(linewidth <= 1)
				linewidth = WIDTH;
			lineset = 1;
			break;
		}
	}
	if(lineset == 0)
		getwidth();
	cbuf = cbufp = malloc(ALLOC_QUANTA*(sizeof *cbuf));
	word = malloc(WORD_ALLOC_QUANTA*(sizeof *word));
	if(word == 0 || cbuf == 0)
		error("out of memory");
	if(argc == 1)
		readbuf(0);
	else{
		for(i = 1; i < argc; i++){
			if((ifd = open(*++argv, OREAD)) == -1)
				fprint(2, "mc: can't open %s (%r)\n", *argv);
			else{
				readbuf(ifd);
				Bflush(&bin);
				close(ifd);
			}
		}
	}
	columnate();
	Bflush(&bout);
	threadexitsall(0);
}
Exemple #3
0
int
Bprint(Biobuf *bb, char *fmt, ...)
{
	va_list arg;
	int n, pcol;
	char *ip, *ep, *out;
	Biobufhdr *bp = &bb->_h;

	va_start(arg, fmt);
	ep = (char*)bp->ebuf;
	ip = ep + bp->ocount;
	pcol = printcol;
	out = doprint(ip, ep, fmt, arg);
	if(out >= ep-UTFmax-1) {
		Bflush(bb);
		ip = ep + bp->ocount;
		printcol = pcol;
		out = doprint(ip, ep, fmt, arg);
		if(out >= ep-UTFmax-1) {
			va_end(arg);
			return Beof;
		}
	}
	n = out-ip;
	bp->ocount += n;
	va_end(arg);
	return n;
}
Exemple #4
0
void
winclean(Window *w)
{
	if(w->body)
		Bflush(w->body);
	ctlprint(w->ctl, "clean\n");
}
Exemple #5
0
void
r_fl(int argc, Rune **argv)
{
	USED(argc);
	USED(argv);
	Bflush(&bout);
}
Exemple #6
0
static int
stlscmd(char*)
{
	int fd;
	TLSconn conn;

	if(didtls)
		return senderr("tls already started");
	if(!tlscert)
		return senderr("don't have any tls credentials");
	sendok("");
	Bflush(&out);

	memset(&conn, 0, sizeof conn);
	conn.cert = tlscert;
	conn.certlen = ntlscert;
	if(debug)
		conn.trace = trace;
	fd = tlsServer(0, &conn);
	if(fd < 0)
		sysfatal("tlsServer: %r");
	dup(fd, 0);
	dup(fd, 1);
	close(fd);
	Binit(&in, 0, OREAD);
	Binit(&out, 1, OWRITE);
	didtls = 1;
	return 0;
}
Exemple #7
0
void
mk(char *target)
{
	Node *node;
	int did = 0;

	nproc();		/* it can be updated dynamically */
	nrep();			/* it can be updated dynamically */
	runerrs = 0;
	node = graph(target);
	if(DEBUG(D_GRAPH)){
		dumpn("new target\n", node);
		Bflush(&bout);
	}
	clrmade(node);
	while(node->flags&NOTMADE){
		if(work(node, (Node *)0, (Arc *)0))
			did = 1;	/* found something to do */
		else {
			if(waitup(1, (int *)0) > 0){
				if(node->flags&(NOTMADE|BEINGMADE)){
					assert(/*must be run errors*/ runerrs);
					break;	/* nothing more waiting */
				}
			}
		}
	}
	if(node->flags&BEINGMADE)
		waitup(-1, (int *)0);
	while(jobs)
		waitup(-2, (int *)0);
	assert(/*target didnt get done*/ runerrs || (node->flags&MADE));
	if(did == 0)
		Bprint(&bout, "mk: '%s' is up to date\n", node->name);
}
Exemple #8
0
void
putfile(void)
{
	int *a1;
	Rune *lp;
	long c;

	a1 = addr1;
	do {
		lp = getline(*a1++);
		for(;;) {
			count++;
			c = *lp++;
			if(c == 0) {
				if(Bputrune(&iobuf, '\n') < 0)
					error(Q);
				break;
			}
			if(Bputrune(&iobuf, c) < 0)
				error(Q);
		}
	} while(a1 <= addr2);
	if(Bflush(&iobuf) < 0)
		error(Q);
}
Exemple #9
0
void
patch(void)
{
	vlong c, vexit;
	Prog *p, *q;
	Sym *s;
	int a;

	if(debug['v'])
		Bprint(&bso, "%5.2f patch\n", cputime());
	Bflush(&bso);
	mkfwd();
	s = lookup("exit", 0);
	vexit = s->value;
	for(p = firstp; p != P; p = p->link) {
		a = p->as;
		if(a == ATEXT)
			curtext = p;
		if((a == AJAL || a == AJMP || a == ARET) &&
		   p->to.type != D_BRANCH && p->to.sym != S) {
			s = p->to.sym;
			if(s->type != STEXT) {
				diag("undefined: %s\n%P", s->name, p);
				s->type = STEXT;
				s->value = vexit;
			}
			p->to.offset = s->value;
			p->to.type = D_BRANCH;
		}
		if(p->to.type != D_BRANCH)
			continue;
		c = p->to.offset;
		for(q = firstp; q != P;) {
			if(q->forwd != P)
			if(c >= q->forwd->pc) {
				q = q->forwd;
				continue;
			}
			if(c == q->pc)
				break;
			q = q->link;
		}
		if(q == P) {
			diag("branch out of range %lld\n%P", c, p);
			p->to.type = D_NONE;
		}
		p->cond = q;
	}

	for(p = firstp; p != P; p = p->link) {
		if(p->as == ATEXT)
			curtext = p;
		if(p->cond != P) {
			p->cond = brloop(p->cond);
			if(p->cond != P)
			if(p->to.type == D_BRANCH)
				p->to.offset = p->cond->pc;
		}
	}
}
Exemple #10
0
void
wclean(Win *w)
{
	if(w->body)
		Bflush(w->body);
	ctlwrite(w, "clean\n");
}
Exemple #11
0
void
threadmain(int argc, char *argv[])
{
	char *errmsg;
	int ac;
	char *ap, *av[256];
	Cmd *cp;
	int32_t status;

	if (argc > 3) {
		print("usage: cifscmd [to [share]]\n");
		exits("args");
	}
	smbglobalsguess(1);
	errmsg = nil;

	if (Binit(&bin, 0, OREAD) == Beof || Binit(&bout, 1, OWRITE) == Beof) {
		fprint(2, "%s: can't init bio: %r\n", argv0);
		threadexits("Binit");
	}

	if (argc > 1) {
		c = smbconnect(argv[1], argc == 3 ? argv[2] : nil, &errmsg);
		if (c == nil)
			fprint(2, "failed to connect: %s\n", errmsg);
	}
	while (ap = Brdline(&bin, '\n')) {
		ap[Blinelen(&bin) - 1] = 0;
		switch (ac = parse(ap, av, nelem(av))) {
		default:
			for (cp = cmd; cp->name; cp++) {
				if (strcmp(cp->name, av[0]) == 0)
					break;
			}
			if (cp->name == 0) {
				Bprint(&bout, "eh?\n");
				break;
			}
			if (c == 0 && cp->connected) {
				Bprint(&bout, "not currently connected\n");
				break;
			}
			if ((status = (*cp->f)(c, ac - 1, &av[1])) != -1) {
				if(verbose)
					Bprint(&bout, "ok %ld/%ld\n", status >> 16, status & 0xffff);
				break;
			}
			break;

		case -1:
			Bprint(&bout, "eh?\n");
			break;

		case 0:
			break;
		}
		Bflush(&bout);
	}
	threadexits(0);
}
Exemple #12
0
void
syswrite(int64_t offset)
{
	int fd;
	uint32_t size, a;
	char *buf;
	int n;

	fd = getmem_w(reg.r[13]+4);
	a = getmem_w(reg.r[13]+8);
	size = getmem_w(reg.r[13]+12);

	Bflush(bioout);
	buf = memio(0, a, size, MemRead);
	n = pwrite(fd, buf, size, offset);
	if(n < 0)
		errstr(errbuf, sizeof errbuf);	

	if(sysdbg)
		itrace("write(%d, %lux, %d, 0x%llx) = %d", fd, a, size, offset, n);

	free(buf);

	reg.r[REGRET] = n;
}
Exemple #13
0
void
error(char *fmt, ...)
{
	int i;
	char buf[2048];
	va_list arg;

	/* Unstack io channels */
	if(iop != 0) {
		for(i = 1; i < iop; i++)
			Bterm(io[i]);
		bout = io[0];
		iop = 0;
	}

	ret = 0;
	gotint = 0;
	Bflush(bout);
	if(silent)
		silent = 0;
	else {
		va_start(arg, fmt);
		vseprint(buf, buf+sizeof(buf), fmt, arg);
		va_end(arg);
		fprint(2, "%L: (error) %s\n", buf);
	}
	while(popio())
		;
	interactive = 1;
	longjmp(err, 1);
}
Exemple #14
0
void
pipifc(void)
{
	Ipifc *ip, *nip;
	Iplifc *lifc;
	char buf[100];
	int l, i;

	fmtinstall('I', eipfmt);
	fmtinstall('M', eipfmt);

	ip = readipifc(netroot, nil, -1);

	l = 7;
	for(nip = ip; nip; nip = nip->next){
		for(lifc = nip->lifc; lifc; lifc = lifc->next){
			i = snprint(buf, sizeof buf, "%I", lifc->ip);
			if(i > l)
				l = i;
			i = snprint(buf, sizeof buf, "%I", lifc->net);
			if(i > l)
				l = i;
		}
	}

	for(nip = ip; nip; nip = nip->next){
		for(lifc = nip->lifc; lifc; lifc = lifc->next)
			Bprint(&out, "%-12s %5d %-*I %5M %-*I %8lud %8lud %8lud %8lud\n",
				nip->dev, nip->mtu, 
				l, lifc->ip, lifc->mask, l, lifc->net,
				nip->pktin, nip->pktout,
				nip->errin, nip->errout);
	}
	Bflush(&out);
}
Exemple #15
0
Fichier : lex.c Projet : hfeeki/go
void
cclean(void)
{

	outcode(AEND, Always, &nullgen, NREG, &nullgen);
	Bflush(&obuf);
}
Exemple #16
0
void
codeblk(int64 addr, int64 size)
{
	LSym *sym;
	int64 eaddr, n;
	uchar *q;

	if(debug['a'])
		Bprint(&bso, "codeblk [%#x,%#x) at offset %#llx\n", addr, addr+size, cpos());

	blk(ctxt->textp, addr, size);

	/* again for printing */
	if(!debug['a'])
		return;

	for(sym = ctxt->textp; sym != nil; sym = sym->next) {
		if(!sym->reachable)
			continue;
		if(sym->value >= addr)
			break;
	}

	eaddr = addr + size;
	for(; sym != nil; sym = sym->next) {
		if(!sym->reachable)
			continue;
		if(sym->value >= eaddr)
			break;

		if(addr < sym->value) {
			Bprint(&bso, "%-20s %.8llux|", "_", (vlong)addr);
			for(; addr < sym->value; addr++)
				Bprint(&bso, " %.2ux", 0);
			Bprint(&bso, "\n");
		}

		Bprint(&bso, "%.6llux\t%-20s\n", (vlong)addr, sym->name);
		n = sym->size;
		q = sym->p;

		while(n >= 16) {
			Bprint(&bso, "%.6ux\t%-20.16I\n", addr, q);
			addr += 16;
			q += 16;
			n -= 16;
		}
		if(n > 0)
			Bprint(&bso, "%.6ux\t%-20.*I\n", addr, (int)n, q);
		addr += n;
	}

	if(addr < eaddr) {
		Bprint(&bso, "%-20s %.8llux|", "_", (vlong)addr);
		for(; addr < eaddr; addr++)
			Bprint(&bso, " %.2ux", 0);
	}
	Bflush(&bso);
}
Exemple #17
0
void
doprof1(void)
{
#if 0
	Sym *s;
	int32 n;
	Prog *p, *q;

	if(debug['v'])
		Bprint(&bso, "%5.2f profile 1\n", cputime());
	Bflush(&bso);
	s = lookup("__mcount", 0);
	n = 1;
	for(cursym = textp; cursym != nil; cursym = cursym->next) {
		p = cursym->text;
		q = prg();
		q->line = p->line;
		q->link = datap;
		datap = q;
		q->as = ADATA;
		q->from.type = D_EXTERN;
		q->from.offset = n*4;
		q->from.sym = s;
		q->from.scale = 4;
		q->to = p->from;
		q->to.type = D_CONST;

		q = prg();
		q->line = p->line;
		q->pc = p->pc;
		q->link = p->link;
		p->link = q;
		p = q;
		p->as = AADDL;
		p->from.type = D_CONST;
		p->from.offset = 1;
		p->to.type = D_EXTERN;
		p->to.sym = s;
		p->to.offset = n*4 + 4;

		n += 2;
	}
	q = prg();
	q->line = 0;
	q->link = datap;
	datap = q;

	q->as = ADATA;
	q->from.type = D_EXTERN;
	q->from.sym = s;
	q->from.scale = 4;
	q->to.type = D_CONST;
	q->to.offset = n;

	s->type = SBSS;
	s->size = n*4;
#endif
}
Exemple #18
0
void
Cwrite(Cdimg *cd, void *buf, int n)
{
	assert(Boffset(&cd->bwr) >= 16*Blocksize);

	if(Bwrite(&cd->bwr, buf, n) != n)
		sysfatal("Bwrite: %r");
	Bflush(&cd->brd);
}
Exemple #19
0
Fichier : buffer.c Projet : 4ad/sam
void
Bclean(Buffer *b)
{
	if(b->dirty){
		Bflush(b);
		b->c1 = b->c2 = 0;
		Strzero(&b->cache);
	}
}
Exemple #20
0
void
vncflush(Vnc *v)
{
	if(Bflush(&v->out) < 0){
		if(verbose > 1)
			fprint(2, "hungup while sending flush: %r\n");
		vnchungup(v);
	}
}
Exemple #21
0
/* output the message body without ^From escapes */
static int
m_noescape(message *mp, Biobuf *fp)
{
	long offset;
	int n;
	char *p;

	for(offset = 0; offset < mp->size; offset += n){
		n = m_get(mp, offset, &p);
		if(n <= 0){
			Bflush(fp);
			return -1;
		}
		if(Bwrite(fp, p, n) < 0)
			return -1;
	}
	return Bflush(fp);
}
Exemple #22
0
void
Ssyscall(uint32_t)
{
	int call;

	call = reg.r[REGARG];
	if(call < 0 || call >= nelem(systab) || systab[call] == nil) {
		Bprint(bioout, "bad system call %d (%#ux)\n", call, call);
		dumpreg();
		Bflush(bioout);
		return;
	}

	if(trace)
		itrace("SWI\t%s", sysctab[call]);
	(*systab[call])();
	Bflush(bioout);
}
Exemple #23
0
/*
 * print accumulated error reports
 */
void
errprint(void)
{
	Bflush(&bout);
	for(; err != 0; err = err->e_nextp) {
		cerror(err->e_mess);
		fprint(2, "\n");
	}
}
Exemple #24
0
int
dBprint(char *fmt, ...)
{
	char buf[SIZE], *out;
	va_list arg;
	int n;

	va_start(arg, fmt);
	out = vseprint(buf, buf+SIZE, fmt, arg);
	va_end(arg);
	if(debug){
		Bwrite(&berr, buf, (long)(out-buf));
		Bflush(&berr);
	}
	n = Bwrite(&bout, buf, (long)(out-buf));
	Bflush(&bout);
	return n;
}
Exemple #25
0
void
wwritebody(Win *w, char *s, int n)
{
	if(w->body == nil)
		openbody(w, OWRITE);
	if(Bwrite(w->body, s, n) != n)
		  fprint(2,"write error to window: %r");
	Bflush(w->body);
}
Exemple #26
0
void
astro(char *flags, int initial)
{
	int p[2];
	int i, n, np;
	char cmd[256], buf[4096], *lines[20], *fld[10];

	snprint(cmd, sizeof cmd, "/bin/astro -p %s", flags);
	if(pipe(p) < 0){
		fprint(2, "can't pipe: %r\n");
		return;
	}
	if(runcommand(cmd, p) < 0){
		close(p[0]);
		close(p[1]);
		fprint(2, "can't run astro: %r");
		return;
	}
	close(p[1]);
	n = readn(p[0], buf, sizeof buf-1);
	if(n <= 0){
		fprint(2, "no data from astro\n");
		return;
	}
	if(!initial)
		Bwrite(&bout, buf, n);
	buf[n] = '\0';
	np = getfields(buf, lines, nelem(lines), 0, "\n");
	if(np <= 1){
		fprint(2, "astro: not enough output\n");
		return;
	}
	Bprint(&bout, "%s\n", lines[0]);
	Bflush(&bout);
	/* get latitude and longitude */
	if(getfields(lines[0], fld, nelem(fld), 1, " ") < 8)
		fprint(2, "astro: can't read longitude: too few fields\n");
	else{
		mysid = getra(fld[5])*180./PI;
		mylat = getra(fld[6])*180./PI;
		mylon = getra(fld[7])*180./PI;
	}
	/*
	 * Each time we run astro, we generate a new planet list
	 * so multiple appearances of a planet may exist as we plot
	 * its motion over time.
	 */
	planet = malloc(NPlanet*sizeof planet[0]);
	if(planet == nil){
		fprint(2, "astro: malloc failed: %r\n");
		exits("malloc");
	}
	memset(planet, 0, NPlanet*sizeof planet[0]);
	for(i=1; i<np; i++)
		parseplanet(lines[i], &planet[i-1]);
}
Exemple #27
0
uchar*
getrange(Block *b)
{
	uchar *data;
	char *status;
	int netfd;
	static Biobuf netbio;

	b->len = Blocksize;
	if(b->off + b->len > size)
		b->len = size - b->off;

	if(debug)
		print("getrange: %lld %lld\n", b->off, b->len);

	netfd = dialhttp(&netbio);

	fprint(netfd, 
		"GET %s HTTP/1.1\r\n"
		"Host: %s\r\n"
		"Accept-Encoding:\r\n"
		"Range: bytes=%lld-%lld\r\n"
		"\r\n",
		get, host, b->off, b->off+b->len);
	Bflush(&netbio);

	status = readhttphdr(&netbio, nil);
	if(status == nil)
		return nil;

	/*
	 * Some servers (e.g., www.google.com) return 200 OK
	 * when you ask for the entire page in one range.
	 */
	if(strstr(status, "206 Partial Content")==nil
	&& (b->off!=0 || b->len!=size || strstr(status, "200 OK")==nil)){
		free(status);
		close(netfd);
		werrstr("did not get requested range");
		return nil;
	}
	free(status);

	data = emalloc9p(b->len);
	if(Bread(&netbio, data, b->len) != b->len){
		free(data);
		close(netfd);
		werrstr("not enough bytes read");
		return nil;
	}

	b->p = data;

	close(netfd);
	return data;
}
Exemple #28
0
void
cclean(void)
{
	Gen2 g2;

	g2.from = nullgen;
	g2.to = nullgen;
	outcode(AEND, &g2);
	Bflush(&obuf);
}
Exemple #29
0
void
warning(char *s,...)
{
	va_list argl;

	va_start(argl, s);
	printerr("Warning", s, argl);
	va_end(argl);
	Bflush(&fout);
}
Exemple #30
0
void
main(int argc, char **argv)
{
	int fd, ofd;
	char diffout[40], idiffout[40];
	Biobuf *b1, *b2, bdiff, bout, bstdout;
	Dir *d;

	ARGBEGIN{
	default:
		usage();
	case 'b':
		diffbflag++;
		break;
	case 'w':
		diffwflag++;
		break;
	}ARGEND

	if(argc != 2)
		usage();

	if((d = dirstat(argv[0])) == nil)
		sysfatal("stat %s: %r", argv[0]);
	if(d->mode&DMDIR)
		sysfatal("%s is a directory", argv[0]);
	free(d);
	if((d = dirstat(argv[1])) == nil)
		sysfatal("stat %s: %r", argv[1]);
	if(d->mode&DMDIR)
		sysfatal("%s is a directory", argv[1]);
	free(d);

	if((b1 = Bopen(argv[0], OREAD)) == nil)
		sysfatal("open %s: %r", argv[0]);
	if((b2 = Bopen(argv[1], OREAD)) == nil)
		sysfatal("open %s: %r", argv[1]);

	strcpy(diffout, "/tmp/idiff.XXXXXX");
	fd = opentemp(diffout, ORDWR|ORCLOSE, 0);
	strcpy(idiffout, "/tmp/idiff.XXXXXX");
	ofd = opentemp(idiffout, ORDWR|ORCLOSE, 0);
	rundiff(argv[0], argv[1], fd);
	seek(fd, 0, 0);
	Binit(&bdiff, fd, OREAD);
	Binit(&bout, ofd, OWRITE);
	idiff(b1, argv[0], b2, argv[1], &bdiff, diffout, &bout, idiffout);
	Bterm(&bdiff);
	Bflush(&bout);
	seek(ofd, 0, 0);
	Binit(&bout, ofd, OREAD);
	Binit(&bstdout, 1, OWRITE);
	copy(&bout, idiffout, &bstdout, "<stdout>");
	exits(nil);
}