home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 3 / FREEWARE.BIN / towns_os / whisper / source / msg.c < prev    next >
Text File  |  1980-01-02  |  24KB  |  1,222 lines

  1. /****************************************
  2.  
  3.     Shell like Message Wind
  4.  
  5.     1990.9.25 make by ken
  6.  
  7. ******************************************/
  8. #include    <stdio.h>
  9. #include    <stdlib.h>
  10. #include    <string.h>
  11. #include    <ctype.h>
  12. #include    <time.h>
  13. #include    <mos.h>
  14. #include    "event.h"
  15. #include    "graphic.h"
  16. #include    "defs.h"
  17. #include    "coldef.h"
  18.  
  19. #define FUNC_MAX        (32*1024)
  20.  
  21. #define    HASH_MAX    16            /* 4,8,16,32... */
  22. #define    HASH(p)            hash_calc(p)
  23.  
  24. #define    MSG_MAX        128
  25. #define    BUF_MAX        256
  26.  
  27. #define    MSG_LEN        50
  28. #define    MSG_X1        112
  29. #define    MSG_Y1        120
  30. #define    MSG_XSIZ    (MSG_LEN*8+16)
  31. #define    MSG_YSIZ    (11*18+16)
  32. #define    MSG_X2        (MSG_X1+MSG_XSIZ-1)
  33. #define    MSG_Y2        (MSG_Y1+MSG_YSIZ-1)
  34.  
  35. #define    YES_X        (MSG_X1+17*8)
  36. #define    YES_Y        (MSG_Y1+10*18+12)
  37. #define    NO_X        (MSG_X1+25*8)
  38. #define    NO_Y        (MSG_Y1+10*18+12)
  39.  
  40. void    CHK_snd(void);
  41. void    CHK_eup(void);
  42. void    DSP_xline();
  43. int    MSG_run();
  44. int    iskan(char *p);
  45. int    kan_pos(char *str,int pos);
  46. void    key_in(void);
  47. void    key_out(void);
  48. int    kbhit(void);
  49. int    getkey(unsigned *ec);
  50. int    getch(void);
  51. int    keyword(char *file,int sw);
  52. void    getdir(char *dir);
  53. int    MSG_cfg_load(char *file);
  54. char    *secret_file(char *file);
  55. void    EDIT_KEY_set(int code,char *func);
  56. void    TERM_KEY_set(int code,char *func);
  57. void    KAN_KAN_open(void);
  58. void    KAN_close(void);
  59. void    CON_open(int no);
  60. void    CON_close();
  61. char    *CON_input(int ch);
  62. int    CON_redisp(int ofs);
  63.  
  64. typedef struct _MAC {
  65.     struct _MAC    *next;
  66.     char    *mac;
  67.     char    *str;
  68. } MACRO;
  69.  
  70. static int    msg_event=ERR;
  71. static int    msg_col=15,msg_bak=9,msg_lin=7,msg_lin2=8;
  72. static int    msg_len=0,msg_ox=0,msg_x=0,msg_y=0;
  73. static int    msg_sts=FALSE;
  74. static int    msg_open_flg=FALSE;
  75. static BLOCK    *msg_save=NULL;
  76.        int    msg_tab=8;
  77. static char    msg_buf[BUF_MAX];
  78.        char    func_buf[FUNC_MAX];
  79.        char     *func_ptr=func_buf;
  80. static MACRO    *topmac[HASH_MAX]={
  81.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  82.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  83. static MACRO    *topprc[HASH_MAX]={
  84.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  85.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  86.  
  87. int    hash_calc(register char *p)
  88. {
  89.     register int hs=0;
  90.  
  91.     while ( *p != '\0' )
  92.     hs = hs * 31 + *(p++);
  93.     return(hs & (HASH_MAX-1));
  94. }
  95. char    *strdup(char *str)
  96. {
  97.     register char *p;
  98.  
  99.     if ( (p = (char *)malloc(strlen(str)+1)) != NULL )
  100.     strcpy(p,str);
  101.     return p;
  102. }
  103. int    htoi(char *p)
  104. {
  105.     int     i=0;
  106.  
  107.     while ( isxdigit(*p) ) {
  108.     if ( isdigit(*p) )
  109.         i = i * 16 + (*p - '0');
  110.     else
  111.         i = i * 16 + (toupper(*p) - 'A' + 10);
  112.     p++;
  113.     }
  114.     return i;
  115. }
  116. void    tsleep(int sec)
  117. {
  118.     clock_t t;
  119.  
  120.     t = clock() + CLK_TCK * sec;
  121.     while ( t > clock() ) {
  122.     CHK_snd();
  123.     CHK_eup();
  124.     }
  125. }
  126. char    *get_word(char *buf,char *str)
  127. {
  128.     while ( *str != '\0' && (isalnum(*str) || *str == '_') )
  129.     *(buf++) = *(str++);
  130.     *buf = '\0';
  131.     return str;
  132. }
  133. char    *prcget(char *prc)
  134. {
  135.     register MACRO *mp;
  136.  
  137.     for ( mp = topprc[HASH(prc)] ; mp != NULL ; mp = mp->next ) {
  138.     if ( strcmp(mp->mac,prc) == 0 )
  139.         return mp->str;
  140.     }
  141.     return "";
  142. }
  143. void    prcset(char *prc,char *str)
  144. {
  145.     int    hs;
  146.     register MACRO *mp;
  147.  
  148.     hs = HASH(prc);
  149.     for ( mp = topprc[hs] ; mp != NULL ; mp = mp->next ) {
  150.     if ( strcmp(mp->mac,prc) == 0 ) {
  151.         free(mp->str);
  152.         mp->str = strdup(str);
  153.         return;
  154.     }
  155.     }
  156.     if ( (mp = (MACRO *)malloc(sizeof(MACRO))) != NULL ) {
  157.     mp->next = topprc[hs];
  158.     topprc[hs] = mp;
  159.     mp->mac = strdup(prc);
  160.     mp->str = strdup(str);
  161.     }
  162. }
  163. char    *macget(char *mac)
  164. {
  165.     register MACRO *mp;
  166.  
  167.     for ( mp = topmac[HASH(mac)] ; mp != NULL ; mp = mp->next ) {
  168.     if ( strcmp(mp->mac,mac) == 0 )
  169.         return mp->str;
  170.     }
  171.     return "";
  172. }
  173. void    macset(char *mac,char *str)
  174. {
  175.     int     hs;
  176.     register MACRO *mp;
  177.  
  178.     hs = HASH(mac);
  179.     for ( mp = topmac[hs] ; mp != NULL ; mp = mp->next ) {
  180.     if ( strcmp(mp->mac,mac) == 0 ) {
  181.         free(mp->str);
  182.         mp->str = strdup(str);
  183.         return;
  184.     }
  185.     }
  186.     if ( (mp = (MACRO *)malloc(sizeof(MACRO))) != NULL ) {
  187.     mp->next = topmac[hs];
  188.     topmac[hs] = mp;
  189.     mp->mac = strdup(mac);
  190.     mp->str = strdup(str);
  191.     }
  192. }
  193. void    macvalset(char *mac,int val)
  194. {
  195.     char    tmp[16];
  196.  
  197.     sprintf(tmp,"%d",val);
  198.     macset(mac,tmp);
  199. }
  200. int    macval(char *mac)
  201. {
  202.     return atoi(macget(mac));
  203. }
  204. char    *cutpara(char *arg,char *str)
  205. {
  206.     int     n=0,len=0;
  207.  
  208.     *arg = '\0';
  209.     if ( *str != '(' )
  210.     return str;
  211.     while ( len < (BUFSIZ - 2) && *(++str) != '\0' ) {
  212.     if ( iskan(str) ) {
  213.         *(arg++) = *(str++);
  214.         *(arg++) = *str;
  215.         len += 2;
  216.     } else if ( *str == '(' ) {
  217.         *(arg++) = *str;
  218.         n++;
  219.         len++;
  220.     } else if ( *str == ')' && --n < 0 ) {
  221.         str++;
  222.         break;
  223.     } else {
  224.         *(arg++) = *str;
  225.         len++;
  226.     }
  227.     }
  228.     *arg = '\0';
  229.     return str;
  230. }
  231. char    *cutcmds(char *str)
  232. {
  233.     int     n;
  234.  
  235.     if ( *(str++) != '{' )
  236.     return NULL;
  237.     for ( n = 0 ; *str != '\0' ; str++ ) {
  238.     if ( iskan(str) )
  239.         str++;
  240.     else if ( *str == '{' )
  241.         n++;
  242.     else if ( *str == '}' && --n < 0 )
  243.         return str;
  244.     }
  245.     return NULL;
  246. }
  247. char    *get_str(char *buf,char *str)
  248. {
  249.     int     n,len=0;
  250.     char    *p;
  251.     char    dmy[BUFSIZ];
  252.  
  253.     while ( len < (BUFSIZ - 2) && *str != '\0' ) {
  254.     if ( *str == '\\' ) {
  255.         str++;
  256.         switch(*(str++)) {
  257.         case 'n':
  258.         *(buf++) = 0x0D;
  259.         *(buf++) = 0x0A;
  260.         len += 2;
  261.         break;
  262.  
  263.         case 'r':
  264.         *(buf++) = 0x0D;
  265.         len++;
  266.         break;
  267.  
  268.         case 't':
  269.         *(buf++) = 0x09;
  270.         len++;
  271.         break;
  272.  
  273.         case 'b':
  274.         *(buf++) = 0x08;
  275.         len++;
  276.         break;
  277.  
  278.         case 'c':
  279.         *(buf++) = 0x0C;
  280.         len++;
  281.         break;
  282.  
  283.         case 'x':
  284.         n = 0;
  285.         while ( *str != '\0' ) {
  286.             if ( isdigit(*str) )
  287.             n = n * 16 + (*str - '0');
  288.             else if ( *str >= 'A' && *str <= 'F' )
  289.             n = n * 16 + (*str - 'A') + 10;
  290.             else if ( *str >= 'a' && *str <= 'f' )
  291.             n = n * 16 + (*str - 'a') + 10;
  292.             else
  293.             break;
  294.             str++;
  295.         }
  296.         *(buf++) = n;
  297.         len++;
  298.         break;
  299.  
  300.         case '(':
  301.         for ( p = dmy ; *str != '\0' ; ) {
  302.             if ( *str == ')' ) {
  303.             str++;
  304.             break;
  305.             }
  306.             *(p++) = *(str++);
  307.         }
  308.         *p = '\0';
  309.         p = macget(dmy);
  310.         while ( len < (BUFSIZ - 2) && *p != '\0' ) {
  311.             *(buf++) = *(p++);
  312.             len++;
  313.         }
  314.         break;
  315.  
  316.         default:
  317.         if ( *(str-1) == '0' ) {
  318.             n = 0;
  319.             while ( *str >= '0' && *str <= '7' )
  320.             n = n * 8 + (*(str++) - '0');
  321.             *(buf++) = n;
  322.         } else if ( isdigit(*(str-1)) ) {
  323.             n = 0; str--;
  324.             while ( isdigit(*str) )
  325.             n = n * 10 + (*(str++) - '0');
  326.             *(buf++) = n;
  327.         } else
  328.             *(buf++) = *(str-1);
  329.         len++;
  330.         break;
  331.         }
  332.     } else if ( *str == '"' ) {
  333.         str++;
  334.         break;
  335.  
  336.     } else if ( iskan(str) ) {
  337.         *(buf++) = *(str++);
  338.         *(buf++) = *(str++);
  339.         len += 2;
  340.  
  341.     } else {
  342.         *(buf++) = *(str++);
  343.         len++;
  344.     }
  345.     }
  346.     *buf = '\0';
  347.     return str;
  348. }
  349. char    *get_para(int *mode,int *no,char *tmp,char *str)
  350. {
  351.     int     n;
  352.  
  353.     *tmp = '\0';
  354.     *mode = (-1);
  355.  
  356.     if ( *str == '"' ) {
  357.     str = get_str(tmp,++str);
  358.     *mode = 0;
  359.  
  360.     } else if ( *str == '0' ) {
  361.     n = 0;
  362.     if ( *(++str) == 'x' ) {
  363.         str++;
  364.         while ( *str != '\0' ) {
  365.         if ( isdigit(*str) )
  366.             n = n * 16 + (*str - '0');
  367.         else if ( *str >= 'A' && *str <= 'F' )
  368.             n = n * 16 + (*str - 'A') + 10;
  369.         else if ( *str >= 'a' && *str <= 'f' )
  370.             n = n * 16 + (*str - 'a') + 10;
  371.         else
  372.             break;
  373.         str++;
  374.         }
  375.  
  376.     } else {
  377.         while ( *str >= '0' && *str <= '7' )
  378.         n = n * 8 + (*(str++) - '0');
  379.     }
  380.     *mode = 1;
  381.  
  382.     } else if ( isdigit(*str) ) {
  383.     n = 0;
  384.     do {
  385.         n = n * 10 + (*(str++) - '0');
  386.     } while ( isdigit(*str) );
  387.     *mode = 1;
  388.     
  389.     } else {
  390.     str = get_word(tmp,str);
  391.     *mode = 2;
  392.     }
  393.  
  394.     *no = n;
  395.  
  396.     return str;
  397. }
  398. char    *get_string(char *tmp,char *str)
  399. {
  400.     int     n;
  401.  
  402.     *tmp = '\0';
  403.  
  404.     if ( *str == '"' ) {
  405.     str = get_str(tmp,++str);
  406.  
  407.     } else if ( *str == '0' ) {
  408.     n = 0;
  409.     if ( *(++str) == 'x' ) {
  410.         str++;
  411.         while ( *str != '\0' ) {
  412.         if ( isdigit(*str) )
  413.             n = n * 16 + (*str - '0');
  414.         else if ( *str >= 'A' && *str <= 'F' )
  415.             n = n * 16 + (*str - 'A') + 10;
  416.         else if ( *str >= 'a' && *str <= 'f' )
  417.             n = n * 16 + (*str - 'a') + 10;
  418.         else
  419.             break;
  420.         str++;
  421.         }
  422.  
  423.     } else {
  424.         while ( *str >= '0' && *str <= '7' )
  425.         n = n * 8 + (*(str++) - '0');
  426.     }
  427.     sprintf(tmp,"%d",n);
  428.  
  429.     } else if ( isdigit(*str) ) {
  430.     n = 0;
  431.     do {
  432.         n = n * 10 + (*(str++) - '0');
  433.     } while ( isdigit(*str) );
  434.     sprintf(tmp,"%d",n);
  435.  
  436.     } else {
  437.     str = get_word(tmp,str);
  438.     strcpy(tmp,macget(tmp));
  439.     }
  440.  
  441.     return str;
  442. }
  443. int     cmp_func(char *str)
  444. {
  445.     int     ch,cd;
  446.     int     no1,no2;
  447.     int     md1,md2;
  448.     char    para1[BUFSIZ];
  449.     char    para2[BUFSIZ];
  450.  
  451.     md1 = md2 = (-1);
  452.  
  453.     str = get_para(&md1,&no1,para1,str);
  454.     if ( (ch = *str) != '\0' )
  455.     str = get_para(&md2,&no2,para2,++str);
  456.  
  457.     switch(md1) {
  458.     case (-1):
  459.     cd = ERR;
  460.     break;
  461.     case 0:
  462.     switch(md2) {
  463.     case (-1): cd = strlen(para1); break;
  464.     case 0:    cd = strcmp(para1,para2); break;
  465.     case 1:    cd = atoi(para1) - no2; break;
  466.     case 2:    cd = strcmp(para1,macget(para2)); break;
  467.     }
  468.     break;
  469.     case 1:
  470.     switch(md2) {
  471.     case (-1): cd = no1; break;
  472.     case 0:    cd = no1 - atoi(para2); break;
  473.     case 1:    cd = no1 - no2; break;
  474.     case 2:    cd = no1 - atoi(macget(para2)); break;
  475.     }
  476.     break;
  477.     case 2:
  478.     switch(md2) {
  479.     case (-1): cd = strlen(macget(para1)); break;
  480.     case 0:    cd = strcmp(macget(para1),para2); break;
  481.     case 1:    cd = atoi(macget(para1)) - no2; break;
  482.     case 2:    cd = strcmp(macget(para1),macget(para2)); break;
  483.     }
  484.     break;
  485.     }
  486.  
  487.     switch(ch) {
  488.     case '=': case '\0':
  489.     return (cd == 0);
  490.     case '!':
  491.     return (cd != 0);
  492.     case '<':
  493.     return (cd < 0);
  494.     case '>':
  495.     return (cd > 0);
  496.     }
  497.     return FALSE;
  498. }
  499. void    MSG_event(EVENT *ep)
  500. {
  501.     switch(ep->now) {
  502.  
  503.     case EVT_CLIP_MOS:
  504.     EVT_clip_on(ep);
  505.     case EVT_ON_MOS:
  506.     DSP_mos(1);
  507.     break;
  508.  
  509.     case EVT_SELECT_MOS:
  510.     msg_event = ep->no;
  511.     case EVT_DOLACK_MOS:
  512.     ep->now = EVT_NON;
  513.     case EVT_MOVE_MOS:
  514.     EVT_clip_off(ep);
  515.     case EVT_OFF_MOS:
  516.     DSP_mos(0);
  517.     break;
  518.     }
  519. }
  520. void    MOS_push(int x1,int y1,int x2,int y2)
  521. {
  522.     static int sw,x,y;
  523.  
  524.     if ( x1 != ERR ) {
  525.     MOS_rdpos(&sw,&x,&y);
  526.     MOS_horizon(x1,x2-8);
  527.     MOS_vertical(y1,y2-8);
  528.     } else {
  529.     MOS_horizon(0,632);
  530.     MOS_vertical(0,470);
  531.     MOS_setpos(x,y);
  532.     }
  533. }
  534. int    MSG_pause(int fg)
  535. {
  536.     unsigned ec;
  537.  
  538.     EVT_sw(YES_X,YES_Y," Y E S ",COL_CHR,msg_bak,500,MSG_event,TRUE);
  539.     if ( fg != FALSE )
  540.     EVT_sw(NO_X,NO_Y,"  N O  ",COL_CHR,msg_bak,500,MSG_event,FALSE);
  541.  
  542.     MOS_disp(TRUE);
  543.  
  544.     if ( fg != FALSE ) {
  545.     MOS_push(YES_X,YES_Y,NO_X+48,YES_Y+8);
  546.     MOS_setpos(NO_X-8,YES_Y+2);
  547.     } else {
  548.     MOS_push(YES_X,YES_Y,YES_X+48,YES_Y+8);
  549.     MOS_setpos(YES_X+28,YES_Y+2);
  550.     }
  551.  
  552.     key_in();        /* key buffer clear */
  553.     key_out();
  554.  
  555.     for ( msg_event = ERR ; msg_event == ERR ; ) {
  556.     EVT_loop(500);
  557.     if ( kbhit() != FALSE ) {
  558.         getkey(&ec); ec &= 0xFF00;
  559.         if ( ec == 0x7300 )
  560.         msg_event = TRUE;
  561.         else if ( ec == 0x7200 )
  562.         msg_event = FALSE;
  563.     }
  564.     }
  565.     EVT_level_free(500);
  566.  
  567.     MOS_disp(FALSE);
  568.     MOS_push(ERR,ERR,ERR,ERR);
  569.     DSP_xline(YES_X,YES_Y,NO_X+60,NO_Y+12,msg_bak,0);
  570.  
  571.     return msg_event;
  572. }
  573. int    MENU_tate(int x,int y,int col,char *argv[])
  574. {
  575.     int    i,n,max;
  576.     BLOCK  *save;
  577.  
  578.     for ( max = 0 ; argv[max] != NULL ; max++ );
  579.  
  580.     i = x+strlen(argv[0])*8+8;
  581.     n = y+max*22;
  582.  
  583.     MOS_disp(FALSE);
  584.     MOS_push(x,y,i,n);
  585.     MOS_setpos((x+i)/2,(y+n)/2);
  586.     save = DSP_push_vram(x,y,i,n);
  587.     DSP_box(x,y,i,n,COL_LINE,col);
  588.  
  589.     for ( i = 0 ; i < max ; i++ )
  590.     EVT_big_sw(x+2,y+i*22+2,argv[i],COL_CHR,col,500,MSG_event,i);
  591.  
  592.     MOS_disp(TRUE);
  593.     msg_event = ERR;
  594.  
  595.     while ( msg_event == ERR )
  596.     EVT_loop(500);
  597.  
  598.     EVT_level_free(500);
  599.     MOS_disp(FALSE);
  600.     MOS_push(ERR,ERR,ERR,ERR);
  601.     DSP_pop_vram(save);
  602.  
  603.     return msg_event;
  604. }
  605. int    MENU_state(int x,int y,int col,char *argv[])
  606. {
  607.     int    i,n,max;
  608.     BLOCK  *save;
  609.  
  610.     for ( max = 0 ; argv[max] != NULL ; max++ );
  611.  
  612.     i = x+strlen(argv[0])*8+8;
  613.     n = y+max*14+1;
  614.  
  615.     MOS_disp(FALSE);
  616.     MOS_push(x,y,i,n);
  617.     MOS_setpos((x+i)/2,(y+n)/2);
  618.     save = DSP_push_vram(x,y,i,n);
  619.     DSP_box(x,y,i,n,COL_LINE,col);
  620.  
  621.     for ( i = 0 ; i < max ; i++ )
  622.     EVT_sw(x+2,y+i*14+2,argv[i],COL_CHR,col,500,MSG_event,i);
  623.  
  624.     MOS_disp(TRUE);
  625.     msg_event = ERR;
  626.  
  627.     while ( msg_event == ERR )
  628.     EVT_loop(500);
  629.  
  630.     EVT_level_free(500);
  631.     MOS_disp(FALSE);
  632.     MOS_push(ERR,ERR,ERR,ERR);
  633.     DSP_pop_vram(save);
  634.  
  635.     return msg_event;
  636. }
  637. int    MENU_syoko(int x,int y,int col,char *argv[])
  638. {
  639.     int    i,n,max,len;
  640.     BLOCK  *save;
  641.  
  642.     for ( max = 0 ; argv[max] != NULL ; max++ );
  643.  
  644.     len = strlen(argv[0]);
  645.     i = x+(len*8+6)*max+3;
  646.     n = y+15;
  647.  
  648.     MOS_disp(FALSE);
  649.     MOS_push(x,y,i,n);
  650.     MOS_setpos((x+i)/2,(y+n)/2);
  651.     save = DSP_push_vram(x,y,x+(len*8+6)*max+3,y+15);
  652.     DSP_box(x,y,x+(len*8+6)*max+3,y+15,COL_LINE,col);
  653.  
  654.     for ( i = 0 ; i < max ; i++ )
  655.     EVT_sw(x+(len*8+6)*i+2,y+2,argv[i],COL_CHR,col,500,MSG_event,i);
  656.  
  657.     MOS_disp(TRUE);
  658.     msg_event = ERR;
  659.  
  660.     while ( msg_event == ERR )
  661.     EVT_loop(500);
  662.  
  663.     EVT_level_free(500);
  664.     MOS_disp(FALSE);
  665.     MOS_push(ERR,ERR,ERR,ERR);
  666.     DSP_pop_vram(save);
  667.  
  668.     return msg_event;
  669. }
  670. char    *MSG_getstr(int x,int y,int col,int bak,char *str,int max)
  671. {
  672.     int     i,n,ch,fg;
  673.     int     ofs=0,len=0,pos=0;
  674.     BLOCK   *save;
  675.     char    *p;
  676.     char    dmy[84];
  677.     static char tmp[84];
  678.  
  679.     cur_x = x;
  680.     cur_y = y;
  681.     key_in();
  682.     fg = macval("NOECHO");
  683.  
  684.     if ( str != NULL ) {
  685.     strcpy(tmp,str);
  686.     if ( (pos = len = strlen(str)) > 80 )
  687.         pos = len = 80;
  688.     }
  689.  
  690.     for ( ch = 0 ; ; ) {
  691.  
  692.     tmp[len] = '\0';
  693.  
  694.     ofs = 0;
  695.     n = pos;
  696.     while ( n >= (max - 4) ) {
  697.         ofs += (max / 2);
  698.         ofs = kan_pos(tmp,ofs);
  699.         n = pos - ofs;
  700.     }
  701.  
  702.     if ( (i = len - ofs) >= max )
  703.         i = kan_pos(tmp,ofs+max) - ofs;
  704.  
  705.     if ( fg == FALSE )
  706.         strncpy(dmy,&(tmp[ofs]),i);
  707.     else
  708.         memset(dmy,'*',i);
  709.  
  710.     dmy[i] = '\0';
  711.  
  712.         save = DSP_push_vram(x,y,x+(i+3)*8,y+15);
  713.         wrtstr(dmy,page_ofs,x/2+y*512,
  714.         col_cnv[col],col_cnv[bak],16);
  715.     DSP_xline(x+n*8,y+14,x+n*8+7,y+15,15,4);
  716.  
  717.     cur_x = x + n * 8;
  718.  
  719.     while ( (ch = getch()) == 0xFFFF );
  720.  
  721.     do {
  722.  
  723.         if ( ch == 0x08 && pos > 0 ) {
  724.         pos = kan_pos(tmp,pos-1);
  725.         p = &(tmp[pos]);
  726.         n = (iskan(p) ? 2:1);
  727.         strcpy(p,p+n);
  728.         len -= n;
  729.  
  730.         } else if ( ch == 0x7F ) {
  731.         if ( pos < len ) {
  732.             p = &(tmp[pos]);
  733.             n = (iskan(p) ? 2:1);
  734.             strcpy(p,p+n);
  735.             len -= n;
  736.         }
  737.  
  738.         } else if ( ch == 0x1C ) {
  739.         if ( pos < len )
  740.             pos += (iskan(&(tmp[pos])) ? 2:1);
  741.  
  742.         } else if ( ch == 0x1D ) {
  743.         if ( pos > 0 )
  744.             pos = kan_pos(tmp,pos-1);
  745.  
  746.         } else if ( ch >= ' ' && len < 80 ) {
  747.         if ( pos < len ) {
  748.             p = &(tmp[len]);
  749.             for ( i = len - pos ; i > 0 ; i--,p-- )
  750.             *p = *(p-1);
  751.         }
  752.         tmp[pos++] = ch;
  753.         len++;
  754.  
  755.         } else if ( ch == 0x0D ) {
  756.         msg_sts = FALSE;
  757.         goto ENDOF;
  758.         } else if ( ch == 0x1B ) {
  759.         msg_sts = ERR;
  760.         goto ENDOF;
  761.         }
  762.  
  763.     } while ( (ch = getch()) != 0xFFFF );
  764.  
  765.         DSP_pop_vram(save);
  766.     }
  767.  
  768. ENDOF:
  769.     DSP_pop_vram(save);
  770.     tmp[len] = '\0';
  771.     key_out();
  772.     return tmp;
  773. }
  774. int    MSG_open_wind(void)
  775. {
  776.     if ( msg_open_flg == FALSE ) {
  777.     msg_save = DSP_push_vram(MSG_X1,MSG_Y1,MSG_X2,MSG_Y2);
  778.     DSP_rbox(MSG_X1,MSG_Y1,MSG_X2,MSG_Y2,msg_lin,msg_lin2,msg_bak);
  779.     msg_open_flg = TRUE;
  780.     }
  781.     return TRUE;
  782. }
  783. int    MSG_close_wind(void)
  784. {
  785.     if ( msg_open_flg != FALSE )
  786.     DSP_pop_vram(msg_save);
  787.     msg_open_flg = FALSE;
  788.     msg_len = msg_ox = msg_x = msg_y = 0;
  789.     return FALSE;
  790. }
  791. void    MSG_flush(void)
  792. {
  793.     if ( msg_x == msg_ox )
  794.     return;
  795.  
  796.     MSG_open_wind();
  797.  
  798.     msg_buf[msg_x] = '\0';
  799.     wrtstr(&msg_buf[msg_ox],
  800.     page_ofs,(MSG_X1+msg_ox*8+8)/2+(MSG_Y1+msg_y*18+8)*512,
  801.     col_cnv[msg_col],col_cnv[msg_bak],16);
  802.     msg_ox = msg_x;
  803. }
  804. void    MSG_putc(char ch)
  805. {
  806.     msg_buf[msg_x++] = ch;
  807.     if ( msg_x >= MSG_LEN ) {
  808.     MSG_flush();
  809.     msg_ox = msg_x = 0;
  810.     msg_y++;
  811.     }
  812. }
  813. void    MSG_puts(char *str)
  814. {
  815.     int     n;
  816.  
  817.     while ( *str != '\0' ) {
  818.     switch(*str) {
  819.     case 0x0D:
  820.         MSG_flush();
  821.         msg_ox = msg_x = 0;
  822.         break;
  823.  
  824.     case 0x0A:
  825.         MSG_flush();
  826.         msg_y++;
  827.         break;
  828.  
  829.     case 0x08:
  830.         MSG_flush();
  831.         msg_ox = msg_x = msg_x - 1;
  832.         break;
  833.  
  834.     case 0x09:
  835.         n = msg_tab - (msg_x % msg_tab);
  836.         while ( n-- > 0 )
  837.             MSG_putc(' ');
  838.         break;    
  839.  
  840.     case 0x0C:
  841.         if ( msg_open_flg != FALSE )
  842.         DSP_rbox(MSG_X1,MSG_Y1,MSG_X2,MSG_Y2,msg_lin,msg_lin2,msg_bak);
  843.         msg_ox = msg_x = msg_y = 0;
  844.         break;    
  845.  
  846.     default:
  847.         MSG_putc(*str);
  848.         break;
  849.     }
  850.     str++;
  851.     }
  852.     MSG_flush();
  853. }
  854. int    MSG_echo(char *argv[])
  855. {
  856.     while ( *argv != NULL )
  857.     MSG_puts(*(argv++));
  858.     return FALSE;
  859. }
  860. int    MSG_input(char *argv[])
  861. {
  862.     char    *p;
  863.  
  864.     while ( *argv != NULL ) {
  865.     p = MSG_getstr(MSG_X1+msg_ox*8+8,MSG_Y1+msg_y*18+8,
  866.             msg_col,msg_bak,macget(*argv),MSG_LEN-msg_ox);
  867.     macset(*(argv++),p);
  868.     }
  869.     return msg_sts;
  870. }
  871. int    MSG_yes(char *argv[])
  872. {
  873.     int     cd;
  874.  
  875.     cd = MSG_pause(FALSE);
  876.     while ( *argv != NULL )
  877.         macvalset(*(argv++),cd);
  878.     return cd;
  879. }
  880. int    MSG_yesno(char *argv[])
  881. {
  882.     int     cd;
  883.  
  884.     cd = MSG_pause(TRUE);
  885.     while ( *argv != NULL )
  886.         macvalset(*(argv++),cd);
  887.     return cd;
  888. }
  889. int    MSG_color(char *argv[])
  890. {
  891.     int     n;
  892.  
  893.     if ( (n = atoi(*argv)) != 0 )
  894.     msg_col = n;
  895.     return n;
  896. }
  897. int    MSG_bakcol(char *argv[])
  898. {
  899.     int     n;
  900.  
  901.     if ( (n = atoi(*argv)) != 0 )
  902.     msg_bak = n;
  903.     return n;
  904. }
  905. int    MSG_lincol(char *argv[])
  906. {
  907.     int     n;
  908.  
  909.     if ( (n = atoi(*argv)) != 0 ) {
  910.     msg_lin = n | 8;
  911.     msg_lin2 = n;
  912.     }
  913.     return n;
  914. }
  915. int    TAB_set(char *argv[])
  916. {
  917.     msg_tab = atoi(argv[0]);
  918.     return msg_tab;
  919. }
  920. int    MSG_ext_cfg(char *argv[])
  921. {
  922.     return MSG_cfg_load(*argv);
  923. }
  924. int    MSG_menu_tate(char *argv[])
  925. {
  926.     return MENU_tate(atoi(argv[0]),atoi(argv[1]),atoi(argv[2]),&(argv[3]));
  927. }
  928. int    MSG_menu_state(char *argv[])
  929. {
  930.     return MENU_state(atoi(argv[0]),atoi(argv[1]),atoi(argv[2]),&(argv[3]));
  931. }
  932. int    MSG_menu_syoko(char *argv[])
  933. {
  934.     return MENU_syoko(atoi(argv[0]),atoi(argv[1]),atoi(argv[2]),&(argv[3]));
  935. }
  936. int    MSG_system(char *argv[])
  937. {
  938.     int    rc;
  939.     BLOCK  *save;
  940.  
  941.     save = DSP_push_vram(0,0,639,479);
  942.     KAN_close();
  943.     CON_open(999);
  944.     rc = system(*argv);
  945.     CON_close();
  946.     DSP_reinit();
  947.     DSP_pop_vram(save);
  948.     KAN_KAN_open();
  949.     return rc;
  950. }
  951. int    equl(char *ptn,char *str)
  952. {
  953.     while ( *ptn != '\0' ) {
  954.     if ( *ptn != toupper(*str) )
  955.         return FALSE;
  956.     ptn++;
  957.     str++;
  958.     }
  959.     return (*str == '\0' ? TRUE:FALSE);
  960. }
  961. int    MSG_command(char *argv[])
  962. {
  963.     int    ch,ofs=0;
  964.     unsigned ec;
  965.     BLOCK  *save;
  966.     char   *p;
  967.     char   tmp[BUFSIZ];
  968.  
  969.     save = DSP_push_vram(0,0,639,479);
  970.     CON_open(atoi(argv[0]));
  971.     key_in();
  972.  
  973.     getdir(tmp);
  974.     if ( (p = strrchr(tmp,'\\')) != NULL ) *p = '\0';
  975.     printf("%s> ",tmp);
  976.     for ( ; ; ) {
  977.     while ( kbhit() == 0 );
  978.  
  979.     ch = getkey(&ec);
  980.     ec &= 0xFF14;
  981.     if ( ec == 0x6E00 ) {
  982.         ofs += 5;
  983.         ofs = CON_redisp(ofs);
  984.  
  985.     } else if ( ec == 0x7000 ) {
  986.         if ( ofs > 0 ) {
  987.         ofs -= 5;
  988.             ofs = CON_redisp(ofs);
  989.         }
  990.  
  991.     } else if ( ch != 0xFFFF ) {
  992.         if ( ofs > 0 ) {
  993.         ofs = 0;
  994.         CON_redisp(ofs);
  995.         }
  996.         if ( (p = CON_input(ch)) != NULL ) {
  997.         if ( *p == '\x1B' || equl("EXIT",p) ) {
  998.             printf("\n");
  999.             goto ENDOF;
  1000.         } else if ( *p != '\0' ) {
  1001.             system(p);
  1002.             printf("\n");
  1003.         }
  1004.         getdir(tmp);
  1005.         if ( (p = strrchr(tmp,'\\')) != NULL ) *p = '\0';
  1006.         printf("%s> ",tmp);
  1007.         }
  1008.     }
  1009.     }
  1010.  
  1011. ENDOF:
  1012.     key_out();
  1013.     CON_close();
  1014.     DSP_pop_vram(save);
  1015.     return FALSE;
  1016. }
  1017. int    MSG_wind(char *str)
  1018. {
  1019.     int     cd;
  1020.  
  1021.     str = prcget(str);
  1022.  
  1023.     if ( str == NULL || *str == '\0' )
  1024.     return ERR;
  1025.  
  1026.     MOS_disp(FALSE);
  1027.     mos_lock = TRUE;
  1028.     msg_open_flg = FALSE;
  1029.  
  1030.     msg_ox = msg_x = msg_y = 0;
  1031.     msg_lin = 7;
  1032.     msg_lin2 = 8;
  1033.     msg_col = 15;
  1034.     msg_event = ERR;
  1035.  
  1036.     cd = MSG_run(str);
  1037.  
  1038.     MSG_close_wind();
  1039.  
  1040.     MOS_disp(TRUE);
  1041.     mos_lock = FALSE;
  1042.  
  1043.     return cd;
  1044. }
  1045. int    MSG_cfg_load(char *file)
  1046. {
  1047.     int     n,nest=0;
  1048.     int     fun_flg = FALSE;
  1049.     FILE    *fp;
  1050.     char    *p,*s,*t;
  1051.     char    tmp[BUFSIZ];
  1052.     char    dmy[BUFSIZ];
  1053.  
  1054.     if ( (fp = fopen(file,"r")) == NULL )
  1055.     return ERR;
  1056.  
  1057.     while ( (p = fgets(tmp,BUFSIZ,fp)) != NULL ) {
  1058.  
  1059.     if ( (t = strrchr(p,'\n')) != NULL )
  1060.         *t = '\0';
  1061. LOOP:
  1062.     while ( isspace(*p) ) p++;
  1063.  
  1064.     if ( *p == '#' || *p == '\0' )
  1065.         continue;
  1066.  
  1067.     if ( fun_flg == FALSE ) {
  1068.  
  1069.         if ( *p == '.' ) {            /* edit key defs */
  1070.         n = htoi(p+1);
  1071.         if ( (p = strchr(p,'=')) == NULL )
  1072.             continue;
  1073.         for ( p++ ; isspace(*p) ; p++ );
  1074.         p = get_word(dmy,p);
  1075.         EDIT_KEY_set(n,dmy);
  1076.         continue;
  1077.  
  1078.         } else if ( *p == '^' ) {        /* term key defs */
  1079.         n = htoi(p+1);
  1080.         if ( (p = strchr(p,'=')) == NULL )
  1081.             continue;
  1082.         for ( p++ ; isspace(*p) ; p++ );
  1083.         p = get_word(dmy,p);
  1084.         TERM_KEY_set(n,dmy);
  1085.         continue;
  1086.         }
  1087.  
  1088.         p = get_word(dmy,p);
  1089.  
  1090.         if ( dmy[0] == '\0' )
  1091.         continue;
  1092.  
  1093.         while ( isspace(*p) ) p++;
  1094.  
  1095.         if ( *p == '=' ) {
  1096.         p++;
  1097.         while ( isspace(*p) ) p++;
  1098.         macset(dmy,p);
  1099.         continue;
  1100.  
  1101.         } else if ( *p == '{' ) {
  1102.         p++;
  1103.         while ( isspace(*p) ) p++;
  1104.         s = func_ptr;
  1105.         nest = 0;
  1106.         fun_flg = TRUE;
  1107.  
  1108.         } else
  1109.         continue;
  1110.     }
  1111.  
  1112.     while ( *p != '\0' ) {
  1113.         if ( *p == '#' )
  1114.         break;
  1115.         else if ( *p == '{' )
  1116.         nest++;
  1117.         else if ( *p == '}' && nest-- <= 0 ) {
  1118.         *s = '\0';
  1119.         prcset(dmy,func_ptr);
  1120.         fun_flg = FALSE;
  1121.         goto LOOP;
  1122.  
  1123.         } else if ( *p == '"' ) {
  1124.         do {
  1125.             if ( iskan(p) ) {
  1126.             if ( s < &func_buf[FUNC_MAX-2] )
  1127.                 *(s++) = *p;
  1128.             p++;
  1129.             }
  1130.             if ( s < &func_buf[FUNC_MAX-2] )
  1131.             *(s++) = *p;
  1132.             p++;
  1133.         } while ( *p != '\0' && *p != '"' );
  1134.  
  1135.         } else if ( iskan(p) ) {
  1136.         if ( s < &func_buf[FUNC_MAX-2] )
  1137.             *(s++) = *p;
  1138.         p++;
  1139.         }
  1140.  
  1141.         if ( s < &func_buf[FUNC_MAX-2] )
  1142.         *(s++) = *p;
  1143.         p++;
  1144.  
  1145.         while ( isspace(*p) ) p++;
  1146.     }
  1147.     }
  1148.  
  1149.     fclose(fp);
  1150.     return FALSE;
  1151. }
  1152. int    MSG_init(char *file,char *user)
  1153. {
  1154.     time_t  t;
  1155.     struct tm *tp;
  1156.     char    *p;
  1157.     char    tmp[80];
  1158.  
  1159.     time(&t);
  1160.     tp = localtime(&t);
  1161.     sprintf(msg_buf,"%02d/%02d/%02d",tp->tm_year,tp->tm_mon+1,tp->tm_mday);
  1162.     macset("DATE",msg_buf);
  1163.     sprintf(msg_buf,"%02d/%02d",tp->tm_mon+1,tp->tm_mday);
  1164.     macset("TODAY",msg_buf);
  1165.     sprintf(msg_buf,"%02d:%02d:%02d",tp->tm_hour,tp->tm_min,tp->tm_sec);
  1166.     macset("TIME",msg_buf);
  1167.  
  1168.     if ( file == NULL )
  1169.     getdir(tmp);
  1170.     else {
  1171.     strcpy(tmp,file);
  1172.     strcat(tmp,"\\");
  1173.     }
  1174.  
  1175.     macset("HOME",tmp);
  1176.     sprintf(msg_buf,"%sWHISPER.CFG",tmp);
  1177.     macset("SYSCFG",msg_buf);
  1178.     sprintf(msg_buf,"%s%s.USR",tmp,(user == NULL ? "NONAME":user));
  1179.     macset("USRCFG",msg_buf);
  1180.  
  1181.     if ( MSG_cfg_load(macget("SYSCFG")) != FALSE )
  1182.     return ERR;
  1183.  
  1184.     macset("KEYWORD","WHISPER");
  1185.     if ( (p = secret_file(macget("USRCFG"))) != NULL ) {
  1186.     MSG_cfg_load(p);
  1187.     remove(p);
  1188.     }
  1189.     macset("KEYWORD","");
  1190.     return FALSE;
  1191. }
  1192. void    MSG_end(void)
  1193. {
  1194.     int     i;
  1195.     char    *file;
  1196.     FILE    *fp;
  1197.     MACRO   *mp;
  1198.  
  1199.     file = macget("USRCFG");
  1200.     if ( (fp = fopen(file,"w")) == NULL )
  1201.     return;
  1202.  
  1203.     fprintf(fp,"NAME = %s\n",macget("NAME"));
  1204.     fprintf(fp,"BASDAY = %s\n",macget("BASDAY"));
  1205.     fprintf(fp,"LEVEL = %s\n",macget("LEVEL"));
  1206.     fprintf(fp,"ACOUNT = %s\n",macget("ACOUNT"));
  1207.     fprintf(fp,"FDATE = %s\n",macget("FDATE"));
  1208.     fprintf(fp,"LDATE = %s\n",macget("DATE"));
  1209.     fprintf(fp,"\n");
  1210.  
  1211.     for ( i = 0 ; i < HASH_MAX ; i++ ) {
  1212.     for ( mp = topmac[i] ; mp != NULL ; mp = mp->next ) {
  1213.         if ( *(mp->mac) == '_' )
  1214.         fprintf(fp,"%s = %s\n",mp->mac,mp->str);
  1215.     }
  1216.     }
  1217.  
  1218.     fclose(fp);
  1219.     macset("KEYWORD","WHISPER");
  1220.     keyword(file,0);
  1221. }
  1222.