@@ -9,27 +9,35 @@ date: 2023.08.13
9
9
10
10
const btnConvert = document . querySelector ( '[data-convert]' ) ;
11
11
const btnClean = document . querySelector ( '[data-clear]' ) ;
12
+ const btnDemo = document . querySelector ( '[data-demo]' ) ;
12
13
const outputBlock = document . querySelector ( '.output' ) ;
13
14
const codeBlock = document . getElementById ( 'textout' ) ;
14
15
let setInstance = "" ;
15
16
16
17
btnConvert . addEventListener ( 'click' , doConvert ) ;
17
18
btnClean . addEventListener ( 'click' , destroyBoxes ) ;
19
+ btnDemo . addEventListener ( 'click' , setDemo ) ;
18
20
const dptree = { } ;
19
21
20
- function SetDPTree ( commands , mode , leaf ) {
22
+ function setDPTree ( commands , mode , leaf ) {
21
23
let str = commands . join ( ' ' ) ;
22
24
if ( dptree [ mode ] === undefined ) dptree [ mode ] = { } ;
23
25
if ( dptree [ mode ] [ str ] === undefined ) dptree [ mode ] [ str ] = leaf ;
24
26
}
25
27
26
- function GetDPTree ( commands , mode ) {
28
+ function getDPTree ( commands , mode ) {
27
29
let str = commands . join ( ' ' ) ;
28
30
if ( dptree [ mode ] === undefined || dptree [ mode ] [ str ] === undefined ) return ;
29
31
setInstance += dptree [ mode ] [ str ] ;
30
32
delete dptree [ mode ] [ str ] ;
31
33
}
32
34
35
+ function setDemo ( e ) {
36
+ document . getElementById ( "textin" ) . value =
37
+ "system {\n processes {\n general-authentication-service {\n traceoptions {\n" +
38
+ " file gas.log size 10k files 3;\n flag all;\n }\n }\n }\n}" ;
39
+ }
40
+
33
41
function FiltrInactive ( leaf ) {
34
42
let str = leaf . slice ( ) ;
35
43
console . log ( str ) ;
@@ -112,19 +120,19 @@ function doConvert() {
112
120
a = a . replace ( 'inactive: ' , '' ) ;
113
121
const linactive = [ ...tree ] ;
114
122
linactive [ 0 ] = 'deactivate' ;
115
- SetDPTree ( tree , 'inactive_array' , retSetCommand ( linactive , a ) ) ;
123
+ setDPTree ( tree , 'inactive_array' , retSetCommand ( linactive , a ) ) ;
116
124
} else if ( a . includes ( 'protect: ' ) ) {
117
125
a = a . replace ( 'protect: ' , '' ) ;
118
126
const lprotect = [ ...tree ] ;
119
127
lprotect [ 0 ] = 'protect' ;
120
- SetDPTree ( tree , 'protect_line' , retSetCommand ( lprotect , a ) ) ;
128
+ setDPTree ( tree , 'protect_line' , retSetCommand ( lprotect , a ) ) ;
121
129
}
122
130
b . split ( ' ' ) . forEach ( function ( item ) {
123
131
if ( ! item . includes ( ']' ) ) {
124
132
setInstance += retSetCommand ( tree , a + ' ' + item ) ;
125
133
} else {
126
- GetDPTree ( tree , 'inactive_array' ) ;
127
- GetDPTree ( tree , 'protect_array' ) ;
134
+ getDPTree ( tree , 'inactive_array' ) ;
135
+ getDPTree ( tree , 'protect_array' ) ;
128
136
}
129
137
} ) ;
130
138
// alert(retSetCommand(tree, cleanElem.split(';')[0]));
@@ -133,20 +141,20 @@ function doConvert() {
133
141
cleanElem = cleanElem . replace ( 'inactive: ' , '' ) ;
134
142
const linactive = [ ...tree ] ;
135
143
linactive [ 0 ] = 'deactivate' ;
136
- SetDPTree ( tree , 'inactive_line' , retSetCommand ( linactive , FiltrInactive ( cleanElem . replace ( / \; \s * .* / , '' ) ) ) ) ; //.split(' ')[0]
144
+ setDPTree ( tree , 'inactive_line' , retSetCommand ( linactive , FiltrInactive ( cleanElem . replace ( / \; \s * .* / , '' ) ) ) ) ; //.split(' ')[0]
137
145
} else if ( cleanElem . includes ( 'protect: ' ) ) {
138
146
cleanElem = cleanElem . replace ( 'protect: ' , '' ) ;
139
147
const lprotect = [ ...tree ] ;
140
148
lprotect [ 0 ] = 'protect' ;
141
- SetDPTree ( tree , 'protect_line' , retSetCommand ( lprotect , cleanElem . replace ( / \; \s * .* / , '' ) ) ) ;
149
+ setDPTree ( tree , 'protect_line' , retSetCommand ( lprotect , cleanElem . replace ( / \; \s * .* / , '' ) ) ) ;
142
150
}
143
151
setInstance += retSetCommand ( tree , cleanElem . replace ( / \; \s * .* / , '' ) ) ;
144
152
}
145
- GetDPTree ( tree , 'inactive_line' ) ;
146
- GetDPTree ( tree , 'protect_line' ) ;
153
+ getDPTree ( tree , 'inactive_line' ) ;
154
+ getDPTree ( tree , 'protect_line' ) ;
147
155
} else if ( cleanElem === '}' ) {
148
- GetDPTree ( tree , 'inactive_block' ) ;
149
- GetDPTree ( tree , 'protect_block' ) ;
156
+ getDPTree ( tree , 'inactive_block' ) ;
157
+ getDPTree ( tree , 'protect_block' ) ;
150
158
tree . pop ( ) ;
151
159
} else {
152
160
cleanElem = cleanElem . replace ( ' {' , '' ) ;
@@ -155,13 +163,13 @@ function doConvert() {
155
163
const linactive = [ ...tree ] ;
156
164
linactive [ 0 ] = 'deactivate' ;
157
165
tree . push ( cleanElem ) ;
158
- SetDPTree ( tree , 'inactive_block' , retSetCommand ( linactive , cleanElem ) ) ;
166
+ setDPTree ( tree , 'inactive_block' , retSetCommand ( linactive , cleanElem ) ) ;
159
167
} else if ( cleanElem . includes ( 'protect: ' ) ) {
160
168
cleanElem = cleanElem . replace ( 'protect: ' , '' ) ;
161
169
const lprotect = [ ...tree ] ;
162
170
lprotect [ 0 ] = 'protect' ;
163
171
tree . push ( cleanElem ) ;
164
- SetDPTree ( tree , 'protect_block' , retSetCommand ( lprotect , cleanElem ) ) ;
172
+ setDPTree ( tree , 'protect_block' , retSetCommand ( lprotect , cleanElem ) ) ;
165
173
} else {
166
174
tree . push ( cleanElem ) ;
167
175
}
0 commit comments