Subversion Repositories wimsdev

Rev

Rev 17177 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9381 schaersvoo 1
#!/bin/sh
2
# do not run compile time !
12107 schaersvoo 3
# generates simple canvasdraw usage html-page and a javascript live example
9381 schaersvoo 4
 
14945 obado 5
# See the generated canvasdraw help at http://localhost/wims/?module=adm/createxo&cmd=help&special_parm=canvasdraw
6
 
13940 bpr 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"
13962 bpr 13
if [ $ans = "D" ]; then
14409 obado 14
  # path used for href/http link !
15
  jsdir="scripts/help/canvas_examples"
16
  mkdir -p "$helpdir/canvas_examples" 2>/dev/null
12107 schaersvoo 17
else
14409 obado 18
  jsdir="./examples"
12107 schaersvoo 19
fi
11013 schaersvoo 20
in="canvasdraw.c"
21
phtml="canvasdraw.phtml"
14945 obado 22
# html="canvasdraw.html"
11013 schaersvoo 23
tmp="canvas_index"
24
keys="keywords"
25
datum=`date +%d-%m-%Y`
14945 obado 26
# htmlhead="<!DOCTYPE html><html><body>"
27
# htmltail="</body></html>"
17177 bpr 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()\">"
12107 schaersvoo 29
 
12106 schaersvoo 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"
18184 bpr 34
#wims_tmp="../sessions/example/getfile/"
35
#mkdir -p $wims_tmp
13940 bpr 36
# the popup html pages and corresponding javascript includes are locate here
37
tmpdir="canvas_examples"
12106 schaersvoo 38
rm -rf $tmpdir
39
mkdir $tmpdir 2>/dev/null
11090 bpr 40
 
13940 bpr 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
11013 schaersvoo 50
 
15722 obado 51
echo "!!generated by Misc/canvasdraw/canvasinfo.sh | Do NOT Modify here.
14409 obado 52
<div class='wims_search_engine'><div class='wimscenter'>
15722 obado 53
  <label for='search'>enter a command name</label>
54
  <input type='search' id='search'
17177 bpr 55
         onkeydown='javascript:if(event.keyCode == 13){look();}'><button class='wims_button icon_button' type='submit' onclick='javascript:look();'>
14409 obado 56
  <span class='Searching'>\$wims_name_search</span></button>
57
</div></div>
14071 bpr 58
<h2 class='wims_title'>Implemented canvasdraw commands ($datum)</h2>
14409 obado 59
<ul class='flex_box grid-x small-up-3 medium-up-4 large-up-8 small'>
11013 schaersvoo 60
" > $phtml
11090 bpr 61
 
9381 schaersvoo 62
p=0
14066 bpr 63
echo "" > $tmp
14069 bpr 64
cntex=0
9381 schaersvoo 65
while read line ; do
14066 bpr 66
  chk=`echo "$line" | grep "@"`
15722 obado 67
  # Lines starting with "@" are docstrings (z test if string empty)
14066 bpr 68
  if [ ! -z "$chk" ] ; then
69
    chk=`echo "$chk" | grep @%`
15722 obado 70
    # if it's not a docstring samples
14066 bpr 71
    if [ -z "$chk" ] ; then
15722 obado 72
      # if it's first line
14066 bpr 73
      if [ $p -eq 0 ]; then
74
        string=`echo "$line" | tr '@' ' '`
75
        idx=`echo "$string" | awk '{ print $1 }'`
76
        echo ",'$idx'" >> $keys
15722 obado 77
        echo "<li class='card cell'><div class='card-section'>" >> $phtml
78
        echo "<a id='${idx}_top' href='#$idx'>$idx</a>" >> $phtml
14409 obado 79
        echo "<h3 id='$idx'>$idx <a href='#${idx}_top' title='return at the command list'>&#8593;</a></h3>
14066 bpr 80
        <code>$string</code>
81
        <ul>" >> $tmp
82
        p=1
15722 obado 83
      # it's not the first line
14066 bpr 84
      else
85
        p=2
