1+ # Documentation Generation System
2+ # for all supported human languages
3+ # Author: G.J.G.T. de Mooij
4+ # License: BSD
5+
6+ # configuration
7+
8+ >> CTREN := ['../../bin/Linux/ctren'].
9+ >> CTR := ['../../bin/Linux/ctr'].
10+ >> DICT := ['../../dict/en'].
11+ >> DIR := ['/tmp/ctrdocs'].
12+ >> TEST := ['../../tests/en/t-'].
13+ >> RUN := ['/tmp/ctrdocs/runner'].
14+
15+ >> t := Moment new.
16+ >> time := t time plain.
17+ >> date := ['year-month-day hour:minute']
18+ year: t year plain,
19+ month: t month,
20+ day: t day,
21+ hour: t hour,
22+ minute: t minute.
23+
24+ >> template := File new: ['example.tpl.html'], read.
25+ >> manual := Dict new.
26+ >> outdir := ['server'].
27+
28+ >> languages := List new.
29+
30+ >> source := ( File new: ['../../base.c'], read ) +
31+ ( File new: ['../../collections.c'], read ).
32+
33+
34+ >> comments := source split: ['/**'].
35+ comments shift.
36+ >> total := comments count.
37+
38+ String on: ['html'] do: {
39+ >> html := self string copy.
40+ html replace: ['&'] with: ['&'].
41+ html replace: ['"'] with: ['"'].
42+ html replace: ['<'] with: ['<'].
43+ html replace: ['>'] with: ['>'].
44+ html replace: ['↵'] with: ['<br>'].
45+ <- html.
46+ }.
47+
48+
49+ File list: ['../../i18nsel'], each: { :i :dict
50+ >> lang := dict file.
51+ lang = ['..'] or: lang = ['.'], continue.
52+ manual put: (List new) at: lang.
53+ languages append: lang.
54+ }.
55+
56+ languages sort: { :a :b <- a > b. }.
57+
58+ Program os: ['mkdir -p /tmp/ctrdocs'].
59+
60+ >> book := Dict new.
61+
62+ languages each: { :i :iso
63+ book put: (List new) at: iso.
64+ }.
65+
66+ >> language-index := [''].
67+ >> first := True.
68+
69+ comments each: { :i :comment
70+
71+ >> comment := comment split: ['*/'], first.
72+ >> parts := comment split: ['@def'].
73+ (parts count < 2) continue.
74+ parts := parts last split: ['@test'].
75+ (parts count < 2) continue.
76+ >> def := parts first replace: ['\n *'] with: [''], trim.
77+ >> testno := parts last trim.
78+
79+
80+ Out write: (
81+ ['Processing comment: <index>/<total>']
82+ <index>: i,
83+ <total>: total
84+ ), stop.
85+
86+ Out write: def, stop.
87+ Out write: testno, stop.
88+
89+ >> path := ['../../tests/en/t-'] + testno + ['.ctr'].
90+ >> example := File new: path, read.
91+
92+
93+
94+ File new: ( ['<DIR>/defsrc.ctr'] <DIR>: DIR ), write: def.
95+
96+
97+
98+ languages each: { :j :iso
99+
100+ Out write: iso, stop.
101+
102+
103+ >> translate-def := ['<CTREN> -t <DICT><ISO>.dict <DIR>/defsrc.ctr > <DIR>/def<ISO>.ctr 2><DIR>/deferr<ISO>.log'].
104+ translate-def
105+ <CTREN>: CTREN,
106+ <DICT>: DICT,
107+ <DIR>: DIR,
108+ <ISO>: iso.
109+
110+
111+ Program os: translate-def.
112+
113+ >> translate-example := ['<CTREN> -t <DICT><ISO>.dict <TEST><NR>.ctr > <RUN><ISO>.ctr 2><DIR>/runerr<ISO>.log'].
114+ translate-example
115+ <CTREN>: CTREN,
116+ <DICT>: DICT,
117+ <DIR>: DIR,
118+ <TEST>: TEST,
119+ <RUN>: RUN,
120+ <NR>: testno,
121+ <ISO>: iso.
122+
123+
124+ Program os: translate-example.
125+
126+ >> run-example := ['<CTR><ISO> <RUN><ISO>.ctr > <DIR>/res<ISO>.txt 2><DIR>/reserr<ISO>.log'].
127+
128+ run-example
129+ <CTR>: CTR,
130+ <DIR>: DIR,
131+ <RUN>: RUN,
132+ <ISO>: iso.
133+
134+
135+ Program os: run-example.
136+
137+ >> path-localized-definition := ['<DIR>/def<ISO>.ctr'] <DIR>: DIR, <ISO>: iso.
138+ >> path-localized-example := ['<RUN><ISO>.ctr'] <RUN>: RUN, <ISO>: iso.
139+ >> path-localized-result := ['<DIR>/res<ISO>.txt'] <DIR>: DIR, <ISO>: iso.
140+
141+ >> localized-definition := File new: path-localized-definition, read.
142+ >> localized-example := File new: path-localized-example, read.
143+ >> localized-result := File new: path-localized-result, read.
144+ >> shasum := (
145+ Program os: ( ['echo "<ISO><DEF>" | sha1sum'] <ISO>: iso, <DEF>: localized-definition )
146+ ) split: [' '], first.
147+ >> fname := shasum + ['.html'].
148+
149+
150+ >> chapter := Dict new
151+ name: shasum,
152+ definition: localized-definition,
153+ example: localized-example,
154+ result: localized-result.
155+
156+ book at: iso, append: chapter.
157+
158+ Out write: book, stop.
159+ Out write: languages, stop.
160+ Out write: i, stop.
161+
162+ (first) true: {
163+ language-index append:
164+ ['<a href="'] + fname + ['">'] + iso + ['</a>'].
165+ }.
166+
167+ Out write: language-index, stop.
168+
169+
170+
171+
172+ #Program end.
173+ True break.
174+ }.
175+
176+ first := False.
177+
178+ }.
179+
180+
181+
182+ book each: { :iso :chapters
183+
184+ >> indexhtml := [''].
185+
186+ chapters each: { :_ :chapter
187+ indexhtml append: ['<a href="'] + chapter name + ['.html">'] + chapter definition + ['</a>'].
188+ }.
189+
190+ chapters each: { :k :chapter
191+
192+ >> page := template copy.
193+
194+ page
195+ replace: ['{{title}}'] with: chapter definition,
196+ replace: ['{{language}}'] with: iso,
197+ replace: ['{{example}}'] with: chapter example,
198+ replace: ['{{result}}'] with: chapter result,
199+ replace: ['{{languages}}'] with: language-index,
200+ replace: ['{{index}}'] with: indexhtml.
201+
202+
203+ Out write: page, stop.
204+ }.
205+
206+ }.
207+
208+ Out write: book, stop.
0 commit comments