summaryrefslogtreecommitdiff
path: root/sed
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2007-01-13 14:00:04 +0000
committerPaolo Bonzini <bonzini@gnu.org>2008-01-09 16:12:25 +0100
commit068afd076e5b48599772616ddd4a3496ac6778ba (patch)
treef8403588fa051f81d72739e6dcdde123b1374c8e /sed
parent318f4cd2470bd13a17c2f021406b39e12adf097e (diff)
downloadsed-068afd076e5b48599772616ddd4a3496ac6778ba.tar.gz
bump version to 4.1c and fix some warningsv4.1c
2006-12-29 Paolo Bonzini <bonzini@gnu.org> * sed/compile.c: Fix warnings. * sed/execute.c: Fix warnings. git-archimport-id: bonzini@gnu.org--2004b/sed--stable--4.1--patch-91
Diffstat (limited to 'sed')
-rw-r--r--sed/Makefile.am2
-rw-r--r--sed/compile.c2
-rw-r--r--sed/execute.c191
-rw-r--r--sed/utils.c4
4 files changed, 97 insertions, 102 deletions
diff --git a/sed/Makefile.am b/sed/Makefile.am
index f3486b7..34ddd52 100644
--- a/sed/Makefile.am
+++ b/sed/Makefile.am
@@ -10,7 +10,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/intl \
-I$(top_srcdir) -I$(top_builddir)/lib \
-I$(top_builddir)/intl -DLOCALEDIR=\"$(localedir)\"
-sed_LDADD = ../lib/libsed.a @INTLLIBS@ @LIB_ACL@
+sed_LDADD = @INTLLIBS@ @LIB_ACL@ ../lib/libsed.a
sed_DEPENDENCIES = ../lib/libsed.a
$(PROGRAMS): $(LDADD)
diff --git a/sed/compile.c b/sed/compile.c
index a7f0307..20a0523 100644
--- a/sed/compile.c
+++ b/sed/compile.c
@@ -384,7 +384,6 @@ get_openfile(file_ptrs, mode, fail)
struct buffer *b;
char *file_name;
struct output *p;
- int is_stderr;
b = read_filename();
file_name = get_buffer(b);
@@ -1581,7 +1580,6 @@ compile_file(cur_program, cmdfile)
struct vector *cur_program;
const char *cmdfile;
{
- size_t len;
struct vector *ret;
prog.file = stdin;
diff --git a/sed/execute.c b/sed/execute.c
index 469242b..10c78f3 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -35,6 +35,8 @@ extern int errno;
# include <unistd.h>
#endif
+#include "acl.h"
+
#ifdef __GNUC__
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__-0 >= 7)
/* silence warning about unused parameter even for "gcc -W -Wunused" */
@@ -269,81 +271,76 @@ str_append_modified(to, string, length, type)
size_t length;
enum replacement_types type;
{
- size_t old_length = to->length;
- char *start, *end;
-
- if (length == 0)
- return;
-
#ifdef HAVE_MBRTOWC
- {
- mbstate_t from_stat;
+ mbstate_t from_stat;
- if (type == REPL_ASIS)
- {
- str_append(to, string, length);
- return;
- }
+ if (type == REPL_ASIS)
+ {
+ str_append(to, string, length);
+ return;
+ }
- if (to->alloc - to->length < length * mb_cur_max)
- resize_line(to, to->length + length * mb_cur_max);
+ if (to->alloc - to->length < length * mb_cur_max)
+ resize_line(to, to->length + length * mb_cur_max);
- MEMCPY (&from_stat, &to->mbstate, sizeof(mbstate_t));
- while (length)
- {
- wchar_t wc;
- int n = MBRTOWC (&wc, string, length, &from_stat);
+ MEMCPY (&from_stat, &to->mbstate, sizeof(mbstate_t));
+ while (length)
+ {
+ wchar_t wc;
+ int n = MBRTOWC (&wc, string, length, &from_stat);
- /* An invalid sequence is treated like a singlebyte character. */
- if (n == -1)
- {
- memset (&to->mbstate, 0, sizeof (from_stat));
- n = 1;
- }
+ /* An invalid sequence is treated like a singlebyte character. */
+ if (n == -1)
+ {
+ memset (&to->mbstate, 0, sizeof (from_stat));
+ n = 1;
+ }
- if (n > 0)
- string += n, length -= n;
- else
- {
- /* Incomplete sequence, copy it manually. */
- str_append(to, string, length);
- return;
- }
+ if (n > 0)
+ string += n, length -= n;
+ else
+ {
+ /* Incomplete sequence, copy it manually. */
+ str_append(to, string, length);
+ return;
+ }
- /* Convert the first character specially... */
- if (type & (REPL_UPPERCASE_FIRST | REPL_LOWERCASE_FIRST))
- {
- if (type & REPL_UPPERCASE_FIRST)
- wc = towupper(wc);
- else
- wc = towlower(wc);
+ /* Convert the first character specially... */
+ if (type & (REPL_UPPERCASE_FIRST | REPL_LOWERCASE_FIRST))
+ {
+ if (type & REPL_UPPERCASE_FIRST)
+ wc = towupper(wc);
+ else
+ wc = towlower(wc);
- type &= ~(REPL_LOWERCASE_FIRST | REPL_UPPERCASE_FIRST);
- if (type == REPL_ASIS)
- {
- n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
- to->length += n;
- str_append(to, string, length);
- return;
- }
- }
+ type &= ~(REPL_LOWERCASE_FIRST | REPL_UPPERCASE_FIRST);
+ if (type == REPL_ASIS)
+ {
+ n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
+ to->length += n;
+ str_append(to, string, length);
+ return;
+ }
+ }
- else if (type & REPL_UPPERCASE)
- wc = towupper(wc);
- else
- wc = towlower(wc);
+ else if (type & REPL_UPPERCASE)
+ wc = towupper(wc);
+ else
+ wc = towlower(wc);
- /* Copy the new wide character to the end of the string. */
- n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
- to->length += n;
- if (n == -1)
- {
- fprintf (stderr, "Case conversion produced an invalid character!");
- abort ();
- }
- }
- }
+ /* Copy the new wide character to the end of the string. */
+ n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
+ to->length += n;
+ if (n == -1)
+ {
+ fprintf (stderr, "Case conversion produced an invalid character!");
+ abort ();
+ }
+ }
#else
+ size_t old_length = to->length;
+ char *start, *end;
+
str_append(to, string, length);
start = to->active + old_length;
end = start + length;
@@ -1102,16 +1099,18 @@ append_replacement (buf, p, regs, repl_mod)
}
if (0 <= i)
- if (regs->end[i] == regs->start[i] && p->repl_type & REPL_MODIFIERS)
- /* Save this modifier, we shall apply it later.
- e.g. in s/()([a-z])/\u\1\2/
- the \u modifier is applied to \2, not \1 */
- repl_mod = curr_type & REPL_MODIFIERS;
-
- else
- str_append_modified(buf, line.active + regs->start[i],
- CAST(size_t)(regs->end[i] - regs->start[i]),
- curr_type);
+ {
+ if (regs->end[i] == regs->start[i] && p->repl_type & REPL_MODIFIERS)
+ /* Save this modifier, we shall apply it later.
+ e.g. in s/()([a-z])/\u\1\2/
+ the \u modifier is applied to \2, not \1 */
+ repl_mod = curr_type & REPL_MODIFIERS;
+
+ else if (regs->end[i] != regs->start[i])
+ str_append_modified(buf, line.active + regs->start[i],
+ CAST(size_t)(regs->end[i] - regs->start[i]),
+ curr_type);
+ }
}
return repl_mod;
@@ -1138,24 +1137,26 @@ do_subst(sub)
return;
if (!sub->replacement && sub->numb <= 1)
- if (regs.start[0] == 0 && !sub->global)
- {
- /* We found a match, set the `replaced' flag. */
- replaced = true;
+ {
+ if (regs.start[0] == 0 && !sub->global)
+ {
+ /* We found a match, set the `replaced' flag. */
+ replaced = true;
- line.active += regs.end[0];
- line.length -= regs.end[0];
- line.alloc -= regs.end[0];
- goto post_subst;
- }
- else if (regs.end[0] == line.length)
- {
- /* We found a match, set the `replaced' flag. */
- replaced = true;
+ line.active += regs.end[0];
+ line.length -= regs.end[0];
+ line.alloc -= regs.end[0];
+ goto post_subst;
+ }
+ else if (regs.end[0] == line.length)
+ {
+ /* We found a match, set the `replaced' flag. */
+ replaced = true;
- line.length = regs.start[0];
- goto post_subst;
- }
+ line.length = regs.start[0];
+ goto post_subst;
+ }
+ }
do
{
@@ -1411,16 +1412,16 @@ execute_program(vec, input)
if (pipe != NULL)
{
+ char buf[4096];
+ int n;
while (!feof (pipe))
- {
- char buf[4096];
- int n = fread (buf, sizeof(char), 4096, pipe);
- if (n > 0)
+ if ((n = fread (buf, sizeof(char), 4096, pipe)) > 0)
+ {
if (!cmd_length)
str_append(&s_accum, buf, n);
else
ck_fwrite(buf, 1, n, output_file.fp);
- }
+ }
pclose (pipe);
if (!cmd_length)
diff --git a/sed/utils.c b/sed/utils.c
index 82c4c1e..9e9ec51 100644
--- a/sed/utils.c
+++ b/sed/utils.c
@@ -189,7 +189,6 @@ ck_fdopen(fd, name, mode, fail)
bool fail;
{
FILE *fp;
- struct open_file *p;
fp = fdopen (fd, mode);
if (!fp)
@@ -212,7 +211,6 @@ ck_mkstemp (p_filename, tmpdir, base)
char *template;
FILE *fp;
int fd;
- struct open_file *p;
if (tmpdir == NULL)
tmpdir = getenv("TMPDIR");
@@ -338,11 +336,9 @@ void
do_ck_fclose(fp)
FILE *fp;
{
- int fd;
ck_fflush(fp);
clearerr(fp);
- /* We want to execute both arms, so use | not ||. */
if (fclose(fp) == EOF)
panic("couldn't close %s: %s", utils_fp_name(fp), strerror(errno));
}