summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-06-16 15:47:40 +0800
committerwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-06-16 15:47:40 +0800
commitf38adb6fe5a682d7799712a85185a7bcab37e680 (patch)
tree650846bf45dff13e202e2702651043bb0a2e06b7 /mbbsd
parent9918ba57360f889cf1163b0924a4bcd7f9022d91 (diff)
downloadpttbbs-f38adb6fe5a682d7799712a85185a7bcab37e680.tar
pttbbs-f38adb6fe5a682d7799712a85185a7bcab37e680.tar.gz
pttbbs-f38adb6fe5a682d7799712a85185a7bcab37e680.tar.bz2
pttbbs-f38adb6fe5a682d7799712a85185a7bcab37e680.tar.lz
pttbbs-f38adb6fe5a682d7799712a85185a7bcab37e680.tar.xz
pttbbs-f38adb6fe5a682d7799712a85185a7bcab37e680.tar.zst
pttbbs-f38adb6fe5a682d7799712a85185a7bcab37e680.zip
Rewrite usercomplete using namecomplete2 and vector-constant
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4371 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/name.c227
1 files changed, 3 insertions, 224 deletions
diff --git a/mbbsd/name.c b/mbbsd/name.c
index ac69873f..fd0ce441 100644
--- a/mbbsd/name.c
+++ b/mbbsd/name.c
@@ -14,75 +14,6 @@ prompt_more()
//-----------------------------------------------------------------------
-char *
-u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag)
-{
- register char *ptr, tmp;
- register int n, total;
- char tagbuf[STRLEN];
- int ch, ch2, num;
-
- if (*tag == '\0') {
- *pnum = SHM->number;
- return SHM->userid[0];
- }
- for (n = 0; tag[n]; n++)
- tagbuf[n] = chartoupper(tag[n]);
- tagbuf[n] = '\0';
- ch = tagbuf[0];
- ch2 = ch - 'A' + 'a';
- total = SHM->number;
- for (n = num = 0; n < total; n++) {
- ptr = SHM->userid[n];
- tmp = *ptr;
- if (tmp == ch || tmp == ch2) {
- if (chkstr(tag, tagbuf, ptr))
- strcpy(buf[num++], ptr);
- }
- }
- *pnum = num;
- return buf[0];
-}
-
-static int
-UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum,
- int count)
-{
- int len, max = 0;
-
- while (count-- > 0 && morenum < cwnum) {
- len = strlen(cwlist[morenum++]);
- if (len > max)
- max = len;
- }
- /* assert max IDLEN */
- if(max > IDLEN)
- max = IDLEN+1;
- return max;
-}
-
-static int
-UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1],
- int cwnum, int key, int pos)
-{
- int key2, num = 0;
- int n, ch;
-
- key = chartoupper(key);
-
- if (key >= 'A' && key <= 'Z')
- key2 = key | 0x20;
- else
- key2 = key;
-
- for (n = 0; n < cwnum; n++) {
- ch = cwlist[n][pos];
- if (ch == key || ch == key2)
- strlcpy(cwbuf[num++], cwlist[n], sizeof(cwbuf[num]));
- }
- return num;
-}
-
void
ShowVector(struct Vector *self, int row, int column, const char *prompt)
{
@@ -281,163 +212,11 @@ namecomplete2(struct Vector *namelist, const char *prompt, char *data)
void
usercomplete(const char *prompt, char *data)
{
- char *temp;
- char *cwbuf, *cwlist;
- int cwnum, x, y, origx, scrx;
- int clearbot = NA, count = 0, morenum = 0;
- char ch;
- int dashdirty = 0;
-
- /* TODO 節省記憶體. (不過這個 function 不常占記憶體...) */
- cwbuf = malloc(MAX_USERS * (IDLEN + 1));
- cwlist = u_namearray((arrptr) cwbuf, &cwnum, "");
- 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) {
- int i;
- char *ptr;
-
- *temp = '\0';
- outc('\n');
- ptr = cwlist;
- for (i = 0; i < cwnum; i++) {
- if (strncasecmp(data, ptr, IDLEN + 1) == 0) {
- strcpy(data, ptr);
- break;
- }
- ptr += IDLEN + 1;
- }
- if (i == cwnum)
- data[0] = '\0';
- break;
-
- } else if (ch == KEY_BS2 || ch == KEY_BS) { /* backspace */
- if (temp == data)
- continue;
- temp--;
- count--;
- *temp = '\0';
- cwlist = u_namearray((arrptr) cwbuf, &cwnum, data);
- morenum = 0;
- continue;
-
- } else if (!(count <= IDLEN && isprint((int)ch))) {
-
- /* invalid input */
- continue;
+ struct Vector namelist;
- } else if (ch != ' ') {
-
- int n;
-
- *temp++ = ch;
- *temp = '\0';
- n = UserSubArray((arrptr) cwbuf, (arrptr) cwlist, cwnum, ch, count);
-
- if (n > 0) {
- /* found something */
- cwlist = cwbuf;
- count++;
- cwnum = n;
- morenum = 0;
- continue;
- }
- /* no break, no continue, list later. */
- }
+ Vector_init_const(&namelist, SHM->userid[0], MAX_USERS, IDLEN+1);
- /* finally, list available users. */
- {
- int col, len;
-
- if (ch == ' ' && cwnum == 1) {
- if(dashdirty)
- {
- move(2,0);
- clrtoeol();
- printdash(cwlist, 0);
- }
- strcpy(data, cwlist);
- count = strlen(data);
- temp = data + count;
- continue;
- }
-
- clearbot = YEA;
- col = 0;
-
- len = UserMaxLen((arrptr) cwlist, cwnum, morenum, p_lines);
- move(2, 0);
- clrtobot();
- printdash("使用者代號一覽表", 0);
- dashdirty = 0;
-
- if(ch != ' ')
- {
- /* no such user */
- move(2,0);
- outs("- 目前無使用者 ");
- outs(data);
- outs(" ");
- temp--;
- *temp = '\0';
- dashdirty = 1;
- }
-
- while (len + col < t_columns-1) {
-
- int i;
-
- for (i = 0; morenum < cwnum && i < p_lines; i++) {
- move(3 + i, col);
- prints("%.*s ", IDLEN,
- cwlist + (IDLEN + 1) * morenum++);
- }
- col += len + 2;
- if (morenum >= cwnum)
- break;
- len = UserMaxLen((arrptr) cwlist, cwnum, morenum, p_lines);
- }
- if (morenum < cwnum) {
- prompt_more();
- } else
- morenum = 0;
-
- continue;
- }
- }
- free(cwbuf);
- 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');
- }
+ namecomplete2(&namelist, prompt, data);
}
static int