You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2002/11/22 15:57:06 UTC

cvs commit: xml-xerces/c/src/xercesc/util/Transcoders/Uniconv390 ccsid.h Makefile.in uniconv.cpp uniconv.h Uniconv390TransService.cpp Uniconv390TransService.hpp

tng         2002/11/22 06:57:06

  Added:       c/src/xercesc/util/Transcoders/Uniconv390 ccsid.h
                        Makefile.in uniconv.cpp uniconv.h
                        Uniconv390TransService.cpp
                        Uniconv390TransService.hpp
  Log:
  390: Uniconv390 support.  Patch by Chris Larsson and Stephen Dulin.
  
  Revision  Changes    Path
  1.1                  xml-xerces/c/src/xercesc/util/Transcoders/Uniconv390/ccsid.h
  
  Index: ccsid.h
  ===================================================================
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * http://www.apache.org/.
   */
  /*
   * $Id: ccsid.h,v 1.1 2002/11/22 14:57:05 tng Exp $
   */
  
  /*****************************************************************
   * Do not manually change this file. It is generated automatically.
   *****************************************************************/
  
  #define _AE_MAX_CODESET_NAME_LENGTH    40
  #define _AE_NUM_OF_CODESETS   554
  
  struct ccsid_mapping {
     char NAME[_AE_MAX_CODESET_NAME_LENGTH];
     int CCSID;
  };
  
  struct ccsid_mapping CCSID_MAPPING[_AE_NUM_OF_CODESETS] =
  { {"ADOBELATIN1ENCODING", 1277},
  {"ADOBESTANDARDENCODING", 1276},
  {"ARABIC", 1089},
  {"ASMO708", 1089},
  {"BIG5", 1370},
  {"CCSID01140", 1140},
  {"CCSID01141", 1141},
  {"CCSID01142", 1142},
  {"CCSID01143", 1143},
  {"CCSID01144", 1144},
  {"CCSID01145", 1145},
  {"CCSID01146", 1146},
  {"CCSID01147", 1147},
  {"CCSID01148", 1148},
  {"CCSID01149", 1149},
  {"CHINESE", 1383},
  {"CP01140", 1140},
  {"CP01141", 1141},
  {"CP01142", 1142},
  {"CP01143", 1143},
  {"CP01144", 1144},
  {"CP01145", 1145},
  {"CP01146", 1146},
  {"CP01147", 1147},
  {"CP01148", 1148},
  {"CP01149", 1149},
  {"CP037", 37},
  {"CP1008", 5104},
  {"CP1025", 1154},
  {"CP1027", 5123},
  {"CP1046", 9238},
  {"CP1089", 1089},
  {"CP1112", 1112},
  {"CP1122", 1122},
  {"CP1123", 1158},
  {"CP1125", 848},
  {"CP1130", 1164},
  {"CP1131", 849},
  {"CP1208", 1208},
  {"CP1250", 5346},
  {"CP1251", 5347},
  {"CP1252", 5348},
  {"CP1253", 5349},
  {"CP1254", 5350},
  {"CP1255", 5351},
  {"CP1256", 5352},
  {"CP1257", 5353},
  {"CP1258", 5354},
  {"CP1364", 1364},
  {"CP1383", 1383},
  {"CP273", 273},
  {"CP277", 277},
  {"CP278", 278},
  {"CP280", 280},
  {"CP284", 284},
  {"CP285", 285},
  {"CP28709", 1159},
  {"CP297", 297},
  {"CP33722", 33722},
  {"CP37", 37},
  {"CP420", 420},
  {"CP424", 424},
  {"CP437", 437},
  {"CP500", 500},
  {"CP65001", 1208},
  {"CP813", 4909},
  {"CP819", 819},
  {"CP850", 850},
  {"CP851", 851},
  {"CP852", 9044},
  {"CP855", 872},
  {"CP856", 856},
  {"CP857", 9049},
  {"CP858", 858},
  {"CP859", 859},
  {"CP860", 860},
  {"CP861", 861},
  {"CP862", 867},
  {"CP863", 863},
  {"CP864", 17248},
  {"CP865", 865},
  {"CP866", 808},
  {"CP867", 867},
  {"CP868", 868},
  {"CP869", 9061},
  {"CP870", 870},
  {"CP871", 871},
  {"CP875", 875},
  {"CP878", 878},
  {"CP9030", 1160},
  {"CP912", 912},
  {"CP913", 913},
  {"CP914", 914},
  {"CP915", 915},
  {"CP916", 916},
  {"CP918", 918},
  {"CP920", 920},
  {"CP921", 901},
  {"CP922", 902},
  {"CP923", 923},
  {"CP932", 943},
  {"CP933", 933},
  {"CP935", 935},
  {"CP936", 1386},
  {"CP937", 937},
  {"CP939", 939},
  {"CP943", 943},
  {"CP950", 1370},
  {"CPAR", 868},
  {"CPGR", 9061},
  {"CPIBM1047", 1047},
  {"CPIBM1123", 1123},
  {"CPIBM1140", 1140},
  {"CPIBM1141", 1141},
  {"CPIBM1142", 1142},
  {"CPIBM1143", 1143},
  {"CPIBM1144", 1144},
  {"CPIBM1145", 1145},
  {"CPIBM1146", 1146},
  {"CPIBM1147", 1147},
  {"CPIBM1148", 1148},
  {"CPIBM1149", 1149},
  {"CPIBM1153", 1153},
  {"CPIBM1154", 1154},
  {"CPIBM1156", 1156},
  {"CPIBM1157", 1157},
  {"CPIBM1158", 1158},
  {"CPIBM1160", 1160},
  {"CPIBM1164", 1164},
  {"CPIBM12712", 12712},
  {"CPIBM1371", 1371},
  {"CPIBM16804", 16804},
  {"CPIBM273", 273},
  {"CPIBM277", 277},
  {"CPIBM278", 278},
  {"CPIBM280", 280},
  {"CPIBM284", 284},
  {"CPIBM285", 285},
  {"CPIBM297", 297},
  {"CPIBM37", 37},
  {"CPIBM4971", 4971},
  {"CPIBM500", 500},
  {"CPIBM871", 871},
  {"CPIBM933", 933},
  {"CPIBM935", 935},
  {"CPIBM937", 937},
  {"CPIS", 861},
  {"CSADOBESTANDARDENCODING", 1276},
  {"CSBIG5", 1370},
  {"CSEUCKR", 970},
  {"CSGB2312", 1383},
  {"CSHPROMAN8", 1051},
  {"CSIBM037", 37},
  {"CSIBM273", 273},
  {"CSIBM277", 277},
  {"CSIBM278", 278},
  {"CSIBM280", 280},
  {"CSIBM284", 284},
  {"CSIBM285", 285},
  {"CSIBM297", 297},
  {"CSIBM420", 420},
  {"CSIBM424", 424},
  {"CSIBM500", 500},
  {"CSIBM855", 872},
  {"CSIBM857", 9049},
  {"CSIBM860", 860},
  {"CSIBM861", 861},
  {"CSIBM863", 863},
  {"CSIBM864", 17248},
  {"CSIBM865", 865},
  {"CSIBM866", 808},
  {"CSIBM868", 868},
  {"CSIBM869", 9061},
  {"CSIBM870", 870},
  {"CSIBM871", 871},
  {"CSIBM918", 918},
  {"CSISO58GB231280", 1383},
  {"CSISOLATIN0", 923},
  {"CSISOLATIN1", 819},
  {"CSISOLATIN2", 912},
  {"CSISOLATIN3", 913},
  {"CSISOLATIN4", 914},
  {"CSISOLATIN5", 920},
  {"CSISOLATIN9", 923},
  {"CSISOLATINARABIC", 1089},
  {"CSISOLATINCYRILLIC", 915},
  {"CSISOLATINGREEK", 4909},
  {"CSISOLATINHEBREW", 916},
  {"CSKOI8R", 878},
  {"CSKSC56011987", 949},
  {"CSMACINTOSH", 1275},
  {"CSPC850MULTILINGUAL", 850},
  {"CSPC851", 851},
  {"CSPC862LATINHEBREW", 867},
  {"CSPC8CODEPAGE437", 437},
  {"CSPCP852", 9044},
  {"CSPCP855", 872},
  {"CSSHIFTJIS", 943},
  {"CSWINDOWS31J", 943},
  {"CYRILLIC", 915},
  {"EBCDICAR", 16804},
  {"EBCDICCPAR1", 420},
  {"EBCDICCPAR2", 918},
  {"EBCDICCPBE", 500},
  {"EBCDICCPCA", 37},
  {"EBCDICCPCH", 500},
  {"EBCDICCPDK", 277},
  {"EBCDICCPES", 284},
  {"EBCDICCPFI", 278},
  {"EBCDICCPFR", 297},
  {"EBCDICCPGB", 285},
  {"EBCDICCPHE", 424},
  {"EBCDICCPIS", 871},
  {"EBCDICCPIT", 280},
  {"EBCDICCPNL", 37},
  {"EBCDICCPNO", 277},
  {"EBCDICCPROECE", 870},
  {"EBCDICCPSE", 278},
  {"EBCDICCPUS", 37},
  {"EBCDICCPWT", 37},
  {"EBCDICCPYU", 870},
  {"EBCDICDE", 273},
  {"EBCDICDK", 277},
  {"EBCDICGB", 285},
  {"EBCDICHE", 12712},
  {"EBCDICSV", 278},
  {"ECMA114", 1089},
  {"ECMA118", 4909},
  {"ECMA128", 920},
  {"ELOT928", 4909},
  {"EUCCN", 1383},
  {"EUCKR", 970},
  {"GB", 1383},
  {"GB18030", 1392},
  {"GB2312", 1383},
  {"GB23121980", 1383},
  {"GB231280", 1383},
  {"GBK", 1386},
  {"GREEK", 4909},
  {"GREEK8", 4909},
  {"HEBREW", 916},
  {"HPROMAN8", 1051},
  {"IBM00858", 858},
  {"IBM01140", 1140},
  {"IBM01141", 1141},
  {"IBM01142", 1142},
  {"IBM01143", 1143},
  {"IBM01144", 1144},
  {"IBM01145", 1145},
  {"IBM01146", 1146},
  {"IBM01147", 1147},
  {"IBM01148", 1148},
  {"IBM01149", 1149},
  {"IBM037", 37},
  {"IBM037S390", 37},
  {"IBM1006", 1006},
  {"IBM1006P1002000", 1006},
  {"IBM1006VPUA", 1006},
  {"IBM1025", 1025},
  {"IBM1025P1002000", 1025},
  {"IBM1025STD", 1025},
  {"IBM1047", 1047},
  {"IBM1047S390", 1047},
  {"IBM1051", 1051},
  {"IBM1089", 1089},
  {"IBM1097", 1097},
  {"IBM1097P1002000", 1097},
  {"IBM1097VPUA", 1097},
  {"IBM1098", 1098},
  {"IBM1098P1002000", 1098},
  {"IBM1098VSUBVPUA", 1098},
  {"IBM1112", 1112},
  {"IBM1112P1002000", 1112},
  {"IBM1112STD", 1112},
  {"IBM1122", 1122},
  {"IBM1122", 1122},
  {"IBM1122P1002000", 1122},
  {"IBM1122STD", 1122},
  {"IBM1123", 1123},
  {"IBM1124", 1124},
  {"IBM1124P1002000", 1124},
  {"IBM1124STD", 1124},
  {"IBM1125", 1125},
  {"IBM1125P1002000", 1125},
  {"IBM1125VSUB", 1125},
  {"IBM1129", 1129},
  {"IBM1129P1002000", 1129},
  {"IBM1129STD", 1129},
  {"IBM1130", 1130},
  {"IBM1130P1002000", 1130},
  {"IBM1130STD", 1130},
  {"IBM1131", 1131},
  {"IBM1131P1002000", 1131},
  {"IBM1131VSUB", 1131},
  {"IBM1132", 1132},
  {"IBM1132P1002000", 1132},
  {"IBM1132STD", 1132},
  {"IBM1133", 1133},
  {"IBM1133P1002000", 1133},
  {"IBM1133STD", 1133},
  {"IBM1137", 1137},
  {"IBM1137P1002000", 1137},
  {"IBM1137STD", 1137},
  {"IBM1140", 1140},
  {"IBM1140S390", 1140},
  {"IBM1141", 1141},
  {"IBM1142", 1142},
  {"IBM1142S390", 1142},
  {"IBM1143", 1143},
  {"IBM1143S390", 1143},
  {"IBM1144", 1144},
  {"IBM1144S390", 1144},
  {"IBM1145", 1145},
  {"IBM1145S390", 1145},
  {"IBM1146", 1146},
  {"IBM1146S390", 1146},
  {"IBM1147", 1147},
  {"IBM1147S390", 1147},
  {"IBM1148", 1148},
  {"IBM1148S390", 1148},
  {"IBM1149", 1149},
  {"IBM1149S390", 1149},
  {"IBM1153", 1153},
  {"IBM1154", 1154},
  {"IBM1156", 1156},
  {"IBM1157", 1157},
  {"IBM1158", 1158},
  {"IBM1159", 1159},
  {"IBM1160", 1160},
  {"IBM1161", 874},
  {"IBM1164", 1164},
  {"IBM1208", 1208},
  {"IBM1209", 1208},
  {"IBM1250", 1250},
  {"IBM1251", 1251},
  {"IBM1252", 1252},
  {"IBM1253", 1253},
  {"IBM1254", 1254},
  {"IBM1255", 1255},
  {"IBM1256", 1256},
  {"IBM1257", 1257},
  {"IBM1258", 1258},
  {"IBM12712", 12712},
  {"IBM1275", 1275},
  {"IBM1276", 1276},
  {"IBM1277", 1277},
  {"IBM1280", 1280},
  {"IBM1281", 1281},
  {"IBM1282", 1282},
  {"IBM1283", 1283},
  {"IBM1363", 1363},
  {"IBM1363P1102000", 1363},
  {"IBM1363VASCIIVSUBVPUA", 1363},
  {"IBM1364", 1364},
  {"IBM1364P1102000", 1364},
  {"IBM1364VPUA", 1364},
  {"IBM1370", 1370},
  {"IBM1371", 1371},
  {"IBM1381", 1381},
  {"IBM1381P1102000", 1381},
  {"IBM1381VSUBVPUA", 1381},
  {"IBM1383", 1383},
  {"IBM1386", 1386},
  {"IBM1386P1002002", 1386},
  {"IBM1386VSUBVPUA", 1386},
  {"IBM1388", 1388},
  {"IBM1392", 1392},
  {"IBM1399", 1399},
  {"IBM16804", 16804},
  {"IBM17248", 17248},
  {"IBM273", 273},
  {"IBM277", 277},
  {"IBM278", 278},
  {"IBM280", 280},
  {"IBM284", 284},
  {"IBM285", 285},
  {"IBM297", 297},
  {"IBM33722", 33722},
  {"IBM367", 367},
  {"IBM37", 37},
  {"IBM37S390", 37},
  {"IBM420", 420},
  {"IBM424", 424},
  {"IBM437", 437},
  {"IBM4909", 4909},
  {"IBM4971", 4971},
  {"IBM500", 500},
  {"IBM5050", 33722},
  {"IBM5104", 5104},
  {"IBM5123", 5123},
  {"IBM5304", 1208},
  {"IBM5305", 1208},
  {"IBM5346", 5346},
  {"IBM5347", 5347},
  {"IBM5348", 5348},
  {"IBM5349", 5349},
  {"IBM5350", 5350},
  {"IBM5351", 5351},
  {"IBM5352", 5352},
  {"IBM5353", 5353},
  {"IBM5354", 5354},
  {"IBM806", 806},
  {"IBM806P1002000", 806},
  {"IBM806VSUB", 806},
  {"IBM808", 808},
  {"IBM813", 4909},
  {"IBM819", 819},
  {"IBM848", 848},
  {"IBM849", 849},
  {"IBM850", 850},
  {"IBM851", 851},
  {"IBM852", 852},
  {"IBM855", 855},
  {"IBM856", 856},
  {"IBM857", 857},
  {"IBM858", 858},
  {"IBM859", 859},
  {"IBM860", 860},
  {"IBM861", 861},
  {"IBM862", 862},
  {"IBM863", 863},
  {"IBM864", 864},
  {"IBM865", 865},
  {"IBM866", 866},
  {"IBM867", 867},
  {"IBM868", 868},
  {"IBM869", 869},
  {"IBM870", 870},
  {"IBM870P1002000", 870},
  {"IBM870STD", 870},
  {"IBM871", 871},
  {"IBM872", 872},
  {"IBM874", 874},
  {"IBM875", 875},
  {"IBM875", 875},
  {"IBM875P1002000", 875},
  {"IBM875STD", 875},
  {"IBM878", 878},
  {"IBM901", 901},
  {"IBM902", 902},
  {"IBM9030", 9030},
  {"IBM9030P1002000", 9030},
  {"IBM9030STD", 9030},
  {"IBM9044", 9044},
  {"IBM9049", 9049},
  {"IBM9061", 9061},
  {"IBM9066", 9066},
  {"IBM9066P1002000", 9066},
  {"IBM9066VSUB", 9066},
  {"IBM912", 912},
  {"IBM913", 913},
  {"IBM914", 914},
  {"IBM915", 915},
  {"IBM916", 916},
  {"IBM918", 918},
  {"IBM918P1002000", 918},
  {"IBM918VPUA", 918},
  {"IBM920", 920},
  {"IBM921", 921},
  {"IBM922", 922},
  {"IBM923", 923},
  {"IBM9238", 9238},
  {"IBM932", 942},
  {"IBM932VASCIIVSUBVPUA", 942},
  {"IBM933", 933},
  {"IBM935", 935},
  {"IBM937", 937},
  {"IBM939", 939},
  {"IBM942", 942},
  {"IBM942P1202000", 942},
  {"IBM942VASCIIVSUBVPUA", 942},
  {"IBM943", 943},
  {"IBM943P14A2000", 943},
  {"IBM943VSUBVPUA", 943},
  {"IBM949", 949},
  {"IBM949P11A2000", 949},
  {"IBM949VSUBVPUA", 949},
  {"IBM950", 950},
  {"IBM970", 970},
  {"IBM970P1102000", 970},
  {"IBMEUCCN", 1383},
  {"IBMEUCKR", 970},
  {"ISO88591", 819},
  {"ISO885915", 923},
  {"ISO885915FDIS", 923},
  {"ISO88592", 912},
  {"ISO88593", 913},
  {"ISO88594", 914},
  {"ISO88595", 915},
  {"ISO88596", 1089},
  {"ISO88597", 4909},
  {"ISO88598", 916},
  {"ISO88599", 920},
  {"ISOIR100", 819},
  {"ISOIR101", 912},
  {"ISOIR109", 913},
  {"ISOIR110", 914},
  {"ISOIR126", 4909},
  {"ISOIR127", 1089},
  {"ISOIR138", 916},
  {"ISOIR144", 915},
  {"ISOIR148", 920},
  {"ISOIR149", 949},
  {"ISOIR58", 1383},
  {"JOHAB", 949},
  {"KOI8", 878},
  {"KOI8R", 878},
  {"KOREAN", 949},
  {"KSC5601", 949},
  {"KSC56011987", 949},
  {"KSC56011987", 949},
  {"KSC56011989", 949},
  {"KSC56011992", 949},
  {"L1", 819},
  {"L2", 912},
  {"L3", 913},
  {"L4", 914},
  {"L5", 920},
  {"LATIN0", 923},
  {"LATIN1", 819},
  {"LATIN1", 819},
  {"LATIN2", 912},
  {"LATIN3", 913},
  {"LATIN4", 914},
  {"LATIN5", 920},
  {"LATIN9", 923},
  {"MAC", 1275},
  {"MACCE", 1282},
  {"MACCY", 1283},
  {"MACGR", 1280},
  {"MACINTOSH", 1275},
  {"MACTR", 1281},
  {"MSKANJI", 943},
  {"R8", 1051},
  {"ROMAN8", 1051},
  {"SHIFTJIS", 943},
  {"SJIS", 943},
  {"UCS2", 1200},
  {"UTF8", 1208},
  {"WINDOWS1250", 5346},
  {"WINDOWS1251", 5347},
  {"WINDOWS1252", 5348},
  {"WINDOWS1253", 5349},
  {"WINDOWS1254", 5350},
  {"WINDOWS1255", 5351},
  {"WINDOWS1256", 5352},
  {"WINDOWS1257", 5353},
  {"WINDOWS1258", 5354},
  {"WINDOWS31J", 943},
  {"WINDOWS936", 1386},
  {"XBIG5", 1370},
  {"XSJIS", 943},
  {"ZHCN", 1386},
  {"", 0} };
  
  
  
  
  1.1                  xml-xerces/c/src/xercesc/util/Transcoders/Uniconv390/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  #
  # The Apache Software License, Version 1.1
  #
  # Copyright (c) 2002 The Apache Software Foundation.  All rights
  # reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  #
  # 1. Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #
  # 2. Redistributions in binary form must reproduce the above copyright
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #
  # 3. The end-user documentation included with the redistribution,
  #    if any, must include the following acknowledgment:
  #       "This product includes software developed by the
  #        Apache Software Foundation (http://www.apache.org/)."
  #    Alternately, this acknowledgment may appear in the software itself,
  #    if and wherever such third-party acknowledgments normally appear.
  #
  # 4. The names "Xerces" and "Apache Software Foundation" must
  #    not be used to endorse or promote products derived from this
  #    software without prior written permission. For written
  #    permission, please contact apache\@apache.org.
  #
  # 5. Products derived from this software may not be called "Apache",
  #    nor may "Apache" appear in their name, without prior written
  #    permission of the Apache Software Foundation.
  #
  # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  # SUCH DAMAGE.
  # ====================================================================
  #
  # This software consists of voluntary contributions made by many
  # individuals on behalf of the Apache Software Foundation, and was
  # originally based on software copyright (c) 1999, International
  # Business Machines, Inc., http://www.ibm.com .  For more information
  # on the Apache Software Foundation, please see
  # <http://www.apache.org/>.
  #
  #
  # $Log: Makefile.in,v $
  # Revision 1.1  2002/11/22 14:57:05  tng
  # 390: Uniconv390 support.  Patch by Chris Larsson and Stephen Dulin.
  #
  #
  
  PLATFORM = @platform@
  CC  = @cc@
  CXX = @cxx@
  CXXFLAGS = @cxxflags@
  CFLAGS = @cflags@
  PREFIX = @prefix@
  PREFIX_INCLUDE = @prefix_include@
  LDFLAGS = @ldflags@
  LIBS = @libs@
  OSVER = @osver@
  USELIBWWW = @uselibwww@
  MESSAGELOADER = @messageloader@
  TRANSCODER = @transcoder@
  THREADS = @threads@
  
  MODULE = util
  SUBMODULE = Transcoders/Uniconv390
  
  include ../../../Makefile.incl
  
  CPP_PUBHEADERS = Uniconv390TransService.hpp uniconv.h
  
  CPP_OBJECTS = Uniconv390TransService.$(TO) uniconv.$(TO)
  
  include ../../Makefile.util.submodule
  
  
  
  1.1                  xml-xerces/c/src/xercesc/util/Transcoders/Uniconv390/uniconv.cpp
  
  Index: uniconv.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Id: uniconv.cpp,v 1.1 2002/11/22 14:57:06 tng Exp $
   */
  
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
  #include <errno.h>
  #include <ctype.h>
  #include <cunhc.h>
  #include "ccsid.h"
  #include "uniconv.h"
  
  XERCES_CPP_NAMESPACE_BEGIN
  
  #define WORK_BUFFER_SIZE 16*1024
  #define DDA_NEEDED CUNBCPRM_DDA_REQ
  #define RETRY_THRESHOLD 10000
  
  // This is utility routine which strips '-', '_' and spaces from the name and
  // also upper cases the name. It also returns the length of the string.
  static int stripNameCopy(const char *s,char *d,int max)
  {
     int si=0;
     int di=0;
  
     while ( (s[si] != '\0') && (di < max) ) {
        if ( (s[si] == ' ') || (s[si] == '_') || (s[si] == '-') )
           si++;
        else {
           d[di] = toupper(s[si]);
           si++;di++;
        }
     }
     d[di] = 0;
     if (s[si] != '\0')
        return -1;
     return si;
  }
  
  // This takes a name and does a lookup into the ccsid table (from ccsid.h)
  // to find the corresponding ccsid. It also checks if the string ends in s390
  // and returns that information to the caller.
  // The lookup into the table is done via a binary search since we know that the
  // table was nicely sorted for us.
  static int getccsid(const char *s,int * is390)
  {
     char tmpstr[_AE_MAX_CODESET_NAME_LENGTH];
     int start;
     int limit;
     int index;
     int result;
     int thelen;
  
     // Clean up the name....
     if (s == NULL)
        return -1;
     if ((thelen = stripNameCopy(s,tmpstr,_AE_MAX_CODESET_NAME_LENGTH-1)) == -1)
        return -1;
  
     // Check for the S390 string in the name
     *is390 = 0;
     if ( (strstr((char *)tmpstr, "S390")) != NULL )
        *is390 = 1;
  
     // Now lookup the name via a binary search
     start = 0;
     limit = _AE_NUM_OF_CODESETS;
     index = limit/2;
     while ( ((result=strcoll(tmpstr, CCSID_MAPPING[index].NAME)) != 0) &&
              (start < limit-1) ) {
        if (result < 0)
           limit = index;
        else
            start = index;
        index = (start+limit)/2;
     }
  
     if (result != 0 && start >= limit-1)
        return -1;
  
     return CCSID_MAPPING[index].CCSID;
  }
  // **********************************************************************
  // These are the character conversion services
  // **********************************************************************
  
  // "Open" the conversion. Allocate memory to hold the handle which
  // unicode services requires. Call unicode services with a 0 length
  // so that it can initialize it's handle.
  // Note that unicode services must always be called in a loop since
  // it could be busy reloading its tables.
  uniconv_t uniconv_open(const char *destenc, const char *srcenc) {
     CUNBCPRM  defparms = {CUNBCPRM_DEFAULT};
     CUNBCPRM * tmpp;
     void * handle_area;
     char *cptr;
     int srcis390;
     int destis390;
  
     errno = 0;
     handle_area = malloc (sizeof(CUNBCPRM)+DDA_NEEDED+WORK_BUFFER_SIZE);
     tmpp = (CUNBCPRM *) handle_area;
     if (tmpp==NULL)
        return (uniconv_t)-1;
  
     // initialize the parm area with defaults, then start filling it
     // in with our values.
     memcpy(tmpp,&defparms,sizeof(defparms));
     tmpp->Src_Buf_Len= 0;
     // get the ccsids.
     if ( ((tmpp->Src_CCSID=getccsid(srcenc,&srcis390)) == -1) ||
          ((tmpp->Targ_CCSID=getccsid(destenc,&destis390)) == -1) ) {
        errno=ENOENT;
        free(handle_area);
        return (uniconv_t)-1;
     }
     tmpp->Wrk_Buf_Ptr=(void*) (((unsigned int) handle_area) + sizeof(CUNBCPRM)+DDA_NEEDED);
     tmpp->Wrk_Buf_Len=WORK_BUFFER_SIZE;
     tmpp->DDA_Buf_Ptr=(void*) ((unsigned int) handle_area + sizeof(CUNBCPRM));
     tmpp->DDA_Buf_Len=DDA_NEEDED;
     // This flag tells the services to automatically refresh the handle if it
     // becomes invalid.
     tmpp->Flag1|=CUNBCPRM_REFRESH_AT_INV_HANDLE_START;
     tmpp->Flag1|=CUNBCPRM_SUB_ACTION_SUBSTITUTE;
  
     /* Determine which technique to use */
     if ( (srcis390) || (destis390) )
        // This technique causes it to swap LF and NL.
        memcpy(tmpp->Technique,"L       ",8);
     else
        memcpy(tmpp->Technique,"        ",8);
  
     // Retry if the services are busy reloading their tables.
     int retry_count = 0;
     while (retry_count < RETRY_THRESHOLD) {
        CUNLCNV(tmpp);
        if (tmpp->Return_Code == CUN_RC_OK)
           break;
        else if ( (tmpp->Return_Code == CUN_RC_WARN) &&
                  ( (tmpp->Reason_Code == CUN_RS_NO_HANDLE) ||
                    (tmpp->Reason_Code == CUN_RS_INV_HANDLE_NOSET) ||
                    (tmpp->Reason_Code == CUN_RS_INV_HANDLE_SET) ) )
           // Let it loop around again
           retry_count++;
        else
           break;
     }
  
     if (tmpp->Return_Code != CUN_RC_OK) {
  // printf("uniconv_open() Error!!! rc=%d rs=%d\n",tmpp->Return_Code,tmpp->Reason_Code);   // remove this after function test
        free(handle_area);
        errno=EINVAL;
        handle_area = (uniconv_t)-1;
     }
  
     return handle_area;
  }
  
  // All that is required for close is to free the handle buffer.
  int uniconv_close(uniconv_t handle_area) {
     errno = 0;
     if (((int)handle_area) <= 0) {
        errno=EBADF;
        return -1;
     }
     free(handle_area);
     return 0;
  }
  
  // This does the real conversion.
  // Note that unicode services must always be called in a loop since
  // it could be busy reloading its tables.
  int uniconv(uniconv_t cd, char **inbuf,  size_t *inbytesleft,
                            char **outbuf, size_t *outbytesleft) {
     CUNBCPRM * tmpp;
     size_t startinlen = *inbytesleft;
     size_t startoutlen = *outbytesleft;
     errno = 0;
  
     if (((int)cd) <= 0) {
        errno=EBADF;
        return -1;
     }
  
     // Fill in the parameter area with current values
     tmpp = (CUNBCPRM *) cd;
     tmpp->Src_Buf_Ptr = *inbuf;
     tmpp->Src_Buf_Len = *inbytesleft;
     tmpp->Targ_Buf_Ptr = *outbuf;
     tmpp->Targ_Buf_Len = *outbytesleft;
  
     // Retry if the services are busy reloading their tables.
     int retry_count = 0;
     while (retry_count < RETRY_THRESHOLD) {
        CUNLCNV(tmpp);
        if (tmpp->Return_Code == CUN_RC_OK)
           break;
        else if ( (tmpp->Return_Code == CUN_RC_WARN) &&
                  ( (tmpp->Reason_Code == CUN_RS_NO_HANDLE) ||
                    (tmpp->Reason_Code == CUN_RS_INV_HANDLE_NOSET) ||
                    (tmpp->Reason_Code == CUN_RS_INV_HANDLE_SET) ) )
           // Let it loop around again
           retry_count++;
        else
           break;
     }
     *inbuf        = (char *)tmpp->Src_Buf_Ptr;
     *inbytesleft  = tmpp->Src_Buf_Len;
     *outbuf       = (char *)tmpp->Targ_Buf_Ptr;
     *outbytesleft = tmpp->Targ_Buf_Len;
  
     if (tmpp->Return_Code != CUN_RC_OK) {
        if (tmpp->Reason_Code == CUN_RS_TRG_EXH)
           errno=E2BIG;
        else if (tmpp->Reason_Code == CUN_RS_MBC_INCOMPLETE)
           errno=EINVAL;
        else {
   printf("uniconv() Error!!! rc=%d rs=%d\n",tmpp->Return_Code,tmpp->Reason_Code); // remove after function test
           errno=EBADF;
           return -1;
        }
     }
     return (startinlen-*inbytesleft);
  }
  
  // **********************************************************************
  // These are the case conversion services.
  // **********************************************************************
  
  // This "opens" the case conversion. It allocates the parameter area
  // then does a dummy call to unicode services so that it can set up
  // the handle.
  // Note that unicode services must always be called in a loop since
  // it could be busy reloading its tables.
  static inline uniconv_t uniconv_case_open(unsigned char direction) {
  CUNBAPRM  defparms = {CUNBAPRM_DEFAULT};
  CUNBAPRM * tmpp;
  void * handle_area;
  
     errno = 0;
     handle_area = malloc (sizeof(CUNBAPRM)+CUNBAPRM_DDA_REQ);
     tmpp = (CUNBAPRM *) handle_area;
     if (tmpp==NULL)
        return (uniconv_t)-1;
     // initialize the parm area with defaults, then start filling it
     // in with our values.
     memcpy(tmpp,&defparms,sizeof(defparms));
     tmpp->DDA_Buf_Ptr=(void*) ((unsigned int) handle_area + sizeof(CUNBAPRM));
     tmpp->DDA_Buf_Len=CUNBAPRM_DDA_REQ;
     // This flag tells the services to automatically refresh the handle if it
     // becomes invalid.
     tmpp->Flag1|=CUNBAPRM_REFRESH_AT_INV_HANDLE_START;
  
     unichar_t inchar = 0x61;
     unichar_t outchar;
     tmpp->Src_Buf_Ptr=&inchar;
     tmpp->Targ_Buf_Ptr=&outchar;
     tmpp->Targ_Buf_Len=sizeof(unichar_t);
     tmpp->Src_Buf_Len=sizeof(unichar_t);
     tmpp->Conv_Type=direction;
  
     // Retry if the services are busy reloading their tables.
     int retry_count = 0;
     while (true) {
        CUNLASE ( tmpp );
  
        if (tmpp->Return_Code == CUN_RC_OK) {
           break;
        } else if ( (tmpp->Return_Code == CUN_RC_WARN) &&
                    ( (tmpp->Reason_Code == CUN_RS_NO_HANDLE) ||
                      (tmpp->Reason_Code == CUN_RS_INV_HANDLE_NOSET) ||
                      (tmpp->Reason_Code == CUN_RS_INV_HANDLE_SET) ) ) {
           // Let it loop around again
           retry_count++;
           if (retry_count > RETRY_THRESHOLD) {
              errno = ENOSYS;
              break;
           }
        } else {
  // printf("CUNLASE: Unicode Services is a Failure!\n");
  // printf("CUNLASE rc=%d rs=%d\n",tmpp->Return_Code,tmpp->Reason_Code);
           errno = ENOSYS;
           break;
        }
     }
     if (tmpp->Return_Code != CUN_RC_OK) {
  // printf("uniconv_case_open() Error!!! rc=%d rs=%d\n",tmpp->Return_Code,tmpp->Reason_Code); // remove after function test.
        free(handle_area);
        errno=EINVAL;
        handle_area = (uniconv_t)-1;
     }
  
     return handle_area;
  }
  
  // These are the actual external interfaces for the open function
  uniconv_t uniconv_toupper_open() {
     return uniconv_case_open(CUNBAPRM_TO_UPPER);
  }
  uniconv_t uniconv_tolower_open() {
     return uniconv_case_open(CUNBAPRM_TO_LOWER);
  }
  // This closes the case conversion. All it does is free the handle buffer.
  int _uniconv_case_close(uniconv_t handle_area) {
     errno = 0;
     if (((int)handle_area) <= 0) {
        errno=EBADF;
        return -1;
     }
     free(handle_area);
     return 0;
  }
  
  // This does the actual case conversion. The direction is already
  // stored in the handle buffer.
  // Note that unicode services must always be called in a loop since
  // it could be busy reloading its tables.
  unichar_t uniconv_caseit (uniconv_t cd,unichar_t inchar) {
     unichar_t outchar;
     CUNBAPRM * tmpp;
  
     errno = 0;
     if (((int)cd) <= 0) {
        errno=EBADF;
        return -1;
     }
     tmpp = (CUNBAPRM *) cd;
     tmpp->Src_Buf_Ptr=&inchar;
     tmpp->Targ_Buf_Ptr=&outchar;
     tmpp->Targ_Buf_Len=sizeof(unichar_t);
     tmpp->Src_Buf_Len=sizeof(unichar_t);
  
     // Retry if the services are busy reloading their tables.
     int retry_count = 0;
     while (true) {
        CUNLASE ( tmpp );
  
        if (tmpp->Return_Code == CUN_RC_OK) {
           break;
        }
        else if ( (tmpp->Return_Code == CUN_RC_WARN) &&
                  ( (tmpp->Reason_Code == CUN_RS_NO_HANDLE) ||
                    (tmpp->Reason_Code == CUN_RS_INV_HANDLE_NOSET) ||
                    (tmpp->Reason_Code == CUN_RS_INV_HANDLE_SET) ) ) {
           // Let it loop around again
           retry_count++;
           if (retry_count > RETRY_THRESHOLD) {
              errno = ENOSYS;
              break;
           }
        } else {
  // printf("CUNLASE: Unicode Services is a Failure!\n");
  // printf("CUNLASE rc=%d rs=%d\n",tmpp->Return_Code,tmpp->Reason_Code);
           errno = ENOSYS;
           break;
        }
     }
     return outchar;
  }
  
  XERCES_CPP_NAMESPACE_END
  
  
  
  1.1                  xml-xerces/c/src/xercesc/util/Transcoders/Uniconv390/uniconv.h
  
  Index: uniconv.h
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Id: uniconv.h,v 1.1 2002/11/22 14:57:06 tng Exp $
   */
  
  #ifndef UNICONV_HPP
  #define UNICONV_HPP
  
  #include <xercesc/util/XercesDefs.hpp>
  
  XERCES_CPP_NAMESPACE_BEGIN
  
  // This is the type for the returned handles
  typedef void * uniconv_t;
  #define UNICONV_ERROR (uniconv_t)-1
  #define UNICONV_NOHANDLE (uniconv_t)0
  
  // These are the character conversion services APIs. They are modeled
  // after the iconv() APIs.
  uniconv_t uniconv_open(const char *,const char *);
  int uniconv_close(uniconv_t);
  int uniconv(uniconv_t cd, char **inbuf,  size_t *inbytesleft,
                            char **outbuf, size_t *outbytesleft);
  
  // These are the case conversion APIs. They use the same handle type as the
  // conversion APIs above.
  typedef unsigned short unichar_t;
  uniconv_t uniconv_toupper_open();
  uniconv_t uniconv_tolower_open();
  #define uniconv_toupper_close(_a) _uniconv_case_close(_a)
  #define uniconv_tolower_close(_a) _uniconv_case_close(_a)
  int _uniconv_case_close(uniconv_t handle_area);
  unichar_t uniconv_caseit(uniconv_t cd, unichar_t inchar);
  
  XERCES_CPP_NAMESPACE_END
  
  #endif
  
  
  
  1.1                  xml-xerces/c/src/xercesc/util/Transcoders/Uniconv390/Uniconv390TransService.cpp
  
  Index: Uniconv390TransService.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Id: Uniconv390TransService.cpp,v 1.1 2002/11/22 14:57:06 tng Exp $
   */
  
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <xercesc/util/Janitor.hpp>
  #include <xercesc/util/TranscodingException.hpp>
  #include <xercesc/util/XMLString.hpp>
  #include <xercesc/util/XMLUniDefs.hpp>
  #include <xercesc/util/Transcoders/ICU/ICUTransService.hpp>
  #include "Uniconv390TransService.hpp"
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <errno.h>
  #include <langinfo.h>
  #include <locale.h>
  #include <xercesc/util/regx/XMLUniCharacter.hpp>
  
  XERCES_CPP_NAMESPACE_BEGIN
  
  // debug printfs.... I'll take these out after function test.
  /*
  #define DBGPRINTF1(a) {}
  #define DBGPRINTF2(a,b) {}
  #define DBGPRINTF3(a,b,c) {}
  #define DBGPRINTF4(a,b,c,d) {}
  #define DBGPRINTF5(a,b,c,d,e) {}
  #define DBGPRINTF6(a,b,c,d,e,f) {}
  #define DBGPRINTF7(a,b,c,d,e,f,g) {}
  */
  #define DBGPRINTF1(a) {if (gViewDebug) printf(a);}
  #define DBGPRINTF2(a,b) {if (gViewDebug) printf(a,b);}
  #define DBGPRINTF3(a,b,c) {if (gViewDebug) printf(a,b,c);}
  #define DBGPRINTF4(a,b,c,d) {if (gViewDebug) printf(a,b,c,d);}
  #define DBGPRINTF5(a,b,c,d,e) {if (gViewDebug) printf(a,b,c,d,e);}
  #define DBGPRINTF6(a,b,c,d,e,f) {if (gViewDebug) printf(a,b,c,d,e,f);}
  #define DBGPRINTF7(a,b,c,d,e,f,g) {if (gViewDebug) printf(a,b,c,d,e,f,g);}
  
  // ---------------------------------------------------------------------------
  //  Local, const data
  // ---------------------------------------------------------------------------
  static const XMLCh gMyServiceId[] =
  {
      chLatin_U, chLatin_N, chLatin_I, chLatin_C, chLatin_O, chLatin_N, chLatin_V, chNull
  };
  
  // These will hold the environment variable settings.
  bool gViewTranscoder;
  static bool gViewDebug;
  static int gForceTranscode;
  #define NO_FORCE 0
  #define MUST_USE_ICU  1
  #define MUST_USE_UNICONV  2
  
  // ---------------------------------------------------------------------------
  //  Local functions
  // ---------------------------------------------------------------------------
  
  // This is a local service routine to figure out the number of characters (not bytes)
  // in a unicode string.
  static unsigned int  getWideCharLength(const XMLCh* const src)
  {
     if (!src)
        return 0;
     unsigned int len = 0;
     const XMLCh* pTmp = src;
     while (*pTmp++)
        len++;
     return len;
  }
  
  // This is a local service routine to open a transcoder to/from unicode.
  static uniconvconverter * addConverter(const char* const EncodingName
                               ,XMLTransService::Codes& resValue)
  {
  DBGPRINTF1("Add converter\n");
     uniconvconverter *tconv = new uniconvconverter;
     tconv->fIconv390DescriptorFrom = uniconv_open("UCS-2",EncodingName);
     if (tconv->fIconv390DescriptorFrom <= (uniconv_t)(0)) {
  DBGPRINTF2("uniconv_open from failed rc=%d\n",(int)tconv->fIconv390DescriptorFrom);
        resValue = XMLTransService::UnsupportedEncoding;
        delete tconv;
        return 0;
     }
     tconv->fIconv390DescriptorTo = uniconv_open(EncodingName,"UCS-2");
     if (tconv->fIconv390DescriptorTo <= (uniconv_t)(0)) {
  DBGPRINTF2("uniconv_open to failed rc=%d\n",(int)tconv->fIconv390DescriptorTo);
        resValue = XMLTransService::UnsupportedEncoding;
        uniconv_close(tconv->fIconv390DescriptorFrom);
        delete tconv;
        return 0;
     }
     return tconv;
  }
  
  // This is a local service routine to close the transcoders.
  static void removeConverter(uniconvconverter* const converter)
  {
  DBGPRINTF1("remove converter\n");
     if (converter) {
        uniconv_close(converter->fIconv390DescriptorFrom);
        uniconv_close(converter->fIconv390DescriptorTo);
        delete converter;
     }
  }
  
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // *************** Uniconv390TransService Class ******************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // ---------------------------------------------------------------------------
  //  Uniconv390TransService: Constructor and Destructor
  // ---------------------------------------------------------------------------
  Uniconv390TransService::Uniconv390TransService()
  {
  
     fCaseConverter = new uniconvcaseconverter;
     fCaseConverter->ftoupperhand=UNICONV_NOHANDLE;
     fCaseConverter->ftolowerhand=UNICONV_NOHANDLE;
  
     char * myenviron = getenv("_IXM_FORCE_CONVERSION");
     gForceTranscode = NO_FORCE;
     if ( !strcmp(myenviron,"USE_ICU") )
        gForceTranscode = MUST_USE_ICU;
     else if ( !strcmp(myenviron,"USE_NATIVE") )
        gForceTranscode = MUST_USE_UNICONV;
    DBGPRINTF3("FORCE PARM=%s %d\n",myenviron,gForceTranscode);
  
     fICUService = new ICUTransService;
  
     gViewTranscoder = false;
     if ( !strcmp(getenv("_IXM_VIEW_CONVERSION"),"YES") )
        gViewTranscoder = true;
  
     gViewDebug = false;
     if ( !strcmp(getenv("_IXM_DEBUG_CONVERSION"),"YES") )
        gViewDebug = true;
  }
  
  Uniconv390TransService::~Uniconv390TransService()
  {
     if ( (fCaseConverter->ftoupperhand!=UNICONV_NOHANDLE) &&
          (fCaseConverter->ftoupperhand!=UNICONV_ERROR) ) {
        uniconv_toupper_close(fCaseConverter->ftoupperhand);
        fCaseConverter->ftoupperhand=UNICONV_NOHANDLE;
     }
     if ( (fCaseConverter->ftolowerhand!=UNICONV_NOHANDLE) &&
          (fCaseConverter->ftolowerhand!=UNICONV_ERROR) ) {
        uniconv_tolower_close(fCaseConverter->ftolowerhand);
        fCaseConverter->ftolowerhand=UNICONV_NOHANDLE;
     }
     if (fCaseConverter) {
        delete [] fCaseConverter;
        fCaseConverter=0;
     }
  }
  
  // ---------------------------------------------------------------------------
  //  Uniconv390TransService: The virtual transcoding service API
  // ---------------------------------------------------------------------------
  int Uniconv390TransService::compareIString(const   XMLCh* const    comp1
                                      , const XMLCh* const    comp2)
  {
  
  //char localname1[500];
  //XMLString::transcode(comp1,localname1,400);
  //char localname2[500];
  //XMLString::transcode(comp2,localname2,400);
  //DBGPRINTF3("comparing %s %s \n",localname1,localname2);
  //printf("toupper handle=%x\n",fCaseConverter->ftoupperhand);
  
     if (fCaseConverter->ftoupperhand!=UNICONV_ERROR) {
        const XMLCh* psz1 = comp1;
        const XMLCh* psz2 = comp2;
        XMLCh tmp1;
        XMLCh tmp2;
  
        XMLMutexLock lockcaser(&fCaseConverter->fcaseMutex);
        if (fCaseConverter->ftoupperhand==UNICONV_NOHANDLE) {
           fCaseConverter->ftoupperhand=uniconv_toupper_open();
        }
  
        unsigned int curCount = 0;
        while (fCaseConverter->ftoupperhand!=UNICONV_ERROR)
        {
           tmp1 = uniconv_caseit(fCaseConverter->ftoupperhand,*psz1);
           if (errno==0)
              tmp2 = uniconv_caseit(fCaseConverter->ftoupperhand,*psz2);
           if (errno) {
              uniconv_toupper_close(fCaseConverter->ftoupperhand);
              fCaseConverter->ftoupperhand=UNICONV_ERROR;
              break;
           }
  
           //
           //  If an inequality, then return the difference.
           //
           if (tmp1 != tmp2)
              return int(*psz1) - int(*psz2);
  
           // If either has ended, then they both ended, so equal
           if (!*psz1 || !*psz2)
              break;
  
           // Move upwards for the next round
           psz1++;
           psz2++;
        }
     }
     // check if unicode services does not support upper casing again, then call ICU.
     if (fCaseConverter->ftoupperhand == UNICONV_ERROR) {
        return fICUService->compareIString(comp1,comp2);
     }
     return 0;
  }
  
  
  int Uniconv390TransService::compareNIString(const  XMLCh* const    comp1
                                      , const XMLCh* const    comp2
                                      , const unsigned int    maxChars)
  {
  //char localname1[500];
  //XMLString::transcode(comp1,localname1,400);
  //char localname2[500];
  //XMLString::transcode(comp2,localname2,400);
  //DBGPRINTF3("comparing NI %s %s \n",localname1,localname2);
  //printf("toupper handle=%x\n",fCaseConverter->ftoupperhand);
  //printf("!!!***comparing NI %s %s\n",localname1,localname2);
  
     if (fCaseConverter->ftoupperhand!=UNICONV_ERROR) {
        const XMLCh* psz1 = comp1;
        const XMLCh* psz2 = comp2;
        XMLCh tmp1;
        XMLCh tmp2;
  
        XMLMutexLock lockcaser(&fCaseConverter->fcaseMutex);
        if (fCaseConverter->ftoupperhand==UNICONV_NOHANDLE) {
           fCaseConverter->ftoupperhand=uniconv_toupper_open();
        }
  
        unsigned int curCount = 0;
        while (fCaseConverter->ftoupperhand!=UNICONV_ERROR) {
           tmp1 = uniconv_caseit(fCaseConverter->ftoupperhand,*psz1);
           if (errno==0)
              tmp2 = uniconv_caseit(fCaseConverter->ftoupperhand,*psz2);
           if (errno) {
              uniconv_toupper_close(fCaseConverter->ftoupperhand);
              fCaseConverter->ftoupperhand=UNICONV_ERROR;
              break;
           }
  
           //
           //  If an inequality, then return the difference.
           //
           if (tmp1 != tmp2)
              return int(*psz1) - int(*psz2);
  
           // If either ended, then both ended, so equal
           if (!*psz1 || !*psz2)
              break;
  
           // Move upwards to next chars
           psz1++;
           psz2++;
  
           //
           //  Bump the count of chars done. If it equals the count then we
           //  are equal for the requested count, so break out and return
           //  equal.
           //
           curCount++;
           if (maxChars == curCount)
              break;
        }
     }
     // check if unicode services does not support upper casing, then call ICU.
     if (fCaseConverter->ftoupperhand == UNICONV_ERROR) {
        return fICUService->compareNIString(comp1,comp2,maxChars);
     }
     return 0;
  }
  
  
  const XMLCh* Uniconv390TransService::getId() const
  {
     return gMyServiceId;
  }
  
  bool Uniconv390TransService::isSpace(const XMLCh toCheck) const
  {
  DBGPRINTF2("isspace checking %x\n",toCheck);
     unsigned short chartype = XMLUniCharacter::getType(toCheck);
     if ( (chartype == XMLUniCharacter::SPACE_SEPARATOR) ||
          (chartype == XMLUniCharacter::LINE_SEPARATOR)   ||
          (chartype == XMLUniCharacter::PARAGRAPH_SEPARATOR) )
        return true;
     else
        return false;
  }
  
  bool Uniconv390TransService::supportsSrcOfs() const
  {
     return false;
  }
  
  void Uniconv390TransService::upperCase(XMLCh* const toUpperCase) const
  {
  
  //char localname1[500];
  //XMLString::transcode(toUpperCase,localname1,400);
  //DBGPRINTF2("upper casing %s \n",localname1);
  //printf("toupper handle=%x\n",fCaseConverter->ftoupperhand);
  
     if (fCaseConverter->ftoupperhand!=UNICONV_ERROR) {
        XMLCh* outPtr = toUpperCase;
  
        XMLMutexLock lockcaser(&fCaseConverter->fcaseMutex);
        if (fCaseConverter->ftoupperhand==UNICONV_NOHANDLE) {
           fCaseConverter->ftoupperhand=uniconv_toupper_open();
        }
  
        unsigned int curCount = 0;
        while ((fCaseConverter->ftoupperhand!=UNICONV_ERROR) && (*outPtr) ) {
           XMLCh tmp = uniconv_caseit(fCaseConverter->ftoupperhand,*outPtr);
           if (errno) {
              uniconv_toupper_close(fCaseConverter->ftoupperhand);
              fCaseConverter->ftoupperhand=UNICONV_ERROR;
              break;
           }
           *outPtr = tmp;
           outPtr++;
        }
     }
     if (fCaseConverter->ftoupperhand==UNICONV_ERROR) {
       return fICUService->upperCase(toUpperCase);
     }
  }
  
  void Uniconv390TransService::lowerCase(XMLCh* const toLowerCase) const
  {
  //char localname1[500];
  //XMLString::transcode(toLowerCase,localname1,400);
  //DBGPRINTF2("lower casing %s \n",localname1);
  //printf("tolower handle=%x\n",fCaseConverter->ftolowerhand);
  //printf("!!!***Lower casing function called: %s \n",localname1);
  
  
  
     if (fCaseConverter->ftolowerhand!=UNICONV_ERROR) {
        XMLCh* outPtr = toLowerCase;
  
        XMLMutexLock lockcaser(&fCaseConverter->fcaseMutex);
        if (fCaseConverter->ftolowerhand==UNICONV_NOHANDLE) {
           fCaseConverter->ftolowerhand=uniconv_tolower_open();
        }
  
        unsigned int curCount = 0;
        while ((fCaseConverter->ftolowerhand!=UNICONV_ERROR) && (*outPtr) ) {
           XMLCh tmp = uniconv_caseit(fCaseConverter->ftolowerhand,*outPtr);
           if (errno) {
              uniconv_tolower_close(fCaseConverter->ftolowerhand);
              fCaseConverter->ftolowerhand=UNICONV_ERROR;
              break;
           }
           *outPtr = tmp;
           outPtr++;
        }
     }
     if (fCaseConverter->ftolowerhand==UNICONV_ERROR) {
       return fICUService->lowerCase(toLowerCase);
     }
  }
  
  XMLLCPTranscoder* Uniconv390TransService::makeNewLCPTranscoder()
  {
     XMLTransService::Codes resValue;
  DBGPRINTF2("makeNewLCPTranscoder() localencoding=%s \n",nl_langinfo(CODESET));
     // USS default code page is IBM-1047
     if (gForceTranscode == MUST_USE_ICU) {
        if (gViewTranscoder)
           printf("IXM1004I LCP - Using ICU - %s\n",nl_langinfo(CODESET));
        fLCPTranscoder = fICUService->makeNewLCPTranscoder();
     } else {
        char codepage[32];
        sprintf(codepage,"%s-s390", nl_langinfo(CODESET));
        uniconvconverter *tconv=addConverter(codepage,resValue);
        DBGPRINTF3("gForce=%d,tconv=%x\n",gForceTranscode,(int)tconv);
  
        if (tconv) {
           if (gViewTranscoder)
              printf("IXM1005I LCP - Using Unicode Services - %s\n",nl_langinfo(CODESET));
           fLCPTranscoder = new Uniconv390LCPTranscoder(tconv);
        } else {
           if (gForceTranscode != MUST_USE_UNICONV) {
              if (gViewTranscoder)
                 printf("IXM1006I LCP - Using ICU - %s\n",nl_langinfo(CODESET));
              fLCPTranscoder = fICUService->makeNewLCPTranscoder();
           }
        }
     }
     return fLCPTranscoder;
  }
  
  // ---------------------------------------------------------------------------
  //  Uniconv390TransService: The protected virtual transcoding service API
  // ---------------------------------------------------------------------------
  XMLTranscoder* Uniconv390TransService::
  makeNewXMLTranscoder(const  XMLCh* const            encodingName
                      ,       XMLTransService::Codes& resValue
                      , const unsigned int            blockSize)
  {
  char * localname = XMLString::transcode(encodingName);
  ArrayJanitor<char> janText((char*)localname);
  DBGPRINTF3("makeNewXMLTranscoder() encoding=%s blocksize=%d\n",localname,blockSize);
  
     if (gForceTranscode == MUST_USE_ICU) {
        if (gViewTranscoder)
           printf("IXM1001I XML - Using ICU - %s\n",localname);
        return fICUService->makeNewXMLTranscoder(encodingName,resValue,blockSize);
     }
  
     uniconvconverter *tconv=addConverter(localname,resValue);
  
     if (tconv == 0) {
        DBGPRINTF1("uniconv failed!!!!!!!!\n");
        if (gForceTranscode == MUST_USE_UNICONV)
           return 0;
        else {
           if (gViewTranscoder)
              printf("IXM1002I XML - Using ICU - %s\n",localname);
           return fICUService->makeNewXMLTranscoder(encodingName,resValue,blockSize);
        }
     }
  
     if (gViewTranscoder)
        printf("IXM1003I XML - Using Unicode Services - %s\n",localname);
     return new Uniconv390Transcoder(encodingName, tconv, blockSize);
  }
  
  
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // *************** Uniconv390Transcoder Class ********************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  
  // ---------------------------------------------------------------------------
  //  Uniconv390Transcoder: Constructors and Destructor
  // ---------------------------------------------------------------------------
  Uniconv390Transcoder::Uniconv390Transcoder(const  XMLCh* const        encodingName
                              ,        uniconvconverter_t * const   toAdopt
                              , const unsigned int        blockSize) :
      XMLTranscoder(encodingName, blockSize)
      , fConverter(toAdopt)
  {
  }
  
  Uniconv390Transcoder::~Uniconv390Transcoder()
  {
     // If there is a converter, clean it up
     if (fConverter) {
        removeConverter(fConverter);
        fConverter=0;
     }
  }
  
  
  // ---------------------------------------------------------------------------
  //  Uniconv390Transcoder: The virtual transcoder API
  // ---------------------------------------------------------------------------
  // ignore  charSizes since that is used to generate character offsets.
  unsigned int
  Uniconv390Transcoder::transcodeFrom(const  XMLByte* const          srcData
                              , const unsigned int            srcCount
                              ,       XMLCh* const            toFill
                              , const unsigned int            maxChars
                              ,       unsigned int&           bytesEaten
                              ,       unsigned char* const    charSizes)
  {
     unsigned int countIn = 0;
     unsigned int countOut = 0;
  DBGPRINTF2("Uniconv390Transcoder::transcodeFrom bytes=%d\n",srcCount);
     int retCode;
     char *tmpInPtr = (char *) srcData;
     char *tmpOutPtr = (char *) toFill;
     unsigned int inByteLeft = srcCount;
     unsigned int outByteLeft = maxChars*sizeof(XMLCh);
     { // locking scope
        XMLMutexLock lockConverter(&fConverter->fMutex);
        retCode = uniconv(fConverter->fIconv390DescriptorFrom, &tmpInPtr, &inByteLeft, &tmpOutPtr, &outByteLeft);
     }
  DBGPRINTF5("Uniconv390Transcoder::transcodeFrom iconv finished, rc=%d inleft=%d outleft=%d errno=%d \n",retCode,inByteLeft,outByteLeft,errno);
     if ( (retCode < 0 ) && (errno != E2BIG) ) {
        return 0;
     }
  
     // Give back the counts of eaten and transcoded
     bytesEaten = srcCount-inByteLeft;
     return maxChars-outByteLeft/sizeof(XMLCh);
  }
  
  // The returned int is really supposed to be the number of bytes, not chars!
  unsigned int
  Uniconv390Transcoder::transcodeTo( const   XMLCh* const    srcData
                              , const unsigned int    srcCount
                              ,       XMLByte* const  toFill
                              , const unsigned int    maxBytes
                              ,       unsigned int&   charsEaten
                              , const UnRepOpts       options)
  {
     unsigned int countIn = 0;
     unsigned int countOut = 0;
  DBGPRINTF2("Uniconv390Transcoder::transcodeTo bytes=%d\n",srcCount);
  
     int retCode;
     char *tmpInPtr = (char *) srcData;
     char *tmpOutPtr = (char *) toFill;
     unsigned int inByteLeft = srcCount*sizeof(XMLCh);
     unsigned int outByteLeft = maxBytes;
     { // locking scope
        XMLMutexLock lockConverter(&fConverter->fMutex);
        retCode = uniconv(fConverter->fIconv390DescriptorTo, &tmpInPtr, &inByteLeft, &tmpOutPtr, &outByteLeft);
     }
     if ( (retCode < 0) && (errno != E2BIG) ) {
        return 0;
     }
  
     // Give back the counts of eaten and transcoded
     charsEaten = srcCount-inByteLeft/sizeof(XMLCh);
     return maxBytes-outByteLeft;
  }
  
  
  bool Uniconv390Transcoder::canTranscodeTo(const unsigned int toCheck) const
  {
     int retCode;
  DBGPRINTF1("Uniconv390Transcoder::canTranscodeTo\n");
  //printf("!!!***Uniconv390Transcoder::canTranscodeTo\n");
     //
     //  If the passed value is really a surrogate embedded together, then
     //  we need to break it out into its two chars. Else just one. While
     //  we are ate it, convert them to UChar format if required.
     //
     XMLCh          srcBuf[2];
     unsigned int    srcCount = 1;
     if (toCheck & 0xFFFF0000) {
        srcBuf[0] = XMLCh((toCheck >> 10) + 0xD800);
        srcBuf[1] = XMLCh(toCheck & 0x3FF) + 0xDC00;
        srcCount++;
     } else {
        srcBuf[0] = XMLCh(toCheck);
     }
  
     // Set up a temp buffer to format into. Make it more than big enough
     char  tmpBuf[16];
  
     char *tmpInPtr = (char *) srcBuf;
     char *tmpOutPtr = (char *) tmpBuf;
     unsigned int inByteLeft = srcCount*sizeof(XMLCh);
     unsigned int outByteLeft = 16;
  
     { // locking scope
        XMLMutexLock lockConverter(&fConverter->fMutex);
        retCode = uniconv(fConverter->fIconv390DescriptorTo, &tmpInPtr, &inByteLeft, &tmpOutPtr, &outByteLeft);
     }
     if ( (retCode < 0) && (errno != E2BIG) ) {
        return false;
     }
  
     return true;
  }
  
  
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // *************** Uniconv390LCPTranscoder Class *****************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  // ***************************************************************************
  
  
  // ---------------------------------------------------------------------------
  //  Uniconv390LCPTranscoder: Constructor and Destructor
  // ---------------------------------------------------------------------------
  Uniconv390LCPTranscoder::Uniconv390LCPTranscoder( uniconvconverter_t* const toAdopt) :
  
      fConverter(toAdopt)
  {
  }
  
  Uniconv390LCPTranscoder::~Uniconv390LCPTranscoder()
  {
      // If there is a converter, clean it up
     if (fConverter) {
        removeConverter(fConverter);
        fConverter=0;
     }
  }
  
  
  // ---------------------------------------------------------------------------
  //  Uniconv390LCPTranscoder: calcRequiredSize
  //
  // The only way I can find to reliably determine the exact required size is to actually
  // transcode the string and see how long it is. Fortunately, this is only done as a last
  // ditch effort so it should only be used very rarely (if at all).
  // ---------------------------------------------------------------------------
  unsigned int Uniconv390LCPTranscoder::calcRequiredSize(const XMLCh* const srcText)
  {
  DBGPRINTF1("Uniconv390LCPTranscoder::calcRequiredSize(const XMLCh* const srcText)  \n");
  //printf("!!!***Uniconv390LCPTranscoder::calcRequiredSize(const XMLCh* const srcText)  \n");
     int thesize=0;
     if (!srcText)
        return 0;
     if (!*srcText)
        return 0;
  
     char * result = transcode(srcText);
     if (result) {
        thesize = strlen(result);
        delete [] result;
     }
     return thesize;
  }
  
  unsigned int Uniconv390LCPTranscoder::calcRequiredSize(const char* const srcText)
  {
  DBGPRINTF1("Uniconv390LCPTranscoder::calcRequiredSize(const char* const srcText)  \n");
  //printf("!!!***Uniconv390LCPTranscoder::calcRequiredSize(const char* const srcText)  \n");
     int thesize=0;
     if (!srcText)
        return 0;
     if (!*srcText)
        return 0;
  
     XMLCh * result = transcode(srcText);
     if (result) {
        thesize = getWideCharLength(result);
        delete [] result;
     }
  
  DBGPRINTF2("Uniconv390LCPTranscoder::calcRequiredSize(const char* const srcText) %d  \n",thesize);
     return thesize;
  }
  
  
  // ---------------------------------------------------------------------------
  //  Uniconv390LCPTranscoder: transcode
  //
  // Now what follows are various methods to transcode to/from unicode.
  // ---------------------------------------------------------------------------
  char* Uniconv390LCPTranscoder::transcode(const XMLCh* const toTranscode)
  {
  //printf("Uniconv390LCPTranscoder::transcode(const XMLCh* const toTranscode) ");
  //printf("transcode handle=%x\n",fConverter->fIconv390DescriptorTo);
     if (!toTranscode)
        return 0;
  
     char* retVal = 0;
      // find out the length of the source and use this as an estimate for the needed buffer length.
     unsigned int  wLent = getWideCharLength(toTranscode);
     if (wLent == 0) {
        retVal = new char[1];
        retVal[0] = 0;
        return retVal;
     }
     retVal = new char[wLent * 2 + 1]; // get double just to be sure.
     while (true) {
        int retCode;
        char *tmpInPtr = (char*) toTranscode;
        char *tmpOutPtr = (char*) retVal;
        unsigned int inByteLeft = wLent*sizeof(XMLCh);
        unsigned int outByteLeft = wLent*sizeof(XMLCh);
  //printf("!!!transcode len=%d\n",wLent);
  
        { // Locking scope
           XMLMutexLock lockConverter(&fConverter->fMutex);
           retCode = uniconv(fConverter->fIconv390DescriptorTo, &tmpInPtr, &inByteLeft, &tmpOutPtr, &outByteLeft);
        }
  //printf("!!!transcode uniconv finished rc=%d errno=%d\n",retCode,errno);
        // If the data does not fit into our estimation of the buffer size, then delete the buffer,
        // double the estimated length and try again.
        if ( ((retCode < 0) && (errno == E2BIG)) || (outByteLeft == 0) ) {
  //printf("!!!Uniconv390LCPTranscoder::transcode(const XMLCh* const toTranscode):Retrying with a bigger buffer.......\n");
           delete [] retVal;
           wLent*=2;
           retVal = new char[wLent*sizeof(XMLCh) + 1];
        }
        // If uniconv doesn't complete for any other reason, then return failure.
        else if (retCode < 0) {
           return 0;
        }
        // it was successful so break out of the loop
        else {
           *tmpOutPtr = 0x00;
           break;
        }
     }
  //printf("Uniconv390LCPTranscoder::transcode(const XMLCh* const toTranscode):%s\n",retVal);
     return retVal;
  }
  
  XMLCh* Uniconv390LCPTranscoder::transcode(const char* const toTranscode)
  {
  DBGPRINTF2("Uniconv390LCPTranscoder::transcode(const char* const toTranscode):%s \n",toTranscode);
  //printf("transcode handle=%x\n",fConverter->fIconv390DescriptorFrom);
     if (!toTranscode)
        return 0;
  
     XMLCh* retVal = 0;
     const unsigned int len = strlen(toTranscode);
     retVal = new XMLCh[len + 1]; // +1 is for the null terminator!
     if (len == 0) {
        retVal[0] = 0;
        return retVal;
     }
  
     int retCode;
     char *tmpInPtr = (char*) toTranscode;
     char *tmpOutPtr = (char*) retVal;
     unsigned int inByteLeft = len;
     unsigned int outByteLeft = len*sizeof(XMLCh);
     { // locking scope
        XMLMutexLock lockConverter(&fConverter->fMutex);
        retCode = uniconv(fConverter->fIconv390DescriptorFrom, &tmpInPtr, &inByteLeft, &tmpOutPtr, &outByteLeft);
     }
     // Because we check the length in the beginning, and we make sure the output buffer
     // is big enough, uniconv should complete the transcoding. If it doesn't for any reason, then
     // return failure.
     if (retCode < 0) {
        delete [] retVal;
        return 0;
     }
     *tmpOutPtr = 0x00;
     *(tmpOutPtr+1) = 0x00;
     return retVal;
  }
  
  
  bool Uniconv390LCPTranscoder::transcode(const  char* const     toTranscode
                                  ,       XMLCh* const    toFill
                                  , const unsigned int    maxChars)
  {
  DBGPRINTF1("Uniconv390LCPTranscoder::transcode(const  char* const     toTranscode, etc.... \n");
  //printf("transcode handle=%x\n",fConverter->fIconv390DescriptorFrom);
      // Check for a couple of psycho corner cases
     if (!toTranscode || !maxChars) {
        toFill[0] = 0;
        return true;
     }
  
     unsigned int  Lent = strlen(toTranscode);
     if (Lent == 0) {
        toFill[0] = 0;
        return true;
     }
  
     int retCode;
     char *tmpInPtr = (char*) toTranscode;
     char *tmpOutPtr = (char*) toFill;
     unsigned int inByteLeft = Lent;
     unsigned int outByteLeft = maxChars*2;
     { // locking scope
        XMLMutexLock lockConverter(&fConverter->fMutex);
        retCode = uniconv(fConverter->fIconv390DescriptorFrom, &tmpInPtr, &inByteLeft, &tmpOutPtr, &outByteLeft);
     }
     // Because we check the length in the beginning, and the caller makes sure that the output buffer
     // is big enough, uniconv should complete the transcoding. If it doesn't for any reason, then
     // return failure.
     if (retCode < 0) {
        return false;
     }
     *tmpOutPtr = 0x00;
     *(tmpOutPtr+1) = 0x00;
     return true;
  }
  
  
  bool Uniconv390LCPTranscoder::transcode(   const   XMLCh* const    toTranscode
                                      ,       char* const     toFill
                                      , const unsigned int    maxBytes)
  {
  DBGPRINTF1("Uniconv390LCPTranscoder::transcode(const  XMLCh* const     toTranscode, etc.... \n");
  //printf("transcode handle=%x\n",fConverter->fIconv390DescriptorTo);
     // Watch for a couple of pyscho corner cases
     if (!toTranscode || !maxBytes) {
        toFill[0] = 0;
        return true;
     }
     //-------------------
     unsigned int  wLent = getWideCharLength(toTranscode);
     if (wLent == 0) {
        toFill[0] = 0;
        return true;
     }
     int retCode;
     char *tmpInPtr = (char*) toTranscode;
     char *tmpOutPtr = (char*) toFill;
     unsigned int inByteLeft = wLent*sizeof(XMLCh);
     unsigned int outByteLeft = maxBytes;
     { // locking scope
        XMLMutexLock lockConverter(&fConverter->fMutex);
        retCode = uniconv(fConverter->fIconv390DescriptorTo, &tmpInPtr, &inByteLeft, &tmpOutPtr, &outByteLeft);
     }
  
     // Because we check the length in the beginning, and the caller makes sure that the output buffer
     // is big enough, uniconv should complete the transcoding. If it doesn't for any reason, then
     // return failure.
     if (retCode < 0) {
        return false;
     }
     *tmpOutPtr = 0x00;
     return true;
  }
  
  XERCES_CPP_NAMESPACE_END
  
  
  
  1.1                  xml-xerces/c/src/xercesc/util/Transcoders/Uniconv390/Uniconv390TransService.hpp
  
  Index: Uniconv390TransService.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Id: Uniconv390TransService.hpp,v 1.1 2002/11/22 14:57:06 tng Exp $
   */
  
  #ifndef UNICONV390TRANSSERVICE_HPP
  #define UNICONV390TRANSSERVICE_HPP
  
  #include <xercesc/util/Mutexes.hpp>
  #include <xercesc/util/TransService.hpp>
  #include <xercesc/util/Transcoders/ICU/ICUTransService.hpp>
  #include "uniconv.h"
  
  XERCES_CPP_NAMESPACE_BEGIN
  
  typedef struct uniconvconverter {
     XMLMutex               fMutex;
     uniconv_t                fIconv390DescriptorFrom;
     uniconv_t                fIconv390DescriptorTo;
  } uniconvconverter_t;
  
  typedef struct uniconvcaseconverter {
     XMLMutex  fcaseMutex;
     uniconv_t ftoupperhand;
     uniconv_t ftolowerhand;
  } uniconvcaseconverter_t;
  
  class XMLUTIL_EXPORT Uniconv390TransService : public XMLTransService
  {
  public :
      // -----------------------------------------------------------------------
      //  Constructors and Destructor
      // -----------------------------------------------------------------------
      Uniconv390TransService();
      ~Uniconv390TransService();
  
  
      // -----------------------------------------------------------------------
      //  Implementation of the virtual transcoding service API
      // -----------------------------------------------------------------------
      virtual int compareIString
      (
          const   XMLCh* const    comp1
          , const XMLCh* const    comp2
      );
  
      virtual int compareNIString
      (
          const   XMLCh* const    comp1
          , const XMLCh* const    comp2
          , const unsigned int    maxChars
      );
  
      virtual const XMLCh* getId() const;
  
      virtual bool isSpace(const XMLCh toCheck) const;
  
      virtual XMLLCPTranscoder* makeNewLCPTranscoder();
  
      virtual bool supportsSrcOfs() const;
  
      virtual void upperCase(XMLCh* const toUpperCase) const;
      virtual void lowerCase(XMLCh* const toLowerCase) const;
  
  protected :
      // -----------------------------------------------------------------------
      //  Protected virtual methods
      // -----------------------------------------------------------------------
      virtual XMLTranscoder* makeNewXMLTranscoder
      (
          const   XMLCh* const            encodingName
          ,       XMLTransService::Codes& resValue
          , const unsigned int            blockSize
      );
  
  
  private :
      // -----------------------------------------------------------------------
      //  Unimplemented constructors and operators
      // -----------------------------------------------------------------------
      Uniconv390TransService(const Uniconv390TransService&);
      void operator=(const Uniconv390TransService&);
      ICUTransService * fICUService;
      XMLLCPTranscoder* fLCPTranscoder;
      uniconvcaseconverter_t *fCaseConverter;
  };
  
  
  
  class XMLUTIL_EXPORT Uniconv390Transcoder : public XMLTranscoder
  {
  public :
      // -----------------------------------------------------------------------
      //  Constructors and Destructor
      // -----------------------------------------------------------------------
      Uniconv390Transcoder
      (
          const   XMLCh* const        encodingName
          ,        uniconvconverter_t* const   toAdopt
          , const unsigned int        blockSize
      );
      ~Uniconv390Transcoder();
  
  
      // -----------------------------------------------------------------------
      //  Implementation of the virtual transcoder interface
      // -----------------------------------------------------------------------
      virtual unsigned int transcodeFrom
      (
          const   XMLByte* const          srcData
          , const unsigned int            srcCount
          ,       XMLCh* const            toFill
          , const unsigned int            maxChars
          ,       unsigned int&           bytesEaten
          ,       unsigned char* const    charSizes
      );
  
      virtual unsigned int transcodeTo
      (
          const   XMLCh* const    srcData
          , const unsigned int    srcCount
          ,       XMLByte* const  toFill
          , const unsigned int    maxBytes
          ,       unsigned int&   charsEaten
          , const UnRepOpts       options
      );
  
      virtual bool canTranscodeTo
      (
          const   unsigned int    toCheck
      )   const;
  
  
  
  private :
      // -----------------------------------------------------------------------
      //  Unimplemented constructors and operators
      // -----------------------------------------------------------------------
      Uniconv390Transcoder();
      Uniconv390Transcoder(const Uniconv390Transcoder&);
      void operator=(const Uniconv390Transcoder&);
  
      ICUTranscoder * fICUTranscoder;
  
      // -----------------------------------------------------------------------
      //  Private data members
      //
      //  fConverter
      //      This is a pointer to the converter structure that this transcoder
      //      uses.
      //
      // -----------------------------------------------------------------------
      uniconvconverter_t *fConverter;
  };
  
  
  class XMLUTIL_EXPORT Uniconv390LCPTranscoder : public XMLLCPTranscoder
  {
  public :
      // -----------------------------------------------------------------------
      //  Constructors and Destructor
      // -----------------------------------------------------------------------
      Uniconv390LCPTranscoder( uniconvconverter_t* const toAdopt);
      ~Uniconv390LCPTranscoder();
  
  
      // -----------------------------------------------------------------------
      //  Implementation of the virtual transcoder interface
      // -----------------------------------------------------------------------
      virtual unsigned int calcRequiredSize(const char* const srcText);
  
      virtual unsigned int calcRequiredSize(const XMLCh* const srcText);
  
      virtual char* transcode(const XMLCh* const toTranscode);
  
      virtual XMLCh* transcode(const char* const toTranscode);
  
      virtual bool transcode
      (
          const   char* const     toTranscode
          ,       XMLCh* const    toFill
          , const unsigned int    maxChars
      );
  
      virtual bool transcode
      (
          const   XMLCh* const    toTranscode
          ,       char* const     toFill
          , const unsigned int    maxChars
      );
  
  
  
  private :
      // -----------------------------------------------------------------------
      //  Unimplemented constructors and operators
      // -----------------------------------------------------------------------
      Uniconv390LCPTranscoder();
      Uniconv390LCPTranscoder(const Uniconv390LCPTranscoder&);
      void operator=(const Uniconv390LCPTranscoder&);
  
      ICULCPTranscoder * fICULCPTranscoder;
  
      // -----------------------------------------------------------------------
      //  Private data members
      //
      //  fConverter
      //      This is a pointer to the converter structure that this transcoder
      //      uses.
      // -----------------------------------------------------------------------
      uniconvconverter_t *fConverter;
  };
  
  XERCES_CPP_NAMESPACE_END
  
  #endif
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org