/ Check-in [6cd81c15d5]
DEMO | DOWNLOAD | DEPLOY | SEARCH
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Release "2.8.36". Initial relase of "jsig.js"
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6cd81c15d57638f58e2bfbbe75263948975f983c
User & Date: pmacdona 2019-06-09 01:35:32
Context
2019-06-09
01:41
Doc check-in: 2baab9ff9f user: pmacdona tags: trunk
01:35
Release "2.8.36". Initial relase of "jsig.js" check-in: 6cd81c15d5 user: pmacdona tags: trunk
2019-06-03
23:51
Release "2.8.35". Add null support to puts. check-in: e46317169a user: pmacdona tags: trunk
Changes

Added js-demos/jsig/bar.jsi.

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
function bar(s:string, n:number):any {
   puts("BAR: "+s);
}
function foo(a:number, ...) {
}

bar(1,2);

Added js-demos/jsig/demo1.html.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<script src="/jsi/web/jsig.js"></script>
<script>
   
    function RunTest() {
        foo();
        bar('abc',0);
        bar(9,0);
        bar('9','0');
        bar(9);
        bar(9,0,0);
    }
    
    //$jsi.conf({mode:'log'});
    $jsi.include(['bar.jsi']);
    $jsi.onload(RunTest);
    
</script>
Type checking with <b>jsig</b>

Changes to lib/Jsi_DebugUI/html/debugui.jsi.

1
2

3
4
5
6
7
8
9
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
...
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
...
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
...
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
// Web browser side of the user interface communicating with Jsi_DebugUI.jsi.
// This file is preprocessed to support function parameters with types.


var self = {
    autosel:true,
    breakpoints:[],
    curline:0, curfunc:null, curfile:null, curfdata:'',  // Current state info.
    debug:0,
    escFunc: null, showGuiCmds:false, // Cmds like print/eval show up in input.
................................................................................
    WsSend('varget', {name:word})
}

// Start function.
function onload()
{
    // Cache the most common DOM lookups
    self.dbfile = $$('#dbfile');
    self.dbinput = $$('#dbinput');
    self.dboutput = $$('#dboutput');
    self.dbstatus = $$('#dbstatus');

    // Use 'bind.js' 2-way form data bindings, sort of like Angular.
    self.uioptions = Bind(
        self.uioptions,
        {
            "verbose"       : '#uioptions input[name="verbose"]',
            "varPrint"      : '#uioptions input[name="varPrint"]',
................................................................................
            break;
        default: return;
    }
    id.value = (val === undefined ? '' : val);
}

function ReloadFuncs() {
    var id = $$('#uifuncs');
    var rr = '<br>';
    for (var r of self.fnlst.sort()) {
        rr += "<button onclick='scrollToLine("+r[1]+")'>"+r[0]+ '</button>';
    }
    rr += '<br>';
    id.innerHTML = rr;
}

// Toggle sub-display and change +/- suffix.
function TogglePanel(cmd:string, parent:object|null) {
    var id = $$('#'+cmd);
    var och = '-', nch = '+';
    var isvis = (id.style.display !== 'none');
    if  (isvis) {
        id.style.display = 'none';
    } else {
        nch = '-'; och = '+';
        id.style.display = 'inline';
................................................................................
function EscPress(e:any) {
    if(e.keyCode == 27 && self.escFunc) self.escFunc();
}

function DoExit(m) {
    AddOutput('Debugger has exited('+m.rc+'): tab may be closed!\n\n\n');
    ClassAdd(self.dbinput,'shade',true);
    ClassAdd($$('#mainbut'), 'bpline',true);
    ClassAdd($$('#uibutton'), 'shade',true);
}

function webClose() {
    DoExit({rc:-2});
}

// Generate html for the source-code view.
................................................................................
function RedrawFile() {
    dputs("REDRAW: "+self.uioptions.lineNumbers);
    DrawFile();
}

function scrollToLine(n) {
    if (n<1) n = 1;
    var myElement = $$('#fline_'+n);
    var topPos = myElement.offsetTop;
    self.dbfile.scrollTop = topPos-self.dbfile.offsetTop;
}


function scrollToFunc(n) {
    notify("unimplemented");
................................................................................
function bpLines() {
    var ids = $('.bpline');
    for (var i=0; i<ids.length; i++)
        ids[i].classList.remove('bpline');
    var bps = self.breakpoints;
    for (var i=0; i<bps.length; i++) {
        if (bps[i].line && bps[i].enabled && bps[i].file === self.curfile)
        $$('#fline_'+bps[i].line).classList.add('bpline');
    }
}

function bpDisable() {
    DoCommand('disable');
}

................................................................................
    bps[n].hits++;
    if (bps[n].temporary)
        bps[n].enabled = false;
    bpUpdate();
}

function SetTitle(msg) {
    var id = $$('title');
    id.innerHTML = 'JsiDebug: '+msg;
}

function SetStatus(str) {
    self.dbstatus.value = str;
}

................................................................................
        + "<td><button title='Click to goto level #"+stks[i].level+"' onclick='DoLevel("+stks[i].level+")'>"+stks[i].level+'</button></td>'
        + '<td>'+stks[i].funcName + (i<(stks.length-1)?('('+stks[i].scope+')'):'')+'</td>'
        + '<td>'+stks[i].line+'</td><td>'+stks[i].file+'</td>'
        + '<td>'+stks[i].dir+'</td>'
        + '</tr>\n';
    }
    rs += '</table>';
    $$('#uistack').innerHTML = rs;
}

function webBreakList(m) {
    obps = self.breakpoints;
    self.breakpoints = m.bps;    
    bpLines();
    if (obps != m.bps) // $$('#uibreak').style.display !== 'none')
        bpUpdate();
}

// Show breakpoints table.
function bpUpdate()
{
    var bps = self.breakpoints;
................................................................................
            rs += ' checked';
        rs += ' onclick="bpToggle('+i+')"></input>';
        rs += '</td><td>'+bps[i].hits;
        rs += '</td><td>'+(bps[i].temporary?'Y':'')+'</td><td>';
        rs += '<button class=del onclick="bpDelete('+i+')" title="Click here to delete breakpoint">x</button></td></tr>';
    }
    rs += '</table>';
    $$('#uibreak').innerHTML = rs;
}

function ToggleMe(id:object) {
    id.value = (id.value=="1"?"0":"1");
}

function FileBrowse() {
................................................................................
    if (m.status)
        SetStatus(m.status);
    else if (prevfile !== m.fname)
        SetStatus('File: '+m.fname);
    if (prevfile !== m.fname)
        SetTitle(m.fname);
        
    if ($$('#uistack').style.display !== 'none')
        schedSendStack(false);
}

function schedSendStack(restart) {
    if (self.uidsendUiStack)
        clearInterval(self.uidsendUiStack);
    else if (restart) return;
................................................................................
    DrawFile();
    self.dbstatus.value = "Loaded file: "+m.fname;
}

