void ToggleNameList(int *reciper, char *listfile, char *msg) { FILE *fp; char genbuf[200]; if((fp = fopen(listfile, "r"))) { while(fgets(genbuf, STRLEN, fp)) { strtok(genbuf, str_space); if(!InNameList(genbuf)) { AddNameList(genbuf); (*reciper)++; } else { RemoveNameList(genbuf); (*reciper)--; } } fclose(fp); ShowNameList(3, 0, msg); } }
int namecomplete(char *prompt, char *data) { char *temp; int ch; int count = 0; int clearbot = NA; struct word *cwlist, *morelist; int x, y; int origx, origy; if (prompt != NULL) { prints("%s", prompt); clrtoeol(); } temp = data; if (toplev == NULL) AddNameList(""); cwlist = GetSubList("", toplev); morelist = NULL; screen_coordinates(&y, &x); screen_coordinates(&origy, &origx); while ((ch = terminal_getchar()) != EOF) { if (ch == '\n' || ch == '\r') { *temp = '\0'; prints("\n"); if (NumInList(cwlist) == 1) strcpy(data, cwlist->name); else { /* 版面 ID 选择的一个精确匹配问题 period */ struct word *list; for (list = cwlist; list != NULL; list = list->next) { if (!strcasecmp(data, list->name)) { strcpy(data, list->name); break; } //if } //for } //else ClearSubList(cwlist); break; } if (ch == ' ' || ch == KEY_TAB) { int col, len, i; if (NumInList(cwlist) == 1) { strcpy(data, cwlist->name); screen_move(y, x); prints("%s", data + count); count = strlen(data); temp = data + count; screen_coordinates(&y, &x); continue; } for (i = strlen(data); i && i < STRLEN; i++) { struct word *node; ch = cwlist->name[i]; if (ch == '\0') break; for (node = cwlist; node; node = node->next) { if (toupper(ch) != toupper(node->name[i])) break; } if (node != NULL) break; *temp++ = ch; count++; *temp = '\0'; node = GetSubList(data, cwlist); if (node == NULL) { temp--; *temp = '\0'; count--; break; } ClearSubList(cwlist); cwlist = node; morelist = NULL; screen_move(y, x); outc(ch); x++; } //for clearbot = YEA; col = 0; if (!morelist) morelist = cwlist; len = MaxLen(morelist, NUMLINES); screen_move(origy + 1, 0); screen_clrtobot(); prints(ANSI_CMD_SO); //% printdash(" 列表 "); printdash(" \xc1\xd0\xb1\xed "); prints(ANSI_CMD_SE); while (len + col < 80) { int i; for (i = NUMLINES; (morelist) && (i > origy - 1); i--) { if (morelist->name[0] != '\0') { screen_move(origy + 2 + (NUMLINES - i), col); prints("%s", morelist->name); } else { i++; } morelist = morelist->next; } col += len + 2; if (!morelist) break; len = MaxLen(morelist, NUMLINES); } //while if (morelist) { screen_move(-1, 0); //% prints("[1;44m-- 还有 -- [m"); prints("[1;44m-- \xbb\xb9\xd3\xd0 -- [m"); } screen_move(y, x); continue; } if (ch == '\177' || ch == '\010') { if (temp == data) continue; temp--; count--; *temp = '\0'; ClearSubList(cwlist); cwlist = GetSubList(data, toplev); morelist = NULL; x--; screen_move(y, x); outc(' '); screen_move(y, x); continue; } //if if (count < STRLEN) { struct word *node; *temp++ = ch; count++; *temp = '\0'; node = GetSubList(data, cwlist); if (node == NULL) { temp--; *temp = '\0'; count--; continue; } ClearSubList(cwlist); cwlist = node; morelist = NULL; screen_move(y, x); outc(ch); x++; } } // while if (ch == EOF) longjmp(byebye, -1); prints("\n"); screen_flush(); if (clearbot) { screen_move(origy, 0); screen_clrtobot(); } if (*data) { screen_move(origy, origx); prints("%s\n", data); /* for (x=1; x<500; x++); delay */ } return 0; }
void namecomplete(char *prompt, char *data) { char *temp; word_t *cwlist, *morelist; int x, y, origx, origy; int ch; int count = 0; int clearbot = NA; if(toplev == NULL) AddNameList(""); cwlist = GetSubList("", toplev); morelist = NULL; temp = data; outs(prompt); clrtoeol(); getyx(&y, &x); getyx(&origy, &origx); standout(); prints("%*s", IDLEN + 1, ""); standend(); move(y, x); refresh(); while((ch = igetch()) != EOF) { if(ch == '\n' || ch == '\r') { *temp = '\0'; outc('\n'); if(NumInList(cwlist) == 1) strcpy(data, cwlist->word); ClearSubList(cwlist); break; } if(ch == ' ') { int col, len; if(NumInList(cwlist) == 1) { strcpy(data, cwlist->word); move(y, x); outs(data + count); count = strlen(data); temp = data + count; getyx(&y, &x); continue; } clearbot = YEA; col = 0; if(!morelist) morelist = cwlist; len = MaxLen(morelist, p_lines); move(2, 0); clrtobot(); printdash("相關資訊一覽表"); while(len + col < 80) { int i; for(i = p_lines; (morelist) && (i > 0); i--) { move(3 + (p_lines - i), col); outs(morelist->word); morelist = morelist->next; } col += len + 2; if(!morelist) break; len = MaxLen(morelist, p_lines); } if(morelist) { move(b_lines, 0); outs(msg_more); } move(y, x); continue; } if(ch == '\177' || ch == '\010') { if(temp == data) continue; temp--; count--; *temp = '\0'; ClearSubList(cwlist); cwlist = GetSubList(data, toplev); morelist = NULL; x--; move(y, x); outc(' '); move(y, x); continue; } if(count < STRLEN && isprint(ch)) { word_t *node; *temp++ = ch; count++; *temp = '\0'; node = GetSubList(data, cwlist); if(node == NULL) { temp--; *temp = '\0'; count--; continue; } ClearSubList(cwlist); cwlist = node; morelist = NULL; move(y, x); outc(ch); x++; } } if(ch == EOF) /* longjmp(byebye, -1); */ raise(SIGHUP); /* jochang: don't know if this is necessary... */ outc('\n'); refresh(); if(clearbot) { move(2, 0); clrtobot(); } if(*data) { move(origy, origx); outs(data); outc('\n'); } }