Skip to content
Snippets Groups Projects
Commit 2d0f0753 authored by rswindell's avatar rswindell
Browse files

cleanup: Removed a few unused functions and bunch of #ifdef'd out code.

parent e8983064
No related branches found
No related tags found
No related merge requests found
......@@ -631,142 +631,6 @@ char* DLLCALL ascii_str(uchar* str)
return((char*)str);
}
char* replace_named_values(const char* src
,char* buf
,size_t buflen /* includes '\0' terminator */
,char* escape_seq
,named_string_t* string_list
,named_int_t* int_list
,BOOL case_sensitive)
{
char val[32];
size_t i;
size_t esc_len=0;
size_t name_len;
size_t value_len;
char* p = buf;
int (*cmp)(const char*, const char*, size_t);
if(case_sensitive)
cmp=strncmp;
else
cmp=strnicmp;
if(escape_seq!=NULL)
esc_len = strlen(escape_seq);
while(*src && (size_t)(p-buf) < buflen-1) {
if(esc_len) {
if(cmp(src, escape_seq, esc_len)!=0) {
*p++ = *src++;
continue;
}
src += esc_len; /* skip the escape seq */
}
if(string_list) {
for(i=0; string_list[i].name!=NULL /* terminator */; i++) {
name_len = strlen(string_list[i].name);
if(cmp(src, string_list[i].name, name_len)==0) {
value_len = strlen(string_list[i].value);
if((p-buf)+value_len > buflen-1) /* buffer overflow? */
value_len = (buflen-1)-(p-buf); /* truncate value */
memcpy(p, string_list[i].value, value_len);
p += value_len;
src += name_len;
break;
}
}
if(string_list[i].name!=NULL) /* variable match */
continue;
}
if(int_list) {
for(i=0; int_list[i].name!=NULL /* terminator */; i++) {
name_len = strlen(int_list[i].name);
if(cmp(src, int_list[i].name, name_len)==0) {
SAFEPRINTF(val,"%d",int_list[i].value);
value_len = strlen(val);
if((p-buf)+value_len > buflen-1) /* buffer overflow? */
value_len = (buflen-1)-(p-buf); /* truncate value */
memcpy(p, val, value_len);
p += value_len;
src += name_len;
break;
}
}
if(int_list[i].name!=NULL) /* variable match */
continue;
}
*p++ = *src++;
}
*p=0; /* terminate string in destination buffer */
return(buf);
}
char* replace_keyed_values(const char* src
,char* buf
,size_t buflen /* includes '\0' terminator */
,char esc_char
,keyed_string_t* string_list
,keyed_int_t* int_list
,BOOL case_sensitive)
{
char val[32];
size_t i;
size_t value_len;
char* p = buf;
while(*src && (size_t)(p-buf) < buflen-1) {
if(esc_char) {
if(*src != esc_char) {
*p++ = *src++;
continue;
}
src ++; /* skip the escape char */
}
if(string_list) {
for(i=0; string_list[i].key!=0 /* terminator */; i++) {
if((case_sensitive && *src == string_list[i].key)
|| ((!case_sensitive) && toupper(*src) == toupper(string_list[i].key))) {
value_len = strlen(string_list[i].value);
if((p-buf)+value_len > buflen-1) /* buffer overflow? */
value_len = (buflen-1)-(p-buf); /* truncate value */
memcpy(p, string_list[i].value, value_len);
p += value_len;
src++;
break;
}
}
if(string_list[i].key!=0) /* variable match */
continue;
}
if(int_list) {
for(i=0; int_list[i].key!=0 /* terminator */; i++) {
if((case_sensitive && *src == int_list[i].key)
|| ((!case_sensitive) && toupper(*src) == toupper(int_list[i].key))) {
SAFEPRINTF(val,"%d",int_list[i].value);
value_len = strlen(val);
if((p-buf)+value_len > buflen-1) /* buffer overflow? */
value_len = (buflen-1)-(p-buf); /* truncate value */
memcpy(p, val, value_len);
p += value_len;
src++;
break;
}
}
if(int_list[i].key!=0) /* variable match */
continue;
}
*p++ = *src++;
}
*p=0; /* terminate string in destination buffer */
return(buf);
}
uint32_t DLLCALL str_to_bits(uint32_t val, const char *str)
{
/* op can be 0 for replace, + for add, or - for remove */
......@@ -799,186 +663,3 @@ uint32_t DLLCALL str_to_bits(uint32_t val, const char *str)
return val;
}
#if 0 /* replace_*_values test */
void main(void)
{
char buf[128];
keyed_string_t strs[] = {
{ '+', "plus" },
{ '=', "equals" },
{ 0 }
};
keyed_int_t ints[] = {
{ 'o', 1 },
{ 't', 2 },
{ 'h', 3 },
{ NULL }
};
printf("'%s'\n", replace_keyed_values("$o $+ $t $= $h", buf, sizeof(buf), '$'
,strs, ints, FALSE));
}
#endif
#if 0 /* to be moved here from xtrn.cpp */
char* quoted_string(const char* str, char* buf, size_t maxlen)
{
if(strchr(str,' ')==NULL)
return((char*)str);
safe_snprintf(buf,maxlen,"\"%s\"",str);
return(buf);
}
#endif
#if 0 /* I think it is a misguided idea :-( */
char* sbbs_cmdstr(const char* src
,char* buf
,size_t buflen /* includes '\0' terminator */
,scfg_t* scfg
,user_t* user
,int node_num
,int minutes
,int rows
,int timeleft
,SOCKET socket_descriptor
,char* protocol
,char* ip_address
,char* fpath
,char* fspec
)
{
const char* nulstr = "";
char alias_buf[LEN_ALIAS+1];
char fpath_buf[MAX_PATH+1];
char fspec_buf[MAX_PATH+1];
char sysop_buf[sizeof(scfg->sys_op)];
keyed_string_t str_list[] = {
/* user alias */
{ 'a', user!=NULL ? quoted_string(user->alias, alias_buf, sizeof(alias_buf)) : nulstr },
{ 'A', user!=NULL ? user->alias : nulstr },
/* connection */
{ 'c', protocol },
{ 'C', protocol },
/* file path */
{ 'f', quoted_string(fpath, fpath_buf, sizeof(fpath_buf)) },
{ 'F', fpath },
/* temp dir */
{ 'g', scfg->temp_dir },
{ 'G', scfg->temp_dir },
/* IP address */
{ 'h', ip_address },
{ 'H', ip_address },
/* data dir */
{ 'j', scfg->data_dir },
{ 'J', scfg->data_dir },
/* ctrl dir */
{ 'k', scfg->ctrl_dir },
{ 'K', scfg->ctrl_dir },
/* node dir */
{ 'n', scfg->node_dir },
{ 'N', scfg->node_dir },
/* sysop */
{ 'o', quoted_string(scfg->sys_op, sysop_buf, sizeof(sysop_buf)) },
{ 'O', scfg->sys_op },
/* protocol */
{ 'p', protocol },
{ 'P', protocol },
/* system QWK-ID */
{ 'q', scfg->sys_id },
{ 'Q', scfg->sys_id },
/* file spec */
{ 's', quoted_string(fspec, fspec_buf, sizeof(fspec_buf)) },
{ 'S', fspec },
/* UART I/O Address (in hex) 'f' for FOSSIL */
{ 'u', "f" },
{ 'U', "f" },
/* text dir */
{ 'z', scfg->text_dir },
{ 'Z', scfg->text_dir },
/* exec dir */
{ '!', scfg->exec_dir },
{ '@',
#ifndef __unix__
scfg->exec_dir
#else
nulstr
#endif
},
/* .exe (on Windows) */
{ '.',
#ifndef __unix__
".exe"
#else
nulstr
#endif
},
/* terminator */
{ 0 }
};
keyed_int_t int_list[] = {
/* node number */
{ '#', node_num },
/* DTE rate */
{ 'b', 38400 },
{ 'B', 38400 },
/* DCE rate */
{ 'd', 30000 },
{ 'D', 30000 },
/* Estimated Rate (cps) */
{ 'e', 3000 },
{ 'E', 3000 },
{ 'h', socket_descriptor },
{ 'H', socket_descriptor },
{ 'l', user==NULL ? 0 : scfg->level_linespermsg[user->level] },
{ 'L', user==NULL ? 0 : scfg->level_linespermsg[user->level] },
{ 'm', minutes },
{ 'M', minutes },
{ 'r', rows },
{ 'R', rows },
/* Time left in seconds */
{ 't', timeleft },
{ 'T', timeleft },
/* Credits */
{ '$', user==NULL ? 0 : (user->cdt+user->freecdt) },
/* terminator */
{ 0 }
};
return replace_keyed_values(src, buf, buflen, '%', str_list, int_list, TRUE);
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment