blob: 51ea9b97a84f78f1340ab79e458942fe6fab44df [file] [log] [blame]
Thomas Klausner1697b891999-07-25 21:09:03 +00001#!/bin/sh
2
Dieter Baron775c2592004-04-25 16:20:16 +00003# make_zip_err_str.sh: create zip_err_str.c from zip.h
Dieter Baron8bc12762007-08-22 13:39:13 +02004# Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
Dieter Baron775c2592004-04-25 16:20:16 +00005#
6# This file is part of libzip, a library to manipulate ZIP archives.
Dieter Baronb86c4332007-11-07 14:35:13 +01007# The authors can be contacted at <libzip@nih.at>
Dieter Baron775c2592004-04-25 16:20:16 +00008#
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
Thomas Klausner1697b891999-07-25 21:09:03 +000035if [ "$#" -ne 2 ]
36then
Dieter Baronb10b8ab1999-07-25 22:51:30 +000037 echo "Usage: $0 in_file out_file" >&2
38 echo " e.g. $0 zip.h zip_err_str.c" >&2
Thomas Klausner1697b891999-07-25 21:09:03 +000039 exit 1
40fi
41
42if [ "$1" = "$2" ]
43then
Dieter Baronb10b8ab1999-07-25 22:51:30 +000044 echo "$0: error: output file = input file" >&2
Thomas Klausner1697b891999-07-25 21:09:03 +000045 exit 1
46fi
47
Dieter Baronb10b8ab1999-07-25 22:51:30 +000048cat <<EOF >> "$2.$$" || exit 1
Dieter Baron775c2592004-04-25 16:20:16 +000049/*
50 This file was generated automatically by $0
51 from $1; make changes there.
Dieter Baron775c2592004-04-25 16:20:16 +000052 */
Thomas Klausner1697b891999-07-25 21:09:03 +000053
Dieter Baron5149dfb2003-10-05 16:05:25 +000054#include "zipint.h"
Dieter Baronb10b8ab1999-07-25 22:51:30 +000055
56
57
Dieter Barone3f91ef2003-10-06 02:50:14 +000058const char * const _zip_err_str[] = {
Dieter Baronb10b8ab1999-07-25 22:51:30 +000059EOF
60
Thomas Klausnerd0147e92004-11-17 21:55:17 +000061sed -n '/^#define ZIP_ER_/ s/.*\/\* . \([^*]*\) \*\// "\1",/p' "$1" \
Dieter Baronb10b8ab1999-07-25 22:51:30 +000062 >> "$2.$$" || exit 1
Dieter Baron5149dfb2003-10-05 16:05:25 +000063
64cat <<EOF >> "$2.$$" || exit 1
65};
66
Dieter Barone3f91ef2003-10-06 02:50:14 +000067const int _zip_nerr_str = sizeof(_zip_err_str)/sizeof(_zip_err_str[0]);
Dieter Baron5149dfb2003-10-05 16:05:25 +000068
69#define N ZIP_ET_NONE
70#define S ZIP_ET_SYS
Thomas Klausnerd0147e92004-11-17 21:55:17 +000071#define Z ZIP_ET_ZLIB
Dieter Baron5149dfb2003-10-05 16:05:25 +000072
73const int _zip_err_type[] = {
74EOF
75
Thomas Klausnerd0147e92004-11-17 21:55:17 +000076sed -n '/^#define ZIP_ER_/ s/.*\/\* \(.\) \([^*]*\) \*\// \1,/p' "$1" \
Dieter Baron5149dfb2003-10-05 16:05:25 +000077 >> "$2.$$" || exit 1
78
Dieter Baronb10b8ab1999-07-25 22:51:30 +000079echo '};' >> "$2.$$" || exit 1
80
81mv "$2.$$" "$2" || exit 1