Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zint/backend/tools/gen_iso4217_h.php @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 <?php | |
| 2 /* Generate ISO 4217 include "backend/iso4217.h" for "backend/gs1.c" */ | |
| 3 /* | |
| 4 libzint - the open source barcode library | |
| 5 Copyright (C) 2021-2024 <rstuart114@gmail.com> | |
| 6 */ | |
| 7 /* SPDX-License-Identifier: BSD-3-Clause */ | |
| 8 | |
| 9 /* To create "backend/iso4217.h" (from project directory): | |
| 10 * | |
| 11 * php backend/tools/gen_iso4217_h.php > backend/iso4217.h | |
| 12 */ | |
| 13 | |
| 14 $basename = basename(__FILE__); | |
| 15 $dirname = dirname(__FILE__); | |
| 16 $dirdirname = basename(dirname($dirname)) . '/' . basename($dirname); | |
| 17 | |
| 18 $opts = getopt('c:h:t:'); | |
| 19 | |
| 20 $print_copyright = isset($opts['c']) ? (bool) $opts['c'] : true; | |
| 21 $print_h_guard = isset($opts['h']) ? (bool) $opts['h'] : true; | |
| 22 $tab = isset($opts['t']) ? $opts['t'] : ' '; | |
| 23 | |
| 24 $numeric = array( | |
| 25 /*ALL*/ 8, /*DZD*/ 12, /*ARS*/ 32, /*AUD*/ 36, /*BSD*/ 44, /*BHD*/ 48, /*BDT*/ 50, /*AMD*/ 51, /*BBD*/ 52, /*BMD*/ 60, | |
| 26 /*BTN*/ 64, /*BOB*/ 68, /*BWP*/ 72, /*BZD*/ 84, /*SBD*/ 90, /*BND*/ 96, /*MMK*/ 104, /*BIF*/ 108, /*KHR*/ 116, /*CAD*/ 124, | |
| 27 /*CVE*/ 132, /*KYD*/ 136, /*LKR*/ 144, /*CLP*/ 152, /*CNY*/ 156, /*COP*/ 170, /*KMF*/ 174, /*CRC*/ 188, /*HRK*/ 191, /*CUP*/ 192, | |
| 28 /*CZK*/ 203, /*DKK*/ 208, /*DOP*/ 214, /*SVC*/ 222, /*ETB*/ 230, /*ERN*/ 232, /*FKP*/ 238, /*FJD*/ 242, /*DJF*/ 262, /*GMD*/ 270, | |
| 29 /*GIP*/ 292, /*GTQ*/ 320, /*GNF*/ 324, /*GYD*/ 328, /*HTG*/ 332, /*HNL*/ 340, /*HKD*/ 344, /*HUF*/ 348, /*ISK*/ 352, /*INR*/ 356, | |
| 30 /*IDR*/ 360, /*IRR*/ 364, /*IQD*/ 368, /*ILS*/ 376, /*JMD*/ 388, /*JPY*/ 392, /*KZT*/ 398, /*JOD*/ 400, /*KES*/ 404, /*KPW*/ 408, | |
| 31 /*KRW*/ 410, /*KWD*/ 414, /*KGS*/ 417, /*LAK*/ 418, /*LBP*/ 422, /*LSL*/ 426, /*LRD*/ 430, /*LYD*/ 434, /*MOP*/ 446, /*MWK*/ 454, | |
| 32 /*MYR*/ 458, /*MVR*/ 462, /*MUR*/ 480, /*MXN*/ 484, /*MNT*/ 496, /*MDL*/ 498, /*MAD*/ 504, /*OMR*/ 512, /*NAD*/ 516, /*NPR*/ 524, | |
| 33 /*ANG*/ 532, /*AWG*/ 533, /*VUV*/ 548, /*NZD*/ 554, /*NIO*/ 558, /*NGN*/ 566, /*NOK*/ 578, /*PKR*/ 586, /*PAB*/ 590, /*PGK*/ 598, | |
| 34 /*PYG*/ 600, /*PEN*/ 604, /*PHP*/ 608, /*QAR*/ 634, /*RUB*/ 643, /*RWF*/ 646, /*SHP*/ 654, /*SAR*/ 682, /*SCR*/ 690, /*SLL*/ 694, | |
| 35 /*SGD*/ 702, /*VND*/ 704, /*SOS*/ 706, /*ZAR*/ 710, /*SSP*/ 728, /*SZL*/ 748, /*SEK*/ 752, /*CHF*/ 756, /*SYP*/ 760, /*THB*/ 764, | |
| 36 /*TOP*/ 776, /*TTD*/ 780, /*AED*/ 784, /*TND*/ 788, /*UGX*/ 800, /*MKD*/ 807, /*EGP*/ 818, /*GBP*/ 826, /*TZS*/ 834, /*USD*/ 840, | |
| 37 /*UYU*/ 858, /*UZS*/ 860, /*WST*/ 882, /*YER*/ 886, /*TWD*/ 901, /*ZWG*/ 924, /*SLE*/ 925, /*UYW*/ 927, /*VES*/ 928, /*MRU*/ 929, | |
| 38 /*STN*/ 930, /*CUC*/ 931, /*ZWL*/ 932, /* TODO: remove 1 Sept 2024 */ | |
| 39 /*BYN*/ 933, /*TMT*/ 934, /*GHS*/ 936, /*SDG*/ 938, /*UYI*/ 940, /*RSD*/ 941, /*MZN*/ 943, /*AZN*/ 944, | |
| 40 /*RON*/ 946, /*CHE*/ 947, /*CHW*/ 948, /*TRY*/ 949, /*XAF*/ 950, /*XCD*/ 951, /*XOF*/ 952, /*XPF*/ 953, /*XBA*/ 955, /*XBB*/ 956, | |
| 41 /*XBC*/ 957, /*XBD*/ 958, /*XAU*/ 959, /*XDR*/ 960, /*XAG*/ 961, /*XPT*/ 962, /*XTS*/ 963, /*XPD*/ 964, /*XUA*/ 965, /*ZMW*/ 967, | |
| 42 /*SRD*/ 968, /*MGA*/ 969, /*COU*/ 970, /*AFN*/ 971, /*TJS*/ 972, /*AOA*/ 973, /*BGN*/ 975, /*CDF*/ 976, /*BAM*/ 977, /*EUR*/ 978, | |
| 43 /*MXV*/ 979, /*UAH*/ 980, /*GEL*/ 981, /*BOV*/ 984, /*PLN*/ 985, /*BRL*/ 986, /*CLF*/ 990, /*XSU*/ 994, /*USN*/ 997, /*XXX*/ 999, | |
| 44 ); | |
| 45 | |
| 46 $numeric_tab = array(); | |
| 47 $val = 0; | |
| 48 $byte = 0; | |
| 49 $max = $numeric[count($numeric) - 1]; | |
| 50 for ($i = 0; $i <= $max; $i++) { | |
| 51 if ($i && $i % 8 == 0) { | |
| 52 $numeric_tab[$byte++] = $val; | |
| 53 $val = 0; | |
| 54 } | |
| 55 if (in_array($i, $numeric)) { | |
| 56 $val |= 1 << ($i & 0x7); | |
| 57 } | |
| 58 } | |
| 59 $numeric_tab[$byte++] = $val; | |
| 60 $numeric_cnt = count($numeric_tab); | |
| 61 | |
| 62 print <<<EOD | |
| 63 /* | |
| 64 * ISO 4217 currency codes generated by "$dirdirname/$basename" | |
| 65 */ | |
| 66 | |
| 67 EOD; | |
| 68 | |
| 69 if ($print_copyright) { | |
| 70 print <<<'EOD' | |
| 71 /* | |
| 72 libzint - the open source barcode library | |
| 73 Copyright (C) 2021-2024 Robin Stuart <rstuart114@gmail.com> | |
| 74 | |
| 75 Redistribution and use in source and binary forms, with or without | |
| 76 modification, are permitted provided that the following conditions | |
| 77 are met: | |
| 78 | |
| 79 1. Redistributions of source code must retain the above copyright | |
| 80 notice, this list of conditions and the following disclaimer. | |
| 81 2. Redistributions in binary form must reproduce the above copyright | |
| 82 notice, this list of conditions and the following disclaimer in the | |
| 83 documentation and/or other materials provided with the distribution. | |
| 84 3. Neither the name of the project nor the names of its contributors | |
| 85 may be used to endorse or promote products derived from this software | |
| 86 without specific prior written permission. | |
| 87 | |
| 88 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 89 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 90 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 91 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
| 92 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 93 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 94 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 95 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 96 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 97 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 98 SUCH DAMAGE. | |
| 99 */ | |
| 100 /* SPDX-License-Identifier: BSD-3-Clause */ | |
| 101 | |
| 102 | |
| 103 EOD; | |
| 104 } | |
| 105 | |
| 106 if ($print_h_guard) { | |
| 107 print <<<'EOD' | |
| 108 #ifndef Z_ISO4217_H | |
| 109 #define Z_ISO4217_H | |
| 110 | |
| 111 EOD; | |
| 112 } | |
| 113 | |
| 114 print <<<EOD | |
| 115 | |
| 116 /* Whether ISO 4217-1 numeric */ | |
| 117 static int iso4217_numeric(int cc) { | |
| 118 {$tab}static const unsigned char codes[$numeric_cnt] = { | |
| 119 EOD; | |
| 120 | |
| 121 for ($i = 0; $i < $numeric_cnt; $i++) { | |
| 122 if ($i % 8 == 0) { | |
| 123 print "\n$tab$tab"; | |
| 124 } else { | |
| 125 print " "; | |
| 126 } | |
| 127 printf("0x%02X,", $numeric_tab[$i]); | |
| 128 } | |
| 129 print <<<EOD | |
| 130 | |
| 131 {$tab}}; | |
| 132 {$tab}int b = cc >> 3; | |
| 133 | |
| 134 {$tab}if (b < 0 || b >= $numeric_cnt) { | |
| 135 {$tab}{$tab}return 0; | |
| 136 {$tab}} | |
| 137 {$tab}return codes[b] & (1 << (cc & 0x7)) ? 1 : 0; | |
| 138 } | |
| 139 | |
| 140 EOD; | |
| 141 | |
| 142 if ($print_h_guard) { | |
| 143 print <<<'EOD' | |
| 144 | |
| 145 #endif /* Z_ISO4217_H */ | |
| 146 | |
| 147 EOD; | |
| 148 } | |
| 149 | |
| 150 /* vim: set ts=4 sw=4 et : */ |
