TMP: add a ctdb snapshot of current ctdb master (git://git.samba.org/ctdb.git) to...
[obnox/samba/samba-obnox.git] / ctdb / libctdb / test / tools / gen-usage
1 #! /bin/sh
2
3 # read a list of C files with inline XML usage given on the command line, and
4 # write a usage function on stdout
5
6 tmpf=`mktemp /tmp/gen-help.XXXXXX`
7 trap "rm -f $tmpf*" EXIT
8 quote() {
9     sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/\\n"/'
10 }
11
12 cat <<EOF
13 #include <stdio.h>
14 #include "utils.h"
15
16 void print_usage(void)
17 {
18         fprintf(stderr,
19 "Usage: ctdb-test [options]\n"
20 "Options available:\n"
21 "\n"
22 EOF
23
24 for file in "$@"
25 do
26     for line in `fgrep -n '/*** XML Argument:' < $file | cut -d: -f1`;
27     do
28         if [ -L tools/link-dtd ]; then
29
30             cat > $tmpf <<EOF
31 <?xml version="1.0"?>
32 <!DOCTYPE article PUBLIC "-//OASIS//DTD Docbook XML V4.1.2//EN"
33 "`pwd`/tools/link-dtd/docbookx.dtd">
34 <article>
35 EOF
36             tools/extract-help $file $line >> $tmpf
37             echo '</article>' >> $tmpf
38
39             tr '\n' ' ' < $tmpf | sed -e 's/[[:space:]]\{2,\}/ /g' |
40                 xsltproc tools/usage.xsl - | fold -w80 -s > $tmpf.txt
41
42             quote < $tmpf.txt
43         else
44             # if we don't have docbook, just strip out the tags and grab
45             # the first two lines
46             tools/extract-help $file $line > $tmpf
47             sed 's/<arg [^>]*>/   /;s/<[^>]*>//g;' < $tmpf | head -3 | quote
48         fi
49
50     done
51 done
52
53 cat <<EOF
54 );
55 }
56 EOF