function webFileBrowse(d)      // File selector.
{
    dputs("fileBrowse: "+JSON.stringify(d));
    var id = $$('#dlg_tool_files');
    var tbl = $$('#tblfiles');
    var tbody = $$('tbody',tbl);
    var hid = $$('#tblfiles_th_0');
    var th = $$('th',hid);
    self.flist.data = d;
    th.innerHTML = d.dir;
    var files = d.files;
    var dirs  = d.dirs;
    var n = 1;
    var rc = '<tr id=tblfiles_tr_0><td>../</td></tr>';
     for (var i in dirs) {


>







 







|
|
|
|







 







|










|







 







|
|







 







|







 







|







 







|







 







|






|







 







|







 







|







 







|
|
|
|
|







1
2
3
4
5
6
7
8
9
10
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
...
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
...
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
...
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
// Web browser side of the user interface communicating with Jsi_DebugUI.jsi.
// This file is preprocessed to support function parameters with types.
"use strict";

var self = {
    autosel:true,
    breakpoints:[],
    curline:0, curfunc:null, curfile:null, curfdata:'',  // Current state info.
    debug:0,
    escFunc: null, showGuiCmds:false, // Cmds like print/eval show up in input.
................................................................................
    WsSend('varget', {name:word})
}

// Start function.
function onload()
{
    // Cache the most common DOM lookups
    self.dbfile = $('#dbfile')[0];
    self.dbinput = $('#dbinput')[0];
    self.dboutput = $('#dboutput')[0];
    self.dbstatus = $('#dbstatus')[0];

    // Use 'bind.js' 2-way form data bindings, sort of like Angular.
    self.uioptions = Bind(
        self.uioptions,
        {
            "verbose"       : '#uioptions input[name="verbose"]',
            "varPrint"      : '#uioptions input[name="varPrint"]',
................................................................................
            break;
        default: return;
    }
    id.value = (val === undefined ? '' : val);
}

function ReloadFuncs() {
    var id = $('#uifuncs')[0];
    var rr = '<br>';
    for (var r of self.fnlst.sort()) {
        rr += "<button onclick='scrollToLine("+r[1]+")'>"+r[0]+ '</button>';
    }
    rr += '<br>';
    id.innerHTML = rr;
}

// Toggle sub-display and change +/- suffix.
function TogglePanel(cmd:string, parent:object|null) {
    var id = $('#'+cmd)[0];
    var och = '-', nch = '+';
    var isvis = (id.style.display !== 'none');
    if  (isvis) {
        id.style.display = 'none';
    } else {
        nch = '-'; och = '+';
        id.style.display = 'inline';
................................................................................
function EscPress(e:any) {
    if(e.keyCode == 27 && self.escFunc) self.escFunc();
}

function DoExit(m) {
    AddOutput('Debugger has exited('+m.rc+'): tab may be closed!\n\n\n');
    ClassAdd(self.dbinput,'shade',true);
    ClassAdd($('#mainbut')[0], 'bpline',true);
    ClassAdd($('#uibutton')[0], 'shade',true);
}

function webClose() {
    DoExit({rc:-2});
}

// Generate html for the source-code view.
................................................................................
function RedrawFile() {
    dputs("REDRAW: "+self.uioptions.lineNumbers);
    DrawFile();
}

function scrollToLine(n) {
    if (n<1) n = 1;
    var myElement = $('#fline_'+n)[0];
    var topPos = myElement.offsetTop;
    self.dbfile.scrollTop = topPos-self.dbfile.offsetTop;
}


function scrollToFunc(n) {
    notify("unimplemented");
................................................................................
function bpLines() {
    var ids = $('.bpline');
    for (var i=0; i<ids.length; i++)
        ids[i].classList.remove('bpline');
    var bps = self.breakpoints;
    for (var i=0; i<bps.length; i++) {
        if (bps[i].line && bps[i].enabled && bps[i].file === self.curfile)
        $('#fline_'+bps[i].line)[0].classList.add('bpline');
    }
}

function bpDisable() {
    DoCommand('disable');
}

................................................................................
    bps[n].hits++;
    if (bps[n].temporary)
        bps[n].enabled = false;
    bpUpdate();
}

function SetTitle(msg) {
    var id = $('title')[0];
    id.innerHTML = 'JsiDebug: '+msg;
}

function SetStatus(str) {
    self.dbstatus.value = str;
}

................................................................................
        + "<td><button title='Click to goto level #"+stks[i].level+"' onclick='DoLevel("+stks[i].level+")'>"+stks[i].level+'</button></td>'
        + '<td>'+stks[i].funcName + (i<(stks.length-1)?('('+stks[i].scope+')'):'')+'</td>'
        + '<td>'+stks[i].line+'</td><td>'+stks[i].file+'</td>'
        + '<td>'+stks[i].dir+'</td>'
        + '</tr>\n';
    }
    rs += '</table>';
    $('#uistack')[0].innerHTML = rs;
}

function webBreakList(m) {
    obps = self.breakpoints;
    self.breakpoints = m.bps;    
    bpLines();
    if (obps != m.bps) // $('#uibreak')[0].style.display !== 'none')
        bpUpdate();
}

// Show breakpoints table.
function bpUpdate()
{
    var bps = self.breakpoints;
................................................................................
            rs += ' checked';
        rs += ' onclick="bpToggle('+i+')"></input>';
        rs += '</td><td>'+bps[i].hits;
        rs += '</td><td>'+(bps[i].temporary?'Y':'')+'</td><td>';
        rs += '<button class=del onclick="bpDelete('+i+')" title="Click here to delete breakpoint">x</button></td></tr>';
    }
    rs += '</table>';
    $('#uibreak')[0].innerHTML = rs;
}

function ToggleMe(id:object) {
    id.value = (id.value=="1"?"0":"1");
}

function FileBrowse() {
................................................................................
    if (m.status)
        SetStatus(m.status);
    else if (prevfile !== m.fname)
        SetStatus('File: '+m.fname);
    if (prevfile !== m.fname)
        SetTitle(m.fname);
        
    if ($('#uistack')[0].style.display !== 'none')
        schedSendStack(false);
}

function schedSendStack(restart) {
    if (self.uidsendUiStack)
        clearInterval(self.uidsendUiStack);
    else if (restart) return;
................................................................................
    DrawFile();
    self.dbstatus.value = "Loaded file: "+m.fname;
}

function webFileBrowse(d)      // File selector.
{
    dputs("fileBrowse: "+JSON.stringify(d));
    var id = $('#dlg_tool_files')[0];
    var tbl = $('#tblfiles')[0];
    var tbody = $('tbody',tbl)[0];
    var hid = $('#tblfiles_th_0')[0];
    var th = $('th',hid)[0];
    self.flist.data = d;
    th.innerHTML = d.dir;
    var files = d.files;
    var dirs  = d.dirs;
    var n = 1;
    var rc = '<tr id=tblfiles_tr_0><td>../</td></tr>';
     for (var i in dirs) {

Changes to lib/Jsi_GenDeep.jsi.

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

    function main() {
        if (self.create) {
            File.copy('/zvfs/lib/web/markdeep/include.shtml', 'include.shtml');
            File.copy('/zvfs/lib/web/markdeep/nginx_deepdoc.conf', 'nginx_deepdoc.conf');
            File.copy('/zvfs/lib/web/markdeep/jsistyle.css', 'jsistyle.css');
            File.copy('/zvfs/lib/web/dumpdeep.js', 'dumpdeep.js');
            File.copy('/zvfs/lib/web/JSig.js', 'jsig.js');
            File.copy('/zvfs/lib/web/markdeep.min.js', 'markdeep.min.js');
            File.mkdir('md');
            File.copy('/zvfs/lib/web/markdeep/DeepDoc.md', 'md/DeepDoc.md');
            puts("DeepDoc created. View with 'jsish -W -url Deepdoc'");
            return;
        }
        var fl = [];







|







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

    function main() {
        if (self.create) {
            File.copy('/zvfs/lib/web/markdeep/include.shtml', 'include.shtml');
            File.copy('/zvfs/lib/web/markdeep/nginx_deepdoc.conf', 'nginx_deepdoc.conf');
            File.copy('/zvfs/lib/web/markdeep/jsistyle.css', 'jsistyle.css');
            File.copy('/zvfs/lib/web/dumpdeep.js', 'dumpdeep.js');
            File.copy('/zvfs/lib/web/jsig.js', 'jsig.js');
            File.copy('/zvfs/lib/web/markdeep.min.js', 'markdeep.min.js');
            File.mkdir('md');
            File.copy('/zvfs/lib/web/markdeep/DeepDoc.md', 'md/DeepDoc.md');
            puts("DeepDoc created. View with 'jsish -W -url Deepdoc'");
            return;
        }
        var fl = [];

Changes to lib/Jsi_Htmlpp.jsi.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
            }
            nstr = self.rc;
            self.rc = odata;
        }
        return nstr;
    }
    
    function include(args:array|string, debug=false)  // Include and evaluate files, recusively.
    { 
        LogTrace('INCLUDE:', args); 
        var ai, fn;
        var odata = self.data;
        args = Util.argArray(args);
        self.data = '';
        for (ai=0; ai<args.length; ai++) {
................................................................................
            var notMarked = false;
            switch (extn) {
                case '.jsi': 
                    // Preprocess typed function in standard javascript for use within browsers.
                    ispp = true;
                    self.jsifiles.push(fn);
                case '.js': 
                    if (debug && !ispp) {
                        echo('<script src="'+tfn+'"></script>\n');
                        continue;
                    }
                    pre += "<script>"+begin;
                    if (!ispp) 
                        pre += File.read(fn);
                    else {
                        if (self.jsifiles.length==1 && self.noCheck) {
                            pre += File.read(self.dir+'/web/JSig.js');
                            if (self.noCheck)
                                pre += 'Jsi.conf({enable:false});\n';
                        }
                        pre += Jsi_Jspp([fn]);
                    }
                    pre += end + "</script>\n";
                    echo(pre);
                    continue;
                    
                case '.cssi':
                    ispp = true;
                case '.css':
                    self.cssfiles.push(fn);
                    if (debug && !ispp) {
                        echo('<link rel="stylesheet" type="text/css" href="'+tfn+'">\n');
                        continue;
                    }
                    pre += "<style>"+begin;
                    if (!ispp)
                        pre += File.read(fn);
                    else {







|







 







|








|

|











|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
            }
            nstr = self.rc;
            self.rc = odata;
        }
        return nstr;
    }
    
    function include(args:array|string, inline=false)  // Include and evaluate files, recusively.
    { 
        LogTrace('INCLUDE:', args); 
        var ai, fn;
        var odata = self.data;
        args = Util.argArray(args);
        self.data = '';
        for (ai=0; ai<args.length; ai++) {
................................................................................
            var notMarked = false;
            switch (extn) {
                case '.jsi': 
                    // Preprocess typed function in standard javascript for use within browsers.
                    ispp = true;
                    self.jsifiles.push(fn);
                case '.js': 
                    if (!inline) {
                        echo('<script src="'+tfn+'"></script>\n');
                        continue;
                    }
                    pre += "<script>"+begin;
                    if (!ispp) 
                        pre += File.read(fn);
                    else {
                        if (self.jsifiles.length==1 && self.noCheck) {
                            pre += File.read(self.dir+'/web/jsig.js');
                            if (self.noCheck)
                                pre += '$jsi.conf({enable:false});\n';
                        }
                        pre += Jsi_Jspp([fn]);
                    }
                    pre += end + "</script>\n";
                    echo(pre);
                    continue;
                    
                case '.cssi':
                    ispp = true;
                case '.css':
                    self.cssfiles.push(fn);
                    if (!inline) {
                        echo('<link rel="stylesheet" type="text/css" href="'+tfn+'">\n');
                        continue;
                    }
                    pre += "<style>"+begin;
                    if (!ispp)
                        pre += File.read(fn);
                    else {

Changes to lib/Jsi_Jspp.jsi.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * 
 *    function foo(s:string='', n:number=1):string {
 * 
 * becomes
 * 
 *    function foo(s, n) { s=Jsi.ArgCheck(...
 * 
 * Code to perform type checking/default values is provided by "web/JSig.js".
 * 
 * Limitation: Comments within function signatures are not supported.
 */

function Jsi_Jspp(files:array|string=null, conf:object=undefined):string|object
{
    var options = { // A JS preprocessor to convert "typed" functions out to web-browser compatible form







|







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * 
 *    function foo(s:string='', n:number=1):string {
 * 
 * becomes
 * 
 *    function foo(s, n) { s=Jsi.ArgCheck(...
 * 
 * Code to perform type checking/default values is provided by "web/jsig.js".
 * 
 * Limitation: Comments within function signatures are not supported.
 */

function Jsi_Jspp(files:array|string=null, conf:object=undefined):string|object
{
    var options = { // A JS preprocessor to convert "typed" functions out to web-browser compatible form

Changes to lib/Jsi_SqliteUI/html/main.htmli.

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

<head>
<title>SqliteUI</title>
<!--
<script src='sqlite.js'></script> 
<link rel="stylesheet" type="text/css" href="sqlite.css">
-->
<script src='/SqliteUI/jsi/web/JSig.js'></script> 
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<? 
// Load .jsi and .cssi for preprocessing.
include(['sqlite.jsi', 'sqlite.cssi'], true);
?>
</head>

<body id=body_main'>


<div id=frame_main>







|



|







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

<head>
<title>SqliteUI</title>
<!--
<script src='sqlite.js'></script> 
<link rel="stylesheet" type="text/css" href="sqlite.css">
-->
<script src='/SqliteUI/jsi/web/jsig.js'></script> 
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<? 
// Load .jsi and .cssi for preprocessing.
include(['sqlite.jsi', 'sqlite.cssi']);
?>
</head>

<body id=body_main'>


<div id=frame_main>

Changes to lib/Jsi_SqliteUI/html/sqlite.jsi.

1

2
3
4
5
6
7
8
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
...
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
...
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
...
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
...
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
...
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
...
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
...
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
...
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
...
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
...
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
...
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
...
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
...
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
...
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
...
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
....
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
....
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
....
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
....
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
....
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
// JS for Web browser side of Jsi_SqliteUI user interface.


var self = {
    debug:0,
    msg:null,
    tlist:{ opened:[], dblclick:null, clkcnt:0 },
    qlist:{ sel:-1, dblclick:null, clkcnt:0, data:[] },
    flist:{ sel:-1, dblclick:null, clkcnt:0 },
................................................................................
    var pid = $('#parm_query');
    //pid.on('keyup', function(e){ return KeyPress(e);});
    //$(document).on('keyup', function(e){ return EscPress(e);});
    window.addEventListener("keyup", function(e){ return EscPress(e);}, false);
    pid[0].addEventListener("keyup", function(e){ return KeyPress(e);}, false);
    var fe = function(e){ DoEnter(e,lst[i]); };
    for (var i in lst) {
        $$('#parm_'+lst[i]).onkeypress = fe;
    }
    $$('#parm_columns').value = ('*');
    $$('#parm_limit').value = (self.queryLimit);
    /*
    $$('#tlist').bind('mousewheel DOMMouseScroll', function(e) {
        var scrollTo = null;
    
        if (e.type == 'mousewheel') {
            scrollTo = (e.originalEvent.wheelDelta * -1);
        }
        else if (e.type == 'DOMMouseScroll') {
            scrollTo = 40 * e.originalEvent.detail;
................................................................................
    puts('Confirm: '+msg);
    return window.confirm(msg);
};

// Close websocket.  TODO: attempt reconnect.
function WsClose() {
    puts("Connection dropped");
    $$('body').classList.add('shade');
    $$('title').innerHTML = '[SqliteUI: '+self.loadObj.dbtail+']';
    //setTimeout(WsReconnect, 1000);
}

function WsReconnect() {
    if (Confirm('Connection dropped.  Attempt to reconnect?'))
        WsConnect();
}
................................................................................
    var url = document.URL.replace(/^http/,'ws');
    puts("Trying to connect: "+url);
    self.ws = new WebSocket(url, "ws");
    try {
        self.ws.onmessage = WsRecv;
        self.ws.onclose = WsClose;
        setTimeout(StartConn, 50);
        $$('body').classList.remove('shade');
    } catch(e) {
        puts("Connect failed");
        setTimeout(WsConnect, 5000);
    }
}

/****** SHARED ***/
................................................................................
   // if (row === self.qlist.sel && self.showing == 'tvals') return row;
    SelRow('qlist', self.qlist.sel, false);
    SelRow('tlist', self.tlist.sel, false);
    SelRow('qlist', row, true);
    self.qlist.sel = row;
    var q = self.qlist.data[row];
    SendQuery(q,true);
    $$('#parm_query').value = (q);
    return row;
}


//Select table.
function OLD_ClickTList(event)
{
................................................................................
function ClickTList(event)
{
    if (event.ctrlKey) {
        DblClickTList(event);
        return false;
    }
    if (!(self.tlist.clkcnt++))
        $$('#tlist').setAttribute('title','');
    var target = event.target || event.srcElement;
    var id, pid = target.parentNode;
    id = pid.id;
    if (id === '')
        return '';
    var rsplit = id.split('_');
    if (rsplit[1] == 'th')
................................................................................
        case 'trigger':
            return LoadSchema(row);
        case 'view':
            break;
        case 'table':
            break;
    }
    defs = {columns:'*', limit:20};
    self.parms[self.curTable] = Parms(defs, true);
    Parms(self.parms[tbl], false);
    self.curTable = tbl;
    ReqLoadTable(tbl);
    //$$('#tnav_add_row').disabled=(data.type === 'table')?false:true;
    return row;
}


//Select file.
function ClickFList(event)
{
................................................................................
}

// Select row in current table.
function ClickTVals(event)
{
    if (self.showing === 'schema') return;
    if (!(self.tvals.clkcnt++))
        $$('#tvals').setAttribute('title','');
    var target = event.target || event.srcElement;
    var id = target.parentNode.id;
    if (id === '') return;
    self.curtbl = 'tvals';
    var rids = id.split('_'), row = parseInt(rids[2]);
    if (row === self.tvals.sel) return row;
    SelRow('tvals', self.tvals.sel, false);
    SelRow('tvals', row, true);
    self.tvals.sel = row;
    if (row == 0) {
        var tname = target.innerHTML;
        id = $$('#parm_orderby');
        if (id.value === tname)
            id.value = tname+' DESC';
        else
            id.value = tname;        
        ReloadTbl();
    }
    return row;
................................................................................

// Edit row 
function DblClickTVals(event) {
    if (self.showing != 'tvals' || self.in == 'qlist') return;
    var row = ClickTVals(event);
    if (row<=0)
        return;
    $$('#dlg_edit_tvals').setAttribute('style', 'display:block');
    DlgEditTVals(row);
    ClearSelection();
}

function Tool(name:string) {
    var id = DlgOpen('dlg_tool_'+name, true);
}

// Open/close a dialog and shade/unshade frame below.
function DlgOpen(name:string, open:boolean)
{
    var id = $$('#'+name);
    var fend = self.frames[self.frames.length-1];
    if (open) {
        if (fend == name) return;
        $$('#'+name).setAttribute('style','display:block');
        puts("NAME: "+name);
        //document.body.style.overflow = "hidden";
        $$('#'+fend).classList.add('shade');
        self.frames.push(name);
        self.escFunc = function () { DlgOpen(name, false); };
        var z = $('input', id);
        if (z && z[0])
            z[0].focus();
        if (id.firstElementChild.className !== 'close-icon') {
            var ct = document.createElement('button');
            ct.onclick = self.escFunc;
            ct.className='close-icon';
            id.insertBefore(ct, id.firstElementChild);
        }
    } else {
        if (fend != name) return;
        $$('#'+name).setAttribute('style','display:none');
        self.frames.pop();
        fend = self.frames[self.frames.length-1];
        $$('#'+fend).classList.remove('shade');
        if (self.frames.length<=1)
            self.escFunc = null;
        else
            self.escFunc = function () { DlgOpen(fend, false); };
    }
    return id;
}
................................................................................

// Update the active/inactive status of Nav buttons.
function TNavUpdateBut()
{
    if (self.tlist.sel<0) return;
    var buts = $('#tvals_parm button'),
        //adata = TListData(),
        ofs = parseInt($$('#parm_offset').value), 
        maxrows = self.dlgmaxrows,
        max = self.tlist.data[self.tlist.sel].size,
        atend = ((ofs+maxrows)>=max),
        atstart = (ofs<=0);
        
    for (var i in buts) {
        switch (buts[i].id) {
................................................................................
            case 'tnav_page_start': break;
        }
    }
}

function TNavCmd(cmd:string)
{
    var id = $$('#parm_offset');
    var sz = self.tlist.data[self.tlist.sel].size;
    var val = id.value, ql = self.queryLimit, max = sz-ql;
    if (max<0)
        max = 0;
    val = parseInt(val);
    if (isNaN(val))
        val = 0;
................................................................................
    if (row === undefined)
        row = self.tlist.sel;
    if (row<0)
        return Alert("table not selected");
    var data = self.tlist.data[row];
    if (!data || data.type !== 'table') return;
    self.curTable = data.name;
    $$('#dlg_add_tvals').setAttribute('style', 'display:block');
    DlgAddTVals(row);
    ClearSelection();
};

// Delete row.
function TNavDelRow(row:number=void)
{
................................................................................
    WsSend('tvalsDelete', subd);
};

//Fill the Edit-Transaction dialog.
function DlgEditTVals(row:number=void)
{
    var id = DlgOpen('dlg_edit_tvals', true);
    var z = $$('tbody',id);
    var ttl = self.tvals.data[0];
    var len = ttl.length-1, dat, dval = '', i, j, n, bd = '', ccnt;
    dat = self.tvals.data[row];
    len = dat.length-1;
    ccnt = parseInt((len+self.dlgmaxrows-2)/self.dlgmaxrows);
    for (i=0; i<len; i++) {
        bd += "<tr>";
................................................................................
            bd += "></td>";
            //bd += " value='"+dval+"'></input></td>";
        }
        i--;
        bd += "</tr>\n";
    }
    z.innerHTML = bd;
    z = $$('thead', id);
    bd = '<tr>';
    for (j=0; j<ccnt; j++)
        bd += "<th>Name</th><th>Value</th>";
    bd += "</tr>";
    z.innerHTML = bd;
    for (i=1; i<=len; i++) 
        document.getElementById('edt_'+ttl[i]).value = dat[i];
................................................................................
    self.tvals.curEd = {row:row, table:self.curTable};
}

//Fill the Add-Transaction dialog.
function DlgAddTVals(row:number=void)
{
    var id = DlgOpen('dlg_add_tvals', true);
    var z = $$('tbody',id);
    var tinfo = self.tlist.data[row], info = tinfo.info;
    var len = info.length, dat, dval = '', i, j, n, bd = '', ccnt;
    ccnt = parseInt((len+(self.dlgmaxrows-1))/self.dlgmaxrows);
    for (i=0; i<len; i++) {
        bd += "<tr>";
        for (j=0; j<ccnt && i<len; j++, i++) {
            var fnam = info[i].name;
................................................................................
            bd += "<td style='text-align:right'><b>"+fnam+":</b></td><td><input id=edt_"+fnam;
            bd += " value='"+dval+"'></input></td>";
        }
        i--;
        bd += "</tr>\n";
    }
    z.innerHTML = bd;
    z = $$('thead',id);
    bd = '<tr>';
    for (j=0; j<ccnt; j++)
        bd += "<th>Name</th><th>Value</th>";
    bd += "</tr>";
    z.innerHTML = bd;
    self.tvals.curRow = row;
    self.tvals.curEd = {row:row, table:self.curTable};
}

// Return fields from form.
function DlgFormFields(fname:string, prefix:string)
{
    var x = $$("#dlg_"+fname);
    var zl = [];
    zl[0] = $('input',x);
    zl[1] = $('select',x);
    var s, id, n, res = {};
    for (var j in zl) {
        var z = zl[j];
        for (var i in z) {
................................................................................
    }
    return res;
}

// Return fields from add form.
function DlgAddFields(fname:string, prefix:string)
{
    var x = $$("#dlg_"+fname);
    var z = $('input',x);
    var s, id, n, res = {};
    for (var i in z) {
        if (z[i].id === undefined) continue;
        id = z[i].id.substr(prefix.length+1);
        res[id] = z[i].value;
    }
................................................................................
function DlgSubmitTVals(tag:string)
{
    var i, fnam = self.frames[self.frames.length-1];
    if (tag == "Cancel")
        return DlgOpen(fnam, false);
    var isEdit = (fnam.indexOf('edit')>=0);
    var row = self.tvals.curEd;
    var x = $$('#'+fnam);
    var z = $('input',x);
    var dat, ttl;
    if (isEdit) {
        row = self.tvals.curRow;
        dat = self.tvals.data[row];
        ttl = self.tvals.data[0];
    } else {
................................................................................
    var fnam = self.frames[self.frames.length-1];
    if (!m.result)
        return Alert(m.msg);
    DlgOpen(fnam, false);
    ReloadTbl();
    if (m.tag == "Add" || m.tag == "Delete") {
        var row = self.tlist.sel;
        var tr = $$('#tlist_tr_'+row);
        var td = $('td',tr)[1];
        var inc = (m.tag == "Add" ? 1 : -1);
        var n = parseInt(td.innerHTML)+inc;
        td.innerHTML = n;
    }
}

................................................................................
}

// Save (or restore) parms.
function Parms(rv:object|void, save:boolean)
{
    var lst = self.inputs;
    for (var i in lst) {
        var ll = lst[i], id = $$('#parm_'+ll),
            defs = self.defaults[ll];
        if (save)
            rv[ll] = id.value;
        else
            id.value = (rv===undefined?defs:rv[ll]);
    }
    return rv;
................................................................................
                bd += '<td>' + ConvChar(row[j]) + '</td>';
            }
            bd += '</tr>\n';
            if (i==0)
                hd +=  '</tr>';
        }
    }
    var tt = $$('#tvals');
    tt.innerHTML = hd+bd;
    //$$('#tvals').innerHTML = (hd+bd);
    SetShowing("schema");
}

function SetShowing(show:string, from:string='')
{
    self.showing = show;
    var vis = (show == 'tvals' && from == 'loadTable');
................................................................................
    if (!data.length) return;
    bd = '<tr id=qlist_th_main><th>Saved Queries</th></tr>';
    for (var i in data) {
        var q = data[i];
        var qsub = (q.length<=30?q:q.substr(0,30)+'...');
        bd += '<tr id=qlist_tr_'+i+' class="qlisttbl_main"><td>'+qsub+'</td></tr>';
    }
    $$('#qlist').innerHTML = bd;
}

function SaveQuery(unsave:boolean)
{
    var uqd='block', sqd='none';
    if (unsave) { sqd='block'; uqd='none'; }

    var row, q = $$('#parm_query').value.trim(' '), qind = self.qlist.data.indexOf(q);
    $$('#SaveQuery').setAttribute('style','display:'+sqd);
    $$('#UnsaveQuery').setAttribute('style','display:'+uqd);
    if (unsave) {
        if (qind<0)
            return;
        self.qlist.data.splice(qind,1);
        row = -1;
    } else {
        if (qind>=0)
................................................................................

function LoadTable(m:object)
{
    SetShowing('tvals', m.from);
    self.tlist.reqload = -1;
    switch (m.opts.mode) {
    case 'html':
        $$('#tvals').innerHTML = m.data;
        return;

    case 'arrays':
        var cclass, tag, row, values=m.data, bd = '';
        self.tvals.data = m.data;
        self.tvals.sel = -1;
        if (m.from == "runQuery") {
................................................................................
                var vval = '';
                if (row[j] !== undefined)
                    vval = ConvChar(row[j]);  // TODO: perhaps use dom access instead.
                bd += '<'+tag+'>' + vval + '</'+tag+'>';
            }
            bd += '</tr>\n';
        }
        $$('#tvals').innerHTML = bd;
        if (self.tvals.sel != -1)
            SelRow('tvals', self.tvals.sel, true);
        TNavUpdateBut();
        return;
    }
}

................................................................................
        for (i in dbs) {
            j = dbs[i];
            //if (j.name == 'main') continue; 
            cclass = ' id=tlist_db_'+j.name+' class="tlist_db  tlisttbl_db"';
            bd +=  '<tr '+cclass+'><td>' + j.file + '</td><td>' + j.name + '</td></tr>\n';
        }
    }
    $$('#tlist').innerHTML = bd;
    if (tcnt) {
        SelRow('tlist', self.tlist.sel, true);
        ReqLoadTable(self.curTable);
    }
}

/* Load schemas and current-table. */
function LoadAll(m:object)
{
    self.loadObj =  m;
    $$('title').innerHTML = 'SqliteUI: '+m.dbtail;
    LoadTList(m);
    if (m.savedq) {
        for (var i in m.savedq) 
            self.qlist.data.push(m.savedq[i].query);
        LoadSaved();
    }
    if (m.integrityFail)
................................................................................
//Handle hitting enter
function DoEnter(e:any, inp:string)
{
    if (!e) e = window.event;
    var keyCode = e.keyCode || e.which;
    if (keyCode == '13'){
        if (inp === 'query') {
            var val = $$('#parm_query').value.trim(' ');
            if (val !== '') {
                self.queries.push(val);
                self.qpos = 0;
                SelRow('qlist', self.qlist.sel, false);
                SelRow('tlist', self.tlist.sel, false);
                return SendQuery(val,false);
            }
................................................................................
function KeyPress(e:any)
{
    var key = e.key;
    switch (key) {
        case 'ArrowUp':
        case 'ArrowDown':
            var len = self.queries.length;
            var val = $$('#parm_query').value.trim(' ');
            self.qpos += (key=="ArrowUp"?1:-1);
            if (self.qpos<0)
                self.qpos = 0;
            else if (self.qpos>=len)
                self.qpos=len-1;
            val = self.queries[len-1-self.qpos];
            break;
        default: return;
    }
    id.value = (val === undefined ? '' : val);
}

function ToggleUI(ui:string) {
    var id = $$('#'+ui);
    if (id.style.display === 'none')
        id.style.display = 'inline';
    else
        id.style.display = 'none';
}

function ToggleOpt(opt:string) {
    old = self.conf[opt];
    self.conf[opt] = !old;
    switch (opt) {
        case 'wrap':
            ClassMod('#tvals', 'conf_spacepre', old);
            break;
        default: dputs("unknown opt: "+opt);
    }
................................................................................
}

function EscPress(e:any) {
    if(e.keyCode == 27 && self.escFunc) self.escFunc();
}

function DoExit() {
    $$('#body_main').innerHTML = '<H3>SqliteUI has exited: please close window</H3>';
}

function StartConn() {
    if (self.ws.readyState == 1)
        WsSend("loadAll", {init:true});
    else
        setTimeout(StartConn, 50);
................................................................................
    flds = { files_dir:'/tmp' };
    WsSend('fileBrowse',flds);
}

function fileBrowse(d)      // File selector.
{
    dputs("fileBrowse: "+JSON.stringify(d));
    var hid = $$('#tblfiles_th_0');
    $$('th',hid).innerHTML = d.dir;
    self.flist.data = d;
    var files = d.files;
    var dirs  = d.dirs;
    var n = 1;
    var rc = '<tr id=tblfiles_tr_0><td>../</td></tr>';
     for (var i in dirs) {
        rc += '<tr id=tblfiles_tr_'+ n++ +'><td>' + ConvChar(dirs[i]) + '/</td></tr>';
     }
     for (var j in files) {
        rc += '<tr id=tblfiles_tr_'+ n++ +'><td>' + ConvChar(files[j]) + '</td></tr>';
    }
    var tbl = $$('#tblfiles');
    $$('tbody',tbl).innerHTML = rc;
    DlgOpen('dlg_tool_files', true);
}


function ConvChar( str:any )
{
    if (str === undefined) return '';
    if (str === null) {
        if (self.nullValue !== null)
            return self.nullValue;
        return '';
    }
    c = {'<':'&lt;', '>':'&gt;', '&':'&amp;', '"':'&quot;', "'":'&#039;', '#':'&#035;'};
    return str.toString().replace( /[<&>'"#]/g, function(s) { return c[s]; } );
}

$(function() { onload(); });

puts("DONE");

>







 







|

|
|

|







 







|
|







 







|







 







|







 







|







 







|




|







 







|











|







 







|











|



|


|













|


|







 







|







 







|







 







|







 







|







 







|







 







|







 







|












|







 







|







 







|







 







|







 







|







 







|

|







 







|







|
|
|







 







|







 







|







 







|










|







 







|







 







|













|







|







 







|







 







|
|











|
|












|



|


1
2
3
4
5
6
7
8
9
..
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
...
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
...
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
...
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
...
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
...
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
...
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
...
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
...
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
...
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
...
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
...
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
...
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
...
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
...
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
....
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
....
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
....
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
....
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
....
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
// JS for Web browser side of Jsi_SqliteUI user interface.
"use strict";

var self = {
    debug:0,
    msg:null,
    tlist:{ opened:[], dblclick:null, clkcnt:0 },
    qlist:{ sel:-1, dblclick:null, clkcnt:0, data:[] },
    flist:{ sel:-1, dblclick:null, clkcnt:0 },
................................................................................
    var pid = $('#parm_query');
    //pid.on('keyup', function(e){ return KeyPress(e);});
    //$(document).on('keyup', function(e){ return EscPress(e);});
    window.addEventListener("keyup", function(e){ return EscPress(e);}, false);
    pid[0].addEventListener("keyup", function(e){ return KeyPress(e);}, false);
    var fe = function(e){ DoEnter(e,lst[i]); };
    for (var i in lst) {
        $('#parm_'+lst[i])[0].onkeypress = fe;
    }
    $('#parm_columns')[0].value = ('*');
    $('#parm_limit')[0].value = (self.queryLimit);
    /*
    $('#tlist')[0].bind('mousewheel DOMMouseScroll', function(e) {
        var scrollTo = null;
    
        if (e.type == 'mousewheel') {
            scrollTo = (e.originalEvent.wheelDelta * -1);
        }
        else if (e.type == 'DOMMouseScroll') {
            scrollTo = 40 * e.originalEvent.detail;
................................................................................
    puts('Confirm: '+msg);
    return window.confirm(msg);
};

// Close websocket.  TODO: attempt reconnect.
function WsClose() {
    puts("Connection dropped");
    $('body')[0].classList.add('shade');
    $('title')[0].innerHTML = '[SqliteUI: '+self.loadObj.dbtail+']';
    //setTimeout(WsReconnect, 1000);
}

function WsReconnect() {
    if (Confirm('Connection dropped.  Attempt to reconnect?'))
        WsConnect();
}
................................................................................
    var url = document.URL.replace(/^http/,'ws');
    puts("Trying to connect: "+url);
    self.ws = new WebSocket(url, "ws");
    try {
        self.ws.onmessage = WsRecv;
        self.ws.onclose = WsClose;
        setTimeout(StartConn, 50);
        $('body')[0].classList.remove('shade');
    } catch(e) {
        puts("Connect failed");
        setTimeout(WsConnect, 5000);
    }
}

/****** SHARED ***/
................................................................................
   // if (row === self.qlist.sel && self.showing == 'tvals') return row;
    SelRow('qlist', self.qlist.sel, false);
    SelRow('tlist', self.tlist.sel, false);
    SelRow('qlist', row, true);
    self.qlist.sel = row;
    var q = self.qlist.data[row];
    SendQuery(q,true);
    $('#parm_query')[0].value = (q);
    return row;
}


//Select table.
function OLD_ClickTList(event)
{
................................................................................
function ClickTList(event)
{
    if (event.ctrlKey) {
        DblClickTList(event);
        return false;
    }
    if (!(self.tlist.clkcnt++))
        $('#tlist')[0].setAttribute('title','');
    var target = event.target || event.srcElement;
    var id, pid = target.parentNode;
    id = pid.id;
    if (id === '')
        return '';
    var rsplit = id.split('_');
    if (rsplit[1] == 'th')
................................................................................
        case 'trigger':
            return LoadSchema(row);
        case 'view':
            break;
        case 'table':
            break;
    }
    var defs = {columns:'*', limit:20};
    self.parms[self.curTable] = Parms(defs, true);
    Parms(self.parms[tbl], false);
    self.curTable = tbl;
    ReqLoadTable(tbl);
    //$('#tnav_add_row')[0].disabled=(data.type === 'table')?false:true;
    return row;
}


//Select file.
function ClickFList(event)
{
................................................................................
}

// Select row in current table.
function ClickTVals(event)
{
    if (self.showing === 'schema') return;
    if (!(self.tvals.clkcnt++))
        $('#tvals')[0].setAttribute('title','');
    var target = event.target || event.srcElement;
    var id = target.parentNode.id;
    if (id === '') return;
    self.curtbl = 'tvals';
    var rids = id.split('_'), row = parseInt(rids[2]);
    if (row === self.tvals.sel) return row;
    SelRow('tvals', self.tvals.sel, false);
    SelRow('tvals', row, true);
    self.tvals.sel = row;
    if (row == 0) {
        var tname = target.innerHTML;
        id = $('#parm_orderby')[0];
        if (id.value === tname)
            id.value = tname+' DESC';
        else
            id.value = tname;        
        ReloadTbl();
    }
    return row;
................................................................................

// Edit row 
function DblClickTVals(event) {
    if (self.showing != 'tvals' || self.in == 'qlist') return;
    var row = ClickTVals(event);
    if (row<=0)
        return;
    $('#dlg_edit_tvals')[0].setAttribute('style', 'display:block');
    DlgEditTVals(row);
    ClearSelection();
}

function Tool(name:string) {
    var id = DlgOpen('dlg_tool_'+name, true);
}

// Open/close a dialog and shade/unshade frame below.
function DlgOpen(name:string, open:boolean)
{
    var id = $('#'+name)[0];
    var fend = self.frames[self.frames.length-1];
    if (open) {
        if (fend == name) return;
        $('#'+name)[0].setAttribute('style','display:block');
        puts("NAME: "+name);
        //document.body.style.overflow = "hidden";
        $('#'+fend)[0].classList.add('shade');
        self.frames.push(name);
        self.escFunc = function () { DlgOpen(name, false); };
        var z = $('input', id);
        if (z && z[0])
            z[0].focus();
        if (id.firstElementChild.className !== 'close-icon') {
            var ct = document.createElement('button');
            ct.onclick = self.escFunc;
            ct.className='close-icon';
            id.insertBefore(ct, id.firstElementChild);
        }
    } else {
        if (fend != name) return;
        $('#'+name)[0].setAttribute('style','display:none');
        self.frames.pop();
        fend = self.frames[self.frames.length-1];
        $('#'+fend)[0].classList.remove('shade');
        if (self.frames.length<=1)
            self.escFunc = null;
        else
            self.escFunc = function () { DlgOpen(fend, false); };
    }
    return id;
}
................................................................................

// Update the active/inactive status of Nav buttons.
function TNavUpdateBut()
{
    if (self.tlist.sel<0) return;
    var buts = $('#tvals_parm button'),
        //adata = TListData(),
        ofs = parseInt($('#parm_offset')[0].value), 
        maxrows = self.dlgmaxrows,
        max = self.tlist.data[self.tlist.sel].size,
        atend = ((ofs+maxrows)>=max),
        atstart = (ofs<=0);
        
    for (var i in buts) {
        switch (buts[i].id) {
................................................................................
            case 'tnav_page_start': break;
        }
    }
}

function TNavCmd(cmd:string)
{
    var id = $('#parm_offset')[0];
    var sz = self.tlist.data[self.tlist.sel].size;
    var val = id.value, ql = self.queryLimit, max = sz-ql;
    if (max<0)
        max = 0;
    val = parseInt(val);
    if (isNaN(val))
        val = 0;
................................................................................
    if (row === undefined)
        row = self.tlist.sel;
    if (row<0)
        return Alert("table not selected");
    var data = self.tlist.data[row];
    if (!data || data.type !== 'table') return;
    self.curTable = data.name;
    $('#dlg_add_tvals')[0].setAttribute('style', 'display:block');
    DlgAddTVals(row);
    ClearSelection();
};

// Delete row.
function TNavDelRow(row:number=void)
{
................................................................................
    WsSend('tvalsDelete', subd);
};

//Fill the Edit-Transaction dialog.
function DlgEditTVals(row:number=void)
{
    var id = DlgOpen('dlg_edit_tvals', true);
    var z = $('tbody',id)[0];
    var ttl = self.tvals.data[0];
    var len = ttl.length-1, dat, dval = '', i, j, n, bd = '', ccnt;
    dat = self.tvals.data[row];
    len = dat.length-1;
    ccnt = parseInt((len+self.dlgmaxrows-2)/self.dlgmaxrows);
    for (i=0; i<len; i++) {
        bd += "<tr>";
................................................................................
            bd += "></td>";
            //bd += " value='"+dval+"'></input></td>";
        }
        i--;
        bd += "</tr>\n";
    }
    z.innerHTML = bd;
    z = $('thead', id)[0];
    bd = '<tr>';
    for (j=0; j<ccnt; j++)
        bd += "<th>Name</th><th>Value</th>";
    bd += "</tr>";
    z.innerHTML = bd;
    for (i=1; i<=len; i++) 
        document.getElementById('edt_'+ttl[i]).value = dat[i];
................................................................................
    self.tvals.curEd = {row:row, table:self.curTable};
}

//Fill the Add-Transaction dialog.
function DlgAddTVals(row:number=void)
{
    var id = DlgOpen('dlg_add_tvals', true);
    var z = $('tbody',id)[0];
    var tinfo = self.tlist.data[row], info = tinfo.info;
    var len = info.length, dat, dval = '', i, j, n, bd = '', ccnt;
    ccnt = parseInt((len+(self.dlgmaxrows-1))/self.dlgmaxrows);
    for (i=0; i<len; i++) {
        bd += "<tr>";
        for (j=0; j<ccnt && i<len; j++, i++) {
            var fnam = info[i].name;
................................................................................
            bd += "<td style='text-align:right'><b>"+fnam+":</b></td><td><input id=edt_"+fnam;
            bd += " value='"+dval+"'></input></td>";
        }
        i--;
        bd += "</tr>\n";
    }
    z.innerHTML = bd;
    z = $('thead',id)[0];
    bd = '<tr>';
    for (j=0; j<ccnt; j++)
        bd += "<th>Name</th><th>Value</th>";
    bd += "</tr>";
    z.innerHTML = bd;
    self.tvals.curRow = row;
    self.tvals.curEd = {row:row, table:self.curTable};
}

// Return fields from form.
function DlgFormFields(fname:string, prefix:string)
{
    var x = $("#dlg_"+fname)[0];
    var zl = [];
    zl[0] = $('input',x);
    zl[1] = $('select',x);
    var s, id, n, res = {};
    for (var j in zl) {
        var z = zl[j];
        for (var i in z) {
................................................................................
    }
    return res;
}

// Return fields from add form.
function DlgAddFields(fname:string, prefix:string)
{
    var x = $("#dlg_"+fname)[0];
    var z = $('input',x);
    var s, id, n, res = {};
    for (var i in z) {
        if (z[i].id === undefined) continue;
        id = z[i].id.substr(prefix.length+1);
        res[id] = z[i].value;
    }
................................................................................
function DlgSubmitTVals(tag:string)
{
    var i, fnam = self.frames[self.frames.length-1];
    if (tag == "Cancel")
        return DlgOpen(fnam, false);
    var isEdit = (fnam.indexOf('edit')>=0);
    var row = self.tvals.curEd;
    var x = $('#'+fnam)[0];
    var z = $('input',x);
    var dat, ttl;
    if (isEdit) {
        row = self.tvals.curRow;
        dat = self.tvals.data[row];
        ttl = self.tvals.data[0];
    } else {
................................................................................
    var fnam = self.frames[self.frames.length-1];
    if (!m.result)
        return Alert(m.msg);
    DlgOpen(fnam, false);
    ReloadTbl();
    if (m.tag == "Add" || m.tag == "Delete") {
        var row = self.tlist.sel;
        var tr = $('#tlist_tr_'+row)[0];
        var td = $('td',tr)[1];
        var inc = (m.tag == "Add" ? 1 : -1);
        var n = parseInt(td.innerHTML)+inc;
        td.innerHTML = n;
    }
}

................................................................................
}

// Save (or restore) parms.
function Parms(rv:object|void, save:boolean)
{
    var lst = self.inputs;
    for (var i in lst) {
        var ll = lst[i], id = $('#parm_'+ll)[0],
            defs = self.defaults[ll];
        if (save)
            rv[ll] = id.value;
        else
            id.value = (rv===undefined?defs:rv[ll]);
    }
    return rv;
................................................................................
                bd += '<td>' + ConvChar(row[j]) + '</td>';
            }
            bd += '</tr>\n';
            if (i==0)
                hd +=  '</tr>';
        }
    }
    var tt = $('#tvals')[0];
    tt.innerHTML = hd+bd;
    //$('#tvals')[0].innerHTML = (hd+bd);
    SetShowing("schema");
}

function SetShowing(show:string, from:string='')
{
    self.showing = show;
    var vis = (show == 'tvals' && from == 'loadTable');
................................................................................
    if (!data.length) return;
    bd = '<tr id=qlist_th_main><th>Saved Queries</th></tr>';
    for (var i in data) {
        var q = data[i];
        var qsub = (q.length<=30?q:q.substr(0,30)+'...');
        bd += '<tr id=qlist_tr_'+i+' class="qlisttbl_main"><td>'+qsub+'</td></tr>';
    }
    $('#qlist')[0].innerHTML = bd;
}

function SaveQuery(unsave:boolean)
{
    var uqd='block', sqd='none';
    if (unsave) { sqd='block'; uqd='none'; }

    var row, q = $('#parm_query')[0].value.trim(' '), qind = self.qlist.data.indexOf(q);
    $('#SaveQuery')[0].setAttribute('style','display:'+sqd);
    $('#UnsaveQuery')[0].setAttribute('style','display:'+uqd);
    if (unsave) {
        if (qind<0)
            return;
        self.qlist.data.splice(qind,1);
        row = -1;
    } else {
        if (qind>=0)
................................................................................

function LoadTable(m:object)
{
    SetShowing('tvals', m.from);
    self.tlist.reqload = -1;
    switch (m.opts.mode) {
    case 'html':
        $('#tvals')[0].innerHTML = m.data;
        return;

    case 'arrays':
        var cclass, tag, row, values=m.data, bd = '';
        self.tvals.data = m.data;
        self.tvals.sel = -1;
        if (m.from == "runQuery") {
................................................................................
                var vval = '';
                if (row[j] !== undefined)
                    vval = ConvChar(row[j]);  // TODO: perhaps use dom access instead.
                bd += '<'+tag+'>' + vval + '</'+tag+'>';
            }
            bd += '</tr>\n';
        }
        $('#tvals')[0].innerHTML = bd;
        if (self.tvals.sel != -1)
            SelRow('tvals', self.tvals.sel, true);
        TNavUpdateBut();
        return;
    }
}

................................................................................
        for (i in dbs) {
            j = dbs[i];
            //if (j.name == 'main') continue; 
            cclass = ' id=tlist_db_'+j.name+' class="tlist_db  tlisttbl_db"';
            bd +=  '<tr '+cclass+'><td>' + j.file + '</td><td>' + j.name + '</td></tr>\n';
        }
    }
    $('#tlist')[0].innerHTML = bd;
    if (tcnt) {
        SelRow('tlist', self.tlist.sel, true);
        ReqLoadTable(self.curTable);
    }
}

/* Load schemas and current-table. */
function LoadAll(m:object)
{
    self.loadObj =  m;
    $('title')[0].innerHTML = 'SqliteUI: '+m.dbtail;
    LoadTList(m);
    if (m.savedq) {
        for (var i in m.savedq) 
            self.qlist.data.push(m.savedq[i].query);
        LoadSaved();
    }
    if (m.integrityFail)
................................................................................
//Handle hitting enter
function DoEnter(e:any, inp:string)
{
    if (!e) e = window.event;
    var keyCode = e.keyCode || e.which;
    if (keyCode == '13'){
        if (inp === 'query') {
            var val = $('#parm_query')[0].value.trim(' ');
            if (val !== '') {
                self.queries.push(val);
                self.qpos = 0;
                SelRow('qlist', self.qlist.sel, false);
                SelRow('tlist', self.tlist.sel, false);
                return SendQuery(val,false);
            }
................................................................................
function KeyPress(e:any)
{
    var key = e.key;
    switch (key) {
        case 'ArrowUp':
        case 'ArrowDown':
            var len = self.queries.length;
            var val = $('#parm_query')[0].value.trim(' ');
            self.qpos += (key=="ArrowUp"?1:-1);
            if (self.qpos<0)
                self.qpos = 0;
            else if (self.qpos>=len)
                self.qpos=len-1;
            val = self.queries[len-1-self.qpos];
            break;
        default: return;
    }
    id.value = (val === undefined ? '' : val);
}

function ToggleUI(ui:string) {
    var id = $('#'+ui)[0];
    if (id.style.display === 'none')
        id.style.display = 'inline';
    else
        id.style.display = 'none';
}

function ToggleOpt(opt:string) {
    var old = self.conf[opt];
    self.conf[opt] = !old;
    switch (opt) {
        case 'wrap':
            ClassMod('#tvals', 'conf_spacepre', old);
            break;
        default: dputs("unknown opt: "+opt);
    }
................................................................................
}

function EscPress(e:any) {
    if(e.keyCode == 27 && self.escFunc) self.escFunc();
}

function DoExit() {
    $('#body_main')[0].innerHTML = '<H3>SqliteUI has exited: please close window</H3>';
}

function StartConn() {
    if (self.ws.readyState == 1)
        WsSend("loadAll", {init:true});
    else
        setTimeout(StartConn, 50);
................................................................................
    flds = { files_dir:'/tmp' };
    WsSend('fileBrowse',flds);
}

function fileBrowse(d)      // File selector.
{
    dputs("fileBrowse: "+JSON.stringify(d));
    var hid = $('#tblfiles_th_0')[0];
    $('th',hid)[0].innerHTML = d.dir;
    self.flist.data = d;
    var files = d.files;
    var dirs  = d.dirs;
    var n = 1;
    var rc = '<tr id=tblfiles_tr_0><td>../</td></tr>';
     for (var i in dirs) {
        rc += '<tr id=tblfiles_tr_'+ n++ +'><td>' + ConvChar(dirs[i]) + '/</td></tr>';
     }
     for (var j in files) {
        rc += '<tr id=tblfiles_tr_'+ n++ +'><td>' + ConvChar(files[j]) + '</td></tr>';
    }
    var tbl = $('#tblfiles')[0];
    $('tbody',tbl)[0].innerHTML = rc;
    DlgOpen('dlg_tool_files', true);
}


function ConvChar( str:any )
{
    if (str === undefined) return '';
    if (str === null) {
        if (self.nullValue !== null)
            return self.nullValue;
        return '';
    }
    var c = {'<':'&lt;', '>':'&gt;', '&':'&amp;', '"':'&quot;', "'":'&#039;', '#':'&#035;'};
    return str.toString().replace( /[<&>'"#]/g, function(s) { return c[s]; } );
}

$jsi.onload( function() { onload(); });

puts("DONE");

Changes to lib/Jsi_Websrv.jsi.

327
328
329
330
331
332
333
334





335
336
337
338
339
340
341
342
                urlarg = args[0];
                args.shift();
            }
        }
        if (urlarg) {
            if (self.url)
                throw('can not have args and specify -url');
            else





                self.url = urlarg;
        }
        
        if (self.zip) {
            self.mnt = Jsi_Archive([self.zip], {noRun:true, version:self.zipVer});
            if (!self.rootdir)
                self.rootdir = self.mnt;
            else







<
>
>
>
>
>
|







327
328
329
330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345
346
                urlarg = args[0];
                args.shift();
            }
        }
        if (urlarg) {
            if (self.url)
                throw('can not have args and specify -url');

            var iiq;
            if (self.query === '' && (iiq=urlarg.indexOf('?'))>0) {
                self.query = urlarg.substr(iiq+1);
                urlarg = urlarg.substr(0, iiq);
            }
            self.url = urlarg;
        }
        
        if (self.zip) {
            self.mnt = Jsi_Archive([self.zip], {noRun:true, version:self.zipVer});
            if (!self.rootdir)
                self.rootdir = self.mnt;
            else

Name change from lib/web/JSig.js to lib/web/jsig.js.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
26
27
28
29
30
31
32


















33
34
35
36
37
38
39
...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
...
184
185
186
187
188
189
190

191
192
193
194
195
196
197
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
...
282
283
284
285
286
287
288
289

290
291
292

293
294
295
296





297
298














































299
300
301







302
303
304
305



306


307
308

309

310
311
312
313
314
315
316
317
318
319
320

321
322
323




324
325
326
327
328

329
330
331
332
333
334
335
336
337


338
339
340
341
342
343
344
...
363
364
365
366
367
368
369
370

371
372
373
374
375
376
377

378
379
380
381
382
383
384
385
386




387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

403
404

405
406
407
408
409
410
411

412
413

414
415
// JS signatures: type-checking for arguments of a function call.
// Emulates the typechecking builtin to Jsi, minus return types.  See https://jsish.org

(function () {
"use strict";

var doc = document,
    win = window,
    typeNameStr="number string boolean array function object regexp any userobj void null undefined",
    typeNameLst= typeNameStr.split(' '),
    sigs = {},
    srcList = [],
    srcCnt = 0,
    onloadFunc = null,
    funcLst = [],
    inline = false,
    ENDSTR = '<!--JSIG GEN-->',
    modes = ['assert', 'error', 'warn', 'debug', 'log', 'throw', 'alert'],
    errCnt = 0,
    errCur = null,
    config = {
        mode:'error', 
        enable:true,
        debug:true
................................................................................
    LogDebug = function() {},
    LogTrace = function() {},
    LogTest = function() {},
    LogWarn = console.warn.bind(console),
    LogError = console.error.bind(console),
    isChrome = (window.chrome && window.navigator.vendor === "Google Inc.")
;



















// Code to handle function parameter types and default values.
function Jsi() {
}

Jsi.prototype = {
        
................................................................................
                case "undefined": case "void": if (val === undefined) return; break;
                case "null": if (val === null) return; break;
                default:
                    jsi.errorCmd("type '"+tlst[i]+'" is unknown: not one of: '+typeNameStr);
                    return;
            }
        }
        return 'type mismatch for arg '+(i+1)+' "'+nam+'" expected "'+tlst.join('|')+'" got "'+vtyp+'" '+val;
    },

    $jsig: function(sig, args) { // Check function arguments
        if (!config.enable)
            return;
        var o = sig;
        if (typeof sig === 'string') {
................................................................................
            o = sigs[sig];
            if (!o)
                o = sigs[sig] = jsi.SigParse(sig);        
        }
        if (typeof o !== 'object' || typeof args !== 'object')
            throw('bad sig or arguments:'+sig+args);
        
        var len = o.args.length, msg;
        var pre = 'In "'+o.name+'()" ';
        if (o.max>=0 && len>o.max)
            msg = "extra arguments: expected "+o.max+" got "+len;
        else if (len<o.min)
            msg = "missing arguments: expected "+o.min+" got "+len;
        for (var aind = 0; aind<args.length && !msg; aind++)
            msg = jsi.ArgCheckType(o, aind, args[aind]);
................................................................................
    },

    typeValidate: function (typ) {
        if (typ === '') return null;
        var tlst = typ.split('|');
        var i = -1;
        for (i = 0; i<tlst.length; i++)
            if (typeNameLst.indexOf(tlst[i]) < 0) {
                jsi.parseError("type unknown '"+tlst[i]+'" not one of: '+typeNameStr);
                return null;
            }
        if (tlst.length===1 && tlst[0] === 'any')
            return null;
        return tlst;
    },
................................................................................
            var last = alst.length-1;
            for (var i = 0; i<=last; i++) {
                var aval = alst[i].trim();
                if (aval === '...') {
                    if (i != last)
                        return jsi.parseError("expected ... to be at end");
                    maxargs = -1;

                    continue;
                }
                var rega = /^([a-zA-Z0-9_]+)(:[|a-z]+|)(=.+|)$/;
                var avals = rega.exec(aval);
                if (!avals)
                    return jsi.parseError("invalid argument: "+aval);
                LogTrace(avals);
................................................................................
        
            var astr = vals[2].trim();
            if (astr === '')
                res += str + ') {';
            else {
                var sobj = jsi.SigParse(fnam+'('+vals[2]+')'+vals[3]);
                LogDebug('SOBJ',JSON.stringify(sobj));
                res += sobj.sargs+')'+sobj.retval + '{ $jsig("'+sobj.ssig+'", arguments); ';
            }

            return res;
        }
        var reg = /function\s*[a-zA-Z0-9_]*\s*\([^)]*\)(:[\|a-z]+|)\s*\{/g;
        return code.replace(reg, reMethod) + '\n'+ENDSTR;
    },
    
    SaveFile: function(filename, data, mime) {
        var blob = new Blob([data], {type: (mime?mime:'text/html')});
        if(window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveBlob(blob, filename);
        } else {
................................................................................
        if (id.firstElementChild.className !== 'close-icon') {
            var ct = document.createElement('button');
            ct.onclick = escFunc;
            ct.className='close-icon';
            id.insertBefore(ct, id.firstElementChild);
        }
    },
    ajax: function(o) { // Get file using XMLHttpRequest.

        var xhr = new XMLHttpRequest();
        if (!o.method) o.method = 'GET';
        xhr.open(o.method, o.url);

        xhr.send(null);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) { // req is done.
                if (xhr.status >= 200 && xhr.status < 400) {





                    if (o.success)
                        o.success(xhr.responseText);














































                    else
                        console.log(xhr.responseText);
                } else {







                    if (o.error)
                        o.error(xhr, "failed");
                    else
                        console.log('Error: ' + xhr.status);



                }


            }
        };                

    },

    srcAdd: function(fn, asData) {
        LogDebug('adding',fn);
        var f=document.createElement('script');
        f.setAttribute("type","text/javascript");
        if (asData)
            f.innerHTML = fn;
        else {
            f.setAttribute("src", fn);
            srcCnt++;
            f.setAttribute("onload", '$jsi.srcDone("'+fn+'");');
        }

        document.getElementsByTagName("head")[0].appendChild(f);
    },
    src: function(fn) {




        if (window.jsiWebSocket)
            return jsi.srcAdd(fn);
        srcList.push(fn);
        srcCnt++;
        jsi.ajax({url:fn, success:jsi.srcSuccess, error:jsi.srcError});

    },
    srcDone: function(fn) {
        srcCnt--;
    },
    srcSuccess: function(str) {
        srcCnt--;
        LogDebug('Src Success: '+str);
        var estr = str.substr(str.length-ENDSTR.length);
        if (estr !== ENDSTR) {


            str = jsi.SigConvert(str);
            LogDebug('Src xlate: '+str);
        }
        jsi.srcAdd(str, true);
        //eval.call({}, str);
    },
    srcError: function(str) {
................................................................................
            if (sel.substr(0,1) === '.')
                rc = top.getElementsByClassName(sel.substr(1));
            else
                rc = top.getElementsByTagName(sel);
        }
        return rc;
    },
    

    query1: function(sel, top) {
        var rc = jsi.query(sel, top);
        if (rc && rc.length)
            return rc[0];
        LogWarn('LOOKUP FAILURE: '+sel+' '+top);
        return null;
    },

    onload: function(f) {
        onloadFunc = f;
    },
    DoOnload: function(f) {
        if (srcCnt>0) {
            LogDebug("waiting for src");
            setTimeout(jsi.DoOnload, 1000);
            return;
        }




        if (onloadFunc)
            onloadFunc();
    }

};

var jsi = new Jsi();
win['$jsi'] = jsi;
win['$jsig']= jsi.$jsig;

if (typeof win['$'] === 'undefined')
    win['$'] = jsi.query;

if (typeof win['$$'] === 'undefined')
    win['$$'] = jsi.query1;


if (typeof win['puts'] === 'undefined')
    win['puts'] = console.log.bind(console);

    

LogTest("Loaded jsig");

//eval.call({}, 'function foo() { puts("foo");}');

document.addEventListener('DOMContentLoaded', function() {

    jsi.DoOnload();
}, false);


}());
|
|




|
|
<
<






<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







 







|







 







>







 







|





|







 







<
>
|
|
<
>
|
|
|
|
>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
>
>
>
>
>
>
>
|
<
<
<
>
>
>
|
>
>
|
<
>

>

<







|

>
|

|
>
>
>
>
|
|
|
|
|
>

|


|


<
<
>
>







 







<
>
|
|
|
|
<
|

>









>
>
>
>







|
|

|
|
<
|
<
<
>
|
<
>
|
<
<
<
<
<
<
>

|
>


1
2
3
4
5
6
7
8


9
10
11
12
13
14

15
16
17
18
19
20
21
..
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
298
299
300
301
302
303
304

305
306
307

308
309
310
311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374



375
376
377
378
379
380
381

382
383
384
385

386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415


416
417
418
419
420
421
422
423
424
...
443
444
445
446
447
448
449

450
451
452
453
454

455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482

483


484
485

486
487






488
489
490
491
492
493
// jsig.js: uses signatures for type-checking arguments of function calls.
// Emulates Jsi's builtin typechecking, sans return types.  See https://jsish.org

(function () {
"use strict";

var typeNames={"number":1,"string":1,"boolean":1,"array":1,"function":1,"object":1,"regexp":1,"any":1,"userobj":1,"void":1,"null":1,"undefined":1},
    typeNameStr= Object.keys(typeNames).join(', '),


    sigs = {},
    srcList = [],
    srcCnt = 0,
    onloadFunc = null,
    funcLst = [],
    inline = false,

    modes = ['assert', 'error', 'warn', 'debug', 'log', 'throw', 'alert'],
    errCnt = 0,
    errCur = null,
    config = {
        mode:'error', 
        enable:true,
        debug:true
................................................................................
    LogDebug = function() {},
    LogTrace = function() {},
    LogTest = function() {},
    LogWarn = console.warn.bind(console),
    LogError = console.error.bind(console),
    isChrome = (window.chrome && window.navigator.vendor === "Google Inc.")
;

function FileExt(fn) {
    var i = fn.lastIndexOf('.');
    if (i<0) return '';
    return fn.substr(i+1);
}

function setOpts(obj, opts) {
    for (var i in obj)
        if (opts[i] === undefined)
            throw("unknown option: "+i+' is not one of: '+Object.keys(opts).join(', '));
    for (var i in opts)
        if (obj[i] === undefined)
            obj[i] = opts[i];
    return obj;
}

var uuid = Date.now();

// Code to handle function parameter types and default values.
function Jsi() {
}

Jsi.prototype = {
        
................................................................................
                case "undefined": case "void": if (val === undefined) return; break;
                case "null": if (val === null) return; break;
                default:
                    jsi.errorCmd("type '"+tlst[i]+'" is unknown: not one of: '+typeNameStr);
                    return;
            }
        }
        return 'type mismatch for arg '+(aind+1)+' "'+nam+'" expected "'+tlst.join('|')+'" got "'+vtyp+'" '+val;
    },

    $jsig: function(sig, args) { // Check function arguments
        if (!config.enable)
            return;
        var o = sig;
        if (typeof sig === 'string') {
................................................................................
            o = sigs[sig];
            if (!o)
                o = sigs[sig] = jsi.SigParse(sig);        
        }
        if (typeof o !== 'object' || typeof args !== 'object')
            throw('bad sig or arguments:'+sig+args);
        
        var len = args.length, msg;
        var pre = 'In "'+o.name+'()" ';
        if (o.max>=0 && len>o.max)
            msg = "extra arguments: expected "+o.max+" got "+len;
        else if (len<o.min)
            msg = "missing arguments: expected "+o.min+" got "+len;
        for (var aind = 0; aind<args.length && !msg; aind++)
            msg = jsi.ArgCheckType(o, aind, args[aind]);
................................................................................
    },

    typeValidate: function (typ) {
        if (typ === '') return null;
        var tlst = typ.split('|');
        var i = -1;
        for (i = 0; i<tlst.length; i++)
            if (!typeNames[tlst[i]]) {
                jsi.parseError("type unknown '"+tlst[i]+'" not one of: '+typeNameStr);
                return null;
            }
        if (tlst.length===1 && tlst[0] === 'any')
            return null;
        return tlst;
    },
................................................................................
            var last = alst.length-1;
            for (var i = 0; i<=last; i++) {
                var aval = alst[i].trim();
                if (aval === '...') {
                    if (i != last)
                        return jsi.parseError("expected ... to be at end");
                    maxargs = -1;
                    minargs--;
                    continue;
                }
                var rega = /^([a-zA-Z0-9_]+)(:[|a-z]+|)(=.+|)$/;
                var avals = rega.exec(aval);
                if (!avals)
                    return jsi.parseError("invalid argument: "+aval);
                LogTrace(avals);
................................................................................
        
            var astr = vals[2].trim();
            if (astr === '')
                res += str + ') {';
            else {
                var sobj = jsi.SigParse(fnam+'('+vals[2]+')'+vals[3]);
                LogDebug('SOBJ',JSON.stringify(sobj));
                res += sobj.sargs+')' + '{ $jsig("'+sobj.ssig+'", arguments); ';
            }

            return res;
        }
        var reg = /function\s*[a-zA-Z0-9_]*\s*\([^)]*\)(:[\|a-z]+|)\s*\{/g;
        return code.replace(reg, reMethod) + '\n<!--JSIG GEN-->';
    },
    
    SaveFile: function(filename, data, mime) {
        var blob = new Blob([data], {type: (mime?mime:'text/html')});
        if(window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveBlob(blob, filename);
        } else {
................................................................................
        if (id.firstElementChild.className !== 'close-icon') {
            var ct = document.createElement('button');
            ct.onclick = escFunc;
            ct.className='close-icon';
            id.insertBefore(ct, id.firstElementChild);
        }
    },

    
    guid: function(){
        return '_uuid'+(uuid++).toString(16);

    },
    ajax:function(url, opts) {
        function none(){};
        if (typeof url !== 'string') {
            opts = url;
            url = opts.url;
        }
        if (!url) return false;
    
        opts = setOpts(opts, {
            success:    none,

            error:      none,
            complete:   none,
            type:       'GET',
            dataType:   'text', // One of: json, jsonp, script, text.
            data:       {},   // Query data.
            headers:    {},
            async:      true,
            url:        null
        });
    
        var req, qd = null, dt = opts.dataType;
        switch (dt) {
        case 'jsonp': case 'script': {
            req = document.createElement('script');    
    
            window[opts.data.callback = jsi.guid()] = function(data) {
                opts.success.call(req, data, null, req);
            };
    
            req.onload = req.onerror = function(e) {
                if (e && e.type === "error")
                    opts.error.call(this, req);
                opts.complete.call(this, req);
                req.remove();
            };
    
            qd = '?';
            for (var key in opts.data)
                qd += encodeURIComponent(key) + '=' + encodeURIComponent(opts.data[key]) +'&';
    
            req.src = url + qd;
            document.head.appendChild(req);
            break;
        }
        case 'text':
        case 'json': {
            req = new XMLHttpRequest();
            req.open(opts.type, url, opts.async);
            opts.headers["X-Requested-With"] = "XMLHttpRequest";
            for (var key in opts.headers)
                req.setRequestHeader(key, opts.headers[key]);
    
            req.onload = req.onerror = function onload() {
                var text = req.statusText;
                if ( req.status < 200 || req.status >= 400 )
                    opts.error.call(jsi, req, text);
                else {
                    var resp = req.responseText;

                    if (dt === 'json')
                        resp = JSON.parse(resp);
                    opts.success.call(jsi, resp, text, req);
                }
                opts.complete.call(jsi, req, text);
            };
    
            if (opts.data)



                qd = (typeof opts.data === 'string' ? opts.data : JSON.stringify(opts.data));
            req.send(qd);
            break;
        }
        default:
            throw('dataType not one of: json, jsonp, script, text');
        }

        return req;
    },
    
    srcAdd: function(fn, asData) {

        var f=document.createElement('script');
        f.setAttribute("type","text/javascript");
        if (asData)
            f.innerHTML = fn;
        else {
            f.setAttribute("src", fn);
            srcCnt++;
            f.setAttribute("onload", "$jsi.srcDone()");
        }
        var h = document.querySelector("head");
        h.appendChild(f);
    },
    include: function(fns) {
        if (typeof fns === 'string')
            fns = [fns];
        for (var i in fns) {
            var fn = fns[i];
            if (window.jsiWebSocket)
                return jsi.srcAdd(fn);
            srcList.push(fn);
            srcCnt++;
            jsi.ajax(fn, {success:jsi.srcSuccess, error:jsi.srcError});
        }
    },
    srcDone: function() {
        srcCnt--;
    },
    srcSuccess: function(str, txt, req) {
        srcCnt--;
        LogDebug('Src Success: '+str);


        var hdrs = req.getAllResponseHeaders();
        if (!hdrs || hdrs.indexOf('jsiWebSocket')<0) {
            str = jsi.SigConvert(str);
            LogDebug('Src xlate: '+str);
        }
        jsi.srcAdd(str, true);
        //eval.call({}, str);
    },
    srcError: function(str) {
................................................................................
            if (sel.substr(0,1) === '.')
                rc = top.getElementsByClassName(sel.substr(1));
            else
                rc = top.getElementsByTagName(sel);
        }
        return rc;
    },

    websock:function(WsRecv, prot) {
        if (!prot) prot = 'ws';
        var url = document.URL.replace(/^http/,'ws');
        var ws = new WebSocket(url, prot);
        ws.onmessage = WsRecv;

        return ws;
    },
    
    onload: function(f) {
        onloadFunc = f;
    },
    DoOnload: function(f) {
        if (srcCnt>0) {
            LogDebug("waiting for src");
            setTimeout(jsi.DoOnload, 1000);
            return;
        }
        var debug = (window.location.href.search(/\?.*jsig.debug.*/i) !== -1);
        if (debug)
            jsi.conf({mode:'debug'});
    
        if (onloadFunc)
            onloadFunc();
    }

};

var jsi = new Jsi();
window['$jsi'] = jsi;
window['$jsig']= jsi.$jsig;

if (typeof window['puts'] === 'undefined')
    window['puts'] = console.log.bind(console);    

if (typeof window['$'] === 'undefined')


    window['$'] = document.querySelectorAll.bind(document);
if (typeof window['$$'] === 'undefined')

    window['$$'] = document.querySelector.bind(document);







if (document.readyState !== 'loading')
    jsi.DoOnload();
else
    document.addEventListener("DOMContentLoaded", jsi.DoOnload, false); 

}());

Deleted lib/web/jsiweb.js.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Support functions for Javascript functions with typed parameters.
// Set breakpoint on errorCmd below to debug warnings.
// Also DOM access helper function, minimally compatible with JQuery

if (typeof puts === 'undefined')
    var puts = console.log.bind(console);
puts("Starting jsiweb...");

if (!$) {
    var $ = function(sel, top) {
        var rc;
        if (typeof sel === 'function') {
            document.addEventListener("DOMContentLoaded", function () {
             sel(); });
            return null;
        }
        if (!top)
            top = document; 
        if (sel.match(/^#[\w]+$/)) {
            rc = top.getElementById(sel.substr(1));
            rc = (rc?[rc]:[]);
        } else if (top.querySelectorAll)
            rc = top.querySelectorAll(sel);
        else if (top.getElementsByClassName) {
            if (sel.substr(0,1) === '.')
                rc = top.getElementsByClassName(sel.substr(1));
            else
                rc = top.getElementsByTagName(sel);
        }
        return rc;
    }
    
}

$$ = function(sel, top) {
    var rc = $(sel, top);
    if (rc && rc.length)
        return rc[0];
    puts('LOOKUP FAILURE: '+sel+' '+top);
    return null;
}

// Code to handle function parameter types and default values.
function __Jsi() {
    this.typeNameStr="number string boolean array function object regexp any userobj void null";
    this.typeNameLst= this.typeNameStr.split(' ');
    this.enable=true;
    this.fatal=false;
}

__Jsi.prototype = {
    
    errorCmd: function(msg) {
        // Set breakpoint here to intercept function type warnings.
        console.log(msg);
        debugger;
        if (this.fatal) throw(msg);
    },
    
    conf: function(vals) { // Configure options.
        for (var i in vals) {
            switch (i) {
                case 'enable':
                case 'fatal': this[i] = vals[i]; break;
                default: errorCmd("Option "+i+" not one of: enable, fatal");
            }
        }
    },

    ArgCount: function(nam, min, max, cnt) {
        var pre = 'In "'+nam+'()" ';
        if (!this.enable)
            return;
        if (max>=0 && cnt>max)
            this.errorCmd(pre+"extra arguments: expected "+max+" got "+cnt);
        if (cnt<min)
            this.errorCmd(pre+"missing arguments: expected "+min+" got "+cnt);
    },
 
    RetCheck: function(fnam, val, typ) {
        if (!this.enable || typ === 'any')
            return;
        var tlst = typ.split('|');
        this.ArgCheckType(0, fnam, "return", val, typ);
    },

    ArgCheck: function(anum, fnam, anam, val, typ, def) { // Check arg type and return value or default.
        if (val===undefined) {
            if (def === undefined)
                return val;
            val = def;
        }
        if (this.enable && typ !== 'any') {
            var tlst = typ.split('|'); // TODO: cache this...
            this.ArgCheckType(anum, fnam, anam, val, typ);
        }
        return val;
    },

    ArgCheckType: function(num, fnam, nam, val, typ) {
        var tlst = typ.split('|'), vtyp = typeof(val);
        var pre = 'In "'+fnam+'()" ' + (num?"arg "+num:"value ");
        for (var i = 0; i<tlst.length; i++) {
            switch (tlst[i]) {
                case "number":  if (vtyp === 'number') return; break;
                case "string":  if (vtyp === 'string') return; break;
                case "boolean": if (vtyp === 'boolean') return; break;
                case "function":if (vtyp === 'function') return; break;
                case "array":   if (vtyp === 'object' && val && val.constructor === Array) return; break;
                case "regexp":  if (vtyp === 'object' && val && val.constructor === RegExp) return;  break;
                case "object":  if (vtyp === 'object' && val && val.constructor !== Array) return;  break;
                case "any":     return;
                case "userobj": if (vtyp === 'object') return; break;
                case "undefined": case "void": if (val === undefined) return; break;
                case "null": if (val === null) return; break;
                default:
                    this.errorCmd(pre+" type unknown '"+tlst[i]+'" not one of: '+this.typeNameStr);
                    return 0;
            }
        }
        this.errorCmd(pre+' type mismatch "'+nam+'" is not of type "'+typ+'": '+vtyp);
    },
    
    CheckFunc: function(nam, min, max, cnt) { // Check when no default values.
        var a = arguments;
        this.ArgCount(nam, min, max, cnt);
        var aind = 4, anum = 1;
        for (anum = 1; aind<a.length; anum++, aind += 3) {
            var anam = a[aind], val = a[aind+1], typ = a[aind+2];
            this.ArgCheck(anum, nam, anam, val, typ);
        }
    },
    
    ValueType: function(val) { // Return type of value.
        var vt = typeof val;
        switch (vt) {
            case "undefined": return "void";
            case "number":
            case "string":
            case "boolean":
            case "function":  return vt;
            case "object":
                if (val === null) return "null";
                switch (val.constructor) {
                    case Array: return "array"; 
                    case RegExp: return "regexp";
                    case Object: return "object";
                    default: return "userobj";
                }
            default: return "any";
        }
    },
    
    SaveFile: function(filename, data, mime) {
        var blob = new Blob([data], {type: (mime?mime:'text/html')});
        if(window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveBlob(blob, filename);
        } else {
            var elem = window.document.createElement('a');
            elem.href = window.URL.createObjectURL(blob);
            elem.download = filename;
            document.body.appendChild(elem);
            elem.click();
            document.body.removeChild(elem);
        }
    },
    
    AddClose: function(id, escFunc) {
        if (id.firstElementChild.className !== 'close-icon') {
            var ct = document.createElement('button');
            ct.onclick = escFunc;
            ct.className='close-icon';
            id.insertBefore(ct, id.firstElementChild);
        }
    }
};

var Jsi = new __Jsi();

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






































































































































































































































































































































































Changes to md/Reference.md.

1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
<tr><td>debug</td><td><i>INT</i></td><td>Set debug level. Setting this to 512 will turn on max libwebsocket log levels.</td><td><i></i></td></tr>
<tr><td>echo</td><td><i>BOOL</i></td><td>LogInfo outputs all websock Send/Recv messages.</td><td><i></i></td></tr>
<tr><td>formParams</td><td><i>STRKEY</i></td><td>Comma seperated list of upload form param names ('text,send,file,upload').</td><td><i>readOnly</i></td></tr>
<tr><td>extArgs</td><td><i>OBJ</i></td><td>Arguments for extension handlers.</td><td><i>initOnly</i></td></tr>
<tr><td>extHandlers</td><td><i>BOOL</i></td><td>Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md.</td><td><i>initOnly</i></td></tr>
<tr><td>getRegexp</td><td><i>REGEXP</i></td><td>Call onGet() only if Url matches pattern.</td><td><i></i></td></tr>
<tr><td>headers</td><td><i>ARRAY</i></td><td>List of name/value output header pairs.</td><td><i>initOnly</i></td></tr>
<tr><td>jsiFnPattern</td><td><i>STRKEY</i></td><td>A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsi*.js).</td><td><i>readOnly</i></td></tr>
<tr><td>interface</td><td><i>STRING</i></td><td>Interface for server to listen on, eg. 'eth0' or 'lo'.</td><td><i>initOnly</i></td></tr>
<tr><td>local</td><td><i>BOOL</i></td><td>Limit connections to localhost addresses on the 127 network.</td><td><i></i></td></tr>
<tr><td>localhostName</td><td><i>STRKEY</i></td><td>Client name used by localhost connections ('localhost').</td><td><i></i></td></tr>
<tr><td>maxConnects</td><td><i>INT</i></td><td>In server mode, max number of client connections accepted.</td><td><i></i></td></tr>
<tr><td>maxDownload</td><td><i>INT</i></td><td>Max size of file download.</td><td><i></i></td></tr>
<tr><td>maxUpload</td><td><i>INT</i></td><td>Max size of file upload will accept.</td><td><i></i></td></tr>
<tr><td>mimeTypes</td><td><i>OBJ</i></td><td>Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'}).</td><td><i>initOnly</i></td></tr>







|







1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
<tr><td>debug</td><td><i>INT</i></td><td>Set debug level. Setting this to 512 will turn on max libwebsocket log levels.</td><td><i></i></td></tr>
<tr><td>echo</td><td><i>BOOL</i></td><td>LogInfo outputs all websock Send/Recv messages.</td><td><i></i></td></tr>
<tr><td>formParams</td><td><i>STRKEY</i></td><td>Comma seperated list of upload form param names ('text,send,file,upload').</td><td><i>readOnly</i></td></tr>
<tr><td>extArgs</td><td><i>OBJ</i></td><td>Arguments for extension handlers.</td><td><i>initOnly</i></td></tr>
<tr><td>extHandlers</td><td><i>BOOL</i></td><td>Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md.</td><td><i>initOnly</i></td></tr>
<tr><td>getRegexp</td><td><i>REGEXP</i></td><td>Call onGet() only if Url matches pattern.</td><td><i></i></td></tr>
<tr><td>headers</td><td><i>ARRAY</i></td><td>List of name/value output header pairs.</td><td><i>initOnly</i></td></tr>
<tr><td>jsiFnPattern</td><td><i>STRKEY</i></td><td>A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsig*.js).</td><td><i>readOnly</i></td></tr>
<tr><td>interface</td><td><i>STRING</i></td><td>Interface for server to listen on, eg. 'eth0' or 'lo'.</td><td><i>initOnly</i></td></tr>
<tr><td>local</td><td><i>BOOL</i></td><td>Limit connections to localhost addresses on the 127 network.</td><td><i></i></td></tr>
<tr><td>localhostName</td><td><i>STRKEY</i></td><td>Client name used by localhost connections ('localhost').</td><td><i></i></td></tr>
<tr><td>maxConnects</td><td><i>INT</i></td><td>In server mode, max number of client connections accepted.</td><td><i></i></td></tr>
<tr><td>maxDownload</td><td><i>INT</i></td><td>Max size of file download.</td><td><i></i></td></tr>
<tr><td>maxUpload</td><td><i>INT</i></td><td>Max size of file upload will accept.</td><td><i></i></td></tr>
<tr><td>mimeTypes</td><td><i>OBJ</i></td><td>Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'}).</td><td><i>initOnly</i></td></tr>

Added md/jsig.md.



































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
jsig
====

**jsig.js** provides in-browser runtime type checking of called functions,
without **jsish**.

    <script src="/jsi/web/jsig.js"></script>
    <script>
       
        function RunTest() {
            foo();
            bar('abc',0);
            bar(9,0);
            bar('9','0');
            bar(9);
            bar(9,0,0);
        }
        
        $jsi.include(['bar.jsi']);
        $jsi.onload(RunTest);
        
    </script>
    Type checking with <b>jsig</b>

And here is **bar.jsi**:

    function bar(s:string, n:number):any {
       puts("BAR: "+s);
    }
    function foo(a:number, ...) {
    }
    
    bar(1,2);

==>

    jsig.js:94 type mismatch for arg 1 "s" expected "string" got "number" 1: calling bar(s:string, n:number):any
    bar.jsi:2 BAR: 1
    jsig.js:94 missing arguments: expected 1 got 0: calling foo(a:number, ...)
    bar.jsi:2 BAR: abc
    jsig.js:94 type mismatch for arg 1 "s" expected "string" got "number" 9: calling bar(s:string, n:number):any
    bar.jsi:2 BAR: 9
    jsig.js:94 type mismatch for arg 2 "n" expected "number" got "string" 0: calling bar(s:string, n:number):any
    bar.jsi:2 BAR: 9
    jsig.js:94 missing arguments: expected 2 got 1: calling bar(s:string, n:number):any
    bar.jsi:2 BAR: 9
    jsig.js:94 extra arguments: expected 2 got 3: calling bar(s:string, n:number):any
    bar.jsi:2 BAR: 9
    

Changes to src/jsi.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
.....
52969
52970
52971
52972
52973
52974
52975
52976
52977
52978
52979
52980
52981
52982
52983
.....
53887
53888
53889
53890
53891
53892
53893
53894
53895
53896
53897
53898
53899
53900
53901
.....
53925
53926
53927
53928
53929
53930
53931
53932
53933
53934
53935
53936
53937
53938
53939
.....
55306
55307
55308
55309
55310
55311
55312
55313
55314
55315
55316
55317
55318
55319
55320
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 35

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif

................................................................................
    JSI_OPT(BOOL,   jsi_wsCmdObj, echo,       .help="LogInfo outputs all websock Send/Recv messages"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, formParams, .help="Comma seperated list of upload form param names ('text,send,file,upload')", jsi_IIRO),
    JSI_OPT(OBJ,    jsi_wsCmdObj, extArgs,    .help="Arguments for extension handlers", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, extHandlers,.help="Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md", jsi_IIOF),
    JSI_OPT(REGEXP, jsi_wsCmdObj, getRegexp,  .help="Call onGet() only if Url matches pattern"),
//    JSI_OPT(CUSTOM, jsi_wsCmdObj, handlersPkg,.help="Handlers use package() to upgrade string to function object"),
    JSI_OPT(ARRAY,  jsi_wsCmdObj, headers,    .help="List of name/value output header pairs", jsi_IIOF),
    JSI_OPT(STRKEY, jsi_wsCmdObj, jsiFnPattern,.help="A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsi*.js)", jsi_IIRO),
    JSI_OPT(STRING, jsi_wsCmdObj, interface,  .help="Interface for server to listen on, eg. 'eth0' or 'lo'", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, local,      .help="Limit connections to localhost addresses on the 127 network"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, localhostName,.help="Client name used by localhost connections ('localhost')"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxConnects,.help="In server mode, max number of client connections accepted"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxDownload,.help="Max size of file download"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxUpload,  .help="Max size of file upload will accept"),
    JSI_OPT(OBJ,    jsi_wsCmdObj, mimeTypes,  .help="Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'})", jsi_IIOF),
................................................................................
            // Take result from vrc and return it.
            if (evrc != JSI_OK) {
                Jsi_LogError("failure in websocket handler");
            } else if ((!vrc) ||
                (!(vStr = Jsi_ValueString(interp, vrc, &strLen)))) {
                Jsi_LogError("failed to get result");
            } else {
                hrc = jsi_wsServeString(pss, wsi, vStr, 0, NULL, NULL);
            }
            Jsi_DSFree(&jStr);
            if (isalloc)
                Jsi_DecrRefCount(interp, vrc);
            if (hrc<=0)
                return -1;
            return 1;
................................................................................
            if (jrc == JSI_ERROR)
                goto bail;
            if (jrc == JSI_OK)
                goto done;
        }

        if (Jsi_Strstr(buf, "favicon.ico"))
            rc = jsi_wsServeString(pss, wsi, "data:;base64,iVBORw0KGgo=", 200, NULL, NULL);
        else {
            const char *cp = Jsi_Strrchr(buf,'/');
            if (cp && cp[1]) {
                snprintf(statPath, sizeof(statPath), "/zvfs/lib/web%s", cp);
                Jsi_DecrRefCount(interp, fname);
                fname = Jsi_ValueNewStringDup(interp, statPath);
                Jsi_IncrRefCount(interp, fname);
................................................................................
    cmdPtr->ietf_version = -1;
    cmdPtr->bufferPwr2 = 0;
    cmdPtr->ws_gid = -1;
    cmdPtr->ws_uid = -1;
    cmdPtr->startTime = time(NULL);
    cmdPtr->hasOpts = 1;
    cmdPtr->includeFile = "include.shtml";
    cmdPtr->jsiFnPattern = "jsi*js";
    if ((arg != NULL && !Jsi_ValueIsNull(interp,arg))
        && Jsi_OptionsProcess(interp, WSOptions, cmdPtr, arg, 0) < 0) {
bail:
        jsi_wswebsocketObjFree(interp, cmdPtr);
        return JSI_ERROR;
    }
    Jsi_PathNormalize(interp, &cmdPtr->rootdir);






|







 







|







 







|







 







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
.....
52969
52970
52971
52972
52973
52974
52975
52976
52977
52978
52979
52980
52981
52982
52983
.....
53887
53888
53889
53890
53891
53892
53893
53894
53895
53896
53897
53898
53899
53900
53901
.....
53925
53926
53927
53928
53929
53930
53931
53932
53933
53934
53935
53936
53937
53938
53939
.....
55306
55307
55308
55309
55310
55311
55312
55313
55314
55315
55316
55317
55318
55319
55320
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 36

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif

................................................................................
    JSI_OPT(BOOL,   jsi_wsCmdObj, echo,       .help="LogInfo outputs all websock Send/Recv messages"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, formParams, .help="Comma seperated list of upload form param names ('text,send,file,upload')", jsi_IIRO),
    JSI_OPT(OBJ,    jsi_wsCmdObj, extArgs,    .help="Arguments for extension handlers", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, extHandlers,.help="Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md", jsi_IIOF),
    JSI_OPT(REGEXP, jsi_wsCmdObj, getRegexp,  .help="Call onGet() only if Url matches pattern"),
//    JSI_OPT(CUSTOM, jsi_wsCmdObj, handlersPkg,.help="Handlers use package() to upgrade string to function object"),
    JSI_OPT(ARRAY,  jsi_wsCmdObj, headers,    .help="List of name/value output header pairs", jsi_IIOF),
    JSI_OPT(STRKEY, jsi_wsCmdObj, jsiFnPattern,.help="A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsig*.js)", jsi_IIRO),
    JSI_OPT(STRING, jsi_wsCmdObj, interface,  .help="Interface for server to listen on, eg. 'eth0' or 'lo'", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, local,      .help="Limit connections to localhost addresses on the 127 network"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, localhostName,.help="Client name used by localhost connections ('localhost')"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxConnects,.help="In server mode, max number of client connections accepted"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxDownload,.help="Max size of file download"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxUpload,  .help="Max size of file upload will accept"),
    JSI_OPT(OBJ,    jsi_wsCmdObj, mimeTypes,  .help="Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'})", jsi_IIOF),
................................................................................
            // Take result from vrc and return it.
            if (evrc != JSI_OK) {
                Jsi_LogError("failure in websocket handler");
            } else if ((!vrc) ||
                (!(vStr = Jsi_ValueString(interp, vrc, &strLen)))) {
                Jsi_LogError("failed to get result");
            } else {
                hrc = jsi_wsServeString(pss, wsi, vStr, 0, NULL, mime);
            }
            Jsi_DSFree(&jStr);
            if (isalloc)
                Jsi_DecrRefCount(interp, vrc);
            if (hrc<=0)
                return -1;
            return 1;
................................................................................
            if (jrc == JSI_ERROR)
                goto bail;
            if (jrc == JSI_OK)
                goto done;
        }

        if (Jsi_Strstr(buf, "favicon.ico"))
            rc = jsi_wsServeString(pss, wsi, "data:;base64,iVBORw0KGgo=", 200, NULL, "image/icon");
        else {
            const char *cp = Jsi_Strrchr(buf,'/');
            if (cp && cp[1]) {
                snprintf(statPath, sizeof(statPath), "/zvfs/lib/web%s", cp);
                Jsi_DecrRefCount(interp, fname);
                fname = Jsi_ValueNewStringDup(interp, statPath);
                Jsi_IncrRefCount(interp, fname);
................................................................................
    cmdPtr->ietf_version = -1;
    cmdPtr->bufferPwr2 = 0;
    cmdPtr->ws_gid = -1;
    cmdPtr->ws_uid = -1;
    cmdPtr->startTime = time(NULL);
    cmdPtr->hasOpts = 1;
    cmdPtr->includeFile = "include.shtml";
    cmdPtr->jsiFnPattern = "jsig*.js";
    if ((arg != NULL && !Jsi_ValueIsNull(interp,arg))
        && Jsi_OptionsProcess(interp, WSOptions, cmdPtr, arg, 0) < 0) {
bail:
        jsi_wswebsocketObjFree(interp, cmdPtr);
        return JSI_ERROR;
    }
    Jsi_PathNormalize(interp, &cmdPtr->rootdir);

Changes to src/jsi.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 35

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* jsi.h : External API header file for Jsi. */
#ifndef __JSI_H__
#define __JSI_H__

#define JSI_VERSION_MAJOR   2
#define JSI_VERSION_MINOR   8
#define JSI_VERSION_RELEASE 36

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

#ifndef JSI_EXTERN
#define JSI_EXTERN extern
#endif

Changes to src/jsiWebSocket.c.

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
....
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
....
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
....
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
    JSI_OPT(BOOL,   jsi_wsCmdObj, echo,       .help="LogInfo outputs all websock Send/Recv messages"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, formParams, .help="Comma seperated list of upload form param names ('text,send,file,upload')", jsi_IIRO),
    JSI_OPT(OBJ,    jsi_wsCmdObj, extArgs,    .help="Arguments for extension handlers", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, extHandlers,.help="Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md", jsi_IIOF),
    JSI_OPT(REGEXP, jsi_wsCmdObj, getRegexp,  .help="Call onGet() only if Url matches pattern"),
//    JSI_OPT(CUSTOM, jsi_wsCmdObj, handlersPkg,.help="Handlers use package() to upgrade string to function object"),
    JSI_OPT(ARRAY,  jsi_wsCmdObj, headers,    .help="List of name/value output header pairs", jsi_IIOF),
    JSI_OPT(STRKEY, jsi_wsCmdObj, jsiFnPattern,.help="A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsi*.js)", jsi_IIRO),
    JSI_OPT(STRING, jsi_wsCmdObj, interface,  .help="Interface for server to listen on, eg. 'eth0' or 'lo'", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, local,      .help="Limit connections to localhost addresses on the 127 network"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, localhostName,.help="Client name used by localhost connections ('localhost')"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxConnects,.help="In server mode, max number of client connections accepted"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxDownload,.help="Max size of file download"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxUpload,  .help="Max size of file upload will accept"),
    JSI_OPT(OBJ,    jsi_wsCmdObj, mimeTypes,  .help="Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'})", jsi_IIOF),
................................................................................
            // Take result from vrc and return it.
            if (evrc != JSI_OK) {
                Jsi_LogError("failure in websocket handler");
            } else if ((!vrc) ||
                (!(vStr = Jsi_ValueString(interp, vrc, &strLen)))) {
                Jsi_LogError("failed to get result");
            } else {
                hrc = jsi_wsServeString(pss, wsi, vStr, 0, NULL, NULL);
            }
            Jsi_DSFree(&jStr);
            if (isalloc)
                Jsi_DecrRefCount(interp, vrc);
            if (hrc<=0)
                return -1;
            return 1;
................................................................................
            if (jrc == JSI_ERROR)
                goto bail;
            if (jrc == JSI_OK)
                goto done;
        }

        if (Jsi_Strstr(buf, "favicon.ico"))
            rc = jsi_wsServeString(pss, wsi, "data:;base64,iVBORw0KGgo=", 200, NULL, NULL);
        else {
            const char *cp = Jsi_Strrchr(buf,'/');
            if (cp && cp[1]) {
                snprintf(statPath, sizeof(statPath), "/zvfs/lib/web%s", cp);
                Jsi_DecrRefCount(interp, fname);
                fname = Jsi_ValueNewStringDup(interp, statPath);
                Jsi_IncrRefCount(interp, fname);
................................................................................
    cmdPtr->ietf_version = -1;
    cmdPtr->bufferPwr2 = 0;
    cmdPtr->ws_gid = -1;
    cmdPtr->ws_uid = -1;
    cmdPtr->startTime = time(NULL);
    cmdPtr->hasOpts = 1;
    cmdPtr->includeFile = "include.shtml";
    cmdPtr->jsiFnPattern = "jsi*js";
    if ((arg != NULL && !Jsi_ValueIsNull(interp,arg))
        && Jsi_OptionsProcess(interp, WSOptions, cmdPtr, arg, 0) < 0) {
bail:
        jsi_wswebsocketObjFree(interp, cmdPtr);
        return JSI_ERROR;
    }
    Jsi_PathNormalize(interp, &cmdPtr->rootdir);







|







 







|







 







|







 







|







294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
....
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
....
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
....
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
    JSI_OPT(BOOL,   jsi_wsCmdObj, echo,       .help="LogInfo outputs all websock Send/Recv messages"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, formParams, .help="Comma seperated list of upload form param names ('text,send,file,upload')", jsi_IIRO),
    JSI_OPT(OBJ,    jsi_wsCmdObj, extArgs,    .help="Arguments for extension handlers", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, extHandlers,.help="Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md", jsi_IIOF),
    JSI_OPT(REGEXP, jsi_wsCmdObj, getRegexp,  .help="Call onGet() only if Url matches pattern"),
//    JSI_OPT(CUSTOM, jsi_wsCmdObj, handlersPkg,.help="Handlers use package() to upgrade string to function object"),
    JSI_OPT(ARRAY,  jsi_wsCmdObj, headers,    .help="List of name/value output header pairs", jsi_IIOF),
    JSI_OPT(STRKEY, jsi_wsCmdObj, jsiFnPattern,.help="A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsig*.js)", jsi_IIRO),
    JSI_OPT(STRING, jsi_wsCmdObj, interface,  .help="Interface for server to listen on, eg. 'eth0' or 'lo'", jsi_IIOF),
    JSI_OPT(BOOL,   jsi_wsCmdObj, local,      .help="Limit connections to localhost addresses on the 127 network"),
    JSI_OPT(STRKEY, jsi_wsCmdObj, localhostName,.help="Client name used by localhost connections ('localhost')"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxConnects,.help="In server mode, max number of client connections accepted"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxDownload,.help="Max size of file download"),
    JSI_OPT(INT,    jsi_wsCmdObj, maxUpload,  .help="Max size of file upload will accept"),
    JSI_OPT(OBJ,    jsi_wsCmdObj, mimeTypes,  .help="Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'})", jsi_IIOF),
................................................................................
            // Take result from vrc and return it.
            if (evrc != JSI_OK) {
                Jsi_LogError("failure in websocket handler");
            } else if ((!vrc) ||
                (!(vStr = Jsi_ValueString(interp, vrc, &strLen)))) {
                Jsi_LogError("failed to get result");
            } else {
                hrc = jsi_wsServeString(pss, wsi, vStr, 0, NULL, mime);
            }
            Jsi_DSFree(&jStr);
            if (isalloc)
                Jsi_DecrRefCount(interp, vrc);
            if (hrc<=0)
                return -1;
            return 1;
................................................................................
            if (jrc == JSI_ERROR)
                goto bail;
            if (jrc == JSI_OK)
                goto done;
        }

        if (Jsi_Strstr(buf, "favicon.ico"))
            rc = jsi_wsServeString(pss, wsi, "data:;base64,iVBORw0KGgo=", 200, NULL, "image/icon");
        else {
            const char *cp = Jsi_Strrchr(buf,'/');
            if (cp && cp[1]) {
                snprintf(statPath, sizeof(statPath), "/zvfs/lib/web%s", cp);
                Jsi_DecrRefCount(interp, fname);
                fname = Jsi_ValueNewStringDup(interp, statPath);
                Jsi_IncrRefCount(interp, fname);
................................................................................
    cmdPtr->ietf_version = -1;
    cmdPtr->bufferPwr2 = 0;
    cmdPtr->ws_gid = -1;
    cmdPtr->ws_uid = -1;
    cmdPtr->startTime = time(NULL);
    cmdPtr->hasOpts = 1;
    cmdPtr->includeFile = "include.shtml";
    cmdPtr->jsiFnPattern = "jsig*.js";
    if ((arg != NULL && !Jsi_ValueIsNull(interp,arg))
        && Jsi_OptionsProcess(interp, WSOptions, cmdPtr, arg, 0) < 0) {
bail:
        jsi_wswebsocketObjFree(interp, cmdPtr);
        return JSI_ERROR;
    }
    Jsi_PathNormalize(interp, &cmdPtr->rootdir);

Changes to tools/protos.jsi.

1
2
3
4
5
6
7
8
//JSI Command Prototypes: version 2.8.35
throw("NOT EXECUTABLE: USE FILE IN GEANY EDITOR FOR CMD LINE COMPLETION + GOTO TAG");

var Array = function(cmd,args) {};
Array.prototype.concat = function(...):array {};
Array.prototype.every = function(callback:function):any {};
Array.prototype.fill = function(value:any, start:number=0, end:number=-1):array {};
Array.prototype.filter = function(callback:function, this:object=void):array {};
|







1
2
3
4
5
6
7
8
//JSI Command Prototypes: version 2.8.36
throw("NOT EXECUTABLE: USE FILE IN GEANY EDITOR FOR CMD LINE COMPLETION + GOTO TAG");

var Array = function(cmd,args) {};
Array.prototype.concat = function(...):array {};
Array.prototype.every = function(callback:function):any {};
Array.prototype.fill = function(value:any, start:number=0, end:number=-1):array {};
Array.prototype.filter = function(callback:function, this:object=void):array {};

Changes to www/reference.wiki.

1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
<tr><td>debug</td><td><i>INT</i></td><td>Set debug level. Setting this to 512 will turn on max libwebsocket log levels.</td><td><i></i></td></tr>
<tr><td>echo</td><td><i>BOOL</i></td><td>LogInfo outputs all websock Send/Recv messages.</td><td><i></i></td></tr>
<tr><td>formParams</td><td><i>STRKEY</i></td><td>Comma seperated list of upload form param names ('text,send,file,upload').</td><td><i>readOnly</i></td></tr>
<tr><td>extArgs</td><td><i>OBJ</i></td><td>Arguments for extension handlers.</td><td><i>initOnly</i></td></tr>
<tr><td>extHandlers</td><td><i>BOOL</i></td><td>Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md.</td><td><i>initOnly</i></td></tr>
<tr><td>getRegexp</td><td><i>REGEXP</i></td><td>Call onGet() only if Url matches pattern.</td><td><i></i></td></tr>
<tr><td>headers</td><td><i>ARRAY</i></td><td>List of name/value output header pairs.</td><td><i>initOnly</i></td></tr>
<tr><td>jsiFnPattern</td><td><i>STRKEY</i></td><td>A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsi*.js).</td><td><i>readOnly</i></td></tr>
<tr><td>interface</td><td><i>STRING</i></td><td>Interface for server to listen on, eg. 'eth0' or 'lo'.</td><td><i>initOnly</i></td></tr>
<tr><td>local</td><td><i>BOOL</i></td><td>Limit connections to localhost addresses on the 127 network.</td><td><i></i></td></tr>
<tr><td>localhostName</td><td><i>STRKEY</i></td><td>Client name used by localhost connections ('localhost').</td><td><i></i></td></tr>
<tr><td>maxConnects</td><td><i>INT</i></td><td>In server mode, max number of client connections accepted.</td><td><i></i></td></tr>
<tr><td>maxDownload</td><td><i>INT</i></td><td>Max size of file download.</td><td><i></i></td></tr>
<tr><td>maxUpload</td><td><i>INT</i></td><td>Max size of file upload will accept.</td><td><i></i></td></tr>
<tr><td>mimeTypes</td><td><i>OBJ</i></td><td>Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'}).</td><td><i>initOnly</i></td></tr>







|







1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
<tr><td>debug</td><td><i>INT</i></td><td>Set debug level. Setting this to 512 will turn on max libwebsocket log levels.</td><td><i></i></td></tr>
<tr><td>echo</td><td><i>BOOL</i></td><td>LogInfo outputs all websock Send/Recv messages.</td><td><i></i></td></tr>
<tr><td>formParams</td><td><i>STRKEY</i></td><td>Comma seperated list of upload form param names ('text,send,file,upload').</td><td><i>readOnly</i></td></tr>
<tr><td>extArgs</td><td><i>OBJ</i></td><td>Arguments for extension handlers.</td><td><i>initOnly</i></td></tr>
<tr><td>extHandlers</td><td><i>BOOL</i></td><td>Enable builtin handlers for these extensions: .htmli, .cssi, .jsi, and .md.</td><td><i>initOnly</i></td></tr>
<tr><td>getRegexp</td><td><i>REGEXP</i></td><td>Call onGet() only if Url matches pattern.</td><td><i></i></td></tr>
<tr><td>headers</td><td><i>ARRAY</i></td><td>List of name/value output header pairs.</td><td><i>initOnly</i></td></tr>
<tr><td>jsiFnPattern</td><td><i>STRKEY</i></td><td>A glob-match pattern for files to which is appended 'window.jsiWebSocket=true;' (jsig*.js).</td><td><i>readOnly</i></td></tr>
<tr><td>interface</td><td><i>STRING</i></td><td>Interface for server to listen on, eg. 'eth0' or 'lo'.</td><td><i>initOnly</i></td></tr>
<tr><td>local</td><td><i>BOOL</i></td><td>Limit connections to localhost addresses on the 127 network.</td><td><i></i></td></tr>
<tr><td>localhostName</td><td><i>STRKEY</i></td><td>Client name used by localhost connections ('localhost').</td><td><i></i></td></tr>
<tr><td>maxConnects</td><td><i>INT</i></td><td>In server mode, max number of client connections accepted.</td><td><i></i></td></tr>
<tr><td>maxDownload</td><td><i>INT</i></td><td>Max size of file download.</td><td><i></i></td></tr>
<tr><td>maxUpload</td><td><i>INT</i></td><td>Max size of file upload will accept.</td><td><i></i></td></tr>
<tr><td>mimeTypes</td><td><i>OBJ</i></td><td>Object providing map of file extensions to mime types (eg. {txt:'text/plain', bb:'text/bb'}).</td><td><i>initOnly</i></td></tr>

Changes to www/web.wiki.

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    alert('NOTICE: '+m+': '+n);
}
</pre></nowiki>

which gets converted to:

    <nowiki><pre class=verbatim>
function notifyUser(m, n) { m=Jsi.ArgCheck(...); n=Jsi.ArgCheck(...);
    alert('NOTICE: '+m+': '+n);
}
</pre></nowiki>


This provides runtime type-checking of function calls.








|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    alert('NOTICE: '+m+': '+n);
}
</pre></nowiki>

which gets converted to:

    <nowiki><pre class=verbatim>
function notifyUser(m, n) { $jsig("notifyUser(m:string, n:number=1)"); if (arguments.length<2) n=arguments[1];
    alert('NOTICE: '+m+': '+n);
}
</pre></nowiki>


This provides runtime type-checking of function calls.