From 3de97b6c59cd333758305445294256b8868ae587 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 19 Dec 2003 06:18:17 +0000 Subject: more quick code in Ptt_prints() git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1421 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/kaede.c | 105 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 55 insertions(+), 50 deletions(-) (limited to 'mbbsd/kaede.c') diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c index 4f091b12..fd3de9ac 100644 --- a/mbbsd/kaede.c +++ b/mbbsd/kaede.c @@ -4,56 +4,61 @@ char * Ptt_prints(char *str, int mode) { - char *po, strbuf[256]; - - while ((po = strstr(str, "\033*s"))) { - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), "%s%s%s", str, cuser.userid, po + 3); - strcpy(str, strbuf); - } - while ((po = strstr(str, "\033*t"))) { - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), "%s%s%s", str, Cdate(&now), po + 3); - strcpy(str, strbuf); - } - while ((po = strstr(str, "\033*u"))) { - int attempts; - - attempts = SHM->UTMPnumber; - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), "%s%d%s", str, attempts, po + 3); - strcpy(str, strbuf); - } - while ((po = strstr(str, "\033*b"))) { - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), - "%s%d/%d%s", str, cuser.month, cuser.day, po + 3); - strcpy(str, strbuf); - } - while ((po = strstr(str, "\033*l"))) { - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), - "%s%d%s", str, cuser.numlogins, po + 3); - strcpy(str, strbuf); - } - while ((po = strstr(str, "\033*p"))) { - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), - "%s%d%s", str, cuser.numposts, po + 3); - strcpy(str, strbuf); - } - while ((po = strstr(str, "\033*n"))) { - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), - "%s%s%s", str, cuser.username, po + 3); - strcpy(str, strbuf); - } - while ((po = strstr(str, "\033*m"))) { - po[0] = 0; - snprintf(strbuf, sizeof(strbuf), - "%s%d%s", str, cuser.money, po + 3); - strcpy(str, strbuf); - } + char strbuf[256]; + int r, w; + for( r = w = 0 ; str[r] != 0 && w < (sizeof(strbuf) - 1) ; ++r ) + if( str[r] != '\033' ) + strbuf[w++] = str[r]; + else{ + if( str[++r] != '*' ){ + strbuf[w++] = '\033'; + strbuf[w++] = str[r]; + } + else{ + switch( str[++r] ){ + case 's': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%s", cuser.userid); + break; + case 't': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%s", Cdate(&now)); + break; + case 'u': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%d", SHM->UTMPnumber); + break; + case 'b': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%d/%d", cuser.month, cuser.day); + break; + case 'l': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%d", cuser.numlogins); + break; + case 'p': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%d", cuser.numposts); + break; + case 'n': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%s", cuser.username); + break; + case 'm': + w += snprintf(&strbuf[w], sizeof(strbuf) - w, + "%d", cuser.money); + break; + default: + strbuf[w++] = '\033'; + strbuf[w++] = '*'; + strbuf[w++] = str[r]; + ++w; /* «á­±¦³ --w */ + } + --w; + } + } + strbuf[w] = 0; + strcpy(str, strbuf); strip_ansi(str, str, mode); return str; } -- cgit v1.2.3