- Timestamp:
- Dec 17, 2000, 12:20:18 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/makedesc.cmd
r4678 r4814 1 /* $Id: makedesc.cmd,v 1. 1 2000-11-23 15:12:05bird Exp $1 /* $Id: makedesc.cmd,v 1.2 2000-12-16 23:20:18 bird Exp $ 2 2 * 3 * Syntax: MakeDesc.cmd <.def> "<Vendor>" "<Version>" "<FileVer>" "<description>" 4 * Adds a Description string to the given .deffile. 5 * Fills in build machine and time/date. 6 */ 7 parse arg sDefFile '"'sVendor'"' '"'sVersion'"' '"'sDescription'"' 8 9 10 sHostname = VALUE('HOSTNAME',,'OS2ENVIRONMENT'); 11 if (sHostname = 'SD66290O') then 12 sHostname = 'UnivacJob'; 13 14 sOutput = "@"sVendor":"sVersion"#@##1## "Date()" "Time(); 15 sOutput = left(sOutput, 42) || sHostname": :::"||, 16 sVersion"::@@"||sDescription; 17 /* say sOutput; */ 18 "@echo DESCRIPTION '"||sOutput||"' >>" sDefFile 19 exit(0); 3 * Adds a Description string to the given .def-file. 4 * Fills in default values; like build time and host. 5 * 6 */ 7 8 call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'; 9 call SysLoadFuncs; 10 11 /* 12 * Set default parameter values. 13 */ 14 sDefFileIn = ''; 15 sDefFileOut = ''; 16 sASDFeatureId = ''; 17 sCountryCode = ''; 18 sDateTime = left(' 'date()' 'time(), 26); 19 sDescription = 'Odin32'; 20 sFixPakVer = ''; 21 sHostname = strip(substr(VALUE('HOSTNAME',,'OS2ENVIRONMENT'), 1, 11)); 22 sLanguageCode = ''; 23 sMiniVer = ''; 24 sVendor = 'Project Odin'; 25 sVersion = '0.5'; 26 27 28 /* 29 * Parse parameters. 30 */ 31 parse arg sArgs 32 if (sArgs = '') then 33 do 34 call syntax; 35 exit(1); 36 end 37 38 do while (sArgs <> '') 39 sArgs = strip(sArgs); 40 if (substr(sArgs, 1, 1) = '-' | substr(sArgs, 1, 1) = '/') then 41 do /* 42 * Option. 43 */ 44 ch = translate(substr(sArgs, 2, 1)); 45 if (pos(ch, 'ACDHLMNPRTV') < 1) then 46 do 47 say 'invalid option:' substr(sArgs, 1, 2); 48 call syntax; 49 exit(2); 50 end 51 52 /* get value and advance sArgs to next or to end. */ 53 if (substr(sArgs, 3, 1) = '"') then 54 do 55 iNext = pos('"', sArgs, 4); 56 fQuote = 1; 57 end 58 else 59 do 60 iNext = pos(' ', sArgs, 3); 61 if (iNext <= 0) then 62 iNext = length(sArgs); 63 fQuote = 0; 64 end 65 66 if (iNext > 3 | ch = 'R') then 67 do 68 sValue = substr(sArgs, 3 + fQuote, iNext - 3 - fQuote); 69 sArgs = strip(substr(sArgs, iNext+1)); 70 /*say 'iNext:' iNext 'sValue:' sValue 'sArgs:' sArgs; */ 71 72 /* check if we're gonna search for something in an file. */ 73 if (sValue <> '' & pos('#define=', sValue) > 0) then 74 sValue = LookupDefine(sValue); 75 end 76 else 77 do 78 say 'syntax error near' substr(sArgs, 1, 2)'.'; 79 call syntax; 80 exit(3); 81 end 82 83 84 /* set value */ 85 select 86 when (ch = 'A') then /* ASD Feature Id */ 87 sASDFeatureId = sValue; 88 89 when (ch = 'C') then /* Country code */ 90 sCountryCode = sValue; 91 92 when (ch = 'D') then /* Description */ 93 sDescription = sValue; 94 95 when (ch = 'H') then /* Hostname */ 96 sHostname = sValue; 97 98 when (ch = 'L') then /* Language code */ 99 sLanguageCode = sValue; 100 101 when (ch = 'M') then /* MiniVer */ 102 sMiniVer = sValue; 103 104 when (ch = 'N') then /* Vendor */ 105 sVendor = sValue; 106 107 when (ch = 'R') then /* Vendor */ 108 sDescription = ReadDescription(sValue, sDefFile); 109 110 when (ch = 'P') then /* Fixpak version */ 111 sFixPakVer = sValue; 112 113 when (ch = 'T') then /* Date Time */ 114 sDateTime = sValue; 115 116 when (ch = 'V') then /* Version */ 117 sVersion = sValue; 118 119 /* Otherwise it's an illegal option */ 120 otherwise: 121 say 'invalid option:' substr(sArgs, 1, 2); 122 call syntax; 123 exit(2); 124 end /* select */ 125 end 126 else 127 do /* 128 * Defition file... 129 */ 130 if (sDefFileOut <> '') then 131 do 132 say 'Syntax error: Can''t specify more than two defintion files!'; 133 exit(4); 134 end 135 if (sDefFileIn = '') then 136 parse value sArgs with sDefFileIn' 'sArgs 137 else 138 parse value sArgs with sDefFileOut' 'sArgs 139 sArgs = strip(sArgs); 140 end 141 end 142 143 144 /* check that a defintion file was specified. */ 145 if (sDefFileIn = '') then 146 do 147 say 'Syntax error: Will have to specify a .def-file to update.'; 148 call syntax; 149 exit(5); 150 end 151 152 153 /* 154 * Trim strings to correct lengths. 155 */ 156 sVendor = strip(substr(sVendor, 1, 31)); 157 if (substr(sDateTime, 1, 1) <> ' ') then 158 sDateTime = ' ' || sDateTime; 159 sDateTime = left(sDateTime, 26); 160 sHostname = strip(substr(sHostname, 1, 11)); 161 sMiniVer = strip(substr(sMiniVer, 1, 11)); 162 sDescription = strip(substr(sDescription, 1, 80)); 163 sCountryCode = strip(substr(sCountryCode, 1, 4)); 164 sLanguageCode = strip(substr(sLanguageCode, 1, 4)); 165 sASDFeatureId = strip(substr(sASDFeatureId, 1, 11)); 166 sFixPakVer = strip(substr(sFixPakVer, 1, 11)); 167 168 169 /* 170 * Signature 171 */ 172 sEnhSign = '##1##' 173 174 /* 175 * Build description string. 176 */ 177 sDescription = '@#'sVendor':'sVersion'#@'sEnhSign||, 178 sDateTime||sHostname||, 179 ':'sASDFeatureId':'sLanguageCode':'sCountryCode':'sMiniVer||, 180 '::'sFixPakVer'@@'sDescription; 181 182 /* 183 * Update .def-file. 184 */ 185 rc = UpdateDefFile(sDefFileIn, sDefFileOut, sDescription); 186 exit(rc); 187 188 189 /** 190 * Display script syntax. 191 */ 192 syntax: procedure 193 say 'Syntax: MakeDesc.cmd [options] <deffile in> <deffile out> [options]' 194 say ' <deffile> Defitionfile which will have an DESCRIPTION appended.' 195 say 'Options:' 196 say ' -A<string> ASD Feature Id.' 197 say ' -C<string> Country code.' 198 say ' -D<string> Description.' 199 say ' -R[deffile] Read description from .def file.' 200 say ' -H<string> Hostname.' 201 say ' -L<string> Language code.' 202 say ' -M<string> MiniVer.' 203 say ' -N<string> Vendor.' 204 say ' -P<string> Fixpak version.' 205 say ' -T<string> Date Time.' 206 say ' -V<string> Version.' 207 say '<string> could be a double qoute qouted string or a single word.' 208 say ' You could also reference #defines in C/C++ include files.' 209 say ' The string should then have this form:' 210 say ' "#define=<DEFINE_NAME>,<includefile.h>"' 211 say ''; 212 213 return; 214 215 216 /** 217 * Search for a #define in an C/C++ header or source file. 218 * 219 * @returns String containing the defined value 220 * found for the define in the header file. 221 * Quits on fatal errors. 222 * @param A string on the form: "#define=DEFINETOFIND,includefile.h" 223 * @remark Write only code... - let's hope it works. 224 */ 225 LookupDefine: procedure 226 parse arg '#'sDefine'='sMacro','sIncludeFile 227 228 /* 229 * Validate parameters. 230 */ 231 sMacro = strip(sMacro); 232 sIncludeFile = strip(sIncludeFile); 233 if (sMacro = '') then 234 do 235 say 'syntax error: #define=<DEFINE_NAME>,<includefile.h>.'; 236 say ' <DEFINE_NAME> was empty.'; 237 exit(-20); 238 end 239 if (sIncludeFile = '') then 240 do 241 say 'syntax error: #define=<DEFINE_NAME>,<includefile.h>.'; 242 say ' <includefile.h> was empty.'; 243 exit(-20); 244 end 245 246 247 sIllegal = translate(translate(sMacro),, 248 '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',, 249 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_'); 250 251 if (strip(translate(sIllegal, ' ', '!')) <> '') then 252 do 253 say 'syntax error: #define=<DEFINE_NAME>,<includefile.h>.'; 254 say ' <DEFINE_NAME> contains illegal charater(s).' 255 say ' 'sMacro; 256 say ' 'translate(sIllegal, ' ', '!'); 257 exit(-20); 258 end 259 260 /* 261 * Open include file. 262 */ 263 sRc = stream(sIncludeFile, 'c', 'open read'); 264 if (pos('READY', sRc) <> 1) then 265 do /* search INCLUDE variable */ 266 sFile = SysSearchPath('INCLUDE', sIncludeFile); 267 if (sFile = '') then 268 do 269 say 'Can''t find include file 'sIncludeFile'.'; 270 exit(-20); 271 end 272 sIncludeFile = sFile; 273 274 sRc = stream(sIncludeFile, 'c', 'open read'); 275 if (pos('READY', sRc) <> 1) then 276 do 277 say 'Failed to open include file' sIncludeFile'.'; 278 exit(-20); 279 end 280 end 281 282 /* 283 * Search the file line by line. 284 * We'll check for lines starting with a hash (#) char. 285 * Then check that the word after the hash is 'define'. 286 * Then match the next word with the macro name. 287 * Then then get the next rest of the line to comment or continuation char. 288 * (continuation is not supported) 289 * Finally strip quotes. 290 */ 291 sValue = ''; 292 do while (lines(sIncludeFile) > 0) 293 sLine = strip(linein(sIncludeFile)); 294 if (sLine = '') then 295 iterate; 296 if (substr(sLine, 1, 1) <> '#') then 297 iterate; 298 sLine = substr(sLine, 2); 299 if (word(sLine, 1) <> 'define') then 300 iterate; 301 sLine = strip(substr(sLine, wordpos(sLine, 1) + length('define')+1)); 302 if ( substr(sLine, 1, length(sMacro)) <> sMacro, 303 | substr(sLine, length(sMacro)+1, 1) <> ' ') then 304 iterate; 305 sLine = strip(substr(sLine, length(sMacro) + 1)); 306 if (sLine = '') then 307 do 308 say 'error: #define' sMacro' is empty.'; 309 call stream sIncludeFile, 'c', 'close'; 310 exit(-20); 311 end 312 313 chQuote = substr(sLine, 1, 1); 314 if (chQuote = '"' | chQuote = "'") then 315 do /* quoted string */ 316 iLastQuote = 0; 317 do forever 318 iLast = pos(chQuote, sLine, 2); 319 if (iLast <= 0) then 320 leave; 321 if (substr(sLine, iLast, 1) = '\') then 322 iterate; 323 iLastQuote = iLast; 324 leave; 325 end 326 327 if (iLastQuote <= 0) then 328 do 329 say 'C/C++ syntax error in 'sIncludefile': didn''t find end quote.'; 330 call stream sIncludeFile, 'c', 'close'; 331 exit(-20); 332 end 333 334 call stream sIncludeFile, 'c', 'close'; 335 sValue = substr(sLine, 2, iLastQuote - 2); 336 say 'Found 'sMacro'='sValue; 337 return sValue; 338 end 339 else 340 do 341 iCommentCPP = pos('//',sLine); 342 iCommentC = pos('/*',sLine); 343 if (iCommentC > 0 & iCommentCPP > 0 & iCommentC > iCommentCPP) then 344 iComment = iCommentCPP; 345 else if (iCommentC > 0 & iCommentCPP > 0 & iCommentC < iCommentCPP) then 346 iComment = iCommentC; 347 else if (iCommentCPP > 0) then 348 iComment = iCommentCPP; 349 else if (iCommentC > 0) then 350 iComment = iCommentC; 351 else 352 iComment = 0; 353 354 if (iComment > 0) then 355 sValue = strip(substr(sLine, 1, iComment-1)); 356 else 357 sValue = strip(sLine); 358 359 if (sValue <> '') then 360 do 361 if (substr(sValue, length(sValue)) = '\') then 362 do 363 say 'Found continuation char: Multiline definitions are not supported!\n'; 364 call stream sIncludeFile, 'c', 'close'; 365 exit(-20); 366 end 367 end 368 369 if (sValue = '') then 370 say 'warning: The #define has no value.'; 371 372 call stream sIncludeFile, 'c', 'close'; 373 say 'Found 'sMacro'='sValue; 374 return sValue; 375 end 376 end 377 378 call stream sIncludeFile, 'c', 'close'; 379 say 'error: didn''t find #define' sMacro'.'; 380 exit(-20); 381 382 383 384 /** 385 * Reads the description line for a .def-file. 386 * @returns The Description string, with quotes removed. 387 * Empty string is acceptable. 388 * On error we'll terminate the script. 389 * @param sDefFile Filaname of .def-file to read the description from. 390 * @param sDefFile2 Used if sDefFile is empty. 391 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 392 */ 393 ReadDescription: procedure; 394 parse arg sDefFile, sDefFile2 395 396 /* 397 * Validate parameters. 398 */ 399 if (sDefFile = '') then 400 sDefFile = sDefFile2; 401 if (sDefFile = '') then 402 do 403 say 'error: no definition file to get description from.' 404 exit(-1); 405 end 406 407 /* 408 * Open file 409 */ 410 rc = stream(sDefFile, 'c', 'open read'); 411 if (pos('READY', rc) <> 1) then 412 do 413 say 'error: failed to open deffile file.'; 414 exit(-1); 415 end 416 417 418 /* 419 * Search for the 'DESCRIPTION' line. 420 */ 421 do while (lines(sDefFile) > 0) 422 sLine = strip(linein(sDefFile)); 423 if (sLine = '') then 424 iterate; 425 if (translate(word(sLine, 1)) <> 'DESCRIPTION') then 426 iterate; 427 sLine = strip(substr(sLine, wordpos(sLine, 1) + length('DESCRIPTION')+1)); 428 429 ch = substr(sLine, 1, 1); 430 if (ch <> "'" & ch <> '"') then 431 do 432 say 'syntax error: description line in' sDefFile 'is misformed.'; 433 call stream sDefFile, 'c', 'close'; 434 exit(-10); 435 end 436 437 iEnd = pos(ch, sLine, 2); 438 if (iEnd <= 0) then 439 do 440 say 'syntax error: description line in' sDefFile 'is misformed.'; 441 call stream sDefFile, 'c', 'close'; 442 exit(-10); 443 end 444 445 call stream sDefFile, 'c', 'close'; 446 sValue = substr(sLine, 2, iEnd - 2); 447 say 'Found Description:' sValue; 448 return sValue; 449 end 450 451 call stream sDefFile, 'c', 'close'; 452 say 'info: Didn''t find description line in' sDefFile'.'; 453 return ''; 454 455 456 /** 457 * This is a function which reads sDefFileIn into and 458 * internal array and changes the DESCRIPTION text if found. 459 * If DESCRIPTION isn't found, it is added at the end. 460 * The array is written to sDefFileOut. 461 * @returns 0 on succes. 462 * Errorcode on error. 463 * @param sDefFileIn Input .def-file. 464 * @param sDefFileOut Output .def-file. Overwritten. 465 * @param sDescription New description string. 466 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 467 */ 468 UpdateDefFile: procedure; 469 parse arg sDefFileIn, sDefFileOut, sDescription 470 471 /* 472 * Validate parameters. 473 */ 474 if (sDefFileOut = '') then 475 sDefFileOut = sDefFileIn; 476 477 /* 478 * Open file input file. 479 */ 480 rc = stream(sDefFileIn, 'c', 'open read'); 481 if (pos('READY', rc) <> 1) then 482 do 483 say 'error: failed to open' sDefFileIn 'file.'; 484 return 110; 485 end 486 487 488 /* 489 * Search for the 'DESCRIPTION' line. 490 */ 491 i = 0; 492 fDescription = 0; 493 do while (lines(sDefFileIn) > 0) 494 /* 495 * Read line. 496 */ 497 i = i + 1; 498 asFile.i = strip(linein(sDefFileIn)); 499 500 /* 501 * Look for DESCRIPTION; 502 */ 503 if (asFile.i = '') then 504 iterate; 505 if (translate(word(asFile.i, 1)) <> 'DESCRIPTION') then 506 iterate; 507 if (fDescription) then 508 do 509 say 'warning: multiple descriptions lines. Line' i 'removed'; 510 i = i - 1; 511 iterate; 512 end 513 514 /* 515 * Found description - replace with new description. 516 */ 517 asFile.i = "DESCRIPTION '"||sDescription||"'"; 518 fDescription = 1; 519 end 520 521 /* 522 * Add description is none was found. 523 */ 524 if (\fDescription) then 525 do 526 i = i + 1; 527 asFile.i = "DESCRIPTION '"||sDescription||"'"; 528 end 529 asFile.0 = i; 530 531 532 /* 533 * Close input file and open output file. 534 */ 535 call stream sDefFileIn, 'c', 'close'; 536 call SysFileDelete(sDefFileOut); 537 rc = stream(sDefFileOut, 'c', 'open write'); 538 if (pos('READY', rc) <> 1) then 539 do 540 say 'error: failed to open outputfile' sDefFileOut 'file.'; 541 return 110; 542 end 543 544 /* 545 * Make firstline and write all the lines to the output file. 546 */ 547 call lineout sDefFileOut, '; Updated by makedesc.cmd', 1; 548 do i = 1 to asFile.0 549 rc = lineout(sDefFileOut, asFile.i); 550 if (rc > 0) then 551 do 552 say 'error: failed to write line' i 'to' sDefFileOut'.' 553 call stream sDefFileOut, 'c', 'close'; 554 return 5; 555 end 556 end 557 558 /* 559 * Close output file and return succesfully. 560 */ 561 call stream sDefFileOut, 'c', 'close'; 562 return 0; 563
Note:
See TracChangeset
for help on using the changeset viewer.