File: genparser

package info (click to toggle)
libhdf4 4.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,384 kB
  • sloc: ansic: 128,700; sh: 15,015; fortran: 12,444; java: 5,863; xml: 1,205; makefile: 794; yacc: 678; pascal: 418; perl: 360; javascript: 203; lex: 163; csh: 41
file content (162 lines) | stat: -rwxr-xr-x 4,810 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF.  The full HDF copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the COPYING file, which can be found at the root of the source code
# distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
#

# This script runs flex/lex and bison/yacc to generate parser code for
# the mfhdf code.
#
# NOTE CAREFULLY!
#
# There is NO dependency in either the autotools or CMake to regenerate
# the parser code. If you modify ncgen.l or ncgen.y, you will need to run
# this script manually on a system with a suitable lexer and parser generator.
#
# IMPORTANT OS X NOTE
#
# If you are using OS X, you will probably not have flex or bison
# installed. In addition, even if you do have bison installed, the bison
# version you have installed may also have a bug that makes it unable to
# process our input files.
#
# The easiest way to fix this is to install everything via Homebrew:
#
#   http://brew.sh/
#
# After you install the base packages, install flex/bison.
#
#   brew install flex
#   brew install bison
#
# END IMPORTANT OS X NOTE
#
# If you want to use a particular version of flex or bison, the paths
# to each tool can be overridden using the following environment
# variables:
#
#   HDF_FLEX
#   HDF_BISON
#
# This script takes one option:
#
# -v
#
# This emits some extra information, mainly tool versions.

echo
echo "***************************************"
echo "* HDF4 NetCDF parser generator script *"
echo "***************************************"
echo

# Default is not verbose output
verbose=false

optspec=":hpv-"
while getopts "$optspec" optchar; do
    case "${optchar}" in
    h)
        echo "usage: $0 [OPTIONS] /path/to/ncgen/directory"
        echo
        echo "      -h      Print this help message."
        echo
        echo "      -v      Show more verbose output."
        echo
        echo "  NOTE: Each tool can be set via an environment variable."
        echo "        These are documented inside this script."
        echo
        exit 0
        ;;
    v)
        echo "Setting verbosity: high"
        echo
        verbose=true
        ;;
    *)
        if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
            echo "Non-option argument: '-${OPTARG}'" >&2
        fi
        ;;
    esac
done

# Get the path to the ncgen directory
shift $(($OPTIND - 1))
path_to_ncgen_src=$1
if test -z ${path_to_ncgen_src}; then
    echo "*** ERROR *** - Path to mfhdf/ncgen not set"
    echo "Please add the path to the mfhdf/ncgen directory as a parameter"
    echo "See $0 -h for more help."
    echo
    exit -1
fi

# If paths to autotools are not specified, use whatever the system
# has installed as the default. We use 'which <tool>' to
# show exactly what's being used.
if test -z ${HDF_BISON}; then
    HDF_BISON="$(command -v bison)"
fi
if test -z ${HDF_FLEX}; then
    HDF_FLEX="$(command -v flex)"
fi

# Make sure that these versions of the tools are in the path
BISON_DIR=`dirname ${HDF_BISON}`
FLEX_DIR=`dirname ${HDF_FLEX}`
PATH=${FLEX_DIR}:${BISON_DIR}:$PATH

# Run flex and bison
# automatically generates mfhdf/ncgen/ncgenyy.c and mfhdf/ncgen/ncgentab.c
# Note that, as of Xcode 6.1 (2015), the default bison version on OS X
# is old enough to have the circular dependency bug. You'll have
# to install a later version of bison. See the OS X note at the top
# of this script.
echo
echo "Generating ncgen parser code (requires yacc/bison):"
echo "Generate mfhdf/ncgen/ncgenyy.c from mfhdf/ncgen/ncgen.y"
# HDF_BISON is set via the environment or 'command -v bison', above
if test -z ${HDF_BISON}; then
    echo
    echo "*************************"
    echo " ERROR - bison not found"
    echo "*************************"
    echo "bison is required to generate parser code in mfhdf/ncgen"
    echo
    exit 127
fi
if [ "$verbose" = true ] ; then
    ${HDF_BISON} --version
fi
${HDF_BISON} -o ${path_to_ncgen_src}/ncgentab.c -d ${path_to_ncgen_src}/ncgen.y

echo
echo "Generating ncgen lexer code (requires lex/flex):"
echo "Generate mfhdf/ncgen/ncgentab.c from mfhdf/ncgen/ncgen.l"
# HDF_FLEX is set via the environment or 'command -v flex', above
if test -z ${HDF_FLEX}; then
    echo
    echo "************************"
    echo " ERROR - flex not found"
    echo "************************"
    echo "flex is required to generate lexer code in mfhdf/ncgen"
    echo
    exit 127
fi
if [ "$verbose" = true ] ; then
    ${HDF_FLEX} --version
fi
${HDF_FLEX} --nounistd -o ${path_to_ncgen_src}/ncgenyy.c ${path_to_ncgen_src}/ncgen.l

echo
exit 0