@

AOK's C Source Library Last Update: Nov.14,2006
uLSI C-86 Ver.3.30c ŽŽH”ŁvAuBorland C++ 5.5v‚ΕƒRƒ“ƒpƒCƒ‹o—ˆ‚ά‚·B

Macintosh ¨ Windows ‹@ŽνˆΛ‘Ά•ΆŽš•ΟŠ·
/*  Macintosh ¨ Windows ‹@ŽνˆΛ‘Ά•ΆŽš•ΟŠ·
 */

#include <stdio.h>

#define iskanji(c)  ((c)>=0x81&&(c)<=0x9f)||((c)>=0xe0&&(c)<=0xfc)
#define iskanji2(c) ((c)>=0x40&&(c)<=0x7e)||((c)>=0x80&&(c)<=0xfc)

/*  Macintosh -> Windows ‚Μƒe[ƒuƒ‹
 *
 *      Tue Feb 25 09:51:39 2003
 */

typedef struct {
    unsigned short maccode;
    unsigned short wincode;
} MAC2WIN_TABLE;

const MAC2WIN_TABLE m2w[] = {
    {0x005c,0x0000},{0x0080,0x005c},{0x00a0,0x0000},{0x00fd,0x0000}, /* E \EE */
    {0x00fe,0x0000},{0x815c,0x0000},{0x8160,0x0000},{0x8161,0x0000}, /* EEEE */
    {0x817c,0x0000},{0x8191,0x0000},{0x8192,0x0000},{0x81ca,0x0000}, /* EEEE */
    {0x8540,0x8740},{0x8541,0x8741},{0x8542,0x8742},{0x8543,0x8743}, /* ‡@‡A‡B‡C */
    {0x8544,0x8744},{0x8545,0x8745},{0x8546,0x8746},{0x8547,0x8747}, /* ‡D‡E‡F‡G */
    {0x8548,0x8748},{0x8549,0x8749},{0x854a,0x874a},{0x854b,0x874b}, /* ‡H‡I‡J‡K */
    {0x854c,0x874c},{0x854d,0x874d},{0x854e,0x874e},{0x854f,0x874f}, /* ‡L‡M‡N‡O */
    {0x8550,0x8750},{0x8551,0x8751},{0x8552,0x8752},{0x8553,0x8753}, /* ‡P‡Q‡R‡S */
    {0x855e,0x0000},{0x855f,0x0000},{0x8560,0x0000},{0x8561,0x0000}, /* EEEE */
    {0x8562,0x0000},{0x8563,0x0000},{0x8564,0x0000},{0x8565,0x0000}, /* EEEE */
    {0x8566,0x0000},{0x8567,0x0000},{0x8568,0x0000},{0x8569,0x0000}, /* EEEE */
    {0x856a,0x0000},{0x856b,0x0000},{0x856c,0x0000},{0x856d,0x0000}, /* EEEE */
    {0x856e,0x0000},{0x856f,0x0000},{0x8570,0x0000},{0x8571,0x0000}, /* EEEE */
    {0x857c,0x0000},{0x857d,0x0000},{0x857e,0x0000},{0x8580,0x0000}, /* EEEE */
    {0x8581,0x0000},{0x8582,0x0000},{0x8583,0x0000},{0x8584,0x0000}, /* EEEE */
    {0x8585,0x0000},{0x8592,0x0000},{0x8593,0x0000},{0x8594,0x0000}, /* EEEE */
    {0x8595,0x0000},{0x8596,0x0000},{0x8597,0x0000},{0x8598,0x0000}, /* EEEE */
    {0x8599,0x0000},{0x859a,0x0000},{0x859f,0x8754},{0x85a0,0x8755}, /* EE‡T‡U */
    {0x85a1,0x8756},{0x85a2,0x8757},{0x85a3,0x8758},{0x85a4,0x8759}, /* ‡V‡W‡X‡Y */
    {0x85a5,0x875a},{0x85a6,0x875b},{0x85a7,0x875c},{0x85a8,0x875d}, /* ‡Z‡[‡\‡] */
    {0x85a9,0x0000},{0x85aa,0x0000},{0x85b3,0xeeef},{0x85b4,0xeef0}, /* EEϊ@ϊA */
    {0x85b5,0xeef1},{0x85b6,0xeef2},{0x85b7,0xeef3},{0x85b8,0xeef4}, /* ϊBϊCϊDϊE */
    {0x85b9,0xeef5},{0x85ba,0xeef6},{0x85bb,0xeef7},{0x85bc,0xeef8}, /* ϊFϊGϊHϊI */
    {0x85bd,0x0000},{0x85be,0x0000},{0x85db,0x0000},{0x85dc,0x0000}, /* EEEE */
    {0x85dd,0x0000},{0x85de,0x0000},{0x85df,0x0000},{0x85e0,0x0000}, /* EEEE */
    {0x85e1,0x0000},{0x85e2,0x0000},{0x85e3,0x0000},{0x85e4,0x0000}, /* EEEE */
    {0x85e5,0x0000},{0x85e6,0x0000},{0x85e7,0x0000},{0x85e8,0x0000}, /* EEEE */
    {0x85e9,0x0000},{0x85ea,0x0000},{0x85eb,0x0000},{0x85ec,0x0000}, /* EEEE */
    {0x85ed,0x0000},{0x85ee,0x0000},{0x85ef,0x0000},{0x85f0,0x0000}, /* EEEE */
    {0x85f1,0x0000},{0x85f2,0x0000},{0x85f3,0x0000},{0x85f4,0x0000}, /* EEEE */
    {0x8640,0x876f},{0x8641,0x0000},{0x8642,0x8770},{0x8643,0x0000}, /* ‡oE‡pE */
    {0x8644,0x0000},{0x8646,0x8775},{0x8647,0x0000},{0x8648,0x8771}, /* E‡uE‡q */
    {0x8649,0x0000},{0x864a,0x8772},{0x864c,0x8773},{0x864d,0x8774}, /* E‡r‡s‡t */
    {0x864e,0x0000},{0x864f,0x0000},{0x8650,0x0000},{0x8651,0x0000}, /* EEEE */
    {0x8652,0x0000},{0x8653,0x0000},{0x8654,0x0000},{0x8655,0x0000}, /* EEEE */
    {0x8656,0x0000},{0x8657,0x0000},{0x8658,0x0000},{0x8659,0x0000}, /* EEEE */
    {0x865a,0x0000},{0x865b,0x0000},{0x865c,0x0000},{0x869b,0x8782}, /* EEE‡‚ */
    {0x869c,0x8783},{0x869d,0x8784},{0x869f,0x0000},{0x86a0,0x0000}, /* ‡ƒ‡„EE */
    {0x86a1,0x0000},{0x86a2,0x0000},{0x86a3,0x0000},{0x86a4,0x0000}, /* EEEE */
    {0x86a5,0x0000},{0x86a6,0x0000},{0x86b3,0x0000},{0x86b4,0x0000}, /* EEEE */
    {0x86b5,0x0000},{0x86c7,0x0000},{0x86c8,0x0000},{0x86c9,0x0000}, /* EEEE */
    {0x86ca,0x0000},{0x86cb,0x0000},{0x86cc,0x0000},{0x86cd,0x0000}, /* EEEE */
    {0x86cf,0x0000},{0x86d0,0x0000},{0x86d1,0x0000},{0x86d2,0x0000}, /* EEEE */
    {0x8740,0x0000},{0x8741,0x0000},{0x8742,0x0000},{0x8743,0x0000}, /* EEEE */
    {0x8744,0x0000},{0x8745,0x0000},{0x8746,0x0000},{0x8747,0x0000}, /* EEEE */
    {0x8748,0x0000},{0x8749,0x0000},{0x874a,0x0000},{0x874b,0x878c}, /* EEE‡Œ */
    {0x874c,0x0000},{0x874d,0x878a},{0x874e,0x0000},{0x874f,0x0000}, /* E‡ŠEE */
    {0x8750,0x878b},{0x8751,0x0000},{0x8752,0x0000},{0x8753,0x0000}, /* ‡‹EEE */
    {0x8754,0x0000},{0x8755,0x0000},{0x8756,0x0000},{0x8757,0x0000}, /* EEEE */
    {0x8758,0x0000},{0x8793,0x8785},{0x8794,0x8786},{0x8795,0x8787}, /* E‡…‡†‡‡ */
    {0x8796,0x8788},{0x8797,0x8789},{0x8798,0x0000},{0x8799,0x0000}, /* ‡ˆ‡‰EE */
    {0x879a,0x0000},{0x879b,0x0000},{0x879c,0x0000},{0x879e,0x0000}, /* EEEE */
    {0x879f,0x875f},{0x87a0,0x8761},{0x87a1,0x8762},{0x87a2,0x8760}, /* ‡_‡a‡b‡` */
    {0x87a3,0x0000},{0x87a4,0x0000},{0x87a5,0x0000},{0x87a6,0x0000}, /* EEEE */
    {0x87a7,0x8765},{0x87a8,0x8766},{0x87a9,0x8763},{0x87aa,0x0000}, /* ‡e‡f‡cE */
    {0x87ab,0x8764},{0x87ac,0x8767},{0x87ad,0x876d},{0x87ae,0x0000}, /* ‡d‡g‡mE */
    {0x87af,0x8768},{0x87b0,0x8769},{0x87b1,0x0000},{0x87b2,0x876b}, /* ‡h‡iE‡k */
    {0x87b3,0x876a},{0x87b4,0x876e},{0x87b5,0x876c},{0x87bd,0x0000}, /* ‡j‡n‡lE */
    {0x87be,0x0000},{0x87bf,0x0000},{0x87c0,0x0000},{0x87c1,0x0000}, /* EEEE */
    {0x87e5,0x878d},{0x87e6,0x878e},{0x87e7,0x878f},{0x87e8,0x877e}, /* ‡‡Ž‡‡~ */
    {0x87fa,0x0000},{0x8840,0x8793},{0x8841,0x8798},{0x8842,0x8799}, /* E‡“‡˜‡™ */
    {0x8854,0x8780},{0x8855,0x8781},{0x8868,0x0000},{0x886a,0x0000}, /* ‡€‡EE */
    {0x886b,0x0000},{0x886c,0x0000},{0x886d,0x0000},                 /* EEE   */
};

