home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / taropyon / edia / ccisrc / edipghlp.c < prev    next >
Text File  |  1995-06-20  |  5KB  |  194 lines

  1. /*************************************************************************
  2. *    プログラミングヘルパ
  3. *************************************************************************/
  4.  
  5. char       *MACROKEY_PGHELP_PATH = "ProgHelp_path";
  6. char       *_PGHELP_FN = "_index";
  7.  
  8. #define    _PGHELP_HASH_MAX        (16)
  9. #define    _PGHELP_SIZ_FNINF        (16)
  10.  
  11. #define    _PGHELP_SIZ_TAG            (40)    /* タグサイズ                    */
  12. #define    _PGHELP_SIZ_FNC            (28)    /* タグ格納する関数名の長さ        */
  13. #define    _PGHELP_POS_FNC            (_PGHELP_SIZ_TAG - _PGHELP_SIZ_FNC)
  14.                                         /* タグ中の関数名格納位置        */
  15.  
  16. int        _pgHelp_hash(char *name)
  17. {
  18.     int            hash, ch;
  19.  
  20.     hash = 0;
  21.     while ( *name )
  22.     {
  23.         ch = (*name) & 0xFF;
  24.         hash = hash + (ch * 31);
  25.         ++name;
  26.     }
  27.     return (hash & (_PGHELP_HASH_MAX-1));
  28. }
  29.  
  30. int        _pgHelp(char *name)
  31. {
  32.     char       *path, fnIndex[256], fn[256];
  33.     char       *fpIndex, *fp;
  34.     int            ret, hash, numfn, n, ch, i;
  35.     char        *s, *p, buf[BUFSIZ];
  36.     char       *fntbl, fninf[_PGHELP_SIZ_FNINF];
  37.     char        tag[_PGHELP_SIZ_TAG+4], func[_PGHELP_SIZ_FNC+4];
  38.  
  39.     char        fbuf[64];
  40.     long        fpos;
  41.  
  42.     int            x0, y0;
  43.     char       *dlg;
  44.     char       *txtPtr;
  45.  
  46.     DSP_writePage(1);
  47.     x0 = y0 = DLGPOS_CENTER_OF_SCN;
  48.     txtPtr = NULL;
  49.  
  50.     hash = _pgHelp_hash(name);
  51.     if ( (path = AMAC_getName( SysMacro, MACROKEY_PGHELP_PATH)) == NULL )
  52.     {
  53.         sprintf(buf, "%sMANUAL/", AplGetStartPath() );
  54.         AMAC_setKey( SysMacro, MACROKEY_PGHELP_PATH, buf );
  55.         if ( (path = AMAC_getName( SysMacro, MACROKEY_PGHELP_PATH)) == NULL )
  56.             return (ERR);
  57.     }
  58.  
  59.     /* インデックファイル名の取得    ------------------------------------*/
  60.     sprintf( fnIndex, "%s%s.%03d", path, _PGHELP_FN, hash );
  61.     if ( (fpIndex = fopen(fnIndex,"rb")) == NULL )
  62.     {
  63.         DLG_tmpMsgTime( DLGPOS_MOS_SET_CENTER, DLGPOS_MOS_SET_CENTER,
  64.             C_MBLACK, C_DLGBASE, COLMIX(C_ERROR,C_GRAY),
  65.             3, "  %s : \n  Can't open index file!! ", fnIndex );
  66.         return (ERR);
  67.     }
  68.  
  69.     ret = 0;
  70.     for(;;)
  71.     {
  72.         if ( fread(tag,_PGHELP_SIZ_TAG,1,fpIndex) < 1 )    /* ファイル位置情報    */
  73.         {
  74.             ret = -1;
  75.             break;
  76.         }
  77.         if ( strncmp( name, tag + _PGHELP_POS_FNC, _PGHELP_SIZ_FNC) == 0 )
  78.             break;
  79.     }
  80.     fclose(fpIndex);
  81.  
  82.     if ( ret )
  83.     {    /* 指定の検索パターンはない    */
  84.         DLG_tmpMsgTime( DLGPOS_MOS_SET_CENTER, DLGPOS_MOS_SET_CENTER,
  85.             C_MBLACK, C_DLGBASE, COLMIX(C_ERROR,C_GRAY),
  86.             3, "  %s : \n  Pattern not found!! ", name );
  87.         return (ERR);
  88.     }
  89.  
  90.     /* ファイル名テーブルの読み込み    ------------------------------------*/
  91.     sprintf( fnIndex, "%s%s.tbl", path, _PGHELP_FN );
  92.     if ( (fpIndex = fopen(fnIndex,"rb")) == NULL )
  93.     {
  94.         DLG_tmpMsgTime( DLGPOS_MOS_SET_CENTER, DLGPOS_MOS_SET_CENTER,
  95.             C_MBLACK, C_DLGBASE, COLMIX(C_ERROR,C_GRAY),
  96.             3, "  %s : \n  Can't open index file!! ", fnIndex );
  97.         return (ERR);
  98.     }
  99.     fpos = tag[0] * _PGHELP_SIZ_FNINF;
  100.     fseek(fpIndex,fpos,SEEK_SET);
  101.     fread(fninf,_PGHELP_SIZ_FNINF,1,fpIndex);
  102.     fclose(fpIndex);
  103.  
  104.     if ( fninf[0] != tag[0] )    /* ファイル番号が一致しない    */
  105.         return (ERR);
  106.  
  107.     sprintf(fn,"%s%s", path, fninf + 1);
  108.     if ( (fp = fopen(fn,"rb")) == NULL )
  109.     {
  110.         DLG_tmpMsgTime( DLGPOS_MOS_SET_CENTER, DLGPOS_MOS_SET_CENTER,
  111.             C_MBLACK, C_DLGBASE, COLMIX(C_ERROR,C_GRAY),
  112.             3, "  %s : \n  Can't open manual file!! ", fn );
  113.         return (ERR);
  114.     }
  115.     fpos = _getDword(tag + 1);
  116.     fseek(fp,fpos,SEEK_SET);
  117.  
  118.     /* 説明内容の読み込み    --------------------------------------------*/
  119.     fgets(buf,BUFSIZ,fp);    /* read header line */
  120.     while ( fgets(buf,BUFSIZ,fp) != NULL )
  121.     {
  122.         if ( buf[0] == '.' )
  123.             break;
  124.         txtPtr = DLG_txtSetLinBuf( txtPtr, 8, 80, "%s", buf );
  125.     }
  126.     fclose(fp);
  127.  
  128.     if ( (dlg = DLG_txtOpen(x0,y0,80,20,txtPtr,0)) == NULL )
  129.     {
  130.         DLG_txtFreeLinBuf( txtPtr );
  131.         return (ERR);
  132.     }
  133.     DLG_txtSetTitle( dlg, "PROGRAM HELPER" );
  134.     DLG_txtSetGuideMsg( dlg, "Function : %s", name );
  135.     DLG_txtStart( dlg );
  136.     DLG_txtClose( dlg );
  137.     DLG_txtFreeLinBuf( txtPtr );
  138.  
  139.     return (NORMAL);
  140. }
  141.  
  142.  
  143. /*************************************************************************
  144. *    カーソル位置の単語の説明を見る
  145. *************************************************************************/
  146.  
  147. int        TxdUsr_pg_help( char *txd )
  148. {
  149.     int            ret, ch, len;
  150.     char        func[_PGHELP_SIZ_FNC+4];
  151.     size_t        curLnL, curOfs;
  152.     char       *dlg;
  153.  
  154.     if ( TxdGet_selFlag(txd) != 0 )        /* 選択中なら処理しない    */
  155.         return (0);
  156.  
  157.     /* 現在カーソル位置を取得    */
  158.     curLnL = TxdGet_curPosLnL(txd);
  159.     curOfs = TxdGet_curPosOfs(txd);
  160.  
  161.     if ( (ch = TXD_getch(txd)) > 0 && ch < 256 && (isalpha(ch) || ch == '_') )
  162.     {
  163.         len = 0;
  164.         while( len < _PGHELP_SIZ_FNC )
  165.         {
  166.             ch = TXD_getch(txd);
  167.             TXD_cmdJump( txd, TXD_CUR_RIGHT );
  168.             if ( isalpha(ch) || isdigit(ch) || ch == '_' )
  169.             {
  170.                 func[len++] = ch;
  171.             } else
  172.                 break;
  173.         }
  174.         func[len] = '\0';
  175.         TXD_jumpPos( txd, curLnL, curOfs );
  176.         if ( len == 0 )
  177.             return (NORMAL);
  178.     } else
  179.         func[0] = '\0';
  180.  
  181.     DSP_writePage(1);
  182.     dlg = DLG_getsOpen( DLGPOS_MOS_SET_HOME, DLGPOS_MOS_SET_HOME, 320,
  183.         "検索パターンを入力してください。" );
  184.     DLG_getsSetTitle( dlg, "PATTERN" );
  185.     ret = DLG_getsStart( dlg, _PGHELP_SIZ_FNC, func );
  186.     DLG_getsClose(dlg);
  187.     if ( ret <= 0 )
  188.         return (0);
  189.  
  190.     _pgHelp( func );
  191.  
  192.     return (0);
  193. }
  194.