Partially revert #c325ca3e028388ae6f934df2a4057229d24d021e to strip spaces in strings again.

This commit is contained in:
Y_Less 2018-06-30 16:41:50 +02:00
parent 836d4d9e35
commit 9136cf2946

View File

@ -396,8 +396,11 @@ static void readline(unsigned char *line)
*line='\0'; /* delete line */ *line='\0'; /* delete line */
cont=FALSE; cont=FALSE;
} else { } else {
/* check whether to erase leading whitespace after '\\' on next line */ /* check whether to erase leading spaces */
if (cont) { if (cont) {
unsigned char *ptr=line;
while (*ptr<=' ' && *ptr!='\0')
ptr++;
if (ptr!=line) if (ptr!=line)
memmove(line,ptr,strlen((char*)ptr)+1); memmove(line,ptr,strlen((char*)ptr)+1);
} /* if */ } /* if */
@ -512,6 +515,8 @@ static void stripcomment(unsigned char *line)
if (icomment==2) if (icomment==2)
*line++=' '; *line++=' ';
} else if (*line=='/' && *(line+1)=='/'){ /* comment to end of line */ } else if (*line=='/' && *(line+1)=='/'){ /* comment to end of line */
if (strchr((char*)line,'\a')!=NULL)
error(49); /* invalid line continuation */
#if !defined SC_LIGHT #if !defined SC_LIGHT
if (*(line+2)=='/' && *(line+3)<=' ') { if (*(line+2)=='/' && *(line+3)<=' ') {
/* documentation comment */ /* documentation comment */
@ -903,6 +908,23 @@ static const unsigned char *getstring(unsigned char *dest,int max,const unsigned
return line; return line;
} }
/* strdupwithouta
*
* Duplicate a string, stripping out `\a`s.
*/
static char* strdupwithouta(const char* sourcestring)
{
char* result=strdup(sourcestring);
char* a=result;
if (result==NULL) {
return NULL;
}
while ((a=strchr(a,'\a'))!=NULL) {
strcpy(a,a+1);
}
return result;
}
enum { enum {
CMD_NONE, CMD_NONE,
CMD_TERM, CMD_TERM,
@ -1115,7 +1137,7 @@ static int command(void)
/* remove leading whitespace */ /* remove leading whitespace */
while (*lptr<=' ' && *lptr!='\0') while (*lptr<=' ' && *lptr!='\0')
lptr++; lptr++;
pc_deprecate=strdup((const char *)lptr); pc_deprecate=strdupwithouta((const char *)lptr);
if (pc_deprecate!=NULL) { if (pc_deprecate!=NULL) {
char *ptr=pc_deprecate+strlen(pc_deprecate)-1; char *ptr=pc_deprecate+strlen(pc_deprecate)-1;
/* remove trailing whitespace */ /* remove trailing whitespace */
@ -1499,7 +1521,7 @@ static int command(void)
while (*lptr<=' ' && *lptr!='\0') while (*lptr<=' ' && *lptr!='\0')
lptr++; lptr++;
if (!SKIPPING) { if (!SKIPPING) {
char *usermsg=strdup((const char *)lptr); char *usermsg=strdupwithouta((const char *)lptr);
if (usermsg!=NULL) { if (usermsg!=NULL) {
char *ptr=usermsg+strlen(usermsg)-1; char *ptr=usermsg+strlen(usermsg)-1;
/* remove trailing whitespace and newlines */ /* remove trailing whitespace and newlines */
@ -1893,6 +1915,10 @@ static const unsigned char *unpackedstring(const unsigned char *lptr,int *flags)
while (*lptr==' ' || *lptr=='\t') /* this is as defines with parameters may add them */ while (*lptr==' ' || *lptr=='\t') /* this is as defines with parameters may add them */
lptr++; /* when you use a space after , in a match pattern */ lptr++; /* when you use a space after , in a match pattern */
while (*lptr!='\0') { while (*lptr!='\0') {
if (*lptr=='\a') {
lptr++;
continue;
} /* if */
if (!instring) { if (!instring) {
if (*lptr=='\"') { if (*lptr=='\"') {
instring=1; instring=1;
@ -1963,6 +1989,10 @@ static const unsigned char *packedstring(const unsigned char *lptr,int *flags)
i=sizeof(ucell)-(sCHARBITS/8); /* start at most significant byte */ i=sizeof(ucell)-(sCHARBITS/8); /* start at most significant byte */
val=0; val=0;
while (*lptr!='\0') { while (*lptr!='\0') {
if (*lptr=='\a') { /* ignore '\a' (which was inserted at a line concatenation) */
lptr++;
continue;
} /* if */
if (!instring) { if (!instring) {
if (*lptr=='\"') { if (*lptr=='\"') {
instring=1; instring=1;