File: conf2doc

package info (click to toggle)
elinks 0.19.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,312 kB
  • sloc: ansic: 174,714; cpp: 31,967; sh: 7,841; python: 4,039; perl: 2,183; javascript: 1,794; pascal: 1,720; makefile: 1,006; yacc: 295; lisp: 125; awk: 79; ruby: 70
file content (87 lines) | stat: -rwxr-xr-x 1,614 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
#
# Generate asciidoc from the features.conf file in the top-level direftory.
# Copyright (c) Jonas Fonseca <fonseca@diku.dk>, 2005
#

CONFFILE="$1"
TMPFILE=$(mktemp import-features.conf.XXXXXX) || exit 1

strip_comment()
{
	echo "$1" | sed 's/^#\+\( \)*//'
}

print_line()
{
	line="$1"

	echo "$(strip_comment "$line")"
}

first_section=
config_default=
config_name="features.conf"
section_title=
section_mark="~"
first_section=

print_section()
{
	if [ -n "$section_title" ]; then
		# "### Feature configuration file"
		if [ "$section_title" != "Notes for developers" ]; then
			label=
			if [ -n "$config_name" ]; then
				section_title="$section_title (\`$config_name\`)"
				label="[[$(echo $config_name | sed 's/_/-/g')]]"
			fi
			cat << __END__
$label
$section_title
$(echo "$section_title" | tr 'A-Za-z -_`' "$section_mark")
$(cat $TMPFILE)

$config_default

__END__
		fi
		echo > $TMPFILE
		section_mark="^"
		section_title=
		config_name=
		config_default=
	fi
}

cat "$CONFFILE" | while read line; do
	case "$line" in
	"### "*)
		print_section
		# Reset
		section_title=$(strip_comment "$line")
		;;
	CONFIG*)
		config_name=$(echo "$line" | cut -d '=' -f 1)
		print_section
		;;
	"# Default:"*)
		config_default=$(strip_comment "$line" | sed 's/Default://')
		config_default="*Default:* $config_default"
		;;
	""|"# vim:"*)
		# Ignore
		;;
	"#"*)
		# Backslashify --help, --enable, --disable to avoid &#8212;.
		line=$(strip_comment "$line" | sed 's/ --\([hed]\)/ \\--\1/')
		echo "$line" >> $TMPFILE
		;;
	esac
done

print_section

rm -f $TMPFILE

# vim: tabstop=4 shiftwidth=4 textwidth=76