#!/bin/awk -f # process-biblio.awk # Copyright (C) 2000, Seth David Schoen # This program is free software WITHOUT ANY WARRANTY. You may distribute # and modify it under the terms of the GNU General Public License, version # 2 or (at your option) any later version. # The use of gensub to make hyphenless ISBN anchors may be non-portable # to versions of awk other than gawk. function header() { print ""; print ""; print "

"; print "This list is generated automatically by a script based on the current"; print "contents of my database. This is a list of books I have (in California);"; print "I have only entered about 50% of my library so far."; print "I also have a separate list of books I would like"; print "to have.

"; print "

"; print "Books with a known ISBN are linked to BookFinder.com, a powerful search engine"; print "created by my friend Anirvan Chatterjee"; print "and maintained by his company 13th Generation Media."; print "I don't receive any commission or compensation for"; print "recommending books."; print "These links are provided solely for your convenience"; print "in case you are interested in obtaining a copy of one of these"; print "titles.

"; print "

"; print "I invite you to join me in boycotting Amazon.com.

" print "

"; print "Thanks to Erik Klavon for"; print "suggestions and advice.

"; print "

"; print "This list was generated on "; system("date +'%A, %B %d, %Y, at %H:%M.'"); print "

"; print "

\n"); printf("

\n"); printf("\n"); printf("\n"); } function noperiod(a){ # Delete final periods if (substr(a, length(a), 1) == ".") return substr(a, 1, length(a)-1) else return a; } function hyphenless(a){ return gensub("-", "", "g", a); } function buyurl(i){ # Print out a URL to allow the user to buy the book with ISBN i return "http://www.bookfinder.com/search/?author=&title=&submit=Begin+Search&isbn=" i "¤cy=USD&mode=advanced&st=sr&ac=qr"; } BEGIN { IFS="\t"; FS="\t"; header(); } { printf("
  • "); last=$1 first=$2 title=$3 place=$4 publisher=$5 year=$6 delete optional; if ((last first) != oldname) printf("", tolower(last) "," tolower(first)); oldname = last first; for (i = 7; i <= NF; i++) { split($i, a, ":"); # Delete parentheses if (substr(a[2], 1, 1) == "(") a[2]=substr(a[2], 2, length(a[2])-2); optional[a[1]] = a[2]; } if (optional["ISBN"]) { printf("", optional["ISBN"]); printf("", hyphenless(optional["ISBN"])); } # Is an author's first name given? if (first == "") printf("%s", last) else printf("%s, %s", last, first); # Have to check for co-authors if (optional["OTHERS"]) { printf(", "); if (!(match(optional["OTHERS"], " and ") || match(optional["OTHERS"], "et al"))) printf(" and %s", optional["OTHERS"]); else printf(" %s", optional["OTHERS"]); } # Have to check for role if (optional["ROLE"] != "") printf(" (%s), ", optional["ROLE"]) else printf(", "); printf("%s", title); # This gets complicated, because place, publisher, and year are _all_ # optional, and the formatting of the output depends on which are # supplied. if (place == "") if (!((publisher == "") && (year == ""))) { printf(" ("); if (publisher == "") printf("%s)", year); else printf("%s, %s)", publisher, year); }; if (place != "") { printf(" (%s", place); if (publisher == "") printf(", %s)", year) else { printf(": %s", publisher); if (year == "") printf(")") else printf(", %s)", year); } } printf("."); # Now we get into optional tagged fields like ISBN and the like. if (optional["NOTE"] != "") printf(" %s.", noperiod(optional["NOTE"])); if (optional["EDITION"] != "") printf(" %s.", noperiod(optional["EDITION"])); if (optional["VOLUME"] != "") printf(" %s.", noperiod(optional["VOLUME"])); if (optional["ISBN"] != "") printf(" ISBN %s.", buyurl(optional["ISBN"]), optional["ISBN"]); if (optional["LOC"] != "") printf(" Library of Congress Card No. %s.", optional["LOC"]); printf("\n"); } END { footer(); }