#  # ! = Plain-text version of search string
#  # @ = Lua version w/ dates
#  # ^ = Lua version w/out dates
#  S1 or C4 etc.. the Lua variable name for the string

# To generate Lua code
#  w/dates:
#    grep '#@' ia3.csh | awk -F\| '{if(! match($0,"ALL")) printf("      -- %s\n",$4); printf("      local %s = %s\n",$2,$3)}'
#  w/out dates:
#    grep '#^' ia3.csh | awk -F\| '{if(! match($0,"ALL")) printf("      -- %s\n",$4); printf("      local %s = %s\n",$2,$3)}'
#
# To list wpname's with multiple extended characters
#  awk -F\| '{s = $1; c = gsub(/[\x80-\xFF]/,"", s); if(c > 1) print $0}' gutenberg.dat
#
# Possible options:
#   &groupby=mediatype&sort=-downloads
#

set firstinitial = `$AWK -v s="$name1" 'BEGIN{printf("%-1c",s)}'` 
set middleinitial = `$AWK -v s="$name2" 'BEGIN{printf("%-1c",s)}'` 
if("$firstinitial" == "%") then
  set firstinitial = `$AWK -v s="$name1" 'BEGIN{printf("%s%s%s","%22",sprintf("%-1c",substr(s,4,1)),"%22")}'`
endif
if("$middleinitial" == "%") then
  set firstinitial = `$AWK -v s="$name1" 'BEGIN{printf("%-1c",substr(s,4,1))}'`
endif

echo "firstinitial=" "$firstinitial" > /dev/stderr

echo -n '* [' > "$WI_TEMP""tmpO"
echo -n '<!---wp:prurl-->//archive.org/search.php?query=-contributor%3Agutenberg%20AND%20' >> "$WI_TEMP""tmpO"

# First record starts with "%28", following records start with "%20OR%20"

#! (First Middle Last)
#@ |S1|"%28"..N[FIRST].."%20"..N[MIDDLE].."%20"..N[LAST].."%29"|(First Middle Last)
#^ |S1|"%28"..N[FIRST].."%20"..N[MIDDLE].."%20"..N[LAST].."%29"|(First Middle Last)
echo -n '%28'"$name1"'%20'"$name2"'%20'"$name3"'%29' >> "$WI_TEMP""tmpO"

#! (First Middle Last birthyear-deathyear)
#@ |S2|"%20OR%20%28"..N[FIRST].."%20"..N[MIDDLE].."%20"..N[LAST].."%20"..birth.."-"..death.."%29"|(First Middle Last birthyear-deathyear)
if("$birthdeath" != "") then
  echo -n '%20OR%20%28'"$name1"'%20'"$name2"'%20'"$name3"'%20'"$birth"'-'"$death"'%29' >> "$WI_TEMP""tmpO"
endif

#! (F. M. Last)
#@ |S3|"%20OR%20%28"..firstinitial.."%2E%20"..middleinitial.."%2E%20"..N[LAST].."%29"|(F. M. Last)
#^ |S3|"%20OR%20%28"..firstinitial.."%2E%20"..middleinitial.."%2E%20"..N[LAST].."%29"|(F. M. Last)
echo -n '%20OR%20%28'"$firstinitial"'%2E%20'"$middleinitial"'%2E%20'"$name3"'%29' >> "$WI_TEMP""tmpO"

#! (F. M. Last birthyear-deathyear)
#@ |S4|"%20OR%20%28"..firstinitial.."%2E%20"..middleinitial.."%2E%20"..N[LAST].."%20"..birth.."-"..death.."%29"|(F. M. Last birthyear-deathyear)
if("$birthdeath" != "") then
  echo -n '%20OR%20%28'"$firstinitial"'%2E%20'"$middleinitial"'%2E%20'"$name3"'%20'"$birth"'-'"$death"'%29' >> "$WI_TEMP""tmpO"
endif

#! (First M. Last)
#@ |S5|"%20OR%20%28"..N[FIRST].."%20"..middleinitial.."%2E%20"..N[LAST].."%29"|(First M. Last)
#^ |S5|"%20OR%20%28"..N[FIRST].."%20"..middleinitial.."%2E%20"..N[LAST].."%29"|(First M. Last)
echo -n '%20OR%20%28'"$name1"'%20'"$middleinitial"'%2E%20'"$name3"'%29' >> "$WI_TEMP""tmpO"

#! (First M. Last birthyear-deathyear)
#@ |S6|"%20OR%20%28"..N[FIRST].."%20"..middleinitial.."%2E%20"..N[LAST].."%20"..birth.."-"..death.."%29"|(First M. Last birthyear-deathyear)
if("$birthdeath" != "") then
  echo -n '%20OR%20%28'"$name1"'%20'"$middleinitial"'%2E%20'"$name3"'%20'"$birth"'-'"$death"'%29' >> "$WI_TEMP""tmpO"
endif

#! (First Last)
#@ |S7|"%20OR%20%28"..N[FIRST].."%20"..N[LAST].."%29"|(First Last)
#^ |S7|"%20OR%20%28"..N[FIRST].."%20"..N[LAST].."%29"|(First Last)
echo -n '%20OR%20%28'"$name1"'%20'"$name3"'%29' >> "$WI_TEMP""tmpO"

#! (First Last birthyear-deathyear)
#@ |S8|"%20OR%20%28"..N[FIRST].."%20"..N[LAST].."%20"..birth.."-"..death.."%29"|(First Last birthyear-deathyear)
if("$birthdeath" != "") then
  echo -n '%20OR%20%28'"$name1"'%20'"$name3"'%20'"$birth"'-'"$death"'%29' >> "$WI_TEMP""tmpO"
endif

#@ |SALL|S1..S2..S3..S4..S5..S6..S7..S8| 
#^ |SALL|S1..S3..S5..S7| 

echo -n ' ' >> "$WI_TEMP""tmpO"
echo -n "Works by or about " >> "$WI_TEMP""tmpO"
echo -n "$name1" "$name2" "$name3" >> "$WI_TEMP""tmpO"
echo -n '] at [[Internet Archive]] (scanned books original editions color illustrated)' >> "$WI_TEMP""tmpO"
echo >> "$WI_TEMP""tmpO"



