emacs-gen.sh revision 1.3
11.1Sjtc#!/bin/sh
21.3Sapb#	$NetBSD: emacs-gen.sh,v 1.3 2008/10/19 22:10:04 apb Exp $
31.3Sapb
41.3Sapb: ${AWK:=awk}
51.1Sjtc
61.1Sjtccase $# in
71.1Sjtc1)	file=$1;;
81.1Sjtc*)
91.1Sjtc	echo "$0: Usage: $0 path-to-emacs.c" 1>&2
101.1Sjtc	exit 1
111.1Sjtcesac;
121.1Sjtc
131.1Sjtcif [ ! -r "$file" ] ;then
141.1Sjtc	echo "$0: can't read $file" 1>&2
151.1Sjtc	exit 1
161.1Sjtcfi
171.1Sjtc
181.1Sjtccat << E_O_F || exit 1
191.1Sjtc/*
201.1Sjtc * NOTE: THIS FILE WAS GENERATED AUTOMATICALLY FROM $file
211.1Sjtc *
221.1Sjtc * DO NOT BOTHER EDITING THIS FILE
231.1Sjtc */
241.1SjtcE_O_F
251.1Sjtc
261.1Sjtc# Pass 1: print out lines before @START-FUNC-TAB@
271.1Sjtc#	  and generate defines and function declarations,
281.1Sjtcsed -e '1,/@START-FUNC-TAB@/d' -e '/@END-FUNC-TAB@/,$d' < $file |
291.3Sapb	${AWK} 'BEGIN { nfunc = 0; }
301.1Sjtc	    /^[	 ]*#/ {
311.1Sjtc			    print $0;
321.1Sjtc			    next;
331.1Sjtc		    }
341.1Sjtc	    {
351.1Sjtc		fname = $2;
361.1Sjtc		c = substr(fname, length(fname), 1);
371.1Sjtc		if (c == ",")
381.1Sjtc			fname = substr(fname, 1, length(fname) - 1);
391.1Sjtc		if (fname != "0") {
401.1Sjtc			printf "#define XFUNC_%s %d\n", substr(fname, 3, length(fname) - 2), nfunc;
411.1Sjtc			printf "static int %s ARGS((int c));\n", fname;
421.1Sjtc			nfunc++;
431.1Sjtc		}
441.1Sjtc	    }' || exit 1
451.1Sjtc
461.1Sjtcexit 0
47