2 # Awk Library file for parsing UDB files
5 # nawk has already read the initial line.
6 # Tokenize it before doing anything else.
9 # assign hp-ux ".db" file src and link defaults
10 # if none were designated.
11 if ( SrcDefault == "" )
12 SrcDefault = "a_out_location"
13 if ( LnkDefault == "" )
14 LnkDefault = "link_source"
15 if ( TypDefault == "" )
17 if ( DestDefault == "" )
18 DestDefault = "install_target"
19 if ( ModeDefault == "" )
21 if ( OwnerDefault == "" )
22 OwnerDefault = "owner"
23 if ( GroupDefault == "" )
24 GroupDefault = "group"
28 # -------------------------------------------------------------
30 # This routine reads the defaults at the front section
31 # of the universal database and salts the defaults away.
33 # -------------------------------------------------------------
34 function readDefaults(dflts)
38 for ( i=1; i < Depth; i++ )
39 printf(" ") > DeBugFile
40 print "Entering function readDefaults" > DeBugFile
44 if ( osQual != "defaults" )
45 syntaxError("No defaults for: " BlockToken)
46 if ( os == BlockToken || os == "default" )
52 print "Skipping remaining defaults" > DeBugFile
53 # skip remaining default specs
54 while ( lookAhead() == "{" ) {
55 # This should be another default spec
56 # skip it. (watch out for syntax errors)
58 if ( osQual != "defaults" )
59 syntaxError("Expected os:defaults found: \"" os ":" osQual "\"")
60 if ( os == BlockToken && fileName == FILENAME )
61 syntaxError("Only one \"defaults\" record allowed per os" )
65 if ( DeBug > 0 ) Depth--
67 # -------------------------------------------------------------
71 # (optionally) mail a message to an administrator if a syntax
72 # error occurs in a database.
74 # -------------------------------------------------------------
75 function syntaxError(reason) {
78 for ( i=1; i < Depth; i++ )
79 printf(" ") > DeBugFile
80 print "Entering function syntaxError:" > DeBugFile
82 print "Syntax ERROR line: " NR " of file: " FILENAME
85 system( "rm -f /tmp/SyntaxError" )
86 system( "touch /tmp/SyntaxError" )
87 print "Syntax ERROR line: " NR " of file: " FILENAME > "/tmp/SyntaxError"
89 print " " reason >> "/tmp/SyntaxError"
90 close( "/tmp/SyntaxError" )
92 system( "mailx -s \"database syntax error\" "mailTo" < /tmp/SyntaxError" )
94 system( "rm -f /tmp/SyntaxError" )
97 # -------------------------------------------------------------
99 # This routine reads the defaults in the OS
100 # defaults section of the database. It saves the defaults
101 # in the "defaults" awk-style string array.
103 # -------------------------------------------------------------
104 function fillDefaults() {
107 for ( i=1; i < Depth; i++ )
108 printf(" ") > DeBugFile
109 print "Entering function fillDefaults:" > DeBugFile
114 if ( tempDflt != "" ) {
119 keyword = nextToken()
121 if ( keyword == "}" )
123 if ( "=" != nextToken())
124 syntaxError("Keyword: " keyword " not followed by \"=\" ");
125 tempDflt = nextToken();
126 if ( lookAhead() == "=" )
129 if ( tempDflt == "<SRC>" ) {
130 SrcDefault = keyword;
133 if ( tempDflt == "<LNK>" ) {
134 LnkDefault = keyword;
137 if ( tempDflt == "<TYPE>" ) {
138 TypDefault = keyword;
141 if ( tempDflt == "<DEST>" ) {
142 DestDefault = keyword;
145 if ( tempDflt == "<MODE>" ) {
146 ModeDefault = keyword;
149 if ( tempDflt == "<OWNER>" ) {
150 OwnerDefault = keyword;
153 if ( tempDflt == "<GROUP>" ) {
154 GroupDefault = keyword;
157 defaults[keyword]= tempDflt
161 defOrder[NumEntries++] = keyword;
164 DBGprintArray(defaults,"defaults")
165 print "SrcDefault =" SrcDefault > DeBugFile
166 print "LnkDefault =" LnkDefault > DeBugFile
167 print "TypDefault =" TypDefault > DeBugFile
169 if ( DeBug > 0 ) Depth--
171 # -------------------------------------------------------------
173 # This routine scans the database for an
174 # open brace, then a token, then a ":" indicating
175 # the start of an OS defaults section.
177 # -------------------------------------------------------------
182 for ( i=1; i < Depth; i++ )
183 printf(" ") > DeBugFile
184 print "Entering function getOS:" > DeBugFile
189 if ( "{" != nextToken() )
190 syntaxError("Missing initial {")
192 if ( lookAhead() == ":" ) {
197 if ( DeBug > 0 ) Depth--
200 # -------------------------------------------------------------
202 # parse the incoming data stream into tokens.
204 # -------------------------------------------------------------
205 function nextToken() {
208 for ( i=1; i < Depth; i++ )
209 printf(" ") > DeBugFile
210 print "Entering function nextToken:" > DeBugFile
212 if ( EOF_Reached == 1 )
213 syntaxError("Premature EOF");
214 tmpToken=tokens[TK++]
215 while ( TK > Ntokens || tokens[TK] == ";" ) {
218 if ( newLine() <= 0 ) {
224 print "Returning token: " tmpToken > DeBugFile
225 if ( DeBug > 0 ) Depth--
228 # -------------------------------------------------------------
230 # return the token at the head of the current list of
231 # tokens, but do not bump the token count in TK
233 # -------------------------------------------------------------
234 function lookAhead() {
237 for ( i=1; i < Depth; i++ )
238 printf(" ") > DeBugFile
239 print "Entering function lookAhead" > DeBugFile
241 if ( DeBug > 0 ) Depth--
244 # -------------------------------------------------------------
246 # read a new line of input and tokenize it.
248 # -------------------------------------------------------------
252 for ( i=1; i < Depth; i++ )
253 printf(" ") > DeBugFile
254 print "Entering function newLine:" > DeBugFile
256 if ( (retval = getline) <= 0 ) {
257 if ( DeBug > 0 ) Depth--
261 if ( DeBug > 0 ) Depth--
264 function tokenize() {
267 for ( i=1; i < Depth; i++ )
268 printf(" ") > DeBugFile
269 print "Entering function tokenize:" > DeBugFile
271 # Workaround for a strange awk bug, seen on FreeBSD
272 # and results in .db files generated with
273 # Syntax ERROR line: 10 of file: CDE-INC.udb
278 # Skip blank/comment lines
279 while ( NF == 0 || $0 ~ /^[ ]*#/ ) {
280 if ( (getline) <= 0 ) {
281 if ( DeBug > 0 ) Depth--
288 # Make sure syntactically meaningful characters are surrounded by
289 # white space. (I gave up on gsub for this purpose).
292 Str="" # temp string for modified input line
293 tstStr=$0 # part of input line being tested
294 newStr=$0 # current input line image with modifications
295 ##########################################################################
296 # REPLACE THE FOLLOWING LINE WITH A WORK_AROUND FOR A PROBLEM WITH
297 # THE MATCH FUNCTION FOR THE SUN VERSION OF "nawk"
299 # while ( match(tstStr,"[^\\\][:=}{;]") ) {
301 while ( match(tstStr,"[:=}{;]") ) {
302 if ( RSTART-1 > 0 && substr(tstStr,RSTART-1,1) != "\\") {
307 # The character was escaped with a backslash.
308 # Patch things up -- continue testing the rest
311 Str=Str substr($0,last,RSTART+1)
312 last = last + RSTART + 1
313 tstStr =substr($0,last)
317 ####################### end of workaround ################################
318 ############################################################################
320 print "Tokenize: Match found in: " tstStr
321 print "RSTART= " RSTART " ; RLENGTH = " RLENGTH
324 # the temp string is now modified to contain:
325 # 1) all characters up to the match and the first char of match
326 # 2) blank before the syntactically significant char
327 # 3) the significant character
328 # 4) blank following the significant character
330 Str=Str substr($0,last,RSTART) " " substr($0,last+RSTART,1) " "
331 last = last + RSTART + 1;
333 # Test remaining part of input line for additional occurrences
334 # of syntactically significant characters.
336 tstStr=substr($0,last)
338 # Our best guess for the new string is the part of the
339 # input line already tested plus the part yet to be tested.
344 # Check for any instances of syntax chars at the start of the line
346 sub("^[:=}{;]","& ",newStr);
350 # allow escaping of significant syntax characters
359 # Having insured that interesting chars are surrounded by blanks
360 # now tokenize the input line.
363 Ntokens = split($0,tokens)
367 if ( DeBug > 0 ) Depth--
370 function DBGprintTokens()
372 for ( i = 1; i <= Ntokens ; i++ )
373 print "tokens[" i "] = " tokens[i] > DeBugFile
376 function DBGprintArray(array,name) {
378 print name "[" i "] = " array[i] > DeBugFile
381 # -------------------------------------------------------------
383 # read until the passed in token is encountered
385 # -------------------------------------------------------------
386 function skipToToken(tok)
390 for ( i=1; i < Depth; i++ )
391 printf(" ") > DeBugFile
392 print "Entering function skipToToken:" > DeBugFile
394 while ( nextToken() != tok )
396 if ( DeBug > 0 ) Depth--
398 # -------------------------------------------------------------
401 # -------------------------------------------------------------
402 function readData() {
405 for ( i=1; i < Depth; i++ )
406 printf(" ") > DeBugFile
407 print "Entering function readData" > DeBugFile
409 while ( EOF_Reached == 0 ) {
410 if ( fileName != FILENAME ) {
412 print "====>Files Changed" > DeBugFile
413 print "fileName= " fileName > DeBugFile
414 print "FILENAME= " FILENAME > DeBugFile
417 # skip over defaults section of the new file
418 while ( lookAhead() == "{" ) {
419 # This should be another default spec
420 # skip it. (watch out for syntax errors)
422 if ( osQual != "defaults" )
423 syntaxError("Expected os:defaults found: \"" os ":" osQual "\"")
425 # Relax this restriction since we are
426 # ignoring this defaults record
427 #if ( os == BlockToken )
428 # syntaxError("Only one \"defaults\" record allowed per os" )
433 if ( getNextRecord(record) > 0 )
435 # skip remaining os entries for this source
436 # sorry no error checking.
437 while ( EOF_Reached == 0 && lookAhead() == "{" )
440 print "EOF_Reached = " EOF_Reached > DeBugFile
442 if ( DeBug > 0 ) Depth--
445 # -------------------------------------------------------------
448 # this function fills the rec[] array with defaults
450 # then it scans for a block that has a token maching
451 # BlockToken, or accepts a block with the "default"
452 # token. The "default" token is not accepted if
453 # defaults are disallowed.
455 # finally fillRecord is called to read in the lines
456 # in the block and override the entries in the rec[] array.
458 # -------------------------------------------------------------
459 function getNextRecord(rec) {
462 for ( i=1; i < Depth; i++ )
463 printf(" ") > DeBugFile
464 print "Entering function getNextRecord:" > DeBugFile
467 for ( i in defaults )
468 rec[i] = defaults[i];
472 print "src=" src > DeBugFile
473 # Allow special characters to appear in src names if they have been backslashed
474 # if ( src ~ /[{:=}]/ )
475 # syntaxError("Invalid source: \"" src "\"");
479 print "Got os " os " and qual= " osQual > DeBugFile
480 print "NR= " NR " : " $0 > DeBugFile
482 if (( os != BlockToken || osQual == "not" ) \
483 && ( os != "default" || UseDefaultBlocks != "Y" ) ) {
486 print "Skipping to end of os rec" > DeBugFile
489 if ( EOF_Reached == 1 || fileName != FILENAME ){
490 if ( DeBug > 0 ) Depth--
494 print "Look Ahead is: " tokens[TK] > DeBugFile
495 } while ( lookAhead() == "{" )
496 } while (( os != BlockToken ) && ( os != "default" || UseDefaultBlocks != "Y"))
498 print "About to call fillRecord" > DeBugFile
500 if ( DeBug > 0 ) Depth--
503 function fillRecord(rec) {
506 for ( i=1; i < Depth; i++ )
507 printf(" ") > DeBugFile
508 print "Entering fillRecord:" > DeBugFile
512 if ( tempEntry != "" ) {
516 keyword = nextToken();
517 if ( keyword == "}" )
519 if ( "=" != nextToken())
520 syntaxError("Keyword: " keyword " not followed by \"=\"");
521 tempEntry = nextToken();
522 if ( lookAhead() == "=" )
525 rec[keyword] = tempEntry
530 # check for source entry
531 # THIS IMPLIES KNOWLEDGE OF .db FILE ENTRIES!!
533 print "TYPE= " rec[TypDefault] > DeBugFile
535 if ( rec[TypDefault]=="directory" || rec[TypDefault]=="empty_dir")
537 # no source required for a directory
538 if ( rec[SrcDefault] != "" )
539 syntaxError(SrcDefault " \"" rec[SrcDefault] "\" specified for a directory.")
540 if ( rec[LnkDefault] != "" )
541 syntaxError(LnkDefault " \"" rec[LnkDefault] "\" specified for a directory.")
543 rec[SrcDefault] = src;
544 } else if ( rec["status"] == "---cu-" ) {
545 # This is used for some reason (X11-SERV.db)
546 if ( rec[SrcDefault] != "" )
547 syntaxError( "File: \"" rec["install_target"] "\" with special status: \"---cu-\" should have no source.");
549 syntaxError("Invalid source: \"" src "\" for type: \"" rec[TypDefault] )
550 else if ( rec[TypDefault] ~ /link/ )
551 if ( src ~ /^\// || src ~ /^\./ ) {
552 if ( rec[SrcDefault] != "")
553 syntaxError( SrcDefault ": \"" rec[SrcDefault] "\" specified for link: \"" src "\"")
554 if ( rec[LnkDefault] == "" )
557 syntaxError("Invalid source: \"" src "\" for type: \"" rec[TypDefault] "\"")
558 else if ( rec[TypDefault] == "file" || rec[TypDefault] == "control" )
559 rec[SrcDefault] = src;
561 syntaxError("Unrecognized type:\"" rec[TypDefault] "\"")
563 if ( DeBug > 0 ) Depth--
567 # -------------------------------------------------------------
569 # Print records in ".db" format
570 # -------------------------------------------------------------
571 function printDb(rec) {
574 for ( i=1; i < Depth; i++ )
575 printf(" ") > DeBugFile
576 print "Entering printDb:" > DeBugFile
578 # NumEntries should be one greater than the number of defaults
580 for ( i = 1; i< NumEntries; i++ ) {
581 printf("%-40s %s %s\n",defOrder[i], ":",rec[defOrder[i]])
584 if ( DeBug > 0 ) Depth--
588 # -------------------------------------------------------------
590 # Print records in ".lst" format
591 # -------------------------------------------------------------
592 function printLst(rec) {
595 for ( i=1; i < Depth; i++ )
596 printf(" ") > DeBugFile
597 print "Entering printLst:" > DeBugFile
599 if ( rec[TypDefault] ~ /link/ )
604 printf("%s %s %s %s %s %s %s %s %s\n",
613 rec[ "responsible_project" ] )
615 if ( DeBug > 0 ) Depth--
618 # -------------------------------------------------------------
620 # print records in one of the formats expected by Gather.ksh
621 # (Jim Andreas print routine).
622 # -------------------------------------------------------------
623 function printGather(rec) {
624 # print "Entering printRecord: "
626 if (( BlockToken == "hp-ux" ) && ( rec[ "processor" ] != "378" ))
628 if ( index( rec[ "processor" ], Machine ) == 0 )
630 #printf( "skipping %s, Machine %s machines %s\n", src, Machine, rec[ "processor" ] );
634 if ( action == "toSDD" )
636 if ( rec[ "type" ] == "file" )
638 printf("%s:F:%s:%s:%s:*::\n",
639 rec[ "install_target" ], rec[ "owner" ],
640 rec[ "group" ], rec[ "mode" ])
643 else if ( action == "toReleaseTree" )
645 if ( ( rec[ "type" ] == "hard_link" ) ||
646 ( rec[ "type" ] == "sym_link" ) ||
647 ( rec[ "type" ] == "file" ) )
651 # if this is a link, then fudge a source file for Gather.ksh
652 # to check on. Really we are linking two dest files together
653 # so the hack is to get around the check in Gather.ksh
656 if ( ( rec[ "type" ] == "hard_link" ) ||
657 ( rec[ "type" ] == "sym_link" ) )
659 printf( " {s}%s {d}%s\n", "-", rec[ "install_target" ] );
661 else if ( length( src ) > 34 )
662 printf( " {s}%s {d}%s\n", src, rec[ "install_target" ] );
664 printf( " {s}%-34s {d}%s\n", src, rec[ "install_target" ] );
666 if ( rec[ "install_rule_name" ] == "c-" )
668 printf( "compress -c < {s}%s > {d}%s\n", src,
669 rec[ "install_target" ] );
671 else if ( rec[ "type" ] == "sym_link" )
673 printf( "ln -s %s {d}%s\n", src,
674 rec[ "install_target" ] );
676 else if ( rec[ "type" ] == "hard_link" )
678 printf( "ln {d}%s {d}%s\n", src,
679 rec[ "install_target" ] );
681 else if ( rec[ "uncompress" ] == "true" )
683 printf( "uncompress -c < {s}%s > {d}%s\n", src,
684 rec[ "install_target" ] );
686 else if ( length( src ) > 34 )
688 printf( "cp {s}%s {d}%s\n", src,
689 rec[ "install_target" ] );
693 printf( "cp {s}%-34s {d}%s\n", src,
694 rec[ "install_target" ] );
696 printf( "%s %s %s\n", rec[ "owner" ], rec[ "group" ], rec[ "mode" ])
697 rec[ "install_rule_name" ] = "";
698 rec[ "uncompress" ] = "";
701 else if ( action == "toDeliverArgs" )
703 temp = rec[ "install_target" ];
704 m = n = index( temp, "/" );
707 temp = substr( temp, n+1 );
708 n = index( temp, "/" );
711 dirnametarget = substr( rec[ "install_target" ], 1, m-1 );
713 if ( length( rec[ "install_target" ] ) > 40 )
715 printf("%s -d .%s\n", rec[ "install_target" ], dirnametarget );
719 printf("%-40s -d .%s\n", rec[ "install_target" ], dirnametarget );
722 else if ( action == "toCheckBuild" )
724 # print "Entering printRecord - toCheckBuild: "
728 if ( rec[ "type" ] == "file" )
731 # just print the source path for the checker tool
733 printf("%s\n", src );
736 else if ( action == "toFileList" )
741 if ( rec[ "type" ] == "file" )
744 # print the source and install_target for the human person
746 if ( length( src ) > 40 || length( rec[ "install_target" ] ) > 40 )
748 printf("%s -> %s %s\n", src,
749 rec[ "install_target" ], rec[ "mode" ] );
753 printf("%-40s -> %-40s %s\n", src,
754 rec[ "install_target" ], rec[ "mode" ] );
758 else if ( action == "toTargetList" )
763 if ( rec[ "type" ] == "file" )
766 # just print the install_target
768 printf("%s\n", rec[ "install_target" ] );