remove executable bit
[libvpx.git] / examples / gen_example_text.sh
blob9a8703d7f4dd0d2543ddc21083713785c5b482d5
1 #!/bin/bash
2 ##
3 ## Copyright (c) 2010 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.
13 # gen_example_text.sh
15 self=$0
17 die_usage() {
18 echo "Usage: $self <example.txt>"
19 exit 1
22 die() {
23 echo "$@"
24 exit 1
27 include_block() {
28 local on_block
29 while IFS=$'\n' read -r t_line; do
30 case "$t_line" in
31 \~*\ ${block_name})
32 if [ "x$on_block" == "xyes" ]; then
33 return 0;
34 else
35 on_block=yes
39 if [ "x$on_block" == "xyes" ]; then
40 echo "$t_line"
43 esac
44 done
45 echo "WARNING: failed to find text for block $block_name" >&2
46 return 1
49 txt=$1
50 [ -f "$txt" ] || die_usage
51 read -r template < "$txt"
52 case "$template" in
53 @TEMPLATE*) template=${txt%/*}/${template##@TEMPLATE } ;;
54 *) die "Failed to parse template name from '$template'" ;;
55 esac
57 fence="~~~~~~~~~"
58 fence="${fence}${fence}"
59 fence="${fence}${fence}"
60 fence="${fence}${fence}"
61 while IFS=$'\n' read -r line; do
62 case "$line" in
63 @TEMPLATE*)
64 template=${template##@TEMPLATE }
65 template=${template%.c}.txt
67 @DEFAULT)
68 include_block < "$template"
70 ~~~*)
71 block_name=${line##~* }
72 [ "$block_name" == "INTRODUCTION" ] || echo "$fence"
74 *) echo "$line"
76 esac
77 done < "$txt"
79 echo
80 echo "Putting It All Together"
81 echo "======================="
82 echo "${fence}"
83 ${self%/*}/gen_example_code.sh "${txt}"
84 echo "${fence}"