source: git/omalloc/makeheader @ 6e9d845

spielwiese
Last change on this file since 6e9d845 was 6e9d845, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: makeheader.pl ->makeheader (.pl does not work for windows) git-svn-id: file:///usr/local/Singular/svn/trunk@8468 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 3.3 KB
Line 
1#! /bin/sh
2# $Id: makeheader,v 1.1 2005-07-28 15:02:28 Singular Exp $
3
4#
5# makeheader.sh - generate a header file out of several header files.
6#
7# Type 'makeheader -?' for instructions on syntax/usage.
8#
9
10# print usage if necessary
11if test "$#" = 0 || test "$1" = "-?" || test "$1" = "-help"; then
12    cat 1>&2 << \EOT
13usage: makeheader [-?] {-I<includedir>} <templatefile> <outfile>
14
15This is makeheader, a header file generation tool.
16With makeheader it is possible to generate a single header
17file out of several other header files.
18
19To include a header file into the generated header file
20(= <outfile>) use the two lines
21
22/*MAKEHEADER*/
23#include "<includefile>"
24
25in <templatefile>.
26
27If you use the alternate form
28
29/*MAKEHEADER PUBLIC ONLY*/
30#include "<includefile>"
31
32only sections marked with /*BEGINPUBLIC*/ and /*ENDPUBLIC*/ are
33pasted from <includefile> into <outfile>.
34
35<includefile> is looked up in all <includedir>s, then in the
36current directory, then in the base directory of <templatefile>.
37EOT
38    exit 1
39fi
40
41# get list of include directories
42includes=""
43while echo "$1" | grep '^-I' > /dev/null 2> /dev/null; do
44    # get argument to option -I
45    if test "$1" = "-I"; then
46        shift
47        includes="$includes$1:"
48    else
49        include=`echo "$1" | sed 's/^-I//'`
50        includes="$includes$include:"
51    fi
52    shift
53done
54includes="$includes.:"
55
56# check for rest of arguments
57if test "$#" -lt 2; then
58    echo "usage: makeheader [-?] {-I<includedir>} <templatefile> <outfile>" 1>&2
59    exit 1
60fi
61
62infile="$1"
63outfile="$2"
64
65# get basename of $infile
66if echo "$infile" | grep '.*/' > /dev/null 2> /dev/null; then
67    include=`echo "$infile" | sed 's/\/[^\/]*$//'`
68    includes="$includes$include:"
69fi
70
71if test ! -r "$infile"; then
72    echo "makeheader: Cannot open template file $infile for reading" 1>&2
73    exit 1
74fi
75   
76# try to create $outfile if it does not exist
77if test -w "$outfile" || cp /dev/null "$outfile" > /dev/null 2> /dev/null; then
78    :
79else
80    echo "makeheader: Cannot open header file $outfile for writing" 1>&2
81    exit 1
82fi
83
84echo "/* $outfile automatically generated by makeheader from $infile */" > "$outfile"
85
86# scan through template
87while read line; do
88    if test "$line" = '/*MAKEHEADER*/'; then
89        readmode=1
90    elif test "$line" = '/*MAKEHEADER PUBLIC ONLY*/'; then
91        readmode=2
92    else
93        echo "$line"
94        continue
95    fi
96
97    # get include file from next line
98    read line
99    if echo "$line" | grep -v '^#include ".*"$' > /dev/null 2> /dev/null; then
100        echo "makeheader: Invalid include statement $line" 1>&2
101        exit 1
102    fi
103    includefile=`echo "$line" | sed 's/^#include "//; s/"$//'`
104
105    # search for includefile
106    found=0
107    saveIFS="$IFS"; IFS=:
108    for dir in $includes; do
109        if test -r "$dir/$includefile"; then
110            found=1
111            break
112        fi
113    done
114    IFS="$saveIFS"
115
116    if test $found = 0; then
117        echo "makeheader: Include file $includefile not found" 1>&2
118        exit 1
119    else
120        includefile="$dir/$includefile"
121    fi
122
123    # now paste includefile into outfile
124    echo "/* stuff included from $includefile */"
125    echo
126    if test $readmode = 1; then
127        # read whole includefile
128        cat "$includefile"
129    elif test $readmode = 2; then
130        # read only public sections of includefile
131        sed -n '
132          \@^/\*BEGINPUBLIC\*/$@!d
133          \@^/\*BEGINPUBLIC\*/$@{
134            : loop
135            n
136            \@^/\*ENDPUBLIC\*/$@d
137            p
138            b loop
139          }' "$includefile"
140    fi
141
142done < "$infile" >> "$outfile"
Note: See TracBrowser for help on using the repository browser.