-
Notifications
You must be signed in to change notification settings - Fork 377
/
Copy pathgmt_make_enum_dicts.sh
executable file
·79 lines (70 loc) · 2.98 KB
/
gmt_make_enum_dicts.sh
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
#!/usr/bin/env bash
#--------------------------------------------------------------------
#
# Copyright (c) 1991-2025 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
# See LICENSE.TXT file for copying and redistribution conditions.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 3 or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# Contact info: www.generic-mapping-tools.org
#--------------------------------------------------------------------
#
# This script just makes the include snippet gmt_enum_dict.h
# needed for GMT_API_Enum () to work.
#
# Set LC_ALL to get the same sort order on Linux and macOS
export LC_ALL=C
# Set temporary directory
TMPDIR=${TMPDIR:-/tmp}
egrep -v '^struct|^union|^enum|_GMT|^#define|^char' gmt_resources.h | tr ',' ' ' | awk '{if (substr($1,1,4) == "GMT_") print $1, $3}' > ${TMPDIR}/junk1.txt
grep -v GMT_OPT_ ${TMPDIR}/junk1.txt > ${TMPDIR}/junk2.txt
grep GMT_OPT_ ${TMPDIR}/junk1.txt | awk '{print $1, substr($2,1,2)} '> ${TMPDIR}/junk3.txt
while read key value; do
printf "%s %d\n" $key "$value" >> ${TMPDIR}/junk2.txt
done < ${TMPDIR}/junk3.txt
n=$(wc -l < ${TMPDIR}/junk2.txt | awk '{printf "%d\n", $1}')
COPY_YEAR=$(date +%Y)
cat << EOF > gmt_enum_dict.h
/*--------------------------------------------------------------------
*
* Copyright (c) 1991-$COPY_YEAR by the GMT Team (https://www.generic-mapping-tools.org/team.html)
* See LICENSE.TXT file for copying and redistribution conditions.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3 or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Contact info: www.generic-mapping-tools.org
*--------------------------------------------------------------------*/
/*
* Include file for getting GMT API enum codes programmatically via GMT_Get_Enum ()
* Rerun gmt_make_enum_dicts.sh after adding or changing enums.
*
* Author: Paul Wessel
* Version: 6 API
*/
struct GMT_API_DICT {
char name[32];
int value;
};
#define GMT_N_API_ENUMS $n
static struct GMT_API_DICT gmt_api_enums[GMT_N_API_ENUMS] = {
EOF
sort -k 1 ${TMPDIR}/junk2.txt | awk '{printf "\t{\"%s\", %d},\n", $1, $2}' >> gmt_enum_dict.h
cat << EOF >> gmt_enum_dict.h
};
EOF
printf "gmt_make_enum_dicts.sh: Found %d enums set in gmt_resources.h. Updated gmt_enum_dict.h\n" $n
rm -f ${TMPDIR}/junk?.txt