• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2##
3##  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
4##
5##  Use of this source code is governed by a BSD-style license
6##  that can be found in the LICENSE file in the root of the source
7##  tree. An additional intellectual property rights grant can be found
8##  in the file PATENTS.  All contributing project authors may
9##  be found in the AUTHORS file in the root of the source tree.
10##
11
12if [ "$(uname -o 2>/dev/null)" = "Cygwin" ] \
13   && cygpath --help >/dev/null 2>&1; then
14    FIXPATH='cygpath -m'
15else
16    FIXPATH='echo_path'
17fi
18
19die() {
20    echo "${self_basename}: $@" >&2
21    exit 1
22}
23
24die_unknown(){
25    echo "Unknown option \"$1\"." >&2
26    echo "See ${self_basename} --help for available options." >&2
27    exit 1
28}
29
30echo_path() {
31    for path; do
32        echo "$path"
33    done
34}
35
36# Output one, possibly changed based on the system, path per line.
37fix_path() {
38    $FIXPATH "$@"
39}
40
41# Corrects the paths in file_list in one pass for efficiency.
42# $1 is the name of the array to be modified.
43fix_file_list() {
44    declare -n array_ref=$1
45    files=$(fix_path "${array_ref[@]}")
46    local IFS=$'\n'
47    array_ref=($files)
48}
49
50generate_uuid() {
51    local hex="0123456789ABCDEF"
52    local i
53    local uuid=""
54    local j
55    #93995380-89BD-4b04-88EB-625FBE52EBFB
56    for ((i=0; i<32; i++)); do
57        (( j = $RANDOM % 16 ))
58        uuid="${uuid}${hex:$j:1}"
59    done
60    echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
61}
62
63indent1="    "
64indent=""
65indent_push() {
66    indent="${indent}${indent1}"
67}
68indent_pop() {
69    indent="${indent%${indent1}}"
70}
71
72tag_attributes() {
73    for opt in "$@"; do
74        optval="${opt#*=}"
75        [ -n "${optval}" ] ||
76            die "Missing attribute value in '$opt' while generating $tag tag"
77        echo "${indent}${opt%%=*}=\"${optval}\""
78    done
79}
80
81open_tag() {
82    local tag=$1
83    shift
84    if [ $# -ne 0 ]; then
85        echo "${indent}<${tag}"
86        indent_push
87        tag_attributes "$@"
88        echo "${indent}>"
89    else
90        echo "${indent}<${tag}>"
91        indent_push
92    fi
93}
94
95close_tag() {
96    local tag=$1
97    indent_pop
98    echo "${indent}</${tag}>"
99}
100
101tag() {
102    local tag=$1
103    shift
104    if [ $# -ne 0 ]; then
105        echo "${indent}<${tag}"
106        indent_push
107        tag_attributes "$@"
108        indent_pop
109        echo "${indent}/>"
110    else
111        echo "${indent}<${tag}/>"
112    fi
113}
114
115