Subversion Repositories wimsdev

Rev

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