#!/bin/sh echo "Content-type: text/html" 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])
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"]
summary = var["summary"]
casesensitive = var["casesensitive"]
nitems = 0
ncatalogs = 0
catalogids = ""
if (!casesensitive) {
nentry = tolower(entry);
gsub("\\ä", "%E4", nentry);
gsub("\\ö", "%F6", nentry);
gsub("\\ü", "%FC", nentry);
gsub("a", "[aA]", nentry);
gsub("b", "[bB]", nentry);
gsub("c", "[cC]", nentry);
gsub("d", "[dD]", nentry);
gsub("e", "[eE]", nentry);
gsub("f", "[fF]", nentry);
gsub("g", "[gG]", nentry);
gsub("h", "[hH]", nentry);
gsub("i", "[iI]", nentry);
gsub("j", "[jJ]", nentry);
gsub("k", "[kK]", nentry);
gsub("l", "[lL]", nentry);
gsub("m", "[mM]", nentry);
gsub("n", "[nN]", nentry);
gsub("o", "[oO]", nentry);
gsub("p", "[pP]", nentry);
gsub("q", "[qQ]", nentry);
gsub("r", "[rR]", nentry);
gsub("s", "[sS]", nentry);
gsub("t", "[tT]", nentry);
gsub("u", "[uU]", nentry);
gsub("v", "[vV]", nentry);
gsub("w", "[wW]", nentry);
gsub("x", "[xX]", nentry);
gsub("y", "[yY]", nentry);
gsub("z", "[zZ]", nentry);
gsub("%E4", "\\&[aA]uml;", nentry);
gsub("%F6", "\\&[oO]uml;", nentry);
gsub("%FC", "\\&[uU]uml;", nentry);
entry = nentry;
}
while ((getline < "../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 < "../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 ("../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 && !summary) {
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 } } if (!summary) { 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 ../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 ../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 ../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 "
There are no pictures on Z-World for the following items but they are in the indicated Märklin catalogs. See also http://z-world.com/catalogs/.
"
}
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:"]
}
}
if (summary) {
print catalogitems[i] ": " first ""
if (first != last) {
print " -> " last ""
}
print "
"
} else {
print catalogitems[i] "
"
print "First catalog: " first "
"
print "Last catalog: " last "
Back to Z-World
"
echo "`date`"
echo ""
echo ""
echo ""