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

Changed strip_ctrl() to JUST strip control chars and created prep_file_desc()...

Changed strip_ctrl() to JUST strip control chars and created prep_file_desc() to do what strip_ctrl used to (much more than just strip ctrl chars).
Updated crc32() to auto-detect ASCIIZ string length if no length is specified.
Updated various string loops to check for NULL rather than using strlen().
parent 5de61903
No related branches found
No related tags found
No related merge requests found
......@@ -117,38 +117,53 @@ int bstrlen(char *str)
return(i);
}
void DLLCALL strip_ctrl(char *str)
char* DLLCALL strip_ctrl(char *str)
{
char tmp[1024];
int i,j,k;
int i,j;
k=strlen(str);
for(i=j=0;i<k;i++)
for(i=j=0;str[i];i++)
if(str[i]==CTRL_A)
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);
}
void DLLCALL strip_exascii(char *str)
char* DLLCALL strip_exascii(char *str)
{
char tmp[1024];
int i,j,k;
int i,j;
k=strlen(str);
for(i=j=0;i<k;i++)
for(i=j=0;str[i];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)
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);
}
/****************************************************************************/
......@@ -228,7 +243,7 @@ void ucrc16(uchar ch, ushort *rcrc)
}
/****************************************************************************/
/* Returns CRC-16 of string (not including terminating NULL) */
/* Returns CRC-16 of ASCIIZ string (not including terminating NULL) */
/****************************************************************************/
ushort DLLCALL crc16(char *str)
{
......@@ -244,12 +259,16 @@ ushort DLLCALL crc16(char *str)
}
/****************************************************************************/
/* Returns CRC-32 of string (not including terminating NULL) */
/* Returns CRC-32 of sequence of bytes (binary or ASCIIZ) */
/* Pass len of 0 to auto-determine ASCIIZ string length */
/* or non-zero for arbitrary binary data */
/****************************************************************************/
ulong crc32(char *buf, ulong len)
{
ulong l,crc=0xffffffff;
if(len==0)
len=strlen(buf);
for(l=0;l<len;l++)
crc=ucrc32(buf[l],crc);
return(~crc);
......
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