changeset 1002:a835d605cb85

Get screenshots working again. (Conversion to Vladimir Dronnikov's new layout underway, just going slowly...)
author Rob Landley <rob@landley.net>
date Thu, 18 Mar 2010 02:25:11 -0500
parents c381381fa460
children 6d3db5bf731a
files www/screenshots/screenshots.sh
diffstat 1 files changed, 30 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/www/screenshots/screenshots.sh	Thu Mar 18 02:20:23 2010 -0500
+++ b/www/screenshots/screenshots.sh	Thu Mar 18 02:25:11 2010 -0500
@@ -1,6 +1,32 @@
 #!/bin/bash
 
-escape_screenshot()
+# Take 80x25 screen shot from the end of a text file, and excape it for html.
+
+process_text_file()
+{
+  X=0
+
+  # Break into 80 line chunks, substituting &, < and >
+  sed -e 's/\(................................................................................\)/\1\n/g' "$1" | \
+  tail -n 25 | while read i
+  do
+    echo -n "$i" | sed -e 's@\&@\&amp;@g' -e 's@<@\&lt;@g' -e 's@>@\&gt;@g'
+
+    # If the first line is shorter than 80 characters, pad it.
+    if [ $X -eq 0 ]
+    then
+      X=${#i}
+      while [ $X -lt 80 ]
+      do
+        echo -n '&nbsp;'
+        X=$[$X+1]
+      done
+    fi
+    echo
+  done
+}
+
+wrap_screenshot()
 {
   echo '</center></td></tr><tr>'
 
@@ -20,32 +46,15 @@
 </ul></td>
 EOF
 
-
   echo '<td>'
   echo '<table bgcolor=#000000><tr><td><font color=#ffffff size=-2><pre>'
-
-  i=0
-  while [ $i -lt 80 ]
-  do
-    echo -n '&nbsp;'
-    i=$[$i+1]
-  done
-  echo
-  sed -e 's/\(................................................................................\)/\1\n/g' \
-      -e 's@\&@\&amp;@g' -e 's@<@\&lt;@g' -e 's@>@\&gt;@g' \
-      "screenshot-$1.txt" | tail -n 25
-
+  process_text_file "screenshot-$1.txt"
   echo '</pre></font></td></tr></table></td>'
   echo
   echo '</tr></table></td>'
 }
 
-process_screenshot()
-{
-  escape_screenshot "$1" > "screenshot-$1.html"
-}
-
-for i in *.txt
+for i in $(ls screenshot-*.txt | sed 's/screenshot-\(.*\)\.txt/\1/')
 do
-  process_screenshot "$(echo "$i" | sed 's/screenshot-\(.*\)\.txt/\1/')"
+  wrap_screenshot "$i" > "screenshot-$i.html"
 done