Esempio n. 1
0
void
stakchk(void)
{
	ssize_t len = (stakbas - stakend) + MINSTAK;
	if (len < -(int)SBRK_offset) setbrk(len);
	brkincr = BRKINCR;
}
Esempio n. 2
0
ptinit(){
	register i, j;
	register char **p;
	char *q;
	int x[8];
	extern char *setbrk();

	if(((i=open(termtab,0)) < 0) && (i=open(_PATH_TERM,0)) < 0){
		prstr("Cannot open ");
		prstr(termtab);
		prstr("\n");
		exit(-1);
	}
	read(i,(char *)x,8*sizeof(int));
	/* Calc size of table, not counting zzz */
	j = ((int) &t.zzz - (int) &t.bset);
	read(i, (char *)&t.bset, j);
	x[2] -= j;
	q = setbrk(x[2]);
	lseek(i,(long)t.twinit+8*sizeof(int),0);
	i = read(i,q,x[2]);
	j = q - t.twinit;
	for(p = &t.twinit; p < &t.zzz; p++){
		if(*p)*p += j;else *p = "";
	}
	sps = EM;
	ics = EM*2;
	dtab = 8 * t.Em;
	for(i=0; i<16; i++)tabtab[i] = dtab * (i+1);
	if(eqflg)t.Adj = t.Hor;
}
Esempio n. 3
0
void
pushstak(char c) {
	if (staktop >= stakend) {
		setbrk(brkincr);
		brkincr += 256;
	}
	*staktop++ = c;
}
Esempio n. 4
0
File: n1.c Progetto: 99years/plan9
void init2(void)
{
	int i;
	char buf[100];

	for (i = NTRTAB; --i; )
		trtab[i] = i;
	trtab[UNPAD] = ' ';
	iflg = 0;
	obufp = obuf;
	if (TROFF)
		t_ptinit();
	else
		n_ptinit();
	mchbits();
	cvtime();
	numtabp[PID].val = getpid();
	numtabp[HP].val = init = 0;
	numtabp[NL].val = -1;
	nfo = 0;
	copyf = raw = 0;
	sprintf(buf, ".ds .T %s\n", devname);
	cpushback(buf);
	sprintf(buf, ".ds .P %s\n", DWBhomedir);
	cpushback(buf);
	numtabp[CD].val = -1;	/* compensation */
	nx = mflg;
	frame = stk = (Stack *)setbrk(STACKSIZE);
	dip = &d[0];
	nxf = frame + 1;
	for (i = 1; i < NEV; i++)	/* propagate the environment */
		envcopy(&env[i], &env[0]);
	for (i = 0; i < NEV; i++) {
		if ((env[i]._word._bufp = (Tchar *)calloc(WDSIZE, sizeof(Tchar))) == NULL) {
			ERROR "not enough room for word buffers" WARN;
			done2(1);
		}
		env[i]._word._size = WDSIZE;
		if ((env[i]._line._bufp = (Tchar *)calloc(LNSIZE, sizeof(Tchar))) == NULL) {
			ERROR "not enough room for line buffers" WARN;
			done2(1);
		}
		env[i]._line._size = LNSIZE;
	}
	if ((oline = (Tchar *)calloc(OLNSIZE, sizeof(Tchar))) == NULL) {
		ERROR "not enough room for line buffers" WARN;
		done2(1);
	}
	olinep = oline;
	olnsize = OLNSIZE;
	blockinit();
}
Esempio n. 5
0
char *
getstak (int asize)	/* allocate requested stack */
{
	char	*oldstak = stakbot;
	int	size = align(int, asize, BYTESPERWORD);
	staktop = (stakbot += size);

	size = staktop - stakend;
	if (size >= 0)
		setbrk(max(brkincr, size));

	return oldstak;
}
Esempio n. 6
0
int
ptinit()
{
	int	i, fin, nw;
	char	*setbrk(), *filebase, *p;

	/* open table for device,
	 * read in resolution, size info, font info, etc.
	 * and set params
	 */
	strcat(termtab, "/dev");
	strcat(termtab, devname);
	strcat(termtab, "/DESC.out");	/* makes "..../devXXX/DESC.out" */
	if ((fin = open(termtab, 0)) < 0) {
		errprint(gettext("can't open tables for %s"), termtab);
		done3(1);
	}
	read(fin, (char *) &dev, sizeof(struct dev ));
	Inch = dev.res;
	Hor = dev.hor;
	Vert = dev.vert;
	Unitwidth = dev.unitwidth;
	nfonts = dev.nfonts;
	nsizes = dev.nsizes;
	nchtab = dev.nchtab;
	if (nchtab >= NCHARS - 128) {
		errprint(gettext("too many special characters in file %s"),
			termtab);
		done3(1);
	}
	filebase = setbrk(dev.filesize + 2*EXTRAFONT);	/* enough room for whole file */
	read(fin, filebase, dev.filesize);	/* all at once */
	pstab = (short *) filebase;
	chtab = pstab + nsizes + 1;
	chname = (char *) (chtab + dev.nchtab);
	p = chname + dev.lchname;
	for (i = 1; i <= nfonts; i++) {
		fontbase[i] = (struct Font *) p;
		nw = *p & BYTEMASK;	/* 1st thing is width count */
		fontlab[i] = PAIR(fontbase[i]->namefont[0], fontbase[i]->namefont[1]);
		/* for now, still 2 char names */
		if (smnt == 0 && fontbase[i]->specfont == 1)
			smnt = i;	/* first special font */
		p += sizeof(struct Font);	/* that's what's on the beginning */
		fontab[i] = p;
		kerntab[i] = p + nw;
		codetab[i] = p + 2 * nw;
		fitab[i] = p + 3 * nw;	/* skip width, kern, code */
		p += 3 * nw + dev.nchtab + 128 - 32;
	}
	fontbase[0] = (struct Font *) p;	/* the last shall be first */
	fontbase[0]->nwfont = EXTRAFONT - dev.nchtab - (128-32) - sizeof (struct Font);
	fontab[0] = p + sizeof (struct Font);
	close(fin);
	/* there are a lot of things that used to be constant
	 * that now require code to be executed.
	 */
	sps = SPS;
	ics = ICS;
	for (i = 0; i < 16; i++)
		tabtab[i] = DTAB * (i + 1);
	pl = 11 * INCH;
	po = PO;
	spacesz = SS;
	lss = lss1 = VS;
	ll = ll1 = lt = lt1 = LL;
	specnames();	/* install names like "hyphen", etc. */
	if (ascii)
		return (0);
	fdprintf(ptid, "x T %s\n", devname);
	fdprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert);
	fdprintf(ptid, "x init\n");	/* do initialization for particular device */
  /*
	for (i = 1; i <= nfonts; i++)
		fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
	fdprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth);
	fdprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n",
		dev.nchtab, dev.lchname, dev.nchtab+128-32);
	fdprintf(ptid, "x xxx sizes:\nx xxx ");
	for (i = 0; i < nsizes; i++)
		fdprintf(ptid, " %d", pstab[i]);
	fdprintf(ptid, "\nx xxx chars:\nx xxx ");
	for (i = 0; i < dev.nchtab; i++)
		fdprintf(ptid, " %s", &chname[chtab[i]]);
	fdprintf(ptid, "\nx xxx\n");
  */

	return (0);
}
Esempio n. 7
0
int main(int c, const char *v[])
{
	register int rflag = ttyflg;

	/* initialise storage allocation */
	blokinit();

	stdsigs();

	setbrk(BRKINCR);
	addblok((POS) 0);

	/* set names from userenv */
	sh_getenv();

	/* look for restricted */
/*	if(c>0 && any('r', *v) ) { rflag=0 ;} */

	/* look for options */
	dolc = options(c, v);
	if (dolc < 2)
		flags |= stdflg;

	if ((flags & stdflg) == 0)
		dolc--;

	dolv = v + c - dolc;
	dolc--;

	/* return here for shell file execution */
	setjmp(subshell);

	/* number of positional parameters */
	assnum(&dolladr, dolc);
	cmdadr = (char *)dolv[0];

	/* set pidname */
	assnum(&pidadr, getpid());

	/* set up temp file names */
	settmp();

	/* default ifs */
	dfault(&ifsnod, sptbnl);

	if ((beenhere++) == FALSE) {	/* ? profile */
		if (*cmdadr == '-'
		    && (input = pathopen(nullstr, profile)) >= 0) {
			exfile(rflag);
			flags &= ~ttyflg;
			;
		}
		if (rflag == 0) {
			flags |= rshflg;
		}

		/* open input file if specified */
		if (comdiv) {
			estabf(comdiv);
			input = -1;
		} else {
			input = ((flags & stdflg) ? 0 : chkopen(cmdadr));
			comdiv--;
			;
		}
//      } else {        *execargs=(char *)dolv; /* for `ps' cmd */
		;
	}
	exfile(0);
	done();
}
Esempio n. 8
0
void
addblok(unsigned int reqd)
{
	if (stakbot == 0) {
		brkbegin = setbrk(3 * BRKINCR);
		/*
		 * setbrk() returns 8 byte aligned address
		 * but we could need larger align in future
		 */
		brkbegin = (unsigned char *)round(brkbegin, ALIGNSIZ);
		bloktop = (struct blk *)brkbegin;
	}

	if (stakbas != staktop) {
		unsigned char *rndstak;
		struct blk *blokstak;

		if (staktop >= brkend)
			growstak(staktop);
		pushstak(0);
		rndstak = (unsigned char *)round(staktop, ALIGNSIZ);
		blokstak = (struct blk *)(stakbas) - 1;
		blokstak->word = stakbsy;
		stakbsy = blokstak;
		bloktop->word = (struct blk *)(Rcheat(rndstak) | BUSY);
		bloktop = (struct blk *)(rndstak);
	}
	reqd += brkincr;
	reqd &= ~(brkincr - 1);
	blokp = bloktop;
	/*
	 * brkend points to the first invalid address.
	 * make sure bloktop is valid.
	 */
	if ((unsigned char *)&bloktop->word >= brkend) {
		if (setbrk((unsigned)((unsigned char *)
		    (&bloktop->word) - brkend + sizeof (struct blk))) ==
		    (unsigned char *)-1)
			error(nospace);
	}
	bloktop = bloktop->word = (struct blk *)(Rcheat(bloktop) + reqd);
	if ((unsigned char *)&bloktop->word >= brkend) {
		if (setbrk((unsigned)((unsigned char *)
		    (&bloktop->word) - brkend + sizeof (struct blk))) ==
		    (unsigned char *)-1)
			error(nospace);
	}
	bloktop->word = (struct blk *)(brkbegin + 1);
	{
		unsigned char *stakadr = (unsigned char *)
							(bloktop + 2);
		unsigned char *sp = stakadr;
		if (reqd = (staktop-stakbot)) {
			if (stakadr + reqd >= brkend)
				growstak(stakadr + reqd);
			while (reqd-- > 0)
				*sp++ = *stakbot++;
			sp--;
		}
		staktop = sp;
		if (staktop >= brkend)
			growstak(staktop);
		stakbas = stakbot = stakadr;
	}
}