summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2014-11-06 17:05:35 -0600
committerJim Meyering <meyering@fb.com>2014-11-30 20:47:09 -0800
commit366b04cabde35bf06d1cb3c9b35d7f2f1d094aea (patch)
tree993d2459b09b2edb3571619917bc9f8121fd92d6
parent1743b7f3cb96a25a68ea8b230c2c322d8538ba1e (diff)
downloadsed-366b04cabde35bf06d1cb3c9b35d7f2f1d094aea.tar.gz
maint: manually convert K&R to ANSI style decls; and add "static"
Convert many function definitions from K&R to ANSI style. When possible, make a function static and remove the immediately- preceding declaration of that same function. Also, add the const to a few declarations. * sed/compile.c: As above. (special_files): Likewise. * sed/execute.c: Likewise. * sed/fmt.c: Likewise. * sed/mbcs.c: Likewise. * sed/regexp.c: Likewise. * sed/sed.c: Likewise. * sed/sed.h: Likewise. * sed/utils.c: Likewise.
-rw-r--r--sed/compile.c123
-rw-r--r--sed/execute.c128
-rw-r--r--sed/fmt.c2
-rw-r--r--sed/mbcs.c6
-rw-r--r--sed/regexp.c19
-rw-r--r--sed/sed.c19
-rw-r--r--sed/sed.h4
-rw-r--r--sed/utils.c96
8 files changed, 99 insertions, 298 deletions
diff --git a/sed/compile.c b/sed/compile.c
index 6cb1783..f33e825 100644
--- a/sed/compile.c
+++ b/sed/compile.c
@@ -79,8 +79,8 @@ struct special_files {
FILE **pfp;
};
-FILE *my_stdin, *my_stdout, *my_stderr;
-struct special_files special_files[] = {
+static FILE *my_stdin, *my_stdout, *my_stderr;
+static const struct special_files special_files[] = {
{ { "/dev/stdin", false, NULL, NULL }, &my_stdin },
{ { "/dev/stdout", false, NULL, NULL }, &my_stdout },
{ { "/dev/stderr", false, NULL, NULL }, &my_stderr },
@@ -174,9 +174,8 @@ static struct output *file_write = NULL;
/* Complain about an unknown command and exit. */
-void
-bad_command(ch)
- char ch;
+static void
+bad_command(char ch)
{
const char *msg = _(UNKNOWN_CMD);
char *unknown_cmd = xmalloc(strlen(msg));
@@ -186,8 +185,7 @@ bad_command(ch)
/* Complain about a programming error and exit. */
void
-bad_prog(why)
- const char *why;
+bad_prog(const char *why)
{
if (cur_input.name)
fprintf(stderr, _("%s: file %s line %lu: %s\n"),
@@ -205,9 +203,8 @@ bad_prog(why)
/* Read the next character from the program. Return EOF if there isn't
anything to read. Keep cur_input.line up to date, so error messages
can be meaningful. */
-static int inchar (void);
static int
-inchar()
+inchar(void)
{
int ch = EOF;
@@ -227,10 +224,8 @@ inchar()
}
/* unget `ch' so the next call to inchar will return it. */
-static void savchar (int ch);
static void
-savchar(ch)
- int ch;
+savchar(int ch)
{
if (ch == EOF)
return;
@@ -247,9 +242,8 @@ savchar(ch)
}
/* Read the next non-blank character from the program. */
-static int in_nonblank (void);
static int
-in_nonblank()
+in_nonblank(void)
{
int ch;
do
@@ -259,10 +253,8 @@ in_nonblank()
}
/* Read an integer value from the program. */
-static countT in_integer (int ch);
static countT
-in_integer(ch)
- int ch;
+in_integer (int ch)
{
countT num = 0;
@@ -275,23 +267,15 @@ in_integer(ch)
return num;
}
-static int add_then_next (struct buffer *b, int ch);
static int
-add_then_next(b, ch)
- struct buffer *b;
- int ch;
+add_then_next(struct buffer *b, int ch)
{
add1_buffer(b, ch);
return inchar();
}
-static char * convert_number (char *, char *, const char *, int);
static char *
-convert_number(result, buf, bufend, base)
- char *result;
- char *buf;
- const char *bufend;
- int base;
+convert_number(char *result, char *buf, const char *bufend, int base)
{
int n = 0;
int max = 1;
@@ -332,9 +316,8 @@ convert_number(result, buf, bufend, base)
/* Read in a filename for a `r', `w', or `s///w' command. */
-static struct buffer *read_filename (void);
static struct buffer *
-read_filename()
+read_filename(void)
{
struct buffer *b;
int ch;
@@ -357,12 +340,8 @@ read_filename()
return b;
}
-static struct output *get_openfile (struct output **file_ptrs, const char *mode, int fail);
static struct output *
-get_openfile(file_ptrs, mode, fail)
- struct output **file_ptrs;
- const char *mode;
- int fail;
+get_openfile (struct output **file_ptrs, const char *mode, int fail)
{
struct buffer *b;
char *file_name;
@@ -405,10 +384,8 @@ get_openfile(file_ptrs, mode, fail)
}
-static struct sed_cmd *next_cmd_entry (struct vector **vectorp);
static struct sed_cmd *
-next_cmd_entry(vectorp)
- struct vector **vectorp;
+next_cmd_entry (struct vector **vectorp)
{
struct sed_cmd *cmd;
struct vector *v;
@@ -431,11 +408,8 @@ next_cmd_entry(vectorp)
return cmd;
}
-static int snarf_char_class (struct buffer *b, mbstate_t *cur_stat);
static int
-snarf_char_class(b, cur_stat)
- struct buffer *b;
- mbstate_t *cur_stat;
+snarf_char_class (struct buffer *b, mbstate_t *cur_stat)
{
int ch;
int state = 0;
@@ -512,11 +486,8 @@ snarf_char_class(b, cur_stat)
}
}
-static struct buffer *match_slash (int slash, int regex);
static struct buffer *
-match_slash(slash, regex)
- int slash;
- int regex;
+match_slash (int slash, int regex)
{
struct buffer *b;
int ch;
@@ -568,10 +539,8 @@ match_slash(slash, regex)
return NULL;
}
-static int mark_subst_opts (struct subst *cmd);
static int
-mark_subst_opts(cmd)
- struct subst *cmd;
+mark_subst_opts (struct subst *cmd)
{
int flags = 0;
int ch;
@@ -668,9 +637,8 @@ mark_subst_opts(cmd)
/* read in a label for a `:', `b', or `t' command */
-static char *read_label (void);
static char *
-read_label()
+read_label (void)
{
struct buffer *b;
int ch;
@@ -694,14 +662,9 @@ read_label()
command so that the jump to/from the label can be backpatched after
compilation is complete, or a reference created by a `{' to be
backpatched when the corresponding `}' is found. */
-static struct sed_label *setup_label
- (struct sed_label *, countT, char *, const struct error_info *);
static struct sed_label *
-setup_label(list, idx, name, err_info)
- struct sed_label *list;
- countT idx;
- char *name;
- const struct error_info *err_info;
+setup_label(struct sed_label *list, countT idx, char *name,
+ const struct error_info *err_info)
{
struct sed_label *ret = OB_MALLOC(&obs, 1, struct sed_label);
ret->v_index = idx;
@@ -712,10 +675,8 @@ setup_label(list, idx, name, err_info)
return ret;
}
-static struct sed_label *release_label (struct sed_label *list_head);
static struct sed_label *
-release_label(list_head)
- struct sed_label *list_head;
+release_label (struct sed_label *list_head)
{
struct sed_label *ret;
@@ -746,12 +707,8 @@ new_replacement(char *text, size_t length, enum replacement_types type)
return r;
}
-static void setup_replacement (struct subst *, const char *, size_t);
static void
-setup_replacement(sub, text, length)
- struct subst *sub;
- const char *text;
- size_t length;
+setup_replacement (struct subst *sub, const char *text, size_t length)
{
char *base;
char *p;
@@ -851,11 +808,8 @@ setup_replacement(sub, text, length)
sub->replacement = root.next;
}
-static void read_text (struct text_buf *buf, int leadin_ch);
static void
-read_text(buf, leadin_ch)
- struct text_buf *buf;
- int leadin_ch;
+read_text (struct text_buf *buf, int leadin_ch)
{
int ch;
@@ -911,11 +865,8 @@ read_text(buf, leadin_ch)
return non-zero and store the resulting address in `*addr'.
If the input doesn't look like an address read nothing
and return zero. */
-static bool compile_address (struct addr *addr, int ch);
static bool
-compile_address(addr, ch)
- struct addr *addr;
- int ch;
+compile_address (struct addr *addr, int ch)
{
addr->addr_type = ADDR_IS_NULL;
addr->addr_step = 0;
@@ -1009,10 +960,8 @@ compile_address(addr, ch)
/* Read a program (or a subprogram within `{' `}' pairs) in and store
the compiled form in `*vector'. Return a pointer to the new vector. */
-static struct vector *compile_program (struct vector *);
static struct vector *
-compile_program(vector)
- struct vector *vector;
+compile_program(struct vector *vector)
{
struct sed_cmd *cur_cmd;
struct buffer *b;
@@ -1391,10 +1340,7 @@ compile_program(vector)
/* deal with \X escapes */
size_t
-normalize_text(buf, len, buftype)
- char *buf;
- size_t len;
- enum text_types buftype;
+normalize_text(char *buf, size_t len, enum text_types buftype)
{
const char *bufend = buf + len;
char *p = buf;
@@ -1555,10 +1501,7 @@ convert:
/* `str' is a string (from the command line) that contains a sed command.
Compile the command, and add it to the end of `cur_program'. */
struct vector *
-compile_string(cur_program, str, len)
- struct vector *cur_program;
- char *str;
- size_t len;
+compile_string(struct vector *cur_program, char *str, size_t len)
{
static countT string_expr_count = 0;
struct vector *ret;
@@ -1585,9 +1528,7 @@ compile_string(cur_program, str, len)
Read them in and add them to the end of `cur_program'.
*/
struct vector *
-compile_file(cur_program, cmdfile)
- struct vector *cur_program;
- const char *cmdfile;
+compile_file(struct vector *cur_program, const char *cmdfile)
{
struct vector *ret;
@@ -1618,8 +1559,7 @@ compile_file(cur_program, cmdfile)
In particular: this backpatches the jump targets.
Any cleanup which can be done after these checks is done here also. */
void
-check_final_program(program)
- struct vector *program;
+check_final_program(struct vector *program)
{
struct sed_label *go;
struct sed_label *lbl;
@@ -1687,7 +1627,7 @@ check_final_program(program)
/* Rewind all resources which were allocated in this module. */
void
-rewind_read_files()
+rewind_read_files(void)
{
struct output *p;
@@ -1698,8 +1638,7 @@ rewind_read_files()
/* Release all resources which were allocated in this module. */
void
-finish_program(program)
- struct vector *program;
+finish_program(struct vector *program)
{
/* close all files... */
{
diff --git a/sed/execute.c b/sed/execute.c
index 10a4289..7fe8bab 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -133,11 +133,8 @@ static struct append_queue *append_tail = NULL;
/* increase a struct line's length, making some attempt at
keeping realloc() calls under control by padding for future growth. */
-static void resize_line (struct line *, size_t);
static void
-resize_line(lb, len)
- struct line *lb;
- size_t len;
+resize_line (struct line *lb, size_t len)
{
int inactive;
inactive = lb->active - lb->text;
@@ -166,12 +163,8 @@ resize_line(lb, len)
}
/* Append `length' bytes from `string' to the line `to'. */
-static void str_append (struct line *, const char *, size_t);
static void
-str_append(to, string, length)
- struct line *to;
- const char *string;
- size_t length;
+str_append(struct line *to, const char *string, size_t length)
{
size_t new_length = to->length + length;
@@ -277,10 +270,7 @@ str_append_modified(struct line *to, const char *string, size_t length,
if not null. */
static void line_init (struct line *, struct line *, size_t initial_size);
static void
-line_init(buf, state, initial_size)
- struct line *buf;
- struct line *state;
- size_t initial_size;
+line_init(struct line *buf, struct line *state, size_t initial_size)
{
buf->text = MALLOC(initial_size, char);
buf->active = buf->text;
@@ -296,10 +286,8 @@ line_init(buf, state, initial_size)
/* Reset a "struct line" buffer to length zero. Copy multibyte state from
`state' if not null. */
-static void line_reset (struct line *, struct line *);
static void
-line_reset(buf, state)
- struct line *buf, *state;
+line_reset(struct line *buf, struct line *state)
{
if (buf->alloc == 0)
line_init(buf, state, INITIAL_BUFFER_SIZE);
@@ -316,12 +304,8 @@ line_reset(buf, state)
/* Copy the contents of the line `from' into the line `to'.
This destroys the old contents of `to'.
Copy the multibyte state if `state' is true. */
-static void line_copy (struct line *from, struct line *to, int state);
static void
-line_copy(from, to, state)
- struct line *from;
- struct line *to;
- int state;
+line_copy(struct line *from, struct line *to, int state)
{
/* Remove the inactive portion in the destination buffer. */
to->alloc += to->active - to->text;
@@ -350,12 +334,8 @@ line_copy(from, to, state)
/* Append the contents of the line `from' to the line `to'.
Copy the multibyte state if `state' is true. */
-static void line_append (struct line *from, struct line *to, int state);
static void
-line_append(from, to, state)
- struct line *from;
- struct line *to;
- int state;
+line_append (struct line *from, struct line *to, int state)
{
str_append(to, &buffer_delimiter, 1);
str_append(to, from->active, from->length);
@@ -367,12 +347,8 @@ line_append(from, to, state)
/* Exchange two "struct line" buffers.
Copy the multibyte state if `state' is true. */
-static void line_exchange (struct line *a, struct line *b, int state);
static void
-line_exchange(a, b, state)
- struct line *a;
- struct line *b;
- int state;
+line_exchange (struct line *a, struct line *b, int state)
{
struct line t;
@@ -392,18 +368,14 @@ line_exchange(a, b, state)
/* dummy function to simplify read_pattern_space() */
-static bool read_always_fail (struct input *);
static bool
-read_always_fail(input)
- struct input *input UNUSED;
+read_always_fail(struct input *input UNUSED)
{
return false;
}
-static bool read_file_line (struct input *);
static bool
-read_file_line(input)
- struct input *input;
+read_file_line(struct input *input)
{
static char *b;
static size_t blen;
@@ -423,10 +395,8 @@ read_file_line(input)
}
-static inline void output_missing_newline (struct output *);
static inline void
-output_missing_newline(outf)
- struct output *outf;
+output_missing_newline(struct output *outf)
{
if (outf->missing_newline)
{
@@ -435,22 +405,15 @@ output_missing_newline(outf)
}
}
-static inline void flush_output (FILE *);
static inline void
-flush_output(fp)
- FILE *fp;
+flush_output(FILE *fp)
{
if (fp != stdout || unbuffered)
ck_fflush(fp);
}
-static void output_line (const char *, size_t, int, struct output *);
static void
-output_line(text, length, nl, outf)
- const char *text;
- size_t length;
- int nl;
- struct output *outf;
+output_line(const char *text, size_t length, int nl, struct output *outf)
{
if (!text)
return;
@@ -466,9 +429,8 @@ output_line(text, length, nl, outf)
flush_output(outf->fp);
}
-static struct append_queue *next_append_slot (void);
static struct append_queue *
-next_append_slot()
+next_append_slot(void)
{
struct append_queue *n = MALLOC(1, struct append_queue);
@@ -485,9 +447,8 @@ next_append_slot()
return append_tail = n;
}
-static void release_append_queue (void);
static void
-release_append_queue()
+release_append_queue(void)
{
struct append_queue *p, *q;
@@ -502,9 +463,8 @@ release_append_queue()
append_head = append_tail = NULL;
}
-static void dump_append_queue (void);
static void
-dump_append_queue()
+dump_append_queue(void)
{
struct append_queue *p;
@@ -540,10 +500,8 @@ dump_append_queue()
/* Compute the name of the backup file for in-place editing */
-static char *get_backup_file_name (const char *);
static char *
-get_backup_file_name(name)
- const char *name;
+get_backup_file_name(const char *name)
{
char *old_asterisk, *asterisk, *backup, *p;
int name_length = strlen(name), backup_length = strlen(in_place_extension);
@@ -573,11 +531,8 @@ get_backup_file_name(name)
}
/* Initialize a struct input for the named file. */
-static void open_next_file (const char *name, struct input *);
static void
-open_next_file(name, input)
- const char *name;
- struct input *input;
+open_next_file(const char *name, struct input *input)
{
buffer.length = 0;
@@ -674,10 +629,8 @@ open_next_file(name, input)
/* Clean up an input stream that we are done with. */
-static void closedown (struct input *);
static void
-closedown(input)
- struct input *input;
+closedown(struct input *input)
{
input->read_fn = read_always_fail;
if (!input->fp)
@@ -718,10 +671,8 @@ closedown(input)
}
/* Reset range commands so that they are marked as non-matching */
-static void reset_addresses (struct vector *);
static void
-reset_addresses(vec)
- struct vector *vec;
+reset_addresses(struct vector *vec)
{
struct sed_cmd *cur_cmd;
int n;
@@ -737,12 +688,8 @@ reset_addresses(vec)
/* Read in the next line of input, and store it in the pattern space.
Return zero if there is nothing left to input. */
-static bool read_pattern_space (struct input *, struct vector *, int);
static bool
-read_pattern_space(input, the_program, append)
- struct input *input;
- struct vector *the_program;
- int append;
+read_pattern_space(struct input *input, struct vector *the_program, int append)
{
if (append_head) /* redundant test to optimize for common case */
dump_append_queue();
@@ -782,10 +729,8 @@ read_pattern_space(input, the_program, append)
}
-static bool last_file_with_data_p (struct input *);
static bool
-last_file_with_data_p(input)
- struct input *input;
+last_file_with_data_p(struct input *input)
{
for (;;)
{
@@ -807,10 +752,8 @@ last_file_with_data_p(input)
}
/* Determine if we match the `$' address. */
-static bool test_eof (struct input *);
static bool
-test_eof(input)
- struct input *input;
+test_eof(struct input *input)
{
int ch;
@@ -828,11 +771,8 @@ test_eof(input)
/* Return non-zero if the current line matches the address
pointed to by `addr'. */
-static bool match_an_address_p (struct addr *, struct input *);
static bool
-match_an_address_p(addr, input)
- struct addr *addr;
- struct input *input;
+match_an_address_p(struct addr *addr, struct input *input)
{
switch (addr->addr_type)
{
@@ -866,11 +806,8 @@ match_an_address_p(addr, input)
}
/* return non-zero if current address is valid for cmd */
-static bool match_address_p (struct sed_cmd *, struct input *);
static bool
-match_address_p(cmd, input)
- struct sed_cmd *cmd;
- struct input *input;
+match_address_p(struct sed_cmd *cmd, struct input *input)
{
if (!cmd->a1)
return true;
@@ -945,10 +882,8 @@ match_address_p(cmd, input)
}
-static void do_list (int line_len);
static void
-do_list(line_len)
- int line_len;
+do_list(int line_len)
{
unsigned char *p = (unsigned char *)line.active;
countT len = line.length;
@@ -1047,10 +982,8 @@ static void append_replacement (struct line *buf, struct replacement *p,
}
}
-static void do_subst (struct subst *);
static void
-do_subst(sub)
- struct subst *sub;
+do_subst(struct subst *sub)
{
size_t start = 0; /* where to start scan for (next) match in LINE */
size_t last_end = 0; /* where did the last successful match end in LINE */
@@ -1258,11 +1191,8 @@ shrink_program(vec, cur_cmd)
/* Execute the program `vec' on the current input line.
Return exit status if caller should quit, -1 otherwise. */
-static int execute_program (struct vector *, struct input *);
static int
-execute_program(vec, input)
- struct vector *vec;
- struct input *input;
+execute_program(struct vector *vec, struct input *input)
{
struct sed_cmd *cur_cmd;
struct sed_cmd *end_cmd;
@@ -1704,9 +1634,7 @@ execute_program(vec, input)
/* Apply the compiled script to all the named files. */
int
-process_files(the_program, argv)
- struct vector *the_program;
- char **argv;
+process_files(struct vector *the_program, char **argv)
{
static char dash[] = "-";
static char *stdin_argv[2] = { dash, NULL };
diff --git a/sed/fmt.c b/sed/fmt.c
index eea55ec..389bccb 100644
--- a/sed/fmt.c
+++ b/sed/fmt.c
@@ -222,7 +222,7 @@ fmt (const char *line, const char *line_end, int max_length, FILE *output_file)
paragraph, else true. */
static bool
-get_paragraph ()
+get_paragraph (void)
{
register int c;
diff --git a/sed/mbcs.c b/sed/mbcs.c
index 95f2bdb..b84582c 100644
--- a/sed/mbcs.c
+++ b/sed/mbcs.c
@@ -27,9 +27,7 @@ bool is_utf8;
/* Add a byte to the multibyte character represented by the state
CUR_STAT, and answer its length if a character is completed,
or -2 if it is yet to be completed. */
-int brlen (ch, cur_stat)
- int ch;
- mbstate_t *cur_stat;
+int brlen (int ch, mbstate_t *cur_stat)
{
char c = ch;
@@ -47,7 +45,7 @@ int brlen (ch, cur_stat)
}
void
-initialize_mbcs ()
+initialize_mbcs (void)
{
/* For UTF-8, we know that the encoding is stateless. */
const char *codeset_name;
diff --git a/sed/regexp.c b/sed/regexp.c
index 3a8091d..8a802c9 100644
--- a/sed/regexp.c
+++ b/sed/regexp.c
@@ -41,9 +41,7 @@ static const char errors[] =
static void
-compile_regex_1 (new_regex, needed_sub)
- struct regex *new_regex;
- int needed_sub;
+compile_regex_1 (struct regex *new_regex, int needed_sub)
{
#ifdef REG_PERL
int errcode;
@@ -132,10 +130,7 @@ compile_regex_1 (new_regex, needed_sub)
}
struct regex *
-compile_regex(b, flags, needed_sub)
- struct buffer *b;
- int flags;
- int needed_sub;
+compile_regex(struct buffer *b, int flags, int needed_sub)
{
struct regex *new_regex;
size_t re_len;
@@ -203,13 +198,9 @@ copy_regs (regs, pmatch, nregs)
#endif
int
-match_regex(regex, buf, buflen, buf_start_offset, regarray, regsize)
- struct regex *regex;
- char *buf;
- size_t buflen;
- size_t buf_start_offset;
- struct re_registers *regarray;
- int regsize;
+match_regex(struct regex *regex, char *buf, size_t buflen,
+ size_t buf_start_offset, struct re_registers *regarray,
+ int regsize)
{
int ret;
static struct regex *regex_last;
diff --git a/sed/sed.c b/sed/sed.c
index b360654..28cd0fa 100644
--- a/sed/sed.c
+++ b/sed/sed.c
@@ -57,8 +57,8 @@ bool follow_symlinks = false;
char *in_place_extension = NULL;
/* The mode to use to read/write files, either "r"/"w" or "rb"/"wb". */
-char *read_mode = "r";
-char *write_mode = "w";
+char const *read_mode = "r";
+char const *write_mode = "w";
/* Do we need to be pedantically POSIX compliant? */
enum posixicity_types posixicity;
@@ -71,8 +71,7 @@ static struct vector *the_program = NULL;
static void usage (int);
static void
-contact(errmsg)
- int errmsg;
+contact(int errmsg)
{
FILE *out = errmsg ? stderr : stdout;
#ifndef REG_PERL
@@ -88,17 +87,13 @@ Be sure to include the word ``%s'' somewhere in the ``Subject:'' field.\n"),
PACKAGE_BUGREPORT, PACKAGE);
}
-static void usage (int);
static void
-usage(status)
- int status;
+usage(int status)
{
FILE *out = status ? stderr : stdout;
#ifdef REG_PERL
#define PERL_HELP _(" -R, --regexp-perl\n use Perl 5's regular expressions syntax in the script.\n")
-#else
-#define PERL_HELP ""
#endif
fprintf(out, _("\
@@ -154,9 +149,7 @@ specified, then the standard input is read.\n\
}
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
#ifdef REG_PERL
#define SHORTOPTS "bsnrzRuEe:f:l:i::V:"
@@ -164,7 +157,7 @@ main(argc, argv)
#define SHORTOPTS "bsnrzuEe:f:l:i::V:"
#endif
- const static struct option longopts[] = {
+ static const struct option longopts[] = {
{"binary", 0, NULL, 'b'},
{"regexp-extended", 0, NULL, 'r'},
#ifdef REG_PERL
diff --git a/sed/sed.h b/sed/sed.h
index 5f947e9..d190700 100644
--- a/sed/sed.h
+++ b/sed/sed.h
@@ -231,8 +231,8 @@ extern countT lcmd_out_line_len;
extern char *in_place_extension;
/* The mode to use to read and write files, either "rt"/"w" or "rb"/"wb". */
-extern char *read_mode;
-extern char *write_mode;
+extern char const *read_mode;
+extern char const *write_mode;
/* Should we use EREs? */
extern bool use_extended_syntax_p;
diff --git a/sed/utils.c b/sed/utils.c
index a681c0d..ec9b2e6 100644
--- a/sed/utils.c
+++ b/sed/utils.c
@@ -81,10 +81,8 @@ panic(const char *str, ...)
/* Internal routine to get a filename from open_files */
-static const char *utils_fp_name (FILE *fp);
static const char *
-utils_fp_name(fp)
- FILE *fp;
+utils_fp_name(FILE *fp)
{
struct open_file *p;
@@ -102,10 +100,7 @@ utils_fp_name(fp)
}
static void
-register_open_file (fp, name, temp)
- FILE *fp;
- const char *name;
- int temp;
+register_open_file (FILE *fp, const char *name, int temp)
{
struct open_file *p;
for (p=open_files; p; p=p->link)
@@ -129,10 +124,7 @@ register_open_file (fp, name, temp)
/* Panic on failing fopen */
FILE *
-ck_fopen(name, mode, fail)
- const char *name;
- const char *mode;
- int fail;
+ck_fopen(const char *name, const char *mode, int fail)
{
FILE *fp;
@@ -151,11 +143,7 @@ ck_fopen(name, mode, fail)
/* Panic on failing fdopen */
FILE *
-ck_fdopen(fd, name, mode, fail)
- int fd;
- const char *name;
- const char *mode;
- int fail;
+ck_fdopen( int fd, const char *name, const char *mode, int fail)
{
FILE *fp;
@@ -173,10 +161,8 @@ ck_fdopen(fd, name, mode, fail)
}
FILE *
-ck_mkstemp (p_filename, tmpdir, base, mode)
- char **p_filename;
- const char *base, *tmpdir;
- const char *mode;
+ck_mkstemp (char **p_filename, const char *tmpdir,
+ const char *base, const char *mode)
{
char *template;
FILE *fp;
@@ -217,11 +203,7 @@ ck_mkstemp (p_filename, tmpdir, base, mode)
/* Panic on failing fwrite */
void
-ck_fwrite(ptr, size, nmemb, stream)
- const void *ptr;
- size_t size;
- size_t nmemb;
- FILE *stream;
+ck_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
clearerr(stream);
if (size && fwrite(ptr, size, nmemb, stream) != nmemb)
@@ -232,11 +214,7 @@ ck_fwrite(ptr, size, nmemb, stream)
/* Panic on failing fread */
size_t
-ck_fread(ptr, size, nmemb, stream)
- void *ptr;
- size_t size;
- size_t nmemb;
- FILE *stream;
+ck_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
clearerr(stream);
if (size && (nmemb=fread(ptr, size, nmemb, stream)) <= 0 && ferror(stream))
@@ -246,11 +224,7 @@ ck_fread(ptr, size, nmemb, stream)
}
size_t
-ck_getdelim(text, buflen, buffer_delimiter, stream)
- char **text;
- size_t *buflen;
- char buffer_delimiter;
- FILE *stream;
+ck_getdelim(char **text, size_t *buflen, char buffer_delimiter, FILE *stream)
{
ssize_t result;
bool error;
@@ -270,8 +244,7 @@ ck_getdelim(text, buflen, buffer_delimiter, stream)
/* Panic on failing fflush */
void
-ck_fflush(stream)
- FILE *stream;
+ck_fflush(FILE *stream)
{
if (!fwriting(stream))
return;
@@ -283,8 +256,7 @@ ck_fflush(stream)
/* Panic on failing fclose */
void
-ck_fclose(stream)
- FILE *stream;
+ck_fclose(FILE *stream)
{
struct open_file r;
struct open_file *prev;
@@ -320,8 +292,7 @@ ck_fclose(stream)
/* Close a single file. */
void
-do_ck_fclose(fp)
- FILE *fp;
+do_ck_fclose(FILE *fp)
{
ck_fflush(fp);
clearerr(fp);
@@ -412,9 +383,7 @@ follow_symlink(const char *fname)
/* Panic on failing rename */
void
-ck_rename (from, to, unlink_if_fail)
- const char *from, *to;
- const char *unlink_if_fail;
+ck_rename (const char *from, const char *to, const char *unlink_if_fail)
{
int rd = rename (from, to);
if (rd != -1)
@@ -441,8 +410,7 @@ ck_rename (from, to, unlink_if_fail)
/* Panic on failing malloc */
void *
-ck_malloc(size)
- size_t size;
+ck_malloc(size_t size)
{
void *ret = calloc(1, size ? size : 1);
if (!ret)
@@ -452,9 +420,7 @@ ck_malloc(size)
/* Panic on failing realloc */
void *
-ck_realloc(ptr, size)
- void *ptr;
- size_t size;
+ck_realloc(void *ptr, size_t size)
{
void *ret;
@@ -473,8 +439,7 @@ ck_realloc(ptr, size)
/* Return a malloc()'d copy of a string */
char *
-ck_strdup(str)
- const char *str;
+ck_strdup(const char *str)
{
char *ret = MALLOC(strlen(str)+1, char);
return strcpy(ret, str);
@@ -482,9 +447,7 @@ ck_strdup(str)
/* Return a malloc()'d copy of a block of memory */
void *
-ck_memdup(buf, len)
- const void *buf;
- size_t len;
+ck_memdup(const void *buf, size_t len)
{
void *ret = ck_malloc(len);
return memcpy(ret, buf, len);
@@ -504,7 +467,7 @@ struct buffer
#define MIN_ALLOCATE 50
struct buffer *
-init_buffer()
+init_buffer(void)
{
struct buffer *b = MALLOC(1, struct buffer);
b->b = MALLOC(MIN_ALLOCATE, char);
@@ -514,24 +477,19 @@ init_buffer()
}
char *
-get_buffer(b)
- struct buffer *b;
+get_buffer(struct buffer *b)
{
return b->b;
}
size_t
-size_buffer(b)
- struct buffer *b;
+size_buffer(struct buffer *b)
{
return b->length;
}
-static void resize_buffer (struct buffer *b, size_t newlen);
static void
-resize_buffer(b, newlen)
- struct buffer *b;
- size_t newlen;
+resize_buffer(struct buffer *b, size_t newlen)
{
char *try = NULL;
size_t alen = b->allocated;
@@ -551,10 +509,7 @@ resize_buffer(b, newlen)
}
char *
-add_buffer(b, p, n)
- struct buffer *b;
- const char *p;
- size_t n;
+add_buffer(struct buffer *b, const char *p, size_t n)
{
char *result;
if (b->allocated - b->length < n)
@@ -565,9 +520,7 @@ add_buffer(b, p, n)
}
char *
-add1_buffer(b, c)
- struct buffer *b;
- int c;
+add1_buffer(struct buffer *b, int c)
{
/* This special case should be kept cheap;
* don't make it just a mere convenience
@@ -589,8 +542,7 @@ add1_buffer(b, c)
}
void
-free_buffer(b)
- struct buffer *b;
+free_buffer(struct buffer *b)
{
if (b)
free(b->b);