Beispiel #1
0
static int
generate_citekey( fields *info, int nref )
{
	newstr citekey;
	int n1, n2;
	char *p, buf[100];
	newstr_init( &citekey );
	n1 = fields_find( info, "AUTHOR", 0 );
	if ( n1==-1 ) n1 = fields_find( info, "AUTHOR", -1 );
	n2 = fields_find( info, "YEAR", 0 );
	if ( n2==-1 ) n2 = fields_find( info, "YEAR", -1 );
	if ( n2==-1 ) n2 = fields_find( info, "PARTYEAR", 0 );
	if ( n2==-1 ) n2 = fields_find( info, "PARTYEAR", -1 );
	if ( n1!=-1 && n2!=-1 ) {
		p = info->data[n1].data;
		while ( p && *p && *p!='|' ) {
			if ( !is_ws( *p ) ) newstr_addchar( &citekey, *p ); 
			p++;
		}
		p = info->data[n2].data;
		while ( p && *p ) {
			if ( !is_ws( *p ) ) newstr_addchar( &citekey, *p );
			p++;
		}
		fields_add( info, "REFNUM", citekey.data, 0 );
	} else {
		sprintf( buf, "ref%d\n", nref );
		newstr_strcpy( &citekey, buf );
	}
	newstr_free( &citekey );
	return fields_find( info, "REFNUM", -1 );
}
Beispiel #2
0
/* name_nocomma()
 *
 * names in the format "H. F. Author"
 */
