diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-09 15:05:42 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-09 15:05:42 +0800 |
commit | 22bb492bf7c59f517cb8216d0f0dc980e23cb460 (patch) | |
tree | b56b76019ed1480f1cea5283aa0f41723da96ff5 /mbbsd | |
parent | e8edfbff2de447873e7ba9cf3019dcb689fe4082 (diff) | |
download | pttbbs-22bb492bf7c59f517cb8216d0f0dc980e23cb460.tar pttbbs-22bb492bf7c59f517cb8216d0f0dc980e23cb460.tar.gz pttbbs-22bb492bf7c59f517cb8216d0f0dc980e23cb460.tar.bz2 pttbbs-22bb492bf7c59f517cb8216d0f0dc980e23cb460.tar.lz pttbbs-22bb492bf7c59f517cb8216d0f0dc980e23cb460.tar.xz pttbbs-22bb492bf7c59f517cb8216d0f0dc980e23cb460.tar.zst pttbbs-22bb492bf7c59f517cb8216d0f0dc980e23cb460.zip |
- (internal) change Ptt_prints to better function: expand_esc_star
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4108 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/kaede.c | 172 |
1 files changed, 94 insertions, 78 deletions
diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c index b3d9c0ae..fa591aad 100644 --- a/mbbsd/kaede.c +++ b/mbbsd/kaede.c @@ -4,63 +4,79 @@ // TODO move stuff to libbbs(or util)/string.c, ... // this file can be removed (or not?) -char * +int +expand_esc_star(char *buf, const char *src, int szbuf) +{ + if (*src != ESC_CHR) + { + strlcpy(buf, src, szbuf); + return 0; + } + + if (*++src != '*') // unknown escape... strip the ESC. + { + strlcpy(buf, src, szbuf); + return 0; + } + + switch(*++src) + { + // + // secure content + // + case 't': // current time + strlcpy(buf, Cdate(&now), szbuf); + return 1; + case 'u': // current online users + snprintf(buf, szbuf, "%d", SHM->UTMPnumber); + return 1; + // + // insecure content + // + case 's': // current user id + strlcpy(buf, cuser.userid, szbuf); + return 2; + case 'n': // current user nickname + strlcpy(buf, cuser.nickname, szbuf); + return 2; + case 'l': // current user logins + snprintf(buf, szbuf, "%d", cuser.numlogins); + return 2; + case 'p': // current user posts + snprintf(buf, szbuf, "%d", cuser.numposts); + return 2; + } + + // unknown characters, return from star. + strlcpy(buf, src-1, szbuf); + return 0; +} + +char * Ptt_prints(char *str, size_t size, int mode) { char *strbuf = alloca(size); int r, w; for( r = w = 0 ; str[r] != 0 && w < (size - 1) ; ++r ) - if( str[r] != ESC_CHR ) - strbuf[w++] = str[r]; - else{ - if( str[++r] != '*' ){ - if(w+2>=size-1) break; - strbuf[w++] = ESC_CHR; - strbuf[w++] = str[r]; - } - else{ - /* Note, w will increased by copied length after */ - switch( str[++r] ){ - - // secure content - - case 't': // current time - strlcpy(strbuf+w, Cdate(&now), size-w); - w += strlen(strbuf+w); - break; - case 'u': // current online users - w += snprintf(&strbuf[w], size - w, - "%d", SHM->UTMPnumber); - break; - - // insecure content - - case 's': // current user id - strlcpy(strbuf+w, cuser.userid, size-w); - w += strlen(strbuf+w); - break; - case 'n': // current user nickname - strlcpy(strbuf+w, cuser.nickname, size-w); - w += strlen(strbuf+w); - break; - case 'l': // current user logins - w += snprintf(&strbuf[w], size - w, - "%d", cuser.numlogins); - break; - case 'p': // current user posts - w += snprintf(&strbuf[w], size - w, - "%d", cuser.numposts); - break; - - /* It's saver not to send these undefined escape string. - default: - strbuf[w++] = ESC_CHR; - strbuf[w++] = '*'; - strbuf[w++] = str[r]; - */ - } - } - } + { + if( str[r] != ESC_CHR ) + { + strbuf[w++] = str[r]; + continue; + } + + if( str[++r] != '*' ){ + if(w+2>=size-1) break; + strbuf[w++] = ESC_CHR; + strbuf[w++] = str[r]; + continue; + } + + /* Note, w will increased by copied length after */ + expand_esc_star(strbuf+w, &(str[r-1]), size-w); + r ++; + w += strlen(strbuf+w); + } strbuf[w] = 0; strip_ansi(str, strbuf, mode); return str; @@ -71,7 +87,7 @@ void outs_n(const char *str, int n) { while (*str && n--) { - outc(*str++); + outc(*str++); } } @@ -81,13 +97,13 @@ void outslr(const char *left, int leftlen, const char *right, int rightlen) { if (left == NULL) - left = ""; + left = ""; if (right == NULL) - right = ""; + right = ""; if(*left && leftlen < 0) - leftlen = strlen(left); + leftlen = strlen(left); if(*right && rightlen < 0) - rightlen = strlen(right); + rightlen = strlen(right); // now calculate padding rightlen = t_columns - leftlen - rightlen; outs(left); @@ -95,13 +111,13 @@ outslr(const char *left, int leftlen, const char *right, int rightlen) // ignore right msg if we need to. if(rightlen >= 0) { - while(--rightlen > 0) - outc(' '); - outs(right); + while(--rightlen > 0) + outc(' '); + outs(right); } else { - rightlen = t_columns - leftlen; - while(--rightlen > 0) - outc(' '); + rightlen = t_columns - leftlen; + while(--rightlen > 0) + outc(' '); } } @@ -110,19 +126,19 @@ outslr(const char *left, int leftlen, const char *right, int rightlen) void out_lines(const char *str, int line) { - int y, x; - getyx(&y, &x); + int y, x; + getyx(&y, &x); while (*str && line) { - if (*str == '\n') - { - move(++y, 0); - line--; - } else - { - outc(*str); - } - str++; - } + if (*str == '\n') + { + move(++y, 0); + line--; + } else + { + outc(*str); + } + str++; + } } void @@ -145,8 +161,8 @@ outmsglr(const char *msg, int llen, const char *rmsg, int rlen) void prints(const char *fmt,...) { - va_list args; - char buff[1024]; + va_list args; + char buff[1024]; va_start(args, fmt); vsnprintf(buff, sizeof(buff), fmt, args); @@ -162,4 +178,4 @@ mouts(int y, int x, const char *str) outs(str); } -// vim:ts=4 +// vim:ts=4:expandtab |