diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-03-06 14:13:47 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-03-06 14:13:47 +0000 |
commit | 236dae9fb3183b9c1d8bc6f77614797d65800987 (patch) | |
tree | 21d3944488650e4b2b02aa011f1ec70b538620f5 /strings.sh | |
parent | 898c9b0f76e9e166aa032a9d01aac9500a114b31 (diff) | |
download | mandoc-236dae9fb3183b9c1d8bc6f77614797d65800987.tar.gz mandoc-236dae9fb3183b9c1d8bc6f77614797d65800987.tar.zst mandoc-236dae9fb3183b9c1d8bc6f77614797d65800987.zip |
Strings abstracted into dynamically-created C files.
Added -V option.
Deprecated README files.
Diffstat (limited to 'strings.sh')
-rw-r--r-- | strings.sh | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/strings.sh b/strings.sh new file mode 100644 index 00000000..84b7244c --- /dev/null +++ b/strings.sh @@ -0,0 +1,83 @@ +#! /bin/sh +# $Id: strings.sh,v 1.1 2009/03/06 14:13:47 kristaps Exp $ + +# strings.sh [-o output] name input +# +# Generate the file of strings. This will contain the following +# function: +# +# const char * +# mdoc_a2NAME(const char *); +# +# The input file must be tab-delimited as follows: +# +# attnam0 A longer description +# attnam1 Another longer description + +input= +output= +args=`getopt o: $*` + +if [ $? -ne 0 ]; then + echo "usage: $0 [-o output] name input" 1>&2 + exit 1 +fi + +set -- $args + +while [ $# -ge 0 ] +do + case "$1" in + -o) + output="$2" ; shift; shift ;; + --) + shift ; break ;; + esac +done + +name=$1 + +if [ -z "$name" ]; then + echo "usage: $0 [-o output] name input" 1>&2 + exit 1 +fi + +input=$2 + +if [ "$output" ]; then + exec 1<>$output +fi + +if [ "$input" ]; then + exec 0<>$input +fi + +cat <<! +/* + * DO NOT EDIT! Automatically generated by $0. + */ +#include <stdlib.h> + +#include "private.h" + +const char * +mdoc_a2${name}(const char *p) +{ + +! + +while read in ; do + key=`printf "%s\n" "$in" | cut -f 1` + val=`printf "%s\n" "$in" | cut -f 2- | sed 's!^[ ]*!!'` + cat <<! + if (xstrcmp(p, "$key")) + return("$val"); +! +done + +cat <<! + + /* No keys found. */ + return(NULL); +} +! |