File: gen-usage

package info (click to toggle)
ctdb 1.12%2Bgit20120201-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,656 kB
  • sloc: ansic: 61,736; sh: 18,367; xml: 3,887; python: 1,220; makefile: 554; perl: 319; awk: 118
file content (56 lines) | stat: -rwxr-xr-x 1,184 bytes parent folder | download
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
#! /bin/sh

# read a list of C files with inline XML usage given on the command line, and
# write a usage function on stdout

tmpf=`mktemp /tmp/gen-help.XXXXXX`
trap "rm -f $tmpf*" EXIT
quote() {
    sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/\\n"/'
}

cat <<EOF
#include <stdio.h>
#include "utils.h"

void print_usage(void)
{
	fprintf(stderr,
"Usage: ctdb-test [options]\n"
"Options available:\n"
"\n"
EOF

for file in "$@"
do
    for line in `fgrep -n '/*** XML Argument:' < $file | cut -d: -f1`;
    do
	if [ -L tools/link-dtd ]; then

	    cat > $tmpf <<EOF
<?xml version="1.0"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD Docbook XML V4.1.2//EN"
"`pwd`/tools/link-dtd/docbookx.dtd">
<article>
EOF
	    tools/extract-help $file $line >> $tmpf
	    echo '</article>' >> $tmpf

	    tr '\n' ' ' < $tmpf | sed -e 's/[[:space:]]\{2,\}/ /g' |
		xsltproc tools/usage.xsl - | fold -w80 -s > $tmpf.txt

	    quote < $tmpf.txt
	else
	    # if we don't have docbook, just strip out the tags and grab
	    # the first two lines
	    tools/extract-help $file $line > $tmpf
	    sed 's/<arg [^>]*>/   /;s/<[^>]*>//g;' < $tmpf | head -3 | quote
	fi

    done
done

cat <<EOF
);
}
EOF