tools/ctdb: Pass memory context for returning nodes in parse_nodestring
[Samba/wip.git] / ctdb / libctdb / test / tools / gen-usage
blob6fad0e1e4bcee649f8aaddb55510260abf6fb463
1 #! /bin/sh
3 # read a list of C files with inline XML usage given on the command line, and
4 # write a usage function on stdout
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"/'
12 cat <<EOF
13 #include <stdio.h>
14 #include "utils.h"
16 void print_usage(void)
18 fprintf(stderr,
19 "Usage: ctdb-test [options]\n"
20 "Options available:\n"
21 "\n"
22 EOF
24 for file in "$@"
26 for line in `fgrep -n '/*** XML Argument:' < $file | cut -d: -f1`;
28 if [ -L tools/link-dtd ]; then
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
39 tr '\n' ' ' < $tmpf | sed -e 's/[[:space:]]\{2,\}/ /g' |
40 xsltproc tools/usage.xsl - | fold -w80 -s > $tmpf.txt
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
50 done
51 done
53 cat <<EOF
56 EOF