[BACK]Return to strings.sh CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

File: [cvsweb.bsd.lv] / mandoc / Attic / strings.sh (download)

Revision 1.3, Sun Mar 8 19:32:03 2009 UTC (15 years, 1 month ago) by kristaps
Branch: MAIN
CVS Tags: VERSION_1_5_1, VERSION_1_4_6, VERSION_1_4_5, VERSION_1_4_4, VERSION_1_4_2
Changes since 1.2: +9 -6 lines

Fixed strings.sh to work with NetBSD.
Fixed various lint warnings.

#! /bin/sh
# $Id: strings.sh,v 1.3 2009/03/08 19:32:03 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 >$output
fi

if [ "$input" ]; then
	exec <$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
	if [ -z "$in" ]; then
		continue
	fi
	if [ "#" = `echo "$in" | cut -c1` ]; then
		continue
	fi
	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);
}
!