mdnconv.c revision 04bdb234571448ed6194e1d4048e6512f2446f1c
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updaterstatic char *rcsid = "$Id: mdnconv.c,v 1.19 2000/09/13 05:55:55 ishisone Exp $";
803b50652fd6ad81d04d18fc04332c8a94f8fe9aAndreas Gustafsson * Copyright (c) 2000 Japan Network Information Center. All rights reserved.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * By using this file, you agree to the terms and conditions set forth bellow.
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * LICENSE TERMS AND CONDITIONS
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * The following License Terms and Conditions apply, unless a different
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * license is obtained from Japan Network Information Center ("JPNIC"),
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * a Japanese association, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
8a66318e41ed14c5a88130e8c362610e8faa2121Mark Andrews * Tokyo, Japan.
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater * 1. Use, Modification and Redistribution (including distribution of any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * modified or derived work) in source and/or binary forms is permitted
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * under this License Terms and Conditions.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 2. Redistribution of source code must retain the copyright notices as they
852ccdd42a71550c974111b49415204ffeca6573Automatic Updater * appear in each source code file, this License Terms and Conditions.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 3. Redistribution in binary form must reproduce the Copyright Notice,
0c6ada0a814f3c5417daa1654129bc2af56ed504Automatic Updater * this License Terms and Conditions, in the documentation and/or other
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * materials provided with the distribution. For the purposes of binary
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * distribution the "Copyright Notice" refers to the following language:
0c6ada0a814f3c5417daa1654129bc2af56ed504Automatic Updater * "Copyright (c) Japan Network Information Center. All rights reserved."
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 4. Neither the name of JPNIC may be used to endorse or promote products
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * derived from this Software without specific prior written approval of
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
d060d8669f5558690e7faf4a1c12fe5c02a7c60dAutomatic Updater * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 6. Indemnification by Licensee
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Any person or entities using and/or redistributing this Software under
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * this License Terms and Conditions shall defend indemnify and hold
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * harmless JPNIC from and against any and all judgements damages,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * expenses, settlement liabilities, cost and other liabilities of any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * kind as a result of use and redistribution of this Software or any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * claim, suite, action, litigation or proceeding by any third party
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * arising out of or relates to this License Terms and Conditions.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * 7. Governing Law, Jurisdiction and Venue
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * This License Terms and Conditions shall be governed by and and
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * construed in accordance with the law of Japan. Any person or entities
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * using and/or redistributing this Software under this License Terms and
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Conditions hereby agrees and consent to the personal and exclusive
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * jurisdiction and venue of Tokyo District Court of Japan.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * mdnconv -- Codeset converter for named.conf and zone files
ed4475f3f583f6137b4ff7fea775c5363a4fdb29Automatic Updater/* Maxmum number of normalizers */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinint line_number; /* current input file line number */
7329012471d165cd3dc4180ad2a0a43de91e7f01Mark Andrewsmdn_converter_t conv_in_ctx; /* input converter */
7329012471d165cd3dc4180ad2a0a43de91e7f01Mark Andrewsmdn_converter_t conv_out_ctx; /* output converter */
351b62535d4c4f89883bfdba025999dd32490266Evan Huntstatic int convert_file(FILE *fp, char *zld, int auto_zld,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Load configuration file.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein r = mdn_resconf_loadfile(resconf, resconf_file);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein errormsg("error reading configuration file: %s\n",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Get default input/output code.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein (c = mdn_resconf_serverconverter(resconf)) != NULL)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Initialize codeset converter.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (!initialize_converter(in_code, out_code, encoding_alias))
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Initialize normalizer.
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews !initialize_normalizer(normalizer, nnormalizer))
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Default ZLD.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein const char *conf_zld = mdn_resconf_zld(resconf);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Open input file.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Do the conversion.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return convert_file(fp, zld, auto_zld, selective);
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrewsconvert_file(FILE *fp, char *zld, int auto_zld, int selective) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if (strcmp(mdn_converter_localencoding(conv_in_ctx),
731cc132f22dbc9e0ecd7035dce314a61076d31bAutomatic Updater while (fgets(line1, sizeof(line1), fp) != NULL) {
731cc132f22dbc9e0ecd7035dce314a61076d31bAutomatic Updater * Trim newline at the end. This is needed for
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews * those ascii-comatible encodings such as UTF-5 or RACE
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews * not to try converting newlines, which will result
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews * in `invalid encoding' error.
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater * Convert input line to UTF-8.
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater * Find portions encoded in RACE using RACE's prefix
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater * "bq--", and selectively decode those portions.
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater r = mdn_converter_localtoutf8(conv_in_ctx,
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater errormsg("conversion failed at line %d: %s\n",
7c6b9b263898daf28d657f65dbd75c330ca4aa13Automatic Updater errormsg("conversion to utf-8 failed at line %d\n",
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews * Normalize and convert to the output codeset.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein r = selective_encode(line2, line1, sizeof(line1),
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews static char *options[] = {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "-in input-codeset : specifies input codeset name.",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "-out output-codeset : specifies output codeset name.",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "-normalize scheme : specifies normalization scheme.",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein " this option can be specified",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein " multiple times.",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "-zld zld : specifies ZLD to use.",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "-auto : automatically appends ZLD where",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein " seemed appropriate.",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "-alias alias-file : specifies codeset alias file.",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "-conf conf-file : specifies pathname of MDN resolver",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein " configuration file.",
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews "-noconf : do not load MDN resolver configuration",
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews "-flush : line-buffering mode.",
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews "-whole : convert the whole region instead of",
69f175fc57a578dd85c1548ed3f34284321f9d3aMark Andrews " regions containing non-ascii characters",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein fprintf(stderr, "Usage: %s [options..] [file]\n", cmd);