Commit 6ae9dbb4 authored by rswindell's avatar rswindell
Browse files

Allow @-code format modifiers to be separated from the code-name/argument

with a pipe (|) symbol, rather than a '-'. This accomplishes 2 things:
- code:args can be used again with format-modifiers as pipe (|) is an illegal
  filename char in all supported OSes.
- multiple format modifers can be specified for some may (now) be combined.

* New format modifier 'T' (for thousands separated), adds separator (,) between
  thousands in numeric expanded @-codes. May be combined with other format
  modifiers when using the pipe-syntax (not the dash).
parent 1e341998
......@@ -47,6 +47,27 @@
#define SOCKLIB_DESC NULL
#endif
static char* separate_thousands(const char* src, char *dest, size_t maxlen, char sep)
{
if(strlen(src) * 1.3 > maxlen)
return (char*)src;
const char* tail = src;
while(*tail && isdigit(*tail))
tail++;
if(tail == src)
return (char*)src;
size_t digits = tail - src;
char* d = dest;
for(size_t i = 0; i < digits; d++, i++) {
*d = src[i];
if(i && i + 3 < digits && (digits - (i + 1)) % 3 == 0)
*(++d) = sep;
}
*d = 0;
strcpy(d, tail);
return dest;
}
/****************************************************************************/
/* Returns 0 if invalid @ code. Returns length of @ code if valid. */
/****************************************************************************/
......@@ -61,6 +82,7 @@ int sbbs_t::show_atcode(const char *instr)
bool zero_padded=false;
bool truncated = true;
bool doubled = false;
bool thousep = false; // thousands-separated
long pmode = 0;
const char *cp;
......@@ -76,7 +98,23 @@ int sbbs_t::show_atcode(const char *instr)
sp=(str+1);
disp_len=len;
if(strchr(sp, ':') != NULL)
if((p = strchr(sp, '|')) != NULL) {
if(strchr(p, 'T') != NULL)
thousep = true;
if(strchr(p, 'L') != NULL)
padded_left = true;
else if(strchr(p, 'R') != NULL)
padded_right = true;
else if(strchr(p, 'C') != NULL)
centered = true;
else if(strchr(p, 'W') != NULL)
doubled = true;
else if(strchr(p, 'Z') != NULL)
zero_padded = true;
else if(strchr(p, '>') != NULL)
truncated = false;
}
else if(strchr(sp, ':') != NULL)
p = NULL;
else if((p=strstr(sp,"-L"))!=NULL)
padded_left=true;
......@@ -88,10 +126,14 @@ int sbbs_t::show_atcode(const char *instr)
doubled=true;
else if((p=strstr(sp,"-Z"))!=NULL)
zero_padded=true;
else if((p=strstr(sp,"-T"))!=NULL)
thousep=true;
else if((p=strstr(sp,"->"))!=NULL) /* wrap */
truncated = false;
if(p!=NULL) {
char* lp = p + 2;
char* lp = p;
while(*lp && !isdigit(*lp))
lp++;
if(*lp && isdigit(*lp))
disp_len=atoi(lp);
*p=0;
......@@ -101,6 +143,10 @@ int sbbs_t::show_atcode(const char *instr)
if(cp==NULL)
return(0);
char separated[128];
if(thousep)
cp = separate_thousands(cp, separated, sizeof(separated), ',');
if(p==NULL || truncated == false)
disp_len = strlen(cp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment