示例#1
0
文件: definekey.c 项目: xingskycn/kbs
static int set_keydefine_key(struct _select_def *conf, int key)
{
    int oldmode;

    switch (key) {
        case KEY_TAB:
            ask_define();
            return SHOW_DIRCHANGE;
        case 'a':                  /* add new user */
            if (keymem_total < MAX_KEY_DEFINE) {
                int i,j;
                struct key_struct k;
                char buf[120];

                clear();
                move(1, 0);
                prints("请键入自定义键: ");
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) return SHOW_DIRCHANGE;
                prints("%s\n", buf);
                k.key = i;
                move(2, 0);
                prints("请输入替换序列(最多10个),按一次ESC结束: ");
                j=0;
                do {
                    do {
                        i = igetkey();
                        get_key_name(i, buf);
                    } while (!buf[0]&&i!=KEY_ESC);
                    if (i==KEY_ESC) break;
                    prints("%s ", buf);
                    k.mapped[j] = i;
                    j++;
                    if (j>=10) break;
                } while (1);
                if (j<10) k.mapped[j]=0;
                if (j==0) return SHOW_DIRCHANGE;

                k.status[0] = -1;
                add_key(&k);

                return SHOW_DIRCHANGE;
            }
            break;
        case 'e':
            set_modes(keymem[conf->pos-1].status);
            return SHOW_DIRCHANGE;
        case 's': {
            int i,j,x,y;
            struct key_struct k;
            char buf[120];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1, 0);
            prints("请键入自定义键: ");
            do {
                i = igetkey();
                get_key_name(i, buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC) return SHOW_DIRCHANGE;
            prints("%s\n", buf);
            k.key = i;
            move(2, 0);
            prints("请输入替换序列(最多10个),按一次ESC结束: ");
            j=0;
            do {
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j] = i;
                j++;
                if (j>=10) break;
            } while (1);
            if (j<10) k.mapped[j]=0;
            if (j==0) return SHOW_DIRCHANGE;

            memcpy(keymem+conf->pos-1, &k, sizeof(struct key_struct));

            return SHOW_DIRCHANGE;
        }
        break;
        case 'x': {
            struct key_struct k;
            int i;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请键入自定义键: ");
            do {
                i=igetkey();
                get_key_name(i,buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC)
                return SHOW_DIRCHANGE;
            k.key=i;
            prints("%s",buf);
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 't': {
            struct key_struct k;
            int i,j,x,y;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请输入替换序列(最多10个), 按一次ESC结束: ");
            for (j=0; j<10; j++) {
                do {
                    i=igetkey();
                    get_key_name(i,buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC)
                    break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j]=i;
            }
            if (!j)
                return SHOW_DIRCHANGE;
            if (j<10)
                k.mapped[j]=0;
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 'd':                  /* delete existed user */
            if (keymem_total > 0) {
                char ans[3];

                getdata(t_lines - 1, 0, "确实要删除该定义键吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true);
                if (ans[0] == 'Y' || ans[0] == 'y') {
                    remove_key(conf->pos-1);
                    if (keymem_total==0) {
                        struct key_struct key;
                        key.key = 'A';
                        key.mapped[0] = 'A';
                        key.mapped[1] = 0;
                        key.status[0] = 0;
                        add_key(&key);
                    }
                }
                return SHOW_DIRCHANGE;
            }
            break;
        case 'L':
        case 'l':
            oldmode = uinfo.mode;
            show_allmsgs();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'W':
        case 'w':
            oldmode = uinfo.mode;
            if (!HAS_PERM(getCurrentUser(), PERM_PAGE))
                break;
            s_msg();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'u':
            oldmode = uinfo.mode;
            clear();
            modify_user_mode(QUERY);
            t_query(NULL);
            modify_user_mode(oldmode);
            clear();
            return SHOW_REFRESH;
    }

    return SHOW_CONTINUE;
}
示例#2
0
文件: tmpl.c 项目: zhouqt/kbs
static int tmpl_key(struct _select_def *conf, int key)
{
    int oldmode;
    switch (key) {
        case 'a' :
            tmpl_check_limit(template_num);
            tmpl_add();
            return SHOW_DIRCHANGE;
            break;
        case 'd' : {
            char ans[3];

            getdata(t_lines - 1, 0, "确实要删除吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true);
            if (ans[0] == 'Y' || ans[0] == 'y') {
                int i;

                deepfree(ptemplate + conf->pos - 1, currboard->filename);

                template_num--;
                for (i=conf->pos-1; i<template_num; i++)
                    memcpy(ptemplate+i, ptemplate+i+1, sizeof(struct a_template));
                ptemplate[template_num].tmpl = NULL;
                ptemplate[template_num].cont = NULL;


                tmpl_save();
            }
            if (template_num > 0)
                return SHOW_DIRCHANGE;
            else
                return SHOW_QUIT;
        }
        break;
        case 'c':
            do {
                extern bool in_do_sendmsg;
                extern int super_select_board(char *bname);

                int ret;
                char bname[STRLEN] = "";

                move(0,0); clrtoeol();
                prints("%s","复制到讨论区 [ \033[1;32mSPACE/TAB\033[m - 自动补全, \033[1;32mESC\033[m - 退出 ]");
                move(1,0); clrtoeol();
                prints("请输入讨论区名称 [\033[1;32m%s\033[m]: ",currboard->filename);

                make_blist(0, 3);
                in_do_sendmsg=1;
                ret = namecomplete(NULL, bname);
                in_do_sendmsg=0;
                CreateNameList();   /*  free list memory. */

                if (ret == KEY_ESC) {
                    /* noop */
                } else if (!*bname || !strcmp(bname, currboard->filename)) {
                    /* copy to current board */
                    tmpl_check_BM(currboard->filename); /* sanity check, how about stick here when deposing? */
                    tmpl_check_limit(template_num);
                    if (tmpl_copy(conf->pos))
                        tmplcp_sorry();
                    else
                        tmplcp_success();
                } else { /* copy to another board */
                    struct a_template *ptemp;
                    int temp_num = tmpl_init_ex(0, bname, &ptemp);
                    if (temp_num >= 0) {
                        tmpl_check_BM(bname); /* sanity check */
                        tmpl_check_limit(temp_num);
                        if (tmpl_copy_to_board(bname, &ptemp, &temp_num, conf->pos))
                            tmplcp_sorry();
                        else
                            tmplcp_success();
                        tmpl_free_ex(&ptemp, temp_num);
                    }
                }
            } while (0);
            return SHOW_DIRCHANGE;
            /* etnlegend, 2006.05.19, move templates... */
        case 'm':
            do {
                struct a_template temp;
                char ans[4];
                int i,pos;
                getdata(t_lines-1,0,"请输入希望移动到的位置序号: ",ans,4,DOECHO,NULL,true);
                trimstr(ans);
                if (!isdigit(ans[0]))
                    break;
                pos=atoi(ans);
                pos=((pos<1)?1:((pos>template_num)?template_num:pos));
                if (pos==conf->pos)
                    break;
                memcpy(&temp,&ptemplate[conf->pos-1],sizeof(struct a_template));
                if (pos>conf->pos) {
                    for (i=(conf->pos-1); i<(pos-1); i++)
                        memcpy(&ptemplate[i],&ptemplate[i+1],sizeof(struct a_template));
                } else {
                    for (i=(conf->pos-1); i>(pos-1); i--)
                        memcpy(&ptemplate[i],&ptemplate[i-1],sizeof(struct a_template));
                }
                memcpy(&ptemplate[pos-1],&temp,sizeof(struct a_template));
                tmpl_save();
            } while (0);
            return SHOW_DIRCHANGE;
            /* END - etnlegend, 2006.05.19, move templates ... */
        case 't' : {
            char newtitle[60];

            strcpy(newtitle, ptemplate[conf->pos-1].tmpl->title);
            getdata(t_lines - 1, 0, "新名称: ", newtitle, 50, DOECHO, NULL, false);

            if (newtitle[0] == '\0' || newtitle[0]=='\n' || ! strcmp(newtitle,ptemplate[conf->pos-1].tmpl->title))
                return SHOW_REFRESH;

            strncpy(ptemplate[conf->pos-1].tmpl->title, newtitle, 50);
            ptemplate[conf->pos-1].tmpl->title[49]='\0';

            tmpl_save();

            return SHOW_REFRESH;
        }
        break;/*
 case 'z' :
  {
   char newtitle[30];

   strcpy(newtitle, ptemplate[conf->pos-1].tmpl->title_prefix);
getdata(t_lines - 1, 0, "请输入此模板的文章标题前缀: ", newtitle, 20, DOECHO, NULL, false);

   if( newtitle[0] == '\0' || newtitle[0]=='\n' || ! strcmp(newtitle,ptemplate[conf->pos-1].tmpl->title_prefix) )
return SHOW_REFRESH;

   strncpy(ptemplate[conf->pos-1].tmpl->title_prefix, newtitle, 20);
   ptemplate[conf->pos-1].tmpl->title_prefix[19]='\0';

   tmpl_save();

   return SHOW_REFRESH;
  }*/
        case 'f' : {
            char filepath[STRLEN];
            int oldmode;

            oldmode = uinfo.mode;
            modify_user_mode(EDITUFILE);

            if (ptemplate[conf->pos-1].tmpl->filename[0] == '\0') {

                setbfile(filepath, currboard->filename, "");
                if (GET_POSTFILENAME(ptemplate[conf->pos-1].tmpl->filename, filepath) != 0) {
                    clear();
                    move(3,0);
                    prints("创建模板文件失败!");
                    pressanykey();
                    return SHOW_REFRESH;
                }
                tmpl_save();
            }

            setbfile(filepath, currboard->filename, ptemplate[conf->pos-1].tmpl->filename);

            vedit(filepath,0,NULL,NULL,0);
            modify_user_mode(oldmode);

            return SHOW_REFRESH;
        }
        case 's' : {
            char filepath[STRLEN];
            setbfile(filepath, currboard->filename, ptemplate[conf->pos-1].tmpl->filename);
            clear();
            ansimore(filepath,1);
            return SHOW_REFRESH;
        }
        case 'b' : {
            if (ptemplate[conf->pos-1].tmpl->flag & TMPL_BM_FLAG)
                ptemplate[conf->pos-1].tmpl->flag &= ~TMPL_BM_FLAG ;
            else
                ptemplate[conf->pos-1].tmpl->flag |= TMPL_BM_FLAG;

            tmpl_save();

            return SHOW_REFRESH;
        }
        case 'i' : {
            char newtitle[STRLEN];

            strcpy(newtitle, ptemplate[conf->pos-1].tmpl->title_tmpl);
            getdata(t_lines - 1, 0, "新文章标题: ", newtitle, STRLEN, DOECHO, NULL, false);

            if (newtitle[0] == '\0' || newtitle[0]=='\n' || ! strcmp(newtitle,ptemplate[conf->pos-1].tmpl->title_tmpl))
                return SHOW_REFRESH;

            strncpy(ptemplate[conf->pos-1].tmpl->title_tmpl, newtitle, STRLEN);
            ptemplate[conf->pos-1].tmpl->title_tmpl[STRLEN-1]='\0';

            tmpl_save();

            return SHOW_REFRESH;
        }
        case 'x' : {
            clear();
            move(2,0);
            prints("此模版的标题设置为");
            move(4,0);
            prints("%s",ptemplate[conf->pos-1].tmpl->title_tmpl);
            pressanykey();
            return SHOW_REFRESH;
        }
        /*
        case 'h':
        {
         clear();
         move(1,0);
         prints("  x  :  查看标题格式\n");
         prints("  i  :  修改标题格式");
         pressanykey();
         return SHOW_REFRESH;
        }
        */
        case 'l': /* by pig2532 on 2005.12.01 */
            oldmode = uinfo.mode;
            show_allmsgs();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'w':                  /* by pig2532 on 2005-12-1 */
            oldmode = uinfo.mode;
            if (!HAS_PERM(getCurrentUser(), PERM_PAGE))
                break;
            s_msg();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'u':                  /* by pig2532 on 2005-12-1 */
            clear();
            oldmode = uinfo.mode;
            modify_user_mode(QUERY);
            t_query(NULL);
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'U':  /* pig2532 2005.12.10 */
            board_query();
            return SHOW_REFRESH;
        default :
            break;
    }

    return SHOW_CONTINUE;
}