|
|
1.1 root 1: ###
2: ### apa reference formatting style
3: ###
4:
5: BEGIN {
6: PASS=""; # only one pass thru document
7: sortflag = 1; # reference_placement bib is sortedone
8: STYLE = "apa";
9: SKEY = "adt";
10: }
11:
12:
13:
14: #######################################################
15: #
16: # Functions required by general awk script
17: #
18: #######################################################
19:
20:
21: ##
22: ## Set author and editor fields
23: ## for reference list
24: ## for citation
25: ## for possible sorting
26: ##
27: func setauthor(b,a) {
28: Afull[b,a] = LastF_M();
29: Alast[b,a] = Last;
30: Asort[b] = Asort[b] Afull[b,a] " ";
31: }
32:
33: func seteditor(b,a) {
34: E[b,a] = F_MLast();
35: Efull[b,a] = LastF_M();
36: Elast[b,a] = Last;
37: Esort[b] = Esort[b] Efull[b,a] " ";
38: }
39:
40:
41: ##
42: ## citations
43: ## print a citation list
44: ## (Last, year; Last, year...)
45: ##
46: func citations(lastpunc) {
47: sep = "\n(";
48: if(lastpunc == "\"" || lastpunc == "'") {
49: sep = lastpunc " (";
50: lastpunc = "\\ ";
51: }
52: ptext = 0;
53: ctext = 0;
54: for(i=1; i<=cites; i++) {
55: cn = bibptr[i];
56: b = uniqno[cn];
57: if (pre_text[cn] || post_text[cn]) ctext = 1;
58: punc = ", ";
59: if ((ctext == 1) || (ptext == 1) || new_author(i)) {
60: printf sep;
61: ppunc = "";
62: if (pre_text[cn]) {
63: printf "%s", pre_text[cn];
64: if((no_author[cn] == 0) || (no_date[cn] == 0))
65: printf " ";
66: }
67: if (no_author[cn] == 0) {
68: if(authors[b])
69: printlast(b);
70: else if (editors[b])
71: printlasted(b);
72: else if (issuer[b])
73: printf issuer[b];
74: else
75: printf title[b];
76: }
77: else punc = "";
78: }
79: if(no_date[cn] == 0) {
80: if(year[b] ~ /^[0-9][0-9][0-9][0-9]$/)
81: printf "%s%s", punc, year[b];
82: else {
83: if (date[b] != 0) printf "%s%s", punc, date[b];
84: }
85: }
86: if (post_text[cn]) {
87: if (is_punc(substr(post_text[cn],1,1)) == 0) print "";
88: printf "%s", post_text[cn];
89: }
90: sep = ";\n";
91: ptext = ctext;
92: ctext = 0;
93: }
94: printf ")";
95: printf lastpunc;
96: }
97:
98: func is_punc(p)
99: {
100: if(p == ",") return 1;
101: if(p == ".") return 1;
102: if(p == ";") return 1;
103: return 0;
104: }
105:
106: ##
107: ## new_author
108: ## returns 1 if current author is difference from
109: ## previous author in the citation list
110: ##
111: func new_author(c) {
112: if (c == 1) return 1;
113: b1 = uniqno[bibptr[c-1]];
114: b = uniqno[bibptr[c]];
115: if(authors[b] == 0) return 1;
116: if(authors[b1] != authors[b]) return 1;
117: for(k = 1; k <= authors[b]; k++) {
118: if (Alast[b1,k] != Alast[b,k]) return 1;
119: }
120: return 0;
121: }
122:
123:
124: ##
125: ## print author last name for citation
126: ## First
127: ## First and Second
128: ## First, Second,..., & Last
129: func printlast(c) {
130: a = authors[c]
131: if ( a == 1 ) printf "%s", Alast[c,1];
132: else if ( a == 2 ) printf "%s & %s", Alast[c,1], Alast[c,2];
133: else if (a > 5) printf "%s et al.", Alast[c,1];
134: else {
135: for ( j = 1; j < a; j++ ) printf Alast[c,j] ", ";
136: printf "& %s", Alast[c,a];
137: }
138: }
139:
140: ##
141:
142: ## print editor last name for citation
143: ## First
144: ## First and Second
145: ## First, Second,..., & Last
146: func printlasted(c) {
147: a = editors[c]
148: if ( a == 1 ) printf "%s", Elast[c,1];
149: else if ( a == 2 ) printf "%s & %s", Elast[c,1], Elast[c,2];
150: else if (a > 5) printf "%s et al.", Elast[c,1] ;
151: else {
152: for ( j = 1; j < a; j++ ) printf Elast[c,j] ", ";
153: printf "& %s", Elast[c,a];
154: }
155: }
156:
157:
158: ##
159: ## bibindex
160: ## set up indentation for bibliography;
161: ## return an index for accessing rest of citation
162: ##
163: func bibindex(i) {
164: printf ".sp .5\n.ti -.5i\n";
165: if (sortflag)
166: return sortorder[i];
167: else return i;
168: }
169:
170:
171:
172: #############################################
173: #
174: # Reference types
175: #
176: ############################################
177:
178:
179: func book(b) {
180: # authorlist
181: if(authors[b]) {
182: printfull(b);
183: printf "\n";
184: }
185: # (date).
186: printf "(%s)", date[b] ;
187: punc = ".\n";
188: # italic(title)
189: if(title[b]) {
190: printf "%s\\f2\\&%s\\f1\\&", punc, title[b];
191: # (Vol #).
192: if(volstr[b])
193: printf " (%s)", volstr[b];
194: else if(volume[b])
195: printf " (Vol. %s)", volume[b];
196: }
197: # location: publisher.
198: if (city[b]) {
199: printf "%s%s", punc, city[b] ;
200: punc = ": ";
201: }
202: printf "%s%s", punc, issuer[b] ;
203: }
204:
205:
206: func editedbook(b) {
207: # authorlist
208: if(authors[b]) {
209: printfull(b);
210: if(authors[b] <2)
211: printf " (Ed.).\n";
212: else
213: printf " (Eds.).\n";
214: }
215: # (date).
216: printf "(%s)", date[b] ;
217: punc = ".\n";
218: # italic(title)
219: if(title[b]) {
220: printf "%s\\f2\\&%s\\f1\\&", punc, title[b];
221: # (Vol #).
222: if(volstr[b])
223: printf " (%s)", volstr[b];
224: else if(volume[b])
225: printf " (Vol. %s)", volume[b];
226: }
227: # location: publisher.
228: if (city[b]) {
229: printf "%s%s", punc, city[b] ;
230: punc = ": ";
231: }
232: printf "%s%s", punc, issuer[b] ;
233: }
234:
235:
236: func thesis(b) {
237:
238: # authorlist
239: if(authors[b]) {
240: printfull(b);
241: printf "\n";
242: }
243: # (date).
244: printf "(%s).\n", date[b] ;
245: # italic(title).
246: if(title[b]) {
247: printf "\\f2\\&%s\\f1\\&.\n", title[b];
248: }
249: # thesis, school.
250: if(reftype[b] == "phdthesis")
251: printf "Unpublished doctoral dissertation, %s", issuer[b];
252: else if(reftype[b] == "mastersthesis")
253: printf "Unpublished master's thesis, %s", issuer[b];
254: }
255:
256: func review(b) {
257: article(b);
258: }
259:
260:
261: func article(b) {
262:
263: # authorlist
264: if(authors[b]) {
265: printfull(b);
266: printf "\n";
267: }
268: # (date).
269: printf "(%s).\n", date[b] ;
270: # title.
271: if(title[b]) {
272: printf title[b] ".\n";
273: }
274: # [reviewed title.]
275: if(booktitle[b]) {
276: printf "[Review of \\f2\\&%s\\f1\\&", booktitle[b];
277: if(editors[b]) {
278: printf " by ";
279: editorlist(b);
280: }
281: if (issuer[b]) {
282: printf " %s", issuer[b];
283: }
284: printf "].\n";
285: }
286:
287: # italics journal,
288: printf "\\f2\\&%s\\f1\\&", journal[b];
289: # italics(volume)
290: if (volstr[b])
291: printf ", \\f2\\&%s\\f1\\&", volstr[b];
292: else if (volume[b])
293: printf ", \\f2\\&%s\\f1\\&", volume[b];
294: # (number Pt. part)
295: if (numstr[b]) {
296: printf "(%s", numstr[b];
297: if(partstr[b])
298: printf " %s", partstr[b];
299: else if(part[b])
300: printf " Pt. %s", part[b];
301: printf ")";
302: }
303: else if (number[b]) {
304: printf "(%s", number[b];
305: if(partstr[b])
306: printf " %s", partstr[b];
307: else if(part[b])
308: printf " Pt. %s", part[b];
309: printf ")";
310: }
311: # , pages
312: if ( pages[b] ) printf ", %s", pages[b];
313: }
314:
315: func inproceedings(b) {
316:
317: # authorlist
318: if(authors[b]) {
319: printfull(b);
320: printf "\n";
321: }
322: # (date).
323: printf "(%s).\n", date[b] ;
324: # title.
325: if(title[b]) {
326: printf title[b] ".\n";
327: }
328:
329: # italics journal,
330: printf "\\f2\\&%s\\f1\\&", journal[b];
331: # italics(volume)
332: if (volstr[b])
333: printf ", \\f2\\&%s\\f1\\&", volstr[b];
334: else if (volume[b])
335: printf ", \\f2\\&%s\\f1\\&", volume[b];
336: # (number Pt. part)
337: if (numstr[b]) {
338: printf "(%s", numstr[b];
339: if(partstr[b])
340: printf " %s", partstr[b];
341: else if(part[b])
342: printf " Pt. %s", part[b];
343: printf ")";
344: }
345: else if (number[b]) {
346: printf "(%s", number[b];
347: if(partstr[b])
348: printf " %s", partstr[b];
349: else if(part[b])
350: printf " Pt. %s", part[b];
351: printf ")";
352: }
353: # editors
354: if(editors[b]) {
355: printf ", ";
356: editorlist(b);
357: if (editors[b] == 1) printf " (Ed.)"
358: else if (editors[b] > 1) printf " (Eds.)"
359: }
360: # , pages
361: if ( pages[b] ) printf ", %s", pages[b];
362: }
363:
364: func proceedings(b) {
365: punc = "";
366: # authorlist
367: if(authors[b] >0) {
368: printfull(b);
369: punc = "\n";
370: }
371: # editor
372: else if(editors[b]) {
373: printedfull(b);
374: if (editors[b] == 1) printf " (Ed.)"
375: else if (editors[b] > 1) printf " (Eds.)"
376: punc = ".\n";
377: }
378:
379: # publisher
380: else if(issuer[b]) {
381: printf "%s%s", punc, issuer[b];
382: punc = ".\n";
383: }
384: # (date).
385: printf "%s(%s).\n", punc, date[b] ;
386: # italic(title)
387: if (title[b]) {
388: printf "\\f2\\&%s\\f1\\&", title[b];
389: punc = ".\n";
390: if(substr(title[b],length(title[b]),1) == ".")
391: punc = "\n";
392: # italics(volume)
393: if (volstr[b])
394: printf ", \\f2\\&%s\\f1\\&", volstr[b];
395: else if (volume[b])
396: printf ", \\f2\\&%s\\f1\\&", volume[b];
397: # (number Pt. part)
398: if (numstr[b]) {
399: printf "(%s", numstr[b];
400: if(partstr[b])
401: printf " %s", partstr[b];
402: else if(part[b])
403: printf " Pt. %s", part[b];
404: printf ")";
405: }
406: else if (number[b]) {
407: printf "(%s", number[b];
408: if(partstr[b])
409: printf " %s", partstr[b];
410: else if(part[b])
411: printf " Pt. %s", part[b];
412: printf ")";
413: }
414: }
415: # location: publisher,
416: if (city[b]) {
417: printf "%s%s", punc, city[b] ;
418: punc = ": ";
419: }
420: printf "%s%s", punc, issuer[b] ;
421: }
422:
423: func incollection(b) {
424:
425: # authorlist
426: if(authors[b]) {
427: printfull(b);
428: printf "\n";
429: }
430: # (date).
431: printf "(%s).\n", date[b] ;
432: # title
433: if(title[b]) {
434: printf "%s.\n", title[b];
435: }
436: # In editorlist (Ed.),
437: if(editors[b]) {
438: printf "In "
439: editorlist(b);
440: if (editors[b] == 1) printf " (Ed.),\n"
441: else if (editors[b] > 1) printf " (Eds.),\n"
442: }
443: # italics(booktitle)
444: printf "\\f2\\&%s\\f1\\&", booktitle[b];
445: # (volume, pages).
446: if (volume[b] || pages[b]) {
447: comma = "";
448: printf "\n(" ;
449: if(volstr[b]) {
450: printf "%s", volstr[b];
451: comma = ", " ;
452: }
453: else if(volume[b]) {
454: printf "Vol. %s", volume[b];
455: comma = ", " ;
456: }
457: if(pages[b]) {
458: if ( pages[b] ~ /[,-]/ )
459: printf "%spp. %s", comma, pages[b];
460: else printf "%sp. %s)", comma, pages[b];
461: }
462: printf ")"
463: }
464: printf ".\n";
465: # location: publisher,
466: if (city[b]) printf "%s: ", city[b] ;
467: printf "%s", issuer[b] ;
468: }
469:
470:
471:
472: func techreport(b) {
473:
474: # authorlist
475: if(authors[b]) {
476: printfull(b);
477: printf "\n";
478: }
479: # (date).
480: printf "(%s).\n", date[b] ;
481: # italic(title)
482: if(title[b])
483: printf "\\f2\\&%s\\f1\\&\n", title[b];
484: # (report number).
485: printf "(%s).\n", report[b];
486:
487: # location: publisher.
488: if (city[b]) printf "%s: ", city[b] ;
489: printf issuer[b];
490: }
491:
492: func tm(b) {
493:
494: # authorlist
495: if(authors[b]) {
496: printfull(b);
497: printf "\n";
498: }
499: # (date).
500: printf "(%s).\n", date[b] ;
501: # italic(title)
502: if(title[b])
503: printf "\\f2\\&%s\\f1\\&\n", title[b];
504: # (tm number).
505: if(rp)
506: printf "(AT&T Bell Laboratories internal memorandum)";
507: else
508: printf "(%s)", tmno[b]
509: }
510:
511: func manual(b) {
512: punc = "";
513: # authorlist
514: if(authors[b] >0) {
515: printfull(b);
516: punc = "\n";
517: }
518: # editor
519: else if(editors[b]) {
520: printedfull(b);
521: if (editors[b] == 1) printf " (Ed.)"
522: else if (editors[b] > 1) printf " (Eds.)"
523: punc = ".\n";
524: }
525:
526: # publisher
527: else if(issuer[b]) {
528: printf "%s%s", punc, issuer[b];
529: punc = ".\n";
530: }
531: # (date).
532: printf "%s(%s).\n", punc, date[b] ;
533: # italic(title)
534: if(title[b]) {
535: printf "\\f2\\&%s\\f1\\&", title[b];
536: # (Vol #).
537: if(volstr[b]) {
538: printf " (%s)", volstr[b];
539: punc = ".\n"
540: }
541: else if(volume[b]) {
542: printf " (Vol. %s)", volume[b];
543: punc = ".\n"
544: }
545: punc = ".\n"
546: }
547:
548: # location: publisher.
549: if (city[b]) {
550: printf "%s%s", punc, city[b] ;
551: punc = ": ";
552: }
553: if(issuer[b]) {
554: if(editors[b] || authors[b]);
555: printf "%s%s", punc, issuer[b];
556: }
557: }
558:
559: func pamphlet(b)
560: {
561:
562: punc = "";
563: # authorlist
564: if(authors[b] >0) {
565: printfull(b);
566: punc = "\n";
567: }
568: # publisher
569: else if(issuer[b]) {
570: printf "%s%s", punc, issuer[b];
571: punc = ".\n";
572: }
573: # italic(title)
574: else if(title[b]) {
575: printf "\\f2\\&%s\\f1\\&", title[b];
576: punc = ".\n"
577: }
578: # (date).
579: if(date[b]) {
580: printf "%s(%s)", punc, date[b] ;
581: punc = ".\n";
582: }
583: # italic(title)
584: if(editors[b] || authors[b] || issuer[b]) {
585: if(title[b]) {
586: printf "%s\\f2\\&%s\\f1\\&", punc, title[b];
587: punc = ".\n"
588: }
589: }
590:
591: # location: publisher.
592: if (city[b]) {
593: printf "%s%s", punc, city[b] ;
594: punc = ": ";
595: }
596: if(issuer[b]) {
597: if(editors[b] || authors[b]);
598: printf "%s%s", punc, issuer[b];
599: }
600:
601: }
602:
603: func default(b) {
604: punc = "";
605: # authorlist
606: if(authors[b]) {
607: printfull(b);
608: punc = "\n";
609: }
610: # publisher
611: else if(issuer[b]) {
612: printf "%s%s", punc, issuer[b];
613: punc = ".\n";
614: }
615: # italic(title).
616: else if(title[b]) {
617: printf "\\f2\\&%s\\f1\\&", title[b];
618: punc = ".\n"
619: }
620: # (date).
621: if(date[b]) {
622: printf "%s(%s)", punc, date[b] ;
623: punc = ".\n";
624: }
625: # italic(title)
626: if(editors[b] || authors[b] || issuer[b] ) {
627: if(title[b]) {
628: printf "%s%s", punc, title[b];
629: punc = ".\n"
630: }
631: }
632: # (Vol #, pp.).
633: if(pages[b] || volume[b]) {
634: printf punc;
635: printf "("
636: if(volstr[b]) {
637: printf volstr[b];
638: punc = ", ";
639: }
640: else if(volume[b]) {
641: printf "Vol. %s", volume[b];
642: punc = ", ";
643: }
644: if (pages[b]) {
645: if ( pages[b] ~ /[,-]/ )
646: printf "%spp. %s", punc, pages[b];
647: else
648: printf "%sp. %s", punc, pages[b];
649: }
650: printf ")";
651: punc = ".\n"
652: }
653:
654: # location: publisher.
655: if (city[b]) {
656: printf "%s%s", punc, city[b] ;
657: punc = ": ";
658: }
659: if(issuer[b]) {
660: if(editors[b] || authors[b]);
661: printf "%s%s", punc, issuer[b];
662: }
663: }
664:
665:
666: # Author, First
667: # Author, First, and Second Author
668: # Author, First, Second Author, and Remaining Authors
669:
670: func printfull(b) {
671: if ( authors[b] == 0 ) ;
672: else if ( authors[b] == 1 ) {
673: printf Afull[b,1] ;
674: if(aetal[b]) printf ", et al.";
675: }
676: else if ( authors[b] == 2 ) printf Afull[b,1] ", & " Afull[b,2];
677: else {
678: for ( j = 1 ; j < authors[b]; j++ )
679: printf Afull[b,j] ", ";
680: printf "& " Afull[b,authors[b]];
681: }
682: }
683: func printedfull(b) {
684: if ( editors[b] == 0 ) ;
685: else if ( editors[b] == 1 ) {
686: printf Efull[b,1] ;
687: if(eetal[b]) printf ", et al.";
688: }
689: else if ( editors[b] == 2 ) printf Efull[b,1] ", & " Efull[b,2];
690: else {
691: for ( j = 1 ; j < editors[b]; j++ )
692: printf Efull[b,j] ", ";
693: printf "& " Efull[b,editors[b]];
694: }
695: }
696:
697: func editorlist(b) {
698: if ( editors[b] == 0 ) ;
699: else if ( editors[b] == 1 ) printf "%s", E[b,1] ;
700: else if ( editors[b] == 2 ) printf "%s & %s", E[b,1], E[b,2];
701: else {
702: for ( j = 1; j < editors[b]; j++ ) printf E[b,j] ", ";
703: printf "& %s", E[b,editors[b]];
704: }
705: }
706:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.