History

Initial WebM release

John Koleszar committed 16 years agov0.9.0

Commit 0ea50ceNo parent (first commit)724 files · +210045 −-49Browse files

Showing the changes to examples/gen_example_code.sh (1 of 724 files). Show all

Unified · Split

examples/gen_example_code.sh+84−0
@@ -0,0 +1,84 @@
1+#!/bin/bash
2+##
3+## Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4+##
5+## Use of this source code is governed by a BSD-style license and patent
6+## grant that can be found in the LICENSE file in the root of the source
7+## tree. All contributing project authors may be found in the AUTHORS
8+## file in the root of the source tree.
9+##
10+
11+
12+# gen_example_code.sh
13+
14+self=$0
15+
16+die_usage() {
17+ echo "Usage: $self <example.txt>"
18+ exit 1
19+}
20+
21+die() {
22+ echo "$@"
23+ exit 1
24+}
25+
26+include_block() {
27+ show_bar=$1
28+ block_name=${line##*@}
29+ indent=${line%%${block_name}}
30+ indent=${#indent}
31+ [ $indent -eq 1 ] && indent=0
32+ local on_block
33+ while IFS=$'\n' read -r t_line; do
34+ case "$t_line" in
35+ \~*\ ${block_name})
36+ if [ "x$on_block" == "xyes" ]; then
37+ return 0;
38+ else
39+ on_block=yes
40+ fi
41+ ;;
42+ @DEFAULT)
43+ if [ "x$on_block" == "xyes" ]; then
44+ include_block $show_bar < "${template%.c}.txt"
45+ return 0
46+ fi
47+ ;;
48+ *)
49+ if [ "x$on_block" == "xyes" ]; then
50+ local rem
51+ (( rem = 78 - indent ))
52+ case "$block_name" in
53+ \**) printf "%${indent}s * %s\n" "" "$t_line" ;;
54+ *)
55+ if [ "$show_bar" == "yes" ]; then
56+ printf "%${indent}s%-${rem}s//\n" "" "$t_line"
57+ else
58+ printf "%${indent}s%s\n" "" "$t_line"
59+ fi
60+ ;;
61+ esac
62+ fi
63+ esac
64+ done
65+ return 1
66+}
67+
68+txt=$1
69+[ -f "$txt" ] || die_usage
70+read -r template < "$txt"
71+case "$template" in
72+ @TEMPLATE*) template=${txt%/*}/${template##@TEMPLATE } ;;
73+ *) die "Failed to parse template name from '$template'" ;;
74+esac
75+
76+while IFS=$'\n' read -r line; do
77+ case "$line" in
78+ @*) include_block yes < "$txt" \
79+ || include_block < "${template%.c}.txt" \
80+ #|| echo "WARNING: failed to find text for block $block_name" >&2
81+ ;;
82+ *) echo "$line" ;;
83+ esac
84+done < "$template"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t