unsigned short bsearch_wincode(unsigned short maccode)
{
    int left, right, middle;
    left = 0;
    right = sizeof(m2w) / sizeof(m2w[0]) - 1;
    while (left < right) {
        middle = (left + right) / 2;
        if (m2w[middle].maccode < maccode)
            left = middle + 1;
        else
            right = middle;
    }
    if (m2w[left].maccode == maccode)
        return m2w[left].wincode;
    return maccode;
}

void maccode2wincode(void)
{
    unsigned char c;
    unsigned short m, s;
    int ch, mode = 0;
    while ((ch = fgetc(stdin)) != EOF) {
        c = ch;
        switch (mode) {
            case 0:
                if (iskanji(c)) {
                    m = (c << 8) & 0xFF00;
                    mode = 1;
                } else {
                    putchar(c);
                }
                break;
            case 1:
                m |= c;
                if (iskanji2(c)) {
                    s = bsearch_wincode(m);
                    if (s) {
                        putchar((char)(s >> 8));
                        putchar((char)(s & 0xFF));
                    } else {
                        putchar(0x81);
                        putchar(0x45);
                    }
                } else {
                    fprintf(stderr, "•s³‚Θ•ΆŽš >> 0x%04x\n", m);
                }
                mode = 0;
                break;
            default:
                break;
        }
    }
}

int main()
{
    maccode2wincode();
    return 0;
}

–ί‚ι Copyright (c) 2006 AOK. All Rights Reserved.