15715 schaersvoo 86
        alt=`echo "$line" | grep "@ alternative:" | awk -F'alternative:' '{ print $2 }' | tr -d '[:blank:]'`
15722 obado 87
        # it's a command alias
14066 bpr 88
        if [ ! -z $alt ] ; then
89
          echo ",'$alt'" >> $keys
15731 obado 90
          echo "<a href='#$idx'>$alt</a>" >> $phtml
15733 obado 91
          echo "<li><span>alternative command: <a id='${alt}' href='#${alt}_top'><code>$alt</code></a></span></li>" >> $tmp
14066 bpr 92
        else
14071 bpr 93
          echo $line | sed 's/@/<li>/g' | sed "s/''/<span class=\"wims_emph\">/g" | sed "s!\`\`!</span>!g" >> $tmp
14066 bpr 94
          echo "</li>" >> $tmp
95
        fi
96
      fi
12106 schaersvoo 97
    else
14066 bpr 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
14069 bpr 106
      if [ $cntex -eq 0 ]; then echo "<li>" >> $tmp ; fi
107
      cntex=$(($cntex+1))
108
      echo "
14066 bpr 109
      !set wims_ref_class=wims_button
110
      !href cmd=help&special_parm=canvas_examples,$name \$wims_name_Example: $name
14069 bpr 111
      " >> $tmp
14066 bpr 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
12106 schaersvoo 118
    fi
119
  else
14066 bpr 120
    if [ $p -eq 2 ]; then
14069 bpr 121
      if [ $cntex -gt 0 ]; then
122
        echo "</li>" >> $tmp
123
      fi
124
      cntex=0
14066 bpr 125
      echo "</ul>" >> $tmp
15722 obado 126
      echo "</div></li>" >> $phtml
14066 bpr 127
    fi
128
    p=0
9383 schaersvoo 129
  fi
9381 schaersvoo 130
done < $in
11013 schaersvoo 131
 
14409 obado 132
echo "</ul>" >> $phtml
133
 
11013 schaersvoo 134
cat $tmp >> $phtml
9381 schaersvoo 135
keywords=`cat $keys | tr -d '\n'`
136
echo "
14409 obado 137
<script>
9381 schaersvoo 138
 var keys = ['canvasdraw' $keywords];
139
 var keys_len = keys.length;
9382 schaersvoo 140
 function match(s1,s2){
14066 bpr 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;
9382 schaersvoo 156
 };
9381 schaersvoo 157
 function look(){
9382 schaersvoo 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;
9381 schaersvoo 160
  for(var p = 0; p < keys_len ; p++){
14066 bpr 161
    ss = keys[p];
162
    if( s == ss ){
14409 obado 163
      document.getElementById(s).scrollIntoView({behavior: \"smooth\", block: \"center\"});
14066 bpr 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
    };
9381 schaersvoo 172
  };
9382 schaersvoo 173
  if(next_best != -1 ){
14066 bpr 174
    typo = keys[next_best];
14409 obado 175
    if(confirm('\"'+s+'\" is not a valid canvasdraw command. Did you mean \"'+typo+'\" ?')){
176
      document.getElementById(typo).scrollIntoView({behavior: \"smooth\", block: \"center\"});
14066 bpr 177
      return;
178
    };
9382 schaersvoo 179
  }
14409 obado 180
  else{
14066 bpr 181
    alert(s+' is not a valid canvasdraw command');
9382 schaersvoo 182
  };
9381 schaersvoo 183
  return;
184
 };
11013 schaersvoo 185
</script>" >> $phtml
186
 
13940 bpr 187
##cat $phtml >> $html
188
##echo "
189
##</body>
190
##</html>" >> $html
12107 schaersvoo 191
 
192
# install in wims distribution scripts/help/en
13962 bpr 193
if [ $ans = "D" ] ; then
14066 bpr 194
  mv $phtml "$helpdir/en"
195
  cp -rv $tmpdir $helpdir
12107 schaersvoo 196
fi
197
 
9381 schaersvoo 198
rm $tmp
199
rm $keys