"Fossies" - the Fresh Open Source Software Archive

Member "libzip-1.5.2/lib/make_zipconf.sh" (12 Mar 2019, 4310 Bytes) of package /linux/misc/libzip-1.5.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 #  make_zipconf.sh: create platform specific include file zipconf.h
    4 #  Copyright (C) 1999-2011 Dieter Baron and Thomas Klausner
    5 #
    6 #  This file is part of libzip, a library to manipulate ZIP archives.
    7 #  The authors can be contacted at <libzip@nih.at>
    8 #
    9 #  Redistribution and use in source and binary forms, with or without
   10 #  modification, are permitted provided that the following conditions
   11 #  are met:
   12 #  1. Redistributions of source code must retain the above copyright
   13 #     notice, this list of conditions and the following disclaimer.
   14 #  2. Redistributions in binary form must reproduce the above copyright
   15 #     notice, this list of conditions and the following disclaimer in
   16 #     the documentation and/or other materials provided with the
   17 #     distribution.
   18 #  3. The names of the authors may not be used to endorse or promote
   19 #     products derived from this software without specific prior
   20 #     written permission.
   21 # 
   22 #  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
   23 #  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   24 #  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   25 #  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
   26 #  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   27 #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   28 #  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   29 #  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
   30 #  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   31 #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   32 #  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   33 
   34 
   35 set -e
   36 
   37 define_type()
   38 {
   39     short=$1
   40     long=$2
   41     bytes=$3
   42     infile="$4"
   43     outfile="$5"
   44 
   45     bits=`expr $bytes '*' 8`
   46     type="${short}int${bits}"
   47     TYPE=`echo $type | tr '[a-z]' '[A-Z]'`
   48     if grep "define HAVE_${TYPE}_T" "$infile" > /dev/null
   49     then
   50     echo "typedef ${type}_t zip_${type}_t;" >> "$outfile"
   51     LTYPE="$TYPE"
   52     else
   53     SHORT=`echo $short | tr '[a-z]' '[A-Z]'`
   54     if [ -z "$SHORT" ]
   55     then
   56         SHORT='S'
   57     fi
   58     if [ "$bytes" -eq 1 ]
   59     then
   60         if [ -z "$long" ]
   61         then
   62         long='signed'
   63         fi
   64         echo "typedef $long char ${type}_t;" >> $outfile
   65         LTYPE="${SHORT}CHAR"
   66     else
   67         ctype=`sed -n "s/.define SIZEOF_\([A-Z_]*\) $bytes/\1/p" "$infile" \
   68         | head -1 | tr '[A-Z_]' '[a-z ]'`
   69         if [ -z "$ctype" ]
   70         then
   71         echo "$0: no $bits bit type found" >&2
   72         exit 1
   73         fi
   74         echo "typedef $long $ctype ${type}_t;" >> "$outfile"
   75         case "$ctype" in
   76         short) LTYPE=${SHORT}SHRT;;
   77         int) LTYPE=${SHORT}INT;;
   78                 long) LTYPE=${SHORT}LONG;;
   79         "long long") LTYPE=${SHORT}LLONG;;
   80             esac
   81     fi
   82     fi
   83 
   84     if [ -z "$long" ]
   85     then
   86     echo "#define ZIP_${TYPE}_MIN ${LTYPE}_MIN" >> "$outfile"
   87     fi
   88     echo "#define ZIP_${TYPE}_MAX ${LTYPE}_MAX" >> "$outfile"
   89     echo >> "$outfile"
   90 }
   91 
   92 
   93 if [ "$#" -ne 2 ]
   94 then
   95     echo "Usage: $0 config_h_file out_file" >&2
   96     echo "       e.g. $0 ../config.h zip_err_str.c" >&2
   97     exit 1
   98 fi
   99 
  100 if [ "$1" = "$2" ]
  101 then
  102     echo "$0: error: output file = input file" >&2
  103     exit 1
  104 fi
  105 
  106 cat <<EOF > "$2.$$"
  107 #ifndef _HAD_ZIPCONF_H
  108 #define _HAD_ZIPCONF_H
  109 
  110 /*
  111    zipconf.h -- platform specific include file
  112 
  113    This file was generated automatically by $0
  114    based on $1.
  115  */
  116 
  117 EOF
  118 
  119 version=`sed -n 's/^#define VERSION "\(.*\)"/\1/p' "$1"`
  120 
  121 version_major=`expr "$version" : '^\([0-9]*\)' || true`
  122 version_minor=`expr "$version" : '^[0-9]*\.\([0-9]*\)' || true`
  123 version_micro=`expr "$version" : '^[0-9]*\.[0-9]\.\([0-9]*\)' || true`
  124 
  125 if [ -z "$version_major" ]
  126 then
  127     version_major=0
  128 fi
  129 if [ -z "$version_minor" ]
  130 then
  131     version_minor=0
  132 fi
  133 if [ -z "$version_micro" ]
  134 then
  135     version_micro=0
  136 fi
  137 
  138 cat <<EOF >> "$2.$$"
  139 #define LIBZIP_VERSION "$version"
  140 #define LIBZIP_VERSION_MAJOR $version_major
  141 #define LIBZIP_VERSION_MINOR $version_minor
  142 #define LIBZIP_VERSION_MICRO $version_micro
  143 
  144 EOF
  145 
  146 if grep 'define HAVE_INTTYPES_H' "$1" > /dev/null
  147 then
  148     echo '#include <inttypes.h>' >> "$2.$$"
  149 else
  150     echo '#include <limits.h>' >> "$2.$$"
  151 fi
  152 echo >> "$2.$$"
  153 
  154 for size in 1 2 4 8
  155 do
  156     define_type '' '' $size "$1" "$2.$$"
  157     define_type u unsigned $size "$1" "$2.$$"
  158 done
  159 
  160 echo >> "$2.$$"
  161 echo '#endif /* zipconf.h */' >> "$2.$$"
  162 
  163 mv "$2.$$" "$2"