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 # Skip blank/comment lines
272 while ( NF == 0 || $0 ~ /^[ ]*#/ ) {
273 if ( (getline) <= 0 ) {
274 if ( DeBug > 0 ) Depth--
281 # Make sure syntactically meaningful characters are surrounded by
282 # white space. (I gave up on gsub for this purpose).
285 Str="" # temp string for modified input line
286 tstStr=$0 # part of input line being tested
287 newStr=$0 # current input line image with modifications
288 ##########################################################################
289 # REPLACE THE FOLLOWING LINE WITH A WORK_AROUND FOR A PROBLEM WITH
290 # THE MATCH FUNCTION FOR THE SUN VERSION OF "nawk"
292 # while ( match(tstStr,"[^\\\][:=}{;]") ) {
294 while ( match(tstStr,"[:=}{;]") ) {
295 if ( RSTART-1 > 0 && substr(tstStr,RSTART-1,1) != "\\") {
300 # The character was escaped with a backslash.
301 # Patch things up -- continue testing the rest
304 Str=Str substr($0,last,RSTART+1)
305 last = last + RSTART + 1
306 tstStr =substr($0,last)
310 ####################### end of workaround ################################
311 ############################################################################
313 print "Tokenize: Match found in: " tstStr
314 print "RSTART= " RSTART " ; RLENGTH = " RLENGTH
317 # the temp string is now modified to contain:
318 # 1) all characters up to the match and the first char of match
319 # 2) blank before the syntactically significant char
320 # 3) the significant character
321 # 4) blank following the significant character
323 Str=Str substr($0,last,RSTART) " " substr($0,last+RSTART,1) " "
324 last = last + RSTART + 1;
326 # Test remaining part of input line for additional occurances
327 # of syntactically significant characters.
329 tstStr=substr($0,last)
331 # Our best guess for the new string is the part of the
332 # input line already tested plus the part yet to be tested.
337 # Check for any instances of syntax chars at the start of the line
339 sub("^[:=}{;]","& ",newStr);
343 # allow escaping of significant syntax characters
352 # Having insured that interesting chars are surrounded by blanks
353 # now tokenize the input line.
356 Ntokens = split($0,tokens)
360 if ( DeBug > 0 ) Depth--
363 function DBGprintTokens()
365 for ( i = 1; i <= Ntokens ; i++ )
366 print "tokens[" i "] = " tokens[i] > DeBugFile
369 function DBGprintArray(array,name) {
371 print name "[" i "] = " array[i] > DeBugFile
374 # -------------------------------------------------------------
376 # read until the passed in token is encountered
378 # -------------------------------------------------------------
379 function skipToToken(tok)
383 for ( i=1; i < Depth; i++ )
384 printf(" ") > DeBugFile
385 print "Entering function skipToToken:" > DeBugFile
387 while ( nextToken() != tok )
389 if ( DeBug > 0 ) Depth--
391 # -------------------------------------------------------------
394 # -------------------------------------------------------------
395 function readData() {
398 for ( i=1; i < Depth; i++ )
399 printf(" ") > DeBugFile
400 print "Entering function readData" > DeBugFile
402 while ( EOF_Reached == 0 ) {
403 if ( fileName != FILENAME ) {
405 print "====>Files Changed" > DeBugFile
406 print "fileName= " fileName > DeBugFile
407 print "FILENAME= " FILENAME > DeBugFile
410 # skip over defaults section of the new file
411 while ( lookAhead() == "{" ) {
412 # This should be another default spec
413 # skip it. (watch out for syntax errors)
415 if ( osQual != "defaults" )
416 syntaxError("Expected os:defaults found: \"" os ":" osQual "\"")
418 # Relax this restriction since we are
419 # ignoring this defaults record
420 #if ( os == BlockToken )
421 # syntaxError("Only one \"defaults\" record allowed per os" )
426 if ( getNextRecord(record) > 0 )
428 # skip remaining os entries for this source
429 # sorry no error checking.
430 while ( EOF_Reached == 0 && lookAhead() == "{" )
433 print "EOF_Reached = " EOF_Reached > DeBugFile
435 if ( DeBug > 0 ) Depth--
438 # -------------------------------------------------------------
441 # this function fills the rec[] array with defaults
443 # then it scans for a block that has a token maching
444 # BlockToken, or accepts a block with the "default"
445 # token. The "default" token is not accepted if
446 # defaults are disallowed.
448 # finally fillRecord is called to read in the lines
449 # in the block and override the entries in the rec[] array.
451 # -------------------------------------------------------------
452 function getNextRecord(rec) {
455 for ( i=1; i < Depth; i++ )
456 printf(" ") > DeBugFile
457 print "Entering function getNextRecord:" > DeBugFile
460 for ( i in defaults )
461 rec[i] = defaults[i];
465 print "src=" src > DeBugFile
466 # Allow special characters to appear in src names if they have been backslashed
467 # if ( src ~ /[{:=}]/ )
468 # syntaxError("Invalid source: \"" src "\"");
472 print "Got os " os " and qual= " osQual > DeBugFile
473 print "NR= " NR " : " $0 > DeBugFile
475 if (( os != BlockToken || osQual == "not" ) \
476 && ( os != "default" || UseDefaultBlocks != "Y" ) ) {
479 print "Skipping to end of os rec" > DeBugFile
482 if ( EOF_Reached == 1 || fileName != FILENAME ){
483 if ( DeBug > 0 ) Depth--
487 print "Look Ahead is: " tokens[TK] > DeBugFile
488 } while ( lookAhead() == "{" )
489 } while (( os != BlockToken ) && ( os != "default" || UseDefaultBlocks != "Y"))
491 print "About to call fillRecord" > DeBugFile
493 if ( DeBug > 0 ) Depth--
496 function fillRecord(rec) {
499 for ( i=1; i < Depth; i++ )
500 printf(" ") > DeBugFile
501 print "Entering fillRecord:" > DeBugFile
505 if ( tempEntry != "" ) {
509 keyword = nextToken();
510 if ( keyword == "}" )
512 if ( "=" != nextToken())
513 syntaxError("Keyword: " keyword " not followed by \"=\"");
514 tempEntry = nextToken();
515 if ( lookAhead() == "=" )
518 rec[keyword] = tempEntry
523 # check for source entry
524 # THIS IMPLIES KNOWLEDGE OF .db FILE ENTRIES!!
526 print "TYPE= " rec[TypDefault] > DeBugFile
528 if ( rec[TypDefault]=="directory" || rec[TypDefault]=="empty_dir")
530 # no source required for a directory
531 if ( rec[SrcDefault] != "" )
532 syntaxError(SrcDefault " \"" rec[SrcDefault] "\" specified for a directory.")
533 if ( rec[LnkDefault] != "" )
534 syntaxError(LnkDefault " \"" rec[LnkDefault] "\" specfied for a directory.")
536 rec[SrcDefault] = src;
537 } else if ( rec["status"] == "---cu-" ) {
538 # This is used for some reason (X11-SERV.db)
539 if ( rec[SrcDefault] != "" )
540 syntaxError( "File: \"" rec["install_target"] "\" with special status: \"---cu-\" should have no source.");
542 syntaxError("Invalid source: \"" src "\" for type: \"" rec[TypDefault] )
543 else if ( rec[TypDefault] ~ /link/ )
544 if ( src ~ /^\// || src ~ /^\./ ) {
545 if ( rec[SrcDefault] != "")
546 syntaxError( SrcDefault ": \"" rec[SrcDefault] "\" specified for link: \"" src "\"")
547 if ( rec[LnkDefault] == "" )
550 syntaxError("Invalid source: \"" src "\" for type: \"" rec[TypDefault] "\"")
551 else if ( rec[TypDefault] == "file" || rec[TypDefault] == "control" )
552 rec[SrcDefault] = src;
554 syntaxError("Unrecognized type:\"" rec[TypDefault] "\"")
556 if ( DeBug > 0 ) Depth--
560 # -------------------------------------------------------------
562 # Print records in ".db" format
563 # -------------------------------------------------------------
564 function printDb(rec) {
567 for ( i=1; i < Depth; i++ )
568 printf(" ") > DeBugFile
569 print "Entering printDb:" > DeBugFile
571 # NumEntries should be one greater than the number of defaults
573 for ( i = 1; i< NumEntries; i++ ) {
574 printf("%-40s %s %s\n",defOrder[i], ":",rec[defOrder[i]])
577 if ( DeBug > 0 ) Depth--
581 # -------------------------------------------------------------
583 # Print records in ".lst" format
584 # -------------------------------------------------------------
585 function printLst(rec) {
588 for ( i=1; i < Depth; i++ )
589 printf(" ") > DeBugFile
590 print "Entering printLst:" > DeBugFile
592 if ( rec[TypDefault] ~ /link/ )
597 printf("%s %s %s %s %s %s %s %s %s\n",
606 rec[ "responsible_project" ] )
608 if ( DeBug > 0 ) Depth--
611 # -------------------------------------------------------------
613 # print records in one of the formats expected by Gather.ksh
614 # (Jim Andreas print routine).
615 # -------------------------------------------------------------
616 function printGather(rec) {
617 # print "Entering printRecord: "
619 if (( BlockToken == "hp-ux" ) && ( rec[ "processor" ] != "378" ))
621 if ( index( rec[ "processor" ], Machine ) == 0 )
623 #printf( "skipping %s, Machine %s machines %s\n", src, Machine, rec[ "processor" ] );
627 if ( action == "toSDD" )
629 if ( rec[ "type" ] == "file" )
631 printf("%s:F:%s:%s:%s:*::\n",
632 rec[ "install_target" ], rec[ "owner" ],
633 rec[ "group" ], rec[ "mode" ])
636 else if ( action == "toReleaseTree" )
638 if ( ( rec[ "type" ] == "hard_link" ) ||
639 ( rec[ "type" ] == "sym_link" ) ||
640 ( rec[ "type" ] == "file" ) )
644 # if this is a link, then fudge a source file for Gather.ksh
645 # to check on. Really we are linking two dest files together
646 # so the hack is to get around the check in Gather.ksh
649 if ( ( rec[ "type" ] == "hard_link" ) ||
650 ( rec[ "type" ] == "sym_link" ) )
652 printf( " {s}%s {d}%s\n", "-", rec[ "install_target" ] );
654 else if ( length( src ) > 34 )
655 printf( " {s}%s {d}%s\n", src, rec[ "install_target" ] );
657 printf( " {s}%-34s {d}%s\n", src, rec[ "install_target" ] );
659 if ( rec[ "install_rule_name" ] == "c-" )
661 printf( "compress -c < {s}%s > {d}%s\n", src,
662 rec[ "install_target" ] );
664 else if ( rec[ "type" ] == "sym_link" )
666 printf( "ln -s %s {d}%s\n", src,
667 rec[ "install_target" ] );
669 else if ( rec[ "type" ] == "hard_link" )
671 printf( "ln {d}%s {d}%s\n", src,
672 rec[ "install_target" ] );
674 else if ( rec[ "uncompress" ] == "true" )
676 printf( "uncompress -c < {s}%s > {d}%s\n", src,
677 rec[ "install_target" ] );
679 else if ( length( src ) > 34 )
681 printf( "cp {s}%s {d}%s\n", src,
682 rec[ "install_target" ] );
686 printf( "cp {s}%-34s {d}%s\n", src,
687 rec[ "install_target" ] );
689 printf( "%s %s %s\n", rec[ "owner" ], rec[ "group" ], rec[ "mode" ])
690 rec[ "install_rule_name" ] = "";
691 rec[ "uncompress" ] = "";
694 else if ( action == "toDeliverArgs" )
696 temp = rec[ "install_target" ];
697 m = n = index( temp, "/" );
700 temp = substr( temp, n+1 );
701 n = index( temp, "/" );
704 dirnametarget = substr( rec[ "install_target" ], 1, m-1 );
706 if ( length( rec[ "install_target" ] ) > 40 )
708 printf("%s -d .%s\n", rec[ "install_target" ], dirnametarget );
712 printf("%-40s -d .%s\n", rec[ "install_target" ], dirnametarget );
715 else if ( action == "toCheckBuild" )
717 # print "Entering printRecord - toCheckBuild: "
721 if ( rec[ "type" ] == "file" )
724 # just print the source path for the checker tool
726 printf("%s\n", src );
729 else if ( action == "toFileList" )
734 if ( rec[ "type" ] == "file" )
737 # print the source and install_target for the human person
739 if ( length( src ) > 40 || length( rec[ "install_target" ] ) > 40 )
741 printf("%s -> %s %s\n", src,
742 rec[ "install_target" ], rec[ "mode" ] );
746 printf("%-40s -> %-40s %s\n", src,
747 rec[ "install_target" ], rec[ "mode" ] );
751 else if ( action == "toTargetList" )
756 if ( rec[ "type" ] == "file" )
759 # just print the install_target
761 printf("%s\n", rec[ "install_target" ] );