source: git/MP/MP/makeheader.pl @ 1d0eb7

fieker-DuValspielwiese
Last change on this file since 1d0eb7 was ba65c4, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: MP/makeheader.pl' generated comment does not contain a date any more git-svn-id: file:///usr/local/Singular/svn/trunk@478 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 2.9 KB
Line 
1#!/usr/bin/perl
2# $Id: makeheader.pl,v 1.2 1997-07-01 15:21:53 Singular Exp $
3#
4# makeheader.pl - generate a header file out of several header file (ver 1.2).
5#
6
7#
8# searchpath - search a file in a path and return full path.
9#
10sub searchpath {
11    local ( $file, $path ) = @_;
12    for ( split ( /:/, $path ) ) {
13        if ( -f "$_/$file" ) {
14            return "$_/$file";
15        }
16    }
17    return "";
18}
19       
20if ( ( $#ARGV == -1 ) || ( $ARGV[0] =~ /-help|-\?/ ) ) {
21    die "
22usage: makeheader [-?] {-I<includedir>} <templatefile> <outfile>
23
24This is makeheader, a header file generation tool.
25With makeheader it is possible to generate a single header
26file out of several other header files.
27
28To include a header file into the generated header file
29\(= <outfile>) use the two lines
30
31/*MAKEHEADER*/
32#include \"<includefile>\"
33
34in <templatefile>.
35
36If you use the alternate form
37
38/*MAKEHEADER PUBLIC ONLY*/
39#include \"<includefile>\"
40
41only sections marked with /*BEGINPUBLIC*/ and /*ENDPUBLIC*/ are
42pasted from <includefile> into <outfile>.
43
44<includefile> is looked up in all <includedir>s, then in the
45current directory, then in the base directory of
46<templatefile>.\n";
47}
48
49# get list of include directories
50$includes = "";
51while ( $ARGV[0] =~ /^-/ ) {
52    $_ = shift;
53    if ( /^-I(.*)/ ) {
54        $includes .= ( $1 ? $1 : shift ) . ":";
55    }
56}
57$includes .= ".:";
58
59# check for rest of arguments
60if ( $#ARGV < 1 ) {
61    die "usage: makeheader [-?] {-I<includedir>} <templatefile> <outfile>\n\n";
62}
63
64$infile = shift( @ARGV );
65$outfile = shift( @ARGV );
66if ( $infile =~ /(.*)\// ) {
67    $includes .= "$1:";
68}
69
70open( INFILE, $infile ) || 
71    die "makeheader: Can not open template file $infile for reading!\n";
72open( OUTFILE, ">$outfile" ) ||
73    die "makeheader: Can not open header file $outfile for writing!\n";
74
75print OUTFILE "\n/* $outfile automatically generated by $0 " . "*/\n";
76
77while( <INFILE> ) {
78    if ( /^\/\*MAKEHEADER(.*)\*\/$/ ) {
79        # check whether we have to read public part only
80        if ( $1 eq " PUBLIC ONLY" ) {
81            $public_only = 1;
82        } else {
83            $public_only = 0;
84        }
85
86        # get name of file to include
87        $_ = <INFILE>; chop;
88        if ( /^\#include \"(.*)\"$/ ) {
89            $inclfile = $1;
90        } else {
91            die "makeheader: $_ is not a valid include directive!\n";
92        }
93
94        $inclfile = &searchpath( $inclfile, $includes ) ||
95            die "makeheader: Can not open included file $inclfile for reading!\n";
96        open( INCLFILE, $inclfile ) ||
97            die "makeheader: Can not open included file $inclfile for reading!\n";
98
99        print OUTFILE "\n/* Stuff included from $inclfile */\n";
100        if ( $public_only ) {
101            # read public part only
102            while ( <INCLFILE> ) {
103                if ( /^\/\*BEGINPUBLIC\*\/$/ ) {
104                    while ( <INCLFILE> ) {
105                        last if ( /^\/\*ENDPUBLIC\*\/$/ );
106                        print OUTFILE $_;
107                    }
108                }
109            }
110        } else {
111            # just paste contents into output
112            while ( <INCLFILE> ) { print OUTFILE $_; }
113        }
114        close INCLFILE;
115    }
116    else {
117        print OUTFILE $_;
118    }
119}
120
121close OUTFILE;
122close INFILE;
Note: See TracBrowser for help on using the repository browser.