Exemple #1
0
/*
 *  print out a header line, expanding any domainless addresses into
 *  address@him
 */
char*
bprintnode(Biobuf *b, Node *p, int *cntp)
{
	int len;

	*cntp = 0;
	if(p->s){
		if(p->addr && strchr(s_to_c(p->s), '@') == nil){
			if(Bprint(b, "%s@%s", s_to_c(p->s), him) < 0)
				return nil;
			*cntp += s_len(p->s) + 1 + strlen(him);
		} else {
			len = s_len(p->s);
			if(Bwrite(b, s_to_c(p->s), len) < 0)
				return nil;
			*cntp += len;
		}
	}else{
		if(Bputc(b, p->c) < 0)
			return nil;
		++*cntp;
	}
	if(p->white) {
		len = s_len(p->white);
		if(Bwrite(b, s_to_c(p->white), len) < 0)
			return nil;
		*cntp += len;
	}
	return p->end+1;
}
Exemple #2
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 #3
0
static int
retrcmd(char *arg)
{
	int n;
	Biobuf *b;
	char buf[40], *p;

	if(*arg == 0)
		return senderr("RETR requires a message number");
	n = atoi(arg)-1;
	if(n < 0 || n >= nmsg || msg[n].deleted)
		return senderr("no such message");
	snprint(buf, sizeof buf, "%d/raw", msg[n].upasnum);
	if((b = Bopen(buf, OREAD)) == nil)
		return senderr("message disappeared");
	sendok("");
	while((p = Brdstr(b, '\n', 1)) != nil){
		if(p[0]=='.')
			Bwrite(&out, ".", 1);
		Bwrite(&out, p, strlen(p));
		Bwrite(&out, "\r\n", 2);
		free(p);
	}
	Bterm(b);
	sendcrnl(".");
	return 0;
}
Exemple #4
0
char*
qmail(char **argv, char *buf, int n, Biobuf *cout)
{
    Waitmsg *status;
    int i, pid, pipefd[2];
    char path[512];
    Biobuf *bp;

    pid = 0;
    if(tflag == 0) {
        if(pipe(pipefd) < 0)
            exits("pipe");
        pid = fork();
        if(pid == 0) {
            dup(pipefd[0], 0);
            for(i = sysfiles(); i >= 3; i--)
                close(i);
            snprint(path, sizeof(path), "%s/qer", UPASBIN);
            *argv=path;
            exec(path, argv);
            exits("exec");
        }
        Binit(&bout, pipefd[1], OWRITE);
        bp = &bout;
    } else
        bp = Bopen("/dev/null", OWRITE);

    while(n > 0) {
        Bwrite(bp, buf, n);
        if(cout)
            Bwrite(cout, buf, n);
        n = Bread(&bin, buf, sizeof(buf)-1);
    }
    Bterm(bp);
    if(cout)
        Bterm(cout);
    if(tflag)
        return 0;

    close(pipefd[1]);
    close(pipefd[0]);
    for(;;) {
        status = wait();
        if(status == nil || status->pid == pid)
            break;
        free(status);
    }
    if(status == nil)
        strcpy(buf, "wait failed");
    else {
        strcpy(buf, status->msg);
        free(status);
    }
    return buf;
}
Exemple #5
0
void
Bputname(Biobuf *b, Sym *s)
{
	Bprint(b, "%s", s->pkg->prefix);
	Bputc(b, '.');
	Bwrite(b, s->name, strlen(s->name)+1);
}
Exemple #6
0
char*
nntppost(Netbuf *n, char *msg)
{
	char *p, *q;

	if(nntpcmd(n, "POST", 34) < 0)
		return n->response;

	for(p=msg; *p; p=q){
		if((q = strchr(p, '\n')) != nil)
			*q++ = '\0';
		else
			q = p+strlen(p);

		if(p[0]=='.')
			Bputc(&n->bw, '.');
		Bwrite(&n->bw, p, strlen(p));
		Bputc(&n->bw, '\r');
		Bputc(&n->bw, '\n');
	}
	Bprint(&n->bw, ".\r\n");

	if(nntpresponse(n, 0, nil) < 0)
		return n->response;

	if(n->code/100 != 2)
		return n->response;
	return nil;
}
Exemple #7
0
void
outWrite(void *buf, int n)
{
	if(Bwrite(out, buf, n) < n)
		sysfatal("write failed: %r");
	outdg = sha1((uchar*)buf, n, nil, outdg);
}
Exemple #8
0
/*
 * return a simple string
 */
