Subversion Repositories wimsdev

Rev

Rev 14071 | Rev 14945 | 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
 
13940 bpr 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"
13962 bpr 11
if [ $ans = "D" ]; then
14409 obado 12
  # path used for href/http link !
13
  jsdir="scripts/help/canvas_examples"
14
  mkdir -p "$helpdir/canvas_examples" 2>/dev/null
12107 schaersvoo 15
else
14409 obado 16
  jsdir="./examples"
12107 schaersvoo 17
fi
11013 schaersvoo 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`
12106 schaersvoo 24
htmlhead="<!DOCTYPE html><html><body>"
25
htmltail="</body></html>"
14409 obado 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()\" />"
12107 schaersvoo 27
 
12106 schaersvoo 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"
12107 schaersvoo 32
wims_tmp="../sessions/example/getfile/"
12106 schaersvoo 33
mkdir -p $wims_tmp
13940 bpr 34
# the popup html pages and corresponding javascript includes are locate here
35
tmpdir="canvas_examples"
12106 schaersvoo 36
rm -rf $tmpdir
37
mkdir $tmpdir 2>/dev/null
11090 bpr 38
 
13940 bpr 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
11013 schaersvoo 48
 
14409 obado 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>
14071 bpr 56
<h2 class='wims_title'>Implemented canvasdraw commands ($datum)</h2>
14409 obado 57
<ul class='flex_box grid-x small-up-3 medium-up-4 large-up-8 small'>
11013 schaersvoo 58
" > $phtml
11090 bpr 59
 
9381 schaersvoo 60
p=0
14066 bpr 61
echo "" > $tmp
14069 bpr 62
cntex=0
9381 schaersvoo 63
while read line ; do
14066 bpr 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
14409 obado 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>
14066 bpr 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
14069 bpr 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
14066 bpr 86
        else
14071 bpr 87
          echo $line | sed 's/@/<li>/g' | sed "s/''/<span class=\"wims_emph\">/g" | sed "s!\`\`!</span>!g" >> $tmp
14066 bpr 88
          echo "</li>" >> $tmp
89
        fi
90
      fi
12106 schaersvoo 91
    else
14066 bpr 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
14069 bpr 100
      if [ $cntex -eq 0 ]; then echo "<li>" >> $tmp ; fi
101
      cntex=$(($cntex+1))
102
      echo "
14066 bpr 103
      !set wims_ref_class=wims_button
104
      !href cmd=help&special_parm=canvas_examples,$name \$wims_name_Example: $name
14069 bpr 105
      " >> $tmp
14066 bpr 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
12106 schaersvoo 112
    fi
113
  else
14066 bpr 114
    if [ $p -eq 2 ]; then
14069 bpr 115
      if [ $cntex -gt 0 ]; then
116
        echo "</li>" >> $tmp
117
      fi
118
      cntex=0
14066 bpr 119
      echo "</ul>" >> $tmp
120
    fi
121
    p=0
9383 schaersvoo 122
  fi
9381 schaersvoo 123
done < $in
11013 schaersvoo 124
 
125
 
14409 obado 126
echo "</ul>" >> $phtml
127
 
11013 schaersvoo 128
cat $tmp >> $phtml
129
 
9381 schaersvoo 130
keywords=`cat $keys | tr -d '\n'`
131
echo "
14409 obado 132
<script>
9381 schaersvoo 133
 var keys = ['canvasdraw' $keywords];
134
 var keys_len = keys.length;
9382 schaersvoo 135
 function match(s1,s2){
14066 bpr 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;
9382 schaersvoo 151
 };
9381 schaersvoo 152
 function look(){
9382 schaersvoo 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;
9381 schaersvoo 155
  for(var p = 0; p < keys_len ; p++){
14066 bpr 156
    ss = keys[p];
157
    if( s == ss ){
14409 obado 158
      document.getElementById(s).scrollIntoView({behavior: \"smooth\", block: \"center\"});
14066 bpr 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
    };
9381 schaersvoo 167
  };
9382 schaersvoo 168
  if(next_best != -1 ){
14066 bpr 169
    typo = keys[next_best];
14409 obado 170
    if(confirm('\"'+s+'\" is not a valid canvasdraw command. Did you mean \"'+typo+'\" ?')){
171
      document.getElementById(typo).scrollIntoView({behavior: \"smooth\", block: \"center\"});
14066 bpr 172
      return;
173
    };
9382 schaersvoo 174
  }
14409 obado 175
  else{
14066 bpr 176
    alert(s+' is not a valid canvasdraw command');
9382 schaersvoo 177
  };
9381 schaersvoo 178
  return;
179
 };
11013 schaersvoo 180
</script>" >> $phtml
181
 
13940 bpr 182
##cat $phtml >> $html
183
##echo "
184
##</body>
185
##</html>" >> $html
12107 schaersvoo 186
 
187
# install in wims distribution scripts/help/en
13962 bpr 188
if [ $ans = "D" ] ; then
14066 bpr 189
  mv $phtml "$helpdir/en"
190
  cp -rv $tmpdir $helpdir
12107 schaersvoo 191
fi
192
 
9381 schaersvoo 193
rm $tmp
194
rm $keys