Skip to content
Snippets Groups Projects
Commit 743f77a6 authored by rswindell's avatar rswindell
Browse files

Moved C-exported functions to str_util.c

parent a4da9482
No related branches found
No related tags found
No related merge requests found
......@@ -37,81 +37,6 @@
#include "sbbs.h"
const char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
const char *mon[]={"Jan","Feb","Mar","Apr","May","Jun"
,"Jul","Aug","Sep","Oct","Nov","Dec"};
/****************************************************************************/
/* Removes ctrl-a codes from the string 'instr' */
/****************************************************************************/
char* DLLCALL remove_ctrl_a(char *instr, char *outstr)
{
char str[1024],*p;
uint i,j;
for(i=j=0;instr[i] && j<sizeof(str)-1;i++) {
if(instr[i]==CTRL_A && instr[i+1]!=0)
i++;
else str[j++]=instr[i];
}
str[j]=0;
if(outstr!=NULL)
p=outstr;
else
p=instr;
strcpy(p,str);
return(p);
}
char* DLLCALL strip_ctrl(char *str)
{
char tmp[1024];
int i,j;
for(i=j=0;str[i] && j<(int)sizeof(tmp)-1;i++)
if(str[i]==CTRL_A && str[i+1]!=0)
i++;
else if((uchar)str[i]>=SP)
tmp[j++]=str[i];
tmp[j]=0;
strcpy(str,tmp);
return(str);
}
char* DLLCALL strip_exascii(char *str)
{
char tmp[1024];
int i,j;
for(i=j=0;str[i] && j<(int)sizeof(tmp)-1;i++)
if(!(str[i]&0x80))
tmp[j++]=str[i];
tmp[j]=0;
strcpy(str,tmp);
return(str);
}
char* DLLCALL prep_file_desc(char *str)
{
char tmp[1024];
int i,j;
for(i=j=0;str[i];i++)
if(str[i]==CTRL_A && str[i+1]!=0)
i++;
else if(j && str[i]<=SP && tmp[j-1]==SP)
continue;
else if(i && !isalnum(str[i]) && str[i]==str[i-1])
continue;
else if((uchar)str[i]>=SP)
tmp[j++]=str[i];
else if(str[i]==TAB || (str[i]==CR && str[i+1]==LF))
tmp[j++]=SP;
tmp[j]=0;
strcpy(str,tmp);
return(str);
}
/****************************************************************************/
/* Lists all users who have access to the current sub. */
/****************************************************************************/
......@@ -784,90 +709,6 @@ void sbbs_t::dirinfo(uint dirnum)
printfile(str,0);
}
/****************************************************************************/
/* Pattern matching string search of 'insearchof' in 'fname'. */
/****************************************************************************/
extern "C" BOOL DLLCALL findstr(scfg_t* cfg, char* insearchof, char* fname)
{
char* p;
char str[128];
char search[81];
int c;
int i;
BOOL found;
FILE* stream;
if((stream=fopen(fname,"r"))==NULL)
return(FALSE);
SAFECOPY(search,insearchof);
strupr(search);
found=FALSE;
while(!feof(stream) && !ferror(stream) && !found) {
if(!fgets(str,sizeof(str),stream))
break;
found=FALSE;
p=str;
while(*p && *p<=' ') p++; /* Skip white-space */
if(*p==';') /* comment */
continue;
if(*p=='!') { /* !match */
found=TRUE;
p++;
}
truncsp(p);
c=strlen(p);
if(c) {
c--;
strupr(p);
if(p[c]=='~') {
p[c]=0;
if(strstr(search,p))
found=!found;
}
else if(p[c]=='^' || p[c]=='*') {
p[c]=0;
if(!strncmp(p,search,c))
found=!found;
}
else if(p[0]=='*') {
i=strlen(search);
if(i<c)
continue;
if(!strncmp(p+1,search+(i-c),c))
found=!found;
}
else if(!strcmp(p,search))
found=!found;
}
}
fclose(stream);
return(found);
}
/****************************************************************************/
/* Searches the file <name>.can in the TEXT directory for matches */
/* Returns TRUE if found in list, FALSE if not. */
/****************************************************************************/
extern "C" BOOL DLLCALL trashcan(scfg_t* cfg, char* insearchof, char* name)
{
char fname[MAX_PATH+1];
sprintf(fname,"%s%s.can",cfg->text_dir,name);
return(findstr(cfg,insearchof,fname));
}
/****************************************************************************/
/* Searches the file <name>.can in the TEXT directory for matches */
/* Returns TRUE if found in list, FALSE if not. */
......
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