xref: /netbsd/bin/ksh/emacs-gen.sh (revision bf9ec67e)
1#!/bin/sh
2#	$NetBSD: emacs-gen.sh,v 1.2 1997/01/12 19:11:46 tls Exp $
3
4case $# in
51)	file=$1;;
6*)
7	echo "$0: Usage: $0 path-to-emacs.c" 1>&2
8	exit 1
9esac;
10
11if [ ! -r "$file" ] ;then
12	echo "$0: can't read $file" 1>&2
13	exit 1
14fi
15
16cat << E_O_F || exit 1
17/*
18 * NOTE: THIS FILE WAS GENERATED AUTOMATICALLY FROM $file
19 *
20 * DO NOT BOTHER EDITING THIS FILE
21 */
22E_O_F
23
24# Pass 1: print out lines before @START-FUNC-TAB@
25#	  and generate defines and function declarations,
26sed -e '1,/@START-FUNC-TAB@/d' -e '/@END-FUNC-TAB@/,$d' < $file |
27	awk 'BEGIN { nfunc = 0; }
28	    /^[	 ]*#/ {
29			    print $0;
30			    next;
31		    }
32	    {
33		fname = $2;
34		c = substr(fname, length(fname), 1);
35		if (c == ",")
36			fname = substr(fname, 1, length(fname) - 1);
37		if (fname != "0") {
38			printf "#define XFUNC_%s %d\n", substr(fname, 3, length(fname) - 2), nfunc;
39			printf "static int %s ARGS((int c));\n", fname;
40			nfunc++;
41		}
42	    }' || exit 1
43
44exit 0
45