#! /bin/bash
# Last edited on 2003-09-15 20:24:24 by stolfi

for f in [0-9]*[0-9] ; do
  echo "$f" 1>&2
  echo -n "$f/" > $f/.main
  if [ -r $f/p.png ]; then
    cat $f/p.comments \
      | grep 'run-povray-png'\
      | tail -1 \
      | gawk '//{print $(NF)}' \
      >> $f/.main
  else
    echo 'no-png' >> $f/.main
  fi
done

cat [0-9]*[0-9]/.main \
  | sort -b +1 -2 \
  | grep -v '/no-png' \
  > .mains

/bin/rm -f .captions
for main in `cat .mains` ; do
  echo ${main} 1>&2
  cat ${main} \
    | gawk -v f="${main}" \
        ' BEGIN {s = "NOSTYLE"; v = "NOVIEW"; g = "NOLIGHTS"; } \
          // { \
            gsub(/[\/][\/].*/, "", $0); \
            gsub(/[#]include *["]/, "#include ", $0); \
            gsub(/[.]inc["]/, "", $0); \
          } \
          /[#]include *fgstyle/ { s = $2; next; } \
          /[#]include *dcc-view/ { v = $2; next; } \
          /[#]include *dcc-lights/ { g = $2; next; } \
          END { printf "%s:%s:%s:%s\n", f, s, v, g; } \
        ' \
    >> .captions
done

cat <<EOF
<html>
<head><title>Test of IC logos</title></head>
<body bgcolor="#20a0b0"> 

<h1>IC Logos</h1>

<table border=0 cellspacing=0 cellpadding=0>
  <tr align=center>
EOF

cat .captions \
  | tr '/' ':' \
  | sort -t: +1 -5 \
  | gawk \
      ' // { gsub(/[:/]/, " ", $0); } \
        (n == 4) { printf "  <tr>\n  <tr align=center>\n"; n = 0; } \
        // { d = $1; f = $2; s = $3; v = $4; g = $5; \
             gsub(/fgstyle-/, "", s); \
             gsub(/dcc-view-/, "", v); \
             gsub(/dcc-lights-/, "", g); \
             printf "    <td><img src=\"%s/p.png\"><br>%s<br>%s", d, d, f; \
             printf "<br><small>style %s view %s lights %s</small></td>\n", s, v, g; \
             n++; \
           } \
      '

cat <<EOF
  </tr>
</table>

<!-- Last edited on `yyyy-mm-dd-hhmmss` by $0 -->
</body>
</html>
EOF

  
  
        
