forked from bonzini/smalltalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenDoc.st
147 lines (126 loc) · 4.94 KB
/
GenDoc.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"======================================================================
|
| Smalltalk documentation publisher (utility script)
|
|
======================================================================"
"======================================================================
|
| Copyright 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
| Written by Paolo Bonzini.
|
| This file is part of GNU Smalltalk.
|
| GNU Smalltalk is free software; you can redistribute it and/or modify it
| under the terms of the GNU General Public License as published by the Free
| Software Foundation; either version 2, or (at your option) any later version.
|
| GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
| FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
| details.
|
| You should have received a copy of the GNU General Public License along with
| GNU Smalltalk; see the file COPYING. If not, write to the Free Software
| Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
======================================================================"
"Load the prerequisites"
PackageLoader fileInPackage: #ClassPublisher!
| package outFile publisher files classes classPatterns loader defaultNamespace |
classPatterns := OrderedCollection new.
publisher := STInST.TexinfoDocPublisher.
defaultNamespace := Smalltalk.
helpString :=
'Usage:
gst-doc [ flag ... ] class ...
Options:
-I --image-file=FILE look for classes in the given image
-p --package=PKG look for classes in the given package
-f --file=FILE look for classes in the given file
-n --namespace=NAMESP load files in the given namespace
-o --output=FILE emit documentation in the given file (default=stdout)
--kernel-dir=PATH use the specified kernel directory
-h --help show this message
--version print version information and exit
'.
[
loader := STInST.STClassLoader new.
Namespace current: Smalltalk.
"Parse the command-line arguments."
Smalltalk
arguments: '-h|--help --version -p|--package: -f|--file: -n|--namespace:
-I|--image-file: -o|--output: --kernel-directory:'
do: [ :opt :arg |
opt = 'help' ifTrue: [
helpString displayOn: stdout.
ObjectMemory quit: 0 ].
opt = 'version' ifTrue: [
('gst-doc - %1' % {Smalltalk version}) displayNl.
ObjectMemory quit: 0 ].
opt = 'output' ifTrue: [
outFile isNil ifFalse: [
self error: '--output specified multiple times' ].
outFile := arg ].
opt = 'namespace' ifTrue: [
defaultNamespace := Smalltalk.
(arg subStrings: $.) do:
[:each |
| key |
key := each asSymbol.
(defaultNamespace includesKey: key)
ifFalse: [defaultNamespace addSubspace: key].
defaultNamespace := defaultNamespace at: key].
loader currentNamespace: defaultNamespace ].
opt = 'package' ifTrue: [
package := PackageLoader packageAt: arg.
loader currentNamespace: package createNamespace.
files := package fullPathsOf: package fileIns.
files do: [ :each || file |
file := FileStream open: each mode: FileStream read.
loader
parseSmalltalkStream: file
with: STInST.GSTFileInParser ].
loader currentNamespace: defaultNamespace ].
opt = 'file' ifTrue: [
file := FileStream open: arg mode: FileStream read.
loader
parseSmalltalkStream: file
with: STInST.GSTFileInParser ].
opt isNil ifTrue: [ classPatterns add: arg ] ]
ifError: [
helpString displayOn: stderr.
ObjectMemory quit: 1 ].
classPatterns isEmpty
ifTrue: [
classes := loader fullyDefinedLoadedClasses.
classes isEmpty
ifTrue: [ self error: 'specify -p, -f, or a class name' ] ]
ifFalse: [
allClasses :=
loader fullyDefinedLoadedClasses,
(Class allSubclasses collect: [ :each | each instanceClass ]).
classes := IdentitySet new.
classPatterns do: [ :pat || ns |
(pat last: 2) = '.*'
ifTrue: [
ns := pat allButLast: 2.
classes addAll:
(allClasses select: [ :each |
(each environment nameIn: Smalltalk) = ns ]) ]
ifFalse: [
classes addAll:
(allClasses select: [ :each |
pat match: (each nameIn: Smalltalk) ]) ] ] ].
outFile isNil
ifTrue: [
Transcript message: stderr -> #nextPutAllFlush:.
publisher publishAll: classes on: stdout ]
ifFalse: [
publisher publishAll: classes onFile: outFile ]
]
on: Error
do: [ :ex |
('gst-doc: ', ex messageText, '
') displayOn: stderr.
"ex pass." ObjectMemory quit: 1 ]!