summaryrefslogtreecommitdiff
path: root/sed
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2014-10-10 22:03:11 -0700
committerJim Meyering <meyering@fb.com>2014-11-30 18:59:35 -0800
commite48ca0d39c2734330cafb8c6fef4ea7cea56b23e (patch)
tree5d0becfbc6eaa60774a990ea10e401e2ca383e10 /sed
parent8d5fa64778161a6bbccb8a80478849467003cabd (diff)
downloadsed-e48ca0d39c2734330cafb8c6fef4ea7cea56b23e.tar.gz
maint: enable sc_prohibit_tab_based_indentation syntax check
* cfg.mk (local-checks-to-skip): Remove its exemption. Exempt all files under testsuite/, for now, and a few others. * .gitmodules: Change each leading TAB to 8 spaces spaces. * BUGS: Likewise. * NEWS: Likewise. * configure.ac: Likewise. * sed/compile.c: Likewise. * sed/execute.c: Likewise. * sed/fmt.c: Likewise. * sed/regexp.c: Likewise. * sed/sed.c: Likewise. * sed/sed.h: Likewise. * sed/utils.c: Likewise. * sed/utils.h: Likewise. * COPYING: Update from coreutils.
Diffstat (limited to 'sed')
-rw-r--r--sed/compile.c1212
-rw-r--r--sed/execute.c1024
-rw-r--r--sed/fmt.c92
-rw-r--r--sed/regexp.c22
-rw-r--r--sed/sed.c160
-rw-r--r--sed/sed.h4
-rw-r--r--sed/utils.c88
-rw-r--r--sed/utils.h2
8 files changed, 1302 insertions, 1302 deletions
diff --git a/sed/compile.c b/sed/compile.c
index 07e3837..77aec27 100644
--- a/sed/compile.c
+++ b/sed/compile.c
@@ -191,13 +191,13 @@ bad_prog(why)
{
if (cur_input.name)
fprintf(stderr, _("%s: file %s line %lu: %s\n"),
- myname, cur_input.name, (unsigned long)cur_input.line, why);
+ myname, cur_input.name, (unsigned long)cur_input.line, why);
else
fprintf(stderr, _("%s: -e expression #%lu, char %lu: %s\n"),
- myname,
- (unsigned long)cur_input.string_expr_count,
- (unsigned long)(prog.cur-prog.base),
- why);
+ myname,
+ (unsigned long)cur_input.string_expr_count,
+ (unsigned long)(prog.cur-prog.base),
+ why);
exit(EXIT_FAILURE);
}
@@ -214,12 +214,12 @@ inchar()
if (prog.cur)
{
if (prog.cur < prog.end)
- ch = *prog.cur++;
+ ch = *prog.cur++;
}
else if (prog.file)
{
if (!feof(prog.file))
- ch = getc(prog.file);
+ ch = getc(prog.file);
}
if (ch == '\n')
++cur_input.line;
@@ -239,8 +239,8 @@ savchar(ch)
if (prog.cur)
{
if (prog.cur <= prog.base || *--prog.cur != ch)
- panic("Called savchar() with unexpected pushback (%x)",
- (unsigned char)ch);
+ panic("Called savchar() with unexpected pushback (%x)",
+ (unsigned char)ch);
}
else
ungetc(ch, prog.file);
@@ -301,26 +301,26 @@ convert_number(result, buf, bufend, base)
{
int d = -1;
switch (*p)
- {
- case '0': d = 0x0; break;
- case '1': d = 0x1; break;
- case '2': d = 0x2; break;
- case '3': d = 0x3; break;
- case '4': d = 0x4; break;
- case '5': d = 0x5; break;
- case '6': d = 0x6; break;
- case '7': d = 0x7; break;
- case '8': d = 0x8; break;
- case '9': d = 0x9; break;
- case 'A': case 'a': d = 0xa; break;
- case 'B': case 'b': d = 0xb; break;
- case 'C': case 'c': d = 0xc; break;
- case 'D': case 'd': d = 0xd; break;
- case 'E': case 'e': d = 0xe; break;
- case 'F': case 'f': d = 0xf; break;
- }
+ {
+ case '0': d = 0x0; break;
+ case '1': d = 0x1; break;
+ case '2': d = 0x2; break;
+ case '3': d = 0x3; break;
+ case '4': d = 0x4; break;
+ case '5': d = 0x5; break;
+ case '6': d = 0x6; break;
+ case '7': d = 0x7; break;
+ case '8': d = 0x8; break;
+ case '9': d = 0x9; break;
+ case 'A': case 'a': d = 0xa; break;
+ case 'B': case 'b': d = 0xb; break;
+ case 'C': case 'c': d = 0xc; break;
+ case 'D': case 'd': d = 0xd; break;
+ case 'E': case 'e': d = 0xe; break;
+ case 'F': case 'f': d = 0xf; break;
+ }
if (d < 0 || base <= d)
- break;
+ break;
n = n * base + d;
}
if (p == buf+1)
@@ -345,11 +345,11 @@ read_filename()
{
#if 0 /*XXX ZZZ 1998-09-12 kpp: added, then had second thoughts*/
if (posixicity == POSIXLY_EXTENDED)
- if (ch == ';' || ch == '#')
- {
- savchar(ch);
- break;
- }
+ if (ch == ';' || ch == '#')
+ {
+ savchar(ch);
+ break;
+ }
#endif
ch = add_then_next(b, ch);
}
@@ -385,9 +385,9 @@ get_openfile(file_ptrs, mode, fail)
for (special = special_files; special->outf.name; special++)
if (strcmp(special->outf.name, file_name) == 0)
{
- special->outf.fp = *special->pfp;
- free_buffer (b);
- return &special->outf;
+ special->outf.fp = *special->pfp;
+ free_buffer (b);
+ return &special->outf;
}
}
@@ -449,61 +449,61 @@ snarf_char_class(b, cur_stat)
ch = add_then_next(b, ch);
/* States are:
- 0 outside a collation element, character class or collation class
- 1 after the bracket
- 2 after the opening ./:/=
- 3 after the closing ./:/= */
+ 0 outside a collation element, character class or collation class
+ 1 after the bracket
+ 2 after the opening ./:/=
+ 3 after the closing ./:/= */
for (;; ch = add_then_next (b, ch))
{
pending_mb = BRLEN (ch, cur_stat) != 1;
switch (ch)
- {
- case EOF:
- case '\n':
- return ch;
-
- case '.':
- case ':':
- case '=':
- if (pending_mb)
- continue;
-
- if (state == 1)
- {
- delim = ch;
- state = 2;
- }
- else if (state == 2 && ch == delim)
- state = 3;
- else
- break;
-
- continue;
-
- case OPEN_BRACKET:
- if (pending_mb)
- continue;
-
- if (state == 0)
- state = 1;
- continue;
-
- case CLOSE_BRACKET:
- if (pending_mb)
- continue;
-
- if (state == 0 || state == 1)
- return ch;
- else if (state == 3)
- state = 0;
-
- break;
-
- default:
- break;
- }
+ {
+ case EOF:
+ case '\n':
+ return ch;
+
+ case '.':
+ case ':':
+ case '=':
+ if (pending_mb)
+ continue;
+
+ if (state == 1)
+ {
+ delim = ch;
+ state = 2;
+ }
+ else if (state == 2 && ch == delim)
+ state = 3;
+ else
+ break;
+
+ continue;
+
+ case OPEN_BRACKET:
+ if (pending_mb)
+ continue;
+
+ if (state == 0)
+ state = 1;
+ continue;
+
+ case CLOSE_BRACKET:
+ if (pending_mb)
+ continue;
+
+ if (state == 0 || state == 1)
+ return ch;
+ else if (state == 3)
+ state = 0;
+
+ break;
+
+ default:
+ break;
+ }
/* Getting a character different from .=: whilst in state 1
goes back to state 0, getting a character different from ]
@@ -535,29 +535,29 @@ match_slash(slash, regex)
{
bool pending_mb = !MBSINIT (&cur_stat);
if (BRLEN (ch, &cur_stat) == 1 && !pending_mb)
- {
- if (ch == slash)
- return b;
- else if (ch == '\\')
- {
- ch = inchar();
- if (ch == EOF)
- break;
+ {
+ if (ch == slash)
+ return b;
+ else if (ch == '\\')
+ {
+ ch = inchar();
+ if (ch == EOF)
+ break;
#ifndef REG_PERL
- else if (ch == 'n' && regex)
- ch = '\n';
+ else if (ch == 'n' && regex)
+ ch = '\n';
#endif
- else if (ch != '\n' && (ch != slash || (!regex && ch == '&')))
- add1_buffer(b, '\\');
- }
+ else if (ch != '\n' && (ch != slash || (!regex && ch == '&')))
+ add1_buffer(b, '\\');
+ }
else if (ch == OPEN_BRACKET && regex)
- {
- add1_buffer(b, ch);
- ch = snarf_char_class(b, &cur_stat);
- if (ch != CLOSE_BRACKET)
- break;
- }
- }
+ {
+ add1_buffer(b, ch);
+ ch = snarf_char_class(b, &cur_stat);
+ if (ch != CLOSE_BRACKET)
+ break;
+ }
+ }
add1_buffer(b, ch);
}
@@ -587,82 +587,82 @@ mark_subst_opts(cmd)
{
case 'i': /* GNU extension */
case 'I': /* GNU extension */
- if (posixicity == POSIXLY_BASIC)
- bad_prog(_(UNKNOWN_S_OPT));
- flags |= REG_ICASE;
- break;
+ if (posixicity == POSIXLY_BASIC)
+ bad_prog(_(UNKNOWN_S_OPT));
+ flags |= REG_ICASE;
+ break;
#ifdef REG_PERL
case 's': /* GNU extension */
case 'S': /* GNU extension */
- if (posixicity == POSIXLY_BASIC)
- bad_prog(_(UNKNOWN_S_OPT));
- if (extended_regexp_flags & REG_PERL)
- flags |= REG_DOTALL;
- break;
+ if (posixicity == POSIXLY_BASIC)
+ bad_prog(_(UNKNOWN_S_OPT));
+ if (extended_regexp_flags & REG_PERL)
+ flags |= REG_DOTALL;
+ break;
case 'x': /* GNU extension */
case 'X': /* GNU extension */
- if (posixicity == POSIXLY_BASIC)
- bad_prog(_(UNKNOWN_S_OPT));
- if (extended_regexp_flags & REG_PERL)
- flags |= REG_EXTENDED;
- break;
+ if (posixicity == POSIXLY_BASIC)
+ bad_prog(_(UNKNOWN_S_OPT));
+ if (extended_regexp_flags & REG_PERL)
+ flags |= REG_EXTENDED;
+ break;
#endif
case 'm': /* GNU extension */
case 'M': /* GNU extension */
- if (posixicity == POSIXLY_BASIC)
- bad_prog(_(UNKNOWN_S_OPT));
- flags |= REG_NEWLINE;
- break;
+ if (posixicity == POSIXLY_BASIC)
+ bad_prog(_(UNKNOWN_S_OPT));
+ flags |= REG_NEWLINE;
+ break;
case 'e':
- cmd->eval = true;
- break;
+ cmd->eval = true;
+ break;
case 'p':
- if (cmd->print)
- bad_prog(_(EXCESS_P_OPT));
- cmd->print |= (1 << cmd->eval); /* 1=before eval, 2=after */
- break;
+ if (cmd->print)
+ bad_prog(_(EXCESS_P_OPT));
+ cmd->print |= (1 << cmd->eval); /* 1=before eval, 2=after */
+ break;
case 'g':
- if (cmd->global)
- bad_prog(_(EXCESS_G_OPT));
- cmd->global = true;
- break;
+ if (cmd->global)
+ bad_prog(_(EXCESS_G_OPT));
+ cmd->global = true;
+ break;
case 'w':
- cmd->outf = get_openfile(&file_write, write_mode, true);
- return flags;
+ cmd->outf = get_openfile(&file_write, write_mode, true);
+ return flags;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
- if (cmd->numb)
- bad_prog(_(EXCESS_N_OPT));
- cmd->numb = in_integer(ch);
- if (!cmd->numb)
- bad_prog(_(ZERO_N_OPT));
- break;
+ if (cmd->numb)
+ bad_prog(_(EXCESS_N_OPT));
+ cmd->numb = in_integer(ch);
+ if (!cmd->numb)
+ bad_prog(_(ZERO_N_OPT));
+ break;
case CLOSE_BRACE:
case '#':
- savchar(ch);
- /* Fall Through */
+ savchar(ch);
+ /* Fall Through */
case EOF:
case '\n':
case ';':
- return flags;
+ return flags;
case '\r':
- if (inchar() == '\n')
- return flags;
- /* FALLTHROUGH */
+ if (inchar() == '\n')
+ return flags;
+ /* FALLTHROUGH */
default:
- bad_prog(_(UNKNOWN_S_OPT));
- /*NOTREACHED*/
+ bad_prog(_(UNKNOWN_S_OPT));
+ /*NOTREACHED*/
}
}
@@ -680,7 +680,7 @@ read_label()
ch = in_nonblank();
while (ch != EOF && ch != '\n'
- && !ISBLANK(ch) && ch != ';' && ch != CLOSE_BRACE && ch != '#')
+ && !ISBLANK(ch) && ch != ';' && ch != CLOSE_BRACE && ch != '#')
ch = add_then_next (b, ch);
savchar(ch);
@@ -770,77 +770,77 @@ setup_replacement(sub, text, length)
for (p=base; p<text_end; ++p)
{
if (*p == '\\')
- {
- /* Preceding the backslash may be some literal text: */
- tail = tail->next =
- new_replacement(base, (size_t)(p - base), repl_type);
-
- repl_type = save_type;
-
- /* Skip the backslash and look for a numeric back-reference,
- or a case-munging escape if not in POSIX mode: */
- ++p;
- if (p == text_end)
- ++tail->prefix_length;
-
- else if (posixicity == POSIXLY_BASIC && !ISDIGIT (*p))
- {
- p[-1] = *p;
- ++tail->prefix_length;
- }
-
- else
- switch (*p)
- {
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- tail->subst_id = *p - '0';
- if (sub->max_id < tail->subst_id)
- sub->max_id = tail->subst_id;
- break;
-
- case 'L':
- repl_type = REPL_LOWERCASE;
- save_type = REPL_LOWERCASE;
- break;
-
- case 'U':
- repl_type = REPL_UPPERCASE;
- save_type = REPL_UPPERCASE;
- break;
-
- case 'E':
- repl_type = REPL_ASIS;
- save_type = REPL_ASIS;
- break;
-
- case 'l':
- save_type = repl_type;
- repl_type |= REPL_LOWERCASE_FIRST;
- break;
-
- case 'u':
- save_type = repl_type;
- repl_type |= REPL_UPPERCASE_FIRST;
- break;
-
- default:
- p[-1] = *p;
- ++tail->prefix_length;
- }
-
- base = p + 1;
- }
+ {
+ /* Preceding the backslash may be some literal text: */
+ tail = tail->next =
+ new_replacement(base, (size_t)(p - base), repl_type);
+
+ repl_type = save_type;
+
+ /* Skip the backslash and look for a numeric back-reference,
+ or a case-munging escape if not in POSIX mode: */
+ ++p;
+ if (p == text_end)
+ ++tail->prefix_length;
+
+ else if (posixicity == POSIXLY_BASIC && !ISDIGIT (*p))
+ {
+ p[-1] = *p;
+ ++tail->prefix_length;
+ }
+
+ else
+ switch (*p)
+ {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ tail->subst_id = *p - '0';
+ if (sub->max_id < tail->subst_id)
+ sub->max_id = tail->subst_id;
+ break;
+
+ case 'L':
+ repl_type = REPL_LOWERCASE;
+ save_type = REPL_LOWERCASE;
+ break;
+
+ case 'U':
+ repl_type = REPL_UPPERCASE;
+ save_type = REPL_UPPERCASE;
+ break;
+
+ case 'E':
+ repl_type = REPL_ASIS;
+ save_type = REPL_ASIS;
+ break;
+
+ case 'l':
+ save_type = repl_type;
+ repl_type |= REPL_LOWERCASE_FIRST;
+ break;
+
+ case 'u':
+ save_type = repl_type;
+ repl_type |= REPL_UPPERCASE_FIRST;
+ break;
+
+ default:
+ p[-1] = *p;
+ ++tail->prefix_length;
+ }
+
+ base = p + 1;
+ }
else if (*p == '&')
- {
- /* Preceding the ampersand may be some literal text: */
- tail = tail->next =
- new_replacement(base, (size_t)(p - base), repl_type);
-
- repl_type = save_type;
- tail->subst_id = 0;
- base = p + 1;
- }
+ {
+ /* Preceding the ampersand may be some literal text: */
+ tail = tail->next =
+ new_replacement(base, (size_t)(p - base), repl_type);
+
+ repl_type = save_type;
+ tail->subst_id = 0;
+ base = p + 1;
+ }
}
/* There may be some trailing literal text: */
if (base < text_end)
@@ -863,7 +863,7 @@ read_text(buf, leadin_ch)
if (buf)
{
if (pending_text)
- free_buffer(pending_text);
+ free_buffer(pending_text);
pending_text = init_buffer();
buf->text = NULL;
buf->text_length = 0;
@@ -881,17 +881,17 @@ read_text(buf, leadin_ch)
while (ch != EOF && ch != '\n')
{
if (ch == '\\')
- {
- ch = inchar();
- if (ch != EOF)
- add1_buffer (pending_text, '\\');
- }
+ {
+ ch = inchar();
+ if (ch != EOF)
+ add1_buffer (pending_text, '\\');
+ }
if (ch == EOF)
- {
- add1_buffer (pending_text, '\n');
- return;
- }
+ {
+ add1_buffer (pending_text, '\n');
+ return;
+ }
ch = add_then_next (pending_text, ch);
}
@@ -900,7 +900,7 @@ read_text(buf, leadin_ch)
if (!buf)
buf = old_text_buf;
buf->text_length = normalize_text (get_buffer (pending_text),
- size_buffer (pending_text), TEXT_BUFFER);
+ size_buffer (pending_text), TEXT_BUFFER);
buf->text = MEMDUP(get_buffer(pending_text), buf->text_length, char);
free_buffer(pending_text);
pending_text = NULL;
@@ -928,45 +928,45 @@ compile_address(addr, ch)
struct buffer *b;
addr->addr_type = ADDR_IS_REGEX;
if (ch == '\\')
- ch = inchar();
+ ch = inchar();
if ( !(b = match_slash(ch, true)) )
- bad_prog(_(UNTERM_ADDR_RE));
+ bad_prog(_(UNTERM_ADDR_RE));
for(;;)
- {
- ch = in_nonblank();
- if (posixicity == POSIXLY_BASIC)
- goto posix_address_modifier;
+ {
+ ch = in_nonblank();
+ if (posixicity == POSIXLY_BASIC)
+ goto posix_address_modifier;
switch(ch)
- {
- case 'I': /* GNU extension */
- flags |= REG_ICASE;
- break;
+ {
+ case 'I': /* GNU extension */
+ flags |= REG_ICASE;
+ break;
#ifdef REG_PERL
- case 'S': /* GNU extension */
- if (extended_regexp_flags & REG_PERL)
- flags |= REG_DOTALL;
- break;
-
- case 'X': /* GNU extension */
- if (extended_regexp_flags & REG_PERL)
- flags |= REG_EXTENDED;
- break;
+ case 'S': /* GNU extension */
+ if (extended_regexp_flags & REG_PERL)
+ flags |= REG_DOTALL;
+ break;
+
+ case 'X': /* GNU extension */
+ if (extended_regexp_flags & REG_PERL)
+ flags |= REG_EXTENDED;
+ break;
#endif
- case 'M': /* GNU extension */
- flags |= REG_NEWLINE;
- break;
-
- default:
- posix_address_modifier:
- savchar (ch);
- addr->addr_regex = compile_regex (b, flags, 0);
- free_buffer(b);
- return true;
- }
- }
+ case 'M': /* GNU extension */
+ flags |= REG_NEWLINE;
+ break;
+
+ default:
+ posix_address_modifier:
+ savchar (ch);
+ addr->addr_regex = compile_regex (b, flags, 0);
+ free_buffer(b);
+ return true;
+ }
+ }
}
else if (ISDIGIT(ch))
{
@@ -974,28 +974,28 @@ compile_address(addr, ch)
addr->addr_type = ADDR_IS_NUM;
ch = in_nonblank();
if (ch != '~' || posixicity == POSIXLY_BASIC)
- {
- savchar(ch);
- }
+ {
+ savchar(ch);
+ }
else
- {
- countT step = in_integer(in_nonblank());
- if (step > 0)
- {
- addr->addr_step = step;
- addr->addr_type = ADDR_IS_NUM_MOD;
- }
- }
+ {
+ countT step = in_integer(in_nonblank());
+ if (step > 0)
+ {
+ addr->addr_step = step;
+ addr->addr_type = ADDR_IS_NUM_MOD;
+ }
+ }
}
else if ((ch == '+' || ch == '~') && posixicity != POSIXLY_BASIC)
{
addr->addr_step = in_integer(in_nonblank());
if (addr->addr_step==0)
- ; /* default to ADDR_IS_NULL; forces matching to stop on next line */
+ ; /* default to ADDR_IS_NULL; forces matching to stop on next line */
else if (ch == '+')
- addr->addr_type = ADDR_IS_STEP;
+ addr->addr_type = ADDR_IS_STEP;
else
- addr->addr_type = ADDR_IS_STEP_MOD;
+ addr->addr_type = ADDR_IS_STEP_MOD;
}
else if (ch == '$')
{
@@ -1035,44 +1035,44 @@ compile_program(vector)
struct addr a;
while ((ch=inchar()) == ';' || ISSPACE(ch))
- ;
+ ;
if (ch == EOF)
- break;
+ break;
cur_cmd = next_cmd_entry(&vector);
if (compile_address(&a, ch))
- {
- if (a.addr_type == ADDR_IS_STEP
- || a.addr_type == ADDR_IS_STEP_MOD)
- bad_prog(_(BAD_STEP));
-
- cur_cmd->a1 = MEMDUP(&a, 1, struct addr);
- ch = in_nonblank();
- if (ch == ',')
- {
- if (!compile_address(&a, in_nonblank()))
- bad_prog(_(BAD_COMMA));
-
- cur_cmd->a2 = MEMDUP(&a, 1, struct addr);
- ch = in_nonblank();
- }
-
- if ((cur_cmd->a1->addr_type == ADDR_IS_NUM
- && cur_cmd->a1->addr_number == 0)
- && ((!cur_cmd->a2 || cur_cmd->a2->addr_type != ADDR_IS_REGEX)
- || posixicity == POSIXLY_BASIC))
- bad_prog(_(INVALID_LINE_0));
- }
+ {
+ if (a.addr_type == ADDR_IS_STEP
+ || a.addr_type == ADDR_IS_STEP_MOD)
+ bad_prog(_(BAD_STEP));
+
+ cur_cmd->a1 = MEMDUP(&a, 1, struct addr);
+ ch = in_nonblank();
+ if (ch == ',')
+ {
+ if (!compile_address(&a, in_nonblank()))
+ bad_prog(_(BAD_COMMA));
+
+ cur_cmd->a2 = MEMDUP(&a, 1, struct addr);
+ ch = in_nonblank();
+ }
+
+ if ((cur_cmd->a1->addr_type == ADDR_IS_NUM
+ && cur_cmd->a1->addr_number == 0)
+ && ((!cur_cmd->a2 || cur_cmd->a2->addr_type != ADDR_IS_REGEX)
+ || posixicity == POSIXLY_BASIC))
+ bad_prog(_(INVALID_LINE_0));
+ }
if (ch == '!')
- {
- cur_cmd->addr_bang = true;
- ch = in_nonblank();
- if (ch == '!')
- bad_prog(_(BAD_BANG));
- }
+ {
+ cur_cmd->addr_bang = true;
+ ch = in_nonblank();
+ if (ch == '!')
+ bad_prog(_(BAD_BANG));
+ }
/* Do not accept extended commands in --posix mode. Also,
- a few commands only accept one address in that mode. */
+ a few commands only accept one address in that mode. */
if (posixicity == POSIXLY_BASIC)
switch (ch)
{
@@ -1080,131 +1080,131 @@ compile_program(vector)
case 'Q': case 'T': case 'R': case 'W':
bad_command(ch);
- case 'a': case 'i': case 'l':
- case '=': case 'r':
- if (cur_cmd->a2)
- bad_prog(_(ONE_ADDR));
- }
+ case 'a': case 'i': case 'l':
+ case '=': case 'r':
+ if (cur_cmd->a2)
+ bad_prog(_(ONE_ADDR));
+ }
cur_cmd->cmd = ch;
switch (ch)
- {
- case '#':
- if (cur_cmd->a1)
- bad_prog(_(NO_SHARP_ADDR));
- ch = inchar();
- if (ch=='n' && first_script && cur_input.line < 2)
- if ( (prog.base && prog.cur==2+prog.base)
- || (prog.file && !prog.base && 2==ftell(prog.file)))
- no_default_output = true;
- while (ch != EOF && ch != '\n')
- ch = inchar();
- continue; /* restart the for (;;) loop */
-
- case 'v':
- /* This is an extension. Programs needing GNU sed might start
- * with a `v' command so that other seds will stop.
- * We compare the version and ignore POSIXLY_CORRECT.
- */
- {
- char *version = read_label ();
- char *compared_version;
- compared_version = (*version == '\0') ? "4.0" : version;
- if (strverscmp (compared_version, SED_FEATURE_VERSION) > 0)
- bad_prog(_(ANCIENT_VERSION));
-
- free (version);
- posixicity = POSIXLY_EXTENDED;
- }
- continue;
-
- case '{':
- blocks = setup_label(blocks, vector->v_length, NULL, &cur_input);
- cur_cmd->addr_bang = !cur_cmd->addr_bang;
- break;
-
- case '}':
- if (!blocks)
- bad_prog(_(EXCESS_CLOSE_BRACE));
- if (cur_cmd->a1)
- bad_prog(_(NO_CLOSE_BRACE_ADDR));
- ch = in_nonblank();
- if (ch == CLOSE_BRACE || ch == '#')
- savchar(ch);
- else if (ch != EOF && ch != '\n' && ch != ';')
- bad_prog(_(EXCESS_JUNK));
-
- vector->v[blocks->v_index].x.jump_index = vector->v_length;
- blocks = release_label(blocks); /* done with this entry */
- break;
-
- case 'e':
- ch = in_nonblank();
- if (ch == EOF || ch == '\n')
- {
- cur_cmd->x.cmd_txt.text_length = 0;
- break;
- }
- else
- goto read_text_to_slash;
-
- case 'a':
- case 'i':
- case 'c':
- ch = in_nonblank();
-
- read_text_to_slash:
- if (ch == EOF)
- bad_prog(_(EXPECTED_SLASH));
-
- if (ch == '\\')
- ch = inchar();
- else
- {
- if (posixicity == POSIXLY_BASIC)
- bad_prog(_(EXPECTED_SLASH));
- savchar(ch);
- ch = '\n';
- }
-
- read_text(&cur_cmd->x.cmd_txt, ch);
- break;
-
- case ':':
- if (cur_cmd->a1)
- bad_prog(_(NO_COLON_ADDR));
- labels = setup_label(labels, vector->v_length, read_label(), NULL);
- break;
-
- case 'T':
- case 'b':
- case 't':
- jumps = setup_label(jumps, vector->v_length, read_label(), NULL);
- break;
-
- case 'Q':
- case 'q':
- if (cur_cmd->a2)
- bad_prog(_(ONE_ADDR));
- /* Fall through */
-
- case 'L':
- case 'l':
- ch = in_nonblank();
- if (ISDIGIT(ch) && posixicity != POSIXLY_BASIC)
- {
- cur_cmd->x.int_arg = in_integer(ch);
- ch = in_nonblank();
- }
- else
- cur_cmd->x.int_arg = -1;
-
- if (ch == CLOSE_BRACE || ch == '#')
- savchar(ch);
- else if (ch != EOF && ch != '\n' && ch != ';')
- bad_prog(_(EXCESS_JUNK));
-
- break;
+ {
+ case '#':
+ if (cur_cmd->a1)
+ bad_prog(_(NO_SHARP_ADDR));
+ ch = inchar();
+ if (ch=='n' && first_script && cur_input.line < 2)
+ if ( (prog.base && prog.cur==2+prog.base)
+ || (prog.file && !prog.base && 2==ftell(prog.file)))
+ no_default_output = true;
+ while (ch != EOF && ch != '\n')
+ ch = inchar();
+ continue; /* restart the for (;;) loop */
+
+ case 'v':
+ /* This is an extension. Programs needing GNU sed might start
+ * with a `v' command so that other seds will stop.
+ * We compare the version and ignore POSIXLY_CORRECT.
+ */
+ {
+ char *version = read_label ();
+ char *compared_version;
+ compared_version = (*version == '\0') ? "4.0" : version;
+ if (strverscmp (compared_version, SED_FEATURE_VERSION) > 0)
+ bad_prog(_(ANCIENT_VERSION));
+
+ free (version);
+ posixicity = POSIXLY_EXTENDED;
+ }
+ continue;
+
+ case '{':
+ blocks = setup_label(blocks, vector->v_length, NULL, &cur_input);
+ cur_cmd->addr_bang = !cur_cmd->addr_bang;
+ break;
+
+ case '}':
+ if (!blocks)
+ bad_prog(_(EXCESS_CLOSE_BRACE));
+ if (cur_cmd->a1)
+ bad_prog(_(NO_CLOSE_BRACE_ADDR));
+ ch = in_nonblank();
+ if (ch == CLOSE_BRACE || ch == '#')
+ savchar(ch);
+ else if (ch != EOF && ch != '\n' && ch != ';')
+ bad_prog(_(EXCESS_JUNK));
+
+ vector->v[blocks->v_index].x.jump_index = vector->v_length;
+ blocks = release_label(blocks); /* done with this entry */
+ break;
+
+ case 'e':
+ ch = in_nonblank();
+ if (ch == EOF || ch == '\n')
+ {
+ cur_cmd->x.cmd_txt.text_length = 0;
+ break;
+ }
+ else
+ goto read_text_to_slash;
+
+ case 'a':
+ case 'i':
+ case 'c':
+ ch = in_nonblank();
+
+ read_text_to_slash:
+ if (ch == EOF)
+ bad_prog(_(EXPECTED_SLASH));
+
+ if (ch == '\\')
+ ch = inchar();
+ else
+ {
+ if (posixicity == POSIXLY_BASIC)
+ bad_prog(_(EXPECTED_SLASH));
+ savchar(ch);
+ ch = '\n';
+ }
+
+ read_text(&cur_cmd->x.cmd_txt, ch);
+ break;
+
+ case ':':
+ if (cur_cmd->a1)
+ bad_prog(_(NO_COLON_ADDR));
+ labels = setup_label(labels, vector->v_length, read_label(), NULL);
+ break;
+
+ case 'T':
+ case 'b':
+ case 't':
+ jumps = setup_label(jumps, vector->v_length, read_label(), NULL);
+ break;
+
+ case 'Q':
+ case 'q':
+ if (cur_cmd->a2)
+ bad_prog(_(ONE_ADDR));
+ /* Fall through */
+
+ case 'L':
+ case 'l':
+ ch = in_nonblank();
+ if (ISDIGIT(ch) && posixicity != POSIXLY_BASIC)
+ {
+ cur_cmd->x.int_arg = in_integer(ch);
+ ch = in_nonblank();
+ }
+ else
+ cur_cmd->x.int_arg = -1;
+
+ if (ch == CLOSE_BRACE || ch == '#')
+ savchar(ch);
+ else if (ch != EOF && ch != '\n' && ch != ';')
+ bad_prog(_(EXCESS_JUNK));
+
+ break;
case '=':
case 'd':
@@ -1213,79 +1213,79 @@ compile_program(vector)
case 'g':
case 'G':
case 'h':
- case 'H':
- case 'n':
- case 'N':
- case 'p':
- case 'P':
- case 'z':
- case 'x':
- ch = in_nonblank();
- if (ch == CLOSE_BRACE || ch == '#')
- savchar(ch);
- else if (ch != EOF && ch != '\n' && ch != ';')
- bad_prog(_(EXCESS_JUNK));
- break;
-
- case 'r':
- b = read_filename();
- cur_cmd->x.fname = ck_strdup(get_buffer(b));
- free_buffer(b);
- break;
+ case 'H':
+ case 'n':
+ case 'N':
+ case 'p':
+ case 'P':
+ case 'z':
+ case 'x':
+ ch = in_nonblank();
+ if (ch == CLOSE_BRACE || ch == '#')
+ savchar(ch);
+ else if (ch != EOF && ch != '\n' && ch != ';')
+ bad_prog(_(EXCESS_JUNK));
+ break;
+
+ case 'r':
+ b = read_filename();
+ cur_cmd->x.fname = ck_strdup(get_buffer(b));
+ free_buffer(b);
+ break;
case 'R':
- cur_cmd->x.fp = get_openfile(&file_read, read_mode, false)->fp;
- break;
+ cur_cmd->x.fp = get_openfile(&file_read, read_mode, false)->fp;
+ break;
case 'W':
- case 'w':
- cur_cmd->x.outf = get_openfile(&file_write, write_mode, true);
- break;
-
- case 's':
- {
- struct buffer *b2;
- int flags;
- int slash;
-
- slash = inchar();
- if ( !(b = match_slash(slash, true)) )
- bad_prog(_(UNTERM_S_CMD));
- if ( !(b2 = match_slash(slash, false)) )
- bad_prog(_(UNTERM_S_CMD));
-
- cur_cmd->x.cmd_subst = OB_MALLOC(&obs, 1, struct subst);
- setup_replacement(cur_cmd->x.cmd_subst,
- get_buffer(b2), size_buffer(b2));
- free_buffer(b2);
-
- flags = mark_subst_opts(cur_cmd->x.cmd_subst);
- cur_cmd->x.cmd_subst->regx =
- compile_regex(b, flags, cur_cmd->x.cmd_subst->max_id + 1);
- free_buffer(b);
- }
- break;
-
- case 'y':
- {
- size_t len, dest_len;
- int slash;
- struct buffer *b2;
+ case 'w':
+ cur_cmd->x.outf = get_openfile(&file_write, write_mode, true);
+ break;
+
+ case 's':
+ {
+ struct buffer *b2;
+ int flags;
+ int slash;
+
+ slash = inchar();
+ if ( !(b = match_slash(slash, true)) )
+ bad_prog(_(UNTERM_S_CMD));
+ if ( !(b2 = match_slash(slash, false)) )
+ bad_prog(_(UNTERM_S_CMD));
+
+ cur_cmd->x.cmd_subst = OB_MALLOC(&obs, 1, struct subst);
+ setup_replacement(cur_cmd->x.cmd_subst,
+ get_buffer(b2), size_buffer(b2));
+ free_buffer(b2);
+
+ flags = mark_subst_opts(cur_cmd->x.cmd_subst);
+ cur_cmd->x.cmd_subst->regx =
+ compile_regex(b, flags, cur_cmd->x.cmd_subst->max_id + 1);
+ free_buffer(b);
+ }
+ break;
+
+ case 'y':
+ {
+ size_t len, dest_len;
+ int slash;
+ struct buffer *b2;
char *src_buf, *dest_buf;
- slash = inchar();
- if ( !(b = match_slash(slash, false)) )
- bad_prog(_(UNTERM_Y_CMD));
+ slash = inchar();
+ if ( !(b = match_slash(slash, false)) )
+ bad_prog(_(UNTERM_Y_CMD));
src_buf = get_buffer(b);
- len = normalize_text(src_buf, size_buffer (b), TEXT_BUFFER);
+ len = normalize_text(src_buf, size_buffer (b), TEXT_BUFFER);
if ( !(b2 = match_slash(slash, false)) )
- bad_prog(_(UNTERM_Y_CMD));
+ bad_prog(_(UNTERM_Y_CMD));
dest_buf = get_buffer(b2);
- dest_len = normalize_text(dest_buf, size_buffer (b2), TEXT_BUFFER);
+ dest_len = normalize_text(dest_buf, size_buffer (b2), TEXT_BUFFER);
if (mb_cur_max > 1)
- {
+ {
int i, j, idx, src_char_num;
size_t *src_lens = MALLOC(len, size_t);
char **trans_pairs;
@@ -1347,38 +1347,38 @@ compile_program(vector)
}
else
{
- unsigned char *translate =
- OB_MALLOC(&obs, YMAP_LENGTH, unsigned char);
+ unsigned char *translate =
+ OB_MALLOC(&obs, YMAP_LENGTH, unsigned char);
unsigned char *ustring = (unsigned char *)src_buf;
- if (len != dest_len)
+ if (len != dest_len)
bad_prog(_(Y_CMD_LEN));
- for (len = 0; len < YMAP_LENGTH; len++)
- translate[len] = len;
+ for (len = 0; len < YMAP_LENGTH; len++)
+ translate[len] = len;
while (dest_len--)
translate[*ustring++] = (unsigned char)*dest_buf++;
- cur_cmd->x.translate = translate;
- }
+ cur_cmd->x.translate = translate;
+ }
if ((ch = in_nonblank()) != EOF && ch != '\n' && ch != ';')
bad_prog(_(EXCESS_JUNK));
free_buffer(b);
free_buffer(b2);
- }
- break;
+ }
+ break;
- case EOF:
- bad_prog(_(NO_COMMAND));
- /*NOTREACHED*/
+ case EOF:
+ bad_prog(_(NO_COMMAND));
+ /*NOTREACHED*/
- default:
- bad_command (ch);
- /*NOTREACHED*/
- }
+ default:
+ bad_command (ch);
+ /*NOTREACHED*/
+ }
/* this is buried down here so that "continue" statements will miss it */
++vector->v_length;
@@ -1418,7 +1418,7 @@ normalize_text(buf, len, buftype)
{
mbclen = MBRLEN (p, bufend - p, &cur_stat);
if (mbclen != 1)
- {
+ {
/* An invalid sequence, or a truncated multibyte character.
We treat it as a singlebyte character. */
if (mbclen == (size_t) -1 || mbclen == (size_t) -2 || mbclen == 0)
@@ -1427,68 +1427,68 @@ normalize_text(buf, len, buftype)
memmove (q, p, mbclen);
q += mbclen;
p += mbclen;
- continue;
- }
+ continue;
+ }
if (*p == '\\' && p+1 < bufend && bracket_state == 0)
- switch (*++p)
- {
+ switch (*++p)
+ {
#if defined __STDC__ && __STDC__-0
- case 'a': *q++ = '\a'; p++; continue;
+ case 'a': *q++ = '\a'; p++; continue;
#else /* Not STDC; we'll just assume ASCII */
- case 'a': *q++ = '\007'; p++; continue;
+ case 'a': *q++ = '\007'; p++; continue;
#endif
- /* case 'b': *q++ = '\b'; p++; continue; --- conflicts with \b RE */
- case 'f': *q++ = '\f'; p++; continue;
- case '\n': /*fall through */
- case 'n': *q++ = '\n'; p++; continue;
- case 'r': *q++ = '\r'; p++; continue;
- case 't': *q++ = '\t'; p++; continue;
- case 'v': *q++ = '\v'; p++; continue;
-
- case 'd': /* decimal byte */
+ /* case 'b': *q++ = '\b'; p++; continue; --- conflicts with \b RE */
+ case 'f': *q++ = '\f'; p++; continue;
+ case '\n': /*fall through */
+ case 'n': *q++ = '\n'; p++; continue;
+ case 'r': *q++ = '\r'; p++; continue;
+ case 't': *q++ = '\t'; p++; continue;
+ case 'v': *q++ = '\v'; p++; continue;
+
+ case 'd': /* decimal byte */
base = 10;
goto convert;
- case 'x': /* hexadecimal byte */
+ case 'x': /* hexadecimal byte */
base = 16;
goto convert;
#ifdef REG_PERL
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- if ((extended_regexp_flags & REG_PERL)
- && p+1 < bufend
- && p[1] >= '0' && p[1] <= '9')
- {
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ if ((extended_regexp_flags & REG_PERL)
+ && p+1 < bufend
+ && p[1] >= '0' && p[1] <= '9')
+ {
base = 8;
goto convert;
- }
- else
- {
- /* we just pass the \ up one level for interpretation */
- if (buftype != TEXT_BUFFER)
- *q++ = '\\';
- }
-
- continue;
-
- case 'o': /* octal byte */
- if (!(extended_regexp_flags & REG_PERL))
- {
+ }
+ else
+ {
+ /* we just pass the \ up one level for interpretation */
+ if (buftype != TEXT_BUFFER)
+ *q++ = '\\';
+ }
+
+ continue;
+
+ case 'o': /* octal byte */
+ if (!(extended_regexp_flags & REG_PERL))
+ {
base = 8;
goto convert;
- }
- else
- {
- /* we just pass the \ up one level for interpretation */
- if (buftype != TEXT_BUFFER)
- *q++ = '\\';
- }
-
- continue;
+ }
+ else
+ {
+ /* we just pass the \ up one level for interpretation */
+ if (buftype != TEXT_BUFFER)
+ *q++ = '\\';
+ }
+
+ continue;
#else
- case 'o': /* octal byte */
+ case 'o': /* octal byte */
base = 8;
#endif
convert:
@@ -1500,27 +1500,27 @@ convert:
*q++ = ch;
continue;
- case 'c':
- if (++p < bufend)
- {
- *q++ = toupper((unsigned char) *p) ^ 0x40;
- p++;
- continue;
- }
- else
- {
- /* we just pass the \ up one level for interpretation */
- if (buftype != TEXT_BUFFER)
- *q++ = '\\';
- continue;
- }
-
- default:
- /* we just pass the \ up one level for interpretation */
- if (buftype != TEXT_BUFFER)
- *q++ = '\\';
- break;
- }
+ case 'c':
+ if (++p < bufend)
+ {
+ *q++ = toupper((unsigned char) *p) ^ 0x40;
+ p++;
+ continue;
+ }
+ else
+ {
+ /* we just pass the \ up one level for interpretation */
+ if (buftype != TEXT_BUFFER)
+ *q++ = '\\';
+ continue;
+ }
+
+ default:
+ /* we just pass the \ up one level for interpretation */
+ if (buftype != TEXT_BUFFER)
+ *q++ = '\\';
+ break;
+ }
else if (buftype == TEXT_REGEX && posixicity != POSIXLY_EXTENDED)
switch (*p)
{
@@ -1529,16 +1529,16 @@ convert:
bracket_state = -1;
break;
- case ':':
- case '.':
- case '=':
+ case ':':
+ case '.':
+ case '=':
if (bracket_state == -1 && p[-1] == '[')
bracket_state = *p;
break;
case ']':
if (bracket_state == 0)
- ;
+ ;
else if (bracket_state == -1)
bracket_state = 0;
else if (p[-2] != bracket_state && p[-1] == bracket_state)
@@ -1638,7 +1638,7 @@ check_final_program(program)
old_text_buf->text_length = size_buffer(pending_text);
if (old_text_buf->text_length)
old_text_buf->text = MEMDUP(get_buffer(pending_text),
- old_text_buf->text_length, char);
+ old_text_buf->text_length, char);
free_buffer(pending_text);
pending_text = NULL;
}
@@ -1646,18 +1646,18 @@ check_final_program(program)
for (go = jumps; go; go = release_label(go))
{
for (lbl = labels; lbl; lbl = lbl->next)
- if (strcmp(lbl->name, go->name) == 0)
- break;
+ if (strcmp(lbl->name, go->name) == 0)
+ break;
if (lbl)
- {
- program->v[go->v_index].x.jump_index = lbl->v_index;
- }
+ {
+ program->v[go->v_index].x.jump_index = lbl->v_index;
+ }
else
- {
- if (*go->name)
- panic(_("can't find label for jump to `%s'"), go->name);
- program->v[go->v_index].x.jump_index = program->v_length;
- }
+ {
+ if (*go->name)
+ panic(_("can't find label for jump to `%s'"), go->name);
+ program->v[go->v_index].x.jump_index = program->v_length;
+ }
}
jumps = NULL;
@@ -1671,17 +1671,17 @@ check_final_program(program)
for (p=file_read; p; p=p->link)
if (p->name)
- {
- free(p->name);
- p->name = NULL;
- }
+ {
+ free(p->name);
+ p->name = NULL;
+ }
for (p=file_write; p; p=p->link)
if (p->name)
- {
- free(p->name);
- p->name = NULL;
- }
+ {
+ free(p->name);
+ p->name = NULL;
+ }
}
}
@@ -1707,23 +1707,23 @@ finish_program(program)
for (p=file_read; p; p=q)
{
- if (p->fp)
- ck_fclose(p->fp);
- q = p->link;
+ if (p->fp)
+ ck_fclose(p->fp);
+ q = p->link;
#if 0
- /* We use obstacks. */
- free(p);
+ /* We use obstacks. */
+ free(p);
#endif
}
for (p=file_write; p; p=q)
{
- if (p->fp)
- ck_fclose(p->fp);
- q = p->link;
+ if (p->fp)
+ ck_fclose(p->fp);
+ q = p->link;
#if 0
- /* We use obstacks. */
- free(p);
+ /* We use obstacks. */
+ free(p);
#endif
}
file_read = file_write = NULL;
diff --git a/sed/execute.c b/sed/execute.c
index 39780ce..10a4289 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -152,7 +152,7 @@ resize_line(lb, len)
inactive = 0;
if (lb->alloc > len)
- return;
+ return;
}
lb->alloc *= 2;
@@ -187,24 +187,24 @@ str_append(to, string, length)
/* An invalid or imcomplete sequence is treated like a singlebyte character. */
if (n == (size_t) -1 || n == (size_t) -2)
- {
- memset (&to->mbstate, 0, sizeof (to->mbstate));
- n = 1;
- }
+ {
+ memset (&to->mbstate, 0, sizeof (to->mbstate));
+ n = 1;
+ }
if (n > 0)
- {
- string += n;
- length -= n;
- }
+ {
+ string += n;
+ length -= n;
+ }
else
- break;
+ break;
}
}
static void
str_append_modified(struct line *to, const char *string, size_t length,
- enum replacement_types type)
+ enum replacement_types type)
{
mbstate_t from_stat;
@@ -233,28 +233,28 @@ str_append_modified(struct line *to, const char *string, size_t length,
if (n > 0)
string += n, length -= n;
else
- {
- /* Incomplete sequence, copy it manually. */
- str_append(to, string, length);
- return;
- }
+ {
+ /* 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);
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;
- }
+ 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)
@@ -266,10 +266,10 @@ str_append_modified(struct line *to, const char *string, size_t length,
n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
to->length += n;
if (n == -1 || n == -2)
- {
- fprintf (stderr, "Case conversion produced an invalid character!");
- abort ();
- }
+ {
+ fprintf (stderr, "Case conversion produced an invalid character!");
+ abort ();
+ }
}
}
@@ -330,11 +330,11 @@ line_copy(from, to, state)
{
to->alloc *= 2;
if (to->alloc < from->length)
- to->alloc = from->length;
+ to->alloc = from->length;
if (to->alloc < INITIAL_BUFFER_SIZE)
- to->alloc = INITIAL_BUFFER_SIZE;
+ to->alloc = INITIAL_BUFFER_SIZE;
/* Use free()+MALLOC() instead of REALLOC() to
- avoid unnecessary copying of old text. */
+ avoid unnecessary copying of old text. */
free(to->text);
to->text = MALLOC(to->alloc, char);
}
@@ -515,23 +515,23 @@ dump_append_queue()
ck_fwrite(p->text, 1, p->textlen, output_file.fp);
if (p->fname)
- {
- char buf[FREAD_BUFFER_SIZE];
- size_t cnt;
- FILE *fp;
-
- /* "If _fname_ does not exist or cannot be read, it shall
- be treated as if it were an empty file, causing no error
- condition." IEEE Std 1003.2-1992
- So, don't fail. */
- fp = ck_fopen(p->fname, read_mode, false);
- if (fp)
- {
- while ((cnt = ck_fread(buf, 1, sizeof buf, fp)) > 0)
- ck_fwrite(buf, 1, cnt, output_file.fp);
- ck_fclose(fp);
- }
- }
+ {
+ char buf[FREAD_BUFFER_SIZE];
+ size_t cnt;
+ FILE *fp;
+
+ /* "If _fname_ does not exist or cannot be read, it shall
+ be treated as if it were an empty file, causing no error
+ condition." IEEE Std 1003.2-1992
+ So, don't fail. */
+ fp = ck_fopen(p->fname, read_mode, false);
+ if (fp)
+ {
+ while ((cnt = ck_fread(buf, 1, sizeof buf, fp)) > 0)
+ ck_fwrite(buf, 1, cnt, output_file.fp);
+ ck_fclose(fp);
+ }
+ }
}
flush_output(output_file.fp);
@@ -617,9 +617,9 @@ open_next_file(name, input)
/* get the base name */
tmpdir = ck_strdup(input->in_file_name);
if ((p = strrchr(tmpdir, '/')))
- *p = 0;
+ *p = 0;
else
- strcpy(tmpdir, ".");
+ strcpy(tmpdir, ".");
if (isatty (fileno (input->fp)))
panic(_("couldn't edit %s: is a terminal"), input->in_file_name);
@@ -630,36 +630,36 @@ open_next_file(name, input)
panic(_("couldn't edit %s: not a regular file"), input->in_file_name);
if (is_selinux_enabled () > 0)
- {
+ {
security_context_t con;
- if (getfilecon (input->in_file_name, &con) != -1)
- {
- /* Save and restore the old context for the sake of w and W
- commands. */
- reset_fscreatecon = getfscreatecon (&old_fscreatecon) >= 0;
- if (setfscreatecon (con) < 0)
- fprintf (stderr, _("%s: warning: failed to set default file creation context to %s: %s"),
- myname, con, strerror (errno));
- freecon (con);
- }
- else
- {
- if (errno != ENOSYS)
- fprintf (stderr, _("%s: warning: failed to get security context of %s: %s"),
- myname, input->in_file_name, strerror (errno));
- }
- }
+ if (getfilecon (input->in_file_name, &con) != -1)
+ {
+ /* Save and restore the old context for the sake of w and W
+ commands. */
+ reset_fscreatecon = getfscreatecon (&old_fscreatecon) >= 0;
+ if (setfscreatecon (con) < 0)
+ fprintf (stderr, _("%s: warning: failed to set default file creation context to %s: %s"),
+ myname, con, strerror (errno));
+ freecon (con);
+ }
+ else
+ {
+ if (errno != ENOSYS)
+ fprintf (stderr, _("%s: warning: failed to get security context of %s: %s"),
+ myname, input->in_file_name, strerror (errno));
+ }
+ }
output_file.fp = ck_mkstemp (&input->out_file_name, tmpdir, "sed",
- write_mode);
+ write_mode);
output_file.missing_newline = false;
free (tmpdir);
if (reset_fscreatecon)
- {
- setfscreatecon (old_fscreatecon);
- freecon (old_fscreatecon);
- }
+ {
+ setfscreatecon (old_fscreatecon);
+ freecon (old_fscreatecon);
+ }
if (!output_file.fp)
panic(_("couldn't open temporary file %s: %s"), input->out_file_name, strerror(errno));
@@ -696,17 +696,17 @@ closedown(input)
fchown (output_fd, -1, input->st.st_gid);
#endif
copy_acl (input->in_file_name, input_fd,
- input->out_file_name, output_fd,
- input->st.st_mode);
+ input->out_file_name, output_fd,
+ input->st.st_mode);
ck_fclose (input->fp);
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);
+ 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);
free (input->out_file_name);
@@ -728,8 +728,8 @@ reset_addresses(vec)
for (cur_cmd = vec->v, n = vec->v_length; n--; cur_cmd++)
if (cur_cmd->a1
- && cur_cmd->a1->addr_type == ADDR_IS_NUM
- && cur_cmd->a1->addr_number == 0)
+ && cur_cmd->a1->addr_type == ADDR_IS_NUM
+ && cur_cmd->a1->addr_number == 0)
cur_cmd->range_state = RANGE_ACTIVE;
else
cur_cmd->range_state = RANGE_INACTIVE;
@@ -756,23 +756,23 @@ read_pattern_space(input, the_program, append)
closedown(input);
if (!*input->file_list)
- return false;
+ return false;
if (input->reset_at_next_file)
- {
- input->line_number = 0;
- hold.length = 0;
- reset_addresses (the_program);
- rewind_read_files ();
-
- /* If doing in-place editing, we will never append the
- new-line to this file; but if the output goes to stdout,
- we might still have to output the missing new-line. */
- if (in_place_extension)
- output_file.missing_newline = false;
-
- input->reset_at_next_file = separate_files;
- }
+ {
+ input->line_number = 0;
+ hold.length = 0;
+ reset_addresses (the_program);
+ rewind_read_files ();
+
+ /* If doing in-place editing, we will never append the
+ new-line to this file; but if the output goes to stdout,
+ we might still have to output the missing new-line. */
+ if (in_place_extension)
+ output_file.missing_newline = false;
+
+ input->reset_at_next_file = separate_files;
+ }
open_next_file (*input->file_list++, input);
}
@@ -793,16 +793,16 @@ last_file_with_data_p(input)
closedown(input);
if (!*input->file_list)
- return true;
+ return true;
open_next_file(*input->file_list++, input);
if (input->fp)
- {
- if ((ch = getc(input->fp)) != EOF)
- {
- ungetc(ch, input->fp);
- return false;
- }
- }
+ {
+ if ((ch = getc(input->fp)) != EOF)
+ {
+ ungetc(ch, input->fp);
+ return false;
+ }
+ }
}
}
@@ -844,7 +844,7 @@ match_an_address_p(addr, input)
case ADDR_IS_NUM_MOD:
return (input->line_number >= addr->addr_number
- && ((input->line_number - addr->addr_number) % addr->addr_step) == 0);
+ && ((input->line_number - addr->addr_number) % addr->addr_step) == 0);
case ADDR_IS_STEP:
case ADDR_IS_STEP_MOD:
@@ -878,47 +878,47 @@ match_address_p(cmd, input)
if (cmd->range_state != RANGE_ACTIVE)
{
/* Find if we are going to activate a range. Handle ADDR_IS_NUM
- specially: it represent an "absolute" state, it should not
- be computed like regexes. */
+ specially: it represent an "absolute" state, it should not
+ be computed like regexes. */
if (cmd->a1->addr_type == ADDR_IS_NUM)
- {
- if (!cmd->a2)
- return (input->line_number == cmd->a1->addr_number);
-
- if (cmd->range_state == RANGE_CLOSED
- || input->line_number < cmd->a1->addr_number)
- return false;
- }
+ {
+ if (!cmd->a2)
+ return (input->line_number == cmd->a1->addr_number);
+
+ if (cmd->range_state == RANGE_CLOSED
+ || input->line_number < cmd->a1->addr_number)
+ return false;
+ }
else
- {
+ {
if (!cmd->a2)
- return match_an_address_p(cmd->a1, input);
+ return match_an_address_p(cmd->a1, input);
- if (!match_an_address_p(cmd->a1, input))
+ if (!match_an_address_p(cmd->a1, input))
return false;
- }
+ }
/* Ok, start a new range. */
cmd->range_state = RANGE_ACTIVE;
switch (cmd->a2->addr_type)
- {
- case ADDR_IS_REGEX:
- /* Always include at least two lines. */
- return true;
- case ADDR_IS_NUM:
- /* Same handling as below, but always include at least one line. */
+ {
+ case ADDR_IS_REGEX:
+ /* Always include at least two lines. */
+ return true;
+ case ADDR_IS_NUM:
+ /* Same handling as below, but always include at least one line. */
if (input->line_number >= cmd->a2->addr_number)
- cmd->range_state = RANGE_CLOSED;
+ cmd->range_state = RANGE_CLOSED;
+ return true;
+ case ADDR_IS_STEP:
+ cmd->a2->addr_number = input->line_number + cmd->a2->addr_step;
+ return true;
+ case ADDR_IS_STEP_MOD:
+ cmd->a2->addr_number = input->line_number + cmd->a2->addr_step
+ - (input->line_number%cmd->a2->addr_step);
return true;
- case ADDR_IS_STEP:
- cmd->a2->addr_number = input->line_number + cmd->a2->addr_step;
- return true;
- case ADDR_IS_STEP_MOD:
- cmd->a2->addr_number = input->line_number + cmd->a2->addr_step
- - (input->line_number%cmd->a2->addr_step);
- return true;
- default:
- break;
+ default:
+ break;
}
}
@@ -929,10 +929,10 @@ match_address_p(cmd, input)
{
/* If the second address is a line number, and if we got past
that line, fail to match (it can happen when you jump
- over such addresses with `b' and `t'. Use RANGE_CLOSED
+ over such addresses with `b' and `t'. Use RANGE_CLOSED
so that the range is not re-enabled anymore. */
if (input->line_number >= cmd->a2->addr_number)
- cmd->range_state = RANGE_CLOSED;
+ cmd->range_state = RANGE_CLOSED;
return (input->line_number <= cmd->a2->addr_number);
}
@@ -963,40 +963,40 @@ do_list(line_len)
o = obuf;
/* Some locales define 8-bit characters as printable. This makes the
- testsuite fail at 8to7.sed because the `l' command in fact will not
- convert the 8-bit characters. */
+ testsuite fail at 8to7.sed because the `l' command in fact will not
+ convert the 8-bit characters. */
#if defined isascii || defined HAVE_ISASCII
if (isascii(*p) && ISPRINT(*p)) {
#else
if (ISPRINT(*p)) {
#endif
- *o++ = *p;
- if (*p == '\\')
- *o++ = '\\';
+ *o++ = *p;
+ if (*p == '\\')
+ *o++ = '\\';
} else {
- *o++ = '\\';
- switch (*p) {
+ *o++ = '\\';
+ switch (*p) {
#if defined __STDC__ && __STDC__-0
- case '\a': *o++ = 'a'; break;
+ case '\a': *o++ = 'a'; break;
#else /* Not STDC; we'll just assume ASCII */
- case 007: *o++ = 'a'; break;
+ case 007: *o++ = 'a'; break;
#endif
- case '\b': *o++ = 'b'; break;
- case '\f': *o++ = 'f'; break;
- case '\n': *o++ = 'n'; break;
- case '\r': *o++ = 'r'; break;
- case '\t': *o++ = 't'; break;
- case '\v': *o++ = 'v'; break;
- default:
- sprintf(o, "%03o", *p);
- o += strlen(o);
- break;
- }
+ case '\b': *o++ = 'b'; break;
+ case '\f': *o++ = 'f'; break;
+ case '\n': *o++ = 'n'; break;
+ case '\r': *o++ = 'r'; break;
+ case '\t': *o++ = 't'; break;
+ case '\v': *o++ = 'v'; break;
+ default:
+ sprintf(o, "%03o", *p);
+ o += strlen(o);
+ break;
+ }
}
olen = o - obuf;
if (width+olen >= line_len && line_len > 0) {
- ck_fwrite("\\\n", 1, 2, fp);
- width = 0;
+ ck_fwrite("\\\n", 1, 2, fp);
+ width = 0;
}
ck_fwrite(obuf, 1, olen, fp);
width += olen;
@@ -1007,7 +1007,7 @@ do_list(line_len)
static void append_replacement (struct line *buf, struct replacement *p,
- struct re_registers *regs)
+ struct re_registers *regs)
{
enum replacement_types repl_mod = 0;
@@ -1027,23 +1027,23 @@ static void append_replacement (struct line *buf, struct replacement *p,
if (p->prefix_length)
{
str_append_modified(buf, p->prefix, p->prefix_length,
- curr_type);
+ curr_type);
curr_type &= ~REPL_MODIFIERS;
}
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 if (regs->end[i] != regs->start[i])
- str_append_modified(buf, line.active + regs->start[i],
- (size_t)(regs->end[i] - regs->start[i]),
- curr_type);
- }
+ 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],
+ (size_t)(regs->end[i] - regs->start[i]),
+ curr_type);
+ }
}
}
@@ -1064,28 +1064,28 @@ do_subst(sub)
/* The first part of the loop optimizes s/xxx// when xxx is at the
start, and s/xxx$// */
if (!match_regex(sub->regx, line.active, line.length, start,
- &regs, sub->max_id + 1))
+ &regs, sub->max_id + 1))
return;
if (!sub->replacement && sub->numb <= 1)
{
if (regs.start[0] == 0 && !sub->global)
{
- /* We found a match, set the `replaced' flag. */
- replaced = true;
+ /* 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;
+ 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;
+ /* 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;
}
}
@@ -1096,11 +1096,11 @@ do_subst(sub)
/* Copy stuff to the left of this match into the output string. */
if (start < offset)
- str_append(&s_accum, line.active + start, offset - start);
+ str_append(&s_accum, line.active + start, offset - start);
/* If we're counting up to the Nth match, are we there yet?
And even if we are there, there is another case we have to
- skip: are we matching an empty string immediately following
+ skip: are we matching an empty string immediately following
another match?
This latter case avoids that baaaac, when passed through
@@ -1108,41 +1108,41 @@ do_subst(sub)
unacceptable because it is not consistently applied (for
example, `baaaa' gives `xbx', not `xbxx'). */
if ((matched > 0 || count == 0 || offset > last_end)
- && ++count >= sub->numb)
+ && ++count >= sub->numb)
{
/* We found a match, set the `replaced' flag. */
replaced = true;
/* Now expand the replacement string into the output string. */
append_replacement (&s_accum, sub->replacement, &regs);
- again = sub->global;
+ again = sub->global;
}
else
- {
+ {
/* The match was not replaced. Copy the text until its
end; if it was vacuous, skip over one character and
- add that character to the output. */
- if (matched == 0)
- {
- if (start < line.length)
- matched = 1;
- else
- break;
- }
-
- str_append(&s_accum, line.active + offset, matched);
+ add that character to the output. */
+ if (matched == 0)
+ {
+ if (start < line.length)
+ matched = 1;
+ else
+ break;
+ }
+
+ str_append(&s_accum, line.active + offset, matched);
}
/* Start after the match. last_end is the real end of the matched
- substring, excluding characters that were skipped in case the RE
- matched the empty string. */
+ substring, excluding characters that were skipped in case the RE
+ matched the empty string. */
start = offset + matched;
last_end = regs.end[0];
}
while (again
- && start <= line.length
- && match_regex(sub->regx, line.active, line.length, start,
- &regs, sub->max_id + 1));
+ && start <= line.length
+ && match_regex(sub->regx, line.active, line.length, start,
+ &regs, sub->max_id + 1));
/* Copy stuff to the right of the last match into the output string. */
if (start < line.length)
@@ -1171,27 +1171,27 @@ do_subst(sub)
pipe_fp = popen(line.active, "r");
if (pipe_fp != NULL)
- {
- while (!feof (pipe_fp))
- {
- char buf[4096];
- int n = fread (buf, sizeof(char), 4096, pipe_fp);
- if (n > 0)
- str_append(&s_accum, buf, n);
- }
-
- pclose (pipe_fp);
-
- /* Exchange line and s_accum. This can be much cheaper than copying
- s_accum.active into line.text (for huge lines). See comment above
- for 'g' as to while the third argument is incorrect anyway. */
- line_exchange(&line, &s_accum, true);
- if (line.length &&
- line.active[line.length - 1] == buffer_delimiter)
- line.length--;
- }
+ {
+ while (!feof (pipe_fp))
+ {
+ char buf[4096];
+ int n = fread (buf, sizeof(char), 4096, pipe_fp);
+ if (n > 0)
+ str_append(&s_accum, buf, n);
+ }
+
+ pclose (pipe_fp);
+
+ /* Exchange line and s_accum. This can be much cheaper than copying
+ s_accum.active into line.text (for huge lines). See comment above
+ for 'g' as to while the third argument is incorrect anyway. */
+ line_exchange(&line, &s_accum, true);
+ if (line.length &&
+ line.active[line.length - 1] == buffer_delimiter)
+ line.length--;
+ }
else
- panic(_("error in subprocess"));
+ panic(_("error in subprocess"));
#else
panic(_("option `e' not supported"));
#endif
@@ -1220,13 +1220,13 @@ count_branches(program)
while (isn_cnt-- > 0)
{
switch (cur_cmd->cmd)
- {
- case 'b':
- case 't':
- case 'T':
- case '{':
- ++cnt;
- }
+ {
+ case 'b':
+ case 't':
+ case 'T':
+ case '{':
+ ++cnt;
+ }
}
return cnt;
}
@@ -1272,173 +1272,173 @@ execute_program(vec, input)
while (cur_cmd < end_cmd)
{
if (match_address_p(cur_cmd, input) != cur_cmd->addr_bang)
- {
- switch (cur_cmd->cmd)
- {
- case 'a':
- {
- struct append_queue *aq = next_append_slot();
- aq->text = cur_cmd->x.cmd_txt.text;
- aq->textlen = cur_cmd->x.cmd_txt.text_length;
- }
- break;
-
- case '{':
- case 'b':
- cur_cmd = vec->v + cur_cmd->x.jump_index;
- continue;
-
- case '}':
- case '#':
- case ':':
- /* Executing labels and block-ends are easy. */
- break;
-
- case 'c':
- if (cur_cmd->range_state != RANGE_ACTIVE)
- output_line(cur_cmd->x.cmd_txt.text,
- cur_cmd->x.cmd_txt.text_length - 1, true,
- &output_file);
- /* POSIX.2 is silent about c starting a new cycle,
- but it seems to be expected (and make sense). */
- /* Fall Through */
- case 'd':
- return -1;
-
- case 'D':
- {
- char *p = memchr(line.active, buffer_delimiter, line.length);
- if (!p)
- return -1;
-
- ++p;
- line.alloc -= p - line.active;
- line.length -= p - line.active;
- line.active += p - line.active;
-
- /* reset to start next cycle without reading a new line: */
- cur_cmd = vec->v;
- continue;
- }
-
- case 'e': {
+ {
+ switch (cur_cmd->cmd)
+ {
+ case 'a':
+ {
+ struct append_queue *aq = next_append_slot();
+ aq->text = cur_cmd->x.cmd_txt.text;
+ aq->textlen = cur_cmd->x.cmd_txt.text_length;
+ }
+ break;
+
+ case '{':
+ case 'b':
+ cur_cmd = vec->v + cur_cmd->x.jump_index;
+ continue;
+
+ case '}':
+ case '#':
+ case ':':
+ /* Executing labels and block-ends are easy. */
+ break;
+
+ case 'c':
+ if (cur_cmd->range_state != RANGE_ACTIVE)
+ output_line(cur_cmd->x.cmd_txt.text,
+ cur_cmd->x.cmd_txt.text_length - 1, true,
+ &output_file);
+ /* POSIX.2 is silent about c starting a new cycle,
+ but it seems to be expected (and make sense). */
+ /* Fall Through */
+ case 'd':
+ return -1;
+
+ case 'D':
+ {
+ char *p = memchr(line.active, buffer_delimiter, line.length);
+ if (!p)
+ return -1;
+
+ ++p;
+ line.alloc -= p - line.active;
+ line.length -= p - line.active;
+ line.active += p - line.active;
+
+ /* reset to start next cycle without reading a new line: */
+ cur_cmd = vec->v;
+ continue;
+ }
+
+ case 'e': {
#ifdef HAVE_POPEN
- FILE *pipe_fp;
- int cmd_length = cur_cmd->x.cmd_txt.text_length;
- line_reset(&s_accum, NULL);
-
- if (!cmd_length)
- {
- str_append (&line, "", 1);
- pipe_fp = popen(line.active, "r");
- }
- else
- {
- cur_cmd->x.cmd_txt.text[cmd_length - 1] = 0;
- pipe_fp = popen(cur_cmd->x.cmd_txt.text, "r");
+ FILE *pipe_fp;
+ int cmd_length = cur_cmd->x.cmd_txt.text_length;
+ line_reset(&s_accum, NULL);
+
+ if (!cmd_length)
+ {
+ str_append (&line, "", 1);
+ pipe_fp = popen(line.active, "r");
+ }
+ else
+ {
+ cur_cmd->x.cmd_txt.text[cmd_length - 1] = 0;
+ pipe_fp = popen(cur_cmd->x.cmd_txt.text, "r");
output_missing_newline(&output_file);
- }
-
- if (pipe_fp != NULL)
- {
- char buf[4096];
- int n;
- while (!feof (pipe_fp))
- if ((n = fread (buf, sizeof(char), 4096, pipe_fp)) > 0)
- {
- if (!cmd_length)
- str_append(&s_accum, buf, n);
- else
- ck_fwrite(buf, 1, n, output_file.fp);
- }
-
- pclose (pipe_fp);
- if (!cmd_length)
- {
- /* Store into pattern space for plain `e' commands */
- if (s_accum.length &&
- s_accum.active[s_accum.length - 1] == buffer_delimiter)
- s_accum.length--;
-
- /* Exchange line and s_accum. This can be much
- cheaper than copying s_accum.active into line.text
- (for huge lines). See comment above for 'g' as
- to while the third argument is incorrect anyway. */
- line_exchange(&line, &s_accum, true);
- }
+ }
+
+ if (pipe_fp != NULL)
+ {
+ char buf[4096];
+ int n;
+ while (!feof (pipe_fp))
+ if ((n = fread (buf, sizeof(char), 4096, pipe_fp)) > 0)
+ {
+ if (!cmd_length)
+ str_append(&s_accum, buf, n);
+ else
+ ck_fwrite(buf, 1, n, output_file.fp);
+ }
+
+ pclose (pipe_fp);
+ if (!cmd_length)
+ {
+ /* Store into pattern space for plain `e' commands */
+ if (s_accum.length &&
+ s_accum.active[s_accum.length - 1] == buffer_delimiter)
+ s_accum.length--;
+
+ /* Exchange line and s_accum. This can be much
+ cheaper than copying s_accum.active into line.text
+ (for huge lines). See comment above for 'g' as
+ to while the third argument is incorrect anyway. */
+ line_exchange(&line, &s_accum, true);
+ }
else
flush_output(output_file.fp);
- }
- else
- panic(_("error in subprocess"));
+ }
+ else
+ panic(_("error in subprocess"));
#else
- panic(_("`e' command not supported"));
+ panic(_("`e' command not supported"));
#endif
- break;
- }
-
- case 'g':
- /* We do not have a really good choice for the third parameter.
- The problem is that hold space and the input file might as
- well have different states; copying it from hold space means
- that subsequent input might be read incorrectly, while
- keeping it as in pattern space means that commands operating
- on the moved buffer might consider a wrong character set.
- We keep it true because it's what sed <= 4.1.5 did. */
- line_copy(&hold, &line, true);
- break;
-
- case 'G':
- /* We do not have a really good choice for the third parameter.
- The problem is that hold space and pattern space might as
- well have different states. So, true is as wrong as false.
- We keep it true because it's what sed <= 4.1.5 did, but
- we could consider having line_ap. */
- line_append(&hold, &line, true);
- break;
-
- case 'h':
- /* Here, it is ok to have true. */
- line_copy(&line, &hold, true);
- break;
-
- case 'H':
- /* See comment above for 'G' regarding the third parameter. */
- line_append(&line, &hold, true);
- break;
-
- case 'i':
- output_line(cur_cmd->x.cmd_txt.text,
- cur_cmd->x.cmd_txt.text_length - 1,
- true, &output_file);
- break;
-
- case 'l':
- do_list(cur_cmd->x.int_arg == -1
- ? lcmd_out_line_len
- : cur_cmd->x.int_arg);
- break;
-
- case 'L':
+ break;
+ }
+
+ case 'g':
+ /* We do not have a really good choice for the third parameter.
+ The problem is that hold space and the input file might as
+ well have different states; copying it from hold space means
+ that subsequent input might be read incorrectly, while
+ keeping it as in pattern space means that commands operating
+ on the moved buffer might consider a wrong character set.
+ We keep it true because it's what sed <= 4.1.5 did. */
+ line_copy(&hold, &line, true);
+ break;
+
+ case 'G':
+ /* We do not have a really good choice for the third parameter.
+ The problem is that hold space and pattern space might as
+ well have different states. So, true is as wrong as false.
+ We keep it true because it's what sed <= 4.1.5 did, but
+ we could consider having line_ap. */
+ line_append(&hold, &line, true);
+ break;
+
+ case 'h':
+ /* Here, it is ok to have true. */
+ line_copy(&line, &hold, true);
+ break;
+
+ case 'H':
+ /* See comment above for 'G' regarding the third parameter. */
+ line_append(&line, &hold, true);
+ break;
+
+ case 'i':
+ output_line(cur_cmd->x.cmd_txt.text,
+ cur_cmd->x.cmd_txt.text_length - 1,
+ true, &output_file);
+ break;
+
+ case 'l':
+ do_list(cur_cmd->x.int_arg == -1
+ ? lcmd_out_line_len
+ : cur_cmd->x.int_arg);
+ break;
+
+ case 'L':
output_missing_newline(&output_file);
- fmt(line.active, line.active + line.length,
- cur_cmd->x.int_arg == -1
- ? lcmd_out_line_len
- : cur_cmd->x.int_arg,
- output_file.fp);
+ fmt(line.active, line.active + line.length,
+ cur_cmd->x.int_arg == -1
+ ? lcmd_out_line_len
+ : cur_cmd->x.int_arg,
+ output_file.fp);
flush_output(output_file.fp);
- break;
+ break;
- case 'n':
- if (!no_default_output)
- output_line(line.active, line.length, line.chomped, &output_file);
- if (test_eof(input) || !read_pattern_space(input, vec, false))
- return -1;
- break;
+ case 'n':
+ if (!no_default_output)
+ output_line(line.active, line.length, line.chomped, &output_file);
+ if (test_eof(input) || !read_pattern_space(input, vec, false))
+ return -1;
+ break;
- case 'N':
- str_append(&line, &buffer_delimiter, 1);
+ case 'N':
+ str_append(&line, &buffer_delimiter, 1);
if (test_eof(input) || !read_pattern_space(input, vec, true))
{
@@ -1448,101 +1448,101 @@ execute_program(vec, input)
&output_file);
return -1;
}
- break;
+ break;
- case 'p':
- output_line(line.active, line.length, line.chomped, &output_file);
- break;
+ case 'p':
+ output_line(line.active, line.length, line.chomped, &output_file);
+ break;
- case 'P':
- {
- char *p = memchr(line.active, buffer_delimiter, line.length);
- output_line(line.active, p ? p - line.active : line.length,
- p ? true : line.chomped, &output_file);
- }
- break;
+ case 'P':
+ {
+ char *p = memchr(line.active, buffer_delimiter, line.length);
+ output_line(line.active, p ? p - line.active : line.length,
+ p ? true : line.chomped, &output_file);
+ }
+ break;
case 'q':
if (!no_default_output)
output_line(line.active, line.length, line.chomped, &output_file);
- dump_append_queue();
-
- case 'Q':
- return cur_cmd->x.int_arg == -1 ? 0 : cur_cmd->x.int_arg;
-
- case 'r':
- if (cur_cmd->x.fname)
- {
- struct append_queue *aq = next_append_slot();
- aq->fname = cur_cmd->x.fname;
- }
- break;
-
- case 'R':
- if (cur_cmd->x.fp && !feof (cur_cmd->x.fp))
- {
- struct append_queue *aq;
- size_t buflen;
- char *text = NULL;
- int result;
-
- result = ck_getdelim (&text, &buflen, buffer_delimiter,
- cur_cmd->x.fp);
- if (result != EOF)
- {
- aq = next_append_slot();
- aq->free = true;
- aq->text = text;
- aq->textlen = result;
- }
- }
- break;
-
- case 's':
- do_subst(cur_cmd->x.cmd_subst);
- break;
-
- case 't':
- if (replaced)
- {
- replaced = false;
- cur_cmd = vec->v + cur_cmd->x.jump_index;
- continue;
- }
- break;
-
- case 'T':
- if (!replaced)
- {
- cur_cmd = vec->v + cur_cmd->x.jump_index;
- continue;
- }
- else
- replaced = false;
- break;
-
- case 'w':
- if (cur_cmd->x.fp)
- output_line(line.active, line.length,
- line.chomped, cur_cmd->x.outf);
- break;
-
- case 'W':
- if (cur_cmd->x.fp)
- {
- char *p = memchr(line.active, buffer_delimiter, line.length);
- output_line(line.active, p ? p - line.active : line.length,
- p ? true : line.chomped, cur_cmd->x.outf);
- }
- break;
-
- case 'x':
- /* See comment above for 'g' regarding the third parameter. */
- line_exchange(&line, &hold, false);
- break;
-
- case 'y':
- {
+ dump_append_queue();
+
+ case 'Q':
+ return cur_cmd->x.int_arg == -1 ? 0 : cur_cmd->x.int_arg;
+
+ case 'r':
+ if (cur_cmd->x.fname)
+ {
+ struct append_queue *aq = next_append_slot();
+ aq->fname = cur_cmd->x.fname;
+ }
+ break;
+
+ case 'R':
+ if (cur_cmd->x.fp && !feof (cur_cmd->x.fp))
+ {
+ struct append_queue *aq;
+ size_t buflen;
+ char *text = NULL;
+ int result;
+
+ result = ck_getdelim (&text, &buflen, buffer_delimiter,
+ cur_cmd->x.fp);
+ if (result != EOF)
+ {
+ aq = next_append_slot();
+ aq->free = true;
+ aq->text = text;
+ aq->textlen = result;
+ }
+ }
+ break;
+
+ case 's':
+ do_subst(cur_cmd->x.cmd_subst);
+ break;
+
+ case 't':
+ if (replaced)
+ {
+ replaced = false;
+ cur_cmd = vec->v + cur_cmd->x.jump_index;
+ continue;
+ }
+ break;
+
+ case 'T':
+ if (!replaced)
+ {
+ cur_cmd = vec->v + cur_cmd->x.jump_index;
+ continue;
+ }
+ else
+ replaced = false;
+ break;
+
+ case 'w':
+ if (cur_cmd->x.fp)
+ output_line(line.active, line.length,
+ line.chomped, cur_cmd->x.outf);
+ break;
+
+ case 'W':
+ if (cur_cmd->x.fp)
+ {
+ char *p = memchr(line.active, buffer_delimiter, line.length);
+ output_line(line.active, p ? p - line.active : line.length,
+ p ? true : line.chomped, cur_cmd->x.outf);
+ }
+ break;
+
+ case 'x':
+ /* See comment above for 'g' regarding the third parameter. */
+ line_exchange(&line, &hold, false);
+ break;
+
+ case 'y':
+ {
if (mb_cur_max > 1)
{
int idx, prev_idx; /* index in the input line. */
@@ -1617,14 +1617,14 @@ execute_program(vec, input)
for (e=p+line.length; p<e; ++p)
*p = cur_cmd->x.translate[*p];
}
- }
- break;
+ }
+ break;
- case 'z':
- line.length = 0;
- break;
+ case 'z':
+ line.length = 0;
+ break;
- case '=':
+ case '=':
output_missing_newline(&output_file);
fprintf(output_file.fp, "%lu\n",
(unsigned long)input->line_number);
@@ -1641,7 +1641,7 @@ execute_program(vec, input)
default:
panic("INTERNAL ERROR: Bad cmd %c", cur_cmd->cmd);
}
- }
+ }
#ifdef EXPERIMENTAL_DASH_N_OPTIMIZATION
/* If our top-level program consists solely of commands with
@@ -1658,37 +1658,37 @@ execute_program(vec, input)
Don't use this when in-place editing is active, because line
numbers restart each time then. */
else if (!separate_files)
- {
- if (cur_cmd->a1->addr_type == ADDR_IS_NUM
- && (cur_cmd->a2
- ? cur_cmd->range_state == RANGE_CLOSED
- : cur_cmd->a1->addr_number < input->line_number))
- {
- /* Skip this address next time */
- cur_cmd->addr_bang = !cur_cmd->addr_bang;
- cur_cmd->a1->addr_type = ADDR_IS_NULL;
- if (cur_cmd->a2)
- cur_cmd->a2->addr_type = ADDR_IS_NULL;
-
- /* can we make an optimization? */
- if (cur_cmd->addr_bang)
- {
- if (cur_cmd->cmd == 'b' || cur_cmd->cmd == 't'
- || cur_cmd->cmd == 'T' || cur_cmd->cmd == '}')
- branches--;
-
- cur_cmd->cmd = '#'; /* replace with no-op */
- if (branches == 0)
- cur_cmd = shrink_program(vec, cur_cmd);
- if (!cur_cmd && no_default_output)
- return 0;
- end_cmd = vec->v + vec->v_length;
- if (!cur_cmd)
- cur_cmd = end_cmd;
- continue;
- }
- }
- }
+ {
+ if (cur_cmd->a1->addr_type == ADDR_IS_NUM
+ && (cur_cmd->a2
+ ? cur_cmd->range_state == RANGE_CLOSED
+ : cur_cmd->a1->addr_number < input->line_number))
+ {
+ /* Skip this address next time */
+ cur_cmd->addr_bang = !cur_cmd->addr_bang;
+ cur_cmd->a1->addr_type = ADDR_IS_NULL;
+ if (cur_cmd->a2)
+ cur_cmd->a2->addr_type = ADDR_IS_NULL;
+
+ /* can we make an optimization? */
+ if (cur_cmd->addr_bang)
+ {
+ if (cur_cmd->cmd == 'b' || cur_cmd->cmd == 't'
+ || cur_cmd->cmd == 'T' || cur_cmd->cmd == '}')
+ branches--;
+
+ cur_cmd->cmd = '#'; /* replace with no-op */
+ if (branches == 0)
+ cur_cmd = shrink_program(vec, cur_cmd);
+ if (!cur_cmd && no_default_output)
+ return 0;
+ end_cmd = vec->v + vec->v_length;
+ if (!cur_cmd)
+ cur_cmd = end_cmd;
+ continue;
+ }
+ }
+ }
#endif /*EXPERIMENTAL_DASH_N_OPTIMIZATION*/
/* this is buried down here so that a "continue" statement can skip it */
@@ -1738,9 +1738,9 @@ process_files(the_program, argv)
{
status = execute_program(the_program, &input);
if (status == -1)
- status = EXIT_SUCCESS;
+ status = EXIT_SUCCESS;
else
- break;
+ break;
}
closedown(&input);
diff --git a/sed/fmt.c b/sed/fmt.c
index 24fd4d2..eea55ec 100644
--- a/sed/fmt.c
+++ b/sed/fmt.c
@@ -235,10 +235,10 @@ get_paragraph ()
{
c = copy_rest (c);
if (c == EOF)
- {
- next_char = EOF;
- return false;
- }
+ {
+ next_char = EOF;
+ return false;
+ }
putc ('\n', outfile);
c = GETC();
}
@@ -308,7 +308,7 @@ get_line (register int c)
word_limit->text = parabuf - 1;
do
- c = GETC();
+ c = GETC();
while (c != EOF && !ISSPACE (c));
word_limit->length = parabuf - word_limit->text - (c != EOF);
in_column += word_limit->length;
@@ -321,18 +321,18 @@ get_line (register int c)
c = get_space (c);
word_limit->space = in_column - start;
word_limit->final = (c == EOF
- || (word_limit->period
- && (c == '\n' || word_limit->space > 1)));
+ || (word_limit->period
+ && (c == '\n' || word_limit->space > 1)));
if (c == '\n' || c == EOF)
- word_limit->space = word_limit->final ? 2 : 1;
+ word_limit->space = word_limit->final ? 2 : 1;
if (word_limit == end_of_word)
- flush_paragraph ();
+ flush_paragraph ();
word_limit++;
if (c == EOF)
- {
- in_column = first_indent;
- return EOF;
- }
+ {
+ in_column = first_indent;
+ return EOF;
+ }
}
while (c != '\n');
@@ -350,11 +350,11 @@ get_space (register int c)
for (;;)
{
if (c == ' ')
- in_column++;
+ in_column++;
else if (c == '\t')
- in_column = (in_column / TABWIDTH + 1) * TABWIDTH;
+ in_column = (in_column / TABWIDTH + 1) * TABWIDTH;
else
- return c;
+ return c;
c = GETC();
}
}
@@ -399,12 +399,12 @@ flush_paragraph (void)
for (w = words->next_break; w != word_limit; w = w->next_break)
{
if (w->best_cost - w->next_break->best_cost < best_break)
- {
- split_point = w;
- best_break = w->best_cost - w->next_break->best_cost;
- }
+ {
+ split_point = w;
+ best_break = w->best_cost - w->next_break->best_cost;
+ }
if (best_break <= MAXCOST - LINE_CREDIT)
- best_break += LINE_CREDIT;
+ best_break += LINE_CREDIT;
}
put_paragraph (split_point);
@@ -412,7 +412,7 @@ flush_paragraph (void)
the source and target may overlap. */
memmove ((char *) words, (char *) split_point,
- (word_limit - split_point + 1) * sizeof (WORD));
+ (word_limit - split_point + 1) * sizeof (WORD));
word_limit -= split_point - words;
}
@@ -442,22 +442,22 @@ fmt_paragraph (void)
w = start;
len += w->length;
do
- {
- w++;
-
- /* Consider breaking before w. */
-
- wcost = line_cost (w, len) + w->best_cost;
- if (start == words && last_line_length > 0)
- wcost += RAGGED_COST (len - last_line_length);
- if (wcost < best)
- {
- best = wcost;
- start->next_break = w;
- start->line_length = len;
- }
- len += (w - 1)->space + w->length; /* w > start >= words */
- }
+ {
+ w++;
+
+ /* Consider breaking before w. */
+
+ wcost = line_cost (w, len) + w->best_cost;
+ if (start == words && last_line_length > 0)
+ wcost += RAGGED_COST (len - last_line_length);
+ if (wcost < best)
+ {
+ best = wcost;
+ start->next_break = w;
+ start->line_length = len;
+ }
+ len += (w - 1)->space + w->length; /* w > start >= words */
+ }
while (len < max_width);
start->best_cost = best + base_cost (start);
}
@@ -478,16 +478,16 @@ base_cost (register WORD *this)
if (this > words)
{
if ((this - 1)->period)
- {
- if ((this - 1)->final)
- cost -= SENTENCE_BONUS;
- else
- cost += NOBREAK_COST;
- }
+ {
+ if ((this - 1)->final)
+ cost -= SENTENCE_BONUS;
+ else
+ cost += NOBREAK_COST;
+ }
else if ((this - 1)->punct)
- cost -= PUNCT_BONUS;
+ cost -= PUNCT_BONUS;
else if (this > words + 1 && (this - 2)->final)
- cost += WIDOW_COST ((this - 1)->length);
+ cost += WIDOW_COST ((this - 1)->length);
}
if (this->paren)
diff --git a/sed/regexp.c b/sed/regexp.c
index 827c699..428315f 100644
--- a/sed/regexp.c
+++ b/sed/regexp.c
@@ -49,9 +49,9 @@ compile_regex_1 (new_regex, needed_sub)
#ifdef REG_PERL
int errcode;
errcode = regncomp(&new_regex->pattern, new_regex->re, new_regex->sz,
- (needed_sub ? 0 : REG_NOSUB)
- | new_regex->flags
- | extended_regexp_flags);
+ (needed_sub ? 0 : REG_NOSUB)
+ | new_regex->flags
+ | extended_regexp_flags);
if (errcode)
{
@@ -62,7 +62,7 @@ compile_regex_1 (new_regex, needed_sub)
#else
const char *error;
int syntax = ((extended_regexp_flags & REG_EXTENDED)
- ? RE_SYNTAX_POSIX_EXTENDED
+ ? RE_SYNTAX_POSIX_EXTENDED
: RE_SYNTAX_POSIX_BASIC);
syntax &= ~RE_DOT_NOT_NULL;
@@ -100,7 +100,7 @@ compile_regex_1 (new_regex, needed_sub)
re_set_syntax (syntax);
error = re_compile_pattern (new_regex->re, new_regex->sz,
- &new_regex->pattern);
+ &new_regex->pattern);
new_regex->pattern.newline_anchor = (new_regex->flags & REG_NEWLINE) != 0;
new_regex->pattern.translate = NULL;
@@ -110,7 +110,7 @@ compile_regex_1 (new_regex, needed_sub)
static char translate[1 << (sizeof(char) * 8)];
int i;
for (i = 0; i < sizeof(translate) / sizeof(char); i++)
- translate[i] = tolower (i);
+ translate[i] = tolower (i);
new_regex->pattern.translate = translate;
}
@@ -127,7 +127,7 @@ compile_regex_1 (new_regex, needed_sub)
{
char buf[200];
sprintf(buf, _("invalid reference \\%d on `s' command's RHS"),
- needed_sub - 1);
+ needed_sub - 1);
bad_prog(buf);
}
}
@@ -145,7 +145,7 @@ compile_regex(b, flags, needed_sub)
if (size_buffer(b) == 0)
{
if (flags > 0)
- bad_prog(_(BAD_MODIF));
+ bad_prog(_(BAD_MODIF));
return NULL;
}
@@ -227,7 +227,7 @@ match_regex(regex, buf, buflen, buf_start_offset, regarray, regsize)
{
regex = regex_last;
if (!regex_last)
- bad_prog(_(NO_REGEX));
+ bad_prog(_(NO_REGEX));
}
else
regex_last = regex;
@@ -248,8 +248,8 @@ match_regex(regex, buf, buflen, buf_start_offset, regarray, regsize)
regex->pattern.regs_allocated = REGS_REALLOCATE;
ret = re_search (&regex->pattern, buf, buflen, buf_start_offset,
- buflen - buf_start_offset,
- regsize ? regarray : NULL);
+ buflen - buf_start_offset,
+ regsize ? regarray : NULL);
return (ret > -1);
#endif
diff --git a/sed/sed.c b/sed/sed.c
index 71713ac..b360654 100644
--- a/sed/sed.c
+++ b/sed/sed.c
@@ -85,7 +85,7 @@ General help using GNU software: <http://www.gnu.org/gethelp/>.\n"));
if (!errmsg)
fprintf(out, _("E-mail bug reports to: <%s>.\n\
Be sure to include the word ``%s'' somewhere in the ``Subject:'' field.\n"),
- PACKAGE_BUGREPORT, PACKAGE);
+ PACKAGE_BUGREPORT, PACKAGE);
}
static void usage (int);
@@ -222,108 +222,108 @@ main(argc, argv)
{
countT t = atoi(cols);
if (t > 1)
- lcmd_out_line_len = t-1;
+ lcmd_out_line_len = t-1;
}
myname = *argv;
while ((opt = getopt_long(argc, argv, SHORTOPTS, longopts, NULL)) != EOF)
{
switch (opt)
- {
- case 'n':
- no_default_output = true;
- break;
- case 'e':
- the_program = compile_string(the_program, optarg, strlen(optarg));
- break;
- case 'f':
- the_program = compile_file(the_program, optarg);
- break;
-
- case 'z':
- buffer_delimiter = 0;
- break;
-
- case 'F':
- follow_symlinks = true;
- break;
-
- case 'i':
- separate_files = true;
- if (optarg == NULL)
- /* use no backups */
- in_place_extension = ck_strdup ("*");
-
- else if (strchr(optarg, '*') != NULL)
- in_place_extension = ck_strdup(optarg);
-
- else
- {
- in_place_extension = MALLOC (strlen(optarg) + 2, char);
- in_place_extension[0] = '*';
- strcpy (in_place_extension + 1, optarg);
- }
-
- break;
-
- case 'l':
- lcmd_out_line_len = atoi(optarg);
- break;
-
- case 'p':
- posixicity = POSIXLY_BASIC;
- break;
+ {
+ case 'n':
+ no_default_output = true;
+ break;
+ case 'e':
+ the_program = compile_string(the_program, optarg, strlen(optarg));
+ break;
+ case 'f':
+ the_program = compile_file(the_program, optarg);
+ break;
+
+ case 'z':
+ buffer_delimiter = 0;
+ break;
+
+ case 'F':
+ follow_symlinks = true;
+ break;
+
+ case 'i':
+ separate_files = true;
+ if (optarg == NULL)
+ /* use no backups */
+ in_place_extension = ck_strdup ("*");
+
+ else if (strchr(optarg, '*') != NULL)
+ in_place_extension = ck_strdup(optarg);
+
+ else
+ {
+ in_place_extension = MALLOC (strlen(optarg) + 2, char);
+ in_place_extension[0] = '*';
+ strcpy (in_place_extension + 1, optarg);
+ }
+
+ break;
+
+ case 'l':
+ lcmd_out_line_len = atoi(optarg);
+ break;
+
+ case 'p':
+ posixicity = POSIXLY_BASIC;
+ break;
case 'b':
- read_mode = "rb";
- write_mode = "wb";
- break;
+ read_mode = "rb";
+ write_mode = "wb";
+ break;
- case 'E':
- case 'r':
- if (extended_regexp_flags)
- usage(4);
- extended_regexp_flags = REG_EXTENDED;
- break;
+ case 'E':
+ case 'r':
+ if (extended_regexp_flags)
+ usage(4);
+ extended_regexp_flags = REG_EXTENDED;
+ break;
#ifdef REG_PERL
- case 'R':
- if (extended_regexp_flags)
- usage(4);
- extended_regexp_flags = REG_PERL;
- break;
+ case 'R':
+ if (extended_regexp_flags)
+ usage(4);
+ extended_regexp_flags = REG_PERL;
+ break;
#endif
- case 's':
- separate_files = true;
- break;
+ case 's':
+ separate_files = true;
+ break;
- case 'u':
- unbuffered = true;
- break;
+ case 'u':
+ unbuffered = true;
+ break;
- case 'v':
+ case 'v':
version_etc(stdout, program_name, PACKAGE_NAME, VERSION,
AUTHORS, (char *) NULL);
- contact(false);
- ck_fclose (NULL);
- exit (0);
- case 'h':
- usage(0);
- default:
- usage(4);
- }
+ contact(false);
+ ck_fclose (NULL);
+ exit (0);
+ case 'h':
+ usage(0);
+ default:
+ usage(4);
+ }
}
if (!the_program)
{
if (optind < argc)
- {
- char *arg = argv[optind++];
- the_program = compile_string(the_program, arg, strlen(arg));
- }
+ {
+ char *arg = argv[optind++];
+ the_program = compile_string(the_program, arg, strlen(arg));
+ }
else
- usage(4);
+ usage(4);
}
check_final_program(the_program);
diff --git a/sed/sed.h b/sed/sed.h
index 9d6e2fe..152e1f1 100644
--- a/sed/sed.h
+++ b/sed/sed.h
@@ -191,8 +191,8 @@ void finish_program (struct vector *);
struct regex *compile_regex (struct buffer *b, int flags, int needed_sub);
int match_regex (struct regex *regex,
- char *buf, size_t buflen, size_t buf_start_offset,
- struct re_registers *regarray, int regsize);
+ char *buf, size_t buflen, size_t buf_start_offset,
+ struct re_registers *regarray, int regsize);
#ifdef DEBUG_LEAKS
void release_regex (struct regex *);
#endif
diff --git a/sed/utils.c b/sed/utils.c
index dbf3e14..a681c0d 100644
--- a/sed/utils.c
+++ b/sed/utils.c
@@ -65,13 +65,13 @@ panic(const char *str, ...)
while (open_files)
{
if (open_files->temp)
- {
- fclose (open_files->fp);
- errno = 0;
- unlink (open_files->name);
+ {
+ fclose (open_files->fp);
+ errno = 0;
+ unlink (open_files->name);
if (errno != 0)
fprintf (stderr, _("cannot remove %s: %s"), open_files->name, strerror (errno));
- }
+ }
open_files = open_files->link;
}
@@ -111,10 +111,10 @@ register_open_file (fp, name, temp)
for (p=open_files; p; p=p->link)
{
if (fp == p->fp)
- {
- free(p->name);
- break;
- }
+ {
+ free(p->name);
+ break;
+ }
}
if (!p)
{
@@ -190,9 +190,9 @@ ck_mkstemp (p_filename, tmpdir, base, mode)
tmpdir = getenv("TMP");
if (tmpdir == NULL)
#ifdef P_tmpdir
- tmpdir = P_tmpdir;
+ tmpdir = P_tmpdir;
#else
- tmpdir = "/tmp";
+ tmpdir = "/tmp";
#endif
}
@@ -226,8 +226,8 @@ ck_fwrite(ptr, size, nmemb, stream)
clearerr(stream);
if (size && fwrite(ptr, size, nmemb, stream) != nmemb)
panic(ngettext("couldn't write %d item to %s: %s",
- "couldn't write %d items to %s: %s", nmemb),
- nmemb, utils_fp_name(stream), strerror(errno));
+ "couldn't write %d items to %s: %s", nmemb),
+ nmemb, utils_fp_name(stream), strerror(errno));
}
/* Panic on failing fread */
@@ -296,14 +296,14 @@ ck_fclose(stream)
while ( (cur = prev->link) )
{
if (!stream || stream == cur->fp)
- {
- do_ck_fclose (cur->fp);
- prev->link = cur->link;
- free(cur->name);
- free(cur);
- }
+ {
+ do_ck_fclose (cur->fp);
+ prev->link = cur->link;
+ free(cur->name);
+ free(cur);
+ }
else
- prev = cur;
+ prev = cur;
}
open_files = r.link;
@@ -368,37 +368,37 @@ follow_symlink(const char *fname)
buf2 = ck_realloc (buf2, buf_size);
}
if (rc < 0)
- panic (_("couldn't follow symlink %s: %s"), buf, strerror(errno));
+ panic (_("couldn't follow symlink %s: %s"), buf, strerror(errno));
else
- buf2 [rc] = '\0';
+ buf2 [rc] = '\0';
if (buf2[0] != '/' && (c = strrchr (buf, '/')) != NULL)
- {
- /* Need to handle relative paths with care. Reallocate buf1 and
- buf2 to be big enough. */
- int len = c - buf + 1;
- if (len + rc + 1 > buf_size)
- {
- buf_size = len + rc + 1;
- buf1 = ck_realloc (buf1, buf_size);
- buf2 = ck_realloc (buf2, buf_size);
- }
-
- /* Always store the new path in buf1. */
- if (buf != buf1)
+ {
+ /* Need to handle relative paths with care. Reallocate buf1 and
+ buf2 to be big enough. */
+ int len = c - buf + 1;
+ if (len + rc + 1 > buf_size)
+ {
+ buf_size = len + rc + 1;
+ buf1 = ck_realloc (buf1, buf_size);
+ buf2 = ck_realloc (buf2, buf_size);
+ }
+
+ /* Always store the new path in buf1. */
+ if (buf != buf1)
memcpy (buf1, buf, len);
/* Tack the relative symlink at the end of buf1. */
memcpy (buf1 + len, buf2, rc + 1);
- buf = buf1;
- }
+ buf = buf1;
+ }
else
- {
- /* Use buf2 as the buffer, it saves a strcpy if it is not pointing to
- another link. It works for absolute symlinks, and as long as
- symlinks do not leave the current directory. */
- buf = buf2;
- }
+ {
+ /* Use buf2 as the buffer, it saves a strcpy if it is not pointing to
+ another link. It works for absolute symlinks, and as long as
+ symlinks do not leave the current directory. */
+ buf = buf2;
+ }
}
if (rc < 0)
@@ -579,7 +579,7 @@ add1_buffer(b, c)
{
char *result;
if (b->allocated - b->length < 1)
- resize_buffer(b, b->length+1);
+ resize_buffer(b, b->length+1);
result = b->b + b->length++;
*result = c;
return result;
diff --git a/sed/utils.h b/sed/utils.h
index addf8bd..bf0981c 100644
--- a/sed/utils.h
+++ b/sed/utils.h
@@ -31,7 +31,7 @@ void ck_fclose (FILE *stream);
const char *follow_symlink (const char *path);
size_t ck_getdelim (char **text, size_t *buflen, char buffer_delimiter, FILE *stream);
FILE * ck_mkstemp (char **p_filename, const char *tmpdir, const char *base,
- const char *mode);
+ const char *mode);
void ck_rename (const char *from, const char *to, const char *unlink_if_fail);
void *ck_malloc (size_t size);