void
name_nocomma( char *start, newstr *outname )
{
	char *p, *last, *end;
	int uplast, lowlast, upfirst, lowfirst, splitfirst;

	/* move to end */
	p = start;
	while ( *p && *(p+1) ) p++;

	/* point to last name */
	end = p;
	while ( p>start && !is_ws( *p ) ) p--;
	if ( !strcasecmp( p, "Jr." ) || !strcasecmp( p, "III" ) ) {
		while ( p>start && is_ws( *p ) ) p--;
		while ( p>start && !is_ws( *p ) ) p--;
	}
	last = p;

	p = skip_ws( p );

	/* look for upper and lower case in last name */
	check_case( p, end+1, &uplast, &lowlast );

	/* copy last name */
	while ( p<=end )
		newstr_addchar( outname, *p++ );

	if ( start==last ) return;   /*Only last name */

	/* Given names */
	newstr_addchar( outname, '|' );

	/* look for upper and lower case in given name(s) */
	check_case( start, last, &upfirst, &lowfirst );
	splitfirst = should_split( uplast, lowlast, upfirst, lowfirst );

	/* copy given name(s), splitfirst to identify cases of "HF Author" */
	p = start;
	while ( p!=last ) {
		if ( *p!=' ' && *p!='\t' ) {
			if ( !(splitfirst && ( *p=='.' || *p=='-' ) ) ) {
				p = name_addmultibytechar( outname, p, last );
				if ( splitfirst )
					newstr_addchar(outname,'|');
			} else p++;
		} else {
			while ( p!=last && ( *p==' ' || *p=='\t' ) )
				p++;
			if ( p!=last && !splitfirst )
				newstr_addchar( outname, '|' );
		}
	}
}
const char* SkParse::FindHex(const char str[], uint32_t* value)
{
    SkASSERT(str);
    str = skip_ws(str);

    if (!is_hex(*str))
        return NULL;

    uint32_t n = 0;
    int max_digits = 8;
    int digit;

    while ((digit = to_hex(*str)) >= 0)
    {
        if (--max_digits < 0)
            return NULL;
        n = (n << 4) | digit;
        str += 1;
    }

    if (*str == 0 || is_ws(*str))
    {
        if (value)
            *value = n;
        return str;
    }
    return NULL;
}
Beispiel #4
0
static void
addpage( fields *info, char *p, int level )
{
	newstr page;
	newstr_init( &page );
	p = skip_ws( p );
	while ( *p && !is_ws(*p) && *p!='-' && *p!='\r' && *p!='\n' ) 
		newstr_addchar( &page, *p++ );
	if ( page.len>0 ) fields_add( info, "PAGESTART", page.data, level );
	newstr_empty( &page );
	while ( *p && (is_ws(*p) || *p=='-' ) ) p++;
	while ( *p && !is_ws(*p) && *p!='-' && *p!='\r' && *p!='\n' ) 
		newstr_addchar( &page, *p++ );
	if ( page.len>0 ) fields_add( info, "PAGEEND", page.data, level );
	newstr_free( &page );
}
Beispiel #5
0
static char *
bibtex_item( char *p, newstr *s )
{
	int nquotes = 0;
	int nbrackets = 0;
	while ( *p ) {
		if ( !nquotes && !nbrackets ) {
			if ( *p==',' || *p=='=' || *p=='}' || *p==')' )
				goto out;
		}
		if ( *p=='\"' && *(p-1)!='\\') {
			nquotes = ( nquotes==0 );
			newstr_addchar( s, *p );
		} else if ( *p=='{' ) {
			nbrackets++;
			/*if ( s->len!=0 )*/ newstr_addchar( s, *p );
		} else if ( *p=='}' ) {
			nbrackets--;
			/*if ( nbrackets>0 )*/ newstr_addchar( s, *p );
		} else {
			if ( s->len!=0 || ( s->len==0 && !is_ws( *p ) ) )
				newstr_addchar( s, *p );
		}
		p++;
	}
out:
	newstr_trimendingws( s );
	return p;
}
Beispiel #6
0
static const char* skip_ws(const char str[])
{
    SkASSERT(str);
    while (is_ws(*str))
        str++;
    return str;
}
Beispiel #7
0
static void
bibtex_split( list *tokens, newstr *s )
{
	newstr currtok;
	int nquotes = 0, nbrackets = 0;
	int i, n = s->len;
	newstr_init( &currtok );
	for ( i=0; i<n; ++i ) {
		if ( s->data[i]=='\"' ) {
			if ( nquotes ) nquotes = 0;
			else nquotes = 1;
			newstr_addchar( &currtok, '\"' );
		} else if ( s->data[i]=='{' ) {
			nbrackets++;
			newstr_addchar( &currtok, '{' );
		} else if ( s->data[i]=='}' ) {
			nbrackets--;
			newstr_addchar( &currtok, '}' );
		} else if ( s->data[i]=='#' && !nquotes && !nbrackets ) {
			if ( currtok.len ) list_add( tokens, currtok.data );
			newstr_empty( &currtok );
		} else if ( !is_ws( s->data[i] ) || nquotes || nbrackets ) {
			newstr_addchar( &currtok, s->data[i] );
		}
	}
	if ( currtok.len ) list_add( tokens, currtok.data );
	for ( i=0; i<tokens->n; ++i ) {
		newstr_trimendingws( &(tokens->str[i]) );
	}
	newstr_free( &currtok );
}
Beispiel #8
0
/* <AuthorList CompleteYN="Y">
 *    <Author>
 *        <LastName>Barondeau</LastName>
 *        <ForeName>David P</ForeName>
 *        ( or <FirstName>David P</FirstName> )
 *        <Initials>DP</Initials>
 *    </Author>
 *    <Author>
 *        <CollectiveName>Organization</CollectiveName>
 *    </Author>
 * </AuthorList>
 */
