Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Fedora Release Engineering | a57f118040 | |
Jan Görig | 5f4b1e1d68 | |
Bill Nottingham | f4507f7c35 | |
Jiří Moskovčák | 911eeed339 | |
Jesse Keating | e89800c384 |
21
Makefile
21
Makefile
|
@ -1,21 +0,0 @@
|
|||
# Makefile for source rpm: sed
|
||||
# $Id: Makefile,v 1.1 2004/09/09 12:09:04 cvsdist Exp $
|
||||
NAME := sed
|
||||
SPECFILE = $(firstword $(wildcard *.spec))
|
||||
|
||||
define find-makefile-common
|
||||
for d in common ../common ../../common ; do if [ -f $$d/Makefile.common ] ; then if [ -f $$d/CVS/Root -a -w $$/Makefile.common ] ; then cd $$d ; cvs -Q update ; fi ; echo "$$d/Makefile.common" ; break ; fi ; done
|
||||
endef
|
||||
|
||||
MAKEFILE_COMMON := $(shell $(find-makefile-common))
|
||||
|
||||
ifeq ($(MAKEFILE_COMMON),)
|
||||
# attempt a checkout
|
||||
define checkout-makefile-common
|
||||
test -f CVS/Root && { cvs -Q -d $$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2
|
||||
endef
|
||||
|
||||
MAKEFILE_COMMON := $(shell $(checkout-makefile-common))
|
||||
endif
|
||||
|
||||
include $(MAKEFILE_COMMON)
|
|
@ -1,223 +0,0 @@
|
|||
diff -Burp sed-4.1.5/doc/sed.1 sed-4.1.5-f+c/doc/sed.1
|
||||
--- sed-4.1.5/doc/sed.1 2006-02-03 10:27:35.000000000 +0100
|
||||
+++ sed-4.1.5-f+c/doc/sed.1 2006-12-08 16:42:59.000000000 +0100
|
||||
@@ -1,5 +1,5 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
|
||||
-.TH SED "1" "February 2006" "sed version 4.1.4" "User Commands"
|
||||
+.TH SED "1" "June 2006" "sed version 4.1.5" "User Commands"
|
||||
.SH NAME
|
||||
sed \- stream editor for filtering and transforming text
|
||||
.SH SYNOPSIS
|
||||
@@ -36,6 +36,11 @@ add the contents of script-file to the c
|
||||
.IP
|
||||
edit files in place (makes backup if extension supplied)
|
||||
.HP
|
||||
+\fB\-c\fR, \fB\-\-copy\fR
|
||||
+.IP
|
||||
+use copy instead of rename when shuffling files in \fB\-i\fR mode
|
||||
+(avoids change of input file ownership)
|
||||
+.HP
|
||||
\fB\-l\fR N, \fB\-\-line\-length\fR=\fIN\fR
|
||||
.IP
|
||||
specify the desired line-wrap length for the `l' command
|
||||
diff -Burp sed-4.1.5/lib/utils.c sed-4.1.5-f+c/lib/utils.c
|
||||
--- sed-4.1.5/lib/utils.c 2006-12-08 16:41:41.000000000 +0100
|
||||
+++ sed-4.1.5-f+c/lib/utils.c 2006-12-08 16:42:59.000000000 +0100
|
||||
@@ -405,6 +406,55 @@ _unlink_if_fail (rd, unlink_if_fail)
|
||||
return rd != -1;
|
||||
}
|
||||
|
||||
+/* Copy contents between files. */
|
||||
+static int
|
||||
+_copy (from, to)
|
||||
+ const char *from, *to;
|
||||
+{
|
||||
+ static size_t bufsize = 1024;
|
||||
+ FILE *infile, *outfile;
|
||||
+ int retval = 0;
|
||||
+ char * buf;
|
||||
+
|
||||
+ errno = 0;
|
||||
+
|
||||
+ infile = fopen (from, "r");
|
||||
+ if (infile == NULL)
|
||||
+ return -1;
|
||||
+
|
||||
+ outfile = fopen (to, "w");
|
||||
+ if (outfile == NULL)
|
||||
+ {
|
||||
+ fclose (infile);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ buf = alloca (bufsize);
|
||||
+ while (1)
|
||||
+ {
|
||||
+ size_t bytes_in = fread (buf, 1, bufsize, infile);
|
||||
+ size_t bytes_out;
|
||||
+ if (bytes_in == 0)
|
||||
+ {
|
||||
+ if (ferror (infile))
|
||||
+ retval = -1;
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ bytes_out = fwrite (buf, 1, bytes_in, outfile);
|
||||
+ if (bytes_out != bytes_in)
|
||||
+ {
|
||||
+ retval = -1;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ fclose (outfile);
|
||||
+ fclose (infile);
|
||||
+
|
||||
+ return retval;
|
||||
+}
|
||||
+
|
||||
/* Panic on failing rename */
|
||||
void
|
||||
ck_rename (from, to, unlink_if_fail)
|
||||
@@ -415,6 +465,26 @@ ck_rename (from, to, unlink_if_fail)
|
||||
panic (_("cannot rename %s: %s"), from, strerror (errno));
|
||||
}
|
||||
|
||||
+/* Attempt to copy file contents between the files. */
|
||||
+void
|
||||
+ck_fcmove (from, to, unlink_if_fail)
|
||||
+ const char *from, *to;
|
||||
+ const char *unlink_if_fail;
|
||||
+{
|
||||
+ if (!_unlink_if_fail (_copy (from, to), unlink_if_fail))
|
||||
+ panic (_("cannot copy %s to %s: %s"), from, to, strerror (errno));
|
||||
+}
|
||||
+
|
||||
+/* Copy contents between files, and then unlink the source. */
|
||||
+void
|
||||
+ck_fcopy (from, to, unlink_if_fail)
|
||||
+ const char *from, *to;
|
||||
+ const char *unlink_if_fail;
|
||||
+{
|
||||
+ ck_fcmove (from, to, unlink_if_fail);
|
||||
+ ck_unlink (from);
|
||||
+}
|
||||
+
|
||||
|
||||
|
||||
/* Panic on failing malloc */
|
||||
diff -Burp sed-4.1.5/lib/utils.h sed-4.1.5-f+c/lib/utils.h
|
||||
--- sed-4.1.5/lib/utils.h 2006-12-08 16:41:41.000000000 +0100
|
||||
+++ sed-4.1.5-f+c/lib/utils.h 2006-12-08 16:42:59.000000000 +0100
|
||||
@@ -31,6 +31,8 @@ size_t ck_getline P_((char **text, size_
|
||||
FILE * ck_mkstemp P_((char **p_filename, char *tmpdir, char *base));
|
||||
const char* ck_follow_symlink P_((const char * fname));
|
||||
void ck_rename P_((const char *from, const char *to, const char *unlink_if_fail));
|
||||
+void ck_fcopy P_((const char *from, const char *to, const char *unlink_if_fail));
|
||||
+void ck_fcmove P_((const char *from, const char *to, const char *unlink_if_fail));
|
||||
|
||||
VOID *ck_malloc P_((size_t size));
|
||||
VOID *xmalloc P_((size_t size));
|
||||
diff -Burp sed-4.1.5/sed/execute.c sed-4.1.5-f+c/sed/execute.c
|
||||
--- sed-4.1.5/sed/execute.c 2006-12-08 16:41:41.000000000 +0100
|
||||
+++ sed-4.1.5-f+c/sed/execute.c 2006-12-08 16:42:59.000000000 +0100
|
||||
@@ -716,12 +716,14 @@ closedown(input)
|
||||
ck_fclose (output_file.fp);
|
||||
if (strcmp(in_place_extension, "*") != 0)
|
||||
{
|
||||
- char *backup_file_name = get_backup_file_name(target_name);
|
||||
- ck_rename (target_name, backup_file_name, input->out_file_name);
|
||||
+ char *backup_file_name = get_backup_file_name(target_name);
|
||||
+ (copy_instead_of_rename?ck_fcmove:ck_rename)
|
||||
+ (target_name, backup_file_name, input->out_file_name);
|
||||
free (backup_file_name);
|
||||
}
|
||||
|
||||
- ck_rename (input->out_file_name, target_name, input->out_file_name);
|
||||
+ (copy_instead_of_rename?ck_fcopy:ck_rename)
|
||||
+ (input->out_file_name, target_name, input->out_file_name);
|
||||
free (input->out_file_name);
|
||||
free (target_name);
|
||||
}
|
||||
diff -Burp sed-4.1.5/sed/sed.c sed-4.1.5-f+c/sed/sed.c
|
||||
--- sed-4.1.5/sed/sed.c 2005-06-21 16:09:47.000000000 +0200
|
||||
+++ sed-4.1.5-f+c/sed/sed.c 2006-12-08 16:42:59.000000000 +0100
|
||||
@@ -73,6 +73,10 @@ bool separate_files = false;
|
||||
/* How do we edit files in-place? (we don't if NULL) */
|
||||
char *in_place_extension = NULL;
|
||||
|
||||
+/* Do we use copy or rename when in in-place edit mode? (boolean
|
||||
+ value, non-zero for copy, zero for rename).*/
|
||||
+int copy_instead_of_rename = 0;
|
||||
+
|
||||
/* Do we need to be pedantically POSIX compliant? */
|
||||
enum posixicity_types posixicity;
|
||||
|
||||
@@ -107,6 +111,9 @@ Usage: %s [OPTION]... {script-only-if-no
|
||||
add the contents of script-file to the commands to be executed\n"));
|
||||
fprintf(out, _(" -i[SUFFIX], --in-place[=SUFFIX]\n\
|
||||
edit files in place (makes backup if extension supplied)\n"));
|
||||
+ fprintf(out, _(" -c, --copy\n\
|
||||
+ use copy instead of rename when shuffling files in -i mode\n\
|
||||
+ (avoids change of input file ownership)\n"));
|
||||
fprintf(out, _(" -l N, --line-length=N\n\
|
||||
specify the desired line-wrap length for the `l' command\n"));
|
||||
fprintf(out, _(" --posix\n\
|
||||
@@ -142,9 +149,9 @@ main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
#ifdef REG_PERL
|
||||
-#define SHORTOPTS "snrRue:f:l:i::V:"
|
||||
+#define SHORTOPTS "csnrRue:f:l:i::V:"
|
||||
#else
|
||||
-#define SHORTOPTS "snrue:f:l:i::V:"
|
||||
+#define SHORTOPTS "csnrue:f:l:i::V:"
|
||||
#endif
|
||||
|
||||
static struct option longopts[] = {
|
||||
@@ -155,6 +162,7 @@ main(argc, argv)
|
||||
{"expression", 1, NULL, 'e'},
|
||||
{"file", 1, NULL, 'f'},
|
||||
{"in-place", 2, NULL, 'i'},
|
||||
+ {"copy", 0, NULL, 'c'},
|
||||
{"line-length", 1, NULL, 'l'},
|
||||
{"quiet", 0, NULL, 'n'},
|
||||
{"posix", 0, NULL, 'p'},
|
||||
@@ -215,6 +223,10 @@ main(argc, argv)
|
||||
the_program = compile_file(the_program, optarg);
|
||||
break;
|
||||
|
||||
+ case 'c':
|
||||
+ copy_instead_of_rename = true;
|
||||
+ break;
|
||||
+
|
||||
case 'i':
|
||||
separate_files = true;
|
||||
if (optarg == NULL)
|
||||
@@ -284,6 +296,12 @@ to the extent permitted by law.\n\
|
||||
}
|
||||
}
|
||||
|
||||
+ if (copy_instead_of_rename && in_place_extension == NULL)
|
||||
+ {
|
||||
+ fprintf (stderr, _("Error: -c used without -i.\n"));
|
||||
+ usage(4);
|
||||
+ }
|
||||
+
|
||||
if (!the_program)
|
||||
{
|
||||
if (optind < argc)
|
||||
diff -Burp sed-4.1.5/sed/sed.h sed-4.1.5-f+c/sed/sed.h
|
||||
--- sed-4.1.5/sed/sed.h 2006-12-08 16:41:41.000000000 +0100
|
||||
+++ sed-4.1.5-f+c/sed/sed.h 2006-12-08 16:42:59.000000000 +0100
|
||||
@@ -228,6 +228,10 @@ extern countT lcmd_out_line_len;
|
||||
/* How do we edit files in-place? (we don't if NULL) */
|
||||
extern char *in_place_extension;
|
||||
|
||||
+/* Do we use copy or rename when in in-place edit mode? (boolean
|
||||
+ value, non-zero for copy, zero for rename).*/
|
||||
+extern int copy_instead_of_rename;
|
||||
+
|
||||
/* Should we use EREs? */
|
||||
extern bool use_extended_syntax_p;
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
diff -Burp sed-4.1.5-orig/lib/utils.c sed-4.1.5-follow/lib/utils.c
|
||||
--- sed-4.1.5-orig/lib/utils.c 2005-06-21 16:09:40.000000000 +0200
|
||||
+++ sed-4.1.5-follow/lib/utils.c 2006-12-07 19:08:02.000000000 +0100
|
||||
@@ -35,6 +35,12 @@
|
||||
# include <stdlib.h>
|
||||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
+#include <sys/types.h>
|
||||
+#include <sys/stat.h>
|
||||
+#include <unistd.h>
|
||||
+#include <sys/sendfile.h>
|
||||
+#include <fcntl.h>
|
||||
+
|
||||
#include "utils.h"
|
||||
|
||||
const char *myname;
|
||||
@@ -315,32 +321,99 @@ do_ck_fclose(fp)
|
||||
}
|
||||
|
||||
|
||||
-/* Panic on failing rename */
|
||||
-void
|
||||
-ck_rename (from, to, unlink_if_fail)
|
||||
- const char *from, *to;
|
||||
- const char *unlink_if_fail;
|
||||
+#include <libgen.h>
|
||||
+
|
||||
+/* Follow symlink and panic if something fails. Returned value is
|
||||
+ ultimate symlink target, stored in malloc'd buffer.*/
|
||||
+const char*
|
||||
+ck_follow_symlink(const char * fname)
|
||||
{
|
||||
- int rd = rename (from, to);
|
||||
- if (rd != -1)
|
||||
- return;
|
||||
+ static struct stat statbuf;
|
||||
+ int err;
|
||||
+ char * dir;
|
||||
+
|
||||
+ static size_t bufsize = 1024;
|
||||
+ char * buf = malloc (bufsize);
|
||||
+ char * buf2 = alloca (bufsize);
|
||||
+
|
||||
+ if (strlen (fname) >= bufsize)
|
||||
+ panic("ck_follow_symlink: file name too long");
|
||||
+ strcpy (buf, fname);
|
||||
|
||||
- if (unlink_if_fail)
|
||||
+ while (1)
|
||||
{
|
||||
- int save_errno = errno;
|
||||
- errno = 0;
|
||||
- unlink (unlink_if_fail);
|
||||
+ err = lstat (buf, &statbuf);
|
||||
+
|
||||
+ if (err != 0)
|
||||
+ panic("ck_follow_symlink: couldn't lstat %s: %s", buf, strerror(errno));
|
||||
|
||||
- /* Failure to remove the temporary file is more severe, so trigger it first. */
|
||||
- if (errno != 0)
|
||||
- panic (_("cannot remove %s: %s"), unlink_if_fail, strerror (errno));
|
||||
+ if ((statbuf.st_mode & S_IFLNK) == S_IFLNK)
|
||||
+ {
|
||||
+ err = readlink (buf, buf2, bufsize);
|
||||
+
|
||||
+ if (err < 0)
|
||||
+ panic("ck_follow_symlink: readlink failed on %s: %s", buf, strerror(errno));
|
||||
+ else if (err == bufsize)
|
||||
+ panic("ck_follow_symlink: pointee name too long");
|
||||
+ else
|
||||
+ buf2 [err] = '\0';
|
||||
+
|
||||
+ /* need to handle relative paths with care */
|
||||
+ dir = dirname (buf); // dir part of orig path
|
||||
+ int len = strlen (dir); // orig path len
|
||||
+ if (buf2[0] != '/' && len != 1 && dir[0] != '.')
|
||||
+ {
|
||||
+ buf[len] = '/';
|
||||
+ strncpy (buf+len+1, buf2, bufsize - len - 1);
|
||||
+ if (buf[bufsize-1] != 0)
|
||||
+ panic("ck_follow_symlink: pointee name too long");
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ strcpy (buf, buf2);
|
||||
+ }
|
||||
+ }
|
||||
+ else
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return buf;
|
||||
+}
|
||||
|
||||
+/* Panic on failing unlink */
|
||||
+void
|
||||
+ck_unlink (name)
|
||||
+ const char *name;
|
||||
+{
|
||||
+ if (unlink (name) == -1)
|
||||
+ panic (_("cannot remove %s: %s"), name, strerror (errno));
|
||||
+}
|
||||
+
|
||||
+/* Attempt to unlink denoted file if operation rd failed. */
|
||||
+static int
|
||||
+_unlink_if_fail (rd, unlink_if_fail)
|
||||
+ int rd;
|
||||
+ const char *unlink_if_fail;
|
||||
+{
|
||||
+ if (rd == -1 && unlink_if_fail)
|
||||
+ {
|
||||
+ int save_errno = errno;
|
||||
+ ck_unlink (unlink_if_fail);
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
- panic (_("cannot rename %s: %s"), from, strerror (errno));
|
||||
+ return rd != -1;
|
||||
}
|
||||
|
||||
+/* Panic on failing rename */
|
||||
+void
|
||||
+ck_rename (from, to, unlink_if_fail)
|
||||
+ const char *from, *to;
|
||||
+ const char *unlink_if_fail;
|
||||
+{
|
||||
+ if (!_unlink_if_fail (rename (from, to), unlink_if_fail))
|
||||
+ panic (_("cannot rename %s: %s"), from, strerror (errno));
|
||||
+}
|
||||
|
||||
|
||||
|
||||
diff -Burp sed-4.1.5-orig/lib/utils.h sed-4.1.5-follow/lib/utils.h
|
||||
--- sed-4.1.5-orig/lib/utils.h 2005-06-21 16:09:40.000000000 +0200
|
||||
+++ sed-4.1.5-follow/lib/utils.h 2006-12-07 19:00:11.000000000 +0100
|
||||
@@ -29,6 +29,7 @@ void ck_fflush P_((FILE *stream));
|
||||
void ck_fclose P_((FILE *stream));
|
||||
size_t ck_getline P_((char **text, size_t *buflen, FILE *stream));
|
||||
FILE * ck_mkstemp P_((char **p_filename, char *tmpdir, char *base));
|
||||
+const char* ck_follow_symlink P_((const char * fname));
|
||||
void ck_rename P_((const char *from, const char *to, const char *unlink_if_fail));
|
||||
|
||||
VOID *ck_malloc P_((size_t size));
|
||||
--- sed-4.1.5-orig/sed/execute.c 2006-12-08 16:33:20.000000000 +0100
|
||||
+++ sed-4.1.5-follow/sed/execute.c 2006-12-07 18:53:11.000000000 +0100
|
||||
@@ -712,16 +712,18 @@
|
||||
|
||||
if (in_place_extension && output_file.fp != NULL)
|
||||
{
|
||||
+ char * target_name = ck_strdup (ck_follow_symlink (input->in_file_name));
|
||||
ck_fclose (output_file.fp);
|
||||
if (strcmp(in_place_extension, "*") != 0)
|
||||
{
|
||||
+ char *backup_file_name = get_backup_file_name(target_name);
|
||||
+ ck_rename (target_name, backup_file_name, input->out_file_name);
|
||||
- char *backup_file_name = get_backup_file_name(input->in_file_name);
|
||||
- ck_rename (input->in_file_name, backup_file_name, input->out_file_name);
|
||||
free (backup_file_name);
|
||||
}
|
||||
|
||||
+ ck_rename (input->out_file_name, target_name, input->out_file_name);
|
||||
- ck_rename (input->out_file_name, input->in_file_name, input->out_file_name);
|
||||
free (input->out_file_name);
|
||||
+ free (target_name);
|
||||
}
|
||||
|
||||
input->fp = NULL;
|
|
@ -1,113 +0,0 @@
|
|||
* looking for bonzini@gnu.org--2004b/sed--stable--4.1--patch-69 to compare with
|
||||
* comparing to bonzini@gnu.org--2004b/sed--stable--4.1--patch-69
|
||||
M sed/mbcs.c
|
||||
M sed/sed.h
|
||||
M sed/execute.c
|
||||
|
||||
* modified files
|
||||
|
||||
--- orig/sed/execute.c
|
||||
+++ mod/sed/execute.c
|
||||
@@ -235,25 +235,26 @@ str_append(to, string, length)
|
||||
to->length = new_length;
|
||||
|
||||
#ifdef HAVE_MBRTOWC
|
||||
- if (mb_cur_max == 1)
|
||||
- return;
|
||||
-
|
||||
- while (length)
|
||||
- {
|
||||
- int n = MBRLEN (string, length, &to->mbstate);
|
||||
+ if (mb_cur_max > 1 && !is_utf8)
|
||||
+ while (length)
|
||||
+ {
|
||||
+ size_t n = MBRLEN (string, length, &to->mbstate);
|
||||
|
||||
- /* An invalid sequence is treated like a singlebyte character. */
|
||||
- if (n == -1)
|
||||
- {
|
||||
- memset (&to->mbstate, 0, sizeof (to->mbstate));
|
||||
- n = 1;
|
||||
- }
|
||||
+ /* An invalid sequence is treated like a singlebyte character. */
|
||||
+ if (n == (size_t) -1)
|
||||
+ {
|
||||
+ memset (&to->mbstate, 0, sizeof (to->mbstate));
|
||||
+ n = 1;
|
||||
+ }
|
||||
|
||||
- if (n > 0)
|
||||
- length -= n;
|
||||
- else
|
||||
- break;
|
||||
- }
|
||||
+ if (n > 0)
|
||||
+ {
|
||||
+ string += n;
|
||||
+ length -= n;
|
||||
+ }
|
||||
+ else
|
||||
+ break;
|
||||
+ }
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- orig/sed/mbcs.c
|
||||
+++ mod/sed/mbcs.c
|
||||
@@ -18,7 +18,12 @@
|
||||
#include "sed.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
+#ifdef HAVE_LANGINFO_CODESET
|
||||
+#include <langinfo.h>
|
||||
+#endif
|
||||
+
|
||||
int mb_cur_max;
|
||||
+bool is_utf8;
|
||||
|
||||
#ifdef HAVE_MBRTOWC
|
||||
/* Add a byte to the multibyte character represented by the state
|
||||
@@ -47,6 +52,26 @@ int brlen (ch, cur_stat)
|
||||
void
|
||||
initialize_mbcs ()
|
||||
{
|
||||
+ /* For UTF-8, we know that the encoding is stateless. */
|
||||
+ const char *codeset_name;
|
||||
+
|
||||
+#ifdef HAVE_LANGINFO_CODESET
|
||||
+ codeset_name = nl_langinfo (CODESET);
|
||||
+#else
|
||||
+ codeset_name = getenv ("LC_ALL");
|
||||
+ if (codeset_name == NULL || codeset_name[0] == '\0')
|
||||
+ codeset_name = getenv ("LC_CTYPE");
|
||||
+ if (codeset_name == NULL || codeset_name[0] == '\0')
|
||||
+ codeset_name = getenv ("LANG");
|
||||
+ if (codeset_name == NULL)
|
||||
+ codeset_name = "";
|
||||
+ else if (strchr (codeset_name, '.') != NULL)
|
||||
+ codeset_name = strchr (codeset_name, '.') + 1;
|
||||
+#endif
|
||||
+
|
||||
+ is_utf8 = (strcasecmp (codeset_name, "UTF-8") == 0
|
||||
+ || strcasecmp (codeset_name, "UTF8") == 0);
|
||||
+
|
||||
#ifdef HAVE_MBRTOWC
|
||||
mb_cur_max = MB_CUR_MAX;
|
||||
#else
|
||||
|
||||
|
||||
--- orig/sed/sed.h
|
||||
+++ mod/sed/sed.h
|
||||
@@ -233,6 +233,7 @@ extern bool use_extended_syntax_p;
|
||||
|
||||
/* Declarations for multibyte character sets. */
|
||||
extern int mb_cur_max;
|
||||
+extern bool is_utf8;
|
||||
|
||||
#ifdef HAVE_MBRTOWC
|
||||
#ifdef HAVE_BTOWC
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,262 @@
|
|||
diff --git a/doc/sed.1 b/doc/sed.1
|
||||
index 42a0a28..bb235c8 100644
|
||||
--- a/doc/sed.1
|
||||
+++ b/doc/sed.1
|
||||
@@ -1,5 +1,5 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
|
||||
-.TH SED "1" "June 2009" "sed version 4.2.1" "User Commands"
|
||||
+.TH SED "1" "February 2010" "sed version 4.2.1" "User Commands"
|
||||
.SH NAME
|
||||
sed \- stream editor for filtering and transforming text
|
||||
.SH SYNOPSIS
|
||||
@@ -40,6 +40,10 @@ follow symlinks when processing in place
|
||||
.IP
|
||||
edit files in place (makes backup if extension supplied)
|
||||
.HP
|
||||
+\fB\-c\fR, \fB\-\-copy\fR
|
||||
+.IP
|
||||
+use copy instead of rename when shuffling files in \fB\-i\fR mode
|
||||
+.HP
|
||||
\fB\-l\fR N, \fB\-\-line\-length\fR=\fIN\fR
|
||||
.IP
|
||||
specify the desired line-wrap length for the `l' command
|
||||
diff --git a/sed/execute.c b/sed/execute.c
|
||||
index af8c4d2..c05b418 100644
|
||||
--- a/sed/execute.c
|
||||
+++ b/sed/execute.c
|
||||
@@ -822,11 +822,13 @@ closedown(input)
|
||||
if (strcmp(in_place_extension, "*") != 0)
|
||||
{
|
||||
char *backup_file_name = get_backup_file_name(target_name);
|
||||
- ck_rename (target_name, backup_file_name, input->out_file_name);
|
||||
+ (copy_instead_of_rename?ck_fcmove:ck_rename)
|
||||
+ (target_name, backup_file_name, input->out_file_name);
|
||||
free (backup_file_name);
|
||||
}
|
||||
|
||||
- ck_rename (input->out_file_name, target_name, input->out_file_name);
|
||||
+ (copy_instead_of_rename?ck_fcmove:ck_rename)
|
||||
+ (input->out_file_name, target_name, input->out_file_name);
|
||||
free (input->out_file_name);
|
||||
}
|
||||
else
|
||||
diff --git a/sed/sed.c b/sed/sed.c
|
||||
index 723958d..1fbb279 100644
|
||||
--- a/sed/sed.c
|
||||
+++ b/sed/sed.c
|
||||
@@ -75,6 +75,10 @@ bool follow_symlinks = false;
|
||||
/* How do we edit files in-place? (we don't if NULL) */
|
||||
char *in_place_extension = NULL;
|
||||
|
||||
+/* Do we use copy or rename when in in-place edit mode? (boolean
|
||||
+ value, non-zero for copy, zero for rename).*/
|
||||
+int copy_instead_of_rename = 0;
|
||||
+
|
||||
/* The mode to use to read files, either "rt" or "rb". */
|
||||
char *read_mode = "rt";
|
||||
|
||||
@@ -135,6 +139,8 @@ Usage: %s [OPTION]... {script-only-if-no-other-script} [input-file]...\n\
|
||||
#endif
|
||||
fprintf(out, _(" -i[SUFFIX], --in-place[=SUFFIX]\n\
|
||||
edit files in place (makes backup if extension supplied)\n"));
|
||||
+ fprintf(out, _(" -c, --copy\n\
|
||||
+ use copy instead of rename when shuffling files in -i mode\n"));
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(MSDOS) || defined(__EMX__)
|
||||
fprintf(out, _(" -b, --binary\n\
|
||||
open files in binary mode (CR+LFs are not processed specially)\n"));
|
||||
@@ -174,9 +180,9 @@ main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
#ifdef REG_PERL
|
||||
-#define SHORTOPTS "bsnrRuEe:f:l:i::V:"
|
||||
+#define SHORTOPTS "bcsnrRuEe:f:l:i::V:"
|
||||
#else
|
||||
-#define SHORTOPTS "bsnruEe:f:l:i::V:"
|
||||
+#define SHORTOPTS "bcsnruEe:f:l:i::V:"
|
||||
#endif
|
||||
|
||||
static struct option longopts[] = {
|
||||
@@ -188,6 +194,7 @@ main(argc, argv)
|
||||
{"expression", 1, NULL, 'e'},
|
||||
{"file", 1, NULL, 'f'},
|
||||
{"in-place", 2, NULL, 'i'},
|
||||
+ {"copy", 0, NULL, 'c'},
|
||||
{"line-length", 1, NULL, 'l'},
|
||||
{"quiet", 0, NULL, 'n'},
|
||||
{"posix", 0, NULL, 'p'},
|
||||
@@ -254,6 +261,10 @@ main(argc, argv)
|
||||
|
||||
case 'F':
|
||||
follow_symlinks = true;
|
||||
+ break;
|
||||
+
|
||||
+ case 'c':
|
||||
+ copy_instead_of_rename = true;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
@@ -334,6 +345,12 @@ to the extent permitted by law.\n\
|
||||
}
|
||||
}
|
||||
|
||||
+ if (copy_instead_of_rename && in_place_extension == NULL)
|
||||
+ {
|
||||
+ fprintf (stderr, _("Error: -c used without -i.\n"));
|
||||
+ usage(4);
|
||||
+ }
|
||||
+
|
||||
if (!the_program)
|
||||
{
|
||||
if (optind < argc)
|
||||
diff --git a/sed/sed.h b/sed/sed.h
|
||||
index 6b4101d..d4d9aa9 100644
|
||||
--- a/sed/sed.h
|
||||
+++ b/sed/sed.h
|
||||
@@ -233,6 +233,10 @@ extern countT lcmd_out_line_len;
|
||||
/* How do we edit files in-place? (we don't if NULL) */
|
||||
extern char *in_place_extension;
|
||||
|
||||
+/* Do we use copy or rename when in in-place edit mode? (boolean
|
||||
+ value, non-zero for copy, zero for rename).*/
|
||||
+extern int copy_instead_of_rename;
|
||||
+
|
||||
/* The mode to use to read files, either "rt" or "rb". */
|
||||
extern char *read_mode;
|
||||
|
||||
diff --git a/sed/utils.c b/sed/utils.c
|
||||
index 241ef1d..ebe6030 100644
|
||||
--- a/sed/utils.c
|
||||
+++ b/sed/utils.c
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
+#include <fcntl.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "pathmax.h"
|
||||
@@ -408,33 +409,99 @@ follow_symlink(const char *fname)
|
||||
return fname;
|
||||
#endif /* ENABLE_FOLLOW_SYMLINKS */
|
||||
}
|
||||
+
|
||||
|
||||
-/* Panic on failing rename */
|
||||
+/* Panic on failing unlink */
|
||||
void
|
||||
-ck_rename (from, to, unlink_if_fail)
|
||||
- const char *from, *to;
|
||||
- const char *unlink_if_fail;
|
||||
+ck_unlink (name)
|
||||
+ const char *name;
|
||||
{
|
||||
- int rd = rename (from, to);
|
||||
- if (rd != -1)
|
||||
- return;
|
||||
+ if (unlink (name) == -1)
|
||||
+ panic (_("cannot remove %s: %s"), name, strerror (errno));
|
||||
+}
|
||||
|
||||
- if (unlink_if_fail)
|
||||
+/* Attempt to unlink denoted file if operation rd failed. */
|
||||
+static int
|
||||
+_unlink_if_fail (rd, unlink_if_fail)
|
||||
+ int rd;
|
||||
+ const char *unlink_if_fail;
|
||||
+{
|
||||
+ if (rd == -1 && unlink_if_fail)
|
||||
{
|
||||
int save_errno = errno;
|
||||
+ ck_unlink (unlink_if_fail);
|
||||
+ errno = save_errno;
|
||||
+ }
|
||||
+
|
||||
+ return rd != -1;
|
||||
+}
|
||||
+
|
||||
+/* Copy contents between files. */
|
||||
+static int
|
||||
+_copy (from, to)
|
||||
+ const char *from, *to;
|
||||
+{
|
||||
+ static char buf[4096];
|
||||
+
|
||||
+ FILE *infile, *outfile;
|
||||
+ int c, retval = 0;
|
||||
errno = 0;
|
||||
- unlink (unlink_if_fail);
|
||||
|
||||
- /* Failure to remove the temporary file is more severe, so trigger it first. */
|
||||
- if (errno != 0)
|
||||
- panic (_("cannot remove %s: %s"), unlink_if_fail, strerror (errno));
|
||||
+ infile = fopen (from, "r");
|
||||
+ if (infile == NULL)
|
||||
+ return -1;
|
||||
|
||||
- errno = save_errno;
|
||||
+ outfile = fopen (to, "w");
|
||||
+ if (outfile == NULL)
|
||||
+ {
|
||||
+ fclose (infile);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ while (1)
|
||||
+ {
|
||||
+ size_t bytes_in = fread (buf, 1, sizeof (buf), infile);
|
||||
+ size_t bytes_out;
|
||||
+ if (bytes_in == 0)
|
||||
+ {
|
||||
+ if (ferror (infile))
|
||||
+ retval = -1;
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ bytes_out = fwrite (buf, 1, bytes_in, outfile);
|
||||
+ if (bytes_out != bytes_in)
|
||||
+ {
|
||||
+ retval = -1;
|
||||
+ break;
|
||||
+ }
|
||||
}
|
||||
|
||||
+ fclose (outfile);
|
||||
+ fclose (infile);
|
||||
+
|
||||
+ return retval;
|
||||
+}
|
||||
+
|
||||
+/* Panic on failing rename */
|
||||
+void
|
||||
+ck_rename (from, to, unlink_if_fail)
|
||||
+ const char *from, *to;
|
||||
+ const char *unlink_if_fail;
|
||||
+{
|
||||
+ if (!_unlink_if_fail (rename (from, to), unlink_if_fail))
|
||||
panic (_("cannot rename %s: %s"), from, strerror (errno));
|
||||
}
|
||||
|
||||
+/* Attempt to copy file contents between the files. */
|
||||
+void
|
||||
+ck_fcmove (from, to, unlink_if_fail)
|
||||
+ const char *from, *to;
|
||||
+ const char *unlink_if_fail;
|
||||
+{
|
||||
+ if (!_unlink_if_fail (_copy (from, to), unlink_if_fail))
|
||||
+ panic (_("cannot copy %s to %s: %s"), from, to, strerror (errno));
|
||||
+}
|
||||
|
||||
|
||||
|
||||
diff --git a/sed/utils.h b/sed/utils.h
|
||||
index d3f431d..b915596 100644
|
||||
--- a/sed/utils.h
|
||||
+++ b/sed/utils.h
|
||||
@@ -32,6 +32,7 @@ const char *follow_symlink P_((const char *path));
|
||||
size_t ck_getline P_((char **text, size_t *buflen, FILE *stream));
|
||||
FILE * ck_mkstemp P_((char **p_filename, char *tmpdir, char *base));
|
||||
void ck_rename P_((const char *from, const char *to, const char *unlink_if_fail));
|
||||
+void ck_fcmove P_((const char *from, const char *to, const char *unlink_if_fail));
|
||||
|
||||
VOID *ck_malloc P_((size_t size));
|
||||
VOID *xmalloc P_((size_t size));
|
|
@ -1,25 +0,0 @@
|
|||
--- sed-4.2.1/sed/sed.c 2009-06-03 21:10:51.000000000 +0200
|
||||
+++ sed-4.2.1_copy/sed/sed.c 2009-06-30 14:12:28.000000000 +0200
|
||||
@@ -174,11 +174,11 @@ main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
#ifdef REG_PERL
|
||||
-#define SHORTOPTS "bsnrRuEe:f:l:i::V:"
|
||||
+#define SHORTOPTS "cbsnrRuEe:f:l:i::V:"
|
||||
#else
|
||||
-#define SHORTOPTS "bsnruEe:f:l:i::V:"
|
||||
+#define SHORTOPTS "cbsnruEe:f:l:i::V:"
|
||||
#endif
|
||||
-
|
||||
+/* -c --copy is just a dummy param to keep backward compatibility */
|
||||
static struct option longopts[] = {
|
||||
{"binary", 0, NULL, 'b'},
|
||||
{"regexp-extended", 0, NULL, 'r'},
|
||||
@@ -196,6 +196,7 @@ main(argc, argv)
|
||||
{"unbuffered", 0, NULL, 'u'},
|
||||
{"version", 0, NULL, 'v'},
|
||||
{"help", 0, NULL, 'h'},
|
||||
+ {"copy", 0, NULL, 'c'},
|
||||
#ifdef ENABLE_FOLLOW_SYMLINKS
|
||||
{"follow-symlinks", 0, NULL, 'F'},
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
diff --git a/ChangeLog b/ChangeLog
|
||||
index 06956a7..30d9fca 100644
|
||||
--- a/ChangeLog
|
||||
+++ b/ChangeLog
|
||||
@@ -1,3 +1,7 @@
|
||||
+2009-10-14 Yuri G. Kudryashov <urkud.urkud@gmail.com> (tiny change)
|
||||
+
|
||||
+ * testsuite/Makefile.tests: Override LC_ALL, not LANG.
|
||||
+
|
||||
2009-06-27 Paolo Bonzini <bonzini@gnu.org>
|
||||
|
||||
* configure.ac: Bump version.
|
||||
diff --git a/testsuite/Makefile.tests b/testsuite/Makefile.tests
|
||||
index 1f04290..c0910dc 100644
|
||||
--- a/testsuite/Makefile.tests
|
||||
+++ b/testsuite/Makefile.tests
|
||||
@@ -34,16 +34,16 @@ y-bracket y-newline insert brackets::
|
||||
@$(RM) $@.out
|
||||
|
||||
badenc::
|
||||
- LANG=ru_RU.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
+ LC_ALL=ru_RU.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
|
||||
$(CMP) $(srcdir)/$@.good $@.out
|
||||
- LANG=it_IT.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
+ LC_ALL=it_IT.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
|
||||
$(CMP) $(srcdir)/$@.good $@.out
|
||||
- LANG=en_US.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
+ LC_ALL=en_US.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
|
||||
$(CMP) $(srcdir)/$@.good $@.out
|
||||
- LANG=en_GB.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
+ LC_ALL=en_GB.UTF-8 $(TIME) $(SED) -nf $(srcdir)/$@.sed \
|
||||
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out
|
||||
$(CMP) $(srcdir)/$@.good $@.out
|
||||
@$(RM) $@.out
|
||||
@@ -51,10 +51,10 @@ badenc::
|
||||
# Try with ru_RU.UTF-8. If it is presumably not installed, see if the current
|
||||
# locale is UTF-8 and run it in the current locale.
|
||||
utf8-1 utf8-2 utf8-3 utf8-4::
|
||||
- echo "LANG=ru_RU.UTF-8" \
|
||||
+ echo "LC_ALL=ru_RU.UTF-8" \
|
||||
"$(TIME) $(SED) -f $(srcdir)/$@.sed" \
|
||||
"< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out"; \
|
||||
- LANG=ru_RU.UTF-8 \
|
||||
+ LC_ALL=ru_RU.UTF-8 \
|
||||
$(TIME) $(SED) -f $(srcdir)/$@.sed \
|
||||
< $(srcdir)/$@.inp | $(TR) -d \\r > $@.out; \
|
||||
$(CMP) $(srcdir)/$@.good $@.out && exit 0; \
|
26
sed.spec
26
sed.spec
|
@ -6,15 +6,16 @@
|
|||
Summary: A GNU stream text editor
|
||||
Name: sed
|
||||
Version: 4.2.1
|
||||
Release: 3%{?dist}
|
||||
License: GPLv2+
|
||||
Release: 5%{?dist}
|
||||
License: GPLv3+
|
||||
Group: Applications/Text
|
||||
URL: http://sed.sourceforge.net/
|
||||
Source0: ftp://ftp.gnu.org/pub/gnu/sed/sed-%{version}.tar.bz2
|
||||
Source1: http://sed.sourceforge.net/sedfaq.txt
|
||||
Patch0: sed-4.2.1-dummyparam.diff
|
||||
Patch0: sed-4.2.1-copy.patch
|
||||
Patch1: sed-4.2.1-makecheck.patch
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
BuildRequires: glibc-devel
|
||||
BuildRequires: glibc-devel, libselinux-devel
|
||||
Requires(post): /sbin/install-info
|
||||
Requires(preun): /sbin/install-info
|
||||
|
||||
|
@ -28,6 +29,7 @@ specified in a script file or from the command line.
|
|||
%prep
|
||||
%setup -q
|
||||
%patch0 -p1
|
||||
%patch1 -p1
|
||||
|
||||
%build
|
||||
%configure --without-included-regex
|
||||
|
@ -48,12 +50,14 @@ rm -f ${RPM_BUILD_ROOT}/%{_infodir}/dir
|
|||
%find_lang %{name}
|
||||
|
||||
%post
|
||||
/sbin/install-info %{_infodir}/sed.info.gz %{_infodir}/dir || :
|
||||
/sbin/install-info %{_infodir}/sed.info.gz %{_infodir}/dir || &> /dev/null
|
||||
:
|
||||
|
||||
%preun
|
||||
if [ $1 = 0 ]; then
|
||||
/sbin/install-info --delete %{_infodir}/sed.info.gz %{_infodir}/dir || :
|
||||
/sbin/install-info --delete %{_infodir}/sed.info.gz %{_infodir}/dir || &> /dev/null
|
||||
fi
|
||||
:
|
||||
|
||||
%clean
|
||||
rm -rf ${RPM_BUILD_ROOT}
|
||||
|
@ -66,6 +70,16 @@ rm -rf ${RPM_BUILD_ROOT}
|
|||
%{_mandir}/man*/*
|
||||
|
||||
%changelog
|
||||
* Wed Mar 17 2010 Jan Görig <jgorig@redhat.com> 4.2.1-5
|
||||
- fixed make check on non UTF-8 locale - upstream patch rhbz#550731
|
||||
- readded -c option (thanks Paolo Bonzini) rhbz#566455
|
||||
- removed previous -c dummy patch
|
||||
- changed license to GPLv3+
|
||||
|
||||
* Fri Oct 16 2009 Jiri Moskovcak <jmoskovc@redhat.com> 4.2.1-4
|
||||
- added libselinux-devel to buildrequires rhbz#514182
|
||||
- fixed problem with --excludedocs rhbz#515913
|
||||
|
||||
* Tue Aug 11 2009 Ville Skyttä <ville.skytta@iki.fi> - 4.2.1-3
|
||||
- Use bzipped upstream tarball.
|
||||
|
||||
|
|
Loading…
Reference in New Issue