home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix Heaven Sunny 2
/
APPARE2.BIN
/
oh_towns
/
dic
/
src
/
cmds.c
< prev
next >
Wrap
Text File
|
1995-06-20
|
8KB
|
312 lines
/******************************************
Command Mode
*******************************************/
#include "defs.h"
static int cmd_diclist();
static int cmd_dicselect(char *para);
static int cmd_indexlist();
static int cmd_copyright();
static int cmd_menu();
static int cmd_multilist();
static int cmd_multiselect(char *para);
static int cmd_pause(char *para);
static int cmd_prompt(char *para);
static int cmd_gaiji(char *para);
static int cmd_bitmap(char *para);
static int cmd_map(char *para);
static int cmd_mapfile(char *para);
static int cmd_color(char *para);
static int cmd_pager(char *para);
static int cmd_separate(char *para);
static int cmd_history(char *para);
static int cmd_log(char *para);
static int cmd_help();
static int cmd_quit();
static struct {
char *cmds;
char *help;
int (*func)();
} cmds_list[] = {
{ "diclist"," Dictionary List\n", cmd_diclist },
{ "dicselect"," <no> Dictionary Select\n", cmd_dicselect },
{ "multilist"," Multi Index List\n", cmd_multilist },
{ "multiselect"," <no> Multi Index Select\n", cmd_multiselect },
{ "indexlist"," All Index List\n", cmd_indexlist },
{ "menu"," Menu Select\n", cmd_menu },
{ "copyright"," Dictionary Copyright\n",cmd_copyright },
{ "log"," <File Name> Log File Set\n", cmd_log },
{ "bitmap"," <Code> Gaiji Bitmap Display\n",cmd_bitmap },
{ "map"," <Code> <Strings> Gaiji String Maping\n", cmd_map },
{ "mapfile"," <File Name> Gaiji Convert File\n", cmd_mapfile },
{ "gaiji"," [on/off] Gaiji On/Off\n", cmd_gaiji },
{ "color"," [on/off] Color Disp On/Off\n", cmd_color },
{ "pager"," [on/off] Pager Disp On/Off\n", cmd_pager },
{ "pause"," [on/off] Display Pause On/Off\n",cmd_pause },
{ "prompt"," [on/off] Prompt On/Off\n", cmd_prompt },
{ "separate"," [on/off] Separate On/Off\n", cmd_separate },
{ "history", " [on/off] History Input On/Off\n",cmd_history },
{ "quit"," End of Dic\n", cmd_quit },
{ "end", NULL, cmd_quit },
{ "help", NULL, cmd_help },
{ "?", NULL, cmd_help },
{ NULL, NULL, NULL } };
static int switch_flag(int flag, char *para)
{
strlow(para);
if ( strcmp(para, "on") == 0 )
flag = TRUE;
else if ( strcmp(para, "off") == 0 )
flag = FALSE;
return flag;
}
static int cmd_diclist()
{
main_dic_list();
return FALSE;
}
static int cmd_dicselect(char *para)
{
if ( main_dic_select(ERR, para) )
return ERR;
printf("Change Dictionary %s\n", now_dic_menu->ttl);
return FALSE;
}
static int cmd_indexlist()
{
dic_index_print();
return FALSE;
}
static int cmd_copyright()
{
if ( IDX_COPR == NULL ) {
fprintf(stderr, "Not Copyright Block\n");
return FALSE;
}
dic_display(IDX_COPR->start_block, 0);
return FALSE;
}
static int cmd_menu()
{
if ( IDX_MENU == NULL ) {
fprintf(stderr, "Not Menu Block\n");
return FALSE;
}
menu_disp_flg = TRUE;
dic_display(IDX_MENU->start_block, 0);
menu_disp_flg = FALSE;
return FALSE;
}
static int cmd_multilist()
{
int n;
MULTI *mu;
MULPTR *mi;
if ( (mu = multi_top) == NULL ) {
fprintf(stderr, "Not Multi Index\n");
return FALSE;
}
printf("00:Standard Indexs\n");
n = 0;
while ( mu != NULL ) {
mi = mu->mul_list;
while ( mi != NULL ) {
printf("%02d:%s\n", ++n, mi->mul_ttl);
mi = mi->next;
}
mu = mu->next;
}
return FALSE;
}
static int cmd_multiselect(char *para)
{
int n, i;
MULTI *mu;
MULPTR *mi;
if ( (mu = multi_top) == NULL ) {
fprintf(stderr, "Not Multi Index\n");
return FALSE;
}
if ( (i = atoi(para)) <= 0 ) {
index_tab_init(0, index_max);
fprintf(stderr, "Change Standard Index\n");
return FALSE;
}
n = 0;
while ( mu != NULL ) {
mi = mu->mul_list;
while ( mi != NULL ) {
if ( ++n == i ) {
printf("Change Index %s\n", mi->mul_ttl);
index_tab_init(mi->bs, mi->mx);
return FALSE;
}
mi = mi->next;
}
mu = mu->next;
}
fprintf(stderr, "Not Multi Index\n");
return FALSE;
}
static int cmd_pause(char *para)
{
pause_flg = switch_flag(pause_flg, para);
printf("Pause Flag %s\n", pause_flg ? "On":"Off");
return FALSE;
}
static int cmd_prompt(char *para)
{
prompt_flg = switch_flag(prompt_flg, para);
printf("Prompt Flag %s\n", prompt_flg ? "On":"Off");
return FALSE;
}
static int cmd_gaiji(char *para)
{
if ( now_dic_menu == NULL && dicin_gaiji_flag == 0 ) {
fprintf(stderr, "Not Gaiji Font\n");
return FALSE;
}
gaiji_flag = switch_flag(gaiji_flag, para);
if ( gaiji_flag ) {
if ( now_dic_menu != NULL )
Gaiji_init(now_dic_menu->gaz, now_dic_menu->gah);
else if ( dicin_gaiji_flag != 0 )
Gaiji_init(0, 0);
} else
Gaiji_close();
printf("Gaiji Flag %s\n", gaiji_flag ? "On":"Off");
return FALSE;
}
static int cmd_bitmap(char *para)
{
if ( Gaiji_display(htoi(para)) )
fprintf(stderr, "Not Gaiji Font\n");
return FALSE;
}
static int cmd_map(char *para)
{
int n;
if ( (n = htoi(para)) == 0 ) {
fprintf(stderr, "Parameter Error ?\n");
return FALSE;
}
while ( isxdigit((uchar)*para) )
para++;
while ( isspace((uchar)*para) )
para++;
if ( Gaiji_maping(n, para) )
fprintf(stderr, "Error ? %04X > %s\n", n, para);
return FALSE;
}
static int cmd_mapfile(char *para)
{
if ( *para == '\0' ) {
if ( gaiji_map_file != NULL )
printf("Gaiji Map File is %s\n", gaiji_map_file);
else
printf("Not Define Gaiji Map File\n");
} else
Gaiji_config(para);
return FALSE;
}
static int cmd_color(char *para)
{
color_flag = switch_flag(color_flag, para);
printf("Color Flag %s\n", color_flag ? "On":"Off");
return FALSE;
}
static int cmd_pager(char *para)
{
extdisp_flag = switch_flag(extdisp_flag, para);
printf("Pager Flag %s\n", extdisp_flag ? "On":"Off");
return FALSE;
}
static int cmd_separate(char *para)
{
cutof_flag = switch_flag(cutof_flag, para);
printf("Separate Flag %s\n", cutof_flag ? "On":"Off");
return FALSE;
}
static int cmd_history(char *para)
{
extinput_flag = switch_flag(extinput_flag, para);
printf("History Flag %s\n", extinput_flag ? "On":"Off");
return FALSE;
}
static int cmd_log(char *para)
{
if ( *para != '\0' ) {
if ( ext_out_fp != NULL )
fclose(ext_out_fp);
if ( (ext_out_fp = fopen(para, "a")) == NULL &&
(ext_out_fp = fopen(para, "w")) == NULL ) {
fprintf(stderr, "Can't open %s\n", para);
return FALSE;
}
strcpy(ext_out_file, para);
}
if ( ext_out_fp != NULL )
printf("Log Open %s\n", ext_out_file);
else
printf("Log Close\n");
return FALSE;
}
static int cmd_help()
{
int n;
for ( n = 0 ; cmds_list[n].cmds != NULL ; n++ ) {
if ( cmds_list[n].help != NULL )
printf("%s%s", cmds_list[n].cmds, cmds_list[n].help);
}
return FALSE;
}
static int cmd_quit()
{
return ERR;
}
int command(char *cmd)
{
int n;
char *para;
if ( *cmd == '/' )
cmd++;
para = cmd;
while ( !isspace((uchar)*para) && *para != '\0' )
para++;
if ( *para != '\0' )
*(para++) = '\0';
while ( isspace((uchar)*para) )
para++;
strlow(cmd);
for ( n = 0 ; cmds_list[n].cmds != NULL ; n++ ) {
if ( strcmp(cmds_list[n].cmds, cmd) == 0 )
return (*(cmds_list[n].func))(para);
}
fprintf(stderr, "Command Error %s\n", cmd);
return FALSE;
}