int namecomplete_board(BOARDHEADER *bhp, char *data, BOOL simple) { struct word *bwtop = NULL; int i; if (!num_brds) { CreateBoardList(&curuser); if (num_brds <= 0) return -1; } if (!simple) { move(1, 0); clrtobot(); move(2, 0); outs(_msg_board_5); move(1, 0); outs(_msg_board_6); } for (i = 0; i < num_brds; i++) add_wlist(&bwtop, (all_brds[i].bhr)->filename, NULL); namecomplete(bwtop, data, simple); free_wlist(&bwtop, NULL); if (data[0] == '\0') return -1; if (bhp) return get_board(bhp, data); return 0; }
/* if prompt is zero then we are really a menu */ word open_dialog(char *title, word width, word height, char *prompt) { word num; if ( (num=spare_window())==-1) return ERRM_NOSPARE; dlog=wlist[num]; /* centered on screen */ dlog->x=(maxw-width-2)/2; dlog->y=(maxh-height-2)/2; dlog->w=width+2; dlog->h=height+2; dlog->open=TRUE; dlog->number=num; dlog->type=WTYPE_DIALOG; dlog->magic=NULL; add_wlist(dlog); /* mark us on the screen, carefully as we are not in the wlist */ window_cls(dlog); window_title2(dlog,title,FALSE); recalcw(dlog); update_rectangle(dlog->x,dlog->y,dlog->w,dlog->h); line_buffer=dlog_line; /* where it will be remembered */ if (prompt) { winit_command(dlog); if (dlog->type==WTYPE_NONE) { close_dialog(); return ERRM_NOMEMORY; } print_dialog(1,prompt); /* print prompt */ dlog->xpos=DLOGX; dlog->ypos++; start_command(dlog,""); } return 0; }
/* 2nd line is optional */ word general_alert(char *title, char *line1, char *line2, const char *keylist, word *res) { word width,height; word num; struct ws *alertw; word key,mx,my,ev; word err; width=strlen(line1); height=5; if (line2) { width=max(width,strlen(line2)); height+=2; } width+=4; width=min(maxw,width); if ( (num=spare_window())==-1) return ERRM_NOSPARE; alertw=wlist[num]; /* centered on screen */ alertw->x=(maxw-width)/2; alertw->y=(maxh-height)/2; alertw->w=width; alertw->h=height; alertw->open=TRUE; alertw->number=num; alertw->type=WTYPE_DIALOG; alertw->magic=NULL; add_wlist(alertw); /* mark us on the screen, carefully as we are not in the wlist */ window_cls(alertw); window_title2(alertw,title ? title : "",FALSE); recalcw(alertw); update_rectangle(alertw->x,alertw->y,alertw->w,alertw->h); alertw->xpos=2; alertw->ypos=2; wprint_str(line1); if (line2) { alertw->xpos=2; alertw->ypos+=2; wprint_str(line2); } for (;;) { err=0; ev=get_event(&key,&mx,&my); if (keylist) { if (ev&EV_KEY) { char *match; if (key==KEY_ESC) { err=ERRM_INTERRUPTED; break; } key=toupper(key&0xFF); if (match=strchr(keylist,key)) { *res=(word)(match-keylist); break; /* returns 0 */ } } } else if (ev&(EV_KEY|EV_CLICK)) break; /* any key exits or a click */ } remove_wlist(alertw); alertw->open=FALSE; /* restore correct view of world */ recalc_frontback(); /* and redraw this new place */ update_rectangle(alertw->x, alertw->y, (word)(alertw->x+alertw->w), (word)(alertw->y+alertw->h) ); return err; }
word do_menu(char *title, word width, word height, char *list[], word *result, bool(*reload)(char*, word*), char *preload ) { word i; word ev,key,mx,my; word currenty,currentx; word visible; word num; struct ws *menuw; char menu_so_far[MAXMENUWIDTH+1]; /* can, in theory, recurse */ word numlist; if (preload==NULL) menu_so_far[0]=0; else { stccpy(menu_so_far,preload,MAXMENUWIDTH); strupr(menu_so_far); } currentx=strlen(menu_so_far); (reload)(menu_so_far,&numlist); /* initial value */ if (numlist==0) { *result=-1; return 0; } if ( (num=spare_window())==-1) return ERRM_NOSPARE; if (width>MAXMENUWIDTH) width=MAXMENUWIDTH; menuw=wlist[num]; /* centered on screen */ menuw->x=(maxw-width-2)/2; menuw->y=(maxh-height-2)/2; menuw->w=width+2; menuw->h=height+2; menuw->open=TRUE; menuw->number=num; menuw->type=WTYPE_DIALOG; menuw->magic=NULL; add_wlist(menuw); /* mark us on the screen, carefully as we are not in the wlist */ window_cls(menuw); window_title2(menuw,title,FALSE); recalcw(menuw); update_rectangle(menuw->x,menuw->y,menuw->w,menuw->h); for (;;) { p: visible=min(height,numlist); currenty=0; /* print the entries */ for (i=0; i<visible; i++) { menuw->xpos=DLOGX; menuw->ypos=i+1; wprint_str(list[i]); } k: if (visible) light_line(currenty,(word)(currentx+1),(word)(width-currentx-1)); else light_line(currenty,1,(word)(width-1)); ev=get_event(&key,&mx,&my); if (visible) light_line(currenty,(word)(currentx+1),(word)(width-currentx-1)); else light_line(currenty,1,(word)(width-1)); if (ev&EV_CLICK) { word w; ubyte edge; if (visible) { w=which_window(&mx,&my,&edge); if ( (w==num) && (edge==0) && (my<=visible) ) { if (key) { /* a double-click */ key=KEY_RETURN; break; } currenty=--my; goto k; } } } if (ev&EV_KEY) { if ( (key==KEY_UP) && (currenty) && visible ) { currenty--; goto k; } if ( (key==KEY_DOWN) && visible && (currenty<(visible-1)) ) { currenty++; goto k; } if ( (key==KEY_RETURN) || (key==KEY_ENTER) || (key==KEY_ESC) ) break; if (reload) { if (key==KEY_BACKSPACE) { if (currentx) menu_so_far[--currentx]=0; } else if (key==KEY_CLEAR) { menu_so_far[currentx=0]=0; } else if (key&0xFF) { if (currentx<MAXMENUWIDTH) menu_so_far[currentx++]=upper((char)key); menu_so_far[currentx]=0; } else goto k; if ( (reload)(menu_so_far,&numlist) ) { window_cls(menuw); update_contents(menuw); goto p; } else goto k; } } goto k; } /* like close_dialog */ remove_wlist(menuw); menuw->open=FALSE; /* restore correct view of world */ recalc_frontback(); /* and redraw this new place */ update_rectangle(menuw->x, menuw->y, (word)(menuw->x+menuw->w), (word)(menuw->y+menuw->h) ); *result=( (key==KEY_ESC) || (visible==0) ) ? -2 : currenty; return 0; }
static void dochatcommand(char *cmd) { char *para; strtok(cmd, " \n"); if ((para = strtok(NULL, "\n")) == NULL) para = cmd + strlen(cmd); if (*cmd == 'h') { printchatline(_msg_chat_41); printchatline(" /leave - Â÷¶}¥»ÀW¹D [/le]"); if (curuser.userlevel >= PERM_CLOAK) printchatline(" /cloak - Áô¨ [/cl]"); printchatline(_msg_chat_43); return; } else if (!strcmp(cmd, "who") || !strcmp(cmd, "w")) { dowho(para, ac); return; } else if (!strcmp(cmd, "ws") || !strcmp(cmd, "whoall")) { dowhoall(ac); return; } else if (!strcmp(cmd, "list") || !strcmp(cmd, "l")) { dolist(ac); return; } else if (!strcmp(cmd, "leave") || !strcmp(cmd, "le")) { net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD); } else if (!strcmp(cmd, "nopasswd") || !strcmp(cmd, "nps")) { net_printf(ac, "PASSWD\t%s\r\n", NOPASSWORD); } else if (!strcmp(cmd, "nick") || !strcmp(cmd, "n")) { fixchatid(para); net_printf(ac, "NICKNAME\t%s\r\n", para); net_gets(ac, genbuf, sizeof(genbuf)); if (!strncmp(genbuf, "-ERR", 4)) printchatline(genbuf + 5); else { xstrncpy(uinfo.chatid, para, sizeof(uinfo.chatid)); update_ulist(cutmp, &uinfo); /* set prompt */ strcpy(prompt, uinfo.chatid); strcat(prompt, ": "); prompt[SAYWORD_POINT] = '\0'; } return; } else if (!strcmp(cmd, "me")) { if (*para) { sprintf(genbuf, "*** %s ***", para); net_printf(ac, "SPEAK\t%s\r\n", genbuf); printchatline(genbuf); } else printchatline(_msg_chat_45); return; } else if (!strcmp(cmd, "pager") || !strcmp(cmd, "p")) { #if 1 add_io(0, 0); #endif toggle_pager(); printchatline(pagerstring(&uinfo)); #if 1 add_io(ac, 0); #endif return; } else if (!strcmp(cmd, "cloak") || !strcmp(cmd, "cl")) { if (HAS_PERM(PERM_CLOAK)) { net_printf(ac, "CLOAK\r\n"); net_gets(ac, genbuf, sizeof(genbuf)); if (!strncmp(genbuf, "-ERR", 4)) printchatline(genbuf + 5); else { uinfo.invisible = (uinfo.invisible) ? FALSE : TRUE; update_ulist(cutmp, &uinfo); if (!uinfo.invisible) printchatline("*** Cloak has been deactivated"); else printchatline("*** Cloak has been activated"); } } else printchatline("*** ERROR: unknown special chat command"); return; } else if (!strcmp(cmd, "clear") || !strcmp(cmd, "c")) { clear(); move(ECHATWIN, 0); outs("________________________________________________________________________________"); chat_line = 0; /* reset */ printchatline(_msg_chat_46); return; } else if (!strcmp(cmd, "ignore") || !strcmp(cmd, "i")) { if (*para) { if (strlen(para) >= IDLEN) para[IDLEN - 1] = '\0'; if (!cmp_wlist(iglist, para, strcmp)) { sprintf(genbuf, _msg_chat_37, para); printchatline(genbuf); add_wlist(&iglist, para, malloc_str); } } return; } else if (!strcmp(cmd, "unignore") || !strcmp(cmd, "ui")) { if (*para) { if (strlen(para) >= IDLEN) para[IDLEN - 1] = '\0'; if (cmp_wlist(iglist, para, strcmp)) { sprintf(genbuf, _msg_chat_36, para); printchatline(genbuf); cmpd_wlist(&iglist, para, strcmp, free); } } return; } else if (!strcmp(cmd, "j") || !strcmp(cmd, "join")) { char *para2; para = strtok(para, " \n"); if (!para) return; para2 = strtok(NULL, " \n"); if (!para2) net_printf(ac, "JOIN\t%s\t%s\r\n", para, NOPASSWORD); else net_printf(ac, "JOIN\t%s\t%s\r\n", para, para2); } else if (!strcmp(cmd, "m") || !strcmp(cmd, "msg")) { char *para2; para = strtok(para, " \n"); para2 = strtok(NULL, ""); if (!para || !para2) return; net_printf(ac, "MSG\t%s\t%s\r\n", para, para2); } else if (!strcmp(cmd, "t") || !strcmp(cmd, "topic")) { net_printf(ac, "TOPIC\t%s\r\n", para); } else if (!strcmp(cmd, "ps") || !strcmp(cmd, "passwd")) { net_printf(ac, "PASSWD\t%s\r\n", para); } else { printchatline("*** ERROR: unknown special chat command"); return; } net_gets(ac, genbuf, sizeof(genbuf)); if (!strncmp(genbuf, "-ERR", 4)) { genbuf[strlen(genbuf) - 1] = '\0'; printchatline(genbuf + 5); } }
/* * 搜尋文章 */ int search_article(register char *direct, register int ent, register char *string, register char op, register struct word **srchwtop) { FILEHEADER *fhr = &fhGol; char author[STRLEN], cmps_str[STRLEN]; int fd; register char *takestr; register int cmps_kind = 0; register int total_target = 0; int total; if (string[0] == '\0') return -1; xstrncpy(cmps_str, string, sizeof(cmps_str)); if (strchr(srchbword, op)) cmps_kind = SCMP_BACKWARD; if (strchr(srchauthor, op)) cmps_kind |= SCMP_AUTHOR; else if (strchr(srchassoc, op)) cmps_kind |= SCMP_ASSOC; #if USE_THREAD if (thr_mode) total = num_thrs; else if (art_mode) total = num_arts; else #endif total = get_num_records(direct, FH_SIZE); if (cmps_kind & SCMP_BACKWARD) { if (++ent > total) return -1; } else { if (--ent < 1) return -1; } if ((cmps_kind & SCMP_ASSOC) || srchwtop) { /* make cmps_str as no Re: */ if (!strncmp(cmps_str, STR_REPLY, REPLY_LEN)) strcpy(cmps_str, cmps_str + REPLY_LEN); } #if USE_THREAD if (!thr_mode && !art_mode) { #endif if ((fd = open(direct, O_RDONLY)) < 0) return -1; lseek(fd, (off_t) ((ent - 1) * FH_SIZE), SEEK_SET); #if USE_THREAD } #endif for (;;) { #if USE_THREAD if (thr_mode || art_mode) { if (ent > total) break; if (thr_mode) fhr = all_thrs[ent-1]; else if (art_mode) fhr = &(all_arts[ent-1]); } else { #endif if (read(fd, fhr, FH_SIZE) != FH_SIZE) break; #if USE_THREAD } #endif if (cmps_kind & SCMP_AUTHOR) { xstrncpy(author, fhr->owner, sizeof(author)); strtok(author, ".@"); takestr = author; if (takestr[0] == '#') takestr++; #ifndef IGNORE_CASE if (!strcmp(takestr, cmps_str)) /* compare */ #else if (!strcasecmp(takestr, cmps_str)) #endif { if (srchwtop) { add_wlist(srchwtop, fhr->filename, malloc_str); total_target++; } else { #if USE_THREAD if (!thr_mode && !art_mode) #endif close(fd); return ent; } } } else if (!(fhr->accessed & FILE_DELE)) { takestr = fhr->title; switch (op) { case '-': case '+': if (fhr->accessed & FILE_RESV) { #if USE_THREAD if (!thr_mode && !art_mode) #endif close(fd); return ent; } break; case '[': case ']': if (!strncmp(takestr, STR_REPLY, REPLY_LEN)) takestr += REPLY_LEN; case '=': if (!strcmp(takestr, cmps_str)) { #if USE_THREAD if (!thr_mode && !art_mode) #endif close(fd); return ent; } break; case '/': if (!srchwtop) { if (!strcmp(takestr, cmps_str)) /* compare */ { #if USE_THREAD if (!thr_mode && !art_mode) #endif close(fd); return ent; /* found it */ } } else { if (!strncmp(takestr, STR_REPLY, REPLY_LEN)) takestr += REPLY_LEN; if (!strcmp(takestr, cmps_str)) { add_wlist(srchwtop, fhr->filename, malloc_str); total_target++; } } break; case '<': case '>': if (strstr(takestr, cmps_str)) /* compare */ { if (!srchwtop) /* found it */ { #if USE_THREAD if (!thr_mode && !art_mode) #endif close(fd); return ent; } add_wlist(srchwtop, fhr->filename, malloc_str); total_target++; } break; } /* switch */ } /* else if */ if (cmps_kind & SCMP_BACKWARD) ent++; else { if (--ent < 1) /* abort search */ break; #if USE_THREAD if (!thr_mode && !art_mode) #endif lseek(fd, -2 * ((off_t) FH_SIZE), SEEK_CUR); } } /* while */ #if USE_THREAD if (!thr_mode && !art_mode) #endif close(fd); if (srchwtop) return total_target; return -1; }