From 9e1a420799a6123d12a45b3f5e445fa6fb6f5e5d Mon Sep 17 00:00:00 2001 From: wens Date: Mon, 16 Jun 2008 05:44:45 +0000 Subject: Goodbye NameList* and namecomplete git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4367 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/name.c | 319 ----------------------------------------------------------- 1 file changed, 319 deletions(-) (limited to 'mbbsd/name.c') diff --git a/mbbsd/name.c b/mbbsd/name.c index fd5a1976..a5d92e11 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -1,8 +1,6 @@ /* $Id$ */ #include "bbs.h" -static word_t *current = NULL; - typedef char (*arrptr)[]; /* name complete for user ID */ @@ -85,82 +83,6 @@ UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], return num; } -void -FreeNameList(void) -{ - word_t *p, *temp; - - for (p = toplev; p; p = temp) { - temp = p->next; - free(p->word); - free(p); - } -} - -void -CreateNameList(void) -{ - if (toplev) - FreeNameList(); - toplev = current = NULL; -} - -void -AddNameList(const char *name) -{ - word_t *node; - - node = (word_t *) malloc(sizeof(word_t)); - node->next = NULL; - node->word = (char *)malloc(strlen(name) + 1); - strcpy(node->word, name); - - if (toplev) - current = current->next = node; - else - current = toplev = node; -} - -int -RemoveNameList(const char *name) -{ - word_t *curr, *prev = NULL; - - for (curr = toplev; curr; curr = curr->next) { - if (!strcmp(curr->word, name)) { - if (prev == NULL) - toplev = curr->next; - else - prev->next = curr->next; - - if (curr == current) - current = prev; - free(curr->word); - free(curr); - return 1; - } - prev = curr; - } - return 0; -} - -static inline int -InList(const word_t * list, const char *name) -{ - const word_t *p; - - for (p = list; p; p = p->next) - if (!strcasecmp(p->word, name)) - return 1; - return 0; -} - -int -InNameList(const char *name) -{ - return InList(toplev, name); -} - void ShowVector(struct Vector *self, int row, int column, const char *prompt) { @@ -185,29 +107,6 @@ ShowVector(struct Vector *self, int row, int column, const char *prompt) } } -void -ShowNameList(int row, int column, const char *prompt) -{ - word_t *p; - - move(row, column); - clrtobot(); - outs(prompt); - - column = 80; - for (p = toplev; p; p = p->next) { - row = strlen(p->word) + 1; - if (column + row > 76) { - column = row; - outc('\n'); - } else { - column += row; - outc(' '); - } - outs(p->word); - } -} - void ToggleVector(struct Vector *list, int *recipient, const char *listfile, const char *msg) { @@ -233,41 +132,6 @@ ToggleVector(struct Vector *list, int *recipient, const char *listfile, const ch } } -void -ToggleNameList(int *reciper, const char *listfile, const char *msg) -{ - FILE *fp; - char genbuf[STRLEN]; - - if ((fp = fopen(listfile, "r"))) { - while (fgets(genbuf, sizeof(genbuf), fp)) { - char *space = strpbrk(genbuf, str_space); - if (space) *space = '\0'; - if (!genbuf[0]) - continue; - if (!InNameList(genbuf)) { - AddNameList(genbuf); - (*reciper)++; - } else { - RemoveNameList(genbuf); - (*reciper)--; - } - } - fclose(fp); - ShowNameList(3, 0, msg); - } -} - -static int -NumInList(const word_t * list) -{ - register int i; - - for (i = 0; list; i++) - list = list->next; - return i; -} - int chkstr(char *otag, const char *tag, const char *name) { @@ -285,189 +149,6 @@ chkstr(char *otag, const char *tag, const char *name) return 1; } -static word_t * -GetSubList(char *tag, word_t * list) -{ - word_t *wlist, *wcurr; - char tagbuf[STRLEN]; - int n; - - wlist = wcurr = NULL; - for (n = 0; tag[n]; n++) - tagbuf[n] = chartoupper(tag[n]); - tagbuf[n] = '\0'; - - while (list) { - if (chkstr(tag, tagbuf, list->word)) { - register word_t *node; - - node = (word_t *) malloc(sizeof(word_t)); - node->word = list->word; - node->next = NULL; - if (wlist) - wcurr->next = node; - else - wlist = node; - wcurr = node; - } - list = list->next; - } - return wlist; -} - -static void -ClearSubList(word_t * list) -{ - struct word_t *tmp_list; - - while (list) { - tmp_list = list->next; - free(list); - list = tmp_list; - } -} - -static int -MaxLen(const word_t * list, int count) -{ - int len = strlen(list->word); - int t; - - while (list && count) { - if ((t = strlen(list->word)) > len) - len = t; - list = list->next; - count--; - } - return len; -} - -/* TODO use namecomplete2() instead */ -void -namecomplete(const char *prompt, char *data) -{ - char *temp; - word_t *cwlist, *morelist; - int x, y, origx, scrx; - 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); - scrx = origx = x; - data[count] = 0; - - while (1) - { - // print input field again - move(y, scrx); outc(' '); clrtoeol(); move(y, scrx); - outs(ANSI_REVERSE); - prints("%-*s", IDLEN + 1, data); - outs(ANSI_RESET); - move(y, scrx + count); - - // get input - if ((ch = igetch()) == EOF) - break; - - if (ch == KEY_ENTER) { - *temp = '\0'; - // outc('\n'); - if (NumInList(cwlist) == 1) - strcpy(data, cwlist->word); - else if (!InList(cwlist, data)) - data[0] = '\0'; - ClearSubList(cwlist); - break; - } - if (ch == ' ') { - int col, len; - - if (NumInList(cwlist) == 1) { - strcpy(data, cwlist->word); - count = strlen(data); - temp = data + count; - continue; - } - clearbot = YEA; - col = 0; - if (!morelist) - morelist = cwlist; - len = MaxLen(morelist, p_lines); - move(2, 0); - clrtobot(); - printdash("相關資訊一覽表", 0); - while (len + col < t_columns) { - 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) { - prompt_more(); - } - continue; - } - if (ch == KEY_BS2 || ch == KEY_BS) { /* backspace */ - if (temp == data) - continue; - temp--; - count--; - *temp = '\0'; - ClearSubList(cwlist); - cwlist = GetSubList(data, toplev); - morelist = NULL; - 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; - } - } - if (ch == EOF) - /* longjmp(byebye, -1); */ - raise(SIGHUP); /* jochang: don't know if this is - * necessary... */ - outc('\n'); - if (clearbot) { - move(2, 0); - clrtobot(); - } - if (*data) { - move(y, origx); - outs(data); - outc('\n'); - } -} - void namecomplete2(struct Vector *namelist, const char *prompt, char *data) { -- cgit v1.2.3