Subversion Repositories wimsdev

Rev

Rev 12107 | Rev 13945 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #!/bin/sh
  2. # do not run compile time !
  3. # generates simple canvasdraw usage html-page and a javascript live example
  4.  
  5. echo "install into wims distribution(D)
  6. or use for local testing (L) ?
  7. D,L ?"
  8. read ans
  9. helpdir="../../../public_html/scripts/help/en"
  10. if [ $ans == "D" ]; then
  11.  # path used for href/http link !
  12.  jsdir="scripts/help/en/examples"
  13.  mkdir -p "$helpdir/examples"  2>/dev/null
  14. else
  15.  jsdir="./examples"
  16. fi
  17. in="canvasdraw.c"
  18. phtml="canvasdraw.phtml"
  19. html="canvasdraw.html"
  20. tmp="canvas_index"
  21. keys="keywords"
  22. datum=`date +%d-%m-%Y`
  23. htmlhead="<!DOCTYPE html><html><body>"
  24. htmltail="</body></html>"
  25. interaction="<script type=\"text/javascript\">\"use strict\";function read_canvas(){if( typeof popup !== 'undefined' ){var fun = popup['read_canvas'+canvas_scripts[0]];return fun();}else{var script_len = canvas_scripts.length;var draw_reply = \"\";var found_result = false;for(var p = 0 ; p < script_len ; p++){var fun = eval(\"read_canvas\"+canvas_scripts[p]);if( typeof fun === 'function'){var result = fun();if( result  && result.length != 0){if(script_len == 1 ){ return result;};found_result = true;draw_reply = draw_reply + \"[\"+p+\"]=\"+ result + \"\n\";};};};if( found_result ){return draw_reply;}else{return null;}};};function read_dragdrop(){if( typeof popup !== 'undefined' ){var fun = popup['read_dragdrop'+canvas_scripts[0]];return fun();}else{var script_len = canvas_scripts.length;var dragdrop_reply = \"\";var found_result = false; for(var p = 0 ; p < script_len ; p++){var fun = eval(\"read_dragdrop\"+canvas_scripts[p]); if(typeof fun === 'function'){var result = fun();if( result && result.length != 0 ){if(script_len == 1 ){ return result;};found_result = true;dragdrop_reply = dragdrop_reply + \"[\"+p+\"]=\" + result +\"\n\";};};};if( found_result ){return dragdrop_reply;}else{return null;}};};</script><input type=\"button\" onclick=\"alert(read_canvas());\" value=\"read_canvas()\" /><input type=\"button\" onclick=\"alert(read_dragdrop());\" value=\"read_dragdrop()\" />"
  26.  
  27. # these are only used to simulate a wims session
  28. export "w_wims_session"="example"
  29. export "w_session"="123"
  30. export "w_wims_home"="/var/wims/src/Misc"
  31. wims_tmp="../sessions/example/getfile/"
  32. mkdir -p $wims_tmp
  33. # the popup html pages and corresponding javascript includes are locate here
  34. tmpdir="examples"
  35. rm -rf $tmpdir
  36. mkdir $tmpdir 2>/dev/null
  37.  
  38. echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\" \"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd\">
  39. <html>
  40. <head><meta charset=\"UTF-8\"></head>
  41. <body xmlns=\"http://www.w3.org/1999/xhtml\" class=\"main_body\" dir=\"ltr\">
  42. <style type='text/css'>
  43. a:link {color:#004077;text-decoration:none;cursor:pointer;}
  44. a:hover {color:#dd6300;}
  45. a:visited {color:#004077;}
  46. </style>"> $html
  47.  
  48. echo "
  49. <input type='text' size='10' value='' id='search'  onkeydown='javascripts:if(event.keyCode == 13){look();}'/><input type='button' onclick='javascript:look();' value='search' />
  50. <h2 style='text-align:center'>Implemented canvasdraw commands ($datum)</h2>
  51. <table style='color:blue;font-size:0.8em;'><tr>
  52. " > $phtml
  53.  
  54. p=0
  55. echo "<ul>" > $tmp
  56. cnt=0
  57. br=8
  58. while read line ; do
  59.  chk=`echo "$line" | grep "@"`
  60.  if [ ! -z "$chk" ] ; then
  61.   chk=`echo "$chk" | grep @%`
  62.   if [ -z "$chk" ] ; then
  63.    echo $line
  64.    if [ $p -eq 0 ]; then
  65.     string=`echo "$line" | tr '@' ' '`
  66.     idx=`echo "$string" | awk '{ print $1 }'`
  67.     echo ",'$idx'" >> $keys
  68.     if [ $cnt -gt $br ]; then
  69.      echo "</tr><tr>" >> $phtml
  70.      cnt=0
  71.     fi
  72.     cnt=$(($cnt+1))
  73.     echo "<td><a name='$idx top' href='#$idx'>$idx</a></td>" >> $phtml
  74.     echo "<li><a name='$idx' href='#$idx top'>$string</a><ul>"  >> $tmp
  75.     p=1
  76.    else
  77.     p=2
  78.     alt=`echo "$line" | grep "@ alternative :" | awk '{ print $4 }' | tr -d '[:blank:]'`
  79.     if [ ! -z $alt ] ; then
  80.      if [ $cnt -gt $br ]; then
  81.       echo "</tr><tr>" >> $phtml
  82.       cnt=0
  83.      fi
  84.      cnt=$(($cnt+1))
  85.      echo ",'$alt'" >> $keys
  86.      echo "<td><a name='$alt top' href='#$idx'>$alt</a></td>" >> $phtml
  87.      echo "<li><span style=\"color:blue;font-size:0.8em\">alternative command:<a name='$alt' href='#$alt top'>$alt</a></span></li>"  >> $tmp
  88.     else
  89.      echo $line | sed 's/@/<li><span style="color:blue;font-size:0.8em">/g'  >> $tmp
  90.      echo  "</span></li>" >> $tmp
  91.     fi
  92.    fi
  93.   else
  94.  # begin generating live examples signalled by @%
  95.    name=`echo "$chk" | awk -F'%' '{ print $2 }'  `
  96.    echo "command $name"
  97.    cont=`echo "$chk" |  tr '%' '\n'`
  98.    echo "$cont" | sed '1,2d'> $tmpdir/$name.txt
  99.    echo "$htmlhead" > $tmpdir/$name.html
  100.    cat $tmpdir/$name.txt | ~/other/bin/canvasdraw | sed 's/src=\"wims.cgi?session=123*.*.js\"/src=\"'$name'.js\"/g' >> $tmpdir/$name.html
  101.    echo "<li><span style=\"color:red;font-size:0.8em\">live example: <a href=\"$jsdir/$name.html\" target=\"_blank\">$name</a></span></li>" >> $tmp
  102.    echo "<textarea cols='60' rows='10'>" >> $tmpdir/$name.html
  103.    echo "$cont" | sed '1,2d' >> $tmpdir/$name.html
  104.    echo "</textarea>" >> $tmpdir/$name.html
  105.    echo "$interaction" >> $tmpdir/$name.html
  106.    echo "$htmltail" >> $tmpdir/$name.html
  107.    mv -v $wims_tmp/*.js $tmpdir/$name.js
  108.   fi
  109.  else
  110.   if [ $p -eq 2 ]; then
  111.    echo  "</ul>" >> $tmp
  112.   fi
  113.   p=0
  114.  fi
  115. done < $in
  116.  
  117. while [ $cnt -le $br ] ; do
  118.  cnt=$(($cnt+1))
  119.  echo "<td>&nbsp;</td>" >> $phtml
  120. done
  121. echo "</tr></table>" >> $phtml
  122.  
  123. cat $tmp >> $phtml
  124.  
  125. keywords=`cat $keys | tr -d '\n'`
  126. echo "
  127. </li>
  128. </ul>
  129. <script type='text/javascript'>
  130. var keys = ['canvasdraw' $keywords];
  131. var keys_len = keys.length;
  132. function match(s1,s2){
  133.  var n1 = s1.length;
  134.  if(n1 < 3){return 0;}
  135.  var n2 = s2.length;
  136.  var c1,c2,found;
  137.  var count = n1 - Math.abs(n1 - n2);
  138.  for(var p = 0;p < n1;p++){
  139.   c1=s1.charAt(p);
  140.   found = false;
  141.   for(var i = 0;i < n2;i++){
  142.    c2 = s2.charAt(i);
  143.    if(c1 == c2){found = true;count = count + n1 - Math.abs(p - i);}
  144.   };
  145.   if(! found ){count = count - n2;}
  146.  };
  147.  return count;
  148. };
  149. function look(){
  150.  var s = ((document.getElementById('search').value).replace(/\s/g, '')).toLowerCase();
  151.  var typo;var next_best = -1;var next_idx = s.length;var tmp;var ss;
  152.  for(var p = 0; p < keys_len ; p++){
  153.   ss = keys[p];
  154.   if( s == ss ){
  155.    window.location.href = '#'+ss;
  156.    return;
  157.   };
  158.   /* not ok? ... try to find a match for a reasonable typo... */
  159.   tmp = match(s,ss);
  160.   if(tmp > next_idx){
  161.    next_idx = tmp;
  162.    next_best = p;
  163.   };
  164.  };
  165.  if(next_best != -1 ){
  166.   typo = keys[next_best];
  167.   if(confirm('\"'+s+'\" is not a valid canvasdraw command\ndid you mean \"'+typo+'\" ?')){
  168.    window.location.href = '#'+typo;
  169.    return;
  170.   };
  171.  }
  172.  else
  173.  {
  174.   alert(s+' is not a valid canvasdraw command');
  175.  };
  176.  return;
  177. };
  178. </script>" >> $phtml
  179.  
  180. cat $phtml >> $html
  181. echo "
  182. </body>
  183. </html>" >> $html
  184.  
  185. # install in wims distribution scripts/help/en
  186. if [ $ans == "D" ] ; then
  187. mv $phtml $helpdir
  188. cp -rv $tmpdir $helpdir
  189. fi
  190.  
  191. rm $tmp
  192. rm $keys
  193.  
  194.  
  195.  
  196.