escape \n and \r, too

This commit is contained in:
provos 2003-08-01 06:15:02 +00:00
parent 1f7a4f40e6
commit 5edbacc575
2 changed files with 26 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lex.l,v 1.10 2003/06/03 01:20:06 provos Exp $ */ /* $NetBSD: lex.l,v 1.11 2003/08/01 06:15:02 provos Exp $ */
/* $OpenBSD: lex.l,v 1.9 2002/08/04 04:15:50 provos Exp $ */ /* $OpenBSD: lex.l,v 1.9 2002/08/04 04:15:50 provos Exp $ */
/* /*
@ -34,7 +34,7 @@
%{ %{
#include <sys/cdefs.h> #include <sys/cdefs.h>
__RCSID("$NetBSD: lex.l,v 1.10 2003/06/03 01:20:06 provos Exp $"); __RCSID("$NetBSD: lex.l,v 1.11 2003/08/01 06:15:02 provos Exp $");
#include <sys/types.h> #include <sys/types.h>
#include <sys/tree.h> #include <sys/tree.h>
@ -116,6 +116,18 @@ as { return AS; }
quoteescape = 0; quoteescape = 0;
} }
<quote>[^\\\"]+ { <quote>[^\\\"]+ {
if (quoteescape) {
switch (yytext[0]) {
case 'n':
yytext[0] = '\n';
break;
case 'r':
yytext[0] = '\r';
break;
default:
break;
}
}
strlcat(quotestr, yytext, sizeof(quotestr)); strlcat(quotestr, yytext, sizeof(quotestr));
quoteescape = 0; quoteescape = 0;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.4 2003/06/03 01:20:06 provos Exp $ */ /* $NetBSD: util.c,v 1.5 2003/08/01 06:15:02 provos Exp $ */
/* $OpenBSD: util.c,v 1.8 2002/07/19 14:38:58 itojun Exp $ */ /* $OpenBSD: util.c,v 1.8 2002/07/19 14:38:58 itojun Exp $ */
/* /*
* Copyright 2002 Niels Provos <provos@citi.umich.edu> * Copyright 2002 Niels Provos <provos@citi.umich.edu>
@ -30,7 +30,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__RCSID("$NetBSD: util.c,v 1.4 2003/06/03 01:20:06 provos Exp $"); __RCSID("$NetBSD: util.c,v 1.5 2003/08/01 06:15:02 provos Exp $");
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
@ -47,15 +47,23 @@ strescape(char *str)
int i, p; int i, p;
for (p = i = 0; i < strlen(str) && p < sizeof(escape) - 1; i++) { for (p = i = 0; i < strlen(str) && p < sizeof(escape) - 1; i++) {
switch (str[i]) { char a = str[i];
switch (a) {
case '\r':
a = 'r';
goto doescape;
case '\n':
a = 'n';
goto doescape;
case '\\': case '\\':
case '\"': case '\"':
doescape:
escape[p++] = '\\'; escape[p++] = '\\';
if (p >= sizeof(escape) - 1) if (p >= sizeof(escape) - 1)
errx(1, "%s: string too long: %s", errx(1, "%s: string too long: %s",
__func__, str); __func__, str);
default: default:
escape[p++] = str[i]; escape[p++] = a;
} }
} }