Exemplo n.º 1
0
void
setline(void)
{
	register tchar *i;
	tchar c, delim;
	int	length;
	int	w, cnt, rem, temp;
	tchar linebuf[NC];

	if (ismot(c = getch()))
		return;
	delim = c;
	vflag = 0;
	dfact = EM;
	length = quant(hatoi(), HOR);
	dfact = 1;
	if (!length) {
		eat(delim);
		return;
	}
s0:
	if (c = getch(), issame(c, delim)) {
		ch = c;
		c = RULE | chbits;
	} else if (cbits(c) == FILLER)
		goto s0;
	w = width(c);
	i = linebuf;
	if (length < 0) {
		*i++ = makem(length);
		length = -length;
	}
	if (!(cnt = length / w)) {
		*i++ = makem(-(temp = ((w - length) / 2)));
		*i++ = c;
		*i++ = makem(-(w - length - temp));
		goto s1;
	}
	if ((rem = length % w)) {
		if (connectchar(c))
			*i++ = c | ZBIT;
		*i++ = makem(rem);
	}
	if (cnt) {
		*i++ = RPT;
		*i++ = cnt;
		*i++ = c;
	}
s1:
	*i++ = 0;
	eat(delim);
	pushback(linebuf);
}
Exemplo n.º 2
0
unsigned hatoi_validate(const char *s, const char *msg)
{
	uint64_t v = hatoi(s);

	if (v & (v - 1)) {
		fprintf(stderr, "%s must be a power of two\n", msg);
		exit(EXIT_FAILURE);
	}

	v /= 512;

	if (v > USHRT_MAX) {
		fprintf(stderr, "%s too large\n", msg);
		exit(EXIT_FAILURE);
	}

	if (!v) {
		fprintf(stderr, "%s too small\n", msg);
		exit(EXIT_FAILURE);
	}

	return v;
}
Exemplo n.º 3
0
int
main()
{
    int i;
    struct timeval t, et;
    char string[] = "2007";
    int aa;

    
    gettimeofday( &t, NULL );

    aa = strlen( string );
    for(i=0;i<10000000;i++){
         fuckfunc( hatoi( string, aa ));
    //    printf( "[%x] \n", hatoi( string, aa ));
    }
    gettimeofday( &et, NULL );

    printf( "%d\n", ( et.tv_sec - t.tv_sec ) * 1000000 +
            ( et.tv_usec - t.tv_usec ));
    return 0;
    
}
Exemplo n.º 4
0
void
setdraw (void)	/* generate internal cookies for a drawing function */
{
	int i, dx[NPAIR], dy[NPAIR], type;
	tchar c, delim;
#ifndef	NROFF
	int	hpos, vpos;
	int j, k;
	tchar drawbuf[NC];
#else
	extern int tlp, utf8;
	char drawbuf[NC];
#endif	/* NROFF */

	/* input is \D'f dx dy dx dy ... c' (or at least it had better be) */
	/* this does drawing function f with character c and the */
	/* specified dx,dy pairs interpreted as appropriate */
	/* pairs are deltas from last point, except for radii */

	/* l dx dy:	line from here by dx,dy */
	/* c x:		circle of diameter x, left side here */
	/* e x y:	ellipse of diameters x,y, left side here */
	/* a dx1 dy1 dx2 dy2:
			ccw arc: ctr at dx1,dy1, then end at dx2,dy2 from there */
	/* ~ dx1 dy1 dx2 dy2...:
			spline to dx1,dy1 to dx2,dy2 ... */
	/* f dx dy ...:	f is any other char:  like spline */

	if (ismot(c = getch()))
		return;
	delim = c;
	type = cbits(getch());
	for (i = 0; i < NPAIR ; i++) {
		do {
			c = getch();
			if (issame(c, delim)) goto argend;
		} while (cbits(c) == ' ');
	/* ought to pick up optional drawing character */
		if (cbits(c) != ' ')
			ch = c;
		vflag = 0;
		dfact = type == DRAWTHICKNESS ? 1 : EM;
		dx[i] = quant(hatoi(), HOR);
		if (dx[i] > MAXMOT)
			dx[i] = MAXMOT;
		else if (dx[i] < -MAXMOT)
			dx[i] = -MAXMOT;
		do {
			c = getch();
			if (issame(c, delim)) {
				dy[i++] = 0;
				goto argend;
			}
		} while (cbits(c) == ' ');
		if (cbits(c) != ' ')
			ch = c;
		vflag = 1;
		dfact = lss;
		dy[i] = quant(hatoi(), VERT);
		if (type == DRAWTHICKNESS)
			dy[i] = 0;
		else if (dy[i] > MAXMOT)
			dy[i] = MAXMOT;
		else if (dy[i] < -MAXMOT)
			dy[i] = -MAXMOT;
	}
argend:
	dfact = 1;
	vflag = 0;
#ifndef NROFF
	drawbuf[0] = DRAWFCN | chbits | ZBIT;
	drawbuf[1] = type | chbits | ZBIT;
	drawbuf[2] = '.' | chbits | ZBIT;	/* use default drawing character */
	hpos = vpos = 0;
	for (k = 0, j = 3; k < i; k++) {
		drawbuf[j++] = MOT | ((dx[k] >= 0) ?
				sabsmot(dx[k]) : (NMOT | sabsmot(-dx[k])));
		drawbuf[j++] = MOT | VMOT | ((dy[k] >= 0) ?
				sabsmot(dy[k]) : (NMOT | sabsmot(-dy[k])));
		hpos += dx[k];
		vpos += dy[k];
	}
	if (type == DRAWELLIPSE || type == DRAWELLIPSEFI) {
		drawbuf[5] = drawbuf[4] | NMOT;	/* so the net vertical is zero */
		j = 6;
	}
	if (gflag && (type == DRAWPOLYGON || type == DRAWPOLYGONFI) &&
			(hpos || vpos)) {
		drawbuf[j++] = MOT | ((hpos < 0) ?
				sabsmot(-hpos) : (NMOT | sabsmot(hpos)));
		drawbuf[j++] = MOT | VMOT | ((vpos < 0) ?
				sabsmot(-vpos) : (NMOT | sabsmot(vpos)));
	}
	drawbuf[j++] = DRAWFCN | chbits | ZBIT;	/* marks end for ptout */
	drawbuf[j] = 0;
	pushback(drawbuf);
#else
	switch (type) {
	case 'l':
		if (dx[0] && !dy[0]) {
			if (dx[0] < 0) {
				snprintf(drawbuf, sizeof(drawbuf), "\\h'%du'",
				    dx[0]);
				cpushback(drawbuf);
			}
			snprintf(drawbuf, sizeof(drawbuf), "\\l'%du%s'",
			    dx[0], tlp ? "\\&-" : utf8 ? "\\U'2500'" : "");
			cpushback(drawbuf);
		} else if (dy[0] && !dx[0]) {
			snprintf(drawbuf, sizeof(drawbuf), "\\L'%du%s'",
			    dy[0], tlp ? "|" : utf8 ? "\\U'2502'" : "");
			cpushback(drawbuf);
		}
	}
#endif
}
Exemplo n.º 5
0
void
setvline(void)
{
	register int i;
	tchar c, _d, delim, rem, ver, neg;
	int	cnt, v;
	tchar vlbuf[NC];
	register tchar *vlp;

	if (ismot(c = getch()))
		return;
	delim = c;
	dfact = lss;
	vflag++;
	i = quant(hatoi(), VERT);
	dfact = 1;
	if (!i) {
		eat(delim);
		vflag = 0;
		return;
	}
	if (c = getch(), issame(c, delim)) {
		c = BOXRULE | chbits;	/*default box rule*/
	} else {
		_d = getch();
		if (!issame(_d, delim))
			nodelim(delim);
	}
	c |= ZBIT;
	neg = 0;
	if (i < 0) {
		i = -i;
		neg = NMOT;
	}
#ifdef NROFF
	v = 2 * t.Halfline;
#endif
#ifndef NROFF
	v = EM;
#endif
	cnt = i / v;
	rem = makem(i % v) | neg;
	ver = makem(v) | neg;
	vlp = vlbuf;
	if (!neg)
		*vlp++ = ver;
	if (absmot(rem) != 0) {
		*vlp++ = c;
		*vlp++ = rem;
	}
	while ((vlp < (vlbuf + NC - 3)) && cnt--) {
		*vlp++ = c;
		*vlp++ = ver;
	}
	*(vlp - 2) &= ~ZBIT;
	if (!neg)
		vlp--;
	*vlp++ = 0;
	pushback(vlbuf);
	vflag = 0;
}