void
fetchBodyStr(Fetch *f, char *buf, ulong size)
{
    Pair p;

    p = fetchBodyPart(f, size);
    Bwrite(&bout, &buf[p.start], p.stop-p.start);
}
Exemple #9
0
static int
topcmd(char *arg)
{
	int done, i, lines, n;
	char buf[40], *p;
	Biobuf *b;

	if(*arg == 0)
		return senderr("TOP requires a message number");
	n = atoi(arg)-1;
	if(n < 0 || n >= nmsg || msg[n].deleted)
		return senderr("no such message");
	arg = nextarg(arg);
	if(*arg == 0)
		return senderr("TOP requires a line count");
	lines = atoi(arg);
	if(lines < 0)
		return senderr("bad args to TOP");
	snprint(buf, sizeof buf, "%d/raw", msg[n].upasnum);
	if((b = Bopen(buf, OREAD)) == nil)
		return senderr("message disappeared");
	sendok("");
	while(p = Brdstr(b, '\n', 1)){
		if(p[0]=='.')
			Bputc(&out, '.');
		Bwrite(&out, p, strlen(p));
		Bwrite(&out, "\r\n", 2);
		done = p[0]=='\0';
		free(p);
		if(done)
			break;
	}
	for(i=0; i<lines; i++){
		p = Brdstr(b, '\n', 1);
		if(p == nil)
			break;
		if(p[0]=='.')
			Bwrite(&out, ".", 1);
		Bwrite(&out, p, strlen(p));
		Bwrite(&out, "\r\n", 2);
		free(p);
	}
	sendcrnl(".");
	Bterm(b);
	return 0;
}
Exemple #10
0
void
winwritebody(Window *w, char *s, int n)
{
	if(w->body == nil)
		winopenbody(w, OWRITE);
	if(Bwrite(w->body, s, n) != n)
		error("write error to window: %r");
}
Exemple #11
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 #12
0
static int
gzwrite(void *bout, void *buf, int n)
{
	if(n != Bwrite(bout, buf, n)){
		eof = 1;
		return -1;
	}
	return n;
}
Exemple #13
0
void
vncwrbytes(Vnc *v, void *a, int n)
{
	if(Bwrite(&v->out, a, n) < 0){
		if(verbose > 1) 
			fprint(2, "hungup while writing bytes\n");
		vnchungup(v);
	}
}
Exemple #14
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 #15
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 #16
0
void
savestate(char *file)
{
	flushram();
	bp = Bopen(file, OWRITE);
	if(bp == nil){
		message("open: %r");
		return;
	}
	Bwrite(bp, reg, sizeof(reg));
	Bwrite(bp, mem, sizeof(mem));
	Bwrite(bp, vram, sizeof(vram));
	Bwrite(bp, oam, sizeof(oam));
	Bwrite(bp, spcmem, sizeof(spcmem));
	Bwrite(bp, dsp, sizeof(dsp));
	put16s(cgram, nelem(cgram));
	put32(ppuclock);
	put32(spcclock);
	put32(dspclock);
	put32(stimerclock);
	put16(rA);
	put16(rX);
	put16(rY);
	put16(rS);
	put8(rP);
	put16(rD);
	put8(rDB>>16);
	put16(pc);
	put8(rPB>>16);
	put8(emu);
	put8(irq);
	put8(nmi);
	put8(dma);
	put32(hdma);
	put8(wai);
	put8(mdr);
	put8(mdr1);
	put8(mdr2);
	put16(oamaddr);
	put16(vramlatch);
	put32(keylatch);
	put16(ppux);
	put16(ppuy);
	put16(subcolor);
	put16s(hofs, nelem(hofs));
	put16s(vofs, nelem(vofs));
	put16s((u16int*) m7, nelem(m7));
	put8(sA);
	put8(sX);
	put8(sY);
	put8(sS);
	put8(sP);
	put8(dspstate);
	put16(dspcounter);
	put16(noise);
	Bwrite(bp, spctimer, sizeof(spctimer));
	dspsave();
	Bterm(bp);
}
Exemple #17
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 #18
0
static int
writelogpage(Biobuf *b, Dpage *p)
{
DBG print("log page %ud\n", p->addr);
	if(Bpbit32(b, p->addr) < 0)
		return -1;
	if(Bwrite(b, p->a, p->s->ds.pagesize) != p->s->ds.pagesize)
		return -1;
	return 0;
}
Exemple #19
0
static int
Bpbit32(Biobuf *b, u32int v)
{
	uchar tmp[4];

	pbit32(tmp, v);
	if(Bwrite(b, tmp, 4) != 4)
		return -1;
	return 0;
}
Exemple #20
0
void
zfile(Biobuf *b, char *p, int n)
{
	BPUTLE2(b, ANAME);
	BPUTC(b, D_FILE);
	BPUTC(b, 1);
	BPUTC(b, '<');
	Bwrite(b, p, n);
	BPUTC(b, 0);
}
Exemple #21
0
void
zfile(Biobuf *b, char *p, int n)
{
	Bputc(b, ANAME);
	Bputc(b, D_FILE);
	Bputc(b, 1);
	Bputc(b, '<');
	Bwrite(b, p, n);
	Bputc(b, 0);
}
Exemple #22
0
void
owrite(int op, Sym *sym, uint8_t *p, int l)
{
	switch(op){
	case ASIGNAME:
		Bwrite(&bout, p, 4);
		p += 4;
		l -= 4;
	case ANAME:
		if(sym->newname){
			Bwrite(&bout, p, 4);
			Bwrite(&bout, sym->newname, strlen(sym->newname)+1);
			break;
		}
	default:
		Bwrite(&bout, p, l);
		break;
	}
}
Exemple #23
0
void
replywindow(Article *m)
{
	Biobuf *b;
	char *p, *ep, *q, tmp[40];
	int fd, copy;
	Article *reply;

	sprint(tmp, "%d/article", m->n);
	p = estrstrdup(dir, tmp);
	if((fd = open(p, OREAD)) < 0){
		free(p);	
		return;
	}
	free(p);

	reply = newpost();
	winopenbody(reply->w, OWRITE);
	b = emalloc(sizeof(*b));
	Binit(b, fd, OREAD);
	copy = 0;
	while(p = Brdline(b, '\n')){
		if(Blinelen(b)==1)
			break;
		ep = p+Blinelen(b);
		if(!isspace(*p)){
			copy = 0;
			if(cistrncmp(p, "newsgroups:", 11)==0){
				for(q=p+11; *q!='\n'; q++)
					if(*q==',')
						*q = ' ';
				copy = 1;
			}else if(cistrncmp(p, "subject:", 8)==0){
				if(!strstr(p, " Re:") && !strstr(p, " RE:") && !strstr(p, " re:")){
					p = skip(p, "subject:");
					ep[-1] = '\0';
					Bprint(reply->w->body, "Subject: Re: %s\n", p);
				}else
					copy = 1;
			}else if(cistrncmp(p, "message-id:", 11)==0){
				Bprint(reply->w->body, "References: ");
				p += 11;
				copy = 1;
			}
		}
		if(copy)
			Bwrite(reply->w->body, p, ep-p);
	}
	Bterm(b);
	close(fd);
	free(b);
	Bprint(reply->w->body, "\n");
	winclean(reply->w);
	winselect(reply->w, "$", 0);
}
Exemple #24
0
void
x86_ppword(uvlong w)
{
	uchar buf[4];

	buf[0] = w;
	buf[1] = w >> 8;
	buf[2] = w >> 16;
	buf[3] = w >> 24;
	Bwrite(pproffd, buf, 4);
}
Exemple #25
0
void
Bputint(Biobufhdr *b, int n)
{
	uchar p[4];

	p[0] = n>>24;
	p[1] = n>>16;
	p[2] = n>>8;
	p[3] = n;
	Bwrite(b, p, 4);
}
Exemple #26
0
void
outhist(void)
{
	Gen g;
	Hist *h;
	char *p, *q, *op;
	int n;

	g = nullgen;
	for(h = hist; h != H; h = h->link) {
		p = h->name;
		op = 0;
		if(p && p[0] != '/' && h->offset == 0 && pathname && pathname[0] == '/') {
			op = p;
			p = pathname;
		}
		while(p) {
			q = strchr(p, '/');
			if(q) {
				n = q-p;
				if(n == 0)
					n = 1;	/* leading "/" */
				q++;
			} else {
				n = strlen(p);
				q = 0;
			}
			if(n) {
				Bputc(&obuf, ANAME);
				Bputc(&obuf, D_FILE);	/* type */
				Bputc(&obuf, 1);	/* sym */
				Bputc(&obuf, '<');
				Bwrite(&obuf, p, n);
				Bputc(&obuf, 0);
			}
			p = q;
			if(p == 0 && op) {
				p = op;
				op = 0;
			}
		}
		g.offset = h->offset;

		Bputc(&obuf, AHISTORY);
		Bputc(&obuf, 0);
		Bputc(&obuf, h->line);
		Bputc(&obuf, h->line>>8);
		Bputc(&obuf, h->line>>16);
		Bputc(&obuf, h->line>>24);
		zaddr(&nullgen, 0);
		zaddr(&g, 0);
	}
}
Exemple #27
0
Fichier : run.c Projet : 8l/cmm
static void
sched(void)
{
	char *flags;
	Job *j;
	Bufblock *buf;
	int slot;
	Node *n;
	Envy *e;

	if(jobs == 0){
		usage();
		return;
	}
	j = jobs;
	jobs = j->next;
	if(DEBUG(D_EXEC))
		printf("firing up job for target %s\n", wtos(j->t, ' '));
	slot = nextslot();
	events[slot].job = j;
	buf = newbuf();
	e = buildenv(j, slot);
	shprint(j->r->recipe, e, buf);
	if(!tflag && (nflag || !(j->r->attr&QUIET)))
		Bwrite(&bout, buf->start, (long)strlen(buf->start));
	freebuf(buf);
	if(nflag||tflag){
		for(n = j->n; n; n = n->next){
			if(tflag){
				if(!(n->flags&VIRTUAL))
					touch(n->name);
				else if(explain)
					Bprint(&bout, "no touch of virtual '%s'\n", n->name);
			}
			n->time = time((long *)0);
			MADESET(n, MADE);
		}
	} else {
		if(DEBUG(D_EXEC))
			printf("recipe='%s'", j->r->recipe);/**/
		Bflush(&bout);
		if(j->r->attr&NOMINUSE)
			flags = 0;
		else
			flags = "-e";
		events[slot].pid = execsh(flags, j->r->recipe, 0, e);
		usage();
		nrunning++;
		if(DEBUG(D_EXEC))
			printf("pid for target %s = %d\n", wtos(j->t, ' '), events[slot].pid);
	}
}
Exemple #28
0
void
amd64_ppword(uvlong w)
{
	uchar buf[8];

	buf[0] = w;
	buf[1] = w >> 8;
	buf[2] = w >> 16;
	buf[3] = w >> 24;
	buf[4] = w >> 32;
	buf[5] = w >> 40;
	buf[6] = w >> 48;
	buf[7] = w >> 56;
	Bwrite(pproffd, buf, 8);
}
Exemple #29
0
void convpalette(void)
{
    int i, fil3;
    short danumshades;

    i = 0;
    while (Bstrncasecmp(wadata[i],"PLAYPAL",7) != 0) i++;
    Blseek(fil1,wadplc[i],BSEEK_SET);
    Bread(fil1,pal,768);
    for(i=0;i<768;i++) pal[i] >>= 2;

    i = 0;
    while (Bstrncasecmp(wadata[i],"COLORMAP",8) != 0) i++;
    Blseek(fil1,wadplc[i],BSEEK_SET);
    Bread(fil1,palookup,8192);

    if ((fil3 = Bopen("palette.dat",BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1)
        { Bprintf("Cannot save palette.dat\n"); exit(0); }
    Bwrite(fil3,pal,768);
    danumshades = 32;
    Bwrite(fil3,&danumshades,2);
    Bwrite(fil3,palookup,8192);
    Bclose(fil3);
}
Exemple #30
0
/*
 *	Write the defined symbols to the symdef file
 */
void
wrsym(Biobuf *bp, int offset, Arsymref *as)
{
    int off;

    while(as) {
        Bputc(bp, as->type);
        off = as->offset+offset;
        Bputc(bp, off);
        Bputc(bp, off>>8);
        Bputc(bp, off>>16);
        Bputc(bp, off>>24);
        if (Bwrite(bp, as->name, as->len+1) != as->len+1)
            wrerr();
        as = as->next;
    }
}