BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libg++ / grot / proto-kit / genclass.extnsn
CommitLineData
f5bd723a
C
1#!/bin/csh
2
3# shell script for generating classes from prototypes
4#
5# usage: genclass protodir cdir extension type {ref | val} [type {ref | val}] ... proto
6#
7
8set PROGRAM_NAME=$0
9set USAGE="Usage: ${PROGRAM_NAME} '<Proto dir> <C dir> <C file extension> <type> {ref | val} [<type> {ref | val}] ... <prototype>'";
10
11# there are at least 6 parameters, plus the program name (total of seven)
12if (($#argv < 6) || ($#argv % 2) > 0) then
13 echo "${PROGRAM_NAME}: invalid parameter count";
14 echo "${USAGE}";
15 exit 1;
16endif
17
18set PWD=`pwd`/
19
20# get the prototype directory, the C directory and the C file extension (.h or .cc)
21# from the argument list
22set PROTODIR = $1; shift;
23set OUTDIR = $1; shift;
24set EXTNSN = $1; shift;
25
26if ($PROTODIR !~ */) then
27 set PROTODIR = $PROTODIR/
28endif
29if ($OUTDIR !~ */) then
30 set OUTDIR = $OUTDIR/
31endif
32
33set FILE_NAME=;
34set CLASS_NAME=;
35set TYPES=;
36set VALS=;
37
38# loop through the parameters, pulling <type> <reference type> pairs off the
39# argument list.
40
41while ( $#argv > 2 )
42 set TYPES = (${TYPES} $1)
43 set VALS = (${VALS} $2)
44 set FILE_NAME = "${FILE_NAME}$1."
45 set CLASS_NAME = "${CLASS_NAME}$1"
46
47 if (($2 != "ref") && ($2 != "val")) then
48 echo "${PROGRAM_NAME}: invalid reference type" ;
49 echo ${USAGE} ;
50 exit 1;
51 endif
52
53 shift;
54 shift;
55end
56
57set CLASS = $1
58
59set FILE_NAME = "${FILE_NAME}${CLASS}.${EXTNSN}"
60set CLASS_NAME = "${CLASS_NAME}${CLASS}"
61set HSRC = "$CLASS.hP"
62set SRC = "$CLASS.${EXTNSN}P"
63set OUT = "$OUTDIR$FILE_NAME"
64
65if ( (-f $PWD$SRC) && (-r $PWD$SRC) && (-f $PWD$HSRC) ) then
66 set PSRC = $PWD$SRC
67 set HSRC = $PWD$HSRC
68else if ( (-f $PROTODIR$SRC) && (-r $PROTODIR$SRC) && (-f $PROTODIR$HSRC) ) then
69 set PSRC = $PROTODIR$SRC
70 set HSRC = $PROTODIR$HSRC
71else
72 echo "${PROGRAM_NAME}: $SRC: no such file";
73 exit 1;
74endif
75
76set SEARCH_STRING = (generic class $CLASS\\\[.\*\\\])
77
78set SED_SCRIPT = /tmp/genclass.$$
79
80# this is so we can handle unreformed files from the distribution
81if (1) then
82 set TYPE_LIST = T
83 if ( $#TYPES == 2 ) set TYPE_LIST = (${TYPE_LIST} C)
84else
85 # get TYPE_LIST somehow... ???
86 set TEMP = "`grep $SEARCH_STRING $HSRC`"
87 set TYPE_LIST=(`expr $TEMP : \[^\\\[\]\*\\\[\(.*\)\\\].\* | tr ',' ' '`);
88 unset TEMP
89 echo "s/$SEARCH_STRING/class $CLASS_NAME/g" >> SED_SCRIPT
90endif
91
92set DUMMY=0
93while ( $DUMMY < $#TYPES )
94 @ DUMMY++
95 set PREAMBLE = 's/<';
96 set MIDDLE = '>/';
97 set POSTAMBLE = '/g';
98 echo ${PREAMBLE}${TYPE_LIST[$DUMMY]}${MIDDLE}${TYPES[$DUMMY]}${POSTAMBLE} >>$SED_SCRIPT
99
100 set MIDDLE = "&$MIDDLE"
101 if ($VALS[$DUMMY] == "ref") set POSTAMBLE = "\&$POSTAMBLE";
102
103 echo ${PREAMBLE}${TYPE_LIST[$DUMMY]}${MIDDLE}${TYPES[$DUMMY]}${POSTAMBLE} >>$SED_SCRIPT
104end
105
106sed -f $SED_SCRIPT < $PSRC > $OUT
107
108rm -f $SED_SCRIPT
109
110
111
112