static int
medin_author( xml *node, newstr *name )
{
	char *p;
	if ( xml_tagexact( node, "LastName" ) ) {
		if ( name->len ) {
			newstr_prepend( name, "|" );
			newstr_prepend( name, xml_data( node ) );
		}
		else newstr_strcat( name, xml_data( node ) );
	} else if ( xml_tagexact( node, "ForeName" ) || 
	            xml_tagexact( node, "FirstName" ) ) {
		p = xml_data( node );
		while ( p && *p ) {
			if ( name->len ) newstr_addchar( name, '|' );
			while ( *p && *p==' ' ) p++;
			while ( *p && *p!=' ' ) newstr_addchar( name, *p++ );
		}
	} else if ( xml_tagexact( node, "Initials" ) && !strchr( name->data, '|' )) {
		p = xml_data( node );
		while ( p && *p ) {
			if ( name->len ) newstr_addchar( name, '|' );
			if ( !is_ws(*p) ) newstr_addchar( name, *p++ );
		}
	}
	if ( node->next ) medin_author( node->next, name );
	return BIBL_OK;
}
Beispiel #9
0
static void
cleanup_wiley_author( fields *endin, int n )
{	
	newstr tmp, tmppart;
	int i, nauthor = 0;
	newstrs_init( &tmp, &tmppart, NULL );
	newstr_newstrcpy( &tmp, &( endin->data[n] ) );
	i = 0;
	while ( i<tmp.len ) {
		if ( tmp.data[i]==',' ) {
			if ( nauthor==0 )
				newstr_newstrcpy( &(endin->data[n]), &tmppart );
			else
				fields_add( endin, endin->tag[n].data,
					tmppart.data, endin->level[n] );
			newstr_empty( &tmppart );
			nauthor++;
			while ( i<tmp.len && is_ws( tmp.data[i] ) ) i++;
		} else {
			newstr_addchar( &tmppart, tmp.data[i] );
		}
		i++;
	}
	newstrs_free( &tmp, &tmppart, NULL );
}
Beispiel #10
0
/* <AuthorList CompleteYN="Y">
 *    <Author>
 *        <LastName>Barondeau</LastName>
 *        <ForeName>David P</ForeName>
 *        ( or <FirstName>David P</FirstName> )
 *        <Initials>DP</Initials>
 *    </Author>
 *    <Author>
 *        <CollectiveName>Organization</CollectiveName>
 *    </Author>
 * </AuthorList>
 */
static int
medin_author( xml *node, str *name )
{
	char *p;
	if ( xml_tag_matches( node, "LastName" ) ) {
		if ( str_has_value( name ) ) {
			str_prepend( name, "|" );
			str_prepend( name, xml_value_cstr( node ) );
		}
		else str_strcat( name, xml_value( node ) );
	} else if ( xml_tag_matches( node, "ForeName" ) ||
	            xml_tag_matches( node, "FirstName" ) ) {
		p = xml_value_cstr( node );
		while ( p && *p ) {
			if ( str_has_value( name ) ) str_addchar( name, '|' );
			while ( *p==' ' ) p++;
			while ( *p && *p!=' ' ) str_addchar( name, *p++ );
		}
	} else if ( xml_tag_matches( node, "Initials" ) && !strchr( name->data, '|' )) {
		p = xml_value_cstr( node );
		while ( p && *p ) {
			if ( str_has_value( name ) ) str_addchar( name, '|' );
			if ( !is_ws(*p) ) str_addchar( name, *p++ );
		}
	}
	if ( node->next ) medin_author( node->next, name );
	return BIBL_OK;
}
Beispiel #11
0
void
name_add( fields *info, char *tag, char *q, int level, list *asis, list *corps )
{
	newstr inname;
	char *p, *start, *end;

	if ( !q ) return;

	newstr_init( &inname );

	while ( *q ) {

		start = q = skip_ws( q );

		/* strip tailing whitespace and commas */
		while ( *q && *q!='|' ) q++;
		end = q;
		while ( is_ws( *end ) || *end==',' || *end=='|' || *end=='\0' )
			end--;

		for ( p=start; p<=end; p++ )
			newstr_addchar( &inname, *p );

		/* keep "names" like " , " from coredumping program */
		if ( inname.len ) {
			name_process( info, tag, level, &inname, asis, corps );
			newstr_empty( &inname );
		}

		if ( *q=='|' ) q++;
	}
	newstr_free( &inname );
}
static size_t linebreak(const char text[], const char stop[], const SkPaint& paint, SkScalar margin)
{
    const char* start = text;

    SkAutoGlyphCache    ac(paint, NULL);
    SkGlyphCache*       cache = ac.getCache();
    SkFixed             w = 0;
    SkFixed             limit = SkScalarToFixed(margin);
    SkAutoKern          autokern;

    const char* word_start = text;
    int         prevWS = true;

    while (text < stop)
    {
        const char* prevText = text;
        SkUnichar   uni = SkUTF8_NextUnichar(&text);
        int         currWS = is_ws(uni);
        const SkGlyph&  glyph = cache->getUnicharMetrics(uni);

        if (!currWS && prevWS)
            word_start = prevText;
        prevWS = currWS;

        w += autokern.adjust(glyph) + glyph.fAdvanceX;
        if (w > limit)
        {
            if (currWS) // eat the rest of the whitespace
            {
                while (text < stop && is_ws(SkUTF8_ToUnichar(text)))
                    text += SkUTF8_CountUTF8Bytes(text);
            }
            else    // backup until a whitespace (or 1 char)
            {
                if (word_start == start)
                {
                    if (prevText > start)
                        text = prevText;
                }
                else
                    text = word_start;
            }
            break;
        }
    }
    return text - start;
}
Beispiel #13
0
static int
attrib_parser(char *v, uint32_t *output, int olen,
	      int (*fn)(uint32_t *output, int olen, const char *attrib, 
			const char *value))
{
  const char *attrib, *value;
  char quote;
  char *attrib_stop;

  while(*v) {
    while(is_ws(*v))
      v++;
    if(!*v)
      return olen;
    attrib = v;
    while(1) {
      if(!*v)
	return olen;
      if(is_ws(*v) || *v == '=')
	break;
      v++;
    }
    attrib_stop = v;
    while(is_ws(*v))
      v++;
    if(*v != '=')
      return olen;
    v++;
    *attrib_stop = 0;
    while(is_ws(*v))
      v++;
    quote = *v++;
    if(quote != '"' && quote != '\'')
      return olen;
    value = v;
    while(1) {
      if(!*v)
	return olen;
      if(*v == quote)
	break;
      v++;
    }
    *v++ = 0;
    olen = fn(output, olen, attrib, value);
  }
  return olen;
}
Beispiel #14
0
char *
skip_ws( char *p )
{
	if ( p ) {
		while ( is_ws( *p ) ) p++;
	}
	return p;
}
Beispiel #15
0
char *
skip_notws( char *p )
{
	if ( p ) {
		while ( *p && !is_ws( *p ) ) p++;
	}
	return p;
}
Beispiel #16
0
void
str_trimendingws( str *s )
{
	assert( s );
	while ( s->len > 0 && is_ws( s->data[s->len-1] ) ) {
		s->data[s->len-1] = '\0';
		s->len--;
	}
}
Beispiel #17
0
/* copac names appear to always start with last name first, but don't
 * always seem to have a comma after the name
 *
 * editors seem to be stuck in as authors with the tag "[Editor]" in it
 */
