1 | #!/usr/local/bin/perl |
---|
2 | |
---|
3 | ### |
---|
4 | ### makeheader - generate a header file out of several header file (ver 1.1) |
---|
5 | ### |
---|
6 | |
---|
7 | if ( ( $#ARGV == 0 ) && ( $ARGV[0] eq '-help' ) ) { |
---|
8 | die "\nThis is makeheader, a header file generation tool.\n\n" . |
---|
9 | " with makeheader it is possible to generate a single header\n" . |
---|
10 | " file out of several other header files\n" . |
---|
11 | " the parts to be included in the generated header file have\n" . |
---|
12 | " to be marked with /*BEGINPUBLIC*/ and /*ENDPUBLIC*/\n" . |
---|
13 | " to include a header file into the generated header file use\n" . |
---|
14 | " the command .INCLUDE name.h on a single line\n\n" . |
---|
15 | "usage: makeheader <template> <outfile>\n\n"; |
---|
16 | } |
---|
17 | |
---|
18 | if ( $#ARGV < 1 ) { |
---|
19 | die "usage: makeheader <template> <outfile>\n\n"; |
---|
20 | } |
---|
21 | |
---|
22 | $infile = shift( @ARGV ); |
---|
23 | $outfile = shift( @ARGV ); |
---|
24 | |
---|
25 | open( INFILE, $infile ) || |
---|
26 | die "makeheader: can not open template file $infile for reading!\n"; |
---|
27 | open( OUTFILE, ">$outfile" ) || |
---|
28 | die "makeheader: can not open header file $outfile for writing!\n"; |
---|
29 | |
---|
30 | while( $currentline = <INFILE> ) { |
---|
31 | if ( index( $currentline, ".INCLUDE" ) == 0 ) { |
---|
32 | $currentline =~ s/.INCLUDE //; |
---|
33 | open( INCLFILE, $currentline ) || |
---|
34 | die "can not open included file '$currentline' for reading!\n"; |
---|
35 | while ( $inclline = <INCLFILE> ) { |
---|
36 | if ( index( $inclline, "/*BEGINPUBLIC*/" ) >= 0 ) { |
---|
37 | while (( $inclline = <INCLFILE> ) && |
---|
38 | ( index( $inclline, "/*ENDPUBLIC*/" ) < 0 )) { |
---|
39 | print OUTFILE $inclline; |
---|
40 | } |
---|
41 | } |
---|
42 | } |
---|
43 | } |
---|
44 | else { |
---|
45 | print OUTFILE $currentline; |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | close OUTFILE; |
---|
50 | close INFILE; |
---|
51 | |
---|