Esempio n. 1
0
/* public helper routine: fmt out a null terminated string already in hand */
int
fmtstrcpy(Fmt *f, char *s)
{
	int p, i;
	if(!s)
		return _fmtcpy(f, "<nil>", 5, 5);
	/* if precision is specified, make sure we don't wander off the end */
	if(f->flags & FmtPrec){
		p = f->prec;
		for(i = 0; i < p; i++)
			if(s[i] == 0)
				break;
		return _fmtcpy(f, s, utfnlen(s, i), i);	/* BUG?: won't print a partial rune at end */
	}

	return _fmtcpy(f, s, utflen(s), strlen(s));
}
Esempio n. 2
0
File: errfmt.c Progetto: 8l/inferno
int
errfmt(Fmt *f)
{
	char buf[ERRMAX];

	rerrstr(buf, sizeof buf);
	return _fmtcpy(f, buf, utflen(buf), strlen(buf));
}
Esempio n. 3
0
/* public helper routine: fmt out a null terminated string already in hand */
int
fmtstrcpy(Fmt *f, char *s)
{
	int i, j;
	Rune r;

	if(!s)
		return _fmtcpy(f, "<nil>", 5, 5);
	/* if precision is specified, make sure we don't wander off the end */
	if(f->flags & FmtPrec){
		i = 0;
		for(j=0; j<f->prec && s[i]; j++)
			i += chartorune(&r, s+i);
		return _fmtcpy(f, s, j, i);
	}
	return _fmtcpy(f, s, utflen(s), strlen(s));
}
Esempio n. 4
0
/* fmt out one character */
int
_charfmt(Fmt *f)
{
	char x[1];

	x[0] = va_arg(f->args, int);
	f->prec = 1;
	return _fmtcpy(f, x, 1, 1);
}
Esempio n. 5
0
File: fltfmt.c Progetto: 8l/inferno
int
_floatfmt(Fmt *fmt, double f)
{
	char s[FDIGIT+10];

	xdtoa(fmt, s, f);
	fmt->flags &= FmtWidth|FmtLeft;
	_fmtcpy(fmt, s, strlen(s), strlen(s));
	return 0;
}
Esempio n. 6
0
int
_floatfmt(Fmt *fmt, double f)
{
	char s[1+NEXP10+1+FDIGIT+1];

	/*
	 * The max length of a %f string is
	 *	'[+-]'+"max exponent"+'.'+"max precision"+'\0'
	 * which is 341 currently.
	 */	
	xdtoa(fmt, s, f);
	fmt->flags &= FmtWidth|FmtLeft;
	_fmtcpy(fmt, s, strlen(s), strlen(s));
	return 0;
}
Esempio n. 7
0
/* public helper routine: fmt out a null terminated rune string already in hand */
int
fmtrunestrcpy(Fmt *f, Rune *s)
{
	Rune *e;
	int n, p;

	if(!s)
		return _fmtcpy(f, "<nil>", 5, 5);
	/* if precision is specified, make sure we don't wander off the end */
	if(f->flags & FmtPrec){
		p = f->prec;
		for(n = 0; n < p; n++)
			if(s[n] == 0)
				break;
	}else{
		for(e = s; *e; e++)
			;
		n = e - s;
	}
	return _fmtrcpy(f, s, n);
}