SOURCES: sed-copy.patch (NEW), sed-follow.patch (NEW), sed-utf8performance....
arekm
arekm at pld-linux.org
Mon Nov 10 20:51:00 CET 2008
Author: arekm Date: Mon Nov 10 19:51:00 2008 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- from fedora
---- Files affected:
SOURCES:
sed-copy.patch (NONE -> 1.1) (NEW), sed-follow.patch (NONE -> 1.1) (NEW), sed-utf8performance.patch (NONE -> 1.1) (NEW)
---- Diffs:
================================================================
Index: SOURCES/sed-copy.patch
diff -u /dev/null SOURCES/sed-copy.patch:1.1
--- /dev/null Mon Nov 10 20:51:01 2008
+++ SOURCES/sed-copy.patch Mon Nov 10 20:50:54 2008
@@ -0,0 +1,223 @@
+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;
+
================================================================
Index: SOURCES/sed-follow.patch
diff -u /dev/null SOURCES/sed-follow.patch:1.1
--- /dev/null Mon Nov 10 20:51:01 2008
+++ SOURCES/sed-follow.patch Mon Nov 10 20:50:54 2008
@@ -0,0 +1,167 @@
+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 */
++ if (buf2[0] != '/')
++ {
++ dir = dirname (buf); // dir part of orig path
++ int len = strlen (dir); // orig path len
++ 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;
================================================================
Index: SOURCES/sed-utf8performance.patch
diff -u /dev/null SOURCES/sed-utf8performance.patch:1.1
--- /dev/null Mon Nov 10 20:51:02 2008
+++ SOURCES/sed-utf8performance.patch Mon Nov 10 20:50:55 2008
@@ -0,0 +1,113 @@
+* looking for bonzini at gnu.org--2004b/sed--stable--4.1--patch-69 to compare with
+* comparing to bonzini at 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
+
+
+
================================================================
More information about the pld-cvs-commit
mailing list