CVS commit: src/usr.bin/sed

2023-01-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jan 20 01:26:02 UTC 2023

Modified Files:
src/usr.bin/sed: compile.c

Log Message:
s/delimeter/delimiter/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/sed/compile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/sed/compile.c
diff -u src/usr.bin/sed/compile.c:1.50 src/usr.bin/sed/compile.c:1.51
--- src/usr.bin/sed/compile.c:1.50	Sat Mar 13 15:46:54 2021
+++ src/usr.bin/sed/compile.c	Fri Jan 20 01:26:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: compile.c,v 1.50 2021/03/13 15:46:54 christos Exp $	*/
+/*	$NetBSD: compile.c,v 1.51 2023/01/20 01:26:02 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1992 Diomidis Spinellis.
@@ -38,7 +38,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: compile.c,v 1.50 2021/03/13 15:46:54 christos Exp $");
+__RCSID("$NetBSD: compile.c,v 1.51 2023/01/20 01:26:02 msaitoh Exp $");
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/usr.bin/sed/compile.c 259132 2013-12-09 18:57:20Z eadler $");
 #endif
@@ -376,7 +376,7 @@ nonsel:		/* Now parse the command */
 }
 
 /*
- * Get a delimited string.  P points to the delimeter of the string; d points
+ * Get a delimited string.  P points to the delimiter of the string; d points
  * to a buffer area.  Newline and delimiter escapes are processed; other
  * escapes are ignored.
  *



CVS commit: src/usr.bin/sed

2023-01-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Jan 20 01:26:02 UTC 2023

Modified Files:
src/usr.bin/sed: compile.c

Log Message:
s/delimeter/delimiter/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/sed/compile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/sed

2021-03-30 Thread Christos Zoulas
In article ,
John Klos   wrote:
>Log Message:
>Use the same options like m4 (-g turns on GNU, -G turns off GNU) Suggested
>by uwe@
>
>It seems, based on comparing netbsd-9 and -current, that the default was 
>-g (GNU on), and is now -G (GNU off). Should the default be mentioned in 
>the man page?

NetBSD-9 did not support gnu extensions, but it silently ignored
them (e.g. \w became w). NetBSD-current supports them but they are
off by default; it also warns about \ escapes it does not recognize.

All the packages that warn now and did not warn before, were just not
working properly before.

christos



Re: CVS commit: src/usr.bin/sed

2021-03-30 Thread John Klos

Log Message:
Use the same options like m4 (-g turns on GNU, -G turns off GNU) Suggested
by uwe@

It seems, based on comparing netbsd-9 and -current, that the default was 
-g (GNU on), and is now -G (GNU off). Should the default be mentioned in 
the man page?


John


Re: CVS commit: src/usr.bin/sed

2021-03-11 Thread Christos Zoulas
In article ,
Valery Ushakov   wrote:
>On Thu, Mar 11, 2021 at 10:15:05 -0500, Christos Zoulas wrote:
>
>> Module Name: src
>> Committed By:christos
>> Date:Thu Mar 11 15:15:05 UTC 2021
>> 
>> Modified Files:
>>  src/usr.bin/sed: main.c sed.1
>> 
>> Log Message:
>> Add -G to support GNU extensions
>
>This is inverse of m4(1) where -g/--gnu enables GNU extensions and
>-G/--traditional disables them.  Can we be consistent about that?  Do
>we have other programs with gnu-compat mode?

I have made it the same as m4. Looking for more programs with gnu extensions.

christos



Re: CVS commit: src/usr.bin/sed

2021-03-11 Thread Valery Ushakov
On Thu, Mar 11, 2021 at 10:15:05 -0500, Christos Zoulas wrote:

> Module Name:  src
> Committed By: christos
> Date: Thu Mar 11 15:15:05 UTC 2021
> 
> Modified Files:
>   src/usr.bin/sed: main.c sed.1
> 
> Log Message:
> Add -G to support GNU extensions

This is inverse of m4(1) where -g/--gnu enables GNU extensions and
-G/--traditional disables them.  Can we be consistent about that?  Do
we have other programs with gnu-compat mode?

-uwe


CVS commit: src/usr.bin/sed

2019-10-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct  5 20:23:55 UTC 2019

Modified Files:
src/usr.bin/sed: compile.c

Log Message:
Recognize \oOOO \dDD \xXX plus the other regular 'C' backslash escapes like
gnu sed does, except when inside regex []. (Gnu sed translates those too,
unless --posix is specified).


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/sed/compile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/sed

2019-10-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct  5 20:23:55 UTC 2019

Modified Files:
src/usr.bin/sed: compile.c

Log Message:
Recognize \oOOO \dDD \xXX plus the other regular 'C' backslash escapes like
gnu sed does, except when inside regex []. (Gnu sed translates those too,
unless --posix is specified).


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/sed/compile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/sed/compile.c
diff -u src/usr.bin/sed/compile.c:1.47 src/usr.bin/sed/compile.c:1.48
--- src/usr.bin/sed/compile.c:1.47	Mon Apr  4 20:13:03 2016
+++ src/usr.bin/sed/compile.c	Sat Oct  5 16:23:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: compile.c,v 1.47 2016/04/05 00:13:03 christos Exp $	*/
+/*	$NetBSD: compile.c,v 1.48 2019/10/05 20:23:55 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992 Diomidis Spinellis.
@@ -38,7 +38,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: compile.c,v 1.47 2016/04/05 00:13:03 christos Exp $");
+__RCSID("$NetBSD: compile.c,v 1.48 2019/10/05 20:23:55 christos Exp $");
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/usr.bin/sed/compile.c 259132 2013-12-09 18:57:20Z eadler $");
 #endif
@@ -89,6 +89,7 @@ static struct s_command
 		 *findlabel(char *);
 static void	  fixuplabel(struct s_command *, struct s_command *);
 static void	  uselabel(void);
+static void	  parse_escapes(char *);
 
 /*
  * Command specification.  This is used to drive the command parser.
@@ -463,6 +464,7 @@ compile_re(char *re, int case_insensitiv
 	if (case_insensitive)
 		flags |= REG_ICASE;
 	rep = xmalloc(sizeof(regex_t));
+	parse_escapes(re);
 	if ((eval = regcomp(rep, re, flags)) != 0)
 		errx(1, "%lu: %s: RE error: %s",
 linenum, fname, strregerror(eval, rep));
@@ -471,6 +473,134 @@ compile_re(char *re, int case_insensitiv
 	return (rep);
 }
 
+static char
+cton(char c, int base)
+{
+	switch (c) {
+	case '0': case '1': case '2': case '3': case '4':
+	case '5': case '6': case '7':
+		return (char)(c - '0');
+	case '8': case '9':
+		return base == 8 ? '?' : (char)(c - '0');
+	case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+		return base == 16 ? (char)(c - 'a' + 10) : '?'; 
+	case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+		return base == 16 ? (char)(c - 'A' + 10) : '?'; 
+	default:
+		return '?';
+	}
+}
+
+static int
+ston(char **pp, char *sp, int base)
+{
+	char *p = *pp, n;
+	int r = cton(p[1], base);
+
+	if (r == '?')
+		return 0;
+
+	p++;
+	while ((n = cton(p[1], base)) != '?' && r < 255) {
+		r = r * base + n;
+		p++;
+	}
+	*sp = (char)r;
+	*pp = p;
+	return 1;
+}
+		
+static int
+unescape(char **pp, char **spp)
+{
+	char *p = *pp;
+	char *sp = *spp;
+
+	switch (*p) {
+	case 'o':
+		if (!ston(, sp, 8))
+			return 0;
+		break;
+	case 'd':
+		if (!ston(, sp, 10))
+			return 0;
+		break;
+	case 'x':
+		if (!ston(, sp, 16))
+			return 0;
+		break;
+	case 'a':
+		*sp = '\a';
+		p++;
+		break;
+#if 0
+	// No, \b RE
+	case 'b':
+		*sp = '\b';
+		break;
+#endif
+	case 'f':
+		*sp = '\f';
+		break;
+	case 'n':
+		*sp = '\n';
+		break;
+	case 'r':
+		*sp = '\r';
+		break;
+	case 'v':
+		*sp = '\v';
+		break;
+	default:
+		return 0;
+	}
+	*spp = sp + 1;
+	*pp = p;
+	return 1;
+}
+
+static void
+parse_escapes(char *buf)
+{
+	char bracket = '\0';
+	char *p, *q;
+
+	p = q = buf;
+
+	for (p = q = buf; *p; p++) {
+		if (*p == '\\' && p[1] && !bracket) {
+			p++;
+			if (unescape(, ))
+continue;
+			*q++ = '\\';
+		}
+		switch (*p) {
+		case '[':
+			if (!bracket)
+bracket = *p;
+			break;
+		case '.':
+		case ':':
+		case '=':
+			if (bracket == '[' && p[-1] == '[')
+bracket = *p;
+			break;
+		case ']':
+			if (!bracket)
+			break;
+			if (bracket == '[')
+bracket = '\0';
+			else if (p[-2] != bracket && p[-1] == bracket)
+bracket = '[';
+			break;
+		default:
+			break;
+		}
+		*q++ = *p;
+	}
+	*q = '\0';
+}
+
 /*
  * Compile the substitution string of a regular expression and set res to
  * point to a saved copy of it.  Nsub is the number of parenthesized regular
@@ -508,7 +638,8 @@ compile_subst(char *p, struct s_subst *s
 else
 	p++;
 
-if (*p == '\0') {
+switch (*p) {
+case '\0':
 	/*
 	 * This escaped character is continued
 	 * in the next part of the line.  Note
@@ -519,7 +650,9 @@ compile_subst(char *p, struct s_subst *s
 	sawesc = 1;
 	p--;
 	continue;
-} else if (strchr("123456789", *p) != NULL) {
+case '0': case '1': case '2': case '3':
+case '4': case '5': case '6': case '7':
+case '8': case '9':
 	*sp++ = '\\';
 	ref = (u_char)(*p - '0');
 	if (s->re != NULL &&
@@ -528,8 +661,16 @@ compile_subst(char *p, struct s_subst *s
 linenum, fname, *p);
 	if (s->maxbref < ref)
 		s->maxbref = ref;
-} else if (*p == '&' || *p == '\\')
+	break;
+case '&':
+case '\\':
 	*sp++ = '\\';
+	break;
+

CVS commit: src/usr.bin/sed

2019-10-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct  5 20:22:36 UTC 2019

Modified Files:
src/usr.bin/sed: main.c

Log Message:
add an abort for a case that can't happen


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/sed/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/sed/main.c
diff -u src/usr.bin/sed/main.c:1.34 src/usr.bin/sed/main.c:1.35
--- src/usr.bin/sed/main.c:1.34	Thu Mar 12 08:40:41 2015
+++ src/usr.bin/sed/main.c	Sat Oct  5 16:22:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.34 2015/03/12 12:40:41 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.35 2019/10/05 20:22:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson.
@@ -39,7 +39,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: main.c,v 1.34 2015/03/12 12:40:41 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.35 2019/10/05 20:22:36 christos Exp $");
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/usr.bin/sed/main.c 252231 2013-06-26 04:14:19Z pfg $");
 #endif
@@ -268,6 +268,8 @@ again:
 			s = script->s;
 			state = ST_STRING;
 			goto again;
+		default:
+			abort();
 		}
 	case ST_FILE:
 		if ((p = fgets(buf, n, f)) != NULL) {



CVS commit: src/usr.bin/sed

2019-10-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct  5 20:22:36 UTC 2019

Modified Files:
src/usr.bin/sed: main.c

Log Message:
add an abort for a case that can't happen


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/sed/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/sed

2015-03-01 Thread Warner Losh

 On Mar 1, 2015, at 8:45 AM, Aleksej Saushev a...@inbox.ru wrote:
 
 chris...@astron.com (Christos Zoulas) writes:
 
 In article 20150228215653.f2f0...@cvs.netbsd.org,
 Aleksej Saushev source-changes-d@NetBSD.org wrote:
 -=-=-=-=-=-
 
 Module Name:src
 Committed By:   asau
 Date:   Sat Feb 28 21:56:53 UTC 2015
 
 Modified Files:
 src/usr.bin/sed: compile.c extern.h main.c process.c
 
 Log Message:
 Improve modularity of sed source:
 - move program source input subroutines into compiler part;
 - move data I/O subroutines into processor part.
 
 It there a good reason for that? We try to keep it synced with FreeBSD..
 
 It makes code a lot cleaner and allows embedding it.
 
 If that's problem, I'll submit changes to FreeBSD.

Sounds like a good idea to me…

Warner


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: CVS commit: src/usr.bin/sed

2015-03-01 Thread Aleksej Saushev
chris...@astron.com (Christos Zoulas) writes:

 In article 20150228215653.f2f0...@cvs.netbsd.org,
 Aleksej Saushev source-changes-d@NetBSD.org wrote:
-=-=-=-=-=-

Module Name:  src
Committed By: asau
Date: Sat Feb 28 21:56:53 UTC 2015

Modified Files:
  src/usr.bin/sed: compile.c extern.h main.c process.c

Log Message:
Improve modularity of sed source:
- move program source input subroutines into compiler part;
- move data I/O subroutines into processor part.

 It there a good reason for that? We try to keep it synced with FreeBSD..

It makes code a lot cleaner and allows embedding it.

If that's problem, I'll submit changes to FreeBSD.


-- 
HE CE3OH...



Re: CVS commit: src/usr.bin/sed

2015-02-28 Thread Christos Zoulas
In article 20150228215653.f2f0...@cvs.netbsd.org,
Aleksej Saushev source-changes-d@NetBSD.org wrote:
-=-=-=-=-=-

Module Name:   src
Committed By:  asau
Date:  Sat Feb 28 21:56:53 UTC 2015

Modified Files:
   src/usr.bin/sed: compile.c extern.h main.c process.c

Log Message:
Improve modularity of sed source:
- move program source input subroutines into compiler part;
- move data I/O subroutines into processor part.

It there a good reason for that? We try to keep it synced with FreeBSD..

christos



Re: CVS commit: src/usr.bin/sed

2014-06-07 Thread Ryo ONODERA
Hi,

This change breaks many pkgsrc packages.
Please take a look at PR bin/48880.

Thank you.

From: Christos Zoulas chris...@netbsd.org, Date: Thu, 5 Jun 2014 20:13:13 
-0400

 Module Name:  src
 Committed By: christos
 Date: Fri Jun  6 00:13:13 UTC 2014
 
 Modified Files:
   src/usr.bin/sed: Makefile POSIX compile.c defs.h extern.h main.c misc.c
   process.c sed.1
 
 Log Message:
 Merge our changes.
 
 
 To generate a diff of this commit:
 cvs rdiff -u -r1.14 -r1.15 src/usr.bin/sed/Makefile
 cvs rdiff -u -r1.4 -r1.5 src/usr.bin/sed/POSIX
 cvs rdiff -u -r1.40 -r1.41 src/usr.bin/sed/compile.c
 cvs rdiff -u -r1.10 -r1.11 src/usr.bin/sed/defs.h
 cvs rdiff -u -r1.11 -r1.12 src/usr.bin/sed/extern.h src/usr.bin/sed/misc.c
 cvs rdiff -u -r1.21 -r1.22 src/usr.bin/sed/main.c
 cvs rdiff -u -r1.39 -r1.40 src/usr.bin/sed/process.c
 cvs rdiff -u -r1.32 -r1.33 src/usr.bin/sed/sed.1
 
 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
 

--
Ryo ONODERA // ryo...@yk.rim.or.jp
PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB  FD1B F404 27FA C7D1 15F3


CVS commit: src/usr.bin/sed

2010-02-19 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Fri Feb 19 16:35:27 UTC 2010

Modified Files:
src/usr.bin/sed: compile.c defs.h extern.h main.c misc.c

Log Message:
Merge the following revisions from OpenBSD to let sed(1) handle
arbitrarily long lines (closes our PR bin/42261).
openbsd/usr.bin/sed/extern.h 1.5
openbsd/usr.bin/sed/main.c 1.13-1.15
openbsd/usr.bin/sed/misc.c 1.8
openbsd/usr.bin/sed/compile.c 1.25-1.28
openbsd/usr.bin/sed/defs.h 1.4


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/sed/compile.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/sed/defs.h
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/sed/extern.h src/usr.bin/sed/misc.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/sed/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.