Skip to content

Commit

Permalink
Currently, less(1) uses K&R prototypes, which both fails to provide u…
Browse files Browse the repository at this point in the history
…seful

compiler-time type checking, and also causes problems for targets where
multiple incompatible calling conventions may be selected based on argument
types.  This change switches less(1) to ANSI prototypes.

While there, we also remove use of "register", and attempt to use "const" a
bit better now that the compiler can check argument types.

Reviewed by:	cem, emaste
MFC after:	3 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D10152
  • Loading branch information
rwatson committed Mar 31, 2017
1 parent 19fbe8b commit 1ea3162
Show file tree
Hide file tree
Showing 38 changed files with 1,083 additions and 1,683 deletions.
14 changes: 5 additions & 9 deletions contrib/less/brac.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
* "close bracket" are given.
*/
public void
match_brac(obrac, cbrac, forwdir, n)
register int obrac;
register int cbrac;
int forwdir;
int n;
match_brac(int obrac, int cbrac, int forwdir, int n)
{
register int c;
register int nest;
int c;
int nest;
POSITION pos;
int (*chget)();
int (*chget)(void);

extern int ch_forw_get(), ch_back_get();
extern int ch_forw_get(void), ch_back_get(void);

/*
* Seek to the line containing the open bracket.
Expand Down
93 changes: 43 additions & 50 deletions contrib/less/ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ static int ch_addbuf();
* Get the character pointed to by the read pointer.
*/
int
ch_get()
ch_get(void)
{
register struct buf *bp;
register struct bufnode *bn;
register int n;
register int slept;
register int h;
struct buf *bp;
struct bufnode *bn;
int n;
int slept;
int h;
POSITION pos;
POSITION len;

Expand Down Expand Up @@ -378,8 +378,7 @@ ch_get()
* a single char onto an input file descriptor.
*/
public void
ch_ungetchar(c)
int c;
ch_ungetchar(int c)
{
if (c != -1 && ch_ungotchar != -1)
error("ch_ungetchar overrun", NULL_PARG);
Expand All @@ -392,7 +391,7 @@ ch_ungetchar(c)
* If we haven't read all of standard input into it, do that now.
*/
public void
end_logfile()
end_logfile(void)
{
static int tried = FALSE;

Expand All @@ -417,10 +416,10 @@ end_logfile()
* Write all the existing buffered data to the log file.
*/
public void
sync_logfile()
sync_logfile(void)
{
register struct buf *bp;
register struct bufnode *bn;
struct buf *bp;
struct bufnode *bn;
int warned = FALSE;
BLOCKNUM block;
BLOCKNUM nblocks;
Expand Down Expand Up @@ -454,12 +453,11 @@ sync_logfile()
* Determine if a specific block is currently in one of the buffers.
*/
static int
buffered(block)
BLOCKNUM block;
buffered(BLOCKNUM block)
{
register struct buf *bp;
register struct bufnode *bn;
register int h;
struct buf *bp;
struct bufnode *bn;
int h;

h = BUFHASH(block);
FOR_BUFS_IN_CHAIN(h, bn)
Expand All @@ -476,8 +474,7 @@ buffered(block)
* Return 0 if successful, non-zero if can't seek there.
*/
public int
ch_seek(pos)
register POSITION pos;
ch_seek(POSITION pos)
{
BLOCKNUM new_block;
POSITION len;
Expand Down Expand Up @@ -515,7 +512,7 @@ ch_seek(pos)
* Seek to the end of the file.
*/
public int
ch_end_seek()
ch_end_seek(void)
{
POSITION len;

Expand All @@ -542,10 +539,10 @@ ch_end_seek()
* Seek to the last position in the file that is currently buffered.
*/
public int
ch_end_buffer_seek()
ch_end_buffer_seek(void)
{
register struct buf *bp;
register struct bufnode *bn;
struct buf *bp;
struct bufnode *bn;
POSITION buf_pos;
POSITION end_pos;

Expand All @@ -570,10 +567,10 @@ ch_end_buffer_seek()
* beginning of the pipe is no longer buffered.
*/
public int
ch_beg_seek()
ch_beg_seek(void)
{
register struct bufnode *bn;
register struct bufnode *firstbn;
struct bufnode *bn;
struct bufnode *firstbn;

/*
* Try a plain ch_seek first.
Expand Down Expand Up @@ -602,7 +599,7 @@ ch_beg_seek()
* Return the length of the file, if known.
*/
public POSITION
ch_length()
ch_length(void)
{
if (thisfile == NULL)
return (NULL_POSITION);
Expand All @@ -619,7 +616,7 @@ ch_length()
* Return the current position in the file.
*/
public POSITION
ch_tell()
ch_tell(void)
{
if (thisfile == NULL)
return (NULL_POSITION);
Expand All @@ -630,9 +627,9 @@ ch_tell()
* Get the current char and post-increment the read pointer.
*/
public int
ch_forw_get()
ch_forw_get(void)
{
register int c;
int c;

if (thisfile == NULL)
return (EOI);
Expand All @@ -653,7 +650,7 @@ ch_forw_get()
* Pre-decrement the read pointer and get the new current char.
*/
public int
ch_back_get()
ch_back_get(void)
{
if (thisfile == NULL)
return (EOI);
Expand All @@ -676,8 +673,7 @@ ch_back_get()
* bufspace is in units of 1024 bytes. -1 mean no limit.
*/
public void
ch_setbufspace(bufspace)
int bufspace;
ch_setbufspace(int bufspace)
{
if (bufspace < 0)
maxbufs = -1;
Expand All @@ -693,9 +689,9 @@ ch_setbufspace(bufspace)
* Flush (discard) any saved file state, including buffer contents.
*/
public void
ch_flush()
ch_flush(void)
{
register struct bufnode *bn;
struct bufnode *bn;

if (thisfile == NULL)
return;
Expand Down Expand Up @@ -760,10 +756,10 @@ ch_flush()
* The buffer is added to the tail of the buffer chain.
*/
static int
ch_addbuf()
ch_addbuf(void)
{
register struct buf *bp;
register struct bufnode *bn;
struct buf *bp;
struct bufnode *bn;

/*
* Allocate and initialize a new buffer and link it
Expand All @@ -785,9 +781,9 @@ ch_addbuf()
*
*/
static void
init_hashtbl()
init_hashtbl(void)
{
register int h;
int h;

for (h = 0; h < BUFHASH_SIZE; h++)
{
Expand All @@ -800,9 +796,9 @@ init_hashtbl()
* Delete all buffers for this file.
*/
static void
ch_delbufs()
ch_delbufs(void)
{
register struct bufnode *bn;
struct bufnode *bn;

while (ch_bufhead != END_OF_CHAIN)
{
Expand All @@ -818,8 +814,7 @@ ch_delbufs()
* Is it possible to seek on a file descriptor?
*/
public int
seekable(f)
int f;
seekable(int f)
{
#if MSDOS_COMPILER
extern int fd0;
Expand All @@ -840,7 +835,7 @@ seekable(f)
* This is used after an ignore_eof read, during which the EOF may change.
*/
public void
ch_set_eof()
ch_set_eof(void)
{
ch_fsize = ch_fpos;
}
Expand All @@ -850,9 +845,7 @@ ch_set_eof()
* Initialize file state for a new file.
*/
public void
ch_init(f, flags)
int f;
int flags;
ch_init(int f, int flags)
{
/*
* See if we already have a filestate for this file.
Expand Down Expand Up @@ -891,7 +884,7 @@ ch_init(f, flags)
* Close a filestate.
*/
public void
ch_close()
ch_close(void)
{
int keepstate = FALSE;

Expand Down Expand Up @@ -934,7 +927,7 @@ ch_close()
* Return ch_flags for the current file.
*/
public int
ch_getflags()
ch_getflags(void)
{
if (thisfile == NULL)
return (0);
Expand Down
Loading

0 comments on commit 1ea3162

Please sign in to comment.