1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/*
* reftypes.c
*
* Copyright (c) Chris Putnam 2003-2021
*
* Source code released under the GPL version 2
*
*/
#include <stdio.h>
#include <string.h>
#include "is_ws.h"
#include "fields.h"
#include "reftypes.h"
int
get_reftype( const char *p, long refnum, char *progname, variants *all, int nall, char *tag, int *is_default, int chattiness )
{
int i;
p = skip_ws( p );
*is_default = 0;
for ( i=0; i<nall; ++i ) {
if ( !strncasecmp( all[i].type, p, strlen(all[i].type) ) )
return i;
}
*is_default = 1;
if ( chattiness==REFTYPE_CHATTY ) {
if ( progname ) fprintf( stderr, "%s: ", progname );
fprintf( stderr, "Did not recognize type '%s' of refnum %ld (%s).\n"
"\tDefaulting to %s.\n", p, refnum, tag, all[0].type );
}
return 0;
}
int
process_findoldtag( const char *oldtag, int reftype, variants all[], int nall )
{
variants *v;
int i;
v = &(all[reftype]);
for ( i=0; i<v->ntags; ++i ) {
if ( !strcasecmp( (v->tags[i]).oldstr, oldtag ) )
return i;
}
return -1;
}
/* translate_oldtag()
*/
int
translate_oldtag( const char *oldtag, int reftype, variants all[], int nall,
int *processingtype, int *level, char **newtag )
{
int n;
n = process_findoldtag( oldtag, reftype, all, nall );
if ( n!=-1 ) {
*processingtype = ((all[reftype]).tags[n]).processingtype;
*level = ((all[reftype]).tags[n]).level;
*newtag = ((all[reftype]).tags[n]).newstr;
return 1;
}
return 0;
}
|