static void
copacin_addname( fields *info, char *tag, newstr *name, int level, list *asis,
	list *corps )
{
	char *usetag = tag, editor[]="EDITOR", *p;
	int comma = 0;
	if ( strstr( name->data,"[Editor]" ) ) {
		newstr_findreplace( name, "[Editor]", "" );
		usetag = editor;
	}
	p = skip_ws( name->data );
	while ( *p && !is_ws( *p ) ) {
		if ( *p==',' ) comma++;
		p++;
	}
	if ( !comma && is_ws( *p ) ) *p = ',';
	name_add( info, usetag, name->data, level, asis, corps );
}
Beispiel #18
0
static int
bibtex_split( list *tokens, newstr *s )
{
	int i, n = s->len, nbrackets = 0, status = BIBL_OK;
	newstr tok, *t;

	newstr_init( &tok );

	for ( i=0; i<n; ++i ) {
		if ( s->data[i]=='{' && ( i==0 || s->data[i-1]!='\\' ) ) {
			nbrackets++;
			newstr_addchar( &tok, '{' );
		} else if ( s->data[i]=='}' && ( i==0 || s->data[i-1]!='\\' ) ) {
			nbrackets--;
			newstr_addchar( &tok, '}' );
		} else if ( !is_ws( s->data[i] ) || nbrackets ) {
			newstr_addchar( &tok, s->data[i] );
		} else if ( is_ws( s->data[i] ) ) {
			if ( tok.len ) {
				t = list_add( tokens, &tok );
				if ( !t ) {
					status = BIBL_ERR_MEMERR;
					goto out;
				}
			}
			newstr_empty( &tok );
		}
	}
	if ( tok.len ) {
		t = list_add( tokens, &tok );
		if ( !t ) {
			status = BIBL_ERR_MEMERR;
			goto out;
		}
	}

	for ( i=0; i<tokens->n; ++i ) {
		newstr_trimstartingws( list_get( tokens, i ) );
		newstr_trimendingws( list_get( tokens, i ) );
	}
out:
	newstr_free( &tok );
	return status;
}
Beispiel #19
0
int get_num( int num[] )
{
	int c, sign;
	unsigned total = 0;

	/* Chomp & get first integer character */
	while( ( c = getchar() ) != EOF && c != '-' && !is_num( c ) );
	/* Negative integer */
	if( c == '-' )
	{
		sign = -1;
		total = 0;
	}
	/* Positive integer */
	else if( is_num( c ) )
	{
		sign = 1;
		total = c - '0';
	}
	/* Errors */
	else if( c == EOF )
	{
		num[ 1 ] = EOF; // tells main() to quit loop
		return ERROR; // no input
	}
	else
	{
		return ERROR; // not an integer
	}

	/* Get the rest of the integer characters */
	while( ( c = getchar() ) != EOF && is_num( c ) )
	{
		total = total * 10 + c - '0';
	}
	num[ 0 ] = total * sign; // assign sign (hehehe)

	/* Determine if integer entry has any errors */
	if( c == EOF )
	{
		num[ 1 ] = EOF;
		return NOERR; // final integer before end of file
	}
	else if( is_ws( c ) )
	{
		return NOERR; // integer separated by white space
	}
	else
	{
		return ERROR; // not an integer
	}
}
Beispiel #20
0
static void
adddate( fields *info, char *tag, char *newtag, char *p, int level )
{
	char *months[12]={ "January", "February", "March", "April",
		"May", "June", "July", "August", "September",
		"October", "November", "December" };
	char month[10];
	int found,i,part;
	newstr date;
	newstr_init( &date );
	part = (!strncasecmp(newtag,"PART",4));
	if ( !strcasecmp( tag, "%D" ) ) {
		while ( *p ) newstr_addchar( &date, *p++ );
		if ( date.len>0 ) {
			if ( part ) 
				fields_add(info, "PARTYEAR", date.data, level);
			else
				fields_add( info, "YEAR", date.data, level );
		}
	} else if ( !strcasecmp( tag, "%8" ) ) {
		while ( *p && *p!=' ' && *p!=',' ) newstr_addchar( &date, *p++ );
		if ( date.len>0 ) {
			found = -1;
			for ( i=0; i<12 && found==-1; ++i )
				if ( !strncasecmp( date.data, months[i], 3 ) )
					found = i;
			if ( found!=-1 ) {
				if (found>8) sprintf( month, "%d", found+1 );
				else sprintf( month, "0%d", found+1 );
				if ( part ) 
					fields_add( info, "PARTMONTH", month, level );
				else    fields_add( info, "MONTH", month, level );
			} else {
				if ( part )
					fields_add( info, "PARTMONTH", date.data, level );
				else
					fields_add( info, "MONTH", date.data, level );
			}
		}
		newstr_empty( &date );
		while ( is_ws( *p ) ) p++;
		while ( *p && *p!='\n' && *p!=',' ) newstr_addchar( &date, *p++ );
		if ( date.len>0 && date.len<3 ) {
			if ( part )
				fields_add( info, "PARTDAY", date.data, level );
			else
				fields_add( info, "DAY", date.data, level );
		}
	}
	newstr_free( &date );
}
Beispiel #21
0
static int
process_pages( fields *info, newstr *s, int level )
{
	int fstatus, status = BIBL_OK;
	newstr page;
	char *p;

	newstr_findreplace( s, " ", "" );
	if ( s->len==0 ) return 1;

	newstr_init( &page );
	p = skip_ws( s->data );
	while ( *p && !is_ws(*p) && *p!='-' && *p!='\r' && *p!='\n' && *p!=-30 )
		newstr_addchar( &page, *p++ );
	if ( page.len>0 ) {
		fstatus = fields_add( info, "PAGESTART", page.data, level );
		if ( fstatus!=FIELDS_OK ) {
			status = BIBL_ERR_MEMERR;
			goto out;
		}
	}

	while ( *p && (is_ws(*p) || *p=='-' ) ) p++;
	if ( *p && is_utf8_emdash( p ) ) p+=3;
	if ( *p && is_utf8_endash( p ) ) p+=3;

	newstr_empty( &page );
	while ( *p && !is_ws(*p) && *p!='-' && *p!='\r' && *p!='\n' )
		newstr_addchar( &page, *p++ );
	if ( page.len>0 ) {
		fstatus = fields_add( info, "PAGEEND", page.data, level );
		if ( fstatus!=FIELDS_OK ) status = BIBL_ERR_MEMERR; 
	}

out:
	newstr_free( &page );
	return status;
}
Beispiel #22
0
void
str_trimstartingws( str *s )
{
	char *p, *q;
	int n;

	assert( s );

	if ( s->len==0 || !is_ws( s->data[0] ) ) return;

	n = 0;
	p = s->data;
	while ( is_ws( *p ) ) p++;

	q = s->data;
	while ( *p ) {
		*q++ = *p++;
		n++;
	}
	*q = '\0';

	s->len = n;
}
Beispiel #23
0
Sip_Header_Value_CSeq::Sip_Header_Value_CSeq(const std::string &build_from)
    : Sip_Header_Value(SIP_HEADER_TYPE_CSEQ,sipHeaderValueCSeqTypeStr)
{
    unsigned maxlen=(unsigned)build_from.size();
    unsigned i=0;

    while (i<maxlen && is_ws(build_from[i]))
        i++;

    std::string num;
    while (i<maxlen && ((build_from[i]>='0' && build_from[i]<='9') || build_from[i]=='-'))
    {
        num+=build_from[i];
        i++;
    }

    while (i<maxlen && is_ws(build_from[i]) )
        i++;

    _method = build_from.substr(i);

    set_cseq(atoi((trim(num)).c_str()));
}
Beispiel #24
0
static mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
    int splits = -1;
    mp_obj_t sep = mp_const_none;
    if (n_args > 1) {
        sep = args[1];
        if (n_args > 2) {
            splits = MP_OBJ_SMALL_INT_VALUE(args[2]);
        }
    }
    assert(sep == mp_const_none);
    (void)sep; // unused; to hush compiler warning
    mp_obj_t res = mp_obj_new_list(0, NULL);
    GET_STR_DATA_LEN(args[0], s, len);
    const byte *top = s + len;
    const byte *start;

    // Initial whitespace is not counted as split, so we pre-do it
    while (s < top && is_ws(*s)) s++;
    while (s < top && splits != 0) {
        start = s;
        while (s < top && !is_ws(*s)) s++;
        rt_list_append(res, mp_obj_new_str(start, s - start, false));
        if (s >= top) {
            break;
        }
        while (s < top && is_ws(*s)) s++;
        if (splits > 0) {
            splits--;
        }
    }

    if (s < top) {
        rt_list_append(res, mp_obj_new_str(s, top - s, false));
    }

    return res;
}
Beispiel #25
0
static int
endin_addpage( fields *info, char *p, int level )
{
	newstr page;
	int ok;
	newstr_init( &page );
	p = skip_ws( p );
	while ( *p && !is_ws(*p) && *p!='-' && *p!='\r' && *p!='\n' ) 
		newstr_addchar( &page, *p++ );
	if ( page.len>0 ) {
		ok = fields_add( info, "PAGESTART", page.data, level );
		if ( !ok ) return 0;
	}
	newstr_empty( &page );
	while ( *p && (is_ws(*p) || *p=='-' ) ) p++;
	while ( *p && !is_ws(*p) && *p!='-' && *p!='\r' && *p!='\n' ) 
		newstr_addchar( &page, *p++ );
	if ( page.len>0 ) {
		ok = fields_add( info, "PAGEEND", page.data, level );
		if ( !ok ) return 0;
	}
	newstr_free( &page );
	return 1;
}
Beispiel #26
0
/* refnum should start with a non-number and not include spaces -- ignore this */
static void
output_refnum( fields *f, int n, FILE *outptr )
{
	char *p = fields_value( f, n, FIELDS_CHRP_NOUSE );
/*	if ( p && ((*p>='0' && *p<='9') || *p=='-' || *p=='_' ))
		fprintf( outptr, "ref" );*/
	while ( p && *p ) {
		if ( !is_ws(*p) ) fprintf( outptr, "%c", *p );
/*		if ( (*p>='A' && *p<='Z') ||
		     (*p>='a' && *p<='z') ||
		     (*p>='0' && *p<='9') ||
		     (*p=='-') || (*p=='
		     (*p=='_') ) fprintf( outptr, "%c", *p );*/
		p++;
	}
}
Beispiel #27
0
int
get_reftype( char *p, long refnum )
{
	int i;
	while ( is_ws( *p ) ) p++;
	for ( i=0; i<nall; ++i ) {
		if ( !strncasecmp( all[i].type, p, strlen(all[i].type)) ){
/*			fprintf( stderr,"SUCCESS strncasecmp('%s', '%s', %d )\n", all[i].type,p,strlen(all[i].type)); */
			return i;
		}else {
/*			fprintf( stderr,"FAILURE strncasecmp('%s', '%s', %d )\n", all[i].type,p,strlen(all[i].type));*/
		}
	}
	fprintf( stderr, "Warning: Did not recognize type '%s' of refnum %ld, defaulting to generic.\n",
			p, refnum );
	return 0;
}
Beispiel #28
0
void
str_stripws( str *s )
{
	unsigned long len = 0;
	char *p, *q;
	assert( s );
	if ( s->len ) {
		p = q = s->data;
		while ( *p ) {
			if ( !is_ws( *p ) ) {
				*q = *p;
				q++;
				len++;
			}
			p++;
		}
		*q = '\0';
	}
	s->len = len;
}
Beispiel #29
0
/*
 * name_comma()
 *
 * names in the format "Author, H.F.", w/comma
 */
