Subversion Repositories wimsdev

Rev

Rev 17177 | 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. # See the generated canvasdraw help at http://localhost/wims/?module=adm/createxo&cmd=help&special_parm=canvasdraw
  6.  
  7. ##echo "install into wims distribution(D)
  8. ##or use for local testing (L) ?
  9. ##D,L ?"
  10. ##read ans
  11. ans="D"
  12. helpdir="../../../public_html/scripts/help"
  13. if [ $ans = "D" ]; then
  14.   # path used for href/http link !
  15.   jsdir="scripts/help/canvas_examples"
  16.   mkdir -p "$helpdir/canvas_examples" 2>/dev/null
  17. else
  18.   jsdir="./examples"
  19. fi
  20. in="canvasdraw.c"
  21. phtml="canvasdraw.phtml"
  22. # html="canvasdraw.html"
  23. tmp="canvas_index"
  24. keys="keywords"
  25. datum=`date +%d-%m-%Y`
  26. # htmlhead="<!DOCTYPE html><html><body>"
  27. # htmltail="</body></html>"
  28. # interaction="<script>\"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()\">"
  29.  
  30. # these are only used to simulate a wims session
  31. export "w_wims_session"="example"
  32. export "w_session"="123"
  33. export "w_wims_home"="/var/wims/src/Misc"
  34. #wims_tmp="../sessions/example/getfile/"
  35. #mkdir -p $wims_tmp
  36. # the popup html pages and corresponding javascript includes are locate here
  37. tmpdir="canvas_examples"
  38. rm -rf $tmpdir
  39. mkdir $tmpdir 2>/dev/null
  40.  
  41. ##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\">
  42. ##<html>
  43. ##<head><meta charset=\"UTF-8\"></head>
  44. ##<body xmlns=\"http://www.w3.org/1999/xhtml\" class=\"main_body\" dir=\"ltr\">
  45. ##<style type='text/css'>
  46. ## a:link {color:#004077;text-decoration:none;cursor:pointer;}
  47. ## a:hover {color:#dd6300;}
  48. ## a:visited {color:#004077;}
  49. ##</style>"> $html
  50.  
  51. echo "!!generated by Misc/canvasdraw/canvasinfo.sh | Do NOT Modify here.
  52. <div class='wims_search_engine'><div class='wimscenter'>
  53.  <label for='search'>enter a command name</label>
  54.  <input type='search' id='search'
  55.         onkeydown='javascript:if(event.keyCode == 13){look();}'><button class='wims_button icon_button' type='submit' onclick='javascript:look();'>
  56.  <span class='Searching'>\$wims_name_search</span></button>
  57. </div></div>
  58. <h2 class='wims_title'>Implemented canvasdraw commands ($datum)</h2>
  59. <ul class='flex_box grid-x small-up-3 medium-up-4 large-up-8 small'>
  60. " > $phtml
  61.  
  62. p=0
  63. echo "" > $tmp
  64. cntex=0
  65. while read line ; do
  66.   chk=`echo "$line" | grep "@"`
  67.   # Lines starting with "@" are docstrings (z test if string empty)
  68.   if [ ! -z "$chk" ] ; then
  69.     chk=`echo "$chk" | grep @%`
  70.     # if it's not a docstring samples
  71.     if [ -z "$chk" ] ; then
  72.       # if it's first line
  73.       if [ $p -eq 0 ]; then
  74.         string=`echo "$line" | tr '@' ' '`
  75.         idx=`echo "$string" | awk '{ print $1 }'`
  76.         echo ",'$idx'" >> $keys
  77.         echo "<li class='card cell'><div class='card-section'>" >> $phtml
  78.         echo "<a id='${idx}_top' href='#$idx'>$idx</a>" >> $phtml
  79.         echo "<h3 id='$idx'>$idx <a href='#${idx}_top' title='return at the command list'>&#8593;</a></h3>
  80.        <code>$string</code>
  81.        <ul>" >> $tmp
  82.         p=1
  83.       # it's not the first line
  84.       else
  85.         p=2
  86.         alt=`echo "$line" | grep "@ alternative:" | awk -F'alternative:' '{ print $2 }' | tr -d '[:blank:]'`
  87.         # it's a command alias
  88.         if [ ! -z $alt ] ; then
  89.           echo ",'$alt'" >> $keys
  90.           echo "<a href='#$idx'>$alt</a>" >> $phtml
  91.           echo "<li><span>alternative command: <a id='${alt}' href='#${alt}_top'><code>$alt</code></a></span></li>" >> $tmp
  92.         else
  93.           echo $line | sed 's/@/<li>/g' | sed "s/''/<span class=\"wims_emph\">/g" | sed "s!\`\`!</span>!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.       echo "</div></li>" >> $phtml
  127.     fi
  128.     p=0
  129.   fi
  130. done < $in
  131.  
  132. echo "</ul>" >> $phtml
  133.  
  134. cat $tmp >> $phtml
  135. keywords=`cat $keys | tr -d '\n'`
  136. echo "
  137. <script>
  138. var keys = ['canvasdraw' $keywords];
  139. var keys_len = keys.length;
  140. function match(s1,s2){
  141.    var n1 = s1.length;
  142.    if(n1 < 3){return 0;}
  143.    var n2 = s2.length;
  144.    var c1,c2,found;
  145.    var count = n1 - Math.abs(n1 - n2);
  146.    for(var p = 0;p < n1;p++){
  147.      c1=s1.charAt(p);
  148.      found = false;
  149.      for(var i = 0;i < n2;i++){
  150.        c2 = s2.charAt(i);
  151.        if(c1 == c2){found = true;count = count + n1 - Math.abs(p - i);}
  152.      };
  153.      if(! found ){count = count - n2;}
  154.    };
  155.    return count;
  156. };
  157. function look(){
  158.  var s = ((document.getElementById('search').value).replace(/\s/g, '')).toLowerCase();
  159.  var typo;var next_best = -1;var next_idx = s.length;var tmp;var ss;
  160.  for(var p = 0; p < keys_len ; p++){
  161.    ss = keys[p];
  162.    if( s == ss ){
  163.      document.getElementById(s).scrollIntoView({behavior: \"smooth\", block: \"center\"});
  164.      return;
  165.    };
  166.    /* not ok? ... try to find a match for a reasonable typo... */
  167.    tmp = match(s,ss);
  168.    if(tmp > next_idx){
  169.     next_idx = tmp;
  170.     next_best = p;
  171.    };
  172.  };
  173.  if(next_best != -1 ){
  174.    typo = keys[next_best];
  175.    if(confirm('\"'+s+'\" is not a valid canvasdraw command. Did you mean \"'+typo+'\" ?')){
  176.      document.getElementById(typo).scrollIntoView({behavior: \"smooth\", block: \"center\"});
  177.      return;
  178.    };
  179.  }
  180.  else{
  181.    alert(s+' is not a valid canvasdraw command');
  182.  };
  183.  return;
  184. };
  185. </script>" >> $phtml
  186.  
  187. ##cat $phtml >> $html
  188. ##echo "
  189. ##</body>
  190. ##</html>" >> $html
  191.  
  192. # install in wims distribution scripts/help/en
  193. if [ $ans = "D" ] ; then
  194.   mv $phtml "$helpdir/en"
  195.   cp -rv $tmpdir $helpdir
  196. fi
  197.  
  198. rm $tmp
  199. rm $keys
  200.