Debian Codegraph @

lib/xmlformat

raw
1 # -*-Shell-script-*-
2 #
3 # Copyright (C) 2015-2020 SUSE Software Solutions Germany GmbH
4 #
5 # Author:
6 # Frank Sundermeyer <fsundermeyer at opensuse dot org>
7 #
8 ###########################################################################
9 #
10 # XMLformat
11 #
12 # Prettyfies the XML sources
13 #
14 ###########################################################################
15 function xmlformat {
16 local _BINARY DAPSXMLFORMAT SHORT_OPTS LONG_OPTS SUB_CMD XMLFORMAT_CMD
17 local _XMLFORMAT_FLAGS
18 SUB_CMD=$1
19 shift
20
21 SHORT_OPTS="h"
22 LONG_OPTS="file:,help,rootid:"
23
24 parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
25 eval set -- "$P_REMAIN_ARGS"
26
27 # check whether xmlformat is installed:
28 for _BINARY in xmlformat xmlformat.pl xmlformat.rb; do
29 XMLFORMAT_CMD="$(which --skip-alias --skip-functions "$_BINARY" 2>/dev/null)" && break
30 done
31 if [[ -z $XMLFORMAT_CMD ]]; then
32 ccecho "error" "Error: xmlformat is not installed"
33 exit 1
34 fi
35
36 #------ Computing the values returned from the parser -----
37 if [[ 1 -eq $P_HELP ]]; then
38 help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
39 help_file
40 help_help
41 help_rootid
42 echo -e " NOTES: * Options --file and --rootid exclude one another.\n * If neither file nor rootid is specified, the rootid\n from the DC-file is used\n * $SUB_CMD follows xi:includes\n * MAIN is ignored when --file or when a ROOTID is specified\n * This command will directly alter your source xml files!"
43 exit 0
44 fi
45
46 if [[ -z "$P_ROOTID" && -z "$P_FILE" ]]; then
47 if [[ 0 -ne $VERBOSITY ]]; then
48 ccecho "info" "Neither file nor rootid specified, using rootid from DC-file"
49 fi
50 elif [[ -n "$P_ROOTID" && -n "$P_FILE" ]]; then
51 exit_on_error "Options --file (-f) and --rootid exclude one another.\nPlease specify only one of these options"
52 fi
53
54 # define which dpas-xmlformat to use
55 #
56 if [[ -n "$DAPSROOT" && "$DAPSROOT" != "$DAPSROOT_DEFAULT" ]]; then
57 # use daps-xmlformat from DAPSROOT if the latter is set
58 DAPSXMLFORMAT="${DAPSROOT}/bin/daps-xmlformat"
59 else
60 DAPSXMLFORMAT="$(which --skip-alias --skip-functions daps-xmlformat 2>/dev/null)" || exit_on_error "Cannot find a daps-xmlformat executable"
61 fi
62
63 # if --file was specified, FILELIST contains just one file
64 # if --rootid was specified, we need to get the list of files
65
66 if [[ -n "$P_FILE" ]]; then
67 FILELIST[0]="$P_FILE"
68 else
69 [[ -n "$P_ROOTID" ]] && export ROOTID="$P_ROOTID"
70 FILELIST=( $(call_make list-srcfiles silent LIST_NODC=1 LIST_NOENT=1 LIST_NOIMG=1 ) )
71 if [[ 0 -ne $? ]]; then
72 exit_on_error "Failed to get filelist for ROOTID \"$ROOTID\""
73 fi
74 fi
75
76 # Be more verbose in debug or -vv mode
77 #
78 if [[ 1 -eq $DEBUG || 2 -le "$VERBOSITY" ]]; then
79 _XMLFORMAT_FLAGS="-i -v"
80 else
81 _XMLFORMAT_FLAGS="-i"
82 fi
83 # run daps-xmlformat
84 #
85 # ignore $MAIN with --file or --rootid
86 #
87 [[ 0 -ne $VERBOSITY ]] && echo "Prettifying the following files:"
88 for FILE in "${FILELIST[@]}"; do
89 if [[ -n "$P_FILE" || -n "$ROOTID" ]]; then
90 [[ "$FILE" = "$MAIN" ]] && continue
91 fi
92 [[ 0 -ne $VERBOSITY ]] && echo -e " $FILE"
93 $DAPSXMLFORMAT $_XMLFORMAT_FLAGS "$FILE" >/dev/null
94 done
95 }