2 Rebol 3.0 Alpha version ONLY
\r
3 May be run with from msys:
\r
4 $ powershell -Command "r3-a96.exe scripts\extract_req.r > result.txt"
\r
6 $ cmd.exe /S /K "r3-a96.exe scripts\extract_req.r > result.txt && exit"
\r
10 Title: "Requirements extractor"
\r
12 File: %extract_req.r
\r
18 ; do/args %req_extract.r ["diff" "OS" "req" "Class=1,Component=Code"]
\r
19 print "Usage: do/args %req_extract.r [ ^"<cmd>^" ^"[....]^" ]"
\r
20 print " req.sh diff OS req ^"Class=1^""
\r
21 print " <cmd> = (diff|ls) "
\r
22 print " diff <module> (code|test) <filter>"
\r
23 print " ls <module> <filter>"
\r
27 ;=======================================================
\r
28 ; See http://www.rebol.com/r3/docs/functions/secure.html
\r
31 file allow ; Allow Read/write to files.
\r
34 ;=======================================================
\r
35 right: func [s [string!] n [integer!]] [
\r
36 copy/part at s (length? s) - n + 1 n
\r
39 ;=======================================================
\r
41 find-files: func [dir list /local files] [
\r
42 files: sort load dir
\r
44 ; Get files that match the above types:
\r
45 foreach file files [
\r
46 if find file-types suffix? file [
\r
47 append list dir/:file
\r
50 ; Search sub-directories:
\r
51 foreach file files [
\r
52 if find file "/" [find-files dir/:file list]
\r
56 ;=======================================================
\r
61 "Filters separated with a ,"
\r
64 ; Get a good rebol3 xml parser..
\r
65 if not any-function? :load-xml [
\r
66 do http://www.ross-gill.com/r/r3xml.r
\r
69 filter-split: parse/all filter ","
\r
70 doc: load-xml/dom filename
\r
71 body: doc/get-by-tag <Req>
\r
73 foreach j filter-split [print j]
\r
76 ; Go over all req tags.
\r
78 ; Look for any matching filter
\r
80 foreach i filter-split [
\r
82 if/else find (iter/get to-tag val/1) val/2 [
\r
88 if fail == false [ append list iter/get #id ]
\r
97 "Filters separated with a ,"
\r
100 ; Get a good rebol3 xml parser..
\r
101 if not any-function? :load-xml [
\r
102 do http://www.ross-gill.com/r/r3xml.r
\r
105 filter-split: parse/all filter "="
\r
106 doc: load-xml/dom filename
\r
107 body: doc/get-by-tag <Req>
\r
109 print ["Filter:" filter-split/1 filter-split/2]
\r
110 foreach iter body [
\r
111 foreach filter-entry filter-split [
\r
112 if/else find (iter/get to-tag filter-split/1) filter-split/2 [
\r
113 append list iter/get #id
\r
121 ;=======================================================
\r
125 file-types: [%.c %.h]
\r
131 ; Grab the file-list...
\r
132 foreach dir dir-list [
\r
134 foreach file load dir [
\r
135 if find file-types suffix? file [append file-list dir/:file]
\r
141 thru "@req " copy text to [ newline | "*/"]
\r
142 (append req-list first parse text none)
\r
143 ; (text2: first parse text none)
\r
144 ; (append req-list text2)
\r
150 foreach file file-list [
\r
153 content: read/string file
\r
157 ;append req-list first parse text none
\r
158 ;parse content [ any [thru "@req" begin: to [ newline | "*/" ] fin: (append req-list trim copy/part at begin 0 ((index? fin) - (index? begin)) )]]
\r
163 ;=======================================================
\r
165 ; Simplest to keep all requirement files in one directory:
\r
166 ; e.g req-os.xml, req-can.xml
\r
168 ; Rebol strange argument passing...
\r
169 if/else (found? system/options/args) [
\r
170 ; Used from real command line
\r
171 args: system/options/args
\r
173 if/else(found? system/script/args) [
\r
174 ; Used when running from within rebol, e.g. do/args...
\r
175 args: system/script/args
\r
179 foreach a args [print ["arg:" a]]
\r
185 "diff" [ if (length? args) != 4 [usage]]
\r
186 "ls" [ if (length? args) != 4 [usage]]
\r
190 ["OS" %req-os.xml [%../system/kernel/ %../system/kernel/include/ %../include/ ] "Class=1,2,3,4"]
\r
191 ["CAN" %req-can.xml [%../arch/ppc/mpc55xx/drivers] ]
\r
194 print length? path-info
\r
195 ;foreach a path-info/1 [print a]
\r
196 ;print length? path-info/1
\r
197 ;print path-info/1/1
\r
198 ;print dir? path-info/1/3
\r
199 ;print path-info/1/2
\r
200 ;print exists? path-info/1/2
\r
202 list-xml: req-xml path-info/1/2 pick args 4 ;"Class=1"
\r
203 list-source: req-source path-info/1/3
\r
205 print length? list-xml
\r
206 print length? list-source
\r
208 print ["Requirements for module:" (pick args 2) "with filter:" pick args 4 ]
\r
209 probe sort list-xml
\r
212 print "Requirements for from source"
\r
213 probe sort list-source
\r
216 print "Requirements diff"
\r
217 probe exclude list-xml list-source
\r