Annotation of mandoc/strings.sh, Revision 1.2
1.1 kristaps 1: #! /bin/sh
1.2 ! kristaps 2: # $Id: strings.sh,v 1.1 2009/03/06 14:13:47 kristaps Exp $
1.1 kristaps 3:
4: # strings.sh [-o output] name input
5: #
6: # Generate the file of strings. This will contain the following
7: # function:
8: #
9: # const char *
10: # mdoc_a2NAME(const char *);
11: #
12: # The input file must be tab-delimited as follows:
13: #
14: # attnam0 A longer description
15: # attnam1 Another longer description
16:
17: input=
18: output=
19: args=`getopt o: $*`
20:
21: if [ $? -ne 0 ]; then
22: echo "usage: $0 [-o output] name input" 1>&2
23: exit 1
24: fi
25:
26: set -- $args
27:
28: while [ $# -ge 0 ]
29: do
30: case "$1" in
31: -o)
32: output="$2" ; shift; shift ;;
33: --)
34: shift ; break ;;
35: esac
36: done
37:
38: name=$1
39:
40: if [ -z "$name" ]; then
41: echo "usage: $0 [-o output] name input" 1>&2
42: exit 1
43: fi
44:
45: input=$2
46:
47: if [ "$output" ]; then
48: exec 1<>$output
49: fi
50:
51: if [ "$input" ]; then
52: exec 0<>$input
53: fi
54:
55: cat <<!
56: /*
57: * DO NOT EDIT! Automatically generated by $0.
58: */
59: #include <stdlib.h>
60:
61: #include "private.h"
62:
63: const char *
64: mdoc_a2${name}(const char *p)
65: {
66:
67: !
68:
69: while read in ; do
1.2 ! kristaps 70: [ -z "$in" ] && continue;
! 71: [ "#" == `echo "$in" | cut -c1` ] && continue;
! 72:
1.1 kristaps 73: key=`printf "%s\n" "$in" | cut -f 1`
74: val=`printf "%s\n" "$in" | cut -f 2- | sed 's!^[ ]*!!'`
75: cat <<!
76: if (xstrcmp(p, "$key"))
77: return("$val");
78: !
79: done
80:
81: cat <<!
82:
83: /* No keys found. */
84: return(NULL);
85: }
86: !
CVSweb