contrib/mdocml/out.c
int
a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
{
	char		 buf[BUFSIZ], hasd;
	int		 i;
	enum roffscale	 unit;

	if ('\0' == *src)
		return(0);

	i = hasd = 0;

	switch (*src) {
	case ('+'):
		src++;
		break;
	case ('-'):
		buf[i++] = *src++;
		break;
	default:
		break;
	}

	if ('\0' == *src)
		return(0);

	while (i < BUFSIZ) {
		if ( ! isdigit((u_char)*src)) {
			if ('.' != *src)
				break;
			else if (hasd)
				break;
			else
				hasd = 1;
		}
		buf[i++] = *src++;
	}

	if (BUFSIZ == i || (*src && *(src + 1)))
		return(0);

	buf[i] = '\0';

	switch (*src) {
	case ('c'):
		unit = SCALE_CM;
		break;
	case ('i'):
		unit = SCALE_IN;
		break;
	case ('P'):
		unit = SCALE_PC;
		break;
	case ('p'):
		unit = SCALE_PT;
		break;
	case ('f'):
		unit = SCALE_FS;
		break;
	case ('v'):
		unit = SCALE_VS;
		break;
	case ('m'):
		unit = SCALE_EM;
		break;
	case ('\0'):
		if (SCALE_MAX == def)
			return(0);
		unit = SCALE_BU;
		break;
	case ('u'):
		unit = SCALE_BU;
		break;
	case ('M'):
		unit = SCALE_MM;
		break;
	case ('n'):
		unit = SCALE_EN;
		break;
	default:
		return(0);
	}

	/* FIXME: do this in the caller. */
	if ((dst->scale = atof(buf)) < 0)
		dst->scale = 0;
	dst->unit = unit;
	return(1);
}
/* 
 * Convert a `scaling unit' to a consistent form, or fail.  Scaling
 * units are documented in groff.7, mdoc.7, man.7.
 */
Convert a `scaling unit' to a consistent form, or fail.
Convert a ` scaling unit ' to a consistent form or fail .
int
a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
{
	char		 buf[BUFSIZ], hasd;
	int		 i;
	enum roffscale	 unit;
	if ('\0' == *src)
		return(0);
	i = hasd = 0;
	switch (*src) {
	case ('+'):
		src++;
		break;
	case ('-'):
		buf[i++] = *src++;
		break;
	default:
		break;
	}
	if ('\0' == *src)
		return(0);
	while (i < BUFSIZ) {
		if ( ! isdigit((u_char)*src)) {
			if ('.' != *src)
				break;
			else if (hasd)
				break;
			else
				hasd = 1;
		}
		buf[i++] = *src++;
	}
	if (BUFSIZ == i || (*src && *(src + 1)))
		return(0);
	buf[i] = '\0';
	switch (*src) {
	case ('c'):
		unit = SCALE_CM;
		break;
	case ('i'):
		unit = SCALE_IN;
		break;
	case ('P'):
		unit = SCALE_PC;
		break;
	case ('p'):
		unit = SCALE_PT;
		break;
	case ('f'):
		unit = SCALE_FS;
		break;
	case ('v'):
		unit = SCALE_VS;
		break;
	case ('m'):
		unit = SCALE_EM;
		break;
	case ('\0'):
		if (SCALE_MAX == def)
			return(0);
		unit = SCALE_BU;
		break;
	case ('u'):
		unit = SCALE_BU;
		break;
	case ('M'):
		unit = SCALE_MM;
		break;
	case ('n'):
		unit = SCALE_EN;
		break;
	default:
		return(0);
	}
	if ((dst->scale = atof(buf)) < 0)
		dst->scale = 0;
	dst->unit = unit;
	return(1);
}
int a2roffsu ( const char * src , struct roffsu * dst , enum roffscale def ) { char buf [ BUFSIZ ] , hasd ; int i ; enum roffscale unit ; if ( ' \0 ' == * src ) return ( 0 ) ; i = hasd = 0 ; switch ( * src ) { case ( ' ' ) : src ++ ; break ; case ( ' ' ) : buf [ i ++ ] = * src ++ ; break ; default : break ; } if ( ' \0 ' == * src ) return ( 0 ) ; while ( i < BUFSIZ ) { if ( ! isdigit ( ( u_char ) * src ) ) { if ( ' ' != * src ) break ; else if ( hasd ) break ; else hasd = 1 ; } buf [ i ++ ] = * src ++ ; } if ( BUFSIZ == i || ( * src && * ( src + 1 ) ) ) return ( 0 ) ; buf [ i ] = ' \0 ' ; switch ( * src ) { case ( ' ' ) : unit = SCALE_CM ; break ; case ( ' ' ) : unit = SCALE_IN ; break ; case ( ' ' ) : unit = SCALE_PC ; break ; case ( ' ' ) : unit = SCALE_PT ; break ; case ( ' ' ) : unit = SCALE_FS ; break ; case ( ' ' ) : unit = SCALE_VS ; break ; case ( ' ' ) : unit = SCALE_EM ; break ; case ( ' \0 ' ) : if ( SCALE_MAX == def ) return ( 0 ) ; unit = SCALE_BU ; break ; case ( ' ' ) : unit = SCALE_BU ; break ; case ( ' ' ) : unit = SCALE_MM ; break ; case ( ' ' ) : unit = SCALE_EN ; break ; default : return ( 0 ) ; } if ( ( dst -> scale = atof ( buf ) ) < 0 ) dst -> scale = 0 ; dst -> unit = unit ; return ( 1 ) ; }
Convert a `scaling unit' to a consistent form, or fail.
Convert a ` scaling unit ' to a consistent form or fail .
/* FIXME: do this in the caller. */