bin/mined cleanup stage2

Sepherosa Ziehau sepherosa at gmail.com
Fri Apr 29 02:48:54 PDT 2005


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

-- 
Live Free or Die
--- mined.h	2005-04-30 01:31:29.000000000 +0800
+++ mined.h	2005-04-30 01:33:13.000000000 +0800
@@ -62,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 */
@@ -158,7 +158,7 @@
  */
 struct regex {
   union {
-  	char *err_mess;
+  	const char *err_mess;
   	int *expression;
   } result;
   char status;
@@ -200,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 */
@@ -288,47 +288,48 @@
 void	 XWT(int);
 void	 SH(int);
 LINE	*proceed(LINE *line, int count);
-int	 bottom_line(FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl);
+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, char *from);
+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, char *text);
+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(char *message);
+void	 panic(const char *message);
 char	*alloc(int bytes);
 void	 free_space(char *p);
 void	 initialize(void);
 char	*basename(char *path);
-void	 load_file(char *file);
+void	 load_file(const char *file);
 int	 get_line(int fd, char *buffer);
-LINE	*install_line(char *buffer, int length);
+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(char *message, long count, char *file, int lines,
+void	 file_status(const char *message, long count, char *file, int lines,
 		     FLAG writefl, FLAG changed);
-void	 build_string(char *buf, char *fmt, ...);
+void	 build_string(char *buf, const char *fmt, ...);
 char	*num_out(long number);
-int	 get_number(char *message, int *result);
+int	 get_number(const char *message, int *result);
 int	 input(char *inbuf, FLAG clearfl);
-int	 get_file(char *message, char *file);
+int	 get_file(const char *message, char *file);
 int	 _getchar(void);
 void	 _flush(void);
 void	 _putchar(int c);
@@ -367,7 +368,7 @@
 void	 S(int character);
 void	 CTL(int);
 void	 LIB(int);
-LINE	*line_insert(LINE *line, char *string, int len);
+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,
@@ -387,12 +388,12 @@
 int	 scratch_file(FLAG mode);
 void	 SF(int);
 void	 SR(int);
-REGEX	*get_expression(char *message);
+REGEX	*get_expression(const char *message);
 void	 GR(int);
 void	 LR(int);
-void	 change(char *message, FLAG file);
+void	 change(const char *message, FLAG file);
 char	*substitute(LINE *line, REGEX *program, char *replacement);
-void	 search(char *message, FLAG method);
+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);
--- mined1.c	2005-04-30 01:31:29.000000000 +0800
+++ mined1.c	2005-04-30 01:32:35.000000000 +0800
@@ -574,7 +574,7 @@
 {
   int w;
   int pid, status;
-  char *shell;
+  const char *shell;
 
   if ((shell = getenv("SHELL")) == NIL_PTR) shell = "/bin/sh";
 
@@ -634,7 +634,8 @@
  * only if bottom_line is visible.
  */
 int
-bottom_line(FLAG revfl, char *s1, char *s2, char *inbuf, FLAG statfl)
+bottom_line(FLAG revfl, const char *s1, const char *s2, char *inbuf,
+	    FLAG statfl)
 {
   int ret = FINE;
   char buf[LINE_LEN];
@@ -865,7 +866,7 @@
  * long enough to hold `from'.
  */
 void
-copy_string(char *to, char *from)
+copy_string(char *to, const char *from)
 {
   while ((*to++ = *from++) != NULL)
   	;
@@ -904,10 +905,10 @@
 #ifdef UNIX
   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 */
 }
 
@@ -993,7 +994,7 @@
  * Writeline writes the given string on the given filedescriptor.
  */
 int
-writeline(int fd, char *text)
+writeline(int fd, const char *text)
 {
   while(*text)
   	 if (write_char(fd, *text++) == ERRORS)
@@ -1188,7 +1189,7 @@
  * Ask the user if he wants to save his file.
  */
 void
-panic(char *message)
+panic(const char *message)
 {
 #ifdef UNIX
   tputs(CL, 0, _putchar);
@@ -1283,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 */
 
 /* 
@@ -1349,7 +1350,7 @@
  * of a `\n' is installed.
  */
 void
-load_file(char *file)
+load_file(const char *file)
 {
   LINE *line = header;
   int len;
@@ -1455,7 +1456,7 @@
  * to the allocated structure.
  */
 LINE *
-install_line(char *buffer, int length)
+install_line(const char *buffer, int length)
 {
   LINE *new_line = (LINE *) alloc(sizeof(LINE));
 
@@ -1790,7 +1791,7 @@
  * count:	Contains number of characters in file
  */
 void
-file_status(char *message, long count, char *file, int lines,
+file_status(const char *message, long count, char *file, int lines,
 	    FLAG writefl, FLAG changed)
 {
   LINE *line;
@@ -1827,10 +1828,10 @@
  * %s indicates an argument string, %d indicated an argument number.
  */
 void
-build_string(char *buf, char *fmt, ...)
+build_string(char *buf, const char *fmt, ...)
 {
   va_list argptr;
-  char *scanp;
+  const char *scanp;
 
   va_start(argptr, fmt);
 
@@ -1896,7 +1897,7 @@
  * into the integer the arguments points to.
  */
 int
-get_number(char *message, int *result)
+get_number(const char *message, int *result)
 {
   int index;
   int count = 0;
@@ -1990,7 +1991,7 @@
  * FILE_LENGHT chars are truncated.
  */
 int
-get_file(char *message, char *file)
+get_file(const char *message, char *file)
 {
   char *ptr;
   int ret = FINE;
--- mined2.c	2005-04-30 01:31:29.000000000 +0800
+++ mined2.c	2005-04-30 01:32:35.000000000 +0800
@@ -61,7 +61,7 @@
   	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"
@@ -610,7 +610,7 @@
  * It returns the address of the new line.
  */
 LINE *
-line_insert(LINE *line, char *string, int len)
+line_insert(LINE *line, const char *string, int len)
 {
   LINE *new_line;
 
@@ -1198,7 +1198,7 @@
  * message pointer.
  */
 REGEX *
-get_expression(char *message)
+get_expression(const char *message)
 {
   static REGEX program;			/* Program of expression */
   char exp_buf[LINE_LEN];			/* Buffer for new expr. */
@@ -1252,7 +1252,7 @@
  * message:	Message to prompt for expression
  */
 void
-change(char *message, FLAG file)
+change(const char *message, FLAG file)
 {
   char mess_buf[LINE_LEN];	/* Buffer to hold message */
   char replacement[LINE_LEN];	/* Buffer to hold subst. pattern */
@@ -1380,7 +1380,7 @@
  * the right coordinates for x and y. These coordinates are passed to move_to()
  */
 void
-search(char *message, FLAG method)
+search(const char *message, FLAG method)
 {
   REGEX *program;
   LINE *match_line;
@@ -1460,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




More information about the Submit mailing list