Fix some minor issues and re-enable building of DE, ES, FR, and IT locale data (help...
[oweals/cde.git] / cde / admin / IntegTools / dbTools / udbToAny.ksh
1 #!/bin/ksh 
2
3 # ------------------------------------------------------------- 
4 #  udbToAny.ksh 
5
6 #     This script was leveraged from "databaseConversionTool.ksh" 
7 # it should provide a superset of the functionality of that script; 
8 # however the primary motivation was to get away from the use of
9 # multiple divergent parsers for the ".udb" style database.  The
10 # parser has been moved into an awk "library" file: udbParseLib.awk.
11 # this parser can and should be used by all scripts wishing to parse
12 # the ".udb" data bases. 
13 #
14 # ----------------------------
15 # new features:
16 #
17 #  -toDB                to convert to old mksubmit-style ".db" format
18 #  -toLst               to convert to old domain-port-style ".lst" files
19 #  -toCustom <prt>      to specify a print routine for a custom format
20 #  -custom <awklib>     to specify a library containing custom print routines.
21 #  -udbParseLib <awkLib> to specify a library containing an alternate parser. 
22 #  -mailTo  <user>      to specify an administrator who will receive mail
23 #                       concerning parsing errors. 
24 #
25 #  -Database            is now obsolete (although it will still work)
26 #  <udbfile> ... ...    The script can now take multiple udb files (Only the
27 #                       defaults specified in the first udb file will apply).
28 #  
29 # ----------------------------
30 #
31 #     This script converts a universal database to an 
32 # HP OSF style System Definition Database (SDD) file,
33 # or a set of args suitable to supply to the Chelmsford deliver
34 # tool, or a set of commands to build a delivery tree.
35 # For more details, please refer to the "X11 and VUE for HP_OSF/1.0"
36 # document.
37 #
38 #  This script was leveraged (read hacked extensively) from
39 #  the "udbToDb" script by Jim Andreas.  Ron Voll authored the
40 #  original "udbToDb" script.
41 #
42 # -------------------------------------------------------------
43
44 # usage:  databaseToSDD.ksh Option udbFile
45 #
46 # where Option is one of the following:
47 #
48 # -toDB              convert a .udb to ".db" format
49 # -toLst             convert a .udb to ".lst" format
50 # -toSDD             convert a .udb to SDD format
51 # -toDeliverArgs     convert a .udb to args that the deliver tool likes
52 # -toReleaseTree     convert a .udb to a script to build a delivery tree
53 # -toCheckBuild      convert a .udb to a script to check the items in a build
54 # -toFileList        convert a .udb to a list of files for carbon units
55 # -Machine           specifies 3,7,8 for hp-ux releases
56 # -ReleaseStream     {hp-ux, osf, whatever} 
57 # -NoDefaults        do not convert any records labeled default
58 # -toTargetList      convert a .udb to a list of target files in product tree
59 #                      the leading path is stripped and just the target
60 #                      file is left - for easy diffing with some other
61 #                      version of a release
62 # -custom <awkFile>             Supply a custom "awk" print library
63 # -toCustom <prt routine>
64 # -udbParseLib <awkFile>        Supply an alternate  "awk" parser library
65
66
67 # -------------------------------------------------------------
68 #  ConvertRoutine
69
70 #   This ksh function invokes awk to do all of the dirty
71 # work.  The DoAction variable is consulted only in the
72 # final stages of printing the desired info after the
73 # .udb "phrases" are parsed.
74 #
75 # -------------------------------------------------------------
76 ConvertRoutine()
77 {
78
79
80 #
81 # set what we are going to do
82 #
83     typeset DoAction=$1
84
85 #
86 # set the "release stream" or token in a block in the .udb
87 # file for which we will scan.
88 #
89     typeset BlockToken=$2
90
91
92 # and for HP-UX releases, the particular machine 68k/Snake/S800 3/7/8
93 #
94     typeset machine=$3
95
96 # set flag if default blocks are to be processed
97 #
98     typeset UseDefaultBlocks=$4
99
100     shift
101     shift
102     shift
103     shift
104
105     AWK=/usr/bin/awk
106     if [ -x /usr/bin/nawk ]; then
107         AWK=/usr/bin/nawk
108     fi
109
110 #
111 # Custom print routines may use the following parser variables:
112 #       defOrder[]      --- An array containing the names of the fields in
113 #                           a data base record (in the correct order).
114 #       NumEntries      --- One MORE than the number of entries in the
115 #                           "defOrder" array.  This is the number of fields
116 #                           in a data base record.
117 #       rec[]           --- An associative array indexed by data base record
118 #                           field name containing the value of the field.
119 #
120 # Assign custom print routines to be used for output.  The default is to
121 # use the "printDb" function associated with the library.
122 #
123
124     typeset     PRT=printDb
125     case "$DoAction" in
126     toDB)
127         PRT=printDb
128         ;;
129     toLst)
130         PRT=printLst
131         ;;
132     toFileList|toTargetList|toCheckBuild|toReleaseTree|toDeliverArgs|toSDD)
133         PRT=printGather;
134         ;;
135     toCustom) 
136         CUSTOM_PRINT="-f $CUSTOM_PRINT_LIB"
137         PRT=$CUS_PRT
138         ;;
139     *)  # Unknown Action
140         echo "$0: Unknown Action>> \"$doAction\""
141         exit 1;
142         ;;
143     esac
144
145    cat > /tmp/awk$$ <<EOF
146 #
147 # The function name "PRTREC" is used by the parsing routines
148 # to do the output. By providing a custom output function you
149 # can print the database any way you want.  The default is to
150 # use the "printRecord" function built defined in the awk file
151 # containing the awk parser.
152 #
153 function PRTREC(rec) {
154         $PRT(rec)
155 }
156 BEGIN {
157         parseUdb()
158 }
159 {
160         print "Getting New Line AWK style -- Problem?"          
161         exit 1
162 }
163 EOF
164
165    #
166    # Create a single awk file for use with the "-f" parameter.
167    # IBM's awk only allows one "-f"
168    #
169     cat "$UDB_PARSE_LIB" >> /tmp/awk$$
170     [ -z "$CUSTOM_PRINT" ]  || cat "$CUSTOM_PRINT_LIB" >> /tmp/awk$$
171
172     $AWK -v mailTo="$Administrator" \
173          -v action="$DoAction" \
174          -v BlockToken="$BlockToken" \
175          -v Machine="$machine" \
176          -v UseDefaultBlocks="$UseDefaultBlocks" \
177          -v DeBugFile="$DEBUGFILE" \
178          -v DeBug="$DEBUGLEVEL" \
179          -f /tmp/awk$$ $*
180
181
182 #
183 # Removed from parameter list because IBM's awk only allows one "-f"
184 #        $CUSTOM_PRINT \
185 #        -f "$UDB_PARSE_LIB" \
186 #
187
188      rm /tmp/awk$$
189 }
190
191 #
192 #  print a handy usage message to stderr (file descriptor 2 )
193 #
194 #
195 usage()
196 {
197     exec >&2
198
199     echo "$ScriptName: usage:" 
200     echo ""
201     echo "  $ScriptName [Options] <UdbFile> ..."
202     echo ""
203     echo "     -toDB              convert a .udb to \".db\" format"
204     echo "     -toLst              convert a .udb to \".lst\" format"
205     echo "     -toSDD             convert a .udb to SDD format"
206     echo "     -toDeliverArgs     convert a .udb to args that the deliver tool likes"
207     echo "     -toReleaseTree     convert a .udb to a script to build a delivery tree"
208     echo "     -toCheckBuild      convert a .udb to a script to check a build"
209     echo "     -toFileList        convert a .udb to a list of files"
210     echo "     -toTargetList      convert a .udb to a list of product files"
211     echo "     -ReleaseStream     {hp-ux, osf, whatever}"
212     echo "     -Machine           specifies machine 3,7,8 for hp-ux"
213     echo "     -NoDefaults        do not convert any records labeled \"default\""
214     echo "     -Database path     (obsolete) specifies full path to the .udb file to convert"
215     echo "   -mailTo  <user>      Specify a user to receive mail on errors."
216     echo "   -toCustom  <prt>     Specify the name of a custom print routine."  
217     echo "   -custom <awkFile>    Supply a custom "awk" print library."
218     echo " -udbParseLib <awkFile> Supply an alternate 'awk' parser library"
219     exit 1
220 }
221
222
223 # OK, here is where we really start execution.
224 #   Check that the first argument defines what this script is
225 #  supposed to do:
226
227 #    Obscurity footprint-in-the-sand:  "${1##*/}" is equivalent
228 #      to basename(1)
229 #
230 ScriptName=${0##*/}
231
232 # -toSDD             convert a .udb to SDD format
233 # -toDeliverArgs     convert a .udb to args that the deliver tool likes
234 # -toReleaseTree     convert a .udb to a script to build a delivery tree
235 # -toCheckBuild      convert a .udb to a script to check the items in a build
236
237 if [ $# -le 3 ]; then
238     usage $0
239 fi
240
241 typeset TakeDefaultBlocks="Y"
242 typeset Administrator=""
243 #typeset DBTOOLSRC=/x/toolsrc/dbTools
244 typeset DBTOOLSRC=`dirname $0`
245 typeset UDB_PARSE_LIB="$DBTOOLSRC/udbParseLib.awk"
246 typeset CUSTOM_PRINT_LIB=""
247 typeset DEBUGFILE="/dev/tty"
248 typeset DEBUGLEVEL=0
249
250 if [ $# -gt 2 ]; then 
251     while [ $# -gt 0 ]
252     do
253         case $1 in 
254         -NoDefaults)
255             TakeDefaultBlocks=N
256             shift
257             continue
258             ;;
259         -toDB)
260             Action=toDB
261             shift;
262             continue;
263             ;;
264         -toLst)
265             Action=toLst
266             shift;
267             continue;
268             ;;
269         -toSDD)
270             Action=toSDD
271             shift
272             continue
273             ;;
274         -toDeliverArgs)
275             Action=toDeliverArgs
276             shift
277             continue
278             ;;
279         -toReleaseTree)
280             Action=toReleaseTree
281             shift
282             continue
283             ;;
284         -toCheckBuild)
285             Action=toCheckBuild
286             shift
287             continue
288             ;;
289         -toTargetList)
290             Action=toTargetList
291             shift
292             continue
293             ;;
294         -toFileList)
295             Action=toFileList
296             shift
297             continue
298             ;;
299         -Machine)
300             if [ "x$2" = "x" ]; then
301                 usage
302             fi
303             Machine=$2
304             shift
305             shift
306             continue
307             ;;
308         -ReleaseStream)
309             if [ "x$2" = "x" ]; then
310                 usage
311             fi
312             ReleaseStream=$2
313             shift
314             shift
315             continue
316             ;;
317         -Database)
318             if [ "x$2" = "x" ]; then
319                 usage
320             fi
321             if [ ! -r "$2" ]; then 
322                 usage
323             fi
324             Database="$Database $2"
325             shift
326             shift
327             continue
328             ;;
329         -udbParseLib) # specify alternate "awk" parser location
330             if [ "x$2" = "x" ]; then
331                 usage
332             fi
333             if [ ! -r "$2" ]; then 
334                 usage
335             fi
336             UDB_PARSE_LIB=$2
337             shift
338             shift
339             continue
340             ;;
341         -toCustom) # specify custom "awk" print routines
342             if [ "x$2" = "x" ]; then
343                 usage
344             fi
345             Action=toCustom
346             CUS_PRT=$2
347             shift
348             shift
349             continue
350             ;;
351         -custom) # specify custom "awk" print routines
352             if [ "x$2" = "x" ]; then
353                 usage
354             fi
355             if [ ! -r "$2" ]; then 
356                 usage
357             fi
358             CUSTOM_PRINT_LIB=$2
359             shift
360             shift
361             continue
362             ;;
363         -mailTo) # specify an administrator who receives mail about errors.
364             if [ "x$2" = "x" ]; then
365                 usage
366             fi
367             Administrator=$2
368             shift
369             shift
370             continue
371             ;;
372         -DeBugFile) # specify a debug file and debug level for parser debug info
373             if [ "x$2" = "x" ]; then
374                 usage
375             fi
376             if [ "x$3" = "x" ]; then
377                 usage
378             fi
379             DEBUGFILE=$2
380             shift 2
381             continue
382             ;;
383         -DeBugLevel) # specify a debug level for parser debug info
384             if [ "x$2" = "x" ]; then
385                 usage
386             fi
387             if [ "x$3" = "x" ]; then
388                 usage
389             fi
390             DEBUGLEVEL=$2
391             shift 2
392             continue
393             ;;
394         -*)
395             echo "unknown option: $1"
396             echo ""
397             usage
398             exit 1;
399             ;;
400         *) if [ ! -r $1 ]; then
401                 usage
402            fi
403            Database="$Database $1"
404            shift;
405            ;;
406         esac
407     done
408 fi
409
410 if [ "$Action" = "toCustom" ]; then
411         if [ -z "$CUSTOM_PRINT_LIB" ]; then
412                 echo "You Must specify an awk file containing the custom print routine \"$CUS_PRT\""
413                 exit 1;
414         fi
415 fi
416
417
418 if [ "$Machine" = "" ]; then
419     Machine=NA
420 elif [ "$Machine" = "300" ]; then
421     Machine="3"
422 elif [ "$Machine" = "700" ]; then
423     Machine="7"
424 elif [ "$Machine" = "800" ]; then
425     Machine="8"
426 fi
427 if [ "$ReleaseStream" = "" ]; then
428     echo "$ScriptName: need to specify a -ReleaseStream" >&2
429     exit 1
430 fi
431 if [ "$Database" = "" ]; then
432     echo "$ScriptName: need to specify a -Database" >&2
433     exit 1
434 fi
435
436
437 ConvertRoutine $Action $ReleaseStream $Machine $TakeDefaultBlocks $Database