Annotation of mandoc/strings.sh, Revision 1.3
1.1 kristaps 1: #! /bin/sh
1.3 ! kristaps 2: # $Id: strings.sh,v 1.2 2009/03/06 14:24:49 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
1.3 ! kristaps 48: exec >$output
1.1 kristaps 49: fi
50:
51: if [ "$input" ]; then
1.3 ! kristaps 52: exec <$input
1.1 kristaps 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.3 ! kristaps 70: if [ -z "$in" ]; then
! 71: continue
! 72: fi
! 73: if [ "#" = `echo "$in" | cut -c1` ]; then
! 74: continue
! 75: fi
1.1 kristaps 76: key=`printf "%s\n" "$in" | cut -f 1`
77: val=`printf "%s\n" "$in" | cut -f 2- | sed 's!^[ ]*!!'`
78: cat <<!
79: if (xstrcmp(p, "$key"))
80: return("$val");
81: !
82: done
83:
84: cat <<!
85:
86: /* No keys found. */
87: return(NULL);
88: }
89: !
CVSweb