home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / rxjis096.zip / rxjis.cpp < prev    next >
C/C++ Source or Header  |  1999-12-21  |  100KB  |  2,908 lines

  1. /* product name: RXJIS                                                */
  2. /* Version:      0.95                                                 */
  3. /* author:       YANO Takashi                                         */
  4. /* target:       OS/2 Warp J3.0+ (J2.1 is possible)                   */
  5. /* module name:  RXJIS.DLL                                            */
  6. /* source name:  RXJIS.CPP                                            */
  7. /* compiler:     VisualAge C++ 3.0                                    */
  8. /* address:      tyano@ca2.so-net.or.jp or tyano@yamato.ibm.co.jp     */
  9. /* comment:      RXJIS is a utility functions for REXX.               */
  10. /*               It encodes and decodes JIS 7 bit strings and MIME    */
  11. /*               format strings.                                      */
  12. /*                                                                    */
  13. /*               It provides the functions:                           */
  14. /*               RxJisToPc                                            */
  15. /*               RxJisJisTo                                           */
  16. /*               RxJisDropFuncs                                       */
  17. /*               RxJisToJis                                           */
  18. /*               RxJisToBase64                                        */
  19. /*               RxJisToQuotedPrintable                               */
  20. /*               RxJisBase64To                                        */
  21. /*               RxJisEucTo                                           */
  22. /*               RxJisToEuc                                           */
  23. /*               RxJisQuotedPrintableTo                               */
  24. /*               RxJisLoadFuncs                                       */
  25. /*               RxJisMimeJisTo                                       */
  26. /*               RxJisJisCharJisTo                                    */
  27. /*               RxJisJisToCharJisTo                                  */
  28. /*               RxJisJisIso8859_1ToCp850                             */
  29. /*               RxJisJisIso8859_2ToCp852                             */
  30. /*               RxJisJisIso8859_9ToCp857                             */
  31. /*               RxJisJisCp850ToIso8859_1                             */
  32. /*               RxJisJisCp852ToIso8859_2                             */
  33. /*               RxJisJisCp857ToIso8859_9                             */
  34. /*               RxJisJisToZenkakuKatakana                            */
  35. /*               RxJisWord                                            */
  36. /*               RxJisWords                                           */
  37. /*               RxJisWordIndex                                       */
  38. /*               RxJisPriority                                        */
  39. /*               RxJisKanjiAlias                                      */
  40. /*               JisFindWord (C/C++ only)                             */
  41. /* history:      1996-2-5  0.00 initial release                       */
  42. /*               1996-2-14 0.10 if find alone reset sequence,         */
  43. /*                         add the set seq at the head.               */
  44. /*                         reduce dll size                            */
  45. /*               1996-3-20 0.20 JIS90 support                         */
  46. /*                              Handle umatch JIS sequence            */
  47. /*                              EUC support                           */
  48. /*               1996-4-21 0.30 JIS78 support                         */
  49. /*                              Performance inprovement               */
  50. /*                              Add .HPP/.LIB                         */
  51. /*               1996-5-1  0.40 Add RxJisMimeJis                      */
  52. /*               1996-5-19 0.50 Add RxJisToDbcs                       */
  53. /*                              Add RxJisToSbcs                       */
  54. /*                              Add RxJisToAscii                      */
  55. /*                              Add RxJisToUpper                      */
  56. /*               1996-5-24 0.51 Fix RxJisToJis bug                    */
  57. /*               1996-5-27 0.52 Fix RxJisToJis bug                    */
  58. /*                              Fix Version No                        */
  59. /*               1996-6-20 0.60 Fix RxJisToDbcs bug                   */
  60. /*                              Try to use JIS instead of IBM unique  */
  61. /*                              in RxJisToJis/RxJisToEuc              */
  62. /*                              Add RxJisJisIso8859_1ToCp850          */
  63. /*                              Add RxJisJisIso8859_2ToCp852          */
  64. /*                              Add RxJisJisIso8859_9ToCp857          */
  65. /*                              Add RxJisJisCp850ToIso8859_1          */
  66. /*                              Add RxJisJisCp852ToIso8859_2          */
  67. /*                              Add RxJisJisCp857ToIso8859_9          */
  68. /*                              Fix RxJisQuotedPrintable bug          */
  69. /*                              Fix JisXX NULL term bug               */
  70. /*               1996-6-26 0.70 Add RxJisToZenkakuKatakana            */
  71. /*                              Add JIS codeset 3 support             */
  72. /*               1996-7-8  0.71 RxJisBase64To/RxJisToBase64 may not   */
  73. /*                              work as expected.                     */
  74. /*                              (from 0.70)                           */
  75. /*               1996-7-21 0.80 Add RxJisAppend                       */
  76. /*                              Add RxJisWord                         */
  77. /*                              Add RxJisWords                        */
  78. /*                              Add RxJisWordIndex                    */
  79. /*                              Add RxJisUrltoVar                     */
  80. /*               1996-7-22 0.81 Fix RxJisToJis bug - > 255 source     */
  81. /*               1996-8-19 0.82 Fix RxJisAppend -> blanks + char      */
  82. /*               1996-9-10 0.83 Add codepage 943 support              */
  83. /*                              Fix Ver bug                           */
  84. /*               1996-9-14 0.84 cp943 has NEC chars                   */
  85. /*               1996-10-28 0.86 Use ESC ( B instead of ESC ( J       */
  86. /*               1997-8-5 0.90  Add JisFindWord                       */
  87. /*                              Fix RxJisToZenkakuKatakana bug        */
  88. /*               1997-8-25 0.91 Add JisFindWord                       */
  89. /*               1997-9-5 0.92 Add RxJisKanjiAlias/RxJisPriority      */
  90. /*               1997-9-11 0.93 Add RxJisTrace                        */
  91. /*               1998-5-27 0.94 Fix old JIS<->new JIS conv problem    */
  92. /*                              Add RxJisSyslog                       */
  93. /*               1998-9-26 0.95 Fix RxJisToAscii bug (DBCS SPC->SBCS  */
  94. /*                              SP does not work                      */
  95. /*                                                                    */
  96.  
  97. #include <stdlib.h>
  98. #include <stdio.h>
  99. #include <limits.h>
  100. #include <string.h>
  101. #include <wcstr.h>
  102. #include <time.h>
  103. #include <ctype.h>
  104. #define INCL_DOSMODULEMGR
  105. #define INCL_DOSERRORS
  106. #define INCL_DOSMISC 
  107. #define INCL_DOSNLS
  108. #define INCL_DOSPROCESS
  109. #define INCL_DOSQUEUES
  110. #include <os2.h>
  111. #define INCL_RXFUNC
  112. #define INCL_RXSHV
  113. #include <rexxsaa.h>
  114. #include <pmwsock.h>
  115. #include "rxjis.h"
  116. #include "rxjistbl.hpp"
  117. #include "pctojis.hpp"
  118. #include "jis2pc.hpp"
  119. #include "jiscase.hpp"
  120.  
  121. #define CallingValid 0
  122. #define CallingInvalid 40
  123. #define RxJisDll "RXJIS"
  124. #define RxJisVersion "0.96" 
  125. #define Base64BitWidth 6
  126. #define ByteBitWidth 8
  127. #define MaxMimeLineSize 76
  128. #define Base64Mask 0x00003f
  129. #define HighByteMask 0x0000ff00
  130. #define Ht '\x09'
  131. #define Space ' '
  132. #define Esc '\x1b'
  133. #define EucMsb 0x0080                     
  134. #define ByteMsb 0x0080                     
  135. #define EucMask 0x007f                    
  136. #define EucSs2 0x008e                    
  137. #define EucSs3 0x008f
  138. #define JisEnvVarName "IPF_KEYS"          
  139. #define Jis90Value "NEWJIS"
  140. #define SyslogdVarName "RXJISSYSLOGD"
  141. #define Jis83InSeq DoubleByteSeqTable[0]  
  142. #define Jis83OutSeq DoubleByteSeqTable[6] 
  143. #define JisSpace 0x2121                   
  144. #define SI 0x0e
  145. #define SO 0x0f
  146. #define CpListSize 8
  147. #define BeginKinsoku L"üAüBüCüDüFüGüEüHüI!%üô),.:;?]}íúñÑüjüpülünüzürütüä>üvüxüJüKüfühüïüîüì▐▀üRüSüTüUü[üXé±âô▌éƒéíéúéÑéºé┴éßéπéσé∞â@âBâDâFâHâbâââàâçâÄâòâûº¿⌐¬½¼¡«»ü`ü±ü≡üÄ"
  148. #define EndKinsoku L"üiüoükümüuüwüy([{óüqüsüâ<üeügüÅ\\üÉ$@üù#üöüºüæüÆ"
  149. #define CodepageJapanese 932
  150. #define CodepageSaaJapanese 942
  151. #define CodepageNewJapanese 943
  152. #define PRINTFQNAME   "\\QUEUES\\PRINTF32"
  153.  
  154. #define RxJisCountCheck2(count, targetsize, sourcewide) \
  155.    if (count >= targetsize) { \
  156.       delete sourcewide; \
  157.       return (RxJisError); \
  158.    } /* endif */
  159.  
  160. extern "C" {
  161. RexxFunctionHandler RxJisLoadFuncs;
  162. RexxFunctionHandler RxJisDropFuncs;
  163. RexxFunctionHandler RxJisToJis;
  164. RexxFunctionHandler RxJisJisTo; 
  165. RexxFunctionHandler RxJisToEuc; 
  166. RexxFunctionHandler RxJisToPc;
  167. RexxFunctionHandler RxJisToBase64;
  168. RexxFunctionHandler RxJisToQuotedPrintable;
  169. RexxFunctionHandler RxJisBase64To;
  170. RexxFunctionHandler RxJisEucTo; 
  171. RexxFunctionHandler RxJisMimeJisTo; 
  172. RexxFunctionHandler RxJisQuotedPrintableTo;
  173. RexxFunctionHandler RxJisJisCharTo; 
  174. RexxFunctionHandler RxJisToJisChar; 
  175. RexxFunctionHandler RxJisToSbcs; 
  176. RexxFunctionHandler RxJisToDbcs; 
  177. RexxFunctionHandler RxJisToAscii; 
  178. RexxFunctionHandler RxJisToUpper; 
  179. RexxFunctionHandler RxJisToZenkakuKatakana; 
  180. RexxFunctionHandler RxJisIso8859_1ToCp850; 
  181. RexxFunctionHandler RxJisIso8859_2ToCp852; 
  182. RexxFunctionHandler RxJisIso8859_9ToCp857; 
  183. RexxFunctionHandler RxJisCp850ToIso8859_1; 
  184. RexxFunctionHandler RxJisCp852ToIso8859_2; 
  185. RexxFunctionHandler RxJisCp857ToIso8859_9; 
  186. RexxFunctionHandler RxJisWords; 
  187. RexxFunctionHandler RxJisWord; 
  188. RexxFunctionHandler RxJisWordIndex;        
  189. RexxFunctionHandler RxJisAppend;        
  190. RexxFunctionHandler RxJisUrlToVar;        
  191. RexxFunctionHandler RxJisKanjiAlias;        
  192. RexxFunctionHandler RxJisPriority;        
  193. RexxFunctionHandler RxJisTrace;        
  194. RexxFunctionHandler RxJisSyslog;        
  195. };
  196.  
  197. static const PSZ RxJisFuncsTable[] = {
  198.    "RxJisLoadFuncs",
  199.    "RxJisDropFuncs",
  200.    "RxJisToBase64",
  201.    "RxJisToQuotedPrintable",
  202.    "RxJisToJis",
  203.    "RxJisToEuc", 
  204.    "RxJisToPc",
  205.    "RxJisJisTo", 
  206.    "RxJisBase64To",
  207.    "RxJisEucTo", 
  208.    "RxJisMimeJisTo", 
  209.    "RxJisQuotedPrintableTo",
  210.    "RxJisJisCharTo", 
  211.    "RxJisToJisChar", 
  212.    "RxJisToSbcs", 
  213.    "RxJisToDbcs", 
  214.    "RxJisToAscii", 
  215.    "RxJisToUpper", 
  216.    "RxJisToZenkakuKatakana", 
  217.    "RxJisIso8859_1ToCp850", 
  218.    "RxJisIso8859_2ToCp852", 
  219.    "RxJisIso8859_9ToCp857", 
  220.    "RxJisCp850ToIso8859_1", 
  221.    "RxJisCp852ToIso8859_2", 
  222.    "RxJisCp857ToIso8859_9", 
  223.    "RxJisWords", 
  224.    "RxJisWord", 
  225.    "RxJisWordIndex", 
  226.    "RxJisAppend", 
  227.    "RxJisUrlToVar", 
  228.    "RxJisKanjiAlias", 
  229.    "RxJisPriority", 
  230.    "RxJisTrace", 
  231.    "RxJisSyslog", 
  232. };
  233.  
  234. static const size_t NoOfEntries = sizeof(RxJisFuncsTable) / sizeof(RxJisFuncsTable[0]);
  235.  
  236. static PWCHAR_T *JisX0212_1990ToPccodeTable = JisCodeToPcCodeTable;
  237. static BOOL TableIsLoaded = FALSE;
  238. static APIRET LoadRxJisTables(void);
  239. static BOOL (APIENTRY16 *NlsFindWord)(USHORT codepage, PSZ string, ULONG strlen, ULONG  position, PULONG pStartWord, PULONG pEndWord, PULONG pNextWord);
  240. static USHORT DefaultCodepage;
  241. static int SyslogdSocket = -1;
  242. static struct sockaddr_in syslogd;
  243. static int Base64To(PCHAR target, PCHAR source, int targetsize, int sourcesize = 0, int linesize = 0);          
  244. static int QuotedPrintableTo( PCHAR target, PCHAR source, int targetsize, int sourcesize = 0, int linesize = 0); 
  245. static int ToPc(PCHAR target, PCHAR source, int targetsize, int sourcesize = 0, int linesize = 0); 
  246.  
  247. #define ToIso8859_1(c) Cp850ToIso8859_1Table[c]
  248. #define ToCp850(c) Iso8859_1ToCp850Table[c]
  249. #define ToIso8859_2(c) Cp852ToIso8859_2Table[c]
  250. #define ToCp852(c) Iso8859_2ToCp852Table[c]
  251. #define ToIso8859_9(c) Cp857ToIso8859_9Table[c]
  252. #define ToCp857(c) Iso8859_9ToCp857Table[c]
  253.  
  254. enum CharSet {
  255.    USASCII,
  256.    ISO8859_1,  
  257.    ISO8859_2,  
  258.    ISO8859_3,  
  259.    ISO8859_4,  
  260.    ISO8859_5,  
  261.    ISO8859_6,  
  262.    ISO8859_7,  
  263.    ISO8859_8,  
  264.    ISO8859_9,  
  265.    ISO2022KR, 
  266.    ISO2022JP,  
  267.    JIS78,
  268.    JISX0212_1990,
  269.    HankakuKatakana,
  270.    SS2         
  271. };
  272.  
  273. struct EscapeSeq {
  274.    PSZ seq;
  275.    int len;
  276.    CharSet charset; 
  277.    PWCHAR_T *jistopccodetable; 
  278. };
  279.  
  280. static const EscapeSeq DoubleByteSeqTable[] = {
  281.    {"\x1b$B", 3, ISO2022JP, NULL},  
  282.    {"\x1b$A", 3, ISO2022JP, NULL},  
  283.    {"\x1b$@", 3, JIS78, NULL},  
  284.    {"\x1b$@\x1b$B", 6, ISO2022JP, NULL}, 
  285.    {"\x1b(J", 3, USASCII, NULL},   
  286.    {"\x1b$(D", 4, JISX0212_1990, JisX0212_1990ToPccodeTable},   
  287.    {"\x1b(B", 3, USASCII, NULL},   
  288.    {"\x1b$(C", 4, ISO2022KR, NULL}, 
  289.    {"\x1b$)C", 4, ISO2022KR, NULL}, 
  290.    {"\x1bN", 2, SS2, NULL},   
  291.    {"\x1b.A", 3, ISO8859_1, NULL},   
  292.    {"\x1b.F", 3, ISO8859_7, NULL},   
  293.    {"\x1b(I", 3, HankakuKatakana, NULL},   
  294.    {NULL, 0}
  295. };
  296.  
  297. struct MimeCharSet {
  298.    PCHAR name;
  299.    int namesize;
  300.    CharSet charset;
  301. };
  302.  
  303. static struct MimeCharSet MimeCharSetTable[] = {
  304.    {"US-ASCII", 8, USASCII},
  305.    {"ISO-8859-1", 10, ISO8859_1}, 
  306.    {"ISO-8859-2", 10, ISO8859_2}, 
  307.    {"ISO-8859-3", 10, ISO8859_3}, 
  308.    {"ISO-8859-4", 10, ISO8859_4}, 
  309.    {"ISO-8859-5", 10, ISO8859_5}, 
  310.    {"ISO-8859-6", 10, ISO8859_6}, 
  311.    {"ISO-8859-7", 10, ISO8859_7}, 
  312.    {"ISO-8859-8", 10, ISO8859_8}, 
  313.    {"ISO-8859-9", 10, ISO8859_9}, 
  314.    {"ISO-2022-JP", 11, ISO2022JP},
  315.    {"ISO-2022-JP-2", 13, ISO2022JP},
  316.    {"ISO-2022-KR", 11, ISO2022KR}
  317. };
  318.  
  319. static const size_t NoOfMimeCharSet = sizeof(MimeCharSetTable) / sizeof(MimeCharSetTable[0]);
  320.  
  321. static struct MimeCharSet *MimeEncodedWordTable;
  322. static size_t NoOfMimeEncodedWord;
  323. static PCHAR ToBase64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  324.  
  325. static int _Optlink
  326. compcharset(
  327. const void *key,
  328. const void *element) {
  329.    MimeCharSet *v1 = (MimeCharSet*)key;
  330.    MimeCharSet *v2 = (MimeCharSet*)element;
  331.    return (strnicmp(v1->name, v2->name, v2->namesize));
  332. }
  333.  
  334. static int
  335. find1stbyte(
  336. PCHAR str,
  337. int pos) {
  338.    if (pos <= 0 || pos > strlen(str)) {
  339.       return (0);
  340.    } /* endif */
  341.    if (strlen(str) == 1) {
  342.       return (1);
  343.    } /* endif */
  344.    for (int i = pos - 1; i >= 2; i -= 1) {
  345.       if (!IsDbcs1st(str[i]) && !IsDbcs1st(str[i-1])) {
  346.          return (i + 1);
  347.       } /* endif */
  348.       if (IsDbcs1st(str[i]) && !IsDbcs1st(str[i-1])) {
  349.          return (i + 1);
  350.       } /* endif */
  351.       if (IsDbcs1st(str[i]) && IsDbcs1st(str[i-1]) && !IsDbcs1st(str[i-2])) {
  352.          return (i - 1);
  353.       } /* endif */
  354.    } /* endfor */
  355.    if (!IsDbcs1st(str[0])) {
  356.       return (2);
  357.    } /* endif */
  358.    return (1);
  359. }
  360.  
  361. int JisFindWord(
  362. char *string, 
  363. int length,
  364. int position, 
  365. int *startWord) {
  366.    int sizeword;
  367.    int& startword = *startWord;
  368.    if (DefaultCodepage != CodepageJapanese && DefaultCodepage != CodepageSaaJapanese && DefaultCodepage != CodepageNewJapanese) {
  369.       ULONG endword;
  370.       ULONG nextword;
  371.       BOOL r = NlsFindWord(DefaultCodepage, string, length, position, (PULONG)&startword, &endword, &nextword);
  372.       if (!r) {
  373.          return (0);
  374.       } /* endif */
  375.       sizeword = endword - startword;
  376.       return (sizeword);
  377.    } /* endif */
  378.    while (position < length && !IsDbcs1st(string[position]) && isspace(string[position])) {
  379.       position += 1;
  380.    } /* endwhile */
  381.    if (position >= length || IsDbcs1st(string[position]) && position + 1 >= length) {
  382.       sizeword = 0;
  383.       return (0);
  384.    } /* endif */
  385.    startword = position;
  386.    sizeword = 0;
  387.    wchar_t w;
  388.    int n = mbtowc(&w, string + position, 2);
  389.    while (wcsrchr(EndKinsoku, w)) {
  390.       sizeword += n;
  391.       if (position + n >= length || IsDbcs1st(string[position+n]) && position + n + 1 >= length) {
  392.          return (sizeword);
  393.       } /* endif */
  394.       position += n;
  395.       n = mbtowc(&w, string + position, 2);
  396.    } /* endwhile */
  397.    if (!IsDbcs1st(string[position]) && string[position] <= SCHAR_MAX) {
  398.       while (position < length && !IsDbcs1st(string[position]) && string[position] <= SCHAR_MAX && !isspace(string[position])) {
  399.          sizeword += 1;
  400.          position += 1;
  401.       } /* endwhile */
  402.    } else {
  403.       sizeword += n;
  404.       position += n;
  405.    } /* endif */
  406.    if (position >= length || IsDbcs1st(string[position]) && position + 1 >= length) {
  407.       return (sizeword);
  408.    } /* endif */
  409.    n = mbtowc(&w, string + position, 2);
  410.    while (wcsrchr(BeginKinsoku, w)) {
  411.       position += n;
  412.       sizeword += n;
  413.       if (position >= length || IsDbcs1st(string[position]) && position + 1 >= length) {
  414.          return (sizeword);
  415.       } /* endif */
  416.       n = mbtowc(&w, string + position, 2);
  417.    } /* endwhile */
  418.    return (sizeword);
  419. }
  420.  
  421. static int
  422. nmbstowcs(
  423. wchar_t *target,
  424. size_t targetsize,
  425. PCHAR source,
  426. size_t sourcesize) {
  427.    size_t i = 0;
  428.    size_t count = 0;
  429.    while (i < sourcesize) {
  430.       RxJisCountCheck(count, targetsize);
  431.       mbtowc(target + count, source + i, sourcesize - i);
  432.       if (target[count] > UCHAR_MAX) {
  433.          i += 2;
  434.       } else {
  435.          i += 1;
  436.       } /* endif */
  437.       count += 1;
  438.    } /* endwhile */
  439.    RxJisCountCheck(count, targetsize);
  440.    target[count] = '\0';
  441.    return (count);
  442. }
  443.  
  444. static wchar_t
  445. JisCodeToPcCode(
  446. wchar_t jiscode) {
  447.    int h = jiscode >> ByteBitWidth;
  448.    int l = jiscode & ByteMask;
  449.    if (h & '\x01') {
  450.       l += '\x1f';
  451.    } else {
  452.       l += '\x7d';
  453.    } /* endif */
  454.    if (l >= '\x7f') {
  455.       l += 1;
  456.    } /* endif */
  457.    h = (h - '\x21') >> 1;
  458.    if (h > '\x1e') {
  459.       h += '\xc1';
  460.    } else {
  461.       h += '\x81';
  462.    } /* endif */
  463.    return (h << ByteBitWidth | l);
  464. }
  465.  
  466. static wchar_t
  467. JisToPc(
  468. wchar_t c,
  469. PWCHAR_T* t) {
  470.    if (!t) {
  471.       return (JisCodeToPcCode(c));
  472.    } /* endif */
  473.    int l = c & ByteMask;
  474.    int h = c >> ByteBitWidth;
  475.    if (!t[h]) {
  476.       return (L'ü@');
  477.    } /* endif */
  478.    return (t[h][l]);
  479. }
  480.  
  481. static int
  482. Base64Size(
  483. PCHAR source,
  484. int sourcesize = 0,
  485. int linesize = 0) {
  486.    if (sourcesize <= 0) { 
  487.       sourcesize = strlen(source);
  488.    } /* endif */
  489.    int n = ByteBitWidth * sourcesize;
  490.    n /= Base64BitWidth;
  491.    if (n % Base64BitWidth) {
  492.       n += 1;
  493.    } /* endif */
  494.    if (linesize > 0) {
  495.       int l = n / linesize;
  496.       if (n % linesize) {
  497.          l += 1;
  498.       } /* endif */
  499.       n += 2 * l;
  500.    } /* endif */
  501.    n += MaxMimeLineSize;
  502.    return (n);
  503. }
  504.  
  505. static int
  506. DbcsSize(
  507. PCHAR source,
  508. int sourcesize = 0,
  509. int linesize = 0) {
  510.    if (sourcesize <= 0) { 
  511.       sourcesize = strlen(source);
  512.    } /* endif */
  513.    return (2 * sourcesize);
  514. }
  515.  
  516. static int
  517. QuotedPrintableSize(
  518. PCHAR source,
  519. int sourcesize = 0,
  520. int linesize = 0) {
  521.    if (sourcesize <= 0) { 
  522.       sourcesize = strlen(source);
  523.    } /* endif */
  524.    int n = 3 * sourcesize;
  525.    if (linesize > 0) {
  526.       int l = n / linesize;
  527.       if (n % linesize) {
  528.          l += 1;
  529.       } /* endif */
  530.       n += 2 * l;
  531.    } /* endif */
  532.    n += linesize;
  533.    return (n);
  534. }
  535.  
  536. static int
  537. JisSize(
  538. PCHAR source,
  539. int sourcesize = 0,
  540. int linesize = 0) {
  541.    if (sourcesize <= 0) { 
  542.       sourcesize = strlen(source);
  543.    } /* endif */
  544.    int sourcesize2 = maxIbm2JisSize * sourcesize + 1;
  545.    PCHAR source2 = new char[sourcesize2];
  546.    if (!source2) {
  547.       return (RxJisError);
  548.    } /* endif */
  549.    if ((sourcesize = IbmcodeStringToJiscodeString(source, sourcesize, source2, sourcesize2)) == RxJisError) {
  550.       delete source2;
  551.       return (RxJisError);
  552.    } /* endif */
  553.    source = source2;
  554.    int count = 0;
  555.    int sourcecount = 0;
  556.    BOOL indoublebyte = FALSE;
  557.    while (sourcecount <= sourcesize) { 
  558.       if (!IsDbcs1st(source[sourcecount])) {  
  559.          if (indoublebyte) {
  560.             indoublebyte = FALSE;
  561.             count += Jis83OutSeq.len; 
  562.          } /* endif */
  563.          count += 1;
  564.          sourcecount += 1;
  565.       } else {
  566.          if (!indoublebyte) {
  567.             indoublebyte = TRUE;
  568.             count += Jis83InSeq.len; 
  569.          } /* endif */
  570.          count += 2;
  571.          sourcecount += 2;
  572.       } /* endif */
  573.    } /* endwhile */
  574.    if (indoublebyte) {
  575.       count += Jis83OutSeq.len; 
  576.    } /* endif */
  577.    return (count + 1);
  578. }
  579.  
  580. static int
  581. EucSize(
  582. PCHAR source,
  583. int sourcesize = 0,
  584. int linesize = 0) {
  585.    if (sourcesize <= 0) { 
  586.       sourcesize = strlen(source);
  587.    } /* endif */
  588.    int count = 0;
  589.    size_t sourcecount = 0;
  590.    while (sourcecount <= sourcesize) {
  591.       if (!IsDbcs1st(source[sourcecount])) {
  592.          count += 1;
  593.          sourcecount += 1;
  594.       } else {
  595.          count += 2;
  596.          sourcecount += 2;
  597.       } /* endif */
  598.    } /* endwhile */
  599.    return (count + 1);
  600. }
  601.  
  602. int _Export 
  603. JisWords(
  604. PCHAR source,
  605. int sourcesize) {
  606.    if (0 == sourcesize) {
  607.       sourcesize = strlen(source);
  608.    } /* endif */
  609.    ULONG pos = 0;
  610.    int count = 0;
  611.    for (; ; ) {
  612.       int startword;
  613.       int sizeword;
  614.       if (!(sizeword = JisFindWord(source, sourcesize, pos, &startword))) {
  615.          break;
  616.       } /* endif */
  617.       count += 1;
  618.       if ((pos = startword + sizeword) >= sourcesize) {
  619.          break;
  620.       } /* endif */
  621.    } /* endfor */
  622.    return (count);
  623. }
  624.  
  625. int _Export 
  626. JisKanjiAlias(
  627. wchar_t kanji,
  628. wchar_t* aliaslist,
  629. int aliassize) {
  630.    char b[2];
  631.    wctomb(b, kanji);
  632.    wchar_t *t;
  633.    if (!KanjiAliasTable[b[0]] || !(t = KanjiAliasTable[b[0]][b[1]])) {
  634.       return (0);
  635.    } /* endif */
  636.    const int n = wcslen(t);
  637.    if (n + 1 > aliassize) {
  638.       return (-1);
  639.    } /* endif */
  640.    wcscpy(aliaslist, t);
  641.    return (n);
  642. }
  643.  
  644. int _Export 
  645. JisWord(
  646. char* target, 
  647. char* source, 
  648. int targetsize, 
  649. int position, 
  650. int sourcesize) {
  651.    if (!target || !source || targetsize <= 0 || position <= 0) {
  652.       return (RxJisError);
  653.    } /* endif */
  654.    if (0 == sourcesize) {
  655.       sourcesize = strlen(source);
  656.    } /* endif */
  657.    if (sourcesize < 0) {
  658.       return (RxJisError);
  659.    } /* endif */
  660.    if (0 == sourcesize) {
  661.       return (0);
  662.    } /* endif */
  663.    int pos = 0;
  664.    int startword;
  665.    int sizeword;
  666.    int count = 0;
  667.    for (; ; ) {
  668.       if (!(sizeword = JisFindWord(source, sourcesize, pos, &startword))) {
  669.          target[0] = '\0';
  670.          return (0);
  671.       } /* endif */
  672.       if (++count == position) {
  673.          break;
  674.       } /* endif */
  675.       pos = startword + sizeword;
  676.    } /* endfor */
  677.    if (sizeword >= targetsize) {
  678.       return (RxJisError);
  679.    } /* endif */
  680.    memcpy(target, source + startword, sizeword);
  681.    target[sizeword] = '\0';
  682.    return (sizeword);
  683. }
  684.  
  685. int _Export 
  686. JisAppend(
  687. char* target, 
  688. char* source, 
  689. int targetsize, 
  690. int targetlength,
  691. int sourcesize) {
  692.    if (!target || !source || targetsize <= 0) {
  693.       return (RxJisError);
  694.    } /* endif */
  695.    if (sourcesize < 0) {
  696.       return (RxJisError);
  697.    } /* endif */
  698.    if (0 == sourcesize) {
  699.       sourcesize = strlen(source);
  700.    } /* endif */
  701.    if (0 == targetlength) {
  702.       targetlength = strlen(target);
  703.    } /* endif */
  704.    if (targetlength + 1 + sourcesize + 1 > targetsize) {
  705.       return (RxJisError);
  706.    } /* endif */
  707.    if (0 == sourcesize) {
  708.       target[targetlength] = '\0';
  709.       return (targetlength);
  710.    } /* endif */
  711.    if (0 == targetlength) {
  712.       memcpy(target, source, sourcesize);
  713.       target[sourcesize] = '\0';
  714.       return (sourcesize);
  715.    } /* endif */
  716.    int i = find1stbyte(target, targetlength);
  717.    for (; ; ) {
  718.       if (i == targetlength || IsDbcs1st(target[i-1]) && i + 1 == targetlength) {
  719.          break;
  720.       } /* endif */
  721.       if (IsDbcs1st(target[i-1])) {
  722.          i += 2;
  723.       } else {
  724.          i += 1;
  725.       } /* endif */
  726.    } /* endfor */
  727.    if (i == targetlength) {
  728.       if (!IsDbcs1st(source[0]) && !isspace(source[0]) && i > 0 && !isspace(target[i-1])) {
  729.          target[targetlength] = ' ';
  730.          targetlength += 1;
  731.       } /* endif */
  732.    } /* endif */           
  733.    memcpy(&target[targetlength], source, sourcesize);
  734.    targetlength += sourcesize;
  735.    target[targetlength] = '\0';
  736.    return (targetlength);
  737. }
  738.  
  739. int _Export 
  740. JisWordIndex(
  741. char* target, 
  742. char* source, 
  743. int targetsize, 
  744. int wordposition, 
  745. int sourcesize) {
  746.    if (!target || !source || targetsize <= 0 || wordposition <= 0) {
  747.       return (RxJisError);
  748.    } /* endif */
  749.    if (0 == sourcesize) {
  750.       sourcesize = strlen(source);
  751.    } /* endif */
  752.    if (sourcesize < 0) {
  753.       return (RxJisError);
  754.    } /* endif */
  755.    if (0 == sourcesize) {
  756.       return (0);
  757.    } /* endif */
  758.    int count = 0;
  759.    int pos = 0;
  760.    int startword;
  761.    int sizeword;
  762.    for (; ; ) {
  763.       if (!(sizeword = JisFindWord(source, sourcesize, pos, &startword))) {
  764.          return (0);
  765.       } /* endif */
  766.       if (++count == wordposition) {
  767.          break;
  768.       } /* endif */
  769.       pos = startword + sizeword;
  770.    } /* endfor */
  771.    return (startword + 1);
  772. }
  773.  
  774. static int
  775. ToEuc(
  776. PCHAR target,
  777. PCHAR source,
  778. int targetsize,
  779. int sourcesize = 0,
  780. int linesize = 0) {
  781.    RxJisArgCheck(source, target, targetsize, sourcesize);
  782.    int sourcesize2 = maxIbm2JisSize * sourcesize + 1;
  783.    PCHAR source2 = new char[sourcesize2];
  784.    if (!source2) {
  785.       return (RxJisError);
  786.    } /* endif */
  787.    if ((sourcesize = IbmcodeStringToJiscodeString(source, sourcesize, source2, sourcesize2)) == RxJisError) {
  788.       delete source2;
  789.       return (RxJisError);
  790.    } /* endif */
  791.    source = source2;
  792.    int count = 0;
  793.    size_t sourcecount = 0;
  794.    while (sourcecount < sourcesize) { 
  795.       if (source[sourcecount] <= SCHAR_MAX) {
  796.          RxJisCountCheck2(count, targetsize, source2);
  797.          target[count++] = source[sourcecount++];
  798.       } else if (!IsDbcs1st(source[sourcecount])) {
  799.          RxJisCountCheck2(count + 1, targetsize, source2);
  800.          target[count++] = EucSs2;
  801.          target[count++] = source[sourcecount++];
  802.       } else {
  803.          RxJisCountCheck2(count + 1, targetsize, source2);
  804.          int h = source[sourcecount++];
  805.          int l = source[sourcecount++];
  806.          wchar_t c = h << ByteBitWidth | l;                    
  807.          c = PccodeToJiscode(c);                                       
  808.          target[count++] = EucMsb | (c >> ByteBitWidth);       
  809.          target[count++] = EucMsb | (c & ByteMask);            
  810.       } /* endif */
  811.    } /* endwhile */
  812.    delete source2;
  813.    RxJisCountCheck(count, targetsize);
  814.    target[count] = '\0';
  815.    return (count);                      
  816. }
  817.  
  818. static int
  819. MimeJisTo(
  820. PCHAR target,
  821. PCHAR source,
  822. int targetsize,
  823. int sourcesize = 0,
  824. int linesize = 0) {
  825.    RxJisArgCheck(source, target, targetsize, sourcesize);
  826.    if (targetsize < sourcesize) {
  827.       return (RxJisError);
  828.    } /* endif */
  829.    int count = 0;
  830.    PCHAR temp1 = new CHAR[targetsize];
  831.    PCHAR temp2 = new CHAR[targetsize];
  832.    if (!temp1 || !temp2) {
  833.       return (RxJisError);
  834.    } /* endif */
  835.    int sourcecount = 0;
  836.    while (sourcecount < sourcesize) {
  837.       PCHAR p;
  838.       PCHAR s;
  839.       MimeCharSet k;
  840.       MimeCharSet *r;
  841.       int n;
  842.       int c;
  843.       switch (source[sourcecount]) {
  844.       case '=':
  845.          k.name = source + sourcecount;
  846.          r = (MimeCharSet*)bsearch(&k, MimeEncodedWordTable, NoOfMimeEncodedWord, sizeof(MimeEncodedWordTable[0]), compcharset);
  847.          if (!r) {
  848.             RxJisCountCheck(count, targetsize);
  849.             temp1[count++] = source[sourcecount++];
  850.             continue;
  851.          } /* endif */
  852.          sourcecount += r->namesize;
  853.          s = source + sourcecount;
  854.          p = strstr(source + sourcecount, "?=");
  855.          if (!p) {
  856.             n = sourcesize - sourcecount;
  857.          } else {
  858.             n = p - s;
  859.          } /* endif */
  860.          if ('B' == r->name[r->namesize-2]) {
  861.             c = Base64To(temp2, s, targetsize, n);
  862.          } else {
  863.             c = QuotedPrintableTo(temp2, s, targetsize, n);
  864.          } /* endif */
  865.          if (c < 0) {
  866.            return (RxJisError);
  867.          } /* endif */
  868.          sourcecount += n + 2;
  869.          memcpy(temp1 + count, temp2, c);
  870.          RxJisCountCheck(count + c, targetsize);
  871.          count += c;
  872.          break;
  873.       default: 
  874.         RxJisCountCheck(count, targetsize);
  875.         temp1[count++] = source[sourcecount++];
  876.         break;
  877.       } /* endswitch */
  878.    } /* endwhile */
  879.    RxJisCountCheck(count, targetsize);
  880.    temp1[count] = '\0';
  881.    count = ToPc(target, temp1, targetsize, count);
  882.    delete temp1;
  883.    delete temp2;
  884.    return (count);
  885. }
  886.  
  887. static int
  888. EucTo(
  889. PCHAR target,
  890. PCHAR source,
  891. int targetsize,
  892. int sourcesize = 0,
  893. int linesize = 0) {
  894.    RxJisArgCheck(source, target, targetsize, sourcesize);
  895.    int count = 0;
  896.    size_t sourcecount = 0;
  897.    while (sourcecount < sourcesize) {
  898.       if (source[sourcecount] <= SCHAR_MAX) {
  899.          RxJisCountCheck(count, targetsize);
  900.          target[count++] = source[sourcecount++];
  901.       } else if (EucSs2 == source[sourcecount]) {
  902.          RxJisCountCheck(count, targetsize);
  903.          sourcecount += 1;
  904.          target[count++] = source[sourcecount++];
  905.       } else if (EucSs3 == source[sourcecount]) {
  906.          sourcecount += 1;        
  907.          RxJisCountCheck(count + 1, targetsize);
  908.          int h = source[sourcecount++] & EucMask; 
  909.          int l = source[sourcecount++] & EucMask; 
  910.          wchar_t c = h << ByteBitWidth | l;        
  911.          c = JisToPc(c, JisX0212_1990ToPccodeTable);                           
  912.          target[count++] = c >> ByteBitWidth;      
  913.          target[count++] = c & ByteMask;           
  914.       } else {
  915.          RxJisCountCheck(count + 1, targetsize);
  916.          int h = source[sourcecount++] & EucMask; 
  917.          int l = source[sourcecount++] & EucMask; 
  918.          wchar_t c = h << ByteBitWidth | l;        
  919.          c = JisCodeToPcCode(c);
  920.          target[count++] = c >> ByteBitWidth;      
  921.          target[count++] = c & ByteMask;           
  922.       } /* endif */
  923.    } /* endwhile */
  924.    RxJisCountCheck(count, targetsize);
  925.    target[count] = '\0';
  926.    return (count);
  927. }
  928.  
  929. static int
  930. ToJisChar(
  931. PCHAR target,
  932. PCHAR source,
  933. int targetsize,
  934. int sourcesize = 0,
  935. int linesize = 0) {
  936.    RxJisArgCheck(source, target, targetsize, sourcesize);
  937.    if (!sourcesize) {
  938.       return (0);
  939.    } /* endif */
  940.    if (targetsize <= 3) {
  941.       return (RxJisError);
  942.    } /* endif */
  943.    wchar_t *temp = new wchar_t[sourcesize+1];
  944.    if (!temp) {
  945.       return (RxJisError);
  946.    } /* endif */
  947.    nmbstowcs(temp, sourcesize, source, sourcesize);
  948.    if (temp[0] <= UCHAR_MAX) {
  949.       delete temp;
  950.       return (0);
  951.    } /* endif */
  952.    wchar_t c = PccodeToJiscode(temp[0]);
  953.    target[0] = c >> ByteBitWidth;
  954.    target[1] = c & ByteMask;
  955.    target[2] = '\0';
  956.    delete temp;
  957.    return (2);
  958. }
  959.  
  960. static int
  961. JisCharTo(
  962. PCHAR target,
  963. PCHAR source,
  964. int targetsize,
  965. int sourcesize = 0,
  966. int linesize = 0) {
  967.    RxJisArgCheck(source, target, targetsize, sourcesize);
  968.    if (sourcesize < 2) {
  969.       return (0);
  970.    } /* endif */
  971.    if (targetsize <= 3) {
  972.       return (RxJisError);
  973.    } /* endif */
  974.    wchar_t c = JisCodeToPcCode((source[0] << ByteBitWidth) | source[1]);
  975.    target[0] = c >> ByteBitWidth;
  976.    target[1] = c & ByteMask;
  977.    target[2] = '\0';
  978.    return (2);
  979. }
  980.  
  981. static int
  982. ToJis(
  983. PCHAR target,
  984. PCHAR source,
  985. int targetsize,
  986. int sourcesize = 0,
  987. int linesize = 0) {
  988.    RxJisArgCheck(source, target, targetsize, sourcesize);
  989.    int sourcesize2 = maxIbm2JisSize * sourcesize + 1;
  990.    PCHAR source2 = new char[sourcesize2];
  991.    if (!source2) {
  992.       return (RxJisError);
  993.    } /* endif */
  994.    if ((sourcesize = IbmcodeStringToJiscodeString(source, sourcesize, source2, sourcesize2)) == RxJisError) {
  995.       delete source2;
  996.       return (RxJisError);
  997.    } /* endif */
  998.    source = source2;
  999.    int count = 0;
  1000.    size_t sourcecount = 0; 
  1001.    while (sourcecount < sourcesize) { 
  1002.       if (!IsDbcs1st(source[sourcecount])) { 
  1003.          RxJisCountCheck2(count, targetsize, source2);
  1004.          target[count++] = source[sourcecount++]; 
  1005.       } else {
  1006.          RxJisCountCheck2(count + Jis83InSeq.len, targetsize, source2);
  1007.          strncpy(target + count, Jis83InSeq.seq, Jis83InSeq.len); 
  1008.          count += Jis83InSeq.len; 
  1009.          while (sourcecount < sourcesize && IsDbcs1st(source[sourcecount])) { 
  1010.             RxJisCountCheck2(count + 2, targetsize, source2);
  1011.             int h = source[sourcecount++];
  1012.             int l = source[sourcecount++];
  1013.             wchar_t c = h << ByteBitWidth | l;                    
  1014.             c = PccodeToJiscode(c);                                       
  1015.             target[count++] = c >> ByteBitWidth; 
  1016.             target[count++] = c & ByteMask;      
  1017.          } /* endwhile */
  1018.          RxJisCountCheck2(count + Jis83OutSeq.len, targetsize, source2);
  1019.          strncpy(target + count, Jis83OutSeq.seq, Jis83OutSeq.len); 
  1020.          count += Jis83OutSeq.len;                                  
  1021.       } /* endif */
  1022.    } /* endwhile */
  1023.    delete source2;
  1024.    RxJisCountCheck(count, targetsize);
  1025.    target[count] = '\0';
  1026.    return (count);
  1027. }
  1028.  
  1029. static int
  1030. ToSbcs(
  1031. PCHAR target,
  1032. PCHAR source,
  1033. int targetsize,
  1034. int sourcesize = 0,
  1035. int linesize = 0) {
  1036.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1037.    int count = 0;
  1038.    size_t sourcecount = 0; 
  1039.    while (sourcecount < sourcesize) { 
  1040.       if (!IsDbcs1st(source[sourcecount])) { 
  1041.          RxJisCountCheck(count, targetsize);
  1042.          target[count++] = source[sourcecount++]; 
  1043.       } else {
  1044.          int h = source[sourcecount++];
  1045.          int l = source[sourcecount++];
  1046.          if (!ToSbcsTable[h] || !ToSbcsTable[h][l]) {
  1047.             RxJisCountCheck(count + 1, targetsize);
  1048.             target[count++] = h;
  1049.             target[count++] = l;
  1050.          } else {
  1051.             for (int i = 0; ToSbcsTable[h][l][i]; i += 1) {
  1052.                RxJisCountCheck(count, targetsize);
  1053.                target[count++] = ToSbcsTable[h][l][i];
  1054.             } /* endfor */
  1055.          } /* endif */
  1056.       } /* endif */
  1057.    } /* endwhile */
  1058.    RxJisCountCheck(count, targetsize);
  1059.    target[count] = '\0';
  1060.    return (count);
  1061. }
  1062.  
  1063. static int
  1064. ToAscii(
  1065. PCHAR target,
  1066. PCHAR source,
  1067. int targetsize,
  1068. int sourcesize = 0,
  1069. int linesize = 0) {
  1070.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1071.    int count = 0;
  1072.    size_t sourcecount = 0; 
  1073.    while (sourcecount < sourcesize) { 
  1074.       if (!IsDbcs1st(source[sourcecount])) { 
  1075.          RxJisCountCheck(count, targetsize);
  1076.          target[count++] = source[sourcecount++]; 
  1077.       } else {
  1078.          int h = source[sourcecount++];
  1079.          int l = source[sourcecount++];
  1080.          if (!ToSbcsTable[h] || !ToSbcsTable[h][l] || ToSbcsTable[h][l][0] > SCHAR_MAX) {
  1081.             RxJisCountCheck(count + 1, targetsize);
  1082.             target[count++] = h;
  1083.             target[count++] = l;
  1084.          } else {
  1085.             RxJisCountCheck(count, targetsize);
  1086.             target[count++] = ToSbcsTable[h][l][0];
  1087.          } /* endif */
  1088.       } /* endif */
  1089.    } /* endwhile */
  1090.    RxJisCountCheck(count, targetsize);
  1091.    target[count] = '\0';
  1092.    return (count);
  1093. }
  1094.  
  1095. static int
  1096. ToUpper(
  1097. PCHAR target,
  1098. PCHAR source,
  1099. int targetsize,
  1100. int sourcesize = 0,
  1101. int linesize = 0) {
  1102.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1103.    int count = 0;
  1104.    wchar_t* sourcewide = new wchar_t[sourcesize + 1]; 
  1105.    if (!sourcewide) {
  1106.       return (CallingInvalid);
  1107.    } /* endif */
  1108.    const size_t sourcewidesize = nmbstowcs(sourcewide, sourcesize + 1, source, sourcesize); 
  1109.    size_t sourcewidecount = 0; 
  1110.    while (sourcewidecount < sourcewidesize) { 
  1111.       switch (sourcewide[sourcewidecount]) {
  1112.       case L'▀':
  1113.       case L'üK':
  1114.       case L'▐':
  1115.       case L'üJ':
  1116.       case L'üE':
  1117.       case L'Ñ':
  1118.       case L'ü[':
  1119.       case L'░':
  1120.          sourcewidecount += 1;
  1121.          continue;
  1122.          break;
  1123.       } /* endswitch */
  1124.       if (sourcewide[sourcewidecount] <= UCHAR_MAX) { 
  1125.          RxJisCountCheck2(count, targetsize, sourcewide);
  1126.          target[count++] = UppercaseTable[0][sourcewide[sourcewidecount++]];
  1127.       } else {
  1128.          char b[2];
  1129.          wctomb(b, sourcewide[sourcewidecount]);
  1130.          if (UppercaseTable[b[0]]) {
  1131.             wchar_t c = UppercaseTable[b[0]][b[1]];
  1132.             wctomb(b, c);
  1133.          } /* endif */
  1134.          RxJisCountCheck2(count + 1, targetsize, sourcewide);
  1135.          strncpy(target + count, b, 2);
  1136.          count += 2;
  1137.          sourcewidecount += 1;
  1138.       } /* endif */
  1139.    } /* endwhile */
  1140.    RxJisCountCheck2(count, targetsize, sourcewide);
  1141.    target[count] = '\0';
  1142.    delete sourcewide; 
  1143.    return (count);
  1144. }
  1145.  
  1146. static int
  1147. ToDbcs(
  1148. PCHAR target,
  1149. PCHAR source,
  1150. int targetsize,
  1151. int sourcesize = 0,
  1152. int linesize = 0) {
  1153.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1154.    int count = 0;
  1155.    wchar_t* sourcewide = new wchar_t[sourcesize + 1]; 
  1156.    if (!sourcewide) {
  1157.       return (CallingInvalid);
  1158.    } /* endif */
  1159.    const size_t sourcewidesize = nmbstowcs(sourcewide, sourcesize + 1, source, sourcesize); 
  1160.    size_t sourcewidecount = 0;
  1161.    while (sourcewidecount < sourcewidesize) {
  1162.       wchar_t c = sourcewide[sourcewidecount++];
  1163.       char b[2];
  1164.       if (c <= UCHAR_MAX) { 
  1165.          if (sourcewidecount >= sourcewidesize) {
  1166.             if (!ToDbcsTable1[c]) {
  1167.                RxJisCountCheck2(count, targetsize, sourcewide);
  1168.                target[count++] = c;
  1169.                continue;
  1170.             } /* endif */
  1171.             c = ToDbcsTable1[c];
  1172.          } else {
  1173.             wchar_t *t = ToDbcsTable1;
  1174.             switch (sourcewide[sourcewidecount]) {
  1175.             case L'▀':
  1176.             case L'üK':
  1177.                t = ToDbcsTable3;
  1178.                sourcewidecount += 1;
  1179.                break;
  1180.             case L'▐':
  1181.             case L'üJ':
  1182.                t = ToDbcsTable2;
  1183.                sourcewidecount += 1;
  1184.                break;
  1185.             } /* endswitch */
  1186.             wchar_t d = t[c];
  1187.             if (!d) {
  1188.                d = ToDbcsTable1[c];
  1189.             } /* endif */
  1190.             if (d) {
  1191.                c = d;
  1192.             } /* endif */
  1193.             if (c <= UCHAR_MAX) {
  1194.                RxJisCountCheck2(count, targetsize, sourcewide);
  1195.                target[count++] = c;
  1196.                continue;
  1197.             } /* endif */
  1198.          } /* endif */
  1199.       } else if (sourcewidecount < sourcewidesize) {
  1200.          PWCHAR_T *t = NULL;
  1201.          switch (sourcewide[sourcewidecount]) {
  1202.             case L'▐':
  1203.             case L'üJ':
  1204.                t = ToDbcsTable4;
  1205.                sourcewidecount += 1;
  1206.                break;
  1207.          case L'▀':
  1208.          case L'üK':
  1209.             t = ToDbcsTable5;
  1210.             sourcewidecount += 1;
  1211.             break;
  1212.          } /* endswitch */
  1213.          wctomb(b, c);
  1214.          if (t && t[b[0]]) {
  1215.             c = t[b[0]][b[1]];
  1216.          } /* endif */
  1217.       } /* endif */
  1218.       RxJisCountCheck2(count + 1, targetsize, sourcewide);
  1219.       wctomb(b, c);
  1220.       strncpy(target + count, b, 2);
  1221.       count += 2;
  1222.    } /* endwhile */
  1223.    RxJisCountCheck2(count, targetsize, sourcewide);
  1224.    target[count] = '\0';
  1225.    delete sourcewide; 
  1226.    return (count);
  1227. }
  1228.  
  1229. static int
  1230. ToZenkakuKatakana(
  1231. PCHAR target,
  1232. PCHAR source,
  1233. int targetsize,
  1234. int sourcesize = 0,
  1235. int linesize = 0) {
  1236.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1237.    int count = 0;
  1238.    wchar_t* sourcewide = new wchar_t[sourcesize + 1]; 
  1239.    if (!sourcewide) {
  1240.       return (CallingInvalid);
  1241.    } /* endif */
  1242.    const size_t sourcewidesize = nmbstowcs(sourcewide, sourcesize + 1, source, sourcesize); 
  1243.    size_t sourcewidecount = 0; 
  1244.    while (sourcewidecount < sourcewidesize) {
  1245.       wchar_t c = sourcewide[sourcewidecount++];
  1246.       char b[2];
  1247.       if (c <= SCHAR_MAX) {
  1248.          RxJisCountCheck2(count, targetsize, sourcewide);
  1249.          target[count++] = c;
  1250.          continue;
  1251.       } else if (c <= UCHAR_MAX) { 
  1252.          if (sourcewidecount >= sourcewidesize) {
  1253.             if (!ToDbcsTable1[c]) {
  1254.                RxJisCountCheck2(count, targetsize, sourcewide);
  1255.                target[count++] = c;
  1256.                continue;
  1257.             } /* endif */
  1258.             c = ToDbcsTable1[c];
  1259.          } else {
  1260.             wchar_t *t = ToDbcsTable1;
  1261.             switch (sourcewide[sourcewidecount]) {
  1262.             case L'▀':
  1263.             case L'üK':
  1264.                t = ToDbcsTable3;
  1265.                sourcewidecount += 1;
  1266.                break;
  1267.             case L'▐':
  1268.             case L'üJ':
  1269.                t = ToDbcsTable2;
  1270.                sourcewidecount += 1;
  1271.                break;
  1272.             } /* endswitch */
  1273.             wchar_t d = t[c];
  1274.             if (!d) {
  1275.                d = ToDbcsTable1[c];
  1276.             } /* endif */
  1277.             if (d) {
  1278.                c = d;
  1279.             } /* endif */
  1280.             if (c <= UCHAR_MAX) {
  1281.                RxJisCountCheck2(count, targetsize, sourcewide);
  1282.                target[count++] = c;
  1283.                continue;
  1284.             } /* endif */
  1285.          } /* endif */
  1286.       } else if (sourcewidecount < sourcewidesize) {
  1287.          PWCHAR_T *t = NULL;
  1288.          switch (sourcewide[sourcewidecount]) {
  1289.             case L'▐':
  1290.             case L'üJ':
  1291.                t = ToDbcsTable4;
  1292.                sourcewidecount += 1;
  1293.                break;
  1294.          case L'▀':
  1295.          case L'üK':
  1296.             t = ToDbcsTable5;
  1297.             sourcewidecount += 1;
  1298.             break;
  1299.          } /* endswitch */
  1300.          wctomb(b, c);
  1301.          if (t && t[b[0]]) {
  1302.             c = t[b[0]][b[1]];
  1303.          } /* endif */
  1304.       } /* endif */
  1305.       RxJisCountCheck2(count + 1, targetsize, sourcewide);
  1306.       wctomb(b, c);
  1307.       strncpy(target + count, b, 2);
  1308.       count += 2;
  1309.    } /* endwhile */
  1310.    RxJisCountCheck2(count, targetsize, sourcewide);
  1311.    target[count] = '\0';
  1312.    delete sourcewide; 
  1313.    return (count);
  1314. }
  1315.  
  1316. static int
  1317. ToQuotedPrintable(
  1318. PCHAR target,
  1319. PCHAR source,
  1320. int targetsize,
  1321. int sourcesize = 0,
  1322. int linesize = 0) {
  1323.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1324.    int count = 0;
  1325.    int column = 0;
  1326.    for (int i = 1; i <= sourcesize; i += 1) {
  1327.       if (count + ToQuotedPrintableTable[*source].len >= targetsize) {
  1328.          return (RxJisError); 
  1329.       } /* endif */
  1330.       if (column + ToQuotedPrintableTable[*source].len > MaxMimeLineSize) {
  1331.          if (count + 3 >= targetsize) {
  1332.             return (RxJisError); 
  1333.          } /* endif */
  1334.          target[count++] = '=';
  1335.          target[count++] = '\r';
  1336.          target[count++] = '\n';
  1337.          column = 0;
  1338.       } /* endif */
  1339.       strncpy(target + count, ToQuotedPrintableTable[*source].seq, ToQuotedPrintableTable[*source].len);
  1340.       count += ToQuotedPrintableTable[*source].len;
  1341.       column += ToQuotedPrintableTable[*source].len;
  1342.       source += 1;
  1343.    } /* endfor */
  1344.    if (count >= targetsize) {
  1345.       return (RxJisError); 
  1346.    } /* endif */
  1347.    target[count] = '\0';
  1348.    return (count);
  1349. }
  1350.  
  1351. static int
  1352. ToBase64(
  1353. PCHAR target,
  1354. PCHAR source,
  1355. int targetsize,
  1356. int sourcesize = 0,
  1357. int linesize = 0) {
  1358.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1359.    int count = 0;
  1360.    int column = 0;
  1361.    for (int i = 1; i <= sourcesize; i += 3) {
  1362.       RxJisCountCheck(count + 3, targetsize);
  1363.       if (column >= MaxMimeLineSize) {
  1364.          RxJisCountCheck(count + 2, targetsize);
  1365.          target[count++] = '\r';
  1366.          target[count++] = '\n';
  1367.          column = 0;
  1368.       } /* endif */
  1369.       long v;
  1370.       if (i + 2 <= sourcesize) {
  1371.          v = *source++ << (2 * ByteBitWidth);
  1372.          v |= *source++ << ByteBitWidth;
  1373.          v |= *source++;
  1374.          target[count++] = ToBase64Table[Base64Mask&(v>>(3*Base64BitWidth))];
  1375.          target[count++] = ToBase64Table[Base64Mask&(v>>2*Base64BitWidth)];
  1376.          target[count++] = ToBase64Table[Base64Mask&(v>>Base64BitWidth)];
  1377.          target[count++] = ToBase64Table[Base64Mask&v];
  1378.       } else if (i + 1 <= sourcesize) {
  1379.          v = *source++ << ByteBitWidth;
  1380.          v |= *source++;
  1381.          v <<= (3*Base64BitWidth-2*ByteBitWidth);
  1382.          target[count++] = ToBase64Table[Base64Mask&(v>>2*Base64BitWidth)];
  1383.          target[count++] = ToBase64Table[Base64Mask&(v>>Base64BitWidth)];
  1384.          target[count++] = ToBase64Table[Base64Mask&v];
  1385.          target[count++] = '=';
  1386.       } else {
  1387.          v = *source++ << (2*Base64BitWidth-ByteBitWidth);
  1388.          target[count++] = ToBase64Table[Base64Mask&(v>>Base64BitWidth)];
  1389.          target[count++] = ToBase64Table[Base64Mask&v];
  1390.          target[count++] = '=';
  1391.          target[count++] = '=';
  1392.       } /* endif */
  1393.    } /* endfor */
  1394.    RxJisCountCheck(count, targetsize);
  1395.    target[count] = '\0';
  1396.    return (count);
  1397. }
  1398.  
  1399. static int
  1400. Iso8859_1ToCp850(
  1401. PCHAR target,
  1402. PCHAR source,
  1403. int targetsize,
  1404. int sourcesize,  
  1405. int linesize) {  
  1406.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1407.    RxJisCountCheck(sourcesize, targetsize);
  1408.    int count = 0;
  1409.    for (int sourcecount = 0; sourcecount < sourcesize; sourcecount += 1) {
  1410.       RxJisCountCheck(count, targetsize);
  1411.       target[count++] = ToCp850(source[sourcecount]);
  1412.    } /* endfor */
  1413.    RxJisCountCheck(count, targetsize);
  1414.    target[count] = '\0';
  1415.    return (count);
  1416. }
  1417.  
  1418. static int
  1419. Cp850ToIso8859_1(
  1420. PCHAR target,
  1421. PCHAR source,
  1422. int targetsize,
  1423. int sourcesize,  
  1424. int linesize) {  
  1425.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1426.    RxJisCountCheck(sourcesize, targetsize);
  1427.    int count = 0;
  1428.    for (int sourcecount = 0; sourcecount < sourcesize; sourcecount += 1) {
  1429.       RxJisCountCheck(count, targetsize);
  1430.       target[count++] = ToIso8859_1(source[sourcecount]);
  1431.    } /* endfor */
  1432.    RxJisCountCheck(count, targetsize);
  1433.    target[count] = '\0';
  1434.    return (count);
  1435. }
  1436.  
  1437. static int
  1438. Cp852ToIso8859_2(
  1439. PCHAR target,
  1440. PCHAR source,
  1441. int targetsize,
  1442. int sourcesize,  
  1443. int linesize) {  
  1444.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1445.    RxJisCountCheck(sourcesize, targetsize);
  1446.    int count = 0;
  1447.    for (int sourcecount = 0; sourcecount < sourcesize; sourcecount += 1) {
  1448.       RxJisCountCheck(count, targetsize);
  1449.       target[count++] = ToIso8859_2(source[sourcecount]);
  1450.    } /* endfor */
  1451.    RxJisCountCheck(count, targetsize);
  1452.    target[count] = '\0';
  1453.    return (count);
  1454. }
  1455.  
  1456. static int
  1457. Cp857ToIso8859_9(
  1458. PCHAR target,
  1459. PCHAR source,
  1460. int targetsize,
  1461. int sourcesize,  
  1462. int linesize) {  
  1463.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1464.    RxJisCountCheck(sourcesize, targetsize);
  1465.    int count = 0;
  1466.    for (int sourcecount = 0; sourcecount < sourcesize; sourcecount += 1) {
  1467.       RxJisCountCheck(count, targetsize);
  1468.       target[count++] = ToIso8859_9(source[sourcecount]);
  1469.    } /* endfor */
  1470.    RxJisCountCheck(count, targetsize);
  1471.    target[count] = '\0';
  1472.    return (count);
  1473. }
  1474.  
  1475. static int
  1476. Iso8859_2ToCp852(
  1477. PCHAR target,
  1478. PCHAR source,
  1479. int targetsize,
  1480. int sourcesize,  
  1481. int linesize) {  
  1482.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1483.    RxJisCountCheck(sourcesize, targetsize);
  1484.    int count = 0;
  1485.    for (int sourcecount = 0; sourcecount < sourcesize; sourcecount += 1) {
  1486.       target[count++] = ToCp852(source[sourcecount]);
  1487.    } /* endfor */
  1488.    RxJisCountCheck(count, targetsize);
  1489.    target[count] = '\0';
  1490.    return (count);
  1491. }
  1492.  
  1493. static int
  1494. Iso8859_9ToCp857(
  1495. PCHAR target,
  1496. PCHAR source,
  1497. int targetsize,
  1498. int sourcesize,  
  1499. int linesize) {  
  1500.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1501.    RxJisCountCheck(sourcesize, targetsize);
  1502.    int count = 0;
  1503.    for (int sourcecount = 0; sourcecount < sourcesize; sourcecount += 1) {
  1504.       target[count++] = ToCp857(source[sourcecount]);
  1505.    } /* endfor */
  1506.    RxJisCountCheck(count, targetsize);
  1507.    target[count] = '\0';
  1508.    return (count);
  1509. }
  1510.  
  1511. static int
  1512. ToPc(
  1513. PCHAR target,
  1514. PCHAR source,
  1515. int targetsize,
  1516. int sourcesize,  
  1517. int linesize) {  
  1518.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1519.    int count = 0;
  1520.    int sourcecount = 0;
  1521.    CharSet currentset = USASCII; 
  1522.    CHAR currentmask = 0x00;
  1523.    PWCHAR_T* jistopccode; 
  1524.    while (sourcecount < sourcesize) { 
  1525.       int i;
  1526.       switch (source[sourcecount]) {
  1527.       case SO:
  1528.       case SI:
  1529.          target[count++] = source[sourcecount++];
  1530.          break;
  1531.       case Esc:
  1532.          for (i = 0; DoubleByteSeqTable[i].seq; i += 1) {
  1533.             if (sourcecount + DoubleByteSeqTable[i].len > sourcesize) {
  1534.                continue; 
  1535.             } /* endif */
  1536.             if (strncmp(source + sourcecount, DoubleByteSeqTable[i].seq, DoubleByteSeqTable[i].len) == 0) {
  1537.                break;
  1538.             } /* endif */
  1539.          } /* endfor */
  1540.          if (DoubleByteSeqTable[i].seq != NULL) {
  1541.             if (sourcecount + DoubleByteSeqTable[i].len > sourcesize) {
  1542.                RxJisCountCheck(count, targetsize);
  1543.                target[count++] = source[sourcecount++];
  1544.                continue;
  1545.             } /* endif */
  1546.             sourcecount += DoubleByteSeqTable[i].len;
  1547.             switch (DoubleByteSeqTable[i].charset) { 
  1548.             case USASCII:
  1549.                switch (currentset) {
  1550.                case ISO8859_1:
  1551.                case ISO8859_7:
  1552.                   RxJisCountCheck(count + Jis83OutSeq.len, targetsize);
  1553.                   strncpy(target + count, Jis83OutSeq.seq, Jis83OutSeq.len);
  1554.                   count += Jis83OutSeq.len;
  1555.                   break;
  1556.                default:
  1557.                  break;
  1558.                } /* endswitch */
  1559.                currentset = DoubleByteSeqTable[i].charset;
  1560.                break;
  1561.             case SS2:
  1562.                if (sourcecount < sourcesize) {
  1563.                   RxJisCountCheck(count, targetsize);
  1564.                   switch (currentset) {
  1565.                   case ISO8859_1:
  1566.                      target[count++] = ToCp850(ByteMsb | source[sourcecount++]); 
  1567.                      break;
  1568.                   default:
  1569.                     target[count++] = source[sourcecount++];                 
  1570.                     break;
  1571.                   } /* endswitch */
  1572.                } /* endif */
  1573.                break;
  1574.             case ISO8859_1:
  1575.             case ISO8859_7:
  1576.                RxJisCountCheck(count + DoubleByteSeqTable[i].len, targetsize);
  1577.                strncpy(target + count, DoubleByteSeqTable[i].seq, DoubleByteSeqTable[i].len);
  1578.                currentset = DoubleByteSeqTable[i].charset;
  1579.                break;
  1580.             default:
  1581.               switch (currentset) {
  1582.               case ISO8859_1:
  1583.               case ISO8859_7:
  1584.               case ISO2022KR:
  1585.                  RxJisCountCheck(count + Jis83OutSeq.len, targetsize);
  1586.                  strncpy(target + count, Jis83OutSeq.seq, Jis83OutSeq.len);
  1587.                  count += Jis83OutSeq.len;
  1588.                  break;
  1589.               } /* endswitch */
  1590.               currentset = DoubleByteSeqTable[i].charset;
  1591.               jistopccode = DoubleByteSeqTable[i].jistopccodetable;
  1592.               break;
  1593.             } /* endswitch */
  1594.          } else {
  1595.             RxJisCountCheck(count, targetsize);
  1596.             currentset = USASCII;
  1597.             target[count++] = source[sourcecount++];                               
  1598.          } /* endif */
  1599.          break;
  1600.       default: 
  1601.         wchar_t c;
  1602.         int l;
  1603.         int h;
  1604.         switch (currentset) {
  1605.         case HankakuKatakana:
  1606.            RxJisCountCheck(count, targetsize);
  1607.            target[count++] = ByteMsb | source[sourcecount++];
  1608.            break;
  1609.         case ISO2022JP:
  1610.         case JIS78:
  1611.         case JISX0212_1990:
  1612.         case ISO2022KR:
  1613.            if (sourcecount + 2 > sourcesize) { 
  1614.               RxJisCountCheck(count, targetsize);
  1615.               target[count++] = source[sourcecount++];
  1616.               continue;
  1617.            } /* endif */                                     
  1618.            RxJisCountCheck(count + 2, targetsize);
  1619.            if (source[sourcecount] <= ' ' || source[sourcecount+1] <= ' ') { 
  1620.               target[count++] = source[sourcecount++];       
  1621.               target[count++] = source[sourcecount++];       
  1622.               currentset = USASCII;
  1623.               continue;                                      
  1624.            } /* endif */                                     
  1625.            h = source[sourcecount++];           
  1626.            l = source[sourcecount++];           
  1627.            c = h << ByteBitWidth | l;
  1628.            switch (currentset) {
  1629.            case ISO2022JP:
  1630.            case JIS78:
  1631.               c = JisCodeToPcCode(c);
  1632.               if (InJis90 && JIS78 == currentset) {
  1633.                  c = OldJisToNewJis(c);
  1634.               } else if (!InJis90 && ISO2022JP == currentset) {
  1635.                  c = NewJisToOldJis(c);
  1636.               } /* endif */
  1637.               break;
  1638.            default:
  1639.              c = JisToPc(c, jistopccode);              
  1640.              break;
  1641.            } /* endswitch */
  1642.            target[count++] = c >> ByteBitWidth;      
  1643.            target[count++] = c & ByteMask;           
  1644.            break;
  1645.         default:
  1646.           RxJisCountCheck(count, targetsize);
  1647.           target[count++] = source[sourcecount++];
  1648.           break;
  1649.         } /* endswitch */
  1650.         break;
  1651.       } /* endswitch */
  1652.    } /* endwhile */
  1653.    switch (currentset) {
  1654.    case ISO8859_1:
  1655.    case ISO8859_7:
  1656.    case ISO2022KR:
  1657.       RxJisCountCheck(count + Jis83OutSeq.len, targetsize);
  1658.       strncpy(target + count, Jis83OutSeq.seq, Jis83OutSeq.len);
  1659.       count += Jis83OutSeq.len;
  1660.       break;
  1661.    } /* endswitch */
  1662.    RxJisCountCheck(count, targetsize);
  1663.    target[count] = '\0';
  1664.    return (count);
  1665. }
  1666.  
  1667. static int
  1668. QuotedPrintableTo(
  1669. PCHAR target,
  1670. PCHAR source,
  1671. int targetsize,
  1672. int sourcesize, 
  1673. int linesize) { 
  1674.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1675.    int count = 0;
  1676.    int sourcecount = 0; 
  1677.    while (sourcecount < sourcesize) { 
  1678.       long v;
  1679.       long c;
  1680.       int p;
  1681.       switch (source[sourcecount]) {
  1682.       case '=':
  1683.          RxJisCountCheck(count, targetsize);
  1684.          if (!source[++sourcecount]) {
  1685.             continue;
  1686.          } /* endif */
  1687.          v = QuotedPrintableTable[source[sourcecount]];
  1688.          if (QuotedPrintableError == v) {
  1689.             continue;
  1690.          } /* endif */
  1691.          if (!source[++sourcecount]) {
  1692.             continue;
  1693.          } /* endif */
  1694.          c = QuotedPrintableTable[source[sourcecount++]];
  1695.          if (QuotedPrintableError == c) {
  1696.             continue;
  1697.          } /* endif */
  1698.          target[count++] = (v << 4) | c;
  1699.          break;
  1700.       case Space:
  1701.       case Ht:
  1702.          p = sourcecount;
  1703.          while (source[p]) {
  1704.             if (source[p] != Space && source[p] != Ht) {
  1705.                break;
  1706.             } /* endif */
  1707.             p += 1;
  1708.          } /* endwhile */
  1709.          if (source[p]) {
  1710.             p = sourcecount;
  1711.             while (source[p]) {
  1712.                RxJisCountCheck(count, targetsize);
  1713.                if (source[p] != Space && source[p] != Ht) {
  1714.                   break;
  1715.                } /* endif */
  1716.                target[count++] = source[p++];
  1717.             } /* endwhile */
  1718.          } /* endif */
  1719.          sourcecount = p;
  1720.          break;
  1721.       default: 
  1722.          RxJisCountCheck(count, targetsize);
  1723.          target[count++] = source[sourcecount++];
  1724.          break;
  1725.       } /* endswitch */
  1726.    } /* endwhile */
  1727.    RxJisCountCheck(count, targetsize);
  1728.    target[count] = '\0';
  1729.    return (count);
  1730. }
  1731.  
  1732. static int
  1733. Base64To(
  1734. PCHAR target,
  1735. PCHAR source,
  1736. int targetsize,
  1737. int sourcesize, 
  1738. int linesize) { 
  1739.    RxJisArgCheck(source, target, targetsize, sourcesize);
  1740.    int count = 0;
  1741.    for (int i = 1; i <= sourcesize; i += 4) {
  1742.       long v = 0;
  1743.       int m = 0;
  1744.       for (int j = 1; *source && j <= 4; j += 1) {
  1745.          long c = Base64Table[*source++];
  1746.          switch (c) {
  1747.          case Base64Error:
  1748.          case Base64Pad:
  1749.             break;
  1750.          default:
  1751.             v = (v << Base64BitWidth) | c;
  1752.             m += Base64BitWidth;
  1753.             break;
  1754.          } /* endswitch */
  1755.       } /* endfor */
  1756.       if (m >= ByteBitWidth) {
  1757.          v >>= (m % ByteBitWidth);
  1758.          m /= ByteBitWidth;
  1759.       } else {
  1760.          v <<= (ByteBitWidth - m);
  1761.          m = 1;
  1762.       } /* endif */
  1763.       if (count + m > targetsize) {
  1764.          return (RxJisError); 
  1765.       } /* endif */
  1766.       for (j = m - 1; j >= 0; j -= 1) {
  1767.          target[count+j] = v & ByteMask;
  1768.          v >>= ByteBitWidth;
  1769.       } /* endfor */
  1770.       count += m;
  1771.    } /* endfor */
  1772.    target[count] = '\0';
  1773.    return (count);
  1774. }
  1775.  
  1776. static ULONG
  1777. JisCommon(
  1778. int (*convert)(PCHAR, PCHAR, int, int, int),
  1779. PCHAR target,
  1780. PCHAR source,
  1781. int targetsize,
  1782. int sourcesize = 0,
  1783. int (*mintargetsize)(PCHAR, int, int) = NULL) {
  1784.    if (!TableIsLoaded) {  
  1785.       LoadRxJisTables();  
  1786.    } /* endif */          
  1787.    if (0 == sourcesize) {
  1788.       sourcesize = strlen(source);
  1789.    } /* endif */
  1790.    if (0 == sourcesize) {
  1791.       target[0] = '\0';
  1792.       return (0);
  1793.    } /* endif */
  1794.    int minsize;
  1795.    if (mintargetsize) {
  1796.       minsize = (*mintargetsize)(source, sourcesize, 0);
  1797.    } else {
  1798.       minsize = sourcesize;
  1799.    } /* endif */
  1800.    if (targetsize < minsize) {
  1801.       return (RxJisError);
  1802.    } /* endif */
  1803.    return ((*convert)(target, source, targetsize, sourcesize, 0));
  1804. }
  1805.  
  1806. int _Export 
  1807. JisToJis(
  1808. char* target, 
  1809. char* source, 
  1810. int targetsize, 
  1811. int sourcesize) {
  1812.    return (JisCommon(ToJis, target, source, targetsize, sourcesize, JisSize));
  1813. }
  1814.  
  1815. int _Export 
  1816. JisToEuc(
  1817. char* target, 
  1818. char* source, 
  1819. int targetsize, 
  1820. int sourcesize) {
  1821.    return (JisCommon(ToEuc, target, source, targetsize, sourcesize, EucSize));
  1822. }
  1823.  
  1824. int _Export 
  1825. JisToBase64(
  1826. char* target,
  1827. char* source, 
  1828. int targetsize, 
  1829. int sourcesize) {
  1830.    return (JisCommon(ToBase64, target, source, targetsize, sourcesize, Base64Size));
  1831. }
  1832.  
  1833. int _Export 
  1834. JisToQuotedPrintable(
  1835. char* target, 
  1836. char* source, 
  1837. int targetsize, 
  1838. int sourcesize) {
  1839.    return (JisCommon(ToQuotedPrintable, target, source, targetsize, sourcesize, QuotedPrintableSize));
  1840. }
  1841.  
  1842. int _Export JisJisTo(
  1843. char* target, 
  1844. char* source, 
  1845. int targetsize, 
  1846. int sourcesize) {
  1847.    return (JisCommon(ToPc, target, source, targetsize, sourcesize));
  1848. }
  1849.  
  1850. int _Export 
  1851. JisBase64To(
  1852. char* target, 
  1853. char* source, 
  1854. int targetsize, 
  1855. int sourcesize) {
  1856.    return (JisCommon(Base64To, target, source, targetsize, sourcesize));
  1857. }
  1858.  
  1859. int _Export 
  1860. JisEucTo(
  1861. char* target, 
  1862. char* source, 
  1863. int targetsize, 
  1864. int sourcesize) {
  1865.    return (JisCommon(EucTo, target, source, targetsize, sourcesize));
  1866. }
  1867.  
  1868. int _Export 
  1869. JisQuotedPrintableTo(
  1870. char* target, 
  1871. char* source, 
  1872. int targetsize, 
  1873. int sourcesize) {
  1874.    return (JisCommon(QuotedPrintableTo, target, source, targetsize, sourcesize));
  1875. }
  1876.  
  1877. int _Export 
  1878. JisMimeJisTo(
  1879. char* target, 
  1880. char* source, 
  1881. int targetsize, 
  1882. int sourcesize) {
  1883.    return (JisCommon(MimeJisTo, target, source, targetsize, sourcesize));
  1884. }
  1885.  
  1886. int _Export 
  1887. JisJisCharTo(
  1888. char* target, 
  1889. char* source, 
  1890. int targetsize, 
  1891. int sourcesize) {
  1892.    return (JisCommon(JisCharTo, target, source, targetsize, sourcesize));
  1893. }
  1894.  
  1895. int _Export 
  1896. JisToJisChar(
  1897. char* target, 
  1898. char* source, 
  1899. int targetsize, 
  1900. int sourcesize) {
  1901.    return (JisCommon(ToJisChar, target, source, targetsize, sourcesize));
  1902. }
  1903.  
  1904. int _Export 
  1905. JisToSbcs(
  1906. char* target, 
  1907. char* source, 
  1908. int targetsize, 
  1909. int sourcesize) {
  1910.    return (JisCommon(ToSbcs, target, source, targetsize, sourcesize));
  1911. }
  1912.  
  1913. int _Export 
  1914. JisToDbcs(
  1915. char* target, 
  1916. char* source, 
  1917. int targetsize, 
  1918. int sourcesize) {
  1919.    return (JisCommon(ToDbcs, target, source, targetsize, sourcesize, DbcsSize));
  1920. }
  1921.  
  1922. int _Export 
  1923. JisToAscii(
  1924. char* target, 
  1925. char* source, 
  1926. int targetsize, 
  1927. int sourcesize) {
  1928.    return (JisCommon(ToAscii, target, source, targetsize, sourcesize));
  1929. }
  1930.  
  1931. int _Export 
  1932. JisToUpper(
  1933. char* target, 
  1934. char* source, 
  1935. int targetsize, 
  1936. int sourcesize) {
  1937.    return (JisCommon(ToUpper, target, source, targetsize, sourcesize));
  1938. }
  1939.  
  1940. int _Export 
  1941. JisCp850ToIso8859_1(
  1942. char* target, 
  1943. char* source, 
  1944. int targetsize, 
  1945. int sourcesize) {
  1946.    return (JisCommon(Cp850ToIso8859_1, target, source, targetsize, sourcesize));
  1947. }
  1948.  
  1949. int _Export 
  1950. JisCp852ToIso8859_2(
  1951. char* target, 
  1952. char* source, 
  1953. int targetsize, 
  1954. int sourcesize) {
  1955.    return (JisCommon(Cp852ToIso8859_2, target, source, targetsize, sourcesize));
  1956. }
  1957.  
  1958. int _Export 
  1959. JisCp857ToIso8859_9(
  1960. char* target, 
  1961. char* source, 
  1962. int targetsize, 
  1963. int sourcesize) {
  1964.    return (JisCommon(Cp857ToIso8859_9, target, source, targetsize, sourcesize));
  1965. }
  1966.  
  1967. int _Export 
  1968. JisIso8859_9ToCp857(
  1969. char* target, 
  1970. char* source, 
  1971. int targetsize, 
  1972. int sourcesize) {
  1973.    return (JisCommon(Iso8859_9ToCp857, target, source, targetsize, sourcesize));
  1974. }
  1975.  
  1976. int _Export 
  1977. JisIso8859_2ToCp852(
  1978. char* target, 
  1979. char* source, 
  1980. int targetsize, 
  1981. int sourcesize) {
  1982.    return (JisCommon(Iso8859_2ToCp852, target, source, targetsize, sourcesize));
  1983. }
  1984.  
  1985. int _Export 
  1986. JisIso8859_1ToCp850(
  1987. char* target, 
  1988. char* source, 
  1989. int targetsize, 
  1990. int sourcesize) {
  1991.    return (JisCommon(Iso8859_1ToCp850, target, source, targetsize, sourcesize));
  1992. }
  1993.  
  1994. int _Export 
  1995. JisToZenkakuKatakana(
  1996. char* target, 
  1997. char* source, 
  1998. int targetsize, 
  1999. int sourcesize) {
  2000.    return (JisCommon(ToZenkakuKatakana, target, source, targetsize, sourcesize));
  2001. }
  2002.  
  2003. static ULONG
  2004. RxJisCommon(
  2005. PUCHAR name, 
  2006. ULONG argc,
  2007. RXSTRING argv[],
  2008. PSZ queuename,
  2009. RXSTRING *retstr,
  2010. int (*convert)(PCHAR, PCHAR, int, int, int),
  2011. int (*mintargetsize)(PCHAR, int, int) = NULL) {
  2012.    if (0 == argc || argc > 2) {
  2013.       return (CallingInvalid);
  2014.    } /* endif */
  2015.    if (NULL == retstr || RXNULLSTRING(argv[0])) {
  2016.       return (CallingInvalid);
  2017.    } /* endif */
  2018.    PSZ& source = RXSTRPTR(argv[0]);
  2019.    const int& sourcesize = RXSTRLEN(argv[0]);
  2020.    int linesize = 0;
  2021.    if (argc > 1) {
  2022.       if (RXNULLSTRING(argv[1])) {
  2023.          return (CallingInvalid);
  2024.       } /* endif */
  2025.       int n = sscanf(RXSTRPTR(argv[1]), "%d", &linesize);
  2026.       if (n != 1 || linesize < MaxMimeLineSize / 2 || linesize > MaxMimeLineSize) {
  2027.          return (CallingInvalid);
  2028.       } /* endif */
  2029.    } /* endif */
  2030.    if (0 == sourcesize) {    
  2031.       retstr->strlength = 0; 
  2032.       return (CallingValid); 
  2033.    } /* endif */             
  2034.    if (!TableIsLoaded) {  
  2035.       LoadRxJisTables();  
  2036.    } /* endif */          
  2037.    int minimumtargetsize;
  2038.    if (mintargetsize) {                                                   
  2039.       minimumtargetsize = (*mintargetsize)(source, sourcesize, linesize); 
  2040.    } else {                                                               
  2041.       minimumtargetsize = 2 * sourcesize + 1;
  2042.    } /* endif */                                                          
  2043.    if (RXNULLSTRING(*retstr) || RXSTRLEN(*retstr) < minimumtargetsize) {  
  2044.       retstr->strlength = minimumtargetsize; 
  2045.       APIRET code = DosAllocMem((PPVOID)&retstr->strptr, retstr->strlength, PAG_COMMIT | PAG_READ | PAG_WRITE);
  2046.       if (code != NO_ERROR) {
  2047.          return (CallingInvalid);
  2048.       } /* endif */
  2049.    } /* endif */
  2050.    int count = (*convert)(RXSTRPTR(*retstr), source, RXSTRLEN(*retstr), sourcesize, linesize);
  2051.    if (count < 0) {
  2052.       return (CallingInvalid);
  2053.    } /* endif */
  2054.    retstr->strlength = count;
  2055.    return (CallingValid);
  2056. }
  2057.  
  2058. ULONG _Export 
  2059. RxJisBase64To(
  2060. PUCHAR name, 
  2061. ULONG argc,
  2062. RXSTRING argv[],
  2063. PSZ queuename,
  2064. RXSTRING *retstr) {
  2065.    return (RxJisCommon(name, argc, argv, queuename, retstr, Base64To));
  2066. }
  2067.  
  2068. ULONG _Export 
  2069. RxJisToPc(
  2070. PUCHAR name, 
  2071. ULONG argc,
  2072. RXSTRING argv[],
  2073. PSZ queuename,
  2074. RXSTRING *retstr) {
  2075.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToPc));
  2076. }
  2077.  
  2078. ULONG _Export
  2079. RxJisJisTo(
  2080. PUCHAR name, 
  2081. ULONG argc,
  2082. RXSTRING argv[],
  2083. PSZ queuename,
  2084. RXSTRING *retstr) {
  2085.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToPc));
  2086. }
  2087.  
  2088. ULONG _Export
  2089. RxJisToZenkakuKatakana(
  2090. PUCHAR name, 
  2091. ULONG argc,
  2092. RXSTRING argv[],
  2093. PSZ queuename,
  2094. RXSTRING *retstr) {
  2095.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToZenkakuKatakana));
  2096. }
  2097.  
  2098. ULONG _Export 
  2099. RxJisQuotedPrintableTo(
  2100. PUCHAR name, 
  2101. ULONG argc,
  2102. RXSTRING argv[],
  2103. PSZ queuename,
  2104. RXSTRING *retstr) {
  2105.    return (RxJisCommon(name, argc, argv, queuename, retstr, QuotedPrintableTo));
  2106. }
  2107.  
  2108. ULONG _Export 
  2109. RxJisToJis(
  2110. PUCHAR name, 
  2111. ULONG argc,
  2112. RXSTRING argv[],
  2113. PSZ queuename,
  2114. RXSTRING *retstr) {
  2115.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToJis, JisSize));
  2116. }
  2117.  
  2118. ULONG _Export 
  2119. RxJisToBase64(
  2120. PUCHAR name, 
  2121. ULONG argc,
  2122. RXSTRING argv[],
  2123. PSZ queuename,
  2124. RXSTRING *retstr) {
  2125.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToBase64, Base64Size));
  2126. }
  2127.  
  2128. ULONG _Export 
  2129. RxJisToQuotedPrintable(
  2130. PUCHAR name, 
  2131. ULONG argc,
  2132. RXSTRING argv[],
  2133. PSZ queuename,
  2134. RXSTRING *retstr) {
  2135.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToQuotedPrintable, QuotedPrintableSize));
  2136. }
  2137.  
  2138. ULONG _Export                                                                
  2139. RxJisToEuc(                                                                  
  2140. PUCHAR name,                                                                 
  2141. ULONG argc,                                                                  
  2142. RXSTRING argv[],                                                             
  2143. PSZ queuename,                                                               
  2144. RXSTRING *retstr) {                                                          
  2145.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToEuc, EucSize));
  2146. }                                                                            
  2147.  
  2148. ULONG _Export                                                                
  2149. RxJisKanjiAlias(                                                                  
  2150. PUCHAR name,                                                                 
  2151. ULONG argc,                                                                  
  2152. RXSTRING argv[],                                                             
  2153. PSZ queuename,                                                               
  2154. RXSTRING *retstr) {                                                          
  2155.    if (argc != 1) {
  2156.       return (CallingInvalid);
  2157.    } /* endif */
  2158.    if (NULL == retstr || RXNULLSTRING(argv[0])) {
  2159.       return (CallingInvalid);
  2160.    } /* endif */
  2161.    PSZ& source = RXSTRPTR(argv[0]);
  2162.    const int& sourcesize = RXSTRLEN(argv[0]);
  2163.    wchar_t* sourcewide = new wchar_t[sourcesize + 1]; 
  2164.    if (!sourcewide) {
  2165.       return (CallingInvalid);
  2166.    } /* endif */
  2167.    const size_t sourcewidesize = nmbstowcs(sourcewide, sourcesize + 1, source, sourcesize); 
  2168.    if (sourcewidesize != 1 || sourcewide[0] <= UCHAR_MAX) {
  2169.       return (CallingInvalid);
  2170.    } /* endif */
  2171.    if (!TableIsLoaded) {  
  2172.       LoadRxJisTables();  
  2173.    } /* endif */          
  2174.    wchar_t* t = new wchar_t[maxKanjiAliasSize];
  2175.    if (!t) {
  2176.       return (CallingInvalid);
  2177.    } /* endif */
  2178.    int n = JisKanjiAlias(sourcewide[0], t, maxKanjiAliasSize);
  2179.    if (n < 0) {
  2180.       return (CallingInvalid);
  2181.    } /* endif */
  2182.    if (0 == n) {    
  2183.       retstr->strlength = 0; 
  2184.       return (CallingValid); 
  2185.    } /* endif */             
  2186.    const int count = sizeof(wchar_t) * n;
  2187.    int minimumtargetsize = count + 1;                                 
  2188.    if (RXNULLSTRING(*retstr) || RXSTRLEN(*retstr) < minimumtargetsize) {  
  2189.       retstr->strlength = minimumtargetsize; 
  2190.       APIRET code = DosAllocMem((PPVOID)&retstr->strptr, retstr->strlength, PAG_COMMIT | PAG_READ | PAG_WRITE);
  2191.       if (code != NO_ERROR) {
  2192.          return (CallingInvalid);
  2193.       } /* endif */
  2194.    } /* endif */
  2195.    wcstombs(RXSTRPTR(*retstr), t, count);
  2196.    delete t;
  2197.    retstr->strlength = count;
  2198.    return (CallingValid);
  2199. }                                                                            
  2200.  
  2201. ULONG _Export                                                                
  2202. RxJisPriority(                                                                  
  2203. PUCHAR name,                                                                 
  2204. ULONG argc,                                                                  
  2205. RXSTRING argv[],                                                             
  2206. PSZ queuename,                                                               
  2207. RXSTRING *retstr) {                                                          
  2208.    if (!(0 == argc || 2 == argc)) {
  2209.       return (CallingInvalid);
  2210.    } /* endif */
  2211.    if (NULL == retstr) {
  2212.       return (CallingInvalid);
  2213.    } /* endif */
  2214.    if (2 == argc && (RXNULLSTRING(argv[0]) || RXNULLSTRING(argv[1]))) {
  2215.       return (CallingInvalid);
  2216.    } /* endif */
  2217.    APIRET code;
  2218.    if (2 == argc) {
  2219.       int nclass;
  2220.       int npri;
  2221.       int n = sscanf(RXSTRPTR(argv[0]), "%d", &nclass);
  2222.       if (n != 1 || nclass < PRTYC_NOCHANGE || nclass > PRTYC_FOREGROUNDSERVER) {
  2223.          return (CallingInvalid);
  2224.       } /* endif */
  2225.       LONG int delta;
  2226.       n = sscanf(RXSTRPTR(argv[1]), "%d", &delta);
  2227.       if (n != 1 || nclass < PRTYD_MINIMUM || nclass > PRTYD_MAXIMUM) {
  2228.          return (CallingInvalid);
  2229.       } /* endif */
  2230.       code = DosSetPriority(PRTYS_THREAD, nclass, delta, 0);
  2231.       if (code != NO_ERROR) {
  2232.          return (CallingInvalid);
  2233.       } /* endif */
  2234.    } /* endif */
  2235.    PTIB tib;
  2236.    PPIB pib;
  2237.    code = DosGetInfoBlocks(&tib, &pib);
  2238.    if (code != NO_ERROR) {
  2239.       return (CallingInvalid);
  2240.    } /* endif */
  2241.    const ULONG pri = tib->tib_ptib2->tib2_ulpri;
  2242.    const int ccls = (pri & 0x0000ff00) >> 8;
  2243.    const int cpri = pri & 0x000000ff;
  2244.    sprintf(RXSTRPTR(*retstr), "%d %d", ccls, cpri);
  2245.    retstr->strlength = strlen(RXSTRPTR(*retstr));
  2246.    return (CallingValid);
  2247. }                                                                            
  2248.  
  2249. ULONG _Export                                                                
  2250. RxJisTrace(                                                                  
  2251. PUCHAR name,                                                                 
  2252. ULONG argc,                                                                  
  2253. RXSTRING argv[],                                                             
  2254. PSZ queuename,                                                               
  2255. RXSTRING *retstr) {                                                          
  2256.    if (argc != 1 || RXNULLSTRING(argv[0]) || NULL == retstr) {
  2257.       return (CallingInvalid);
  2258.    } /* endif */
  2259.    time_t t = time(NULL);
  2260.    if ((time_t)(-1) == t) {
  2261.       return (CallingInvalid);
  2262.    } /* endif */
  2263.    struct tm *l = localtime(&t);
  2264.    const int s = RXSTRLEN(argv[0])+BUFSIZ;
  2265.    char *b = new char[s];
  2266.    if (!b) {
  2267.       return (CallingInvalid);
  2268.    } /* endif */
  2269.    PVOID a = NULL;
  2270.    APIRET apiret = NO_ERROR;
  2271.    HQUEUE hqueue = NULLHANDLE;
  2272.    PID serverpid = 0;
  2273.    size_t n = strftime(b, BUFSIZ - 3, "%Y%m%d-%H%M%S: ", l);
  2274.    if (!n) {
  2275.       goto errorexit;
  2276.    } /* endif */
  2277.    strncpy(b + strlen(b), RXSTRPTR(argv[0]), RXSTRLEN(argv[0])+1);
  2278.    apiret = DosOpenQueue(&serverpid, &hqueue, PRINTFQNAME);
  2279.    if ( ERROR_QUE_NAME_NOT_EXIST == apiret ) {
  2280.       goto noerrorexit;
  2281.    } /* endif */
  2282.    if ( apiret != NO_ERROR ) {
  2283.       goto errorexit;
  2284.    } /* endif */
  2285.    apiret = DosAllocSharedMem(&a, NULL, s, OBJ_GIVEABLE | PAG_WRITE | PAG_COMMIT);
  2286.    if ( apiret != NO_ERROR ) {
  2287.       goto errorexit;
  2288.    } /* endif */
  2289.    apiret = DosGiveSharedMem(a, serverpid, PAG_READ);
  2290.    if ( apiret != NO_ERROR ) {
  2291.       goto errorexit;
  2292.    } /* endif */
  2293.    strncpy((char *)a, b, s);
  2294.    apiret = DosWriteQueue(hqueue, t, strlen((char *)a) + 1, a, 0);            
  2295.    if ( apiret != NO_ERROR ) {
  2296.       goto errorexit;
  2297.    } /* endif */
  2298.    apiret = DosFreeMem(a);
  2299.    if ( apiret != NO_ERROR ) {
  2300.       goto errorexit;
  2301.    } /* endif */
  2302.  
  2303.    noerrorexit:
  2304.  
  2305.    delete b;
  2306.    retstr->strlength = 0;
  2307.    return (CallingValid);
  2308.  
  2309.    errorexit:
  2310.    delete b;
  2311.    return (CallingInvalid);
  2312. }                                                                            
  2313.  
  2314. ULONG _Export                                                                
  2315. RxJisSyslog(                                                                  
  2316. PUCHAR name,                                                                 
  2317. ULONG argc,                                                                  
  2318. RXSTRING argv[],                                                             
  2319. PSZ queuename,                                                               
  2320. RXSTRING *retstr) {                                                          
  2321.    if (argc != 1 || RXNULLSTRING(argv[0]) || NULL == retstr) {
  2322.       return (CallingInvalid);
  2323.    } /* endif */
  2324.    time_t t = time(NULL);
  2325.    if ((time_t)(-1) == t) {
  2326.       return (CallingInvalid);
  2327.    } /* endif */
  2328.    struct tm *l = localtime(&t);
  2329.    const int s = RXSTRLEN(argv[0])+BUFSIZ;
  2330.    char *b = new char[s];
  2331.    if (!b) {
  2332.       return (CallingInvalid);
  2333.    } /* endif */
  2334.    size_t n = strftime(b, BUFSIZ - 3, "%y%m%d%H%M%S: ", l);
  2335.    if (!n) {
  2336.       delete b;
  2337.       return (CallingInvalid);
  2338.    } /* endif */
  2339.    strncpy(b + strlen(b), RXSTRPTR(argv[0]), RXSTRLEN(argv[0])+1);
  2340.    int rc = sendto(SyslogdSocket, b, strlen(b), 0, (struct sockaddr *)&syslogd, sizeof(syslogd));
  2341.    delete b;
  2342.    retstr->strlength = 0;
  2343.    return (CallingValid);
  2344. }                                                                            
  2345.  
  2346. ULONG _Export                                                                
  2347. RxJisEucTo(                                                                  
  2348. PUCHAR name,                                                                 
  2349. ULONG argc,                                                                  
  2350. RXSTRING argv[],                                                             
  2351. PSZ queuename,                                                               
  2352. RXSTRING *retstr) {                                                          
  2353.    return (RxJisCommon(name, argc, argv, queuename, retstr, EucTo));
  2354. }                                                                            
  2355.  
  2356. ULONG _Export                                                                
  2357. RxJisMimeJisTo(                                                              
  2358. PUCHAR name,                                                                 
  2359. ULONG argc,                                                                  
  2360. RXSTRING argv[],                                                             
  2361. PSZ queuename,                                                               
  2362. RXSTRING *retstr) {                                                          
  2363.    return (RxJisCommon(name, argc, argv, queuename, retstr, MimeJisTo));
  2364. }                                                                            
  2365.  
  2366. ULONG _Export                                                                
  2367. RxJisJisCharTo(                                                              
  2368. PUCHAR name,                                                                 
  2369. ULONG argc,                                                                  
  2370. RXSTRING argv[],                                                             
  2371. PSZ queuename,                                                               
  2372. RXSTRING *retstr) {                                                          
  2373.    return (RxJisCommon(name, argc, argv, queuename, retstr, JisCharTo));
  2374. }                                                                            
  2375.  
  2376. ULONG _Export                                                                
  2377. RxJisToJisChar(                                                              
  2378. PUCHAR name,                                                                 
  2379. ULONG argc,                                                                  
  2380. RXSTRING argv[],                                                             
  2381. PSZ queuename,                                                               
  2382. RXSTRING *retstr) {                                                          
  2383.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToJisChar));
  2384. }                                                                            
  2385.  
  2386. ULONG _Export                                                                
  2387. RxJisToDbcs(                                                              
  2388. PUCHAR name,                                                                 
  2389. ULONG argc,                                                                  
  2390. RXSTRING argv[],                                                             
  2391. PSZ queuename,                                                               
  2392. RXSTRING *retstr) {                                                          
  2393.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToDbcs, DbcsSize));
  2394. }                                                                            
  2395.  
  2396. ULONG _Export                                                                
  2397. RxJisToSbcs(                                                              
  2398. PUCHAR name,                                                                 
  2399. ULONG argc,                                                                  
  2400. RXSTRING argv[],                                                             
  2401. PSZ queuename,                                                               
  2402. RXSTRING *retstr) {                                                          
  2403.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToSbcs));
  2404. }                                                                            
  2405.  
  2406. ULONG _Export                                                                
  2407. RxJisToAscii(                                                              
  2408. PUCHAR name,                                                                 
  2409. ULONG argc,                                                                  
  2410. RXSTRING argv[],                                                             
  2411. PSZ queuename,                                                               
  2412. RXSTRING *retstr) {                                                          
  2413.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToAscii));
  2414. }                                                                            
  2415.  
  2416. ULONG _Export                                                                
  2417. RxJisToUpper(                                                              
  2418. PUCHAR name,                                                                 
  2419. ULONG argc,                                                                  
  2420. RXSTRING argv[],                                                             
  2421. PSZ queuename,                                                               
  2422. RXSTRING *retstr) {                                                          
  2423.    return (RxJisCommon(name, argc, argv, queuename, retstr, ToUpper));
  2424. }                                                                            
  2425.  
  2426. ULONG _Export                                                                
  2427. RxJisIso8859_1ToCp850(                                                              
  2428. PUCHAR name,                                                                 
  2429. ULONG argc,                                                                  
  2430. RXSTRING argv[],                                                             
  2431. PSZ queuename,                                                               
  2432. RXSTRING *retstr) {                                                          
  2433.    return (RxJisCommon(name, argc, argv, queuename, retstr, Iso8859_1ToCp850));
  2434. }                                                                            
  2435.  
  2436. ULONG _Export                                                                
  2437. RxJisIso8859_2ToCp852(                                                              
  2438. PUCHAR name,                                                                 
  2439. ULONG argc,                                                                  
  2440. RXSTRING argv[],                                                             
  2441. PSZ queuename,                                                               
  2442. RXSTRING *retstr) {                                                          
  2443.    return (RxJisCommon(name, argc, argv, queuename, retstr, Iso8859_2ToCp852));
  2444. }                                                                            
  2445.  
  2446. ULONG _Export                                                                
  2447. RxJisIso8859_9ToCp857(                                                              
  2448. PUCHAR name,                                                                 
  2449. ULONG argc,                                                                  
  2450. RXSTRING argv[],                                                             
  2451. PSZ queuename,                                                               
  2452. RXSTRING *retstr) {                                                          
  2453.    return (RxJisCommon(name, argc, argv, queuename, retstr, Iso8859_9ToCp857));
  2454. }                                                                            
  2455.  
  2456. ULONG _Export                                                                
  2457. RxJisCp857ToIso8859_9(                                                              
  2458. PUCHAR name,                                                                 
  2459. ULONG argc,                                                                  
  2460. RXSTRING argv[],                                                             
  2461. PSZ queuename,                                                               
  2462. RXSTRING *retstr) {                                                          
  2463.    return (RxJisCommon(name, argc, argv, queuename, retstr, Cp857ToIso8859_9));
  2464. }                                                                            
  2465.  
  2466. ULONG _Export                                                                
  2467. RxJisCp852ToIso8859_2(                                                              
  2468. PUCHAR name,                                                                 
  2469. ULONG argc,                                                                  
  2470. RXSTRING argv[],                                                             
  2471. PSZ queuename,                                                               
  2472. RXSTRING *retstr) {                                                          
  2473.    return (RxJisCommon(name, argc, argv, queuename, retstr, Cp852ToIso8859_2));
  2474. }                                                                            
  2475.  
  2476. ULONG _Export                                                                
  2477. RxJisCp850ToIso8859_1(                                                              
  2478. PUCHAR name,                                                                 
  2479. ULONG argc,                                                                  
  2480. RXSTRING argv[],                                                             
  2481. PSZ queuename,                                                               
  2482. RXSTRING *retstr) {                                                          
  2483.    return (RxJisCommon(name, argc, argv, queuename, retstr, Cp850ToIso8859_1));
  2484. }                                                                            
  2485.  
  2486. ULONG _Export                                                                
  2487. RxJisWords(                                                              
  2488. PUCHAR name,                                                                 
  2489. ULONG argc,                                                                  
  2490. RXSTRING argv[],                                                             
  2491. PSZ queuename,                                                               
  2492. RXSTRING *retstr) {                                                          
  2493.    if (argc != 1) {
  2494.       return (CallingInvalid);
  2495.    } /* endif */
  2496.    int count = JisWords(RXSTRPTR(argv[0]), RXSTRLEN(argv[0]));
  2497.    if (count < 0) {
  2498.       return (CallingInvalid);
  2499.    } /* endif */
  2500.    sprintf(RXSTRPTR(*retstr), "%d", count);
  2501.    retstr->strlength = strlen(RXSTRPTR(*retstr));
  2502.    return (CallingValid);
  2503. }                                                                            
  2504.  
  2505. ULONG _Export                                                                
  2506. RxJisWord(                                                              
  2507. PUCHAR name,                                                                 
  2508. ULONG argc,                                                                  
  2509. RXSTRING argv[],                                                             
  2510. PSZ queuename,                                                               
  2511. RXSTRING *retstr) {                                                          
  2512.    if (argc != 2) {
  2513.       return (CallingInvalid);
  2514.    } /* endif */
  2515.    if (NULL == retstr || RXNULLSTRING(argv[0]) || RXNULLSTRING(argv[1])) {
  2516.       return (CallingInvalid);
  2517.    } /* endif */
  2518.    PSZ& source = RXSTRPTR(argv[0]);
  2519.    const int& sourcesize = RXSTRLEN(argv[0]);
  2520.    int position = 0;
  2521.    int n = sscanf(RXSTRPTR(argv[1]), "%d", &position);
  2522.    if (n != 1 || position < 1) {
  2523.       return (CallingInvalid);
  2524.    } /* endif */
  2525.    if (0 == sourcesize) {    
  2526.       retstr->strlength = 0; 
  2527.       return (CallingValid); 
  2528.    } /* endif */             
  2529.    if (!TableIsLoaded) {  
  2530.       LoadRxJisTables();  
  2531.    } /* endif */          
  2532.    int minimumtargetsize = sourcesize + 1;                                 
  2533.    if (RXNULLSTRING(*retstr) || RXSTRLEN(*retstr) < minimumtargetsize) {  
  2534.       retstr->strlength = minimumtargetsize; 
  2535.       APIRET code = DosAllocMem((PPVOID)&retstr->strptr, retstr->strlength, PAG_COMMIT | PAG_READ | PAG_WRITE);
  2536.       if (code != NO_ERROR) {
  2537.          return (CallingInvalid);
  2538.       } /* endif */
  2539.    } /* endif */
  2540.    PSZ& target = RXSTRPTR(*retstr);
  2541.    const int& targetsize = RXSTRLEN(*retstr);
  2542.    int count = JisWord(target, source, targetsize, position, sourcesize);
  2543.    if (count < 0) {
  2544.       return (CallingInvalid);
  2545.    } /* endif */
  2546.    retstr->strlength = count;
  2547.    return (CallingValid);
  2548. }                                                                            
  2549.  
  2550. ULONG _Export                                                                
  2551. RxJisAppend(                                                              
  2552. PUCHAR name,                                                                 
  2553. ULONG argc,                                                                  
  2554. RXSTRING argv[],                                                             
  2555. PSZ queuename,                                                               
  2556. RXSTRING *retstr) {                                                          
  2557.    if (argc != 2) {
  2558.       return (CallingInvalid);
  2559.    } /* endif */
  2560.    if (NULL == retstr || RXNULLSTRING(argv[0]) || RXNULLSTRING(argv[1])) {
  2561.       return (CallingInvalid);
  2562.    } /* endif */
  2563.    if (!TableIsLoaded) {  
  2564.       LoadRxJisTables();  
  2565.    } /* endif */          
  2566.    PSZ& source = RXSTRPTR(argv[1]);
  2567.    const int& sourcesize = RXSTRLEN(argv[1]);
  2568.    const int& targetlength = RXSTRLEN(argv[0]);
  2569.    const int minimumtargetsize = targetlength + 1 + sourcesize + 1;                                 
  2570.    PSZ& target = RXSTRPTR(*retstr);
  2571.    if (!target || RXSTRLEN(*retstr) < minimumtargetsize) {  
  2572.       retstr->strlength = minimumtargetsize; 
  2573.       APIRET code = DosAllocMem((PPVOID)&target, RXSTRLEN(*retstr), PAG_COMMIT | PAG_READ | PAG_WRITE);
  2574.       if (code != NO_ERROR) {
  2575.          return (CallingInvalid);
  2576.       } /* endif */
  2577.    } /* endif */
  2578.    const int& targetsize = RXSTRLEN(*retstr);
  2579.    memcpy(target, RXSTRPTR(argv[0]), RXSTRLEN(argv[0]) + 1);
  2580.    int count = JisAppend(target, source, targetsize, targetlength, sourcesize);
  2581.    if (count < 0) {
  2582.       return (CallingInvalid);
  2583.    } /* endif */
  2584.    retstr->strlength = count;
  2585.    return (CallingValid);
  2586. }                                                                            
  2587.  
  2588. static int
  2589. parsenamevalue(
  2590. PCHAR target,
  2591. int targetsize,
  2592. PCHAR source,
  2593. int& sourceposition,
  2594. int sourcesize,
  2595. CHAR delimiter) {
  2596.    int count = 0;
  2597.    while (sourceposition < sourcesize) {
  2598.       if (IsDbcs1st(source[sourceposition])) {
  2599.          target[count++] = source[sourceposition++];
  2600.          if (sourceposition < sourcesize) {
  2601.             target[count++] = source[sourceposition++];
  2602.          } /* endif */
  2603.          continue;
  2604.       } /* endif */
  2605.       if (delimiter == source[sourceposition]) {
  2606.          sourceposition += 1;
  2607.          break;
  2608.       } /* endif */
  2609.       switch (source[sourceposition]) {
  2610.       case '%':
  2611.          sourceposition += 1;
  2612.          if (sourceposition + 1 < sourcesize) {
  2613.             int code;
  2614.             sscanf(&source[sourceposition], "%2x", &code);
  2615.             sourceposition += 2;
  2616.             target[count++] = code;
  2617.          } /* endif */
  2618.          break;
  2619.       case '+':
  2620.          target[count++] = ' ';
  2621.          sourceposition += 1;
  2622.          break;
  2623.       default: 
  2624.         target[count++] = source[sourceposition++];
  2625.         break;
  2626.       } /* endswitch */
  2627.    } /* endwhile */
  2628.    target[count] = '\0';
  2629.    return (count);
  2630. }
  2631.  
  2632. static int
  2633. setrexxvar(
  2634. PCHAR varname,
  2635. PCHAR varvalue,
  2636. int varvaluesize) {
  2637.    SHVBLOCK block;
  2638.    block.shvcode = RXSHV_SYSET;
  2639.    block.shvret = RXSHV_OK;
  2640.    block.shvnext = NULL;
  2641.    MAKERXSTRING(block.shvname, varname, strlen(varname));
  2642.    MAKERXSTRING(block.shvvalue, varvalue, varvaluesize);
  2643.    ULONG rc = RexxVariablePool(&block);
  2644.    if (RXSHV_NOAVL == rc || ~(RXSHV_OK | RXSHV_NEWV) & block.shvret) {
  2645.       return (CallingInvalid);
  2646.    } /* endif */
  2647.    return (CallingValid);
  2648. }
  2649.  
  2650. ULONG _Export                                                                
  2651. RxJisUrlToVar(                                                              
  2652. PUCHAR name,                                                                 
  2653. ULONG argc,                                                                  
  2654. RXSTRING argv[],                                                             
  2655. PSZ queuename,                                                               
  2656. RXSTRING *retstr) {                                                          
  2657.    if (argc < 1 || argc > 2) {
  2658.       return (CallingInvalid);
  2659.    } /* endif */
  2660.    if (NULL == retstr || RXNULLSTRING(argv[0]) || (2 == argc && RXNULLSTRING(argv[1]) || RXSTRLEN(argv[1]) < 1)) {
  2661.       return (CallingInvalid);
  2662.    } /* endif */
  2663.    if (!TableIsLoaded) {  
  2664.       LoadRxJisTables();  
  2665.    } /* endif */          
  2666.    PSZ& url = RXSTRPTR(argv[0]);
  2667.    const int& urlsize = RXSTRLEN(argv[0]);
  2668.    const int worksize = urlsize + 1;
  2669.    PSZ stemname;
  2670.    if (2 == argc) {
  2671.       stemname = new CHAR[RXSTRLEN(argv[1]) + 1];
  2672.       strncpy(stemname, RXSTRPTR(argv[1]), RXSTRLEN(argv[1]) + 1);
  2673.       if ('.' == stemname[RXSTRLEN(argv[1]) - 1]) {
  2674.          stemname[RXSTRLEN(argv[1]) - 1] = '\0';
  2675.       } /* endif */
  2676.    } else {
  2677.       stemname = new CHAR[4];
  2678.       strncpy(stemname, "URL", 4);
  2679.    } /* endif */
  2680.    PCHAR varname = new CHAR[worksize];
  2681.    PCHAR varvalue = new CHAR[worksize];
  2682.    PCHAR temp = new CHAR[worksize];
  2683.    sprintf(varname, "%s.", stemname);
  2684.    if (setrexxvar(varname, "", 0) != CallingValid) {
  2685.       return (CallingInvalid);
  2686.    } /* endif */
  2687.    int i = 0;
  2688.    parsenamevalue(temp, worksize, url, i, urlsize, '?');
  2689.    while (i < urlsize) {
  2690.       int tempsize = parsenamevalue(temp, worksize, url, i, urlsize, '=');
  2691.       sprintf(varname, "%s.%s", stemname, temp);
  2692.       tempsize = parsenamevalue(temp, worksize, url, i, urlsize, '&');
  2693.       int varvaluesize = JisJisTo(varvalue, temp, worksize, tempsize);
  2694.       if (setrexxvar(varname, varvalue, varvaluesize) != CallingValid) {
  2695.          return (CallingInvalid);
  2696.       } /* endif */
  2697.    } /* endwhile */
  2698.    delete stemname;
  2699.    delete varname;
  2700.    delete varvalue;
  2701.    delete temp;
  2702.    retstr->strlength = 0;
  2703.    return (CallingValid);
  2704. }                                                                            
  2705.  
  2706. ULONG _Export                                                                
  2707. RxJisWordIndex(
  2708. PUCHAR name,                                                                 
  2709. ULONG argc,                                                                  
  2710. RXSTRING argv[],                                                             
  2711. PSZ queuename,                                                               
  2712. RXSTRING *retstr) {                                                          
  2713.    if (argc != 2) {
  2714.       return (CallingInvalid);
  2715.    } /* endif */
  2716.    if (NULL == retstr || RXNULLSTRING(argv[0]) || RXNULLSTRING(argv[1])) {
  2717.       return (CallingInvalid);
  2718.    } /* endif */
  2719.    PSZ& source = RXSTRPTR(argv[0]);
  2720.    const int& sourcesize = RXSTRLEN(argv[0]);
  2721.    int position = 0;
  2722.    int n = sscanf(RXSTRPTR(argv[1]), "%d", &position);
  2723.    if (n != 1 || position < 1) {
  2724.       return (CallingInvalid);
  2725.    } /* endif */
  2726.    if (0 == sourcesize) {    
  2727.       retstr->strlength = 0; 
  2728.       return (CallingValid); 
  2729.    } /* endif */             
  2730.    if (!TableIsLoaded) {  
  2731.       LoadRxJisTables();  
  2732.    } /* endif */          
  2733.    int minimumtargetsize = sourcesize + 1;                                 
  2734.    if (RXNULLSTRING(*retstr) || RXSTRLEN(*retstr) < minimumtargetsize) {  
  2735.       retstr->strlength = minimumtargetsize; 
  2736.       APIRET code = DosAllocMem((PPVOID)&retstr->strptr, retstr->strlength, PAG_COMMIT | PAG_READ | PAG_WRITE);
  2737.       if (code != NO_ERROR) {
  2738.          return (CallingInvalid);
  2739.       } /* endif */
  2740.    } /* endif */
  2741.    PSZ& target = RXSTRPTR(*retstr);
  2742.    const int& targetsize = RXSTRLEN(*retstr);
  2743.    int count = JisWordIndex(target, source, targetsize, position, sourcesize);
  2744.    if (count < 0) {
  2745.       return (CallingInvalid);
  2746.    } /* endif */
  2747.    sprintf(RXSTRPTR(*retstr), "%d", count);
  2748.    retstr->strlength = strlen(RXSTRPTR(*retstr));
  2749.    return (CallingValid);
  2750. }                                                                            
  2751.  
  2752. static APIRET
  2753. LoadRxJisTables(void) {
  2754.    if (TableIsLoaded) {  
  2755.       return (NO_ERROR); 
  2756.    } /* endif */
  2757.    PCHAR v;
  2758.    struct servent *syslogprot;
  2759.    syslogprot = getservbyname("syslog", "udp");
  2760.    if (!syslogprot) {
  2761.       goto sockerr;
  2762.    } /* endif */
  2763.    v = getenv(SyslogdVarName);                                                  
  2764.    if (!v) {                                                                          
  2765.       v = "localhost";
  2766.    } /* endif */                                                                     
  2767.    syslogd.sin_family = AF_INET;
  2768.    syslogd.sin_addr.s_addr = inet_addr(v);
  2769.    if (syslogd.sin_addr.s_addr == -1) {
  2770.       struct hostent *hp = gethostbyname(v);
  2771.       if (hp) {
  2772.          syslogd.sin_family = hp->h_addrtype;
  2773.          memcpy(&syslogd.sin_addr, hp->h_addr, sizeof(syslogd.sin_addr));
  2774.       } else {
  2775.          goto sockerr;
  2776.       } /* endif */                                                                     
  2777.    } /* endif */                                                                     
  2778.    syslogd.sin_port = syslogprot->s_port;
  2779.    SyslogdSocket = socket(AF_INET, SOCK_DGRAM, 0);
  2780.  
  2781.    sockerr:
  2782.  
  2783.    ULONG cplistsize;
  2784.    ULONG cplist[CpListSize];
  2785.    APIRET rc = DosQueryCp(sizeof(cplist), cplist, &cplistsize);
  2786.    if (rc != NO_ERROR) {
  2787.       return (rc);
  2788.    } /* endif */
  2789.    DefaultCodepage = cplist[0];
  2790.    if (943 == DefaultCodepage) {
  2791.       InJis90 = TRUE;
  2792.    } else {
  2793.       PCHAR v = getenv(JisEnvVarName);                                                  
  2794.       if (v) {                                                                          
  2795.          PCHAR s = strstr(v, Jis90Value);                                               
  2796.          if (s) {                                                                       
  2797.             InJis90 = TRUE;                                                             
  2798.          } /* endif */                                                                  
  2799.       } /* endif */                                                                     
  2800.    } /* endif */
  2801.    NoOfMimeEncodedWord = 2 * NoOfMimeCharSet;
  2802.    MimeEncodedWordTable = new MimeCharSet[NoOfMimeEncodedWord];
  2803.    for (int i = 0; i < NoOfMimeCharSet; i += 1) {
  2804.       int j = 2 * i;
  2805.       MimeEncodedWordTable[j].namesize = MimeEncodedWordTable[j+1].namesize = 2 + MimeCharSetTable[i].namesize + 3;
  2806.       MimeEncodedWordTable[j].charset = MimeEncodedWordTable[j+1].charset = MimeCharSetTable[i].charset;
  2807.       MimeEncodedWordTable[j].name = new char[MimeEncodedWordTable[j].namesize+1];
  2808.       MimeEncodedWordTable[j+1].name = new char[MimeEncodedWordTable[j+1].namesize+1];
  2809.       sprintf(MimeEncodedWordTable[j].name, "=?%s?B?", MimeCharSetTable[i].name);
  2810.       sprintf(MimeEncodedWordTable[j+1].name, "=?%s?Q?", MimeCharSetTable[i].name);
  2811.    } /* endfor */
  2812.    qsort(MimeEncodedWordTable, NoOfMimeEncodedWord, sizeof(MimeEncodedWordTable[0]), compcharset);
  2813.    CHAR name[BUFSIZ];
  2814.    HMODULE hmod;
  2815.    rc = DosLoadModule(name, sizeof(name), "PMNLS", &hmod);
  2816.    if (rc != NO_ERROR) {
  2817.       return (rc);
  2818.    } /* endif */
  2819.    rc = DosQueryProcAddr(hmod, 0L, "NLSFINDWORD", (PFN*)&NlsFindWord);
  2820.    if (rc != NO_ERROR) {
  2821.       return (rc);
  2822.    } /* endif */
  2823.    COUNTRYCODE cc;
  2824.    cc.country = 0;
  2825.    cc.codepage = DefaultCodepage;
  2826.    CHAR vec[BUFSIZ];
  2827.    rc = DosQueryDBCSEnv(sizeof(vec), &cc, vec);
  2828.    if (rc != NO_ERROR) {
  2829.       return (rc);
  2830.    } /* endif */
  2831.    for (i = 0; vec[i]; i += 2) {
  2832.       for (int j = vec[i]; j <= vec[i+1]; j += 1) {
  2833.          DbcsVec[j] = TRUE;
  2834.       } /* endfor */
  2835.    } /* endfor */
  2836.    TableIsLoaded = TRUE;
  2837.    return (NO_ERROR);
  2838. }
  2839.  
  2840. ULONG _Export 
  2841. RxJisLoadFuncs(
  2842. PUCHAR name, 
  2843. ULONG argc,
  2844. RXSTRING argv[],
  2845. PSZ queuename,
  2846. RXSTRING *retstr) {
  2847.    if (argc > 0) {
  2848.       return (CallingInvalid);
  2849.    } /* endif */
  2850.    for (int i = 0; i < NoOfEntries; i += 1) {
  2851.       ULONG code = RexxDeregisterFunction(RxJisFuncsTable[i]);
  2852.       switch (code) {
  2853.       case RXFUNC_OK:
  2854.       case RXFUNC_DEFINED:
  2855.       case RXFUNC_NOTREG:
  2856.          break;
  2857.       default:
  2858.          return (CallingInvalid);
  2859.       } /* endswitch */
  2860.       code = RexxRegisterFunctionDll(RxJisFuncsTable[i], RxJisDll, RxJisFuncsTable[i]);
  2861.       switch (code) {
  2862.       case RXFUNC_OK:
  2863.          break;
  2864.       default:
  2865.          return (CallingInvalid);
  2866.       } /* endswitch */
  2867.       if (code != RXFUNC_OK && code != RXFUNC_DEFINED) {
  2868.          return (CallingInvalid);
  2869.       } /* endif */
  2870.    } /* endfor */
  2871.    if (LoadRxJisTables() != NO_ERROR) {
  2872.       return (CallingInvalid);
  2873.    } /* endif */
  2874.    extern char *RxJisDate;
  2875.    extern char *RxJisTime;
  2876.    i = sprintf(RXSTRPTR(*retstr), "RXJIS Version: %s (%s %s)", RxJisVersion, RxJisDate, RxJisTime);
  2877.    if (i + 1 > RXSTRLEN(*retstr)) {
  2878.       return (CallingInvalid);
  2879.    } /* endif */
  2880.    retstr->strlength = i;
  2881.    return (CallingValid);
  2882. }
  2883.  
  2884. ULONG _Export  
  2885. RxJisDropFuncs(
  2886. PUCHAR name, 
  2887. ULONG argc,
  2888. RXSTRING argv[],
  2889. PSZ queuename,
  2890. RXSTRING *retstr) {
  2891.    if (argc > 0) {
  2892.       return (CallingInvalid);
  2893.    } /* endif */
  2894.    for (int i = 0; i < NoOfEntries; i += 1) {
  2895.       ULONG code = RexxDeregisterFunction(RxJisFuncsTable[i]);
  2896.       switch (code) {
  2897.       case RXFUNC_OK:
  2898.       case RXFUNC_DEFINED:
  2899.       case RXFUNC_NOTREG:
  2900.          break;
  2901.       default:
  2902.          return (CallingInvalid);
  2903.       } /* endswitch */
  2904.    } /* endfor */
  2905.    retstr->strlength = 0;
  2906.    return (CallingValid);
  2907. }
  2908.