Subversion Repositories wimsdev

Rev

Rev 14071 | Rev 14945 | 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>\"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 | Do NOT Modify here.
  50. <div class='wims_search_engine'><div class='wimscenter'>
  51.  <input type='search' id='search' placeholder='enter a command name'
  52.         onkeydown='javascript:if(event.keyCode == 13){look();}'
  53.  /><button class='wims_button icon_button' type='submit' onclick='javascript:look();'>
  54.  <span class='Searching'>\$wims_name_search</span></button>
  55. </div></div>
  56. <h2 class='wims_title'>Implemented canvasdraw commands ($datum)</h2>
  57. <ul class='flex_box grid-x small-up-3 medium-up-4 large-up-8 small'>
  58. " > $phtml
  59.  
  60. p=0
  61. echo "" > $tmp
  62. cntex=0
  63. while read line ; do
  64.   chk=`echo "$line" | grep "@"`
  65.   if [ ! -z "$chk" ] ; then
  66.     chk=`echo "$chk" | grep @%`
  67.     if [ -z "$chk" ] ; then
  68.       if [ $p -eq 0 ]; then
  69.         string=`echo "$line" | tr '@' ' '`
  70.         idx=`echo "$string" | awk '{ print $1 }'`
  71.         echo ",'$idx'" >> $keys
  72.  
  73.         echo "<li class='card cell'><div class='card-section'>
  74.        <a id='${idx}_top' href='#$idx'>$idx</a></div></li>" >> $phtml
  75.         echo "<h3 id='$idx'>$idx <a href='#${idx}_top' title='return at the command list'>&#8593;</a></h3>
  76.        <code>$string</code>
  77.        <ul>" >> $tmp
  78.         p=1
  79.       else
  80.         p=2
  81.         alt=`echo "$line" | grep "@ alternative :" | awk '{ print $4 }' | tr -d '[:blank:]'`
  82.         if [ ! -z $alt ] ; then
  83.           echo ",'$alt'" >> $keys
  84.           echo "<td><a id='${alt}_top' href='#$idx'>$alt</a></td>" >> $phtml
  85.           echo "<li><span>alternative command: <a id='$alt' href='#${alt}_top'>$alt</a></span></li>" >> $tmp
  86.         else
  87.           echo $line | sed 's/@/<li>/g' | sed "s/''/<span class=\"wims_emph\">/g" | sed "s!\`\`!</span>!g" >> $tmp
  88.           echo "</li>" >> $tmp
  89.         fi
  90.       fi
  91.     else
  92.       # begin generating live examples signaled by @%
  93.       name=`echo "$chk" | awk -F'%' '{ print $2 }' `
  94.       echo "command $name"
  95.       cont=`echo "$chk" | tr '%' '\n'`
  96.       #echo "!!generated by canvasinfo.sh" > $tmpdir/$name
  97.       echo "$cont" | sed '1,2d'> $tmpdir/$name
  98.       ##echo "$htmlhead" > $tmpdir/$name.html
  99.       ##cat $tmpdir/$name | ~/other/bin/canvasdraw | sed 's/src=\"wims.cgi?session=123*.*.js\"/src=\"'$name'.js\"/g' >> $tmpdir/$name.html
  100.       if [ $cntex -eq 0 ]; then echo "<li>" >> $tmp ; fi
  101.       cntex=$(($cntex+1))
  102.       echo "
  103.      !set wims_ref_class=wims_button
  104.      !href cmd=help&special_parm=canvas_examples,$name \$wims_name_Example: $name
  105.      " >> $tmp
  106.       ##echo "<textarea cols='60' rows='10'>" >> $tmpdir/$name.html
  107.       ##echo "$cont" | sed '1,2d' >> $tmpdir/$name.html
  108.       ##echo "</textarea>" >> $tmpdir/$name.html
  109.       ##echo "$interaction" >> $tmpdir/$name.html
  110.       ##echo "$htmltail" >> $tmpdir/$name.html
  111.       ##mv -v $wims_tmp/*.js $tmpdir/$name.js
  112.     fi
  113.   else
  114.     if [ $p -eq 2 ]; then
  115.       if [ $cntex -gt 0 ]; then
  116.         echo "</li>" >> $tmp
  117.       fi
  118.       cntex=0
  119.       echo "</ul>" >> $tmp
  120.     fi
  121.     p=0
  122.   fi
  123. done < $in
  124.  
  125.  
  126. echo "</ul>" >> $phtml
  127.  
  128. cat $tmp >> $phtml
  129.  
  130. keywords=`cat $keys | tr -d '\n'`
  131. echo "
  132. <script>
  133. var keys = ['canvasdraw' $keywords];
  134. var keys_len = keys.length;
  135. function match(s1,s2){
  136.    var n1 = s1.length;
  137.    if(n1 < 3){return 0;}
  138.    var n2 = s2.length;
  139.    var c1,c2,found;
  140.    var count = n1 - Math.abs(n1 - n2);
  141.    for(var p = 0;p < n1;p++){
  142.      c1=s1.charAt(p);
  143.      found = false;
  144.      for(var i = 0;i < n2;i++){
  145.        c2 = s2.charAt(i);
  146.        if(c1 == c2){found = true;count = count + n1 - Math.abs(p - i);}
  147.      };
  148.      if(! found ){count = count - n2;}
  149.    };
  150.    return count;
  151. };
  152. function look(){
  153.  var s = ((document.getElementById('search').value).replace(/\s/g, '')).toLowerCase();
  154.  var typo;var next_best = -1;var next_idx = s.length;var tmp;var ss;
  155.  for(var p = 0; p < keys_len ; p++){
  156.    ss = keys[p];
  157.    if( s == ss ){
  158.      document.getElementById(s).scrollIntoView({behavior: \"smooth\", block: \"center\"});
  159.      return;
  160.    };
  161.    /* not ok? ... try to find a match for a reasonable typo... */
  162.    tmp = match(s,ss);
  163.    if(tmp > next_idx){
  164.     next_idx = tmp;
  165.     next_best = p;
  166.    };
  167.  };
  168.  if(next_best != -1 ){
  169.    typo = keys[next_best];
  170.    if(confirm('\"'+s+'\" is not a valid canvasdraw command. Did you mean \"'+typo+'\" ?')){
  171.      document.getElementById(typo).scrollIntoView({behavior: \"smooth\", block: \"center\"});
  172.      return;
  173.    };
  174.  }
  175.  else{
  176.    alert(s+' is not a valid canvasdraw command');
  177.  };
  178.  return;
  179. };
  180. </script>" >> $phtml
  181.  
  182. ##cat $phtml >> $html
  183. ##echo "
  184. ##</body>
  185. ##</html>" >> $html
  186.  
  187. # install in wims distribution scripts/help/en
  188. if [ $ans = "D" ] ; then
  189.   mv $phtml "$helpdir/en"
  190.   cp -rv $tmpdir $helpdir
  191. fi
  192.  
  193. rm $tmp
  194. rm $keys
  195.