1 | /* */
|
---|
2 | /* Create DEF file for a MM helper program from a template */
|
---|
3 | /* */
|
---|
4 | /* (c) Chris Wohlgemuth 2005 */
|
---|
5 | /* */
|
---|
6 |
|
---|
7 | call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
|
---|
8 | call SysLoadFuncs
|
---|
9 |
|
---|
10 | DEBUG=1
|
---|
11 |
|
---|
12 |
|
---|
13 | deffile=ARG(1)
|
---|
14 | if ARG(1)="" then deffile="tst.def"
|
---|
15 | /*Trim off the templateFile if any*/
|
---|
16 | deffile=DELWORD(deffile,2)
|
---|
17 | /* License file to be added to the DEF file */
|
---|
18 | licenseFile=VALUE("CWMMLICENCE", ,"OS2ENVIRONMENT")
|
---|
19 |
|
---|
20 | /* Template file */
|
---|
21 | templateFile=ARG(1)
|
---|
22 | /*Trim end of args*/
|
---|
23 | templateFile=DELWORD(templateFile,3)
|
---|
24 | /*Template file is really ARG(2) but ARG(1) pulls in everything so we delete the first arg*/
|
---|
25 | templateFile=DELWORD(templateFile,1,1)
|
---|
26 | IF templateFile="" THEN
|
---|
27 | templateFile=DIRECTORY()||'\'||def.tpl
|
---|
28 |
|
---|
29 | /* Get the version of the classes */
|
---|
30 | theVersion=VALUE("MMCLSVERSION", ,"OS2ENVIRONMENT")
|
---|
31 | if theVersion="" THEN theVersion="0.0.0"
|
---|
32 |
|
---|
33 | /* The stem holding all the information we get from the template file */
|
---|
34 | fileData.=''
|
---|
35 |
|
---|
36 |
|
---|
37 | call getTemplateData templateFile
|
---|
38 | /* Index */
|
---|
39 | call assignTemplateVars
|
---|
40 |
|
---|
41 | IF DEBUG=1 THEN DO
|
---|
42 | DO a=1 to filedata.0
|
---|
43 | SAY fileData.a.sectionname":"
|
---|
44 | SAY fileData.a
|
---|
45 | END
|
---|
46 | END
|
---|
47 |
|
---|
48 | /* Specify save defaults */
|
---|
49 | IF fileData.buildmachine="" THEN
|
---|
50 | fileData.buildmachine="Default"
|
---|
51 | fileData.buildmachine.desc="Build machine: "
|
---|
52 |
|
---|
53 | IF fileData.author="" THEN
|
---|
54 | fileData.author=" "
|
---|
55 | fileData.author.desc="Author: "
|
---|
56 | IF fileData.name='' THEN
|
---|
57 | fileData.name=""
|
---|
58 |
|
---|
59 | IF DEBUG=1 THEN DO
|
---|
60 | SAY ""
|
---|
61 | SAY "License file: "||licensefile
|
---|
62 | SAY "DEF-file: "||deffile
|
---|
63 | SAY "Version: "||theversion
|
---|
64 | SAY "Template file: "||templateFile
|
---|
65 | SAY "Template data: "
|
---|
66 | DO a=1 to fileData.0
|
---|
67 | SAY " "||fileData.a.desc||": "||fileData.a
|
---|
68 | END
|
---|
69 | END
|
---|
70 |
|
---|
71 | '@type NUL > 'deffile
|
---|
72 |
|
---|
73 | /* Write header */
|
---|
74 | call lineout deffile, ';'
|
---|
75 | call lineout deffile, '; '||WORD(fileData.name,2)||": "fileData.description
|
---|
76 | call lineout deffile, ';'
|
---|
77 |
|
---|
78 | /* Write copyright */
|
---|
79 | call lineout deffile, ';'
|
---|
80 | IF fileData.copyright><"" THEN
|
---|
81 | call lineout deffile, '; '||fileData.copyright||"-"WORD(DATE(),3)
|
---|
82 | ELSE
|
---|
83 | call lineout deffile, '; '||fileData.author||" "WORD(DATE(),3)
|
---|
84 | call lineout deffile, ';'
|
---|
85 | /* Write creation date */
|
---|
86 | call lineout deffile, ';'
|
---|
87 | call lineout deffile, '; Created '||DATE()||" "||TIME()
|
---|
88 | call lineout deffile, ';'
|
---|
89 |
|
---|
90 | /* Write license */
|
---|
91 | DO WHILE LINES(licenseFile)
|
---|
92 | theLine=LINEIN(licenseFile)
|
---|
93 | IF LENGTH(theLine) >0 THEN DO
|
---|
94 | IF substr(theLine,1,1) >< ';' THEN
|
---|
95 | theLine=';'||theLine
|
---|
96 | END
|
---|
97 | ELSE
|
---|
98 | theLine=theLine||';'
|
---|
99 | call LINEOUT deffile, theLine
|
---|
100 | END
|
---|
101 | call stream licenseFile, "C", "close"
|
---|
102 |
|
---|
103 | /* Now write the NAME data */
|
---|
104 | call lineout deffile, fileData.name
|
---|
105 |
|
---|
106 | /* Description with bldlevel info */
|
---|
107 | timeData=OVERLAY(DATE("E")||" "||TIME("N"), " ")
|
---|
108 | versionData=OVERLAY( LEFT(theVersion,3)," ")
|
---|
109 | def="DESCRIPTION '$@#"||fileData.author||" "
|
---|
110 | def=def||":"||theVersion||"#@##1## "||timeData
|
---|
111 | def=def||" "||SUBSTR(fileData.buildmachine,1,11)||"::::"||WORD(TRANSLATE(theVersion," ", "."),3)
|
---|
112 | def=def||"::@@"||fileData.description||" "||fileData.copyright||"-"WORD(DATE(),3)"'"
|
---|
113 | call lineout deffile, def
|
---|
114 |
|
---|
115 | /* Additional info we may have */
|
---|
116 | call lineout deffile, fileData.other
|
---|
117 |
|
---|
118 | call stream deffile, "C", "close"
|
---|
119 |
|
---|
120 | SAY "New DEF file created for V"||theVersion||"."
|
---|
121 | exit
|
---|
122 |
|
---|
123 | /************************************************************/
|
---|
124 | /* Assign the symbols specified by the sections list the position value
|
---|
125 | they have in the list of sections. By doing this the symbols may be used
|
---|
126 | as indexes in the filedata. stem*/
|
---|
127 | assignTemplateVars: procedure expose (fileData.sections)
|
---|
128 | DO a=1 to WORDS(fileData.sections)
|
---|
129 | call VALUE WORD(fileData.sections,a),a
|
---|
130 | END
|
---|
131 | return
|
---|
132 |
|
---|
133 | /************ Parse the template file ***********************/
|
---|
134 | getTemplateData: procedure expose fileData.
|
---|
135 | theFile=arg(1)
|
---|
136 |
|
---|
137 | fileData.=''
|
---|
138 | fileContents.=''
|
---|
139 |
|
---|
140 | fileContents.0=0
|
---|
141 | /* Read in the file for easier processing */
|
---|
142 | DO WHILE LINES(theFile)
|
---|
143 | fileContents.0=fileContents.0+1
|
---|
144 | b=fileContents.0
|
---|
145 | fileContents.b=LINEIN(theFile)
|
---|
146 | END
|
---|
147 | call stream theFile, "C", "close"
|
---|
148 |
|
---|
149 | DO b=1 to fileContents.0
|
---|
150 | theLine=fileContents.b
|
---|
151 | fileContents.current=b
|
---|
152 | section = Strip(Translate(word(theline,1)))
|
---|
153 | select
|
---|
154 | when (Left(section,1) = '#') | section = '' then
|
---|
155 | do
|
---|
156 | /* Jump comments and empty lines */
|
---|
157 | end;
|
---|
158 | WHEN LEFT(section,1)="[" THEN DO
|
---|
159 | call parseSection
|
---|
160 | b=fileContents.current
|
---|
161 | END
|
---|
162 | OTHERWISE
|
---|
163 | nop
|
---|
164 | END
|
---|
165 |
|
---|
166 | END
|
---|
167 | fileData.0=WORDS(fileData.sections)
|
---|
168 | DROP fileContents.
|
---|
169 | return
|
---|
170 |
|
---|
171 | parseSection: procedure expose fileData. fileContents.
|
---|
172 | b=fileContents.current
|
---|
173 | /* Add this section to the list of sections */
|
---|
174 | filedata.sections=filedata.sections||" "||SPACE(TRANSLATE(fileContents.b, " ", "[]"))
|
---|
175 | index=WORDS(fileData.sections)
|
---|
176 | fileData.index=""
|
---|
177 | fileData.index.sectionname=SPACE(TRANSLATE(fileContents.b, " ", "[]"))
|
---|
178 | /* Parse this section */
|
---|
179 | b=b+1
|
---|
180 | DO a=b to fileContents.0
|
---|
181 | theLine=fileContents.a
|
---|
182 | fileContents.current=a
|
---|
183 | section = Strip(Translate(word(theline,1)))
|
---|
184 | select
|
---|
185 | when (Left(section,1) = '#') | section = '' then
|
---|
186 | do
|
---|
187 | /* Jump comments and empty lines */
|
---|
188 | end;
|
---|
189 | WHEN LEFT(section,1)="[" THEN DO
|
---|
190 | /* New section jump back after correcting the index */
|
---|
191 | fileContents.current=fileContents.current-1
|
---|
192 | return
|
---|
193 | END
|
---|
194 | OTHERWISE
|
---|
195 | IF fileData.index <>"" THEN fileData.index=fileData.index||'0d'x||'0a'x
|
---|
196 | fileData.index=fileData.index||theLine
|
---|
197 | END
|
---|
198 |
|
---|
199 | END
|
---|
200 |
|
---|
201 | return
|
---|
202 | /***********************************************/
|
---|