2
2
System: "REBOL [R3] Language Interpreter and Run-time Environment"
3
3
Title: "Make sys-zlib.h and u-zlib.c"
4
4
Rights: {
5
- Copyright 2012-2018 Ren-C Open Source Contributors
5
+ Copyright 2012-2022 Ren-C Open Source Contributors
6
6
REBOL is a trademark of REBOL Technologies
7
7
}
8
8
License: {
@@ -32,116 +32,114 @@ REBOL [
32
32
33
33
https://stackoverflow.com/a/30809775
34
34
}
35
+ Author: []
35
36
]
36
37
37
- do %c-lexicals.r
38
+ do %c-lexicals.reb
38
39
39
40
;
40
41
; Target paths+filenames for the generated include and source file
41
42
;
42
- path-include: %../src/include/
43
+ path-include: %../../ src/include/
43
44
file-include: %sys-zlib.h
44
- path-source: %../src/core/
45
+ path-source: %../../ src/core/
45
46
file-source: %u-zlib.c
46
47
48
+ _: #[none]
47
49
48
- path-zlib: https://raw.githubusercontent.com/madler/zlib/master/
49
-
50
+ path-zlib: %/b\tree\utility\zlib\ ;https://raw.githubusercontent.com/madler/zlib/master/
50
51
51
52
;
52
53
; Disable #include "foo.h" style inclusions (but not #include <foo.h> style)
53
54
; Optionally will inline a list of files at the inclusion point
54
55
;
55
56
disable-user-includes : function [
56
- return: <void >
57
57
lines [block! ] {Block of strings}
58
- /inline [block! ] {Block of filenames to inline if seen}
58
+ /inline files [block! ] {Block of filenames to inline if seen}
59
59
/stdio {Disable stdio.h}
60
- <local > name line-iter line pos
61
- <static >
62
- open-include (charset {"<} )
63
- close-include (charset {">} )
64
60
] [
61
+ open-include: charset {"<}
62
+ close-include: charset {">}
63
+
65
64
include-rule: compose [
66
65
((if stdio [
67
66
[open-include copy name "stdio.h" close-include |]
68
67
]))
69
68
{"} copy name to {"}
70
69
]
71
70
72
- for-next line-iter lines [
73
- parse line: line-iter /1 [
71
+ forall lines [
72
+ if parse line: lines /1 [
74
73
any space {#}
75
74
any space {include}
76
75
some space include-rule to end
77
- ] then [
78
- if pos: find try inline (as file! name) [
79
- change/part line-iter (read /lines join-all [ path-zlib name] ) 1
76
+ ][
77
+ either pos: find files (as file! name) [
78
+ change/part lines (read /lines path-zlib/: name) 1
80
79
take pos
81
- ] else [
82
- insert line unspaced [{//} space]
83
- append line unspaced [
80
+ ][
81
+ insert line ajoin [{//} space]
82
+ append line ajoin [
84
83
space {/* REBOL: see make-zlib.r */}
85
84
]
86
85
]
87
86
]
88
87
]
89
88
90
- if inline and ( not empty? inline) [
91
- fail [
89
+ if all [ inline not empty? files] [
90
+ print as-red [
92
91
{Not all headers inlined by make-zlib:} (mold headers) LF
93
92
{If we inline a header, should happen once and only once for each}
94
93
]
94
+ halt
95
95
]
96
96
]
97
97
98
-
99
98
;
100
99
; Stern warning not to edit the files
101
100
;
102
101
103
- make-warning-lines : func [ name [file! ] title [text ! ]] [
102
+ make-warning-lines : func [ name [file! ] title [string ! ]] [
104
103
reduce [
105
- {/*}
106
- { * Extraction of ZLIB compression and decompression routines}
107
- { * for REBOL [R3] Language Interpreter and Run-time Environment}
108
- { * This is a code-generated file.}
109
- { *}
110
- { * ZLIB Copyright notice:}
111
- { *}
112
- { * (C) 1995-2017 Jean-loup Gailly and Mark Adler}
113
- { *}
114
- { * This software is provided 'as-is', without any express or implied}
115
- { * warranty. In no event will the authors be held liable for any damages}
116
- { * arising from the use of this software.}
117
- { *}
118
- { * Permission is granted to anyone to use this software for any purpose,}
119
- { * including commercial applications, and to alter it and redistribute it}
120
- { * freely, subject to the following restrictions:}
121
- { *}
122
- { * 1. The origin of this software must not be misrepresented; you must not}
123
- { * claim that you wrote the original software. If you use this software}
124
- { * in a product, an acknowledgment in the product documentation would be}
125
- { * appreciated but is not required.}
126
- { * 2. Altered source versions must be plainly marked as such, and must not be}
127
- { * misrepresented as being the original software.}
128
- { * 3. This notice may not be removed or altered from any source distribution.}
129
- { *}
130
- { * Jean-loup Gailly Mark Adler}
131
- { * jloup@gzip.org madler@alumni.caltech.edu}
132
- { *}
133
- { * REBOL is a trademark of REBOL Technologies}
134
- { * Licensed under the Apache License, Version 2.0}
135
- { *}
136
- { * **********************************************************************}
137
- { *}
138
- unspaced [{ * Title: } title]
139
- { * Build: A0}
140
- unspaced [{ * Date: } now /date ]
141
- unspaced [{ * File: } to text! name]
142
- { *}
143
- { * AUTO-GENERATED FILE - Do not modify. (From: make-zlib.r)}
144
- { */}
104
+ {//}
105
+ {// Extraction of ZLIB compression and decompression routines}
106
+ {// for REBOL [R3] Language Interpreter and Run-time Environment}
107
+ {// This is a code-generated file.}
108
+ {//}
109
+ {// ZLIB Copyright notice:}
110
+ {//}
111
+ {// (C) 1995-2022 Jean-loup Gailly and Mark Adler}
112
+ {//}
113
+ {// This software is provided 'as-is', without any express or implied}
114
+ {// warranty. In no event will the authors be held liable for any damages}
115
+ {// arising from the use of this software.}
116
+ {//}
117
+ {// Permission is granted to anyone to use this software for any purpose,}
118
+ {// including commercial applications, and to alter it and redistribute it}
119
+ {// freely, subject to the following restrictions:}
120
+ {//}
121
+ {// 1. The origin of this software must not be misrepresented; you must not}
122
+ {// claim that you wrote the original software. If you use this software}
123
+ {// in a product, an acknowledgment in the product documentation would be}
124
+ {// appreciated but is not required.}
125
+ {// 2. Altered source versions must be plainly marked as such, and must not be}
126
+ {// misrepresented as being the original software.}
127
+ {// 3. This notice may not be removed or altered from any source distribution.}
128
+ {//}
129
+ {// Jean-loup Gailly Mark Adler}
130
+ {// jloup@gzip.org madler@alumni.caltech.edu}
131
+ {//}
132
+ {// REBOL is a trademark of REBOL Technologies}
133
+ {// Licensed under the Apache License, Version 2.0}
134
+ {//}
135
+ {// **********************************************************************}
136
+ {//}
137
+ ajoin [{// Title: } title]
138
+ ajoin [{// Date: } now /date ]
139
+ ajoin [{// File: } name]
140
+ {//}
141
+ {// AUTO-GENERATED FILE - Do not modify. (From: make-zlib.r)}
142
+ {//}
145
143
]
146
144
]
147
145
@@ -182,12 +180,12 @@ fix-kr: function [
182
180
any white-space
183
181
]
184
182
#"^{" check-point: (
185
- ;print ["func:" to text ! fn]
186
- remove/part param-ser length of param-spec
183
+ ;print ["func:" to string ! fn]
184
+ remove/part param-ser length? param-spec
187
185
insert param-ser "^/ "
188
- length-diff: 1 - (length of param-spec)
186
+ length-diff: 1 - (length? param-spec)
189
187
190
- param-len: (index of close-paren) - (index of open-paren)
188
+ param-len: (index? close-paren) - (index? open-paren)
191
189
params: copy/part open-paren param-len
192
190
remove/part open-paren param-len
193
191
length-diff: length-diff - param-len
@@ -223,8 +221,8 @@ fix-kr: function [
223
221
single-param-start: single-param (
224
222
spec-type: (
225
223
copy/part single-param-start
226
- (index of name-start)
227
- - (index of single-param-start)
224
+ (index? name-start)
225
+ - (index? single-param-start)
228
226
)
229
227
;dump spec-type
230
228
)
@@ -237,16 +235,16 @@ fix-kr: function [
237
235
poke (find/skip param-block name 2 ) 2
238
236
either typed? [
239
237
(copy/part single-param-start
240
- (index of param-end)
241
- - (index of single-param-start)
238
+ (index? param-end)
239
+ - (index? single-param-start)
242
240
)
243
241
][
244
242
; handling "j" in case 2)
245
- unspaced [
243
+ ajoin [
246
244
spec-type ; "int "
247
245
(copy/part single-param-start
248
- (index of param-end)
249
- - (index of single-param-start)
246
+ (index? param-end)
247
+ - (index? single-param-start)
250
248
) ; " *j"
251
249
]
252
250
]
@@ -263,16 +261,16 @@ fix-kr: function [
263
261
poke (find/skip param-block name 2 ) 2
264
262
either typed? [
265
263
(copy/part single-param-start
266
- (index of param-end)
267
- - (index of single-param-start)
264
+ (index? param-end)
265
+ - (index? single-param-start)
268
266
)
269
267
][
270
268
; handling "k" in case 2)
271
- unspaced [
269
+ ajoin [
272
270
spec-type ; "int "
273
271
(copy/part single-param-start
274
- (index of param-end)
275
- - (index of single-param-start)
272
+ (index? param-end)
273
+ - (index? single-param-start)
276
274
) ; " **k"
277
275
]
278
276
]
@@ -281,14 +279,12 @@ fix-kr: function [
281
279
]
282
280
]
283
281
284
- ;dump param-block
285
-
286
- insert open-paren new-param: delimit ",^/ " (
282
+ insert open-paren new-param: combine/with (
287
283
extract/index param-block 2 2
288
- )
284
+ ) ", ^/ "
289
285
insert open-paren "^/ "
290
286
291
- length-diff: length-diff + length of new-param
287
+ length-diff: length-diff + length? new-param
292
288
293
289
check-point: skip check-point length-diff
294
290
)
@@ -317,28 +313,28 @@ fix-const-char: func [
317
313
source
318
314
]
319
315
320
- do %common.r
316
+ ; do %common.r
321
317
322
318
;
323
319
; Generate %sys-zlib.h Aggregate Header File
324
320
;
325
321
326
322
header-lines: copy []
327
323
328
- for-each h-file [
324
+ foreach h-file [
329
325
%zconf.h
330
326
%zutil.h
331
327
%zlib.h
332
328
%deflate.h
333
329
] [
334
- append header-lines read /lines join-all [ path-zlib h-file]
330
+ append header-lines read /lines path-zlib/: h-file
335
331
]
336
332
337
333
disable-user-includes header-lines
338
334
339
335
insert header-lines [
340
336
{}
341
- {// Ren-C }
337
+ {// Rebol }
342
338
{#define NO_DUMMY_DECL 1}
343
339
{#define Z_PREFIX 1}
344
340
{#define ZLIB_CONST}
@@ -348,7 +344,7 @@ insert header-lines [
348
344
349
345
insert header-lines make-warning-lines file-include {ZLIB aggregated header}
350
346
351
- write /lines join-all [ path-include file-include] header-lines
347
+ write /lines path-include/: file-include header-lines
352
348
353
349
354
350
@@ -358,7 +354,7 @@ write/lines join-all [path-include file-include] header-lines
358
354
359
355
source-lines: copy []
360
356
361
- append source-lines read /lines join-all [ path-zlib % crc32.c]
357
+ append source-lines read /lines path-zlib/ crc32.c
362
358
363
359
;
364
360
; Macros DO1 and DO8 are defined differently in crc32.c, and if you don't
@@ -369,7 +365,7 @@ append source-lines [
369
365
{#undef DO8 /* REBOL: see make-zlib.r */}
370
366
]
371
367
372
- for-each c-file [
368
+ foreach c-file [
373
369
%adler32.c
374
370
375
371
%deflate.c
@@ -385,7 +381,7 @@ for-each c-file [
385
381
%inffast.c
386
382
%inflate.c
387
383
][
388
- append source-lines read /lines join-all [ path-zlib c-file]
384
+ append source-lines read /lines path-zlib/: c-file
389
385
]
390
386
391
387
disable-user-includes/stdio/inline source-lines copy [
@@ -403,6 +399,9 @@ insert source-lines [
403
399
404
400
insert source-lines make-warning-lines file-source {ZLIB aggregated source}
405
401
406
- all-source: newlined source-lines
402
+ ;all-source: make string! 200'000
403
+ ;forall source-lines [append append all-source source-lines/1 LF]
404
+ ;;write rejoin [path-source file-source] fix-const-char fix-kr all-source
405
+ ;write path-source/:file-source fix-const-char all-source
407
406
408
- write join-all [ path-source file-source] fix-const-char fix-kr all- source
407
+ write /lines path-source/: file-source source-lines
0 commit comments