Subversion Repositories wimsdev

Rev

Rev 20 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20 Rev 11521
Line 2... Line 2...
2
        DynAPI Compiler Beta 1
2
        DynAPI Compiler Beta 1
3
        Written 2002 by Raymond Irving
3
        Written 2002 by Raymond Irving
4
 
4
 
5
        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
5
        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
6
*/
6
*/
7
 
-
 
8
 
-
 
9
 
7
 
10
var jsCLevel='high';
8
var jsCLevel='high';
11
var jsCExclude='';
9
var jsCExclude='';
12
var jsCLastFile = '';
10
var jsCLastFile = '';
13
var jsCLastFileName = '';
11
var jsCLastFileName = '';
14
var jsCDebug=false;             //@IF:DEBUG directive
12
var jsCDebug=false;             //@IF:DEBUG directive
15
var jsCNS4=true;                        //@IF:NS4 directive
13
var jsCNS4=true;                        //@IF:NS4 directive
16
var jsFileIndex = -1;
14
var jsFileIndex = -1;
17
 
15
 
18
var jsCLastUnCompressedSize = 0;
16
var jsCLastUnCompressedSize = 0;
19
var jsCLastCompressedSize = 0;
17
var jsCLastCompressedSize = 0;
20
 
18
 
21
// Compiles or Compresses the select dynapi source folder
19
// Compiles or Compresses the select dynapi source folder
22
// When check==true compressor will check dynapi files in source folder for missing semi-colons
20
// When check==true compressor will check dynapi files in source folder for missing semi-colons
23
function compress(check) {
21
function compress(check) {
24
 
22
 
25
        var f=document.frmcompress;
23
        var f=document.frmcompress;
26
        var source=f.txtsource.value;
24
        var source=f.txtsource.value;
27
        var target=f.txttarget.value;
25
        var target=f.txttarget.value;
28
       
26
 
29
        jsFileIndex = -1;
27
        jsFileIndex = -1;
30
        jsCCheck = check;
28
        jsCCheck = check;
31
        jsCLevel = (jsCCheck)? 'low':f.cbolevel.value;
29
        jsCLevel = (jsCCheck)? 'low':f.cbolevel.value;
32
        jsCDebug = f.chkdebug.checked; 
30
        jsCDebug = f.chkdebug.checked;
33
        jsCNS4 = f.chkns4.checked;     
31
        jsCNS4 = f.chkns4.checked;
34
 
32
 
35
        jsCLastUnCompressedSize = 0;
33
        jsCLastUnCompressedSize = 0;
36
        jsCLastCompressedSize = 0;
34
        jsCLastCompressedSize = 0;
37
 
35
 
38
        // build exclude list
36
        // build exclude list
39
        jsCExclude='';
37
        jsCExclude='';
40
        if(f.chkcvs.checked) jsCExclude='CVS'; 
38
        if(f.chkcvs.checked) jsCExclude='CVS';
41
        for(var i=0;i<f.chk.length;i++){
39
        for(var i=0;i<f.chk.length;i++){
42
                if(!f.chk[i].checked){                 
40
                if(!f.chk[i].checked){
43
                        jsCExclude+=((jsCExclude)? ',':'')+f.chk[i].value;
41
                        jsCExclude+=((jsCExclude)? ',':'')+f.chk[i].value;
44
                }
42
                }
45
        }
43
        }
46
       
44
 
47
        // check for valid source and target path
45
        // check for valid source and target path
48
        if(!CheckFolder(source)) {
46
        if(!CheckFolder(source)) {
49
                alert('Invalid Source Path "'+source+'"');
47
                alert('Invalid Source Path "'+source+'"');
50
                return;
48
                return;
51
        }else if(!CheckFolder(target)) {
49
        }else if(!CheckFolder(target)) {
52
                alert('Invalid Destination Path "'+target+'"');
50
                alert('Invalid Destination Path "'+target+'"');
53
                return;
51
                return;
54
        }
52
        }
55
       
53
 
56
        // store javascript files in an array and copy non-javascript files into target
54
        // store javascript files in an array and copy non-javascript files into target
57
        BuildFileSturcure(source,target,jsCExclude);   
55
        BuildFileSturcure(source,target,jsCExclude);
58
 
56
 
59
        document.images['bar'].style.width='0%';
57
        document.images['bar'].style.width='0%';
60
        document.images['bar'].style.visibility='visible';
58
        document.images['bar'].style.visibility='visible';
61
        f.txtstatus.value='Compiling....';
59
        f.txtstatus.value='Compiling....';
62
        f.txtsizestatus.value='';
60
        f.txtsizestatus.value='';
Line 71... Line 69...
71
        var f=document.frmcompress;
69
        var f=document.frmcompress;
72
        var i,a,p,srcFile,tarFile,content;
70
        var i,a,p,srcFile,tarFile,content;
73
        var totalFiles;
71
        var totalFiles;
74
 
72
 
75
        if(state=='status'){
73
        if(state=='status'){
76
       
74
 
77
                // Display status from Crunch() functions
75
                // Display status from Crunch() functions
78
                f.txtstatus.value='Compiling ['+jsCLastFileName+'] - '+strText;
76
                f.txtstatus.value='Compiling ['+jsCLastFileName+'] - '+strText;
79
               
77
 
80
        }
78
        }
81
        else{
79
        else{
82
                if (jsCCheck && state=="complete"){
80
                if (jsCCheck && state=="complete"){
83
                        // Check file for semi-colon errors
81
                        // Check file for semi-colon errors
84
                        // a much better error checking system is needed here
82
                        // a much better error checking system is needed here
85
                        var t='',l,exclude='{},;';
83
                        var t='',l,exclude='{},;';
86
                        var ar = strText.split('\n');
84
                        var ar = strText.split('\n');
87
                        for(var i=0;i<ar.length;i++){                          
85
                        for(var i=0;i<ar.length;i++){
88
                                l=strTrim(ar[i]);
86
                                l=strTrim(ar[i]);
89
                                if (l && l.length){
87
                                if (l && l.length){
90
                                        ok=false;
88
                                        ok=false;
91
                                        ch=l.substr(l.length-1,1);
89
                                        ch=l.substr(l.length-1,1);
92
                                        if(ar[i]!='}' && exclude.indexOf(ch)>=0) ok=true                                       
90
                                        if(ar[i]!='}' && exclude.indexOf(ch)>=0) ok=true
93
                                        if(!ok){
91
                                        if(!ok){
94
                                                l=l.replace(/</g,'&lt;');
92
                                                l=l.replace(/</g,'&lt;');
95
                                                l=l.replace(/>/g,'&gt;');
93
                                                l=l.replace(/>/g,'&gt;');
96
                                                t+=' Line: '+(i+1)+':   '+l+'<br>'
94
                                                t+=' Line: '+(i+1)+':   '+l+'<br>'
97
                                                +' File: '+jsCLastFile+'<br><br>';                                     
95
                                                +' File: '+jsCLastFile+'<br><br>';
98
                                        }
96
                                        }
99
                                }
97
                                }
100
                        }
98
                        }
101
                        if(t){
99
                        if(t){
102
                                var dv=document.all['dvscreen'];
100
                                var dv=document.all['dvscreen'];
Line 112... Line 110...
112
                        jsCLastCompressedSize+=strText.length;
110
                        jsCLastCompressedSize+=strText.length;
113
                        SaveFile(jsCLastFile,strText);
111
                        SaveFile(jsCLastFile,strText);
114
                        f.txtsizestatus.value=' Last size in bytes: Before = '+jsCLastUnCompressedSize+' / After = '+jsCLastCompressedSize+' / '
112
                        f.txtsizestatus.value=' Last size in bytes: Before = '+jsCLastUnCompressedSize+' / After = '+jsCLastCompressedSize+' / '
115
                        +' Diff = '+(jsCLastUnCompressedSize-jsCLastCompressedSize);
113
                        +' Diff = '+(jsCLastUnCompressedSize-jsCLastCompressedSize);
116
                }
114
                }
117
               
115
 
118
                // Move to next file
116
                // Move to next file
119
                jsFileIndex+=1;
117
                jsFileIndex+=1;
120
                totalFiles=GetTotalFiles();
118
                totalFiles=GetTotalFiles();
121
                if(jsFileIndex<=totalFiles){   
119
                if(jsFileIndex<=totalFiles){
122
               
120
 
123
                        // get target and source file
121
                        // get target and source file
124
                        srcFile=GetSRCFile(jsFileIndex);
122
                        srcFile=GetSRCFile(jsFileIndex);
125
                        tarFile=jsCLastFile=GetTARFile(jsFileIndex);
123
                        tarFile=jsCLastFile=GetTARFile(jsFileIndex);
126
 
124
 
127
                        // update status
125
                        // update status
128
                        p=((jsFileIndex+1)/(totalFiles+1))*100;
126
                        p=((jsFileIndex+1)/(totalFiles+1))*100;
129
                        a=jsCLastFile.split('\\');             
127
                        a=jsCLastFile.split('\\');
130
                        jsCLastFileName=a[a.length-1];
128
                        jsCLastFileName=a[a.length-1];
131
                        f.txtstatus.value='Compiling ['+jsCLastFileName+']....';
129
                        f.txtstatus.value='Compiling ['+jsCLastFileName+']....';
132
                        document.images['bar'].style.width=p+"%";
130
                        document.images['bar'].style.width=p+"%";
133
 
131
 
134
                        // get file content
132
                        // get file content
135
                        content=OpenFile(srcFile)+'';
133
                        content=OpenFile(srcFile)+'';
136
                        jsCLastUnCompressedSize+=content.length;
134
                        jsCLastUnCompressedSize+=content.length;
137
                        if(content.indexOf('\n')<0) content=content.split("\r"); // MAC
135
                        if(content.indexOf('\n')<0) content=content.split("\r"); // MAC
138
                        else content=content.split("\n"); // PC, UNIX                   
136
                        else content=content.split("\n"); // PC, UNIX
139
                        content=content.join('<$Link/>');
137
                        content=content.join('<$Link/>');
140
                        if(!jsCDebug){
138
                        if(!jsCDebug){
141
                                // Remove Debug conditional code blocks
139
                                // Remove Debug conditional code blocks
142
                                content = RemoveCondition('DEBUG',content);
140
                                content = RemoveCondition('DEBUG',content);
143
                                content=content.replace(/dynapi\.debug\.print\(/g,'dPrint\(');
141
                                content=content.replace(/dynapi\.debug\.print\(/g,'dPrint\(');
144
                        }
142
                        }
145
                        if(!jsCNS4) {
143
                        if(!jsCNS4) {
146
                                // Remove NS4 conditinal code blocks   
144
                                // Remove NS4 conditinal code blocks
147
                                content = RemoveCondition('NS4',content);
145
                                content = RemoveCondition('NS4',content);
148
                        }
146
                        }
149
                        content=content.replace(/\<\$Link\/\>/g,'\n');
147
                        content=content.replace(/\<\$Link\/\>/g,'\n');
150
                       
-
 
151
                        // Compress the file content 
-
 
152
                        Crunch(content,jsCLevel,CompressNextFile);             
-
 
153
 
148
 
-
 
149
                        // Compress the file content
-
 
150
                        Crunch(content,jsCLevel,CompressNextFile);
-
 
151
 
154
                }
152
                }
155
                else {
153
                else {
156
               
154
 
157
                        // finished compressing js files
155
                        // finished compressing js files
158
                        f.txtstatus.value="Ready";
156
                        f.txtstatus.value="Ready";
159
                        document.images['bar'].style.visibility='hidden';
157
                        document.images['bar'].style.visibility='hidden';
160
                }
158
                }
161
        }
159
        }
162
};
160
};
163
 
161
 
164
// jsCheckFileState: Used by fsobject to check if the file should be copied or compressed
162
// jsCheckFileState: Used by fsobject to check if the file should be copied or compressed
165
function jsCheckFileState(f,pth){
163
function jsCheckFileState(f,pth){
166
        var state=0,ignore=false;
164
        var state=0,ignore=false;
167
        var a,copy=2, compress=1;
165
        var a,copy=2, compress=1;
168
 
166
 
169
        f=f+''; a=f.split(".");
167
        f=f+''; a=f.split(".");
170
       
168
 
171
        // check if file is a part of the debug library
169
        // check if file is a part of the debug library
172
        ignore=(!jsCDebug && f.indexOf('debug')==0)
170
        ignore=(!jsCDebug && f.indexOf('debug')==0)
173
       
171
 
174
        // check if file is a part of the NS4 library
172
        // check if file is a part of the NS4 library
175
        ignore=(ignore || (!jsCNS4 && f.indexOf('ns4')==0))
173
        ignore=(ignore || (!jsCNS4 && f.indexOf('ns4')==0))
176
 
174
 
177
        if(!ignore){
175
        if(!ignore){
178
                // if .js file the compress otherwise copy the file
176
                // if .js file the compress otherwise copy the file
179
                if(a[a.length-1]=="js") state=compress;
177
                if(a[a.length-1]=="js") state=compress;
180
                else state=copy;
178
                else state=copy;
181
        }
179
        }
182
 
180
 
183
        return state;
181
        return state;
184
};
182
};
Line 206... Line 204...
206
        var dv=document.all['dvscreen'];
204
        var dv=document.all['dvscreen'];
207
        dv.innerHTML='';
205
        dv.innerHTML='';
208
        dv=document.all['dvscreenrow'];
206
        dv=document.all['dvscreenrow'];
209
        if(b) dv.style.display='block';
207
        if(b) dv.style.display='block';
210
        else dv.style.display='none';
208
        else dv.style.display='none';
211
       
209
 
212
}
210
}
213
 
211
 
214
function showHideAbout() {
212
function showHideAbout() {
215
        var dv=document.all['dvabout'];
213
        var dv=document.all['dvabout'];
216
        if(dv.style.display=='block') dv.style.display='none';
214
        if(dv.style.display=='block') dv.style.display='none';
Line 222... Line 220...
222
        else s+=''; // make sure s is a string
220
        else s+=''; // make sure s is a string
223
        dir=(dir)? dir:'<>';
221
        dir=(dir)? dir:'<>';
224
        if(dir=='<'||dir=='<>') s=s.replace(/^(\s+)/g,'');
222
        if(dir=='<'||dir=='<>') s=s.replace(/^(\s+)/g,'');
225
        if(dir=='>'||dir=='<>') s=s.replace(/(\s+)$/g,'');
223
        if(dir=='>'||dir=='<>') s=s.replace(/(\s+)$/g,'');
226
        return s;
224
        return s;
227
       
-
 
228
};
225
};