Subversion Repositories wimsdev

Rev

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