#! /bin/sh echo "Content-type: text/html" echo echo "" echo "" echo "" echo "Find Item" echo "" echo "" echo "" echo "\"\"

" echo "

" 2>&1 awk -v query_string="$QUERY_STRING" ' BEGIN { split(query_string, a, "&") for (i in a) { gsub( "\\+", " ", a[i]) gsub("%20", " ", a[i]) gsub("%21", "!", a[i]) gsub("%22", "\"", a[i]) gsub("%23", "#", a[i]) gsub("%24", "$", a[i]) gsub("%25", "%", a[i]) gsub("%26", "\\&", a[i]) gsub("%27", "'"'"'", a[i]) gsub("%28", "\(", a[i]) gsub("%29", "\)", a[i]) gsub("%2A", "*", a[i]) gsub("%2B", "\\+", a[i]) gsub("%2C", ",", a[i]) gsub("%2D", "-", a[i]) gsub("%2E", ".", a[i]) gsub("%2F", "/", a[i]) gsub("%3A", ":", a[i]) gsub("%3B", ";", a[i]) gsub("%3C", "<", a[i]) gsub("%3D", "=", a[i]) gsub("%3E", ">", a[i]) gsub("%3F", "?", a[i]) gsub("%40", "@", a[i]) gsub("%5B", "[", a[i]) gsub("%5C", "\\", a[i]) gsub("%5D", "]", a[i]) gsub("%5E", "^", a[i]) gsub("%5F", "_", a[i]) gsub("%60", "\`", a[i]) gsub("%7B", "{", a[i]) gsub("%7C", "|", a[i]) gsub("%7D", "}", a[i]) gsub("%7E", "~", a[i]) gsub("%C4", "\\Ä", a[i]) gsub("%D6", "\\Ö", a[i]) gsub("%DC", "\\Ü", a[i]) gsub("%DF", "\\ß", a[i]) gsub("%E4", "\\ä", a[i]) gsub("%F6", "\\ö", a[i]) gsub("%FC", "\\ü", a[i]) split(a[i], b, "="); var[b[1]] = b[2]; } entry = var["entry"] items = var["items"] dates = var["dates"] titles = var["titles"] descriptions = var["descriptions"] nitems = 0 ncatalogs = 0 catalogids = "" while ((getline < "/Library/WebServer/Documents/z-world/db/catalogs.txt") > 0) { while (NF > 0) { if (tmpkeys[$1]) { tmpkeys[$1] = tmpkeys[$1] " " substr($0, length($1)+2, 1+length($0)-length($1)) } else { tmpkeys[$1] = substr($0, length($1)+2, length($0)-(1+length($1))) } r = getline < "/Library/WebServer/Documents/z-world/db/catalogs.txt" if (r != 1) { break } } if (tmpkeys["id:"]) { catalogids = catalogids " " tmpkeys["id:"] for (i in tmpkeys) { if (i != "id:") { catalogs[tmpkeys["id:"], i] = tmpkeys[i] } } ncatalogs = ncatalogs + 1 } delete tmpkeys } close ("/Library/WebServer/Documents/z-world/db/catalogs.txt") split(catalogids, a, " ") for (i in a) { split(catalogs[a[i], "contents:"], b, " ") for (j in b) { itemcataloged[b[j]] = itemcataloged[b[j]] " " a[i] } } } /^#/ { next } { while (NF > 0) { if (tmpkeys[$1]) { tmpkeys[$1] = tmpkeys[$1] " " substr($0, length($1)+2, 1+length($0)-length($1)) } else { tmpkeys[$1] = substr($0, length($1)+2, length($0)-(1+length($1))) } r = getline if (r != 1) { break } } if (tmpkeys["item:"]) { for (i in tmpkeys) { keys[nitems, i] = tmpkeys[i] } nitems = nitems + 1 } delete tmpkeys } END { #print entry, items, titles, descriptions "
" nfound = 0 nfoundincatalog = 0 for (i in itemcataloged) { if (i ~ entry) { foundincatalog[i] = "true" nfoundincatalog++ continue } } for (i = 0; i < nitems; i++) { if (items) { if (keys[i, "item:"] ~ entry || keys[i, "aka:"] ~ entry) { found[nfound++] = i if (keys[i, "item:"] in foundincatalog) { delete foundincatalog[keys[i, "item:"]] nfoundincatalog-- } if (keys[i, "aka:"] in foundincatalog) { delete foundincatalog[keys[i, "aka:"]] nfoundincatalog-- } if (keys[i, "variation:"]) { variations = 1 } continue } } if (titles) { if (keys[i, "title:"] ~ entry) { if (keys[i, "item:"] in foundincatalog) { delete foundincatalog[keys[i, "item:"]] nfoundincatalog-- } if (keys[i, "aka:"] in foundincatalog) { delete foundincatalog[keys[i, "aka:"]] nfoundincatalog-- } if (keys[i, "variation:"]) { variations = 1 } found[nfound++] = i continue } } if (descriptions) { if (keys[i, "description:"] ~ entry) { if (keys[i, "variation:"]) { variations = 1 } found[nfound++] = i if (keys[i, "item:"] in foundincatalog) { delete foundincatalog[keys[i, "item:"]] nfoundincatalog-- } if (keys[i, "aka:"] in foundincatalog) { delete foundincatalog[keys[i, "aka:"]] nfoundincatalog-- } continue } } if (dates) { if (keys[i, "date:"] ~ entry) { if (keys[i, "item:"] in foundincatalog) { delete foundincatalog[keys[i, "item:"]] nfoundincatalog-- } if (keys[i, "aka:"] in foundincatalog) { delete foundincatalog[keys[i, "aka:"]] nfoundincatalog-- } if (keys[i, "variation:"]) { variations = 1 } found[nfound++] = i continue } } } if (!items) { nfoundincatalog = 0 } if ((nfound + nfoundincatalog) == 1) { print "1 match for " entry "
" } else { print (nfound + nfoundincatalog) " matches for " entry "
" } if (variations) { print "about variations" } print "

" sort(found, nfound) for (i = 0; i < nfound; i++) { nvars = 0 for (j = i+1; j < nfound; j++) { if (keys[found[i], "item:"] == keys[found[j], "item:"]) { if (keys[found[i], "start-date:"] == keys[found[j], "start-date:"]) { if (keys[found[i], "end-date:"] == keys[found[j], "end-date:"]) { nvars++ } else { break } } else { break } } else { break } } print keys[found[i], "item:"] ": " "" keys[found[i], "title:"] "

" for (k = 0; k <= nvars; k++) { if (keys[found[i+k], "graphic:"]) { n = split(keys[found[i+k], "graphic:"], a, " ") for (j = 1; j <= n; j++) { n2 = split(a[j], b, "/") cmd = "test -e /Library/Webserver/Documents/z-world/graphics/z/new/fullsize/" b[n2] r = system(cmd) close(cmd) if (r == 0) { print "" } else { print "" } } if (keys[found[i+k], "reverse-graphic:"]) { n = split(keys[found[i+k], "reverse-graphic:"], a, " ") for (j = 1; j <= n; j++) { n2 = split(a[j], b, "/") cmd = "test -e /Library/Webserver/Documents/z-world/graphics/z/new/fullsize/" b[n2] r = system(cmd) close(cmd) if (r == 0) { print "" } else { print "" } } } if (keys[found[i+k], "top-graphic:"]) { n = split(keys[found[i+k], "top-graphic:"], a, " ") for (j = 1; j <= n; j++) { n2 = split(a[j], b, "/") cmd = "test -e /Library/Webserver/Documents/z-world/graphics/z/new/fullsize/" b[n2] r = system(cmd) close(cmd) if (r == 0) { print "" } else { print "" } } } print "
" if (keys[found[i+k], "variation:"]) { printf "Variation: " keys[found[i+k], "variation:"] if (keys[found[i+k], "variation-comment:"]) { print ", " keys[found[i+k], "variation-comment:"] } print "
" if (keys[found[i+k], "variation-start:"]) { vstart = keys[found[i+k], "variation-start:"] if (keys[found[i+k], "variation-end:"]) { vend = keys[found[i+k], "variation-end:"] if (vstart == vend) { print vstart } else { print vstart "-" vend } } else { print vstart "-" } } } } print "

" } print keys[found[i], "description:"] "

" if (keys[found[i], "date:"]) { print "Date: " keys[found[i], "date:"] print "

" } if (keys[found[i], "aka:"]) { gsub(" ", ", ", keys[found[i], "aka:"]) print "AKA: " keys[found[i], "aka:"] print "

" } if (keys[found[i], "length-over-buffers:"]) { print "Length over buffers: " keys[found[i], "length-over-buffers:"] " mm (" mm2inch(keys[found[i], "length-over-buffers:"]) ")" print "

" } if (keys[found[i], "total-length:"]) { print "Total length: " keys[found[i], "total-length:"] " mm (" mm2inch(keys[found[i], "total-length:"]) ")" print "

" } if (keys[found[i], "train-length:"]) { print "Train length: " keys[found[i], "train-length:"] " mm (" mm2inch(keys[found[i], "train-length:"]) ")" print "

" } if (keys[found[i], "length:"]) { print "Length: " keys[found[i], "length:"] " mm (" mm2inch(keys[found[i], "length:"]) ")" print "

" } if (keys[found[i], "availability:"]) { print "" keys[found[i], "availability:"] "" print "

" } startdate = 197200 enddate = 999900 if (keys[found[i], "start-date:"]) { startdate = keys[found[i], "start-date:"] "00" } if (keys[found[i], "end-date:"]) { enddate = keys[found[i], "end-date:"] "99" } if ((keys[found[i], "catalog:"] != "lic") && itemcataloged[keys[found[i], "item:"]]) { split(itemcataloged[keys[found[i], "item:"]], a, " ") firstdate = 999999 lastdate = 0 first = last = "" for (k in a) { if (catalogs[a[k], "date:"] < firstdate && catalogs[a[k], "date:"] >= startdate) { firstdate = catalogs[a[k], "date:"] first = catalogs[a[k], "title:"] } if (catalogs[a[k], "date:"] > lastdate && catalogs[a[k], "date:"] <= enddate) { lastdate = catalogs[a[k], "date:"] last = catalogs[a[k], "title:"] } } print "First catalog: " first "
" print "Last catalog: " last "

" } print "


" if (nvars) { i += nvars } } if (items) { n = 0; for (k in foundincatalog) { if (foundincatalog[k] == "true") { # awk bug workaround - when array items are deleted they are in fact replaced using zero based index with null value catalogitems[n++] = k } } sort(catalogitems, n) for (i = 0; i < n; i++) { split(itemcataloged[catalogitems[i]], a, " ") firstdate = 999999 lastdate = 0 first = last = "" for (k2 in a) { if (catalogs[a[k2], "date:"] < firstdate) { firstdate = catalogs[a[k2], "date:"] first = catalogs[a[k2], "title:"] } if (catalogs[a[k2], "date:"] > lastdate) { lastdate = catalogs[a[k2], "date:"] last = catalogs[a[k2], "title:"] } } print catalogitems[i] "

" print "First catalog: " first "
" print "Last catalog: " last "


" } } if (!nfound && !nfoundincatalog) { print "" entry " not found
" } } function mm2inch(mm) { inches = mm/25.4; whole = int(inches) fraction = inches - whole inches = whole sixteenths = fraction * 16 whole = int(sixteenths) fraction = sixteenths - whole if (fraction > .5) { whole++ } if (whole == 16) { inches++ whole = 0 } if (int(whole/2) != whole/2) { return inches "-" whole "/16\"" } whole = whole/2 if (int(whole/2) != whole/2) { return inches "-" whole "/8\"" } whole = whole/2 if (int(whole/2) != whole/2) { return inches "-" whole "/4\"" } whole = whole/2 if (int(whole/2) != whole/2) { return inches "-" whole "/2\"" } return inches "\"" } function sort(ARRAY, ELEMENTS, temp, i, j) { for (i = 1; i < ELEMENTS; ++i) for (j = i; ARRAY[j-1] > ARRAY[j]; --j) { temp = ARRAY[j] ARRAY[j] = ARRAY[j-1] ARRAY[j-1] = temp } return } ' /Library/WebServer/Documents/z-world/db/master.txt echo "

Back to Z-World
" echo "`date`" echo "" echo "" echo ""