1
+ REBOL [
2
+ System: "REBOL [R3] Language Interpreter and Run-time Environment"
3
+ Title: "Amalgamate Rebol extension include files"
4
+ Rights: {
5
+ Copyright 2012 REBOL Technologies
6
+ Copyright 2012-2023 Rebol Open Source Contributors
7
+ REBOL is a trademark of REBOL Technologies
8
+ }
9
+ License: {
10
+ Licensed under the Apache License, Version 2.0
11
+ See: http://www.apache.org/licenses/LICENSE-2.0
12
+ }
13
+ Author: "Oldes"
14
+ Version: 1.0.0
15
+ Needs: 3.5.0
16
+ Purpose: {
17
+ Collects Rebol extension related include files into a single one.
18
+ }
19
+ ]
20
+ context [
21
+ dir: %../../src/include/
22
+ space-or-tab: system/catalog/bitsets/space
23
+
24
+ amalgamate : func [ files /local result] [
25
+ result: make string! 100000
26
+ included: copy []
27
+ count: length? files
28
+ start: stats /timer
29
+
30
+ append result ajoin [
31
+ {////////////////////////////////////////////////////////////////////////
32
+ // File: rebol-extension.h
33
+ // Home: https://github.com/Oldes/Rebol3/
34
+ // Date: } now /date {
35
+ // Note: This file is amalgamated from these sources:
36
+ //} ]
37
+ foreach file files [
38
+ append result ajoin ["^/ // " file]
39
+ ]
40
+ append result {
41
+ //
42
+ ////////////////////////////////////////////////////////////////////////
43
+ }
44
+ keep-file : function [ file] [
45
+ if find included file [continue]
46
+ append included probe file
47
+ append result ajoin ["^/ // File: " file LF]
48
+ try /except [
49
+ data: read /string dir/: file
50
+ ][
51
+ append result "^/ // *** Failed to include! ***//^/ "
52
+ sys/log/error 'REBOL system/state/last-error
53
+ exit
54
+ ]
55
+ parse data [
56
+ any [
57
+ to "#include" [
58
+ ;; make sure, that the include is not commented out
59
+ s: if (find crlf s/-1 ) [
60
+ 8 skip
61
+ ;; include only file includes
62
+ some space-or-tab #"^"" copy name: to #"^"" thru lf e: (
63
+ ++ count
64
+ name: as file! probe name
65
+ unless find included name [
66
+ insert e append read /string dir/: name LF
67
+ append included name
68
+ ]
69
+ insert s "//"
70
+ )
71
+ | 1 skip
72
+ ]
73
+ ;; in case of above failure, skip this include
74
+ | 8 skip
75
+ ]
76
+ ]
77
+ ]
78
+ append append result data LF
79
+ ]
80
+ foreach file files [
81
+ keep-file file
82
+ ]
83
+ print [
84
+ as-green "Amalgamated"
85
+ as-yellow count
86
+ as-green "files into"
87
+ as-yellow length? result
88
+ as-green "bytes in time:"
89
+ as-yellow stats /timer - start
90
+ ]
91
+ result
92
+ ]
93
+
94
+ make-dir %../../build/
95
+ write %../../build/rebol-extension.h amalgamate [
96
+ %reb-c.h
97
+ %reb-ext.h
98
+ %reb-device.h
99
+ %reb-file.h
100
+ %reb-filereq.h
101
+ %reb-event.h
102
+ %reb-evtypes.h
103
+ %reb-lib.h
104
+ ]
105
+ ]
0 commit comments