/************************************************************************* purpose: duplicate text with only a..z A..Z 0..9 and _ **************************************************************************/ char *strdup_nobadchars(const char *text) { char *duplicate, *s; duplicate = strdup_noblanks(text); s = duplicate; while (*s) { if (!('a' <= *s && *s <= 'z') && !('A' <= *s && *s <= 'Z') && !('0' <= *s && *s <= '9')) *s = '_'; s++; } return duplicate; }
char * strdup_nobadchars(char * text) /************************************************************************* purpose: duplicate text with only a..z A..Z 0..9 and _ ************************************************************************/ { char *dup, *s; dup = strdup_noblanks(text); s = dup; while (*s) { if (!('a' <= *s && *s <= 'z') && !('A' <= *s && *s <= 'Z') && !('0' <= *s && *s <= '9')) *s = '_'; s++; } return dup; }
void CmdCite(int code) /****************************************************************************** purpose: handles \cite ******************************************************************************/ { char punct[4]="[],"; char *text, *str1; char *keys, *key, *next_keys; char *option = NULL; char *pretext = NULL; /* Setup punctuation and read options before citation */ g_current_cite_paren=TRUE; *g_last_author_cited='\0'; if (g_document_bibstyle == BIBSTYLE_STANDARD){ option = getBracketParam(); } if (g_document_bibstyle == BIBSTYLE_APALIKE){ strcpy(punct,"();"); option = getBracketParam(); } if (g_document_bibstyle == BIBSTYLE_AUTHORDATE){ strcpy(punct,"();"); option = getBracketParam(); } if (g_document_bibstyle == BIBSTYLE_NATBIB){ pretext = getBracketParam(); option = getBracketParam(); strcpy(punct,"();"); if (code!=CITE_P && code!=CITE_P_STAR && code!=CITE_ALP && code!=CITE_ALP_STAR && code!=CITE_YEAR_P) g_current_cite_paren=FALSE; } if (g_document_bibstyle == BIBSTYLE_APACITE){ pretext = getAngleParam(); option = getBracketParam(); strcpy(punct,"();"); if (code!=CITE_CITE && code!=CITE_FULL && code!=CITE_SHORT && code!=CITE_YEAR) g_current_cite_paren=FALSE; g_current_cite_type=code; } text = getBraceParam(); str1 = strdup_nocomments(text); free(text); text=str1; if (strlen(text)==0) { free(text); if (pretext) free(pretext); if (option) free(option); return; } /* output text before citation */ if (g_current_cite_paren) fprintRTF("\n%c", punct[0]); if (pretext && g_document_bibstyle == BIBSTYLE_APACITE ) { ConvertString(pretext); fprintRTF(" "); } /* now start processing keys */ keys = strdup_noblanks(text); free(text); key = keys; next_keys = popCommaName(key); g_current_cite_item=0; while (key) { char *s, *t; g_current_cite_item++; s = ScanAux("bibcite", key, 0); /* look up bibliographic reference */ if (g_document_bibstyle == BIBSTYLE_APALIKE) { /* can't use Word refs for APALIKE or APACITE*/ t = s ? s : key; ConvertString(t); } if (g_document_bibstyle == BIBSTYLE_AUTHORDATE) { t = s ? s : key; if (code==CITE_SHORT) g_suppress_name=TRUE; ConvertString(t); if (code==CITE_SHORT) g_suppress_name=FALSE; } if (g_document_bibstyle == BIBSTYLE_APACITE) { /* */ t = s ? s : key; g_current_cite_seen=citation_used(key); ConvertString(t); } if (g_document_bibstyle == BIBSTYLE_NATBIB) { diagnostics(2,"natbib key=[%s] <%s>",key, s); if (s) { g_current_cite_seen=citation_used(key); ConvertNatbib(s,code,pretext,option); } else ConvertString(key); } if (g_document_bibstyle == BIBSTYLE_STANDARD) { /* */ char *signet = strdup_nobadchars(key); t = s ? s : signet; /* if .aux is missing or incomplete use original citation */ if (g_fields_use_REF) { fprintRTF("{\\field{\\*\\fldinst{\\lang1024 REF BIB_%s \\\\* MERGEFORMAT }}",signet); fprintRTF("{\\fldrslt{"); } ConvertString(t); if (g_fields_use_REF) fprintRTF("}}}"); if (signet) free(signet); } if (next_keys) fprintRTF("%c ",punct[2]); /* punctuation between citations */ key=next_keys; next_keys=popCommaName(key); /* key modified to be a single key */ if (s) free(s); } /* final text after citation */ if (option && (g_document_bibstyle == BIBSTYLE_APACITE || g_document_bibstyle == BIBSTYLE_AUTHORDATE)) { fprintRTF(", "); ConvertString(option); } if (g_current_cite_paren) fprintRTF("\n%c", punct[1]); if (keys) free(keys); if (option) free(option); if (pretext) free(pretext); }