|
|
1.1 root 1: #
2: # general - general style awk script
3: # every style script must begin with this general header
4: #
5:
6:
7:
8:
9: BEGIN {
10:
11: #
12: # used by fixname for parsing name string
13: #
14: verbatim="%verbatim[ ]*((\\([^\\)]*\\))|(\\[[^\\]]*\\])|(<[^>]*>)|({[^}]*}))"
15:
16: titles["Mr."] = 1;
17: titles["Mr"] = 1;
18: titles["Mrs."] = 1;
19: titles["Mrs"] = 1;
20: titles["Ms."] = 1;
21: titles["Ms"] = 1;
22: titles["Dr."] = 1;
23: titles["Dr"] = 1;
24: titles["Fr."] = 1;
25: titles["Fr"] = 1;
26: titles["Rev."] = 1;
27: titles["Rev"] = 1;
28:
29: postfix["I"] = 1;
30: postfix["II"] = 1;
31: postfix["III"] = 1;
32: postfix["IV"] = 1;
33: postfix["Jr."] = 1;
34: postfix["Jr"] = 1;
35: postfix["M.D."] = 1;
36: postfix["MD"] = 1;
37: postfix["S.J."] = 1;
38: postfix["SJ"] = 1;
39:
40: prefix["Mac"] = 1;
41: prefix["Mc"] = 1;
42: prefix["Van"] = 1;
43: prefix["Von"] = 1;
44: prefix["mac"] = 1;
45: prefix["mc"] = 1;
46: prefix["van"] = 1;
47: prefix["von"] = 1;
48: prefix["di"] = 1;
49: prefix["Di"] = 1;
50: prefix["de"] = 1;
51: prefix["De"] = 1;
52: prefix["D'"] = 1;
53: prefix["d'"] = 1;
54: prefix["Der"] = 1;
55: prefix["der"] = 1;
56: prefix["Del"] = 1;
57: prefix["del"] = 1;
58: prefix["La"] = 1;
59: prefix["la"] = 1;
60: prefix["L'"] = 1;
61: prefix["l'"] = 1;
62:
63:
64:
65: Monthcode["Foo"] = 00;
66: Monthcode["Jan"] = 01;
67: Monthcode["Feb"] = 02;
68: Monthcode["Mar"] = 03;
69: Monthcode["Apr"] = 04;
70: Monthcode["May"] = 05;
71: Monthcode["Jun"] = 06;
72: Monthcode["Jul"] = 07;
73: Monthcode["Aug"] = 08;
74: Monthcode["Sep"] = 09;
75: Monthcode["Oct"] = 10;
76: Monthcode["Nov"] = 11;
77: Monthcode["Dec"] = 12;
78: }
79:
80:
81: ##
82: ## Control and reference information from prefer
83: ##
84:
85: $1 == "%LETS_GO" {
86: print PASS;
87: if($2 == "nroff") nroff = 1;
88: if($3 == "rp") rp = 1;
89: }
90:
91:
92: $1 == "%BEGIN_CITE" {
93: bibno++;
94: cbibno++;
95: assoc = "";
96: allauthors[bibno] = "";
97: }
98:
99: $1 == "%T" { # check for refer format
100: if(refertitle == 0) {
101: print "Warning: reference data is in refer format; use pconvert to change to refer format" | "cat >&2";
102: }
103: refertitle++;
104: }
105:
106: /^%/ { sub(/[ \t]*$/,""); }
107:
108: $1 == "%author" {
109: if($2 ~ /^et/ && $3 ~ /^al/) {
110: aetal[bibno] = 1;
111: }
112: else {
113: a = ++authors[bibno];
114: fixname();
115: setauthor(bibno,a);
116: if(!aflag)
117: assoc = assoc Afull[bibno,a];
118: allauthors[bibno] = allauthors[bibno] Afull[bibno,a];
119: }
120: }
121:
122:
123: $1 == "%booktitle" { booktitle[bibno] = getrest();}
124:
125: $1 == "%address" { city[bibno] = getrest(); }
126:
127: $1 == "%date" { # assumes Month Day, Year
128: year[bibno] = $NF;
129: if(NF > 2) {
130: month[bibno] = substr($2,1,3);
131: if(NF == 4) {
132: day[bibno] = $3;
133: sub(",","",day[bibno]);
134: }
135: date[bibno] = getrest();
136: }
137: else date[bibno] = $NF;
138: if(!aflag)
139: assoc = assoc date[bibno];
140: }
141:
142: $1 == "%editor" {
143: if($2 ~ /^et/ && $3 ~ /^al/)
144: eetal[bibno] = 1;
145: else {
146: e = ++editors[bibno];
147: fixname();
148: seteditor(bibno,e);
149: }
150: }
151:
152: $1 == "%publisher" { issuer[bibno] = getrest(); }
153:
154: $1 == "%journal" { journal[bibno] = getrest(); }
155:
156: $1 == "%number" {
157: number[bibno] = $2;
158: if(NF > 2) numstr[bibno] = getrest();
159: }
160:
161: $1 == "%other" { other[bibno] = getrest(); }
162:
163: $1 == "%pages" {
164: pages[bibno] = getrest();
165: gsub(/- /,"-",pages[bibno]);
166: gsub(/ -/,"-",pages[bibno]);
167: }
168:
169: $1 == "%part" {
170: part[bibno] = $2
171: if(NF > 2) partstr[bibno] = getrest();
172: }
173:
174: $1 == "%report" { report[bibno] = getrest(); }
175:
176: $1 == "%tm" { tmno[bibno] = getrest(); }
177:
178: $1 == "%type" { reftype[bibno] = $2; }
179:
180: $1 == "%title" {
181: title[bibno] = getrest();
182: if(!aflag)
183: assoc = assoc title[bibno];
184: }
185:
186: $1 == "%volume" {
187: volume[bibno] = $2;
188: if(NF > 2) volstr[bibno] = getrest();
189: }
190:
191: $1 == "%also_begin" {
192: if(++aflag == 1) {
193: savebibno = bibno;
194: }
195: bibno = savebibno " " ++also[savebibno];
196: allauthors[bibno] = "";
197: pre_also[bibno] = getrest();
198: }
199:
200:
201: $1 == "%also_end" {
202: aflag--;
203: if(reftype[bibno] == "not_found" || reftype[savebibno] == "not_found") {
204: erasebib(bibno);
205: also[savebibno]--;
206: }
207:
208: else {
209: if(title[savebibno] == title[bibno])
210: title[bibno] = "";
211: if(allauthors[savebibno] == allauthors[bibno])
212: authors[bibno] = 0;
213: post_also[bibno] = getrest();
214: }
215: if(aflag)
216: bibno = savebibno " " aflag;
217: else
218: bibno = savebibno;
219: }
220:
221: $1 == "%no_cite" { no_cite[cbibno] = 1; }
222:
223: $1 == "%no_author" { no_author[cbibno] = 1; }
224:
225: $1 == "%no_date" { no_date[cbibno] = 1; }
226:
227: $1 == "%pre_text" { pre_text[cbibno] = getrest(); }
228:
229: $1 == "%post_text" { post_text[cbibno] = getrest(); }
230:
231: $1 == "%END_CITE" {
232: if(reftype[bibno] == "not_found") {
233: erasebib(bibno);
234: erasecite(cbibno);
235: bibno--;
236: cbibno--;
237: }
238: else {
239: assoc = assoc reftype[bibno];
240: if (biblist[assoc] != 0) {
241: erasebib(bibno);
242: bibno--;
243: }
244: else
245: biblist[assoc] = bibno;
246: uniqno[cbibno] = biblist[assoc];
247:
248: if (no_cite[cbibno] != 1) {
249: cites++;
250: bibptr[cites] = cbibno;
251: }
252: }
253: }
254:
255: $1 == "%END_LIST" {
256: if (cites > 0) {
257: citations($2);
258: cites = 0;
259: }
260: else printf $2;
261: print $1;
262: }
263:
264: $1 == "%BIBLIO" {
265: if(bibno > 0 && $2 != "no_bib") {
266: if(sortflag && PASS == "")
267: bibsort(SKEY);
268: bibliography();
269: }
270: print "%END_BIB";
271: }
272:
273: $1 == "%WHOLEBIB" {
274: if(bibno > 0) {
275: if ($2) {
276: sortflag = 1;
277: if($2 == "sort")
278: bibsort(SKEY);
279: else
280: bibsort($2);
281: }
282: else sortflag = 0;
283: bibliography();
284: }
285: print "%END_BIB";
286: }
287:
288:
289: ##
290: ## For two passes
291: ##
292: $1 == "%END_CITE2" {
293: cbibno++
294: if (no_cite[cbibno] != 1) {
295: cites++;
296: bibptr[cites] = cbibno;
297:
298: }
299: }
300:
301: $1 == "%END_LIST1" {
302: cites = 0;
303: print $2 "%END_LIST";
304: }
305:
306:
307: $1 == "%BIBLIO1" {
308: if(sortflag)
309: bibsort(SKEY);
310: cbibno = 0;
311: }
312:
313: $1 == "%DBINCLUDE" {
314: cbibno +=$2;
315: }
316:
317:
318:
319: ##############################################
320: ##
321: ## functions
322: ##
323: ##############################################
324:
325: ##
326: ## Sort the entire bibliography by the stated keys
327: ##
328: func bibsort(keys)
329: {
330: if (bibno == 0) return;
331:
332: "echo $$" | getline pid;
333: sortout = "/tmp/sort" pid;
334: sort = "sort -f -o " sortout;
335: for(k=1; k <=3; k++)
336: key[k] = substr(keys,k,1);
337: for(i = 1; i <= bibno; i++) {
338: for(k=1; k <=3; k++) {
339: if(key[k] == "a") {
340: if(authors[i] )
341: printf "%s\t", Asort[i] | sort;
342: else if(editors[i])
343: printf "%s\t", Esort[i] | sort;
344: else if(issuer[i])
345: printf "%s\t", issuer[i] | sort;
346: else
347: printf "%s\t", title[i] | sort;
348: }
349: else if(key[k] == "d") {
350: printf "%s", year[i] | sort;
351: printf "%2s", Monthcode[month[i]] | sort;
352: printf "%2s\t", day[i] | sort;
353: }
354: else if(key[k] == "t")
355: printf "%s\t", title[i] | sort;
356: else
357: printf " \t" | sort;
358: }
359: print i | sort;
360: }
361: close(sort);
362: FS = "\t";
363: for(i = 1; i <= bibno; i++) {
364: getline < sortout;
365: sortorder[i] = $4;
366: inverse[$4] = i;
367: }
368: FS = " ";
369: system("rm " sortout);
370: }
371:
372: ##
373: ## erase bibliographic entry
374: ##
375: func erasebib(b)
376: {
377: authors[b] = 0;
378: allauthors[b] = "";
379: aetal[b] = 0;
380: editors[b] = 0;
381: eetal[b] = 0;
382: title[b] = "";
383: booktitle[b] = "";
384: issuer[b] = "";
385: journal[b] = "";
386: number[b] = "";
387: other[b] = "";
388: pages[b] = "";
389: part[b] = "";
390: report[b] = "";
391: reftype[b] = "";
392: volume[b] = "";
393: volstr[b] = "";
394: date[b] = "";
395: year[b] = "";
396: month[b] = "Foo";
397: day[b] = "00";
398: city[b] = "";
399: Asort[b] = "";
400: Esort[b] = "";
401: also[b] = 0;
402: pre_also[b] = "";
403: post_also[b] = "";
404: }
405:
406:
407: ##
408: ## erase citation entry
409: ##
410: func erasecite(b) {
411: no_cite[b] = 0;
412: no_author[b] = 0;
413: no_date[b] = 0;
414: pre_text[b] = "";
415: post_text[b] = "";
416: }
417:
418: ##
419: ## sequence - dtermine if c is in a sequence c-1, c, c+1
420: ##
421: func sequence(c,n) {
422:
423: # take care of endpoints 1 and n
424: if (c == 1) return "no";
425: if (c == n) {
426: if(seq == "in") return "end";
427: else return "no"
428: }
429:
430: # ignore sequence if pretext or posttext exists
431:
432: text = 0;
433: if (pretext[bibptr[c-1]] || posttext[bibptr[c-1]] || \
434: pretext[bibptr[c]] || posttext[bibptr[c]] || \
435: pretext[bibptr[c+1]] || posttext[bibptr[c+1]] ) text = 1 ;
436:
437: # detect a sequence ..1,2,3..
438:
439: if((makemark(c-1) == makemark(c)-1) && (makemark(c+1) == makemark(c)+1)) {
440: if (text == 1)
441: if(seq == "in") return "end";
442: else return "no";
443: else return "in";
444: }
445:
446: # detect end ..7,8,22
447:
448: if((seq == "in") && (makemark(c+1) != makemark(c)+1)) return "end";
449: }
450:
451:
452:
453: ##
454: ## format a list of bibliographies
455: ## used by both reference_placement and reference_list
456: ##
457: func bibliography()
458: {
459: print ".in .5i";
460: for(i = 1; i <= bibno; i++) {
461: b = bibindex(i);
462: printref(b);
463: }
464: print ".in -5i"
465: print ".nr RF " bibno;
466: }
467:
468: ##
469: ## format a single reference
470: ##
471: func printref(b) {
472: if (reftype[b] == "book") book(b)
473: else if (reftype[b] == "article") article(b)
474: else if (reftype[b] == "review") review(b);
475: else if (reftype[b] == "incollection") incollection(b)
476: else if (reftype[b] == "inproceedings") inproceedings(b)
477: else if (reftype[b] == "techreport") techreport(b)
478: else if (reftype[b] == "phdthesis") thesis(b)
479: else if (reftype[b] == "mastersthesis") thesis(b)
480: else if (reftype[b] == "editedbook") editedbook(b)
481: else if (reftype[b] == "misc") default(b)
482: else if (reftype[b] == "pamphlet") pamphlet(b)
483: else if (reftype[b] == "manual") manual(b)
484: else if (reftype[b] == "proceedings") proceedings(b)
485: else if (reftype[b] == "tm") tm(b)
486: else if (reftype[b] == "unpublished") default(b)
487: else {
488: print "Unknown reference type " reftype[b] " for " Afull[b,1] " ... " title[b] ", " date[b] | "cat >&2";
489: default(b);
490: }
491: if (other[b]) {
492: printf ".\n" other[b];
493: if(substr(other[b],length(other[b]),1) != ".")
494: printf ".";
495: }
496: else printf ".";
497: if(also[b]) {
498: aprint++;
499: print "";
500: for(ia=1; ia <= also[b]; ia++) {
501: prea = pre_also[b " " ia]
502: if(prea) {
503: printf prea;
504: if(bracket(prea) == 0)
505: printf " ";
506: }
507: else printf "Also " ;
508: printref(b " " ia);
509: posta = post_also[b " " ia]
510: if(posta) {
511: if(bracket(posta) == 0)
512: printf " ";
513: print posta;
514: }
515: else print "";
516: }
517: aprint--;
518: }
519: else if(aprint == 0) print "";
520: }
521:
522: func bracket(string)
523: {
524: brack = substr(string,length(string));
525: if(brack ~ /[<>\(\){}\[\]]/)
526: return 1;
527: return 0;
528: }
529:
530: ##
531: ## fixverbatim
532: ## handle strings with %verbatim around them
533: ##
534: func fixverbatim()
535: {
536: vb = 0;
537: while(match($0,verbatim)) {
538: vb++;
539: beg=substr($0,1,RSTART-1);
540: mid=substr($0,RSTART,RLENGTH);
541: end=substr($0,RSTART+RLENGTH,length($0)-(RLENGTH+RSTART-1));
542: gsub("%verbatim[ ]*","",mid);
543: mid=substr(mid,2,length(mid)-2);
544: gsub(" ","\\\\&",mid);
545: $0 = beg mid end;
546: }
547: return vb;
548: }
549:
550:
551:
552: ##
553: ## fixname
554: ## parse namestring from %author and %editor into
555: ## Given Last Title and Post
556: ## e.g., Given = Fred P., Last = Smith, Title = Mr., Post = Jr.
557: ##
558: func fixname() {
559: verbflag = fixverbatim()
560: Given = "";
561: Last = "";
562: Title = "";
563: Post = "";
564: if(postfix[$NF]) { #....Jr.
565: Post = $NF;
566: NF--;
567: if(substr($NF,length($NF),1) == ",") {
568: $NF = substr($NF,1,length($NF)-1);
569: }
570: }
571: for(i=2; i<=NF; i++) { # look for field ending with ","
572: if(substr($i,length($i),1) == ",") {
573: $i = substr($i,1,length($i)-1);
574: break;
575: }
576: }
577: if (i < NF) { # Last, Given...
578: for(k=2; k<i; k++) {
579: Last = Last $k " ";
580: }
581: Last = Last $i;
582: j=i+1;
583: if(titles[$j]) {
584: Title = $j;
585: j++;
586: }
587: for(; j<NF; j++) {
588: Given = Given $j " ";
589: }
590: Given = Given $NF;
591: }
592: else { # Given....Last
593: if(NF > 1) Last = $NF;
594: for(i=NF-1 ;i>1; i--) {
595: if(prefix[$i]) Last = $i " " Last;
596: else break;
597: }
598: j = 2;
599: if (titles[$j]) {
600: Title = $2;
601: j++;
602: }
603: if(j <= i) {
604: for(; j<i; j++) {
605: Given = Given $j " ";
606: }
607: Given = Given $i;
608: }
609: }
610: if(verbflag) {
611: gsub("\\\\&"," ",Last);
612: gsub("\\\\&"," ",Title);
613: gsub("\\\\&"," ",Post);
614: }
615: }
616:
617:
618: ##
619: ## initial - return initial of name string
620: ##
621: func initial(string) {
622: return(substr(string,1,1) ".")
623: }
624:
625:
626: ##
627: ## LastFM - Organize Name: Last, F.M., e.g. Smith, F.P. Jr.
628: ##
629: func LastFM() {
630: Name = "";
631: punc = "";
632: if(Last) {
633: Name = Name Last;
634: punc = ", ";
635: }
636: if(Given) {
637: if(Given ~ /\\\&/) {
638: gsub("\\\\&"," ",Given);
639: Name = Name punc Given;
640: }
641: else {
642: ng = split(Given,G);
643: Name = Name punc initial(G[1]);
644: for(i = 2; i <= ng; i++)
645: Name = Name initial(G[i]);
646: }
647: }
648: punc = " ";
649: if(Post) {
650: Name = Name punc Post;
651: }
652: return(Name);
653:
654: }
655:
656:
657: ##
658: ## FMLast - Organize Name: F.M. Last, e.g., F.P. Smith Jr.
659: ##
660: func FMLast() {
661: Name = "";
662: punc = "";
663: if(Given) {
664: if(Given ~ /\\\&/) {
665: gsub("\\\\&"," ",Given);
666: Name = Name punc Given;
667: }
668: else {
669: ng = split(Given,G);
670: Name = Name initial(G[1]);
671: for(i = 2; i <= ng; i++)
672: Name = Name initial(G[i]);
673: }
674: punc = " ";
675: }
676: if(Last) {
677: Name = Name punc Last;
678: punc = " ";
679: }
680: if(Post) {
681: Name = Name punc Post;
682: }
683:
684: return(Name);
685: }
686:
687: ##
688: ## F_M_Last - Organize Name: F.M. Last, e.g., F.P. Smith Jr.
689: ##
690: func F_M_Last() {
691: Name = "";
692: punc = "";
693: if(Given) {
694: if(Given ~ /\\\&/) {
695: gsub("\\\\&"," ",Given);
696: Name = Name punc Given;
697: }
698: else {
699: ng = split(Given,G);
700: Name = Name initial(G[1]);
701: for(i = 2; i <= ng; i++) {
702: Name = punc Name initial(G[i]);
703: punc = " ";
704: }
705: }
706: punc = " ";
707: }
708: if(Last) {
709: Name = Name punc Last;
710: punc = " ";
711: }
712: if(Post) {
713: Name = Name punc Post;
714: }
715:
716: return(Name);
717: }
718:
719: ##
720: ## LastF_M - Organize Name: Last, F. M., e.g. Smith F. P. Jr.
721: ##
722: func LastF_M() {
723: Name = "";
724: punc = "";
725: if(Last) {
726: Name = Name Last;
727: punc = ", ";
728: }
729: if(Given) {
730: if(Given ~ /\\\&/) {
731: gsub("\\\\&"," ",Given);
732: Name = Name punc Given;
733: }
734: else {
735: ng = split(Given,G);
736: Name = Name punc initial(G[1]);
737: for(i = 2; i <= ng; i++)
738: Name = Name " " initial(G[i]);
739: }
740: }
741: punc = " ";
742: if(Post) {
743: Name = Name punc Post;
744: }
745: return(Name);
746: }
747:
748: ##
749: ## FMLast - Organize Name: F. M. Last, e.g., F. P. Smith Jr.
750: ##
751: func F_MLast() {
752: Name = "";
753: punc = "";
754: if(Given) {
755: if(Given ~ /\\\&/) {
756: gsub("\\\\&"," ",Given);
757: Name = Name punc Given;
758: }
759: else {
760: ng = split(Given,G);
761: Name = Name initial(G[1]);
762: for(i = 2; i <= ng; i++)
763: Name = Name " " initial(G[i]);
764: }
765: punc = " ";
766: }
767: if(Last) {
768: Name = Name punc Last;
769: punc = " ";
770: }
771: if(Post) {
772: Name = Name punc Post;
773: }
774: return(Name);
775: }
776:
777:
778: ##
779: ## FirstMiddleLast - Organize Name: First Middle Last e.g., Fred Peter Smith Jr.
780: ##
781: func FirstMiddleLast()
782: {
783: Name = "";
784: punc = "";
785: if(Given) {
786: if(Given ~ /\\\&/) {
787: gsub("\\\\&"," ",Given);
788: }
789: Name = Name Given;
790: punc = " ";
791: }
792: if(Last) {
793: Name = Name punc Last;
794: punc = " ";
795: }
796: if(Post) {
797: Name = Name punc Post;
798: }
799: return(Name);
800: }
801:
802: ##
803: ## LastFirstMiddle - Organize Name: Last, First Middle Last e.g., Smith, Fred Peter, Jr.
804: ##
805: func LastFirstMiddle()
806: {
807: Name = "";
808: punc = "";
809: if(Last) {
810: Name = Name Last;
811: punc = ", ";
812: }
813: if(Given) {
814: if(Given ~ /\\\&/) {
815: gsub("\\\\&"," ",Given);
816: }
817: Name = Name punc Given;
818: punc = ", ";
819: }
820: if(Post) {
821: Name = Name punc Post;
822: }
823: return(Name);
824: }
825:
826:
827:
828: ##
829: ## getrest - get rest of $0 after lopping off $1.
830: ##
831: func getrest()
832: {
833: rest = substr($0,length($1)+2);
834: return(substr(rest,index(rest,$2))); # strip off blanks
835: }
836: ###
837: ### lsa reference formatting style
838: ###
839:
840: BEGIN {
841: PASS=""; # only one pass thru document
842: sortflag = 1; # reference_placement bib is sortedone
843: STYLE = "lsa";
844: SKEY = "adt";
845: }
846:
847:
848:
849: #######################################################
850: #
851: # Functions required by general awk script
852: #
853: #######################################################
854:
855:
856: ##
857: ## Set author and editor fields
858: ## for reference list
859: ## for citation
860: ## for possible sorting
861: ##
862: func setauthor(b,a) {
863: Afull[b,a] = FirstMiddleLast();
864: Arfull[b,a] = LastFirstMiddle();
865: Alast[b,a] = Last;
866: Asort[b] = Asort[b] Arfull[b,a] " ";
867: }
868:
869: func seteditor(b,a) {
870: Efull[b,a] = FirstMiddleLast();;
871: Erfull[b,a] = LastFirstMiddle();
872: Elast[b,a] = Last;
873: Esort[b] = Esort[b] Erfull[b,a] " ";
874: }
875:
876:
877:
878:
879: ##
880: ## citations
881: ## print a citation list
882: ## (Last year{, year}, Last year...)
883: ##
884: func citations(lastpunc) {
885: sep = "\n(";
886: if(lastpunc == "\"" || lastpunc == "'") {
887: sep = lastpunc " (";
888: lastpunc = "\\ ";
889: }
890: ptext = 0;
891: ctext = 0;
892: for(i=1; i<=cites; i++) {
893: cn = bibptr[i];
894: b = uniqno[cn];
895: if (pre_text[cn]) ctext = 1;
896: if ((ctext == 1) || (ptext == 1) || new_author(i)) {
897: printf sep;
898: if (pre_text[cn]) {
899: printf "%s", pre_text[cn];
900: if((no_author[cn] == 0) || (no_date[cn] == 0))
901: printf " ";
902: }
903: if (no_author[cn] == 0) {
904: if(authors[b])
905: printlast(b);
906: else if (editors[b])
907: printlasted(b);
908: else if (issuer[b])
909: printf issuer[b];
910: else
911: printf title[b];
912: punc = " ";
913: }
914: else punc = "";
915: }
916: else {
917: punc = ", ";
918: }
919: if(no_date[cn] == 0) {
920: if(year[b] ~ /^[0-9][0-9][0-9][0-9]$/)
921: printf "%s%s", punc, year[b];
922: else {
923: if (date[b] != 0) printf "%s%s", punc, date[b];
924: }
925: }
926: if (post_text[cn]) {
927: if (is_punc(substr(post_text[cn],1,1)) == 0) print "";
928: printf "%s", post_text[cn];
929: }
930: sep = ",\n";
931: ptext = ctext;
932: ctext = 0;
933: }
934: printf ")";
935: printf lastpunc;
936: }
937:
938: func is_punc(p)
939: {
940: if(p == ",") return 1;
941: if(p == ".") return 1;
942: if(p == ";") return 1;
943: return 0;
944: }
945:
946: ##
947: ## new_author
948: ## returns 1 if current author is difference from
949: ## previous author in the citation list
950: ##
951: func new_author(c) {
952: if (c == 1) return 1;
953: b1 = uniqno[bibptr[c-1]];
954: b = uniqno[bibptr[c]];
955: if(authors[b] == 0) return 1;
956: if(authors[b1] != authors[b]) return 1;
957: for(k = 1; k <= authors[b]; k++) {
958: if (Alast[b1,k] != Alast[b,k]) return 1;
959: }
960: return 0;
961: }
962:
963:
964: ##
965: ## print author last name for citation
966: ## First
967: ## First and Second
968: ## First, Second,..., & Last
969: func printlast(c) {
970: a = authors[c]
971: if ( a == 1 ) printf "%s", Alast[c,1];
972: else if ( a == 2 ) printf "%s & %s", Alast[c,1], Alast[c,2];
973: else if (a > 5) printf "%s et al.", Alast[c,1];
974: else {
975: for ( j = 1; j < a; j++ ) printf Alast[c,j] ", ";
976: printf "& %s", Alast[c,a];
977: }
978: }
979:
980: ##
981:
982: ## print editor last name for citation
983: ## First
984: ## First and Second
985: ## First, Second,..., & Last
986: func printlasted(c) {
987: a = editors[c]
988: if ( a == 1 ) printf "%s", Elast[c,1];
989: else if ( a == 2 ) printf "%s & %s", Elast[c,1], Elast[c,2];
990: else if (a > 5) printf "%s et al.", Elast[c,1] ;
991: else {
992: for ( j = 1; j < a; j++ ) printf "%s, ", Elast[c,j];
993: printf "& %s", Elast[c,a];
994: }
995: }
996:
997:
998: ##
999: ## bibindex
1000: ## set up indentation for bibliography;
1001: ## return an index for accessing rest of citation
1002: ## do misc stuff specific to this style
1003: ##
1004: func bibindex(i) {
1005: printf ".sp .3\n.ti -.3i\n";
1006: if (sortflag)
1007: return sortorder[i];
1008: else return i;
1009: }
1010:
1011:
1012:
1013: #############################################
1014: #
1015: # Reference types
1016: #
1017: ############################################
1018:
1019:
1020: func book(b) {
1021: # authorlist.
1022: if(authors[b]) {
1023: if(printfull(b) != ".")
1024: printf ".";
1025: printf "\n";
1026: }
1027: # date.
1028: printf "%s", date[b] ;
1029: punc = ".\n";
1030: # title
1031: if(title[b]) {
1032: printf "%s%s", punc, title[b];
1033: # Vol #.
1034: if(volstr[b])
1035: printf ", %s", volstr[b];
1036: else if(volume[b])
1037: printf ", Vol. %s", volume[b];
1038: }
1039: # location: publisher.
1040: if (city[b]) {
1041: printf "%s%s", punc, city[b] ;
1042: punc = ": ";
1043: }
1044: printf "%s%s", punc, issuer[b] ;
1045: }
1046:
1047:
1048: func editedbook(b) {
1049: # authorlist.
1050: if(authors[b]) {
1051: if(printfull(b) != ".")
1052: printf ".";
1053: printf "\n";
1054: }
1055: # date.
1056: printf "%s", date[b] ;
1057: if(authors[b] <2)
1058: printf " (ed.)\n";
1059: else
1060: printf " (eds.)\n";
1061: # italic(title)
1062: if(title[b]) {
1063: printf title[b];
1064: punc = ".\n";
1065: }
1066: # (Vol #).
1067: if(volstr[b])
1068: printf ", %s", volstr[b];
1069: else if(volume[b])
1070: printf ", Vol. %s", volume[b];
1071: # location: publisher.
1072: if (city[b]) {
1073: printf "%s%s", punc, city[b] ;
1074: punc = ": ";
1075: }
1076: printf "%s%s", punc, issuer[b] ;
1077: }
1078:
1079:
1080: func thesis(b) {
1081:
1082: # authorlist.
1083: if(authors[b]) {
1084: if(printfull(b) != ".")
1085: printf ".";
1086: printf "\n";
1087: }
1088: # date.
1089: printf "%s.\n", date[b] ;
1090: # title.
1091: if(title[b]) {
1092: printf "%s.\n", title[b];
1093: }
1094: # city
1095: if(address[b]) {
1096: printf "%s: ", address[b];
1097: }
1098: # thesis, school.
1099: if(reftype[b] == "phdthesis")
1100: printf "%s dissertation", issuer[b];
1101: else if(reftype[b] == "mastersthesis")
1102: printf "%s master's thesis", issuer[b];
1103: }
1104:
1105: func review(b) {
1106: article(b);
1107: }
1108:
1109:
1110: func article(b) {
1111:
1112: # authorlist.
1113: if(authors[b]) {
1114: if(printfull(b) != ".")
1115: printf ".";
1116: printf "\n";
1117: }
1118: # date.
1119: printf "%s.\n", date[b] ;
1120: # title.
1121: if(title[b]) {
1122: printf title[b] ".\n";
1123: }
1124: # [reviewed title.]
1125: if(booktitle[b]) {
1126: printf "[Review of %s", booktitle[b];
1127: if(editors[b]) {
1128: printf " by ";
1129: editorlist(b);
1130: if (issuer[b]) {
1131: printf " %s", issuer[b];
1132: }
1133: }
1134: printf "].\n";
1135: }
1136:
1137: # italics journal,
1138: printf "%s", journal[b];
1139: punc = ", ";
1140: # volume:number.pages
1141: if (volstr[b]) {
1142: printf ", %s", volstr[b];
1143: if (numstr[b]) {
1144: printf ", %s", numstr[b];
1145: }
1146: else if (number[b]) {
1147: printf ", %s", number[b];
1148: }
1149: punc = ".";
1150: }
1151: else if (volume[b]) {
1152: printf " %s", volume[b];
1153: if (numstr[b]) {
1154: printf ", %s", numstr[b];
1155: }
1156: else if (number[b]) {
1157: printf ":%s",number[b];
1158: }
1159: punc = ".";
1160: }
1161: if ( pages[b] ) printf "%s%s", punc, pages[b];
1162: }
1163:
1164: func inproceedings(b) {
1165:
1166: # authorlist.
1167: if(authors[b]) {
1168: if(printfull(b) != ".")
1169: printf ".";
1170: printf "\n";
1171: }
1172: # date.
1173: printf "%s.\n", date[b] ;
1174: # title.
1175: if(title[b]) {
1176: printf title[b] ".\n";
1177: }
1178:
1179: # italics journal,
1180: printf "%s", journal[b];
1181: punc = ",\n";
1182:
1183: # ed. by editorlist,
1184: if(editors[b]) {
1185: printf ", ed. by "
1186: editorlist(b);
1187: }
1188: punc = ".\n";
1189: # pages.
1190: if(pages[b]) {
1191: printf ", %s", pages[b];
1192: }
1193: # location: publisher,
1194: if (city[b]) {
1195: printf "%s%s", punc, city[b] ;
1196: punc = ": ";
1197: }
1198: if (issuer[b])
1199: printf "%s%s", punc, issuer[b] ;
1200: }
1201:
1202: func proceedings(b) {
1203: punc = "";
1204: # authorlist.
1205: if(authors[b] >0) {
1206: if(printfull(b) != ".")
1207: printf ".";
1208: printf "\n";
1209: }
1210: # editor
1211: else if(editors[b]) {
1212: printedfull(b);
1213: if (editors[b] == 1) printf " (Ed.)"
1214: else if (editors[b] > 1) printf " (Eds.)"
1215: punc = ".\n";
1216: }
1217:
1218: # publisher
1219: else if(issuer[b]) {
1220: printf "%s%s", punc, issuer[b];
1221: punc = ".\n";
1222: }
1223: # date.
1224: printf "%s%s.\n", punc, date[b] ;
1225: # title
1226: if (title[b]) {
1227: printf "%s", title[b];
1228: punc = ".\n";
1229: if(substr(title[b],length(title[b]),1) == ".")
1230: punc = "\n";
1231: }
1232: # volume:number
1233: if (volstr[b]) {
1234: printf ", %s", volstr[b];
1235: if (numstr[b]) {
1236: printf ", %s", numstr[b];
1237: }
1238: else if (number[b]) {
1239: printf ", %s", number[b];
1240: }
1241: punc = ".";
1242: }
1243: else if (volume[b]) {
1244: printf " %s", volume[b];
1245: if (numstr[b]) {
1246: printf ", %s", numstr[b];
1247: }
1248: else if (number[b]) {
1249: printf ":%s",number[b];
1250: }
1251: punc = ".";
1252: }
1253: # location: publisher,
1254: if (city[b]) {
1255: printf "%s%s", punc, city[b] ;
1256: punc = ": ";
1257: }
1258: printf "%s%s", punc, issuer[b] ;
1259: }
1260:
1261:
1262: func incollection(b) {
1263:
1264: # authorlist.
1265: if(authors[b]) {
1266: if(printfull(b) != ".")
1267: printf ".";
1268: printf "\n";
1269: }
1270: # date.
1271: printf "%s.\n", date[b] ;
1272: # title
1273: if(title[b]) {
1274: printf "%s.\n", title[b];
1275: }
1276: # booktitle,
1277: printf "%s", booktitle[b];
1278: # Vol #.
1279: if(volstr[b])
1280: printf ", %s", volstr[b];
1281: else if(volume[b])
1282: printf ", Vol. %s", volume[b];
1283: # ed. by editorlist,
1284: if(editors[b]) {
1285: printf ", ed. by "
1286: editorlist(b);
1287: }
1288: punc = ".\n";
1289: # pages.
1290: if(pages[b]) {
1291: printf ", %s", pages[b];
1292: }
1293: # location: publisher,
1294: if (city[b]) {
1295: printf "%s%s", punc, city[b] ;
1296: punc = ": ";
1297: }
1298: printf "%s%s", punc, issuer[b];
1299: }
1300:
1301:
1302:
1303: func techreport(b) {
1304:
1305: # authorlist.
1306: if(authors[b]) {
1307: if(printfull(b) != ".")
1308: printf ".";
1309: printf "\n";
1310: }
1311: # date.
1312: printf "%s.\n", date[b] ;
1313: # title.
1314: if(title[b])
1315: printf "%s.\n", title[b];
1316: # (report number).
1317: printf "(%s).\n", report[b];
1318:
1319: # location: publisher.
1320: if (city[b]) printf "%s: ", city[b] ;
1321: printf issuer[b];
1322: }
1323:
1324: func tm(b) {
1325:
1326: # authorlist.
1327: if(authors[b]) {
1328: if(printfull(b) != ".")
1329: printf ".";
1330: printf "\n";
1331: }
1332: # date.
1333: printf "%s.\n", date[b] ;
1334: # title.
1335: if(title[b])
1336: printf "%s.\n", title[b];
1337: # (tm number).
1338: if(rp)
1339: printf "(AT&T Bell Laboratories internal memorandum)";
1340: else
1341: printf "(%s)", tmno[b]
1342: }
1343:
1344: func manual(b) {
1345: punc = "";
1346: # authorlist.
1347: if(authors[b] >0) {
1348: if(printfull(b) != ".")
1349: printf ".";
1350: printf "\n";
1351: }
1352: # editor.
1353: else if(editors[b]) {
1354: if(printedfull(b) != ".")
1355: printf ".";
1356: printf "\n";
1357: }
1358:
1359: # publisher
1360: else if(issuer[b]) {
1361: printf "%s%s", punc, issuer[b];
1362: punc = ".\n";
1363: }
1364: # date.
1365: printf "%s%s", punc, date[b] ;
1366: if (editors[b] == 1) printf " (ed.)\n";
1367: else if (editors[b] > 1) printf " (eds.)\n";
1368: else printf ".\n";
1369: # title
1370: if(title[b]) {
1371: printf "%s", title[b];
1372: punc = ".\n";
1373: }
1374: # location: publisher.
1375: if (city[b]) {
1376: printf "%s%s", punc, city[b] ;
1377: punc = ": ";
1378: }
1379: if(issuer[b]) {
1380: if(editors[b] || authors[b]);
1381: printf "%s%s", punc, issuer[b];
1382: }
1383: }
1384:
1385: func pamphlet(b)
1386: {
1387:
1388: punc = "";
1389: # authorlist.
1390: if(authors[b] >0) {
1391: if(printfull(b) != ".")
1392: printf ".";
1393: printf "\n";
1394: }
1395: # publisher.
1396: else if(issuer[b]) {
1397: printf issuer[b];
1398: punc = ".\n";
1399: }
1400: # title.
1401: else if(title[b]) {
1402: printf title[b];
1403: punc = ".\n"
1404: }
1405: # date.
1406: if(date[b]) {
1407: printf "%s%s", punc, date[b] ;
1408: punc = ".\n";
1409: }
1410: # title
1411: if(editors[b] || authors[b] || issuer[b]) {
1412: if(title[b]) {
1413: printf "%s%s", punc, title[b];
1414: punc = ".\n"
1415: }
1416: }
1417:
1418: # Vol #.
1419: if(volstr[b])
1420: printf ", %s", volstr[b];
1421: else if(volume[b])
1422: printf ", Vol. %s", volume[b];
1423: # location: publisher.
1424: if (city[b]) {
1425: printf "%s%s", punc, city[b] ;
1426: punc = ": ";
1427: }
1428: if(issuer[b]) {
1429: if(editors[b] || authors[b]);
1430: printf "%s%s", punc, issuer[b];
1431: }
1432:
1433: }
1434:
1435: func default(b) {
1436: punc = "";
1437: # authorlist.
1438: if(authors[b]) {
1439: if(printfull(b) != ".")
1440: printf ".";
1441: printf "\n";
1442: }
1443: # publisher.
1444: else if(issuer[b]) {
1445: printf issuer[b];
1446: punc = ".\n";
1447: }
1448: # title.
1449: else if(title[b]) {
1450: printf title[b];
1451: punc = ".\n"
1452: }
1453: # date.
1454: if(date[b]) {
1455: printf "%s%s", punc, date[b] ;
1456: punc = ".\n";
1457: }
1458: # title
1459: if(editors[b] || authors[b] || issuer[b] ) {
1460: if(title[b]) {
1461: printf "%s%s", punc, title[b];
1462: punc = ".\n"
1463: }
1464: }
1465: # Vol #,
1466: if(volstr[b]) {
1467: printf ", %s", volstr[b];
1468: punc = ".\n";
1469: }
1470: else if(volume[b]) {
1471: printf ", Vol. %s", volume[b];
1472: punc = ".\n";
1473: }
1474: # pages.
1475: if (pages[b]) {
1476: printf ", %s", pages[b];
1477: punc = ".\n";
1478: }
1479:
1480: # location: publisher.
1481: if (city[b]) {
1482: printf "%s%s", punc, city[b] ;
1483: punc = ": ";
1484: }
1485: if(issuer[b]) {
1486: if(editors[b] || authors[b]);
1487: printf "%s%s", punc, issuer[b];
1488: }
1489: }
1490:
1491: #
1492: # return index of previous item
1493: #
1494:
1495: func previous(q)
1496: {
1497: if (sortflag)
1498: return sortorder[inverse[q]-1];
1499: else
1500: return q-1;
1501: }
1502:
1503:
1504:
1505: # Author, First
1506: # Author, First, and Second Author
1507: # Author, First, Second Author, and Remaining Authors
1508:
1509: func printfull(b) {
1510: longdash = "\\(em\\(em\\(em";
1511: dash = 0;
1512: prev = previous(b);
1513: if ( authors[b] == 1 ) {
1514: if(Arfull[b,1] == Arfull[prev,1]) {
1515: printf longdash;
1516: return "";
1517: }
1518: else printf Arfull[b,1] ;
1519: if(aetal[b]) {
1520: printf ", et al.";
1521: return ".";
1522: }
1523: return substr(Arfull[b,1],length(Arfull[b,1]));
1524: }
1525: else if ( authors[b] == 2 ) {
1526: if(Arfull[b,1] == Arfull[prev,1]) {
1527: printf longdash;
1528: dash = 1;
1529: }
1530: else printf Arfull[b,1];
1531: printf ", and "
1532: if(dash && (Afull[b,2] == Afull[prev,2]))
1533: printf longdash;
1534: else printf Afull[b,2];
1535: }
1536: else {
1537: if(Arfull[b,1] == Arfull[prev,1]) {
1538: printf longdash;
1539: dash = 1;
1540: }
1541: else printf Arfull[b,1];
1542: printf "; ";
1543: for ( j = 2 ; j < authors[b]; j++ ) {
1544: if(dash && (Afull[b,j] == Afull[prev,j]))
1545: printf longdash;
1546: else {
1547: dash = 0;
1548: printf Afull[b,j];
1549: }
1550: printf "; ";
1551: }
1552: printf "and "
1553: j = authors[b];
1554: if(dash && (Afull[b,j] == Afull[prev,j]))
1555: printf longdash;
1556: else printf Afull[b,j];
1557: }
1558: return "";
1559: }
1560:
1561: func printedfull(b) {
1562: longdash = "\\(em\\(em\\(em\\(em";
1563: dash = 0;
1564: prev = previous(b);
1565: if ( editors[b] == 0 ) ;
1566: else if ( editors[b] == 1 ) {
1567: if(Erfull[b,1] == Erfull[prev,1]) {
1568: printf longdash;
1569: return "";
1570: }
1571: else printf Erfull[b,1] ;
1572: if(aetal[b]) {
1573: printf ", et al.";
1574: return ".";
1575: }
1576: return substr(Erfull[b,1],length(Erfull[b,1]));
1577: }
1578: else if ( editors[b] == 2 ) {
1579: if(Erfull[b,1] == Erfull[prev,1]) {
1580: printf longdash;
1581: dash = 1;
1582: }
1583: else printf Erfull[b,1];
1584: printf ", and "
1585: if(dash && (Efull[b,2] == Efull[prev,2]))
1586: printf longdash;
1587: else printf Efull[b,2];
1588: }
1589: else {
1590: if(Erfull[b,1] == Erfull[prev,1]) {
1591: printf longdash;
1592: dash = 1;
1593: }
1594: else printf Erfull[b,1];
1595: printf "; ";
1596: for ( j = 2 ; j < editors[b]; j++ ) {
1597: if(dash && (Efull[b,j] == Efull[prev,j]))
1598: printf longdash;
1599: else {
1600: dash = 0;
1601: printf Efull[b,j];
1602: }
1603: printf "; ";
1604: }
1605: printf "and "
1606: j = editors[b];
1607: if(dash && (Efull[b,j] == Efull[prev,j]))
1608: printf longdash;
1609: else printf Efull[b,j];
1610: }
1611: return "";
1612: }
1613:
1614:
1615:
1616: func editorlist(b) {
1617: if ( editors[b] == 0 ) ;
1618: else if ( editors[b] == 1 ) printf "%s", Efull[b,1] ;
1619: else if ( editors[b] == 2 ) printf "%s & %s", Efull[b,1], Efull[b,2];
1620: else {
1621: printf "%s et al.", Efull[b,1];
1622: }
1623: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.