Skip to content

Commit 15fcc00

Browse files
committed
Build: ported Ren-C's make-zlib script to the conservative Rebol3 code
1 parent d4d140b commit 15fcc00

File tree

1 file changed

+94
-95
lines changed

1 file changed

+94
-95
lines changed

make/tools/make-zlib.r3

+94-95
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ REBOL [
22
System: "REBOL [R3] Language Interpreter and Run-time Environment"
33
Title: "Make sys-zlib.h and u-zlib.c"
44
Rights: {
5-
Copyright 2012-2018 Ren-C Open Source Contributors
5+
Copyright 2012-2022 Ren-C Open Source Contributors
66
REBOL is a trademark of REBOL Technologies
77
}
88
License: {
@@ -32,116 +32,114 @@ REBOL [
3232
3333
https://stackoverflow.com/a/30809775
3434
}
35+
Author: []
3536
]
3637

37-
do %c-lexicals.r
38+
do %c-lexicals.reb
3839

3940
;
4041
; Target paths+filenames for the generated include and source file
4142
;
42-
path-include: %../src/include/
43+
path-include: %../../src/include/
4344
file-include: %sys-zlib.h
44-
path-source: %../src/core/
45+
path-source: %../../src/core/
4546
file-source: %u-zlib.c
4647

48+
_: #[none]
4749

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/
5051

5152
;
5253
; Disable #include "foo.h" style inclusions (but not #include <foo.h> style)
5354
; Optionally will inline a list of files at the inclusion point
5455
;
5556
disable-user-includes: function [
56-
return: <void>
5757
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}
5959
/stdio {Disable stdio.h}
60-
<local> name line-iter line pos
61-
<static>
62-
open-include (charset {"<})
63-
close-include (charset {">})
6460
] [
61+
open-include: charset {"<}
62+
close-include: charset {">}
63+
6564
include-rule: compose [
6665
((if stdio [
6766
[open-include copy name "stdio.h" close-include |]
6867
]))
6968
{"} copy name to {"}
7069
]
7170

72-
for-next line-iter lines [
73-
parse line: line-iter/1 [
71+
forall lines [
72+
if parse line: lines/1 [
7473
any space {#}
7574
any space {include}
7675
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
8079
take pos
81-
] else [
82-
insert line unspaced [{//} space]
83-
append line unspaced [
80+
][
81+
insert line ajoin [{//} space]
82+
append line ajoin [
8483
space {/* REBOL: see make-zlib.r */}
8584
]
8685
]
8786
]
8887
]
8988

90-
if inline and (not empty? inline) [
91-
fail [
89+
if all [inline not empty? files] [
90+
print as-red [
9291
{Not all headers inlined by make-zlib:} (mold headers) LF
9392
{If we inline a header, should happen once and only once for each}
9493
]
94+
halt
9595
]
9696
]
9797

98-
9998
;
10099
; Stern warning not to edit the files
101100
;
102101

103-
make-warning-lines: func [name [file!] title [text!]] [
102+
make-warning-lines: func [name [file!] title [string!]] [
104103
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+
{//}
145143
]
146144
]
147145

@@ -182,12 +180,12 @@ fix-kr: function [
182180
any white-space
183181
]
184182
#"^{" 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
187185
insert param-ser "^/"
188-
length-diff: 1 - (length of param-spec)
186+
length-diff: 1 - (length? param-spec)
189187

190-
param-len: (index of close-paren) - (index of open-paren)
188+
param-len: (index? close-paren) - (index? open-paren)
191189
params: copy/part open-paren param-len
192190
remove/part open-paren param-len
193191
length-diff: length-diff - param-len
@@ -223,8 +221,8 @@ fix-kr: function [
223221
single-param-start: single-param (
224222
spec-type: (
225223
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)
228226
)
229227
;dump spec-type
230228
)
@@ -237,16 +235,16 @@ fix-kr: function [
237235
poke (find/skip param-block name 2) 2
238236
either typed? [
239237
(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)
242240
)
243241
][
244242
; handling "j" in case 2)
245-
unspaced [
243+
ajoin [
246244
spec-type ; "int "
247245
(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)
250248
) ; " *j"
251249
]
252250
]
@@ -263,16 +261,16 @@ fix-kr: function [
263261
poke (find/skip param-block name 2) 2
264262
either typed? [
265263
(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)
268266
)
269267
][
270268
; handling "k" in case 2)
271-
unspaced [
269+
ajoin [
272270
spec-type ; "int "
273271
(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)
276274
) ; " **k"
277275
]
278276
]
@@ -281,14 +279,12 @@ fix-kr: function [
281279
]
282280
]
283281

284-
;dump param-block
285-
286-
insert open-paren new-param: delimit ",^/ " (
282+
insert open-paren new-param: combine/with (
287283
extract/index param-block 2 2
288-
)
284+
) ",^/ "
289285
insert open-paren "^/ "
290286

291-
length-diff: length-diff + length of new-param
287+
length-diff: length-diff + length? new-param
292288

293289
check-point: skip check-point length-diff
294290
)
@@ -317,28 +313,28 @@ fix-const-char: func [
317313
source
318314
]
319315

320-
do %common.r
316+
;do %common.r
321317

322318
;
323319
; Generate %sys-zlib.h Aggregate Header File
324320
;
325321

326322
header-lines: copy []
327323

328-
for-each h-file [
324+
foreach h-file [
329325
%zconf.h
330326
%zutil.h
331327
%zlib.h
332328
%deflate.h
333329
] [
334-
append header-lines read/lines join-all [path-zlib h-file]
330+
append header-lines read/lines path-zlib/:h-file
335331
]
336332

337333
disable-user-includes header-lines
338334

339335
insert header-lines [
340336
{}
341-
{// Ren-C}
337+
{// Rebol}
342338
{#define NO_DUMMY_DECL 1}
343339
{#define Z_PREFIX 1}
344340
{#define ZLIB_CONST}
@@ -348,7 +344,7 @@ insert header-lines [
348344

349345
insert header-lines make-warning-lines file-include {ZLIB aggregated header}
350346

351-
write/lines join-all [path-include file-include] header-lines
347+
write/lines path-include/:file-include header-lines
352348

353349

354350

@@ -358,7 +354,7 @@ write/lines join-all [path-include file-include] header-lines
358354

359355
source-lines: copy []
360356

361-
append source-lines read/lines join-all [path-zlib %crc32.c]
357+
append source-lines read/lines path-zlib/crc32.c
362358

363359
;
364360
; Macros DO1 and DO8 are defined differently in crc32.c, and if you don't
@@ -369,7 +365,7 @@ append source-lines [
369365
{#undef DO8 /* REBOL: see make-zlib.r */}
370366
]
371367

372-
for-each c-file [
368+
foreach c-file [
373369
%adler32.c
374370

375371
%deflate.c
@@ -385,7 +381,7 @@ for-each c-file [
385381
%inffast.c
386382
%inflate.c
387383
][
388-
append source-lines read/lines join-all [path-zlib c-file]
384+
append source-lines read/lines path-zlib/:c-file
389385
]
390386

391387
disable-user-includes/stdio/inline source-lines copy [
@@ -403,6 +399,9 @@ insert source-lines [
403399

404400
insert source-lines make-warning-lines file-source {ZLIB aggregated source}
405401

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
407406

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

Comments
 (0)