bin/mined cleanup stage2
Sepherosa Ziehau
sepherosa at gmail.com
Fri Apr 29 17:22:23 PDT 2005
Sorry about that, I forgot to sync with Joerg's recent de-errno work.
I have regenerated the patch, nwo it will patch cleanly.
Please review it. Thanks.
On 4/29/05, Matthew Dillon <dillon at xxxxxxxxxxxxxxxxxxxx> wrote:
>
> :this patch is based on
> :http://leaf.dragonflybsd.org/mailarchive/submit/2005-04/msg00174.html
> :
> :simply constify strings in this stage. now bin/mined is WARNS 6 clean.
> :please review them
> :
> :--=20
>
> For some reason none of the files will patch cleanly. Could you
> regenerate it and make sure it 'patches' against the head of the CVS
> tree ?
>
> -Matt
>
--
Live Free or Die
Index: Makefile
===================================================================
RCS file: /opt/df_cvs/src/bin/mined/Makefile,v
retrieving revision 1.1
diff -u -r1.1 Makefile
--- Makefile 15 Mar 2005 01:56:24 -0000 1.1
+++ Makefile 30 Apr 2005 00:17:27 -0000
@@ -3,6 +3,5 @@
PROG= mined
SRCS= mined1.c mined2.c
-WARNS=0
.include <bsd.prog.mk>
Index: mined.h
===================================================================
RCS file: /opt/df_cvs/src/bin/mined/mined.h,v
retrieving revision 1.4
diff -u -r1.4 mined.h
--- mined.h 15 Mar 2005 02:32:57 -0000 1.4
+++ mined.h 30 Apr 2005 00:17:27 -0000
@@ -39,7 +39,6 @@
* Mined.h *
*========================================================================*/
-#define _PROTOTYPE(a, b) a b
#define INTEL 1
#define CHIP INTEL
#define ASSUME_CONS25
@@ -63,11 +62,11 @@
#else
#define YMAX 24 /* Maximum y coordinate starting at 0 */
/* Escape sequences. */
-extern char *enter_string; /* String printed on entering mined */
-extern char *rev_video; /* String for starting reverse video */
-extern char *normal_video; /* String for leaving reverse video */
-extern char *rev_scroll; /* String for reverse scrolling */
-extern char *pos_string; /* Absolute cursor positioning */
+extern const char *enter_string; /* String printed on entering mined */
+extern const char *rev_video; /* String for starting reverse video */
+extern const char *normal_video; /* String for leaving reverse video */
+extern const char *rev_scroll; /* String for reverse scrolling */
+extern const char *pos_string; /* Absolute cursor positioning */
#define X_PLUS ' ' /* To be added to x for cursor sequence */
#define Y_PLUS ' ' /* To be added to y for cursor sequence */
#endif /* UNIX */
@@ -159,7 +158,7 @@
*/
struct regex {
union {
- char *err_mess;
+ const char *err_mess;
int *expression;
} result;
char status;
@@ -201,7 +200,7 @@
extern int out_count; /* Index in output buffer */
extern char file_name[LINE_LEN]; /* Name of file in use */
extern char text_buffer[MAX_CHARS]; /* Buffer for modifying text */
-extern char *blank_line; /* Clear line to end */
+extern const char *blank_line; /* Clear line to end */
extern char yank_file[]; /* Temp file for buffer */
extern FLAG yank_status; /* Status of yank_file */
@@ -215,7 +214,7 @@
/*
* Print character on terminal
*/
-#define putchar(c) (void) write_char(STD_OUT, (c))
+#define putchar(c) write_char(STD_OUT, (c))
/*
* Ring bell on terminal
@@ -225,12 +224,12 @@
/*
* Print string on terminal
*/
-#define string_print(str) (void) writeline(STD_OUT, (str))
+#define string_print(str) writeline(STD_OUT, (str))
/*
* Flush output buffer
*/
-#define flush() (void) flush_buffer(STD_OUT)
+#define flush() flush_buffer(STD_OUT)
/*
* Convert cnt to nearest tab position
@@ -262,13 +261,11 @@
/*
* Functions handling status_line. ON means in reverse video.
*/
-#define status_line(str1, str2) (void) bottom_line(ON, (str1), \
- (str2), NIL_PTR, FALSE)
-#define error(str1, str2) (void) bottom_line(ON, (str1), \
- (str2), NIL_PTR, FALSE)
+#define status_line(str1, str2) bottom_line(ON, (str1), (str2), NIL_PTR, FALSE)
+#define error(str1, str2) bottom_line(ON, (str1), (str2), NIL_PTR, FALSE)
#define get_string(str1,str2, fl) bottom_line(ON, (str1), NIL_PTR, (str2), fl)
-#define clear_status() (void) bottom_line(OFF, NIL_PTR, NIL_PTR, \
- NIL_PTR, FALSE)
+#define clear_status() bottom_line(OFF, NIL_PTR, NIL_PTR, \
+ NIL_PTR, FALSE)
/*
* Print info about current file and buffer.
@@ -285,133 +282,124 @@
/* mined1.c */
-_PROTOTYPE(void FS, (void));
-_PROTOTYPE(void VI, (void));
-_PROTOTYPE(int WT, (void));
-_PROTOTYPE(void XWT, (void));
-_PROTOTYPE(void SH, (void));
-_PROTOTYPE(LINE *proceed, (LINE *line, int count ));
-_PROTOTYPE(int bottom_line, (FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl ));
-_PROTOTYPE(int count_chars, (LINE *line ));
-_PROTOTYPE(void move, (int new_x, char *new_address, int new_y ));
-_PROTOTYPE(int find_x, (LINE *line, char *address ));
-_PROTOTYPE(char *find_address, (LINE *line, int x_coord, int *old_x ));
-_PROTOTYPE(int length_of, (char *string ));
-_PROTOTYPE(void copy_string, (char *to, char *from ));
-_PROTOTYPE(void reset, (LINE *head_line, int screen_y ));
-_PROTOTYPE(void set_cursor, (int nx, int ny ));
-_PROTOTYPE(void open_device, (void));
-_PROTOTYPE(int getchar, (void));
-_PROTOTYPE(void display, (int x_coord, int y_coord, LINE *line, int count ));
-_PROTOTYPE(int write_char, (int fd, int c ));
-_PROTOTYPE(int writeline, (int fd, char *text ));
-_PROTOTYPE(void put_line, (LINE *line, int offset, FLAG clear_line ));
-_PROTOTYPE(int flush_buffer, (int fd ));
-_PROTOTYPE(void bad_write, (int fd ));
-_PROTOTYPE(void catch, (int sig ));
-_PROTOTYPE(void abort_mined, (void));
-_PROTOTYPE(void raw_mode, (FLAG state ));
-_PROTOTYPE(void panic, (char *message ));
-_PROTOTYPE(char *alloc, (int bytes ));
-_PROTOTYPE(void free_space, (char *p ));
-/*
-#ifdef UNIX
-_PROTOTYPE(void (*key_map [128]), (void));
-#else
-_PROTOTYPE(void (*key_map [256]), (void));
-#endif
-*/
-_PROTOTYPE(void initialize, (void));
-_PROTOTYPE(char *basename, (char *path ));
-_PROTOTYPE(void load_file, (char *file ));
-_PROTOTYPE(int get_line, (int fd, char *buffer ));
-_PROTOTYPE(LINE *install_line, (char *buffer, int length ));
-_PROTOTYPE(int main, (int argc, char *argv []));
-_PROTOTYPE(void RD, (void));
-_PROTOTYPE(void I, (void));
-_PROTOTYPE(void XT, (void));
-_PROTOTYPE(void ESC, (void));
-_PROTOTYPE(int ask_save, (void));
-_PROTOTYPE(int line_number, (void));
-_PROTOTYPE(void file_status, (char *message, long count, char *file, int lines,
- FLAG writefl, FLAG changed ));
-#if __STDC__
-void build_string(char *buf, char *fmt, ...);
-#else
-void build_string();
-#endif
-_PROTOTYPE(char *num_out, (long number ));
-_PROTOTYPE(int get_number, (char *message, int *result ));
-_PROTOTYPE(int input, (char *inbuf, FLAG clearfl ));
-_PROTOTYPE(int get_file, (char *message, char *file ));
-_PROTOTYPE(int _getchar, (void));
-_PROTOTYPE(void _flush, (void));
-_PROTOTYPE(void _putchar, (int c ));
-_PROTOTYPE(void get_term, (void));
+void FS(int);
+void VI(int);
+int WT(void);
+void XWT(int);
+void SH(int);
+LINE *proceed(LINE *line, int count);
+int bottom_line(FLAG revfl, const char *s1, const char *s2, char *inbuf, FLAG statfl);
+int count_chars(LINE *line);
+void move(int new_x, char *new_address, int new_y);
+int find_x(LINE *line, char *address);
+char *find_address(LINE *line, int x_coord, int *old_x);
+int length_of(char *string);
+void copy_string(char *to, const char *from);
+void reset(LINE *head_line, int screen_y);
+void set_cursor(int nx, int ny);
+void open_device(void);
+int getchar(void);
+void display(int x_coord, int y_coord, LINE *line, int count);
+int write_char(int fd, char c);
+int writeline(int fd, const char *text);
+void put_line(LINE *line, int offset, FLAG clear_line);
+int flush_buffer(int fd);
+void bad_write(int fd);
+void catch(int sig);
+void abort_mined(void);
+void raw_mode(FLAG state);
+void panic(const char *message);
+char *alloc(int bytes);
+void free_space(char *p);
+void initialize(void);
+char *basename(char *path);
+void load_file(const char *file);
+int get_line(int fd, char *buffer);
+LINE *install_line(const char *buffer, int length);
+void RD(int);
+void I(int);
+void XT(int);
+void ESC(int);
+int ask_save(void);
+int line_number(void);
+void file_status(const char *message, long count, char *file, int lines,
+ FLAG writefl, FLAG changed);
+void build_string(char *buf, const char *fmt, ...);
+char *num_out(long number);
+int get_number(const char *message, int *result);
+int input(char *inbuf, FLAG clearfl);
+int get_file(const char *message, char *file);
+int _getchar(void);
+void _flush(void);
+void _putchar(int c);
+void get_term(void);
/* mined2.c */
-_PROTOTYPE(void UP, (void));
-_PROTOTYPE(void DN, (void));
-_PROTOTYPE(void LF, (void));
-_PROTOTYPE(void RT, (void));
-_PROTOTYPE(void HIGH, (void));
-_PROTOTYPE(void LOW, (void));
-_PROTOTYPE(void BL, (void));
-_PROTOTYPE(void EL, (void));
-_PROTOTYPE(void GOTO, (void));
-_PROTOTYPE(void HLP, (void));
-_PROTOTYPE(void ST, (void));
-_PROTOTYPE(void PD, (void));
-_PROTOTYPE(void PU, (void));
-_PROTOTYPE(void HO, (void));
-_PROTOTYPE(void EF, (void));
-_PROTOTYPE(void SU, (void));
-_PROTOTYPE(void SD, (void));
-_PROTOTYPE(int forward_scroll, (void));
-_PROTOTYPE(int reverse_scroll, (void));
-_PROTOTYPE(void MP, (void));
-_PROTOTYPE(void move_previous_word, (FLAG remove ));
-_PROTOTYPE(void MN, (void));
-_PROTOTYPE(void move_next_word, (FLAG remove ));
-_PROTOTYPE(void DCC, (void));
-_PROTOTYPE(void DPC, (void));
-_PROTOTYPE(void DLN, (void));
-_PROTOTYPE(void DNW, (void));
-_PROTOTYPE(void DPW, (void));
-_PROTOTYPE(void S, (int character ));
-_PROTOTYPE(void CTL, (void));
-_PROTOTYPE(void LIB, (void));
-_PROTOTYPE(LINE *line_insert, (LINE *line, char *string, int len ));
-_PROTOTYPE(int insert, (LINE *line, char *location, char *string ));
-_PROTOTYPE(LINE *line_delete, (LINE *line ));
-_PROTOTYPE(void delete, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp ));
-_PROTOTYPE(void PT, (void));
-_PROTOTYPE(void IF, (void));
-_PROTOTYPE(void file_insert, (int fd, FLAG old_pos ));
-_PROTOTYPE(void WB, (void));
-_PROTOTYPE(void MA, (void));
-_PROTOTYPE(void YA, (void));
-_PROTOTYPE(void DT, (void));
-_PROTOTYPE(void set_up, (FLAG remove ));
-_PROTOTYPE(FLAG checkmark, (void));
-_PROTOTYPE(int legal, (void));
-_PROTOTYPE(void yank, (LINE *start_line, char *start_textp, LINE *end_line, char *end_textp, FLAG remove ));
-_PROTOTYPE(int scratch_file, (FLAG mode ));
-_PROTOTYPE(void SF, (void));
-_PROTOTYPE(void SR, (void));
-_PROTOTYPE(REGEX *get_expression, (char *message ));
-_PROTOTYPE(void GR, (void));
-_PROTOTYPE(void LR, (void));
-_PROTOTYPE(void change, (char *message, FLAG file ));
-_PROTOTYPE(char *substitute, (LINE *line, REGEX *program, char *replacement ));
-_PROTOTYPE(void search, (char *message, FLAG method ));
-_PROTOTYPE(int find_y, (LINE *match_line ));
-_PROTOTYPE(void finished, (REGEX *program, int *last_exp ));
-_PROTOTYPE(void compile, (char *pattern, REGEX *program ));
-_PROTOTYPE(LINE *match, (REGEX *program, char *string, FLAG method ));
-_PROTOTYPE(int line_check, (REGEX *program, char *string, FLAG method ));
-_PROTOTYPE(int check_string, (REGEX *program, char *string, int *expression ));
-_PROTOTYPE(int star, (REGEX *program, char *end_position, char *string, int *expression ));
-_PROTOTYPE(int in_list, (int *list, int c, int list_length, int opcode ));
-_PROTOTYPE(void dummy_line, (void));
+void UP(int);
+void DN(int);
+void LF(int);
+void RT(int);
+void HIGH(int);
+void LOW(int);
+void BL(int);
+void EL(int);
+void GOTO(int);
+void HLP(int);
+void ST(int);
+void PD(int);
+void PU(int);
+void HO(int);
+void EF(int);
+void SU(int);
+void SD(int);
+int forward_scroll(void);
+int reverse_scroll(void);
+void MP(int);
+void move_previous_word(FLAG remove);
+void MN(int);
+void move_next_word(FLAG remove);
+void DCC(int);
+void DPC(int);
+void DLN(int);
+void DNW(int);
+void DPW(int);
+void S(int character);
+void CTL(int);
+void LIB(int);
+LINE *line_insert(LINE *line, const char *string, int len);
+int insert(LINE *line, char *location, char *string);
+LINE *line_delete(LINE *line);
+void delete(LINE *start_line, char *start_textp,
+ LINE *end_line, char *end_textp);
+void PT(int);
+void IF(int);
+void file_insert(int fd, FLAG old_pos);
+void WB(int);
+void MA(int);
+void YA(int);
+void DT(int);
+void set_up(FLAG remove);
+FLAG checkmark(void);
+int legal(void);
+void yank(LINE *start_line, char *start_textp,
+ LINE *end_line, char *end_textp, FLAG remove);
+int scratch_file(FLAG mode);
+void SF(int);
+void SR(int);
+REGEX *get_expression(const char *message);
+void GR(int);
+void LR(int);
+void change(const char *message, FLAG file);
+char *substitute(LINE *line, REGEX *program, char *replacement);
+void search(const char *message, FLAG method);
+int find_y(LINE *match_line);
+void finished(REGEX *program, int *last_exp);
+void compile(char *pattern, REGEX *program);
+LINE *match(REGEX *program, char *string, FLAG method);
+int line_check(REGEX *program, char *string, FLAG method);
+int check_string(REGEX *program, char *string, int *expression);
+int star(REGEX *program, char *end_position, char *string,
+ int *expression);
+int in_list(int *list, char c, int list_length, int opcode);
+void dummy_line(void);
Index: mined1.c
===================================================================
RCS file: /opt/df_cvs/src/bin/mined/mined1.c,v
retrieving revision 1.6
diff -u -r1.6 mined1.c
--- mined1.c 29 Apr 2005 09:14:50 -0000 1.6
+++ mined1.c 30 Apr 2005 00:17:27 -0000
@@ -33,7 +33,7 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* [original code from minix codebase]
- * $DragonFly: src/bin/mined/mined1.c,v 1.6 2005/04/29 09:14:50 joerg Exp $*
+ * $DragonFly$*
*/
/*
* Part one of the mined editor.
@@ -454,11 +454,8 @@
#include <errno.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
-#if __STDC__
#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+#include <stdlib.h>
int ymax = YMAX;
int screenmax = SCREENMAX;
@@ -467,7 +464,8 @@
/*
* Print file status.
*/
-void FS()
+void
+FS(int u __unused)
{
fstatus(file_name[0] ? "" : "[buffer]", -1L);
}
@@ -476,7 +474,8 @@
* Visit (edit) another file. If the file has been modified, ask the user if
* he wants to save it.
*/
-void VI()
+void
+VI(int u __unused)
{
char new_file[LINE_LEN]; /* Buffer to hold new file name */
@@ -500,10 +499,11 @@
/*
* Write file in core to disc.
*/
-int WT()
+int
+WT(void)
{
- register LINE *line;
- register long count = 0L; /* Nr of chars written */
+ LINE *line;
+ long count = 0L; /* Nr of chars written */
char file[LINE_LEN]; /* Buffer for new file name */
int fd; /* Filedescriptor of file */
@@ -558,9 +558,10 @@
}
/* Call WT and discard value returned. */
-void XWT()
+void
+XWT(int u __unused)
{
- (void) WT();
+ WT();
}
@@ -568,11 +569,12 @@
/*
* Call an interactive shell.
*/
-void SH()
+void
+SH(int u __unused)
{
- register int w;
+ int w;
int pid, status;
- char *shell;
+ const char *shell;
if ((shell = getenv("SHELL")) == NIL_PTR) shell = "/bin/sh";
@@ -601,7 +603,7 @@
}
raw_mode(ON);
- RD();
+ RD(0);
if ((status >> 8) == 127) /* Child died with 127 */
error("Cannot exec ", shell);
@@ -614,9 +616,8 @@
* it returns the count'th line before `line'. When the next (previous)
* line is the tail (header) indicating EOF (tof) it stops.
*/
-LINE *proceed(line, count)
-register LINE *line;
-register int count;
+LINE *
+proceed(LINE *line, int count)
{
if (count < 0)
while (count++ < 0 && line != header)
@@ -632,22 +633,20 @@
* If revfl is TRUE, turn on reverse video on both strings. Set stat_visible
* only if bottom_line is visible.
*/
-int bottom_line(revfl, s1, s2, inbuf, statfl)
-FLAG revfl;
-char *s1, *s2;
-char *inbuf;
-FLAG statfl;
+int
+bottom_line(FLAG revfl, const char *s1, const char *s2, char *inbuf,
+ FLAG statfl)
{
int ret = FINE;
char buf[LINE_LEN];
- register char *p = buf;
+ char *p = buf;
*p++ = ' ';
if (s1 != NIL_PTR)
- while (*p = *s1++)
+ while ((*p = *s1++) != NULL)
p++;
if (s2 != NIL_PTR)
- while (*p = *s2++)
+ while ((*p = *s2++) != NULL)
p++;
*p++ = ' ';
*p++ = 0;
@@ -693,11 +692,11 @@
* Count_chars() count the number of chars that the line would occupy on the
* screen. Counting starts at the real x-coordinate of the line.
*/
-int count_chars(line)
-LINE *line;
+int
+count_chars(LINE *line)
{
- register int cnt = get_shift(line->shift_count) * -SHIFT_SIZE;
- register char *textp = line->text;
+ int cnt = get_shift(line->shift_count) * -SHIFT_SIZE;
+ char *textp = line->text;
/* Find begin of line on screen */
while (cnt < 0) {
@@ -728,12 +727,10 @@
* If we're moving to the same x coordinate, try to move the the x-coordinate
* used on the other previous call.
*/
-void move(new_x, new_address, new_y)
-register int new_x;
-int new_y;
-char *new_address;
+void
+move(int new_x, char *new_address, int new_y)
{
- register LINE *line = cur_line; /* For building new cur_line */
+ LINE *line = cur_line; /* For building new cur_line */
int shift = 0; /* How many shifts to make */
static int rel_x = 0; /* Remember relative x position */
int tx = x;
@@ -807,12 +804,11 @@
* Find_x() returns the x coordinate belonging to address.
* (Tabs are expanded).
*/
-int find_x(line, address)
-LINE *line;
-char *address;
+int
+find_x(LINE *line, char *address)
{
- register char *textp = line->text;
- register int nx = get_shift(line->shift_count) * -SHIFT_SIZE;
+ char *textp = line->text;
+ int nx = get_shift(line->shift_count) * -SHIFT_SIZE;
while (textp != address && *textp != '\0') {
if (is_tab(*textp++)) /* Expand tabs */
@@ -827,13 +823,11 @@
* Find_address() returns the pointer in the line with offset x_coord.
* (Tabs are expanded).
*/
-char *find_address(line, x_coord, old_x)
-LINE *line;
-int x_coord;
-int *old_x;
+char *
+find_address(LINE *line, int x_coord, int *old_x)
{
- register char *textp = line->text;
- register int tx = get_shift(line->shift_count) * -SHIFT_SIZE;
+ char *textp = line->text;
+ int tx = get_shift(line->shift_count) * -SHIFT_SIZE;
while (tx < x_coord && *textp != '\n') {
if (is_tab(*textp)) {
@@ -855,10 +849,10 @@
* Length_of() returns the number of characters int the string `string'
* excluding the '\0'.
*/
-int length_of(string)
-register char *string;
+int
+length_of(char *string)
{
- register int count = 0;
+ int count = 0;
if (string != NIL_PTR) {
while (*string++ != '\0')
@@ -871,11 +865,10 @@
* Copy_string() copies the string `from' into the string `to'. `To' must be
* long enough to hold `from'.
*/
-void copy_string(to, from)
-register char *to;
-register char *from;
+void
+copy_string(char *to, const char *from)
{
- while (*to++ = *from++)
+ while ((*to++ = *from++) != NULL)
;
}
@@ -884,11 +877,10 @@
* which must be the first line of the screen, and an y-coordinate,
* which will be the current y-coordinate (if it isn't larger than last_y)
*/
-void reset(head_line, screen_y)
-LINE *head_line;
-int screen_y;
+void
+reset(LINE *head_line, int screen_y)
{
- register LINE *line;
+ LINE *line;
top_line = line = head_line;
@@ -907,25 +899,24 @@
/*
* Set cursor at coordinates x, y.
*/
-void set_cursor(nx, ny)
-int nx, ny;
+void
+set_cursor(int nx, int ny)
{
#ifdef UNIX
- extern char *tgoto();
-
tputs(tgoto(CM, nx, ny), 0, _putchar);
#else
- char text_buffer[10];
+ char text_buf[10];
- build_string(text_buffer, pos_string, ny+1, nx+1);
- string_print(text_buffer);
+ build_string(text_buf, pos_string, ny+1, nx+1);
+ string_print(text_buf);
#endif /* UNIX */
}
/*
* Routine to open terminal when mined is used in a pipeline.
*/
-void open_device()
+void
+open_device(void)
{
if ((input_fd = open("/dev/tty", 0)) < 0)
panic("Cannot open /dev/tty for read");
@@ -935,7 +926,8 @@
* Getchar() reads one character from the terminal. The character must be
* masked with 0377 to avoid sign extension.
*/
-int getchar()
+int
+getchar(void)
{
#ifdef UNIX
return (_getchar() & 0377);
@@ -955,10 +947,8 @@
* rest of the screen with blank_line's.
* When count is negative, a backwards print from `line' will be done.
*/
-void display(x_coord, y_coord, line, count)
-int x_coord, y_coord;
-register LINE *line;
-register int count;
+void
+display(int x_coord, int y_coord, LINE *line, int count)
{
set_cursor(x_coord, y_coord);
@@ -991,9 +981,8 @@
/*
* Write_char does a buffered output.
*/
-int write_char(fd, c)
-int fd;
-char c;
+int
+write_char(int fd, char c)
{
screen [out_count++] = c;
if (out_count == SCREEN_SIZE) /* Flush on SCREEN_SIZE chars */
@@ -1004,9 +993,8 @@
/*
* Writeline writes the given string on the given filedescriptor.
*/
-int writeline(fd, text)
-register int fd;
-register char *text;
+int
+writeline(int fd, const char *text)
{
while(*text)
if (write_char(fd, *text++) == ERRORS)
@@ -1019,14 +1007,17 @@
* printing will start at that x-coordinate. If the FLAG clear_line is TRUE,
* then (screen) line will be cleared when the end of the line has been
* reached.
+ *
+ * parameter
+ * line: Line to print
+ * offset: Offset to start
+ * clear_line: Clear to eoln if TRUE
*/
-void put_line(line, offset, clear_line)
-LINE *line; /* Line to print */
-int offset; /* Offset to start */
-FLAG clear_line; /* Clear to eoln if TRUE */
+void
+put_line(LINE *line, int offset, FLAG clear_line)
{
- register char *textp = line->text;
- register int count = get_shift(line->shift_count) * -SHIFT_SIZE;
+ char *textp = line->text;
+ int count = get_shift(line->shift_count) * -SHIFT_SIZE;
int tab_count; /* Used in tab expansion */
/* Skip all chars as indicated by the offset and the shift_count field */
@@ -1084,8 +1075,8 @@
/*
* Flush the I/O buffer on filedescriptor fd.
*/
-int flush_buffer(fd)
-int fd;
+int
+flush_buffer(int fd)
{
if (out_count <= 0) /* There is nothing to flush */
return FINE;
@@ -1107,8 +1098,8 @@
/*
* Bad_write() is called when a write failed. Notify the user.
*/
-void bad_write(fd)
-int fd;
+void
+bad_write(int fd)
{
if (fd == STD_OUT) /* Cannot write to terminal? */
exit(1);
@@ -1123,8 +1114,8 @@
/*
* Catch the SIGQUIT signal (^\) send to mined. It turns on the quitflag.
*/
-void catch(sig)
-int sig;
+void
+catch(int sig __unused)
{
/* Reset the signal */
signal(SIGQUIT, catch);
@@ -1134,7 +1125,8 @@
/*
* Abort_mined() will leave mined. Confirmation is asked first.
*/
-void abort_mined()
+void
+abort_mined(void)
{
quit = FALSE;
@@ -1163,8 +1155,8 @@
* Set and reset tty into CBREAK or old mode according to argument `state'. It
* also sets all signal characters (except for ^\) to UNDEF. ^\ is caught.
*/
-void raw_mode(state)
-FLAG state;
+void
+raw_mode(FLAG state)
{
static struct termios old_tty;
static struct termios new_tty;
@@ -1196,23 +1188,21 @@
* It writes the message to the terminal, resets the tty and exits.
* Ask the user if he wants to save his file.
*/
-void panic(message)
-register char *message;
+void
+panic(const char *message)
{
- extern char yank_file[];
-
#ifdef UNIX
tputs(CL, 0, _putchar);
build_string(text_buffer, "%s\nError code %d\n", message, errno);
#else
build_string(text_buffer, "%s%s\nError code %d\n", enter_string, message, errno);
#endif /* UNIX */
- (void) write(STD_OUT, text_buffer, length_of(text_buffer));
+ write(STD_OUT, text_buffer, length_of(text_buffer));
if (loading == FALSE)
- XT(); /* Check if file can be saved */
+ XT(0); /* Check if file can be saved */
else
- (void) unlink(yank_file);
+ unlink(yank_file);
raw_mode(OFF);
#ifdef UNIX
@@ -1222,8 +1212,8 @@
#endif /* UNIX */
}
-char *alloc(bytes)
-int bytes;
+char *
+alloc(int bytes)
{
char *p;
@@ -1236,8 +1226,8 @@
return(p);
}
-void free_space(p)
-char *p;
+void
+free_space(char *p)
{
free(p);
}
@@ -1248,7 +1238,7 @@
/* The mapping between input codes and functions. */
-void (*key_map[256])() = { /* map ASCII characters to functions */
+void (*key_map[256])(int) = { /* map ASCII characters to functions */
/* 000-017 */ MA, BL, MP, YA, SD, EL, MN, IF, DPC, S, S, DT, RD, S, DNW,LIB,
/* 020-037 */ DPW, WB, GR, SH, DLN, SU, VI, XWT, XT, PT, ST, ESC, I, GOTO,
HIGH, LOW,
@@ -1294,12 +1284,12 @@
#ifdef UNIX
char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
#else
-char *enter_string = "\033[H\033[J"; /* String printed on entering mined */
-char *pos_string = "\033[%d;%dH"; /* Absolute cursor position */
-char *rev_scroll = "\033M"; /* String for reverse scrolling */
-char *rev_video = "\033[7m"; /* String for starting reverse video */
-char *normal_video = "\033[m"; /* String for leaving reverse video */
-char *blank_line = "\033[K"; /* Clear line to end */
+const char *enter_string = "\033[H\033[J"; /* String printed on entering mined */
+const char *pos_string = "\033[%d;%dH"; /* Absolute cursor position */
+const char *rev_scroll = "\033M"; /* String for reverse scrolling */
+const char *rev_video = "\033[7m"; /* String for starting reverse video */
+const char *normal_video = "\033[m"; /* String for leaving reverse video */
+const char *blank_line = "\033[K"; /* Clear line to end */
#endif /* UNIX */
/*
@@ -1313,9 +1303,10 @@
* Initialize is called when a another file is edited. It free's the allocated
* space and sets modified back to FALSE and fixes the header/tail pointer.
*/
-void initialize()
+void
+initialize(void)
{
- register LINE *line, *next_line;
+ LINE *line, *next_line;
/* Delete the whole list */
for (line = header->next; line != tail; line = next_line) {
@@ -1333,11 +1324,11 @@
/*
* Basename() finds the absolute name of the file out of a given path_name.
*/
-char *basename(path)
-char *path;
+char *
+basename(char *path)
{
- register char *ptr = path;
- register char *last = NIL_PTR;
+ char *ptr = path;
+ char *last = NIL_PTR;
while (*ptr != '\0') {
if (*ptr == '/')
@@ -1358,11 +1349,11 @@
* couldn't be opened, just some initializations are done, and a line consisting
* of a `\n' is installed.
*/
-void load_file(file)
-char *file;
+void
+load_file(const char *file)
{
- register LINE *line = header;
- register int len;
+ LINE *line = header;
+ int len;
long nr_of_chars = 0L;
int fd = -1; /* Filedescriptor for file */
@@ -1403,10 +1394,10 @@
clear_buffer(); /* Clear output buffer */
cur_line = header->next;
fstatus("Read", nr_of_chars);
- (void) close(fd); /* Close file */
+ close(fd); /* Close file */
}
else /* Just install a "\n" */
- (void) line_insert(line, "\n", 1);
+ line_insert(line, "\n", 1);
reset(header->next, 0); /* Initialize pointers */
@@ -1422,14 +1413,13 @@
* Get_line reads one line from filedescriptor fd. If EOF is reached on fd,
* get_line() returns ERRORS, else it returns the length of the string.
*/
-int get_line(fd, buffer)
-int fd;
-register char *buffer;
+int
+get_line(int fd, char *buffer)
{
static char *last = NIL_PTR;
static char *current = NIL_PTR;
static int read_chars;
- register char *cur_pos = current;
+ char *cur_pos = current;
char *begin = buffer;
do {
@@ -1447,13 +1437,14 @@
if (read_chars <= 0) {
if (buffer == begin)
return ERRORS;
- if (*(buffer - 1) != '\n')
+ if (*(buffer - 1) != '\n') {
if (loading == TRUE) /* Add '\n' to last line of file */
*buffer++ = '\n';
else {
*buffer = '\0';
return NO_LINE;
}
+ }
}
*buffer = '\0';
@@ -1464,11 +1455,10 @@
* Install_line installs the buffer into a LINE structure It returns a pointer
* to the allocated structure.
*/
-LINE *install_line(buffer, length)
-char *buffer;
-int length;
+LINE *
+install_line(const char *buffer, int length)
{
- register LINE *new_line = (LINE *) alloc(sizeof(LINE));
+ LINE *new_line = (LINE *) alloc(sizeof(LINE));
new_line->text = alloc(length + 1);
new_line->shift_count = 0;
@@ -1478,13 +1468,11 @@
}
int
-main(argc, argv)
-int argc;
-char *argv[];
+main(int argc, char *argv[])
{
/* mined is the Minix editor. */
- register int index; /* Index in key table */
+ int index; /* Index in key table */
struct winsize winsize;
#ifdef UNIX
@@ -1519,7 +1507,7 @@
if (argc < 2)
load_file(NIL_PTR);
else {
- (void) get_file(NIL_PTR, argv[1]); /* Truncate filename */
+ get_file(NIL_PTR, argv[1]); /* Truncate filename */
load_file(argv[1]);
}
@@ -1547,7 +1535,8 @@
/*
* Redraw the screen
*/
-void RD()
+void
+RD(int u __unused)
{
/* Clear screen */
#ifdef UNIX
@@ -1573,14 +1562,16 @@
/*
* Ignore this keystroke.
*/
-void I()
+void
+I(int u __unused)
{
}
/*
* Leave editor. If the file has changed, ask if the user wants to save it.
*/
-void XT()
+void
+XT(int u __unused)
{
if (modified == TRUE && ask_save() == ERRORS)
return;
@@ -1589,12 +1580,12 @@
set_cursor(0, ymax);
putchar('\n');
flush();
- (void) unlink(yank_file); /* Might not be necessary */
+ unlink(yank_file); /* Might not be necessary */
exit(0);
}
-void (*escfunc(c))()
-int c;
+static void
+(*escfunc(int c))(int)
{
#if (CHIP == M68000)
#ifndef COMPAT
@@ -1629,8 +1620,8 @@
case '1':
switch (ch) {
case '~': return(SF);
- case '7': (void) getchar(); return(MA);
- case '8': (void) getchar(); return(CTL);
+ case '7': getchar(); return(MA);
+ case '8': getchar(); return(CTL);
}
case '2': return(SR);
case '3': return(PD);
@@ -1709,10 +1700,11 @@
* command count times. If a ^\ is given during repeating, stop looping and
* return to main loop.
*/
-void ESC()
+void
+ESC(int u __unused)
{
- register int count = 0;
- register void (*func)();
+ int count = 0;
+ void (*func)(int);
int index;
index = getchar();
@@ -1749,9 +1741,10 @@
/*
* Ask the user if he wants to save his file or not.
*/
-int ask_save()
+int
+ask_save(void)
{
- register int c;
+ int c;
status_line(file_name[0] ? basename(file_name) : "[buffer]" ,
" has been modified. Save? (y/n)");
@@ -1776,10 +1769,11 @@
/*
* Line_number() finds the line number we're on.
*/
-int line_number()
+int
+line_number(void)
{
- register LINE *line = header->next;
- register int count = 1;
+ LINE *line = header->next;
+ int count = 1;
while (line != cur_line) {
count++;
@@ -1792,15 +1786,15 @@
/*
* Display a line telling how many chars and lines the file contains. Also tell
* whether the file is readonly and/or modified.
+ *
+ * parameter
+ * count: Contains number of characters in file
*/
-void file_status(message, count, file, lines, writefl, changed)
-char *message;
-register long count; /* Contains number of characters in file */
-char *file;
-int lines;
-FLAG writefl, changed;
+void
+file_status(const char *message, long count, char *file, int lines,
+ FLAG writefl, FLAG changed)
{
- register LINE *line;
+ LINE *line;
char msg[LINE_LEN + 40];/* Buffer to hold line */
char yank_msg[LINE_LEN];/* Buffer for msg of yank_file */
@@ -1833,23 +1827,13 @@
* Build_string() prints the arguments as described in fmt, into the buffer.
* %s indicates an argument string, %d indicated an argument number.
*/
-#if __STDC__
-void build_string(char *buf, char *fmt, ...)
+void
+build_string(char *buf, const char *fmt, ...)
{
-#else
-void build_string(buf, fmt, va_alist)
-char *buf, *fmt;
-va_dcl
-{
-#endif
va_list argptr;
- char *scanp;
+ const char *scanp;
-#if __STDC__
va_start(argptr, fmt);
-#else
- va_start(argptr);
-#endif
while (*fmt) {
if (*fmt == '%') {
@@ -1867,7 +1851,7 @@
default :
scanp = "";
}
- while (*buf++ = *scanp++)
+ while ((*buf++ = *scanp++) != NULL)
;
buf--;
}
@@ -1882,12 +1866,12 @@
* Output an (unsigned) long in a 10 digit field without leading zeros.
* It returns a pointer to the first digit in the buffer.
*/
-char *num_out(number)
-long number;
+char *
+num_out(long number)
{
static char num_buf[11]; /* Buffer to build number */
- register long digit; /* Next digit of number */
- register long pow = 1000000000L; /* Highest ten power of long */
+ long digit; /* Next digit of number */
+ long pow = 1000000000L; /* Highest ten power of long */
FLAG digit_seen = FALSE;
int i;
@@ -1912,12 +1896,11 @@
* returned. ERRORS is returned on a bad number. The resulting number is put
* into the integer the arguments points to.
*/
-int get_number(message, result)
-char *message;
-int *result;
+int
+get_number(const char *message, int *result)
{
- register int index;
- register int count = 0;
+ int index;
+ int count = 0;
status_line(message, NIL_PTR);
@@ -1947,12 +1930,11 @@
* Input() reads a string from the terminal. When the KILL character is typed,
* it returns ERRORS.
*/
-int input(inbuf, clearfl)
-char *inbuf;
-FLAG clearfl;
+int
+input(char *inbuf, FLAG clearfl)
{
- register char *ptr;
- register char c; /* Character read */
+ char *ptr;
+ char c; /* Character read */
ptr = inbuf;
@@ -2008,11 +1990,11 @@
* Get_file() reads a filename from the terminal. Filenames longer than
* FILE_LENGHT chars are truncated.
*/
-int get_file(message, file)
-char *message, *file;
+int
+get_file(const char *message, char *file)
{
char *ptr;
- int ret;
+ int ret = FINE;
if (message == NIL_PTR || (ret = get_string(message, file, TRUE)) == FINE) {
if (length_of((ptr = basename(file))) > NAME_MAX)
@@ -2028,7 +2010,8 @@
#ifdef UNIX
#undef putchar
-int _getchar()
+int
+_getchar(void)
{
char c;
@@ -2037,21 +2020,22 @@
return c & 0377;
}
-void _flush()
+void
+_flush(void)
{
- (void) fflush(stdout);
+ fflush(stdout);
}
-void _putchar(c)
-char c;
+void
+_putchar(char c)
{
- (void) write_char(STD_OUT, c);
+ write_char(STD_OUT, c);
}
-void get_term()
+void
+get_term(void)
{
static char termbuf[50];
- extern char *tgetstr(), *getenv();
char *loc = termbuf;
char entry[1024];
Index: mined2.c
===================================================================
RCS file: /opt/df_cvs/src/bin/mined/mined2.c,v
retrieving revision 1.3
diff -u -r1.3 mined2.c
--- mined2.c 15 Mar 2005 02:25:25 -0000 1.3
+++ mined2.c 30 Apr 2005 00:17:27 -0000
@@ -50,17 +50,18 @@
/*
* Move one line up.
*/
-void UP()
+void
+UP(int u __unused)
{
if (y == 0) { /* Top line of screen. Scroll one line */
- (void) reverse_scroll();
+ reverse_scroll();
move_to(x, y);
}
else /* Move to previous line */
move_to(x, y - 1);
}
-static char *help_string=
+static const char *help_string=
" Mined (Minix Editor), FreeBSD version.\n"
"------------------------+-------------------------------+---------------------\n"
" CURSOR MOTION | EDITING | MISC\n"
@@ -88,7 +89,8 @@
/*
* Help
*/
-void HLP()
+void
+HLP(int u __unused)
{
char c;
@@ -96,31 +98,33 @@
string_print(help_string);
flush();
c=getchar();
- RD();
+ RD(0);
return;
}
-void ST()
+void
+ST(int u __unused)
{
raw_mode(OFF);
kill(getpid(), SIGTSTP);
raw_mode(ON);
- RD();
+ RD(0);
}
/*
* Move one line down.
*/
-void DN()
+void
+DN(int u __unused)
{
if (y == last_y) { /* Last line of screen. Scroll one line */
if (bot_line->next == tail && bot_line->text[0] != '\n') {
dummy_line(); /* Create new empty line */
- DN();
+ DN(0);
return;
}
else {
- (void) forward_scroll();
+ forward_scroll();
move_to(x, y);
}
}
@@ -131,11 +135,12 @@
/*
* Move left one position.
*/
-void LF()
+void
+LF(int u __unused)
{
if (x == 0 && get_shift(cur_line->shift_count) == 0) {/* Begin of line */
if (cur_line->prev != header) {
- UP(); /* Move one line up */
+ UP(0); /* Move one line up */
move_to(LINE_END, y);
}
}
@@ -146,11 +151,12 @@
/*
* Move right one position.
*/
-void RT()
+void
+RT(int u __unused)
{
if (*cur_text == '\n') {
if (cur_line->next != tail) { /* Last char of file */
- DN(); /* Move one line down */
+ DN(0); /* Move one line down */
move_to(LINE_START, y);
}
}
@@ -161,7 +167,8 @@
/*
* Move to coordinates [0, 0] on screen.
*/
-void HIGH()
+void
+HIGH(int u __unused)
{
move_to(0, 0);
}
@@ -169,7 +176,8 @@
/*
* Move to coordinates [0, YMAX] on screen.
*/
-void LOW()
+void
+LOW(int u __unused)
{
move_to(0, last_y);
}
@@ -177,7 +185,8 @@
/*
* Move to begin of line.
*/
-void BL()
+void
+BL(int u __unused)
{
move_to(LINE_START, y);
}
@@ -185,7 +194,8 @@
/*
* Move to end of line.
*/
-void EL()
+void
+EL(int u __unused)
{
move_to(LINE_END, y);
}
@@ -193,7 +203,8 @@
/*
* GOTO() prompts for a linenumber and moves to that line.
*/
-void GOTO()
+void
+GOTO(int u __unused)
{
int number;
LINE *line;
@@ -212,9 +223,10 @@
* top_line of display.) Try to leave the cursor on the same line. If this is
* not possible, leave cursor on the line halfway the page.
*/
-void PD()
+void
+PD(int u __unused)
{
- register int i;
+ int i;
for (i = 0; i < screenmax; i++)
if (forward_scroll() == ERRORS)
@@ -232,9 +244,10 @@
* Try to leave the cursor on the same line. If this is not possible, leave
* cursor on the line halfway the page.
*/
-void PU()
+void
+PU(int u __unused)
{
- register int i;
+ int i;
for (i = 0; i < screenmax; i++)
if (reverse_scroll() == ERRORS)
@@ -254,13 +267,14 @@
/*
* Go to top of file, scrolling if possible, else redrawing screen.
*/
-void HO()
+void
+HO(int u __unused)
{
if (proceed(top_line, -screenmax) == header)
- PU(); /* It fits. Let PU do it */
+ PU(0); /* It fits. Let PU do it */
else {
reset(header->next, 0);/* Reset top_line, etc. */
- RD(); /* Display full page */
+ RD(0); /* Display full page */
}
move_to(LINE_START, 0);
}
@@ -268,15 +282,16 @@
/*
* Go to last line of file, scrolling if possible, else redrawing screen
*/
-void EF()
+void
+EF(int u __unused)
{
if (tail->prev->text[0] != '\n')
dummy_line();
if (proceed(bot_line, screenmax) == tail)
- PD(); /* It fits. Let PD do it */
+ PD(0); /* It fits. Let PD do it */
else {
reset(proceed(tail->prev, -screenmax), screenmax);
- RD(); /* Display full page */
+ RD(0); /* Display full page */
}
move_to(LINE_START, last_y);
}
@@ -284,12 +299,13 @@
/*
* Scroll one line up. Leave the cursor on the same line (if possible).
*/
-void SU()
+void
+SU(int u __unused)
{
if (top_line->prev == header) /* Top of file. Can't scroll */
return;
- (void) reverse_scroll();
+ reverse_scroll();
set_cursor(0, ymax); /* Erase very bottom line */
#ifdef UNIX
tputs(CE, 0, _putchar);
@@ -302,7 +318,8 @@
/*
* Scroll one line down. Leave the cursor on the same line (if possible).
*/
-void SD()
+void
+SD(int u __unused)
{
if (forward_scroll() != ERRORS)
move_to(x, (y == 0) ? 0 : y - 1);
@@ -314,7 +331,8 @@
* Perform a forward scroll. It returns ERRORS if we're at the last line of the
* file.
*/
-int forward_scroll()
+int
+forward_scroll(void)
{
if (bot_line->next == tail) /* Last line of file. No dice */
return ERRORS;
@@ -331,7 +349,8 @@
* Perform a backwards scroll. It returns ERRORS if we're at the first line
* of the file.
*/
-int reverse_scroll()
+int
+reverse_scroll(void)
{
if (top_line->prev == header)
return ERRORS; /* Top of file. Can't scroll */
@@ -365,16 +384,17 @@
* MP() moves to the start of the previous word. A word is defined as a
* number of non-blank characters separated by tabs spaces or linefeeds.
*/
-void MP()
+void
+MP(int u __unused)
{
move_previous_word(NO_DELETE);
}
-void move_previous_word(remove)
-FLAG remove;
+void
+move_previous_word(FLAG remove)
{
- register char *begin_line;
- register char *textp;
+ char *begin_line;
+ char *textp;
char start_char = *cur_text;
char *start_pos = cur_text;
@@ -385,7 +405,7 @@
start_char = '\0';
}
- LF();
+ LF(0);
begin_line = cur_line->text;
textp = cur_text;
@@ -415,15 +435,16 @@
* non-blank characters separated by tabs spaces or linefeeds. Always keep in
* mind that the pointer shouldn't pass the '\n'.
*/
-void MN()
+void
+MN(int u __unused)
{
move_next_word(NO_DELETE);
}
-void move_next_word(remove)
-FLAG remove;
+void
+move_next_word(FLAG remove)
{
- register char *textp = cur_text;
+ char *textp = cur_text;
/* Move to the end of the current word. */
while (*textp != '\n' && alpha(*textp))
@@ -440,7 +461,7 @@
/* If we're at end of line. move to the first word on the next line. */
if (*textp == '\n' && cur_line->next != tail) {
- DN();
+ DN(0);
move_to(LINE_START, y);
textp = cur_text;
while (*textp != '\n' && white_space(*textp))
@@ -459,7 +480,8 @@
* If this character is the only character of the line, the current line will
* be deleted.
*/
-void DCC()
+void
+DCC(int u __unused)
{
if (*cur_text == '\n')
delete(cur_line,cur_text, cur_line->next,cur_line->next->text);
@@ -472,23 +494,25 @@
* at the beginning of the line, the last character if the previous line is
* deleted.
*/
-void DPC()
+void
+DPC(int u __unused)
{
if (x == 0 && cur_line->prev == header)
return; /* Top of file */
- LF(); /* Move one left */
- DCC(); /* Delete character under cursor */
+ LF(0); /* Move one left */
+ DCC(0); /* Delete character under cursor */
}
/*
* DLN deletes all characters until the end of the line. If the current
* character is a '\n', then delete that char.
*/
-void DLN()
+void
+DLN(int u __unused)
{
if (*cur_text == '\n')
- DCC();
+ DCC(0);
else
delete(cur_line, cur_text, cur_line, cur_text + length_of(cur_text) -1);
}
@@ -496,10 +520,11 @@
/*
* DNW() deletes the next word (as described in MN())
*/
-void DNW()
+void
+DNW(int u __unused)
{
if (*cur_text == '\n')
- DCC();
+ DCC(0);
else
move_next_word(DELETE);
}
@@ -507,10 +532,11 @@
/*
* DPW() deletes the next word (as described in MP())
*/
-void DPW()
+void
+DPW(int u __unused)
{
if (cur_text == cur_line->text)
- DPC();
+ DPC(0);
else
move_previous_word(DELETE);
}
@@ -518,8 +544,8 @@
/*
* Insert character `character' at current location.
*/
-void S(character)
-register char character;
+void
+S(int character)
{
static char buffer[2];
@@ -533,7 +559,7 @@
set_cursor(0, y);
if (y == screenmax) { /* Can't use display */
line_print(cur_line);
- (void) forward_scroll();
+ forward_scroll();
}
else {
reset(top_line, y); /* Reset pointers */
@@ -553,9 +579,10 @@
* CTL inserts a control-char at the current location. A message that this
* function is called is displayed at the status line.
*/
-void CTL()
+void
+CTL(int u __unused)
{
- register char ctrl;
+ char ctrl;
status_line("Enter control character.", NIL_PTR);
if ((ctrl = getchar()) >= '\01' && ctrl <= '\037') {
@@ -570,10 +597,11 @@
* LIB insert a line at the current position and moves back to the end of
* the previous line.
*/
-void LIB()
+void
+LIB(int u __unused)
{
S('\n'); /* Insert the line */
- UP(); /* Move one line up */
+ UP(0); /* Move one line up */
move_to(LINE_END, y); /* Move to end of this line */
}
@@ -581,12 +609,10 @@
* Line_insert() inserts a new line with text pointed to by `string'.
* It returns the address of the new line.
*/
-LINE *line_insert(line, string, len)
-register LINE *line;
-char *string;
-int len;
+LINE *
+line_insert(LINE *line, const char *string, int len)
{
- register LINE *new_line;
+ LINE *new_line;
/* Allocate space for LINE structure and text */
new_line = install_line(string, len);
@@ -606,12 +632,11 @@
/*
* Insert() insert the string `string' at the given line and location.
*/
-int insert(line, location, string)
-register LINE *line;
-char *location, *string;
+int
+insert(LINE *line, char *location, char *string)
{
- register char *bufp = text_buffer; /* Buffer for building line */
- register char *textp = line->text;
+ char *bufp = text_buffer; /* Buffer for building line */
+ char *textp = line->text;
if (length_of(textp) + length_of(string) >= MAX_CHARS) {
error("Line too long", NIL_PTR);
@@ -646,10 +671,10 @@
* Line_delete() deletes the argument line out of the line list. The pointer to
* the next line is returned.
*/
-LINE *line_delete(line)
-register LINE *line;
+LINE *
+line_delete(LINE *line)
{
- register LINE *next_line = line->next;
+ LINE *next_line = line->next;
/* Delete the line */
line->prev->next = line->next;
@@ -670,13 +695,12 @@
* startposition and endposition and fixes the screen accordingly. It
* returns the number of lines deleted.
*/
-void delete(start_line, start_textp, end_line, end_textp)
-register LINE *start_line;
-LINE *end_line;
-char *start_textp, *end_textp;
+void
+delete(LINE *start_line, char *start_textp,
+ LINE *end_line, char *end_textp)
{
- register char *textp = start_line->text;
- register char *bufp = text_buffer; /* Storage for new line->text */
+ char *textp = start_line->text;
+ char *bufp = text_buffer; /* Storage for new line->text */
LINE *line, *stop;
int line_cnt = 0; /* Nr of lines deleted */
int count = 0;
@@ -711,7 +735,7 @@
/* Check if last line of file should be deleted */
if (end_textp == NIL_PTR && length_of(start_line->text) == 1 && nlines > 1) {
start_line = start_line->prev;
- (void) line_delete(start_line->next);
+ line_delete(start_line->next);
line_cnt++;
}
else { /* Install new text */
@@ -762,9 +786,10 @@
/*
* PT() inserts the buffer at the current location.
*/
-void PT()
+void
+PT(int u __unused)
{
- register int fd; /* File descriptor for buffer */
+ int fd; /* File descriptor for buffer */
if ((fd = scratch_file(READ)) == ERRORS)
error("Buffer is empty.", NIL_PTR);
@@ -778,9 +803,10 @@
* IF() prompt for a filename and inserts the file at the current location
* in the file.
*/
-void IF()
+void
+IF(int u __unused)
{
- register int fd; /* File descriptor of file */
+ int fd; /* File descriptor of file */
char name[LINE_LEN]; /* Buffer for file name */
/* Get the file name */
@@ -799,13 +825,12 @@
* File_insert() inserts a an opened file (as given by filedescriptor fd)
* at the current location.
*/
-void file_insert(fd, old_pos)
-int fd;
-FLAG old_pos;
+void
+file_insert(int fd, FLAG old_pos)
{
char line_buffer[MAX_CHARS]; /* Buffer for next line */
- register LINE *line = cur_line;
- register int line_count = nlines; /* Nr of lines inserted */
+ LINE *line = cur_line;
+ int line_count = nlines; /* Nr of lines inserted */
LINE *page = cur_line;
int ret = ERRORS;
@@ -858,11 +883,12 @@
* WB() writes the buffer (yank_file) into another file, which
* is prompted for.
*/
-void WB()
+void
+WB(int u __unused)
{
- register int new_fd; /* Filedescriptor to copy file */
+ int new_fd; /* Filedescriptor to copy file */
int yank_fd; /* Filedescriptor to buffer */
- register int cnt; /* Count check for read/write */
+ int cnt; /* Count check for read/write */
int ret = 0; /* Error check for write */
char file[LINE_LEN]; /* Output file */
@@ -893,8 +919,8 @@
}
/* Clean up open files and status_line */
- (void) close(new_fd);
- (void) close(yank_fd);
+ close(new_fd);
+ close(yank_fd);
if (ret != ERRORS) /* Bad write */
file_status("Wrote", chars_saved, file, lines_saved, TRUE, FALSE);
@@ -903,7 +929,8 @@
/*
* MA sets mark_line (mark_text) to the current line (text pointer).
*/
-void MA()
+void
+MA(int u __unused)
{
mark_line = cur_line;
mark_text = cur_text;
@@ -914,7 +941,8 @@
* YA() puts the text between the marked position and the current
* in the buffer.
*/
-void YA()
+void
+YA(int u __unused)
{
set_up(NO_DELETE);
}
@@ -922,7 +950,8 @@
/*
* DT() is essentially the same as YA(), but in DT() the text is deleted.
*/
-void DT()
+void
+DT(int u __unused)
{
set_up(DELETE);
}
@@ -931,9 +960,12 @@
* Set_up is an interface to the actual yank. It calls checkmark () to check
* if the marked position is still valid. If it is, yank is called with the
* arguments in the right order.
+ *
+ * parameter
+ * remove: DELETE if text should be deleted
*/
-void set_up(remove)
-FLAG remove; /* DELETE if text should be deleted */
+void
+set_up(FLAG remove)
{
switch (checkmark()) {
case NOT_VALID :
@@ -960,9 +992,10 @@
* NOT_VALID is returned when mark_line and/or mark_text are no longer valid.
* Legal() checks if mark_text is valid on the mark_line.
*/
-FLAG checkmark()
+FLAG
+checkmark(void)
{
- register LINE *line;
+ LINE *line;
FLAG cur_seen = FALSE;
/* Special case: check is mark_line and cur_line are the same. */
@@ -993,9 +1026,10 @@
/*
* Legal() checks if mark_text is still a valid pointer.
*/
-int legal()
+int
+legal(void)
{
- register char *textp = mark_line->text;
+ char *textp = mark_line->text;
/* Locate mark_text on mark_line */
while (textp != mark_text && *textp++ != '\0')
@@ -1008,14 +1042,16 @@
* the buffer.
* The caller must check that the arguments to yank() are valid. (E.g. in
* the right order)
- */
-void yank(start_line, start_textp, end_line, end_textp, remove)
-LINE *start_line, *end_line;
-char *start_textp, *end_textp;
-FLAG remove; /* DELETE if text should be deleted */
+ *
+ * parameter
+ * remove: DELETE if text should be deleted
+ */
+void
+yank(LINE *start_line, char *start_textp, LINE *end_line, char *end_textp,
+ FLAG remove)
{
- register LINE *line = start_line;
- register char *textp = start_textp;
+ LINE *line = start_line;
+ char *textp = start_textp;
int fd;
/* Creat file to hold buffer */
@@ -1029,7 +1065,7 @@
/* Keep writing chars until the end_location is reached. */
while (textp != end_textp) {
if (write_char(fd, *textp) == ERRORS) {
- (void) close(fd);
+ close(fd);
return;
}
if (*textp++ == '\n') { /* Move to the next line */
@@ -1042,10 +1078,10 @@
/* Flush the I/O buffer and close file */
if (flush_buffer(fd) == ERRORS) {
- (void) close(fd);
+ close(fd);
return;
}
- (void) close(fd);
+ close(fd);
yank_status = VALID;
/*
@@ -1072,12 +1108,16 @@
#define MAXTRAILS 26
-int scratch_file(mode)
-FLAG mode; /* Can be READ or WRITE permission */
+/*
+ * parameter
+ * mode: Can be READ or WRITE permission
+ */
+int
+scratch_file(FLAG mode)
{
static int trials = 0; /* Keep track of trails */
- register char *y_ptr, *n_ptr;
- int fd; /* Filedescriptor to buffer */
+ char *y_ptr, *n_ptr;
+ int fd = ERRORS; /* Filedescriptor to buffer */
/* If yank_status == NOT_VALID, scratch_file is called for the first time */
if (yank_status == NOT_VALID && mode == WRITE) { /* Create new file */
@@ -1135,7 +1175,8 @@
/*
* SF searches forward for an expression.
*/
-void SF()
+void
+SF(int u __unused)
{
search("Search forward:", FORWARD);
}
@@ -1143,7 +1184,8 @@
/*
* SF searches backwards for an expression.
*/
-void SR()
+void
+SR(int u __unused)
{
search("Search reverse:", REVERSE);
}
@@ -1155,8 +1197,8 @@
* The save flag indicates whether the expression should be appended at the
* message pointer.
*/
-REGEX *get_expression(message)
-char *message;
+REGEX *
+get_expression(const char *message)
{
static REGEX program; /* Program of expression */
char exp_buf[LINE_LEN]; /* Buffer for new expr. */
@@ -1185,7 +1227,8 @@
* GR() a replaces all matches from the current position until the end
* of the file.
*/
-void GR()
+void
+GR(int u __unused)
{
change("Global replace:", VALID);
}
@@ -1193,7 +1236,8 @@
/*
* LR() replaces all matches on the current line.
*/
-void LR()
+void
+LR(int u __unused)
{
change("Line replace:", NOT_VALID);
}
@@ -1203,16 +1247,18 @@
* all matches of the expression into the substitution. change() start looking
* for expressions at the current line and continues until the end of the file
* if the FLAG file is VALID.
+ *
+ * parameter
+ * message: Message to prompt for expression
*/
-void change(message, file)
-char *message; /* Message to prompt for expression */
-FLAG file;
+void
+change(const char *message, FLAG file)
{
char mess_buf[LINE_LEN]; /* Buffer to hold message */
char replacement[LINE_LEN]; /* Buffer to hold subst. pattern */
REGEX *program; /* Program resulting from compilation */
- register LINE *line = cur_line;
- register char *textp;
+ LINE *line = cur_line;
+ char *textp;
long lines = 0L; /* Nr of lines on which subs occurred */
long subs = 0L; /* Nr of subs made */
int page = y; /* Index to check if line is on screen*/
@@ -1273,14 +1319,15 @@
* Substitute() replaces the match on this ogram. Every '&' in the replacement is replaced by
* the original match. A \ in the replacement escapes the next character.
+ *
+ * parameter
+ * replacement: Contains replacement pattern
*/
-char *substitute(line, program, replacement)
-LINE *line;
-REGEX *program;
-char *replacement; /* Contains replacement pattern */
+char *
+substitute(LINE *line, REGEX *program, char *replacement)
{
- register char *textp = text_buffer;
- register char *subp = replacement;
+ char *textp = text_buffer;
+ char *subp = replacement;
char *linep = line->text;
char *amp;
@@ -1332,12 +1379,11 @@
* Find_x() and find_y() display the right page on the screen, and return
* the right coordinates for x and y. These coordinates are passed to move_to()
*/
-void search(message, method)
-char *message;
-FLAG method;
+void
+search(const char *message, FLAG method)
{
- register REGEX *program;
- register LINE *match_line;
+ REGEX *program;
+ LINE *match_line;
/* Get the expression */
if ((program = get_expression(message)) == NIL_REG)
@@ -1363,11 +1409,11 @@
* returns the new y coordinate, else it displays the correct page with the
* matched line in the middle and returns the new y value;
*/
-int find_y(match_line)
-LINE *match_line;
+int
+find_y(LINE *match_line)
{
- register LINE *line;
- register int count = 0;
+ LINE *line;
+ int count = 0;
/* Check if match_line is on the same page as currently displayed. */
for (line = top_line; line != match_line && line != bot_line->next;
@@ -1389,7 +1435,7 @@
/* Reset pointers and redraw the screen */
reset(line, 0);
- RD();
+ RD(0);
return count;
}
@@ -1414,7 +1460,7 @@
int exp_buffer[BLOCK_SIZE];
/* Errors often used */
-char *too_long = "Regular expression too long";
+static const char *too_long = "Regular expression too long";
/*
* Reg_error() is called by compile() is something went wrong. It set the
@@ -1427,11 +1473,10 @@
* allocates space for the expression, and copies the expression buffer into
* this field.
*/
-void finished(program, last_exp)
-register REGEX *program;
-int *last_exp;
+void
+finished(REGEX *program, int *last_exp)
{
- register int length = (last_exp - exp_buffer) * sizeof(int);
+ int length = (last_exp - exp_buffer) * sizeof(int);
/* Allocate space */
program->result.expression = (int *) alloc(length);
@@ -1445,14 +1490,16 @@
* is set to REG_ERROR and an error message is set into the err_mess field of
* the union. If all went well the expression is saved and the expression
* pointer is set to the saved (and compiled) expression.
+ *
+ * parameter
+ * pattern: Pointer to pattern
*/
-void compile(pattern, program)
-register char *pattern; /* Pointer to pattern */
-REGEX *program;
+void
+compile(char *pattern, REGEX *program)
{
- register int *expression = exp_buffer;
+ int *expression = exp_buffer;
int *prev_char; /* Pointer to previous compiled atom */
- int *acct_field; /* Pointer to last BRACKET start */
+ int *acct_field = NULL; /* Pointer to last BRACKET start */
FLAG negate; /* Negate flag for BRACKET */
char low_char; /* Index for chars in BRACKET */
char c;
@@ -1587,12 +1634,10 @@
* Match() will look through the whole file until a match is found.
* NIL_LINE is returned if no match could be found.
*/
-LINE *match(program, string, method)
-REGEX *program;
-char *string;
-register FLAG method;
+LINE *
+match(REGEX *program, char *string, FLAG method)
{
- register LINE *line = cur_line;
+ LINE *line = cur_line;
char old_char; /* For saving chars */
/* Corrupted program */
@@ -1634,12 +1679,10 @@
* indicates FORWARD or REVERSE search. It scans through the whole string
* until a match is found, or the end of the string is reached.
*/
-int line_check(program, string, method)
-register REGEX *program;
-char *string;
-FLAG method;
+int
+line_check(REGEX *program, char *string, FLAG method)
{
- register char *textp = string;
+ char *textp = string;
/* Assign start_ptr field. We might find a match right away! */
program->start_ptr = textp;
@@ -1682,14 +1725,12 @@
* (and expression). Check() return MATCH for a match, NO_MATCH is the string
* couldn't be matched or REG_ERROR for an illegal opcode in expression.
*/
-int check_string(program, string, expression)
-REGEX *program;
-register char *string;
-int *expression;
+int
+check_string(REGEX *program, char *string, int *expression)
{
- register int opcode; /* Holds opcode of next expr. atom */
+ int opcode; /* Holds opcode of next expr. atom */
char c; /* Char that must be matched */
- char *mark; /* For marking position */
+ char *mark = NULL; /* For marking position */
int star_fl; /* A star has been born */
if (expression == NIL_INT)
@@ -1700,7 +1741,7 @@
*string != '\0' && *string != '\n') {
c = *expression & LOW_BYTE; /* Extract match char */
opcode = *expression & HIGH_BYTE; /* Extract opcode */
- if (star_fl = (opcode & STAR)) { /* Check star occurrence */
+ if ((star_fl = (opcode & STAR)) != 0) { /* Check star occurrence */
opcode &= ~STAR; /* Strip opcode */
mark = string; /* Mark current position */
}
@@ -1758,11 +1799,8 @@
* It searches backwards until the (in check_string()) marked position
* is reached, or a match is found.
*/
-int star(program, end_position, string, expression)
-REGEX *program;
-register char *end_position;
-register char *string;
-int *expression;
+int
+star(REGEX *program, char *end_position, char *string, int *expression)
{
do {
string--;
@@ -1778,11 +1816,8 @@
* it returns MATCH. if it isn't it returns NO_MATCH. These returns values
* are reversed when the NEGATE field in the opcode is present.
*/
-int in_list(list, c, list_length, opcode)
-register int *list;
-char c;
-register int list_length;
-int opcode;
+int
+in_list(int *list, char c, int list_length, int opcode)
{
if (c == '\0' || c == '\n') /* End of string, never matches */
return NO_MATCH;
@@ -1799,9 +1834,10 @@
* useful in combination with the EF and DN command in combination with the
* Yank command set.
*/
-void dummy_line()
+void
+dummy_line(void)
{
- (void) line_insert(tail->prev, "\n", 1);
+ line_insert(tail->prev, "\n", 1);
tail->prev->shift_count = DUMMY;
if (last_y != screenmax) {
last_y++;
More information about the Submit
mailing list