home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / dic / src / dic.c < prev    next >
Text File  |  1995-06-20  |  19KB  |  762 lines

  1. /********************************************
  2.  
  3.     CD Dic Search Func
  4.  
  5. *********************************************/
  6. #include    "defs.h"
  7. #include    "dic.h"
  8.  
  9.     MULTI    *multi_top = NULL;
  10.  
  11.     int    index_tab_base = 0;
  12.     int    index_tab_max  = 0;
  13.  
  14.     INDEX    *index_ptr = NULL;
  15.     int    index_max = 0;
  16.     int    index_total = 0;
  17.     INDEX    index_buf[INDEX_MAX];
  18.     INDTAB    index_tab[] = {
  19.         { MK_KANA  , NULL },    /* かな検索用INDEX          */
  20.         { MK_ALPHA , NULL },    /* 英字検索用INDEX          */
  21.         { MK_KANJI , NULL },    /* 漢字検索用INDEX          */
  22.         { MK_HYOKI , NULL },    /* 表記形検索用INDEX        */
  23.         { MK_KKANA , NULL },    /* 後方一致かな検索用INDEX    */
  24.         { MK_KHYOKI, NULL },    /* 後方一致表記形検索用INDEX    */
  25.         { MK_KALPHA, NULL },    /* 後方一致英字検索用INDEX    */
  26.         { MK_TANGO , NULL },    /* 単語検索用INDEX        */
  27.         { MK_CROSS , NULL },    /* 見出し条件CROSS検索用INDEX    */
  28.         { MK_ZKANA , NULL },    /* 前方一致かな検索用INDEX    */
  29.         { MK_ZHYOKI, NULL },    /* 前方一致表記形検索用INDEX    */
  30.         { MK_ZALPHA, NULL },    /* 前方一致英字検索用INDEX    */
  31.         { MK_NUMBER, NULL },    /* 項目番号(数字)INDEX        */
  32.         { MK_MENU  , NULL },    /* メニュ-表示用DATA        */
  33.         { MK_COPR  , NULL }    /* 著作権表示用DATA        */
  34.     };
  35.  
  36. #define    SER_READ    0
  37. #define    SER_INIT    1
  38. #define    SER_KOTEI    2
  39. #define    SER_KAHEN    3
  40. #define    SER_KIHON    4
  41. #define    SER_CROSS    5
  42. #define    SER_NONTREE    6
  43. #define    SER_ERROR    7
  44.  
  45. static    int    key_stat = SER_READ;
  46. static    ulong    key_block = 0L;
  47. static    int    key_id, key_ent, key_len;
  48. static    int    key_size, key_flg;
  49. static    uchar    *key_ptr;
  50. static    uchar   key_org[COLS_MAX + 2];
  51. static    uchar   key_buf[COLS_MAX + 2];
  52.  
  53.     POINT    title;
  54.     POINT    honbun;
  55.  
  56. /********************************************
  57.  
  58.     Makeing Keyword Func
  59.  
  60. *********************************************/
  61.  
  62. #define    KATA2HIRA(ix)    (((ix)->type[0] & 0xC0) == 0x00)
  63. #define    LOW2UP(ix)    (((ix)->type[0] & 0x30) == 0x00)
  64. #define    NO2DEL(ix)    (((ix)->type[0] & 0x0C) == 0x00)
  65. #define    CYO2BON(ix)    (((ix)->type[0] & 0x03) == 0x00)
  66. #define    CYO2DEL(ix)    (((ix)->type[0] & 0x03) == 0x02)
  67. #define    STU2TU(ix)    (((ix)->type[1] & 0xC0) == 0x00)
  68. #define    SYA2YA(ix)    (((ix)->type[1] & 0x30) == 0x00)
  69. #define    SAI2AI(ix)    (((ix)->type[1] & 0x0C) == 0x00)
  70. #define    DAK2SEI(ix)    (((ix)->type[1] & 0x03) == 0x00)
  71. #define    HDA2SEI(ix)    (((ix)->type[2] & 0xC0) == 0x00)
  72.  
  73. static    uchar    *make_key(uchar *buf, uchar *str)
  74. {
  75.     int     n, ch;
  76.     int     old = 0;
  77.     int     len = 0;
  78.     static struct {
  79.     ushort        old;
  80.     ushort        cod;
  81.     } daku_tab[] = {
  82.     { 0x002c, 0x002b },        /* が */
  83.     { 0x002e, 0x002d },        /* ぎ */
  84.     { 0x0030, 0x002f },        /* ぐ */
  85.     { 0x0032, 0x0031 },        /* げ */
  86.     { 0x0034, 0x0033 },        /* ご */
  87.  
  88.     { 0x0036, 0x0035 },        /* ざ */
  89.     { 0x0038, 0x0037 },        /* じ */
  90.     { 0x003a, 0x0039 },        /* ず */
  91.     { 0x003c, 0x003b },        /* ぜ */
  92.     { 0x003e, 0x003d },        /* ぞ */
  93.  
  94.     { 0x0040, 0x003f },        /* だ */
  95.     { 0x0042, 0x0041 },        /* じ */
  96.     { 0x0045, 0x0044 },        /* ず */
  97.     { 0x0047, 0x0046 },        /* ぜ */
  98.     { 0x0049, 0x0048 },        /* ぞ */
  99.  
  100.     { 0x0050, 0x004f },        /* ば */
  101.     { 0x0053, 0x0052 },        /* び */
  102.     { 0x0056, 0x0055 },        /* ぶ */
  103.     { 0x0059, 0x0058 },        /* べ */
  104.     { 0x005c, 0x005b },        /* ぼ */
  105.  
  106.     { 0x0000, 0x0000 }
  107.  
  108.     }, hdaku_tab[] = {
  109.     { 0x0051, 0x004f },        /* ぱ */
  110.     { 0x0054, 0x0052 },        /* ぴ */
  111.     { 0x0057, 0x0055 },        /* ぷ */
  112.     { 0x005a, 0x0058 },        /* ぺ */
  113.     { 0x005d, 0x005b },        /* ぽ */
  114.  
  115.     { 0x0000, 0x0000 }
  116.     };
  117.  
  118.     while ( len < COLS_MAX ) {
  119.  
  120.     ch = *(str++) << 8;
  121.     ch |= *(str++);
  122.  
  123.     if ( ch == 0 )
  124.         break;
  125.  
  126.     if ( LOW2UP(index_ptr) && ch >= 0x2361 && ch <= 0x237a )/* a-z */
  127.         ch -= 0x20;
  128.  
  129.     if ( KATA2HIRA(index_ptr) && ch >= 0x2521 && ch <= 0x2576 )/* ァ-ヶ */
  130.         ch = 0x2400 | (ch & 0x00FF);
  131.  
  132.     if ( NO2DEL(index_ptr) &&
  133.             (ch == 0x2147 || ch == 0x215D || ch == 0x2126) )
  134.         continue;        /* ’- ・ */
  135.  
  136.     if ( (ch >= 0x2421 && ch <= 0x2476) ||
  137.          (ch >= 0x2521 && ch <= 0x2576) ) {
  138.  
  139.         if ( STU2TU(index_ptr) && (ch == 0x2443 || ch == 0x2543) )
  140.         ch++;
  141.  
  142.         if ( SYA2YA(index_ptr) ) {
  143.         switch(ch & 0x00FF) {
  144.         case 0x0063:        /* ゃ */
  145.         case 0x0065:        /* ゅ */
  146.         case 0x0067:        /* ょ */
  147.             ch++;
  148.             break;
  149.         }
  150.         }
  151.  
  152.         if ( SAI2AI(index_ptr) ) {
  153.         switch(ch & 0x00FF) {
  154.         case 0x0021:        /* ぁ */
  155.         case 0x0023:        /* ぃ */
  156.         case 0x0025:        /* ぅ */
  157.         case 0x0027:        /* ぇ */
  158.         case 0x0029:        /* ぉ */
  159.             ch++;
  160.             break;
  161.         }
  162.         }
  163.  
  164.         if ( DAK2SEI(index_ptr) ) {
  165.         for ( n = 0 ; daku_tab[n].old != 0 ; n++ ) {
  166.             if ( daku_tab[n].old == (ch & 0x00FF) ) {
  167.             ch = (ch & 0xFF00) | daku_tab[n].cod;
  168.             break;
  169.             }
  170.         }
  171.         }
  172.  
  173.         if ( HDA2SEI(index_ptr) ) {
  174.         for ( n = 0 ; hdaku_tab[n].old != 0 ; n++ ) {
  175.             if ( hdaku_tab[n].old == (ch & 0x00FF) ) {
  176.             ch = (ch & 0xFF00) | hdaku_tab[n].cod;
  177.             break;
  178.             }
  179.         }
  180.         }
  181.     }
  182.  
  183.     if ( ch == 0x213c ) {        /* ー */
  184.         if ( CYO2DEL(index_ptr) )
  185.         continue;
  186.         else if ( CYO2BON(index_ptr) &&
  187.         ((old >= 0x2421 && old <= 0x2476) || 
  188.          (old >= 0x2521 && old <= 0x2576)) ) {
  189.             switch(old & 0x00FF) {
  190.             case 0x0022: case 0x002b: case 0x0035: case 0x003f:
  191.             case 0x004a: case 0x004f: case 0x005e: case 0x0064:
  192.             case 0x0069: case 0x006f:
  193.             ch = (old & 0xFF00) | 0x0022;        /* あ */
  194.             break;
  195.             case 0x0024: case 0x002d: case 0x0037: case 0x0041:
  196.             case 0x004b: case 0x0052: case 0x005f: case 0x006a:
  197.             case 0x0070:
  198.             ch = (old & 0xFF00) | 0x0024;        /* い */
  199.             break;
  200.             case 0x0026: case 0x002f: case 0x0039: case 0x0044:
  201.             case 0x004c: case 0x0055: case 0x0060: case 0x0066:
  202.             case 0x006b:
  203.             ch = (old & 0xFF00) | 0x0026;        /* う */
  204.             break;
  205.             case 0x0028: case 0x0031: case 0x003b: case 0x0046:
  206.             case 0x004d: case 0x0058: case 0x0061: case 0x006c:
  207.             case 0x0071:
  208.             ch = (old & 0xFF00) | 0x0028;        /* え */
  209.             break;
  210.             case 0x002a: case 0x0033: case 0x003d: case 0x0048:
  211.             case 0x004e: case 0x005b: case 0x0062: case 0x0068:
  212.             case 0x006d: case 0x0072:
  213.             ch = (old & 0xFF00) | 0x002a;        /* お */
  214.             break;
  215.             case 0x0073:
  216.             ch = (old & 0xFF00) | 0x0073;        /* ん */
  217.             break;
  218.         }
  219.         }
  220.     }
  221.  
  222.     buf[len++] = (uchar)(ch >> 8);
  223.     buf[len++] = (uchar)(ch & 0xFF);
  224.     old = ch;
  225.     }
  226.  
  227.     buf[len++] = '\0';
  228.     buf[len++] = '\0';
  229.  
  230.     return buf;
  231. }
  232. static    INDEX    *key_index(uchar *str)
  233. {
  234.     int    ch, n;
  235.     int    now = KEY_NULL;
  236.     int    zenko = 0;
  237.     INDEX  *ix;
  238.     uchar  *top;
  239.     uchar  *s, *p;
  240.  
  241.     top = str;
  242.     zenkou_flag = FALSE;
  243.  
  244.     while ( now != KEY_HYOKI ) {
  245.     ch = *(str++) << 8;
  246.     ch |= *(str++);
  247.  
  248.     if ( ch == 0 ) {
  249.         break;
  250.  
  251.     } else if ( ch == 0x2121 || ch == 0x2147 ||
  252.             ch == 0x215D || ch == 0x2126 ) {
  253.         continue;
  254.  
  255.     } else if ( now == KEY_NULL && (ch == 0x2177 || ch == 0x215C) ) {
  256.         p = str;
  257.         for ( n = 0 ; *p != '\0' ; n += 2 )
  258.         p += 2;
  259.         memcpy(str - 2, str, n);
  260.         str -= 2;
  261.         str[n] = str[n + 1] = '\0';
  262.  
  263.         if ( ch == 0x2177 && IDX_CROSS != NULL )    /* @ */
  264.         return IDX_CROSS;
  265.         if ( ch == 0x215C && IDX_TANGO != NULL )    /* + */
  266.         return IDX_TANGO;
  267.         continue;
  268.         
  269.     } else if ( ch == 0x2176 || ch == 0x2141 ) {    /* *~ */
  270.         if ( now == KEY_NULL && zenko == 0 ) {
  271.             p = str;
  272.             for ( n = 0 ; *p != '\0' ; n += 2 )
  273.             p += 2;
  274.             memcpy(str - 2, str, n);
  275.             str -= 2;
  276.             str[n] = str[n + 1] = '\0';
  277.  
  278.         zenko = 2;
  279.             zenkou_flag = TRUE;
  280.         continue;
  281.  
  282.         } else if ( *str == 0 && *(str+1) == 0 ) {
  283.         *(str - 2) = *(str - 1) = '\0';
  284.         zenko = 1;
  285.             zenkou_flag = TRUE;
  286.         break;
  287.  
  288.         } else
  289.             n = KEY_HYOKI;        /* is Hyoki */
  290.         
  291.     } else if ( (ch >= 0x2341 && ch <= 0x235A) ||    /* A-Z */
  292.             (ch >= 0x2361 && ch <= 0x237A) ||    /* a-z */
  293.             (ch >= 0x2621 && ch <= 0x2638) ||    /* Α-Ω */
  294.             (ch >= 0x2641 && ch <= 0x2658) ||    /* α-ω */
  295.             (ch >= 0x2721 && ch <= 0x2741) ||    /* А-Я */
  296.             (ch >= 0x2751 && ch <= 0x2771) ||    /* а-я */
  297.             (ch == 0x2147) ) {            /* ’ */
  298.         n = KEY_ALPHA;    /* is Alpha */
  299.  
  300.     } else if ( (ch >= 0x2421 && ch <= 0x2476) ||    /* ぁ- */
  301.             (ch >= 0x2521 && ch <= 0x2576) ||    /* ァ-ヶ */
  302.                 ch == 0x213C ||        /* ー */
  303.                 ch == 0x212B ||        /* ゛ */
  304.                 ch == 0x212C ) {    /* ゜ */
  305.         n = KEY_KANA;    /* is Kana */
  306.  
  307.     } else if ( ch >= 0x2330 && ch <= 0x2339 ) {    /* 0-9 */
  308.         n = KEY_NUMBER;    /* is Number */
  309.  
  310.     } else if ( ch >= 0x3021 ) {    /* 亜 */
  311.         n = KEY_KANJI;    /* is Kanji */
  312.  
  313.     } else {
  314.         n = KEY_HYOKI;    /* is Hyoki */
  315.     }
  316.  
  317.     switch(now) {
  318.     case KEY_NULL:        /* Fast  */
  319.         now = n;
  320.         break;
  321.     case KEY_NUMBER:    /* Kanji */
  322.         if ( n != KEY_NUMBER && n != KEY_ALPHA )
  323.             now = KEY_HYOKI;
  324.         break;
  325.     case KEY_ALPHA:        /* Alpha */
  326.     case KEY_KANA:        /* Kana  */
  327.     case KEY_KANJI:        /* Kanji */
  328.         if ( now != n )
  329.         now = KEY_HYOKI;
  330.         break;
  331.     case KEY_HYOKI:        /* Hyoki */
  332.         break;
  333.     }
  334.     }
  335.  
  336.     switch(now) {
  337.     case KEY_ALPHA:
  338.     if ( zenko != 0 ) {
  339.         if ( zenko == 1 )
  340.             ix = IDX_ZALPHA;
  341.         else
  342.             ix = IDX_KALPHA;
  343.  
  344.         if ( ix == NULL )
  345.         ix = IDX_ALPHA;
  346.     } else
  347.         ix = IDX_ALPHA;
  348.  
  349.     if ( ix == NULL ) {
  350.         if ( IDX_ZALPHA != NULL )
  351.         ix = IDX_ZALPHA;
  352.         else
  353.         goto NOINDEX;
  354.     }
  355.     break;
  356.  
  357.     case KEY_KANA:
  358.     if ( zenko != 0 ) {
  359.         if ( zenko == 1 )
  360.             ix = IDX_ZKANA;
  361.         else
  362.             ix = IDX_KKANA;
  363.  
  364.         if ( ix == NULL )
  365.         ix = IDX_KANA;
  366.     } else
  367.         ix = IDX_KANA;
  368.  
  369.     if ( ix == NULL ) {
  370.         if ( IDX_ZKANA != NULL )
  371.         ix = IDX_ZKANA;
  372.         else
  373.         goto NOINDEX;
  374.     }
  375.     break;
  376.  
  377.     case KEY_KANJI:
  378.     if ( (ix = IDX_KANJI) == NULL )
  379.         goto NOINDEX;
  380.     break;
  381.  
  382.     case KEY_NUMBER:
  383.     if ( (ix = IDX_NUMBER) == NULL )
  384.         goto NOINDEX;
  385.     break;
  386.  
  387.     NOINDEX:
  388.     case KEY_HYOKI:
  389.     case KEY_NULL:
  390.     if ( zenko != 0 ) {
  391.         if ( zenko == 1 )
  392.             ix = IDX_ZHYOKI;
  393.         else
  394.             ix = IDX_KHYOKI;
  395.  
  396.         if ( ix == NULL )
  397.         ix = IDX_HYOKI;
  398.     } else
  399.         ix = IDX_HYOKI;
  400.  
  401.     if ( ix == NULL ) {
  402.         if ( IDX_ZHYOKI != NULL )
  403.         ix = IDX_ZHYOKI;
  404.         else
  405.         ix = NULL;
  406.     }
  407.     break;
  408.     }
  409.  
  410.     if ( ix != NULL &&
  411.     (ix->id == MK_KALPHA || ix->id == MK_KKANA ||
  412.                 ix->id == MK_KHYOKI) ) {
  413.     s = p = top;
  414.     while ( *p != 0 )
  415.         p += 2;
  416.     p -= 2;
  417.     while ( s < p ) {
  418.         ch = *s;
  419.         *s = *p;
  420.         *p = ch;
  421.         ch = *(s + 1);
  422.         *(s + 1) = *(p + 1);
  423.         *(p + 1) = ch;
  424.         s += 2;
  425.         p -= 2;
  426.     }
  427.     }
  428.  
  429.     if ( ix != NULL && zenkou_flag != FALSE ) {
  430.     switch(ix->id) {
  431.     case MK_KKANA: case MK_KHYOKI: case MK_KALPHA:
  432.     case MK_ZKANA: case MK_ZHYOKI: case MK_ZALPHA:
  433.         break;
  434.     default:
  435.         zenkou_flag = FALSE;
  436.         break;
  437.     }
  438.     }
  439.  
  440.     return ix;
  441. }
  442. static    int    reg_exp(register uchar *key, register uchar *idx, int len)
  443. {
  444.     int     cd;
  445.  
  446. #ifdef    DEBUG
  447.     put_jis(key, 256);
  448.     printf(" ? ");
  449.     put_jis(idx, len);
  450.     printf(" %d\n", len);
  451. #endif
  452.  
  453.     for ( ; ; ) {
  454.     if ( len == 0 && *key == '\0' )
  455.         return 0;
  456.     if ( len == 0 )
  457.         return 1;
  458.     if ( *key == '\0' )
  459.         return (zenkou_flag != FALSE ? 0:(-1));
  460.     if ( (cd = *key - *idx) != 0 )
  461.         return cd;
  462.     key++;
  463.     idx++;
  464.     len--;
  465.     }
  466. }
  467. static    ulong    key_to_number(uchar *str)
  468. {
  469.     int     ch;
  470.     ulong   no = 0L;
  471.  
  472.     for ( ; ; ) {
  473.     ch = *(str++) << 8;
  474.     ch |= *(str++);
  475.     if ( ch == 0 || ch < 0x2330 || ch > 0x2339 )    /* 0-9 */
  476.         break;
  477.     no = no * 10 + (ch - 0x2330);
  478.     }
  479.     return no;
  480. }
  481. int    init_serch(char *str)
  482. {
  483.     int     n, ch;
  484.     int     bs, mx;
  485.     uchar   *p;
  486.  
  487.     bs = index_tab_base;
  488.     mx = index_tab_max;
  489.  
  490.     p = str;
  491.     n = 0;
  492.     for ( ; ; ) {
  493.     ch = *(p++) << 8;
  494.     ch |= *(p++);
  495.     if ( ch < 0x2330 || ch > 0x2339 )    /* 0-9 */
  496.         break;
  497.     n = n * 10 + (ch - 0x2330);
  498.     }
  499.  
  500.     if ( ch == 0x2127 ) {        /* : */
  501.     if ( multi_select(n) )
  502.         return ERR;
  503.     str = p;
  504.     }
  505.  
  506.     str_word(key_org, str);
  507.  
  508.     if ( (index_ptr = key_index(key_org)) == NULL )
  509.     return ERR;
  510.  
  511.     make_key(key_buf, key_org);
  512.  
  513.     if ( ch == 0x2127 )
  514.     index_tab_init(bs, mx);
  515.  
  516. #ifdef    DEBUG
  517.     put_jis(key_org, 256); putchar('\n');
  518.     put_jis(key_buf, 256); putchar('\n');
  519. #endif
  520.  
  521.     key_block = index_ptr->start_block;
  522.  
  523.     if ( (index_ptr->id & 0xF0) >= 0xB0 &&
  524.      (index_ptr->id & 0xF0) <= 0xC0 ) {
  525.     key_stat = SER_NONTREE;
  526.     return FALSE;
  527.     }
  528.  
  529.     for ( ; ; ) {
  530.     if ( IO_block_read(key_block++) )
  531.         return ERR;
  532.  
  533.     key_id = dic_buf[0];
  534.  
  535.     if ( (key_id & 0x80) != 0 )        /* 最下位レベルなら */
  536.         break;
  537.  
  538.     key_len = dic_buf[1];
  539.     key_ent = toshort(dic_buf + 2);
  540.     key_ptr = dic_buf + 4;
  541.  
  542.     if ( key_len == 0 )        /* キ-長固定形式のはず! */
  543.         return ERR;
  544.  
  545.     for ( n = 0 ; n < key_ent ; n++ ) {
  546.         if ( reg_exp(key_buf, key_ptr, key_len) <= 0 ) {
  547.         key_block = tolong(key_ptr + key_len);
  548.         break;
  549.         }
  550.         key_ptr += (key_len + 4);
  551.     }
  552.  
  553.     if ( n >= key_ent && (key_id & 0x20) != 0 )    /* 最右端 */
  554.         return ERR;
  555.     }
  556.  
  557.     key_flg = 1;
  558.     key_stat = SER_INIT;
  559.  
  560.     return FALSE;
  561. }
  562. int    dic_serch()
  563. {
  564.     int     mk, cd;
  565.     ulong   no;
  566.  
  567.     for ( ; ; ) {
  568.     LOOP:
  569. #ifdef    DEBUG
  570.     printf("stat %d\n", key_stat);
  571. #endif
  572.     switch(key_stat) {
  573.     case SER_READ:
  574.         if ( (key_id & 0x20) != 0 || IO_block_read(key_block++) )
  575.             return ERR;
  576.         key_stat = SER_INIT;
  577.         break;
  578.  
  579.     case SER_INIT:
  580.         key_id  = dic_buf[0];
  581.  
  582.         if ( (key_id & 0x80) == 0 )        /* 最下位レベルでない */
  583.             return ERR;
  584.  
  585.         key_len = dic_buf[1];
  586.         key_ent = toshort(dic_buf + 2);
  587.         key_ptr = dic_buf + 4;
  588.  
  589.         if ( key_len != 0 ) {            /* キ-長固定形式 */
  590.         key_stat = SER_KOTEI;
  591.  
  592.         } else if ( (key_id & 0x10) == 0 ) {    /* キ-長可変 */
  593.         key_size = (index_ptr->id == MK_ZHYOKI ||
  594.                 index_ptr->id == MK_KHYOKI ||
  595.                 index_ptr->id == MK_ZALPHA ||
  596.                 index_ptr->id == MK_KALPHA ||
  597.                 index_ptr->id == MK_NUMBER ) ? 12:6;
  598.         key_stat = SER_KAHEN;
  599.  
  600.         } else {                /* キ-長可変で基本/集合 */
  601.         key_size = (index_ptr->id == MK_ZKANA ||
  602.                 index_ptr->id == MK_KKANA ) ? 12:6;
  603.         key_stat = (index_ptr->id == MK_CROSS ||
  604.                 index_ptr->id == MK_TANGO ) ? SER_CROSS:SER_KIHON;
  605.         }
  606.         break;
  607.  
  608.     case SER_KOTEI:
  609.         while ( key_ent-- > 0 ) {
  610.         if ( (cd = reg_exp(key_buf, key_ptr, key_len)) <= 0 ) {
  611.             title.block = 0L;
  612.             honbun.block  = tolong(key_ptr + key_len);
  613.             honbun.offset = toshort(key_ptr + key_len + 4);
  614.             key_ptr += (key_len + 6);
  615.             return (cd < 0 ? TRUE:FALSE);
  616.         }
  617.         key_ptr += (key_len + 6);
  618.         }
  619.         key_stat = SER_READ;
  620.         break;
  621.  
  622.     case SER_KAHEN:
  623.         while ( key_ent-- > 0 ) {
  624.         key_len = *(key_ptr++);
  625.         if ( (cd = reg_exp(key_buf, key_ptr, key_len)) <= 0 ) {
  626.             if ( key_size == 12 ) {
  627.             title.block = tolong(key_ptr + key_len + 6);
  628.             title.offset = toshort(key_ptr + key_len + 10);
  629.             } else
  630.             title.block = 0L;
  631.             honbun.block  = tolong(key_ptr + key_len);
  632.             honbun.offset = toshort(key_ptr + key_len + 4);
  633.             key_ptr += (key_len + key_size);
  634.             return (cd < 0 ? TRUE:FALSE);
  635.         }
  636.         key_ptr += (key_len + key_size);
  637.         }
  638.         key_stat = SER_READ;
  639.         break;
  640.  
  641.     case SER_KIHON:
  642.         while ( key_ent-- > 0 ) {
  643.         mk = *(key_ptr++);
  644.         key_len = *(key_ptr++);
  645.  
  646.         if ( mk == 0x00 && key_len == 0x00 ) {    /* Null */
  647.             if ( IO_block_read(key_block++) )
  648.             return ERR;
  649.             key_ptr = dic_buf + 4;
  650.             key_ent++;
  651.  
  652.         } else if ( mk == 0x00 ) {    /* 基本エントリ */
  653.             if ( (cd = reg_exp(key_buf, key_ptr, key_len)) <= 0 ) {
  654.             if ( key_size == 12 ) {
  655.                 title.block = tolong(key_ptr + key_len + 6);
  656.                 title.offset = toshort(key_ptr + key_len + 10);
  657.             } else
  658.                 title.block = 0L;
  659.                 honbun.block  = tolong(key_ptr + key_len);
  660.                 honbun.offset = toshort(key_ptr + key_len + 4);
  661.                 key_ptr += (key_len + key_size);
  662.                 return (cd < 0 ? TRUE:FALSE);
  663.             }
  664.             key_flg = 1;
  665.             key_ptr += (key_len + key_size);
  666.  
  667.         } else if ( mk == 0x80 ) {    /* キ-項目 */
  668.             /* key_sub = toshort(key_ptr); */
  669.             key_ptr += 2;
  670.             key_flg = reg_exp(key_buf, key_ptr, key_len);
  671.             key_ptr += key_len;
  672.  
  673.         } else if ( mk == 0xC0 ) {    /* メンバ項目 */
  674.             if ( (key_flg <  0 &&
  675.             (cd = reg_exp(key_org, key_ptr, key_len)) <= 0) ||
  676.              (key_flg == 0 &&
  677.             (cd = reg_exp(key_org, key_ptr, key_len)) == 0) ) {
  678.             if ( key_size == 12 ) {
  679.                 title.block = tolong(key_ptr + key_len + 6);
  680.                 title.offset = toshort(key_ptr + key_len + 10);
  681.             } else
  682.                 title.block = 0L;
  683.                 honbun.block  = tolong(key_ptr + key_len);
  684.                 honbun.offset = toshort(key_ptr + key_len + 4);
  685.                 key_ptr += (key_len + key_size);
  686.                 return (cd < 0 ? TRUE:FALSE);
  687.             }
  688.             key_ptr += (key_len + key_size);
  689.  
  690.         } else {
  691.             return ERR;
  692.         }
  693.         }
  694.         key_stat = SER_READ;
  695.         break;
  696.  
  697.     case SER_CROSS:            /* 単語クロス見出し用 */
  698.         while ( key_ent-- > 0 ) {
  699.         mk = *(key_ptr++);
  700.  
  701.         if ( mk == 0x00 ) {    /* 基本エントリ */
  702.             if ( (key_len = *(key_ptr++)) == 0 ) {
  703.                 if ( IO_block_read(key_block++) )
  704.                 return ERR;
  705.                 key_ptr = dic_buf + 4;
  706.                 key_ent++;
  707.             continue;
  708.             }
  709.  
  710.             if ( (cd = reg_exp(key_buf, key_ptr, key_len)) <= 0 ) {
  711.                 honbun.block  = tolong(key_ptr + key_len);
  712.                 honbun.offset = toshort(key_ptr + key_len + 4);
  713.             title.block = tolong(key_ptr + key_len + 6);
  714.             title.offset = toshort(key_ptr + key_len + 10);
  715.                 key_ptr += (key_len + 12);
  716.                 return (cd < 0 ? TRUE:FALSE);
  717.             }
  718.             key_flg = 1;
  719.             key_ptr += (key_len + 12);
  720.  
  721.         } else if ( mk == 0x80 ) {    /* キ-項目 */
  722.             key_len = *(key_ptr++);
  723.             /* key_sub = tolong(key_ptr); */
  724.             key_ptr += 4;
  725.             key_flg = reg_exp(key_buf, key_ptr, key_len);
  726.             title.block = tolong(key_ptr + key_len);
  727.             title.offset = toshort(key_ptr + key_len + 4);
  728.             key_ptr += (key_len + 6);
  729.  
  730.         } else if ( mk == 0xC0 ) {    /* メンバ項目 */
  731.             if ( key_flg <= 0 ) {
  732.                 honbun.block  = tolong(key_ptr);
  733.                 honbun.offset = toshort(key_ptr + 4);
  734.                 key_ptr += 6;
  735.                 return (key_flg < 0 ? TRUE:FALSE);
  736.             }
  737.             key_ptr += 6;
  738.  
  739.         } else {
  740.             return ERR;
  741.         }
  742.         }
  743.         key_stat = SER_READ;
  744.         break;
  745.  
  746.     case SER_NONTREE:
  747.         no = key_to_number(key_buf);
  748.         if ( IO_block_read(key_block + no / 341L) )
  749.         return ERR;
  750.         key_ptr = dic_buf + ((no % 341) * 6);
  751.         honbun.block  = tolong(key_ptr);
  752.         honbun.offset = toshort(key_ptr + 4);
  753.         title.block = 0L;
  754.         key_stat = SER_ERROR;
  755.         return FALSE;
  756.  
  757.     case SER_ERROR:
  758.         return ERR;
  759.     }
  760.     }
  761. }
  762.