void
name_comma( char *p, newstr *outname )
{
	char *q;
	int uplast, lowlast, upfirst, lowfirst, splitfirst;

	q = p;
	while ( *q && ( *q!=',' ) ) q++;
	check_case( p, q, &uplast, &lowlast );

	while ( *p && ( *p!=',' ) ) 
		newstr_addchar( outname, *p++ );

	if ( *p==',' ) p++;
	p = skip_ws( p );

	q = p;
	while ( *q ) q++;
	check_case( p, q, &upfirst, &lowfirst );
	splitfirst = should_split( uplast, lowlast, upfirst, lowfirst );

	if ( !*p ) return; /* Only last name */

	/* add each part of the given name */
	newstr_addchar( outname, '|' );

	/* splitfirst to identify cases of Author, HF */
	while ( *p ) {
		if ( !is_ws( *p ) ) {
			if ( ! (splitfirst && ( *p=='.' || *p=='-' ) ) ) {
				p=name_addmultibytechar(outname,p,NULL);
				if ( splitfirst )
					newstr_addchar( outname, '|' );
			} else p++;
		} else if ( *(p+1)!='\0' ) {
			if ( !splitfirst )
				newstr_addchar( outname, '|' );
			p++;
		} else p++;
	}
}
Beispiel #30
0
char *
xml_tree( char *p, xml *onode )
{
	newstr tag;
	xml_attrib *attrib;
	int type, is_style = 0;

	newstr_init( &tag );

	while ( *p ) {
		/* retain white space for <style> tags in endnote xml */
		if ( onode->tag && onode->tag->data && 
			!strcasecmp(onode->tag->data,"style") ) is_style=1;
		while ( *p && *p!='<' ) {
			if ( onode->value->len>0 || is_style || !is_ws( *p ) )
				newstr_addchar( onode->value, *p );
			p++;
		}
		if ( *p=='<' ) {
			newstr_empty( &tag );
			p = xml_processtag( p, &tag, &attrib, &type );
			if ( type==XML_OPEN || type==XML_OPENCLOSE ||
			     type==XML_DESCRIPTOR ) {
				xml *nnode = xml_new();
				newstr_newstrcpy( nnode->tag, &tag );
				nnode->a = attrib;
				xml_appendnode( onode, nnode );
				if ( type==XML_OPEN )
					p = xml_tree( p, nnode );
			} else if ( type==XML_CLOSE ) {
				/*check to see if it's closing for this one*/
				goto out; /* assume it's right for now */
			}
		}
	}
out:
	newstr_free( &tag );
	return p;
}