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

  1. /******************************************
  2.  
  3.     Command Mode
  4.  
  5. *******************************************/
  6. #include    "defs.h"
  7.  
  8. static    int    cmd_diclist();
  9. static    int    cmd_dicselect(char *para);
  10. static    int    cmd_indexlist();
  11. static    int    cmd_copyright();
  12. static    int    cmd_menu();
  13. static    int    cmd_multilist();
  14. static    int    cmd_multiselect(char *para);
  15. static    int    cmd_pause(char *para);
  16. static    int    cmd_prompt(char *para);
  17. static    int    cmd_gaiji(char *para);
  18. static    int    cmd_bitmap(char *para);
  19. static    int    cmd_map(char *para);
  20. static    int    cmd_mapfile(char *para);
  21. static    int    cmd_color(char *para);
  22. static    int    cmd_pager(char *para);
  23. static    int    cmd_separate(char *para);
  24. static    int    cmd_history(char *para);
  25. static    int    cmd_log(char *para);
  26. static    int    cmd_help();
  27. static    int    cmd_quit();
  28.  
  29. static    struct    {
  30.         char    *cmds;
  31.         char    *help;
  32.         int    (*func)();
  33.     } cmds_list[] = {
  34.   { "diclist","            Dictionary List\n",    cmd_diclist },
  35.   { "dicselect"," <no>        Dictionary Select\n",    cmd_dicselect },
  36.   { "multilist","        Multi Index List\n",    cmd_multilist },
  37.   { "multiselect"," <no>    Multi Index Select\n",    cmd_multiselect },
  38.   { "indexlist","         All Index List\n",    cmd_indexlist },
  39.   { "menu","            Menu Select\n",        cmd_menu },
  40.   { "copyright","        Dictionary Copyright\n",cmd_copyright },
  41.   { "log"," <File Name>        Log File Set\n",    cmd_log },
  42.   { "bitmap"," <Code>        Gaiji Bitmap Display\n",cmd_bitmap },
  43.   { "map"," <Code> <Strings>    Gaiji String Maping\n",    cmd_map },
  44.   { "mapfile"," <File Name>    Gaiji Convert File\n",    cmd_mapfile },
  45.   { "gaiji"," [on/off]        Gaiji On/Off\n",    cmd_gaiji },
  46.   { "color"," [on/off]        Color Disp On/Off\n",    cmd_color },
  47.   { "pager"," [on/off]        Pager Disp On/Off\n",    cmd_pager },
  48.   { "pause"," [on/off]        Display Pause On/Off\n",cmd_pause },
  49.   { "prompt"," [on/off]        Prompt On/Off\n",    cmd_prompt },
  50.   { "separate"," [on/off]    Separate On/Off\n",    cmd_separate },
  51.   { "history", " [on/off]    History Input On/Off\n",cmd_history },
  52.   { "quit","            End of Dic\n",        cmd_quit },
  53.   { "end",    NULL,                    cmd_quit },
  54.   { "help",    NULL,                    cmd_help },
  55.   { "?",    NULL,                    cmd_help },
  56.  
  57.   { NULL, NULL, NULL } };
  58.  
  59. static    int    switch_flag(int flag, char *para)
  60. {
  61.     strlow(para);
  62.     if ( strcmp(para, "on") == 0 )
  63.     flag = TRUE;
  64.     else if ( strcmp(para, "off") == 0 )
  65.     flag = FALSE;
  66.     return flag;
  67. }
  68. static    int    cmd_diclist()
  69. {
  70.     main_dic_list();
  71.     return FALSE;
  72. }
  73. static    int    cmd_dicselect(char *para)
  74. {
  75.     if ( main_dic_select(ERR, para) )
  76.     return ERR;
  77.     printf("Change Dictionary %s\n", now_dic_menu->ttl);
  78.     return FALSE;
  79. }
  80. static    int    cmd_indexlist()
  81. {
  82.     dic_index_print();
  83.     return FALSE;
  84. }
  85. static    int    cmd_copyright()
  86. {
  87.     if ( IDX_COPR == NULL ) {
  88.     fprintf(stderr, "Not Copyright Block\n");
  89.     return FALSE;
  90.     }
  91.     dic_display(IDX_COPR->start_block, 0);
  92.     return FALSE;
  93. }
  94. static    int    cmd_menu()
  95. {
  96.     if ( IDX_MENU == NULL ) {
  97.     fprintf(stderr, "Not Menu Block\n");
  98.     return FALSE;
  99.     }
  100.     menu_disp_flg = TRUE;
  101.     dic_display(IDX_MENU->start_block, 0);
  102.     menu_disp_flg = FALSE;
  103.     return FALSE;
  104. }
  105. static    int    cmd_multilist()
  106. {
  107.     int     n;
  108.     MULTI   *mu;
  109.     MULPTR  *mi;
  110.  
  111.     if ( (mu = multi_top) == NULL ) {
  112.     fprintf(stderr, "Not Multi Index\n");
  113.     return FALSE;
  114.     }
  115.     printf("00:Standard Indexs\n");
  116.     n = 0;
  117.     while ( mu != NULL ) {
  118.     mi = mu->mul_list;
  119.     while ( mi != NULL ) {
  120.         printf("%02d:%s\n", ++n, mi->mul_ttl);
  121.         mi = mi->next;
  122.     }
  123.     mu = mu->next;
  124.     }
  125.     return FALSE;
  126. }
  127. static    int    cmd_multiselect(char *para)
  128. {
  129.     int     n, i;
  130.     MULTI   *mu;
  131.     MULPTR  *mi;
  132.  
  133.     if ( (mu = multi_top) == NULL ) {
  134.     fprintf(stderr, "Not Multi Index\n");
  135.     return FALSE;
  136.     }
  137.  
  138.     if ( (i = atoi(para)) <= 0 ) {
  139.     index_tab_init(0, index_max);
  140.     fprintf(stderr, "Change Standard Index\n");
  141.     return FALSE;
  142.     }
  143.  
  144.     n = 0;
  145.     while ( mu != NULL ) {
  146.     mi = mu->mul_list;
  147.     while ( mi != NULL ) {
  148.         if ( ++n == i ) {
  149.         printf("Change Index %s\n", mi->mul_ttl);
  150.         index_tab_init(mi->bs, mi->mx);
  151.         return FALSE;
  152.         }
  153.         mi = mi->next;
  154.     }
  155.     mu = mu->next;
  156.     }
  157.  
  158.     fprintf(stderr, "Not Multi Index\n");
  159.     return FALSE;
  160. }
  161. static    int    cmd_pause(char *para)
  162. {
  163.     pause_flg = switch_flag(pause_flg, para);
  164.     printf("Pause Flag %s\n", pause_flg ? "On":"Off");
  165.     return FALSE;
  166. }
  167. static    int    cmd_prompt(char *para)
  168. {
  169.     prompt_flg = switch_flag(prompt_flg, para);
  170.     printf("Prompt Flag %s\n", prompt_flg ? "On":"Off");
  171.     return FALSE;
  172. }
  173. static    int    cmd_gaiji(char *para)
  174. {
  175.     if ( now_dic_menu == NULL && dicin_gaiji_flag == 0 ) {
  176.     fprintf(stderr, "Not Gaiji Font\n");
  177.     return FALSE;
  178.     }
  179.  
  180.     gaiji_flag = switch_flag(gaiji_flag, para);
  181.  
  182.     if ( gaiji_flag ) {
  183.         if ( now_dic_menu != NULL )
  184.         Gaiji_init(now_dic_menu->gaz, now_dic_menu->gah);
  185.     else if ( dicin_gaiji_flag != 0 )
  186.         Gaiji_init(0, 0);
  187.     } else
  188.     Gaiji_close();
  189.  
  190.     printf("Gaiji Flag %s\n", gaiji_flag ? "On":"Off");
  191.     return FALSE;
  192. }
  193. static    int    cmd_bitmap(char *para)
  194. {
  195.     if ( Gaiji_display(htoi(para)) )
  196.     fprintf(stderr, "Not Gaiji Font\n");
  197.     return FALSE;
  198. }
  199. static    int    cmd_map(char *para)
  200. {
  201.     int     n;
  202.  
  203.     if ( (n = htoi(para)) == 0 ) {
  204.     fprintf(stderr, "Parameter Error ?\n");
  205.     return FALSE;
  206.     }
  207.  
  208.     while ( isxdigit((uchar)*para) )
  209.     para++;
  210.     while ( isspace((uchar)*para) )
  211.     para++;
  212.  
  213.     if ( Gaiji_maping(n, para) )
  214.     fprintf(stderr, "Error ? %04X > %s\n", n, para);
  215.  
  216.     return FALSE;
  217. }
  218. static    int    cmd_mapfile(char *para)
  219. {
  220.     if ( *para == '\0' ) {
  221.     if ( gaiji_map_file != NULL )
  222.         printf("Gaiji Map File is %s\n", gaiji_map_file);
  223.     else
  224.         printf("Not Define Gaiji Map File\n");
  225.     } else
  226.     Gaiji_config(para);
  227.  
  228.     return FALSE;
  229. }
  230. static    int    cmd_color(char *para)
  231. {
  232.     color_flag = switch_flag(color_flag, para);
  233.     printf("Color Flag %s\n", color_flag ? "On":"Off");
  234.     return FALSE;
  235. }
  236. static    int    cmd_pager(char *para)
  237. {
  238.     extdisp_flag = switch_flag(extdisp_flag, para);
  239.     printf("Pager Flag %s\n", extdisp_flag ? "On":"Off");
  240.     return FALSE;
  241. }
  242. static    int    cmd_separate(char *para)
  243. {
  244.     cutof_flag = switch_flag(cutof_flag, para);
  245.     printf("Separate Flag %s\n", cutof_flag ? "On":"Off");
  246.     return FALSE;
  247. }
  248. static    int    cmd_history(char *para)
  249. {
  250.     extinput_flag = switch_flag(extinput_flag, para);
  251.     printf("History Flag %s\n", extinput_flag ? "On":"Off");
  252.     return FALSE;
  253. }
  254. static    int    cmd_log(char *para)
  255. {
  256.     if ( *para != '\0' ) {
  257.     if ( ext_out_fp != NULL )
  258.         fclose(ext_out_fp);
  259.     if ( (ext_out_fp = fopen(para, "a")) == NULL &&
  260.          (ext_out_fp = fopen(para, "w")) == NULL ) {
  261.         fprintf(stderr, "Can't open %s\n", para);
  262.         return FALSE;
  263.     }
  264.     strcpy(ext_out_file, para);
  265.     }
  266.  
  267.     if ( ext_out_fp != NULL )
  268.     printf("Log Open %s\n", ext_out_file);
  269.     else
  270.     printf("Log Close\n");
  271.  
  272.     return FALSE;
  273. }
  274. static    int    cmd_help()
  275. {
  276.     int     n;
  277.  
  278.     for ( n = 0 ; cmds_list[n].cmds != NULL ; n++ ) {
  279.     if ( cmds_list[n].help != NULL )
  280.         printf("%s%s", cmds_list[n].cmds, cmds_list[n].help);
  281.     }
  282.     return FALSE;
  283. }
  284. static    int    cmd_quit()
  285. {
  286.     return ERR;
  287. }
  288. int    command(char *cmd)
  289. {
  290.     int     n;
  291.     char    *para;
  292.  
  293.     if ( *cmd == '/' )
  294.     cmd++;
  295.     para = cmd;
  296.     while ( !isspace((uchar)*para) && *para != '\0' )
  297.     para++;
  298.     if ( *para != '\0' )
  299.     *(para++) = '\0';
  300.     while ( isspace((uchar)*para) )
  301.     para++;
  302.     strlow(cmd);
  303.  
  304.     for ( n = 0 ; cmds_list[n].cmds != NULL ; n++ ) {
  305.     if ( strcmp(cmds_list[n].cmds, cmd) == 0 )
  306.         return (*(cmds_list[n].func))(para);
  307.     }
  308.  
  309.     fprintf(stderr, "Command Error %s\n", cmd);
  310.     return FALSE;
  311. }
  312.