[bdf] Clean up the atom property parsing.
* src/bdflib.c (bdf_is_atom_): Refactor code with fewer checks. (bdf_list_join_): Return NULL. (bdf_add_comment_): Use const argument. (bdf_get_property): Ditto, ditto, make the function static. * src/bdf.h (bdf_get_property): Remove prototype.
This commit is contained in:
parent
0a3836c97d
commit
7ab541a28b
|
@ -239,10 +239,6 @@ FT_BEGIN_HEADER
|
||||||
FT_LOCAL( void )
|
FT_LOCAL( void )
|
||||||
bdf_free_font( bdf_font_t* font );
|
bdf_free_font( bdf_font_t* font );
|
||||||
|
|
||||||
FT_LOCAL( bdf_property_t * )
|
|
||||||
bdf_get_property( char* name,
|
|
||||||
bdf_font_t* font );
|
|
||||||
|
|
||||||
FT_LOCAL( bdf_property_t * )
|
FT_LOCAL( bdf_property_t * )
|
||||||
bdf_get_font_property( bdf_font_t* font,
|
bdf_get_font_property( bdf_font_t* font,
|
||||||
const char* name );
|
const char* name );
|
||||||
|
|
|
@ -378,7 +378,7 @@
|
||||||
*alen = 0;
|
*alen = 0;
|
||||||
|
|
||||||
if ( list == NULL || list->used == 0 )
|
if ( list == NULL || list->used == 0 )
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
dp = list->field[0];
|
dp = list->field[0];
|
||||||
for ( i = j = 0; i < list->used; i++ )
|
for ( i = j = 0; i < list->used; i++ )
|
||||||
|
@ -887,18 +887,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_LOCAL_DEF( bdf_property_t* )
|
static bdf_property_t*
|
||||||
bdf_get_property( char* name,
|
bdf_get_property( const char* name,
|
||||||
bdf_font_t* font )
|
bdf_font_t* font )
|
||||||
{
|
{
|
||||||
size_t* propid;
|
size_t* propid;
|
||||||
|
|
||||||
|
|
||||||
if ( name == NULL || *name == 0 )
|
if ( name == NULL || *name == 0 )
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if ( ( propid = ft_hash_str_lookup( name, &(font->proptbl) ) ) == NULL )
|
if ( ( propid = ft_hash_str_lookup( name, &(font->proptbl) ) ) == NULL )
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if ( *propid >= num_bdf_properties_ )
|
if ( *propid >= num_bdf_properties_ )
|
||||||
return font->user_props + ( *propid - num_bdf_properties_ );
|
return font->user_props + ( *propid - num_bdf_properties_ );
|
||||||
|
@ -944,7 +944,7 @@
|
||||||
|
|
||||||
static FT_Error
|
static FT_Error
|
||||||
bdf_add_comment_( bdf_font_t* font,
|
bdf_add_comment_( bdf_font_t* font,
|
||||||
char* comment,
|
const char* comment,
|
||||||
unsigned long len )
|
unsigned long len )
|
||||||
{
|
{
|
||||||
char* cp;
|
char* cp;
|
||||||
|
@ -1053,27 +1053,24 @@
|
||||||
bdf_property_t* p;
|
bdf_property_t* p;
|
||||||
|
|
||||||
|
|
||||||
*name = sp = ep = line;
|
sp = ep = line;
|
||||||
|
|
||||||
while ( *ep && *ep != ' ' && *ep != '\t' )
|
while ( *ep && *ep != ' ' && *ep != '\t' )
|
||||||
ep++;
|
ep++;
|
||||||
|
|
||||||
hold = -1;
|
hold = *ep;
|
||||||
if ( *ep )
|
*ep = '\0';
|
||||||
{
|
|
||||||
hold = *ep;
|
|
||||||
*ep = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = bdf_get_property( sp, font );
|
p = bdf_get_property( sp, font );
|
||||||
|
|
||||||
/* Restore the character that was saved before any return can happen. */
|
|
||||||
if ( hold != -1 )
|
|
||||||
*ep = (char)hold;
|
|
||||||
|
|
||||||
/* If the property exists and is not an atom, just return here. */
|
/* If the property exists and is not an atom, just return here. */
|
||||||
if ( p && p->format != BDF_ATOM )
|
if ( p && p->format != BDF_ATOM )
|
||||||
|
{
|
||||||
|
*ep = (char)hold; /* Undo NUL-termination. */
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*name = sp;
|
||||||
|
|
||||||
/* The property is an atom. Trim all leading and trailing whitespace */
|
/* The property is an atom. Trim all leading and trailing whitespace */
|
||||||
/* and double quotes for the atom value. */
|
/* and double quotes for the atom value. */
|
||||||
|
@ -1081,25 +1078,26 @@
|
||||||
ep = line + linelen;
|
ep = line + linelen;
|
||||||
|
|
||||||
/* Trim the leading whitespace if it exists. */
|
/* Trim the leading whitespace if it exists. */
|
||||||
if ( *sp )
|
if ( sp < ep )
|
||||||
*sp++ = 0;
|
do
|
||||||
while ( *sp &&
|
sp++;
|
||||||
( *sp == ' ' || *sp == '\t' ) )
|
while ( *sp == ' ' || *sp == '\t' );
|
||||||
sp++;
|
|
||||||
|
|
||||||
/* Trim the leading double quote if it exists. */
|
/* Trim the leading double quote if it exists. */
|
||||||
if ( *sp == '"' )
|
if ( *sp == '"' )
|
||||||
sp++;
|
sp++;
|
||||||
|
|
||||||
*value = sp;
|
*value = sp;
|
||||||
|
|
||||||
/* Trim the trailing whitespace if it exists. */
|
/* Trim the trailing whitespace if it exists. */
|
||||||
while ( ep > sp &&
|
if ( sp < ep )
|
||||||
( *( ep - 1 ) == ' ' || *( ep - 1 ) == '\t' ) )
|
do
|
||||||
*--ep = 0;
|
*ep-- = '\0';
|
||||||
|
while ( *ep == ' ' || *ep == '\t' );
|
||||||
|
|
||||||
/* Trim the trailing double quote if it exists. */
|
/* Trim the trailing double quote if it exists. */
|
||||||
if ( ep > sp && *( ep - 1 ) == '"' )
|
if ( *ep == '"' )
|
||||||
*--ep = 0;
|
*ep = '\0';
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue