This is refdata.c in view mode; [Download] [Up]
/* refdata.c * cm, 20 Dec 90 * * module to handle inserting/retrieving reference style data items */ /* * Copyright (c) 1991 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ #include <stdio.h> #include <ctype.h> #include <mif.h> #include <bib.h> #include <ref.h> extern char *prt_execent(); static RefEnt *refent_root; /* -> linked list of reference ents defined */ static RefEnt *misc_refentp; /* -> Misc entry if one has been defined */ extern char *bibstyle; /* name of the current style */ int new_para; /* allocate memory for new ref entry. */ RefEnt * new_refent() { register RefEnt *rp = (RefEnt *) getmem( sizeof( RefEnt )); rp->re_exec = NULL; rp->re_next = NULL; rp->re_mandatory = rp->re_optional = NULL; return( rp ); } /* allocate memory for new execution entry. */ ExecEnt * new_execent() { register ExecEnt *ep = (ExecEnt *) getmem( sizeof( ExecEnt )); ep->ex_true = ep->ex_false = ep->ex_next = NULL; return( ep ); } /* link in new field's exectree into list of exectrees * for this Ref type. */ store_exectree( rep, ep ) register RefEnt *rep; ExecEnt *ep; { register ExecEnt *np; if( ! rep ) { err( WARN, "store_exectree() - ref node is NULL!\n" ); return; } if( rep->re_exec == NULL ) { rep->re_exec = ep; return; } for( np=rep->re_exec; np->ex_next; np=np->ex_next ) ; np->ex_next = ep; } /* link new refent into the list. */ store_refent( rep ) RefEnt *rep; { register RefEnt *rp; if( refent_root == NULL ) refent_root = rep; else { for( rp = refent_root; rp->re_next; rp = rp->re_next ) ; rp->re_next = rep; } /* save pointer if this is the 'Misc' definition. */ if( (!misc_refentp) && (rep->re_type == reftype("misc")) ) misc_refentp = rep; } /* test execution trees */ prt_refents() { register RefEnt *rp; register ExecEnt *ep; for( rp=refent_root; rp; rp=rp->re_next ) { err(WARN, "-----------------\nREFERENCE = %s\n", refname(rp->re_type)); for( ep=rp->re_exec; ep; ep=ep->ex_next ) exec_tree( 0, ep ); err(WARN, "DONE\n-----------------\n"); } } /* find the style entry for the specified * bib entry, and output the fields present in the bib * entry by executing the style (ref type) exec tree. */ do_bibent( bep ) register BibEnt *bep; { RefEnt *rp; register ExecEnt *ep; if( rp = find_refent( bep->be_reftype )) { new_para=1; for( ep = rp->re_exec; ep; ep = ep->ex_next ) { if( current_font != F_REGULAR ) mif_chfont( O_BIB, F_REGULAR ); exec_tree( ep, bep ); } mif_pgfend(bep); } else err( WARN, "No <%s> or <Misc> reference type defined.\n", refname( bep->be_reftype)); } /* retrieve pointer to the specified reference type * in the style tree. Return pointer to 'Misc' if * no matches or NULL if all fails. */ static RefEnt * find_refent( rtype ) RefType rtype; { RefEnt *rp; for( rp=refent_root; rp; rp=rp->re_next ) if( rp->re_type == rtype ) break; if( rp ) return( rp ); return( misc_refentp ); } RefFldList * new_fldlist() { RefFldList *fldp; fldp = (RefFldList *)getmem( sizeof( RefFldList )); fldp->fl_flds = 0; fldp->fl_next = NULL; return( fldp ); } insert_altflds( flp, altfp ) RefFldList *flp; RefFldList *altfp; { register RefFldList *fp; if( flp->fl_next == NULL ) flp->fl_next = altfp; else { for( fp=flp; fp->fl_next; fp=fp->fl_next ) ; fp->fl_next = altfp; } } verify_bibents( bep ) register BibEnt *bep; { register RefEnt *rp; register RefFldList *flp; register long rollcall; register i; int first; char alt[64]; if( !bep ) return; verify_bibents( bep->be_l ); verify_bibent( bep ); if( !(rp = find_refent( bep->be_reftype ))) { err( WARN, "verify_bibent(): No <%s> or <Misc> reference type defined.\n", refname( bep->be_reftype)); return; } rollcall = bep->be_rollcall; /* verify mandatory fields */ if( (flp = rp->re_mandatory) && flp->fl_flds) { /* unique mandatory fields */ for(i=0; i<32; i++) if( TESTFLD( flp->fl_flds, i )) if( ! FLDPRESENT(rollcall, i)) err(WARN, "Mandatory <%s> field MISSING in bibentry <%s>\n", fldname(i), bep->be_xref ); /* alternative mandatory fields */ while( flp = flp->fl_next ) { for(first=1, i=0; i<32; i++) { if( TESTFLD( flp->fl_flds, i )) { if( first ) { strcpy( alt, fldname(i) ); first=0; } else { strcat( alt, "|" ); strcat( alt, fldname(i)); } } if( FLDPRESENT(rollcall, i)) break; } if( i==32 ) err(WARN, "Mandatory <%s> alt. fields MISSING in bibentry <%s>\n", alt, bep->be_xref ); } } verify_bibents( bep->be_r ); } verify_bibent( bep ) register BibEnt *bep; { register RefEnt *rp; register RefFldList *flp; register long rollcall; register i; int first; char alt[64]; if( !bep ) return; if( !(rp = find_refent( bep->be_reftype ))) { err( WARN, "No <%s> or <Misc> reference type defined, %s, line %d.\n", refname( bep->be_reftype), mif_filename(F_BIB), mif_lineno(F_BIB)); return; } rollcall = bep->be_rollcall; /* verify mandatory fields */ if( (flp = rp->re_mandatory) && flp->fl_flds) { /* unique mandatory fields */ for(i=0; i<32; i++) if( TESTFLD( flp->fl_flds, i )) if( ! FLDPRESENT(rollcall, i)) err(WARN,"Mandatory <%s> field MISSING in <%s>,\n\t(%s near line %d)\n", fldname(i), bep->be_xref, mif_filename(F_BIB), mif_lineno(F_BIB)); /* alternative mandatory fields */ while( flp = flp->fl_next ) { for(first=1, i=0; i<32; i++) { if( TESTFLD( flp->fl_flds, i )) { if( first ) { strcpy( alt, fldname(i) ); first=0; } else { strcat( alt, "|" ); strcat( alt, fldname(i)); } } if( FLDPRESENT(rollcall, i)) break; } if( i==32 ) err(WARN,"Mandatory <%s> alt. fields MISSING in <%s>,\n\t(%s near line %d)\n", alt, bep->be_xref, mif_filename(F_BIB), mif_lineno(F_BIB)); } } } print_refent_defs() { register RefEnt *rp; register RefFldList *flp; register i; int first; printf( "\nStyle Definition for `%s':\n\n", bibstyle ); for( rp=refent_root; rp; rp=rp->re_next ) { printf("%s\n", refname(rp->re_type)); printf( "\tMandatory fields\n"); if( !(flp = rp->re_mandatory)) printf( "\t\t(none)\n"); else { /* unique mandatory fields */ for(i=0; i<32; i++) if( TESTFLD( flp->fl_flds, i )) printf( "\t\t%s\n", fldname(i) ); /* alternative mandatory fields */ while( flp = flp->fl_next ) { for(first=1, i=0; i<32; i++) if( TESTFLD( flp->fl_flds, i )) { if( !first ) printf(" OR %s", fldname(i)); else { first=0; printf( "\t\t%s", fldname(i) ); } } printf("\n"); } } printf( "\tOptional fields\n"); if( !(flp = rp->re_optional)) printf( "\t\t(none)\n"); else { /* unique mandatory fields */ for(i=0; i<32; i++) if( TESTFLD( flp->fl_flds, i )) printf( "\t\t%s\n", fldname(i) ); /* alternative mandatory fields */ while( flp = flp->fl_next ) { for(first=1,i=0; i<32; i++) if( TESTFLD( flp->fl_flds, i )) { if( !first ) printf(" OR %s", fldname(i)); else { first=0; printf( "\t\t%s", fldname(i) ); } } printf("\n"); } } } }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.