Commit 0c397ebe authored by Peter Pentchev's avatar Peter Pentchev

Make a whole slew of variables and parameters const char *.

parent aab0710b
......@@ -50,7 +50,7 @@
#include <stdlib.h>
#include <unistd.h>
static char *usage = "\
static const char *usage = "\
usage: bin2c [-t] [-h] [-o outputfile] [-n name] [inputfile]\n\
-t you can use this option if the inputfile is a small (< 1K) textfile.\n\
-h display this help message.\n\
......@@ -64,7 +64,7 @@ usage: bin2c [-t] [-h] [-o outputfile] [-n name] [inputfile]\n\
int
main(int argc, char **argv)
{
char *name = "data";
const char *name = "data";
FILE *in = stdin, *out = stdout;
int text_f = 0;
char *outfile = 0;
......
......@@ -97,7 +97,7 @@ enum calc_object_e {
|| x.type == CO_FLOAT \
|| x.type == CO_BOOLEAN)
static char *calc_object_names[] = {
static const char *calc_object_names[] = {
"none", "integer", "float", "boolean", "unary operator", "binary operator",
"variable", "error", 0
};
......@@ -109,7 +109,7 @@ enum calc_unary_operator_e {
OP_max_unary_operator
};
static char *calc_unary_operator_names[OP_max_unary_operator] = {
static const char *calc_unary_operator_names[OP_max_unary_operator] = {
"- neg", "! not", "~ comp", "( paropen", ") parclose", ": exec"
};
......@@ -130,7 +130,7 @@ static int prec[OP_max_binary_operator] = {
0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8
};
static char *calc_binary_operator_names[OP_max_binary_operator] = {
static const char *calc_binary_operator_names[OP_max_binary_operator] = {
"** pow",
"* mul", "/ div", "% mod", "+ add", "- sub", "<< shl", ">> shr",
"< les", "<= leq", "> grt", ">= geq", "== equ", "!= neq",
......@@ -972,7 +972,7 @@ eval: /* evaluate a parenthesed expression */
static int
istrue(char *s, char **endptr)
{
static char *true_strings[] = { "true", "t", "TRUE", "True", "T",
static const char *true_strings[] = { "true", "t", "TRUE", "True", "T",
"yes", "y", "YES", "Yes", "on", "ON", "On", 0 };
int i, l;
......@@ -989,7 +989,7 @@ istrue(char *s, char **endptr)
static int
isfalse(char *s, char **endptr)
{
static char *false_strings[] = { "false", "f", "FALSE", "False", "F",
static const char *false_strings[] = { "false", "f", "FALSE", "False", "F",
"no", "n", "NO", "No", "off", "OFF", "Off", 0 };
int i, l;
......
This diff is collapsed.
......@@ -1324,7 +1324,7 @@ he_get_counter(hedit)
long count = -1;
int key, digit;
enum mode_e { OCT = 8, DEC = 10, HEX = 16 } mode = DEC;
char *fmt = 0, *prefix = 0;
const char *fmt = 0, *prefix = 0;
tio_goto_line(hx_lines - 1);
tio_return();
......
......@@ -76,7 +76,7 @@
#define ERESTARTSYS EINTR
#endif
char *exh_initialize[] = {
const char *exh_initialize[] = {
":map b :?\\<[~HAT ^V^I]^M",
":map w :/\\<[~HAT ^V^I]^M",
":map e :/[~HAT ^V^I]\\>^M",
......@@ -90,7 +90,7 @@ char *exh_initialize[] = {
};
static int
exh_shell_command(char *command, int pager_f)
exh_shell_command(const char *command, int pager_f)
/* command to be executed by the shell specified by
* the "SHELL" environment variable. the default shell
* is `EXH_DEFAULT_SHELL'. */
......@@ -111,9 +111,9 @@ exh_shell_command(char *command, int pager_f)
tio_suspend();
tio_clear();
tio_flush();
if (!(*shell = getenv("SHELL"))) *shell = EXH_DEFAULT_SHELL;
if (!(*shell = getenv("SHELL"))) *shell = strdup(EXH_DEFAULT_SHELL);
*shell = strdup(*shell);
if (!(*pager = getenv("PAGER"))) *pager = EXH_DEFAULT_PAGER;
if (!(*pager = getenv("PAGER"))) *pager = strdup(EXH_DEFAULT_PAGER);
*pager = strdup(*pager);
/* break `*shell' and `*pager' down into whitespace separated
* substrings. it is *not* possible to mask whitespace characters in any
......@@ -265,7 +265,7 @@ exh_subshell(void)
tio_suspend();
tio_clear();
tio_flush();
if (!(*shell = getenv("SHELL"))) *shell = EXH_DEFAULT_SHELL;
if (!(*shell = getenv("SHELL"))) *shell = strdup(EXH_DEFAULT_SHELL);
*shell = strdup(*shell);
/* break `*shell' down into whitespace separated substrings.
* it is *not* possible to mask whitespace characters in any way. */
......@@ -297,15 +297,15 @@ exh_subshell(void)
}
/* exh_subshell */
char *
exh_skip_expression(char *exp, char separator)
const char *
exh_skip_expression(const char *exp, char separator)
/* returns a pointer to the first unmasked occurrence of the separator
* `separator'; separators within a range or prefixed by `\' are ignored.
* if no separator is found, 0 is returned.
*/
{
char *p = exp;
char *s = 0;
const char *p = exp;
const char *s = 0;
for (;; ++p) {
while (*p && *p != separator && *p != '\\' && *p != '[') ++p;
......@@ -331,14 +331,14 @@ exh_skip_expression(char *exp, char separator)
}
/* exh_skip_expression */
char *
exh_skip_replace(char *exp, char separator)
const char *
exh_skip_replace(const char *exp, char separator)
/* similar to `exh_skip_expression()', but ignores the special meaning of
* brackets.
*/
{
char *p = exp;
char *s = 0;
const char *p = exp;
const char *s = 0;
for (;; ++p) {
while (*p && *p != separator && *p != '\\') ++p;
......@@ -355,10 +355,10 @@ exh_skip_replace(char *exp, char separator)
}
/* exh_skip_replace */
static char *
exh_get_number(char *exp, unsigned long *number)
static const char *
exh_get_number(const char *exp, unsigned long *number)
{
char *p;
const char *p;
switch (*exp) {
case '0': /* octal or hex number */
......@@ -409,14 +409,14 @@ exh_get_number(char *exp, unsigned long *number)
}
/* exh_get_number */
static char *
exh_get_address(struct he_s *hedit, char *exp, unsigned long *address)
static const char *
exh_get_address(struct he_s *hedit, const char *exp, unsigned long *address)
/* evaluate the specified address and store it in `*address'. on success
* a skip-pointer for the expression is returned, else (if `exp' is not
* a valid address or expression) 0 is returned.
*/
{
char *p = exp, *q;
const char *p = exp, *q;
char *rs;
long rl, ml;
int direction;
......@@ -438,8 +438,14 @@ exh_get_address(struct he_s *hedit, char *exp, unsigned long *address)
/* fall through */
case '/': /* forward search */
p = exh_skip_expression(q = p + 1, separator);
if (p) *p++ = 0; else p = exp + strlen(exp);
*address = he_search(hedit, q, "", direction, 0, 1, -1, &rs, &rl, &ml);
size_t len = p? (size_t)(p - q): strlen(exp);
if (p)
p++;
else
p = exp + len;
char *needle = alloca(len + 1);
snprintf(needle, len + 1, "%s", q);
*address = he_search(hedit, needle, "", direction, 0, 1, -1, &rs, &rl, &ml);
switch (*address) {
case -2: /* invalid expression */
assert(rx_error);
......@@ -519,7 +525,7 @@ exh_get_address(struct he_s *hedit, char *exp, unsigned long *address)
int
exh_command(hedit, cmd)
struct he_s *hedit;
char *cmd;
const char *cmd;
/* execute the exh-command `cmd' on `hedit'. multiple commands may be
* specified (separated by semicolons).
* note: if any of the commands changes the current buffer, all successive
......@@ -530,18 +536,20 @@ exh_command(hedit, cmd)
*/
{
char command[256];
char *p;
const char *p;
unsigned long begin = 0, end = 0;
int i, j, k;
int terminal_match_f = -1;
char *skip;
const char *skip;
struct buffer_s *current = current_buffer;
p = (char *)alloca(strlen(cmd) + 1);
strcpy(p, cmd);
size_t psize = strlen(cmd) + 1;
char *pbuf = (char *)alloca(psize);
snprintf(pbuf, psize, "%s", cmd);
/* remove trailing whitespace */
for (i = strlen(p) - !!*p; i && (p[i] == ' ' || p[i] == '\t'); --i);
if (*p) p[i + 1] = 0;
for (i = psize - 1 - !!*pbuf; i && (pbuf[i] == ' ' || pbuf[i] == '\t'); --i);
if (*pbuf) pbuf[i + 1] = 0;
p = pbuf;
check_terminal:
while (*p == ':') ++p;
/* remove leading whitespace */
......@@ -868,7 +876,7 @@ exh_cpl_option_list(char *prefix)
/* exh_cpl_option_list */
char **
exh_completer(char *prefix, char *command, char *line __unused, int context)
exh_completer(char *prefix, const char *command, char *line __unused, int context)
/* we're looking for completions of `prefix'; `command' is the
* command-string that `prefix' is the argument of; `line' is the
* complete line before the cursor.
......
......@@ -42,12 +42,12 @@
#ifndef _EXH_H_
#define _EXH_H_
extern char *exh_initialize[];
extern const char *exh_initialize[];
int exh_command(struct he_s *hedit, char *cmd);
char **exh_completer(char *, char *, char *, int);
int exh_command(struct he_s *hedit, const char *cmd);
char **exh_completer(char *, const char *, char *, int);
char *exh_skip_expression(char *, char);
char *exh_skip_replace(char *, char);
const char *exh_skip_expression(const char *, char);
const char *exh_skip_replace(const char *, char);
#endif /* _EXH_H_ */
......@@ -78,16 +78,16 @@ struct buffer_s *current_buffer;
struct buffer_s *buffer_list = 0;
struct he_message_s *he_messages;
char *alternate_buffer;
char *he_pagerprg;
const char *he_pagerprg;
#if USE_STDARG
void
he_message(int beep, char *fmt, ...)
he_message(int beep, const char *fmt, ...)
#else
void
he_message(beep, fmt, va_alist)
int beep;
char *fmt;
const char *fmt;
va_dcl
#endif
{
......@@ -168,9 +168,9 @@ action_mapmagic(int current_value)
/* action_mapmagic */
static const struct hexer_options_s {
char *option;
const char *option;
enum s_option_e type;
char *default_value;
const char *default_value;
set_fn action;
} hexer_options[] = {
{ "ascii", S_BOOL, "true", (set_fn)action_ascii },
......@@ -190,7 +190,7 @@ static const struct hexer_options_s {
int
he_open_buffer(name, path)
char *name;
const char *name;
char *path;
{
struct buffer_s *buffer;
......@@ -521,8 +521,8 @@ he_status_message(verbose)
char *
he_query_command(prompt, dfl, context)
char *prompt;
char *dfl;
const char *prompt;
const char *dfl;
int context;
/* Convention:
* `context == 0': exh-command;
......@@ -539,12 +539,12 @@ he_query_command(prompt, dfl, context)
#if USE_STDARG
int
he_query_yn(int dfl, char *fmt, ...)
he_query_yn(int dfl, const char *fmt, ...)
#else
int
he_query_yn(dfl, fmt, va_alist)
int dfl;
char *fmt;
const char *fmt;
va_dcl
#endif
{
......@@ -654,10 +654,10 @@ rxwrap_tell(void)
he_search(hedit, exp, replace, direction, wrap, increment, end,
replace_str, replace_len, match_len)
struct he_s *hedit;
char *exp;
const char *exp;
/* regular expression.
*/
char *replace;
const char *replace;
/* replace template. the replace template may contain back references to
* the regular expression (`\0', ... `\9').
*/
......@@ -794,7 +794,7 @@ hexer_init()
*/
{
int i;
char *hexerinit, *home;
const char *hexerinit, *home;
char path[1024];
char line[1024];
FILE *fp;
......
......@@ -126,7 +126,7 @@ extern struct he_message_s *he_messages;
void
#if USE_STDARG
he_message( int beep, char *fmt, ... );
he_message( int beep, const char *fmt, ... );
#else
he_message( );
#endif
......@@ -257,16 +257,16 @@ struct buffer_s {
extern const struct buffer_s NO_BUFFER;
extern char *alternate_buffer;
extern struct buffer_s *current_buffer;
extern char *he_pagerprg;
extern const char *he_pagerprg;
/* exh commands
*/
typedef char *(*exh_fn)(struct he_s *, char *, long, long);
typedef char *(*exh_fn)(struct he_s *, const char *, long, long);
struct exh_cmd_s {
char *cmd_name;
const char *cmd_name;
char cmd_char;
exh_fn cmd;
int whole_f;
......@@ -284,7 +284,7 @@ struct exh_cmd_s {
#define HE_LINE(x) ((long)(x) >> 4)
int
he_open_buffer(char *name, char *path);
he_open_buffer(const char *name, char *path);
int
he_select_buffer(char *name);
......@@ -338,18 +338,18 @@ void
he_cancel_selection(struct he_s *hedit);
long
he_search(struct he_s *, char *, char *, int, int, int, long,
he_search(struct he_s *, const char *, const char *, int, int, int, long,
char **, long *, long *);
void
he_search_command(struct he_s *, char *, int);
char *
he_query_command(char *, char *, int);
he_query_command(const char *, const char *, int);
int
#if USE_STDARG
he_query_yn( int dfl, char *fmt, ... );
he_query_yn( int dfl, const char *fmt, ... );
#else
he_query_yn( );
#endif
......
......@@ -73,7 +73,7 @@
#include "signal.h"
#include "tio.h"
static char *usage_message = "\
static const char *usage_message = "\
hexer - a binary file editor\n\
usage: hexer [options] [file [...]]\n\
-R/--readonly\n\
......@@ -106,7 +106,7 @@ static struct option longopts[] = {
};
#endif /* HEXER_LONG_OPTIONS */
static char *shortopts = "Rvr:c:dth";
static const char *shortopts = "Rvr:c:dth";
static int hexer_readonly;
......
......@@ -85,9 +85,9 @@
* of 254 (== HXKEY_BIAS) is used for the other keys).
*/
static char *rl_prompt; /* the prompt */
static const char *rl_prompt; /* the prompt */
static int rl_prompt_len; /* the length of the prompt in characters */
static char *rl_default; /* the default answer */
static const char *rl_default; /* the default answer */
static char rl_line[LINE_MAXLEN];
/* buffer for the current line */
......@@ -107,7 +107,7 @@ struct rl_line_s {
} rl = { rl_line, rl_vline };
#if USE_PROTOTYPES
char **(*completer)(char *prefix, char *command, char *line, int context);
char **(*completer)(char *prefix, const char *command, char *line, int context);
#else
char **(*completer)();
#endif
......@@ -406,7 +406,7 @@ rl_make_vline_(struct rl_line_s *rrl)
int i;
int vposition;
int key;
char *rep;
const char *rep;
for (i = vposition = 0; rrl->line[i]; ++i) {
if (rrl->line[i] != RL_ESC)
......@@ -1056,8 +1056,8 @@ restart:
char *
readline(prompt, default_val, context)
char *prompt;
char *default_val;
const char *prompt;
const char *default_val;
int context;
{
int key;
......
......@@ -46,7 +46,7 @@
#ifndef _READLINE_H_
#define _READLINE_H_
extern char **(*completer)(char *prefix, char *command,
extern char **(*completer)(char *prefix, const char *command,
char *line, int context);
extern int rl_backspace_jump;
......@@ -55,7 +55,7 @@ extern int rl_redisplay;
extern void (*rl_winch)(void);
char *
readline(char *prompt, char *default_val, int context);
readline(const char *prompt, const char *default_val, int context);
int
keys_length(void);
......
......@@ -63,6 +63,7 @@
#include <string.h>
#include <ctype.h>
#include "config.h"
#include "defs.h"
#undef EOF
......@@ -162,7 +163,7 @@ enum error_e {
E_interrupt
};
char *rx_error_msg[] = {
const char *rx_error_msg[] = {
"", /* no error */ "invalid range", "invalid character", "unmatched `('",
"unmatched `)'", "operator without operand", "malformed operator",
"operand of `++' and `**' must have fixed length", "unmatched `['",
......@@ -361,7 +362,7 @@ regex_store(long slot, long begin, long end)
}
/* regex_store */
static char *
static const char *
regex_ref(int slot)
/* The contents of undefined slots default to an empty string, therefore
* the return value is always a valid (non-zero) pointer.
......@@ -811,8 +812,8 @@ regex_match(regex, position, replace_str, replace_len, match_len)
long *
regex_compile(str, replace)
char *str;
char *replace;
const char *str;
const char *replace;
/* Compile the regular expression `str' and return a pointer to the
* compiled regex-code. If `replace' is non-zero, the string `replace'
* is interpreted as a replace-string, which may contain `\'-escape
......@@ -836,7 +837,8 @@ regex_compile(str, replace)
if (*++cp == 'x') { ++cp; GET_HEX((n), 32); } else { GET_OCT((n), 32); } \
else { GET_DEC((n), 32); } }
char *cp, *s;
const char *cp;
char *s;
int pc;
/* Parentheses counter; number of unmatched parentheses.
......
......@@ -46,7 +46,7 @@
#ifndef _REGEX_H_
#define _REGEX_H_
extern char *rx_error_msg[];
extern const char *rx_error_msg[];
extern int rx_error;
extern volatile int *rx_interrupt;
extern int rx_nomagic;
......@@ -61,7 +61,7 @@ regex_search(long *, long, long, long, int, char **, long *, long *);
regex_match(long *, long, char **, long *, long *);
long *
regex_compile(char *, char *);
regex_compile(const char *, const char *);
int
regex_init(long (*)(char *, long), long (*)(long), long (*)(void));
......
......@@ -89,7 +89,7 @@ s_get_option_integer(option)
}
/* s_get_option_integer */
char *
const char *
s_get_option_string(option)
const char *option;
{
......@@ -246,7 +246,7 @@ s_get_type(option)
}
/* s_get_type */
char *
const char *
s_get_option(option)
const char *option;
{
......
......@@ -59,7 +59,7 @@ typedef void (*set_fn)();
long
s_get_option_integer(const char *option);
char *
const char *
s_get_option_string(const char *option);
int
......@@ -68,7 +68,7 @@ s_get_option_bool(const char *option);
enum s_option_e
s_get_type(const char *option);
char *
const char *
s_get_option(const char *option);
int
......
This diff is collapsed.
......@@ -100,7 +100,7 @@ enum t_keys_e {
extern int hx_columns;
extern int hx_lines;
extern char *terminal_name;
extern const char *terminal_name;
extern volatile int *tio_interrupt;
extern int tio_tite_f;
extern void (*tio_winch)(void);
......@@ -229,7 +229,7 @@ tio_testkey(int key);
* `HXKEY_RETURN', `HXKEY_ESCAPE', `HXKEY_DELETE', `HXKEY_NONE' and `HXKEY_ERROR'.
*/
char *
const char *
tio_keyname(int key);
/* Returns the name of the key `key'. If `key' is a printable character,
* it is returned as a string. If `key' is a special key, the name of
......@@ -237,7 +237,7 @@ tio_keyname(int key);
* is returned, else a `\x??' hexadecimal code.
*/
char *
const char *
tio_keyrep(int key);
/* Returs a string representation of `key'. If `key' is not a printable
* character an escape sequence is generated:
......@@ -250,7 +250,7 @@ tio_keyrep(int key);
* is returned.
*/
char *
const char *
tio_vkeyrep(int key);
/* Similar to `tio_keyrep', but returns a long string representation
* whenever available.
......@@ -379,7 +379,7 @@ tio_raw_vprintf(const char *fmt, va_list);
*/
int
tio_puts(char *s);
tio_puts(const char *s);
/* Like `fputs(s, stdout)'.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment