3 # openisis - an open implementation of the CDS/ISIS database
4 # Version 0.8.x (patchlevel see file Version)
5 # Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # see README for more information
24 # $Id: oipc,v 1.2 2003/04/08 00:20:53 kripke Exp $
27 # ./oipc foo.oip gcc %o && ./a.out
28 # ./oipc foo.oip gcc %o -shared -o foo.oip.so && ./oipl $PWD/foo.oip.so
33 my $ofile = $ifile . '.c';
34 my $buf = ''; # collected strings from output mode
35 my @code = ('',''); # main and global code
36 my $code = 0, $state = -1;
38 # 0: stuff to output literally
45 die "could not read $ifile" unless open I, $ifile;
46 # transform line by line
48 if ( -1 == $state ) { # skipping initial # lines
50 $state = 0; # switch to output state
53 if ( ! $state ) { # output up to <%
54 my ($o,$s,$m,$x) = /^(.*?)(<%([=!@])?(.*))?$/s;
59 $buf .= '"' . $o . '"';
61 $buf .= '"' . $o . '\n"' . "\n";
64 next LIN unless defined $s;
65 $code[$code] .= "\tOIPS(\n".$buf."\t);\n" if length $buf;
67 ($m ||= 0) =~ y/=!@/123/;
69 $code = 2 < $state ? 1 : 0;
71 $code[$code] .= "\n#line ".$.."\n";
72 next LIN unless length $x;
74 my ($x,$s,$m,$o) = /^(.*?)((!)?%>(.*))?$/s;
77 if ( 2 == $state ) { # <%=
78 if ( 1 == length $buf ) {
79 if ( $buf =~ /[i-n]/ ) { # integer shorthand
81 } elsif ( $buf =~ /[u-w]/ ) { # unsigned shorthand
83 } elsif ( $buf =~ /[f-h]/ ) { # OpenIsis Field shorthand
84 $buf = '"%.*s",'.$buf.'->len,'.$buf.'->val';
87 if ( $buf =~ /^\s*"/ ) {
88 $buf = 'OIPP(OIPF,'.$buf.');';
90 $buf = 'OIPS('.$buf.');';
94 # don't reset print code destination if global ends with !%>
95 $code = 0 unless $code && defined $m;
110 $code[0] .= "OIPS(\n".$buf.");\n" if length $buf;
111 die "could not write $ofile" unless open O, '>', $ofile;
112 print O '#include "oip.h"',"\n";
118 map s/%o/$ofile/, @_;
119 die 'exec '.join(' ',@_)." failed\n" unless exec @_;