summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/accessdb.c2
-rw-r--r--src/catman.c47
-rw-r--r--src/check_mandirs.c9
-rw-r--r--src/filenames.c2
-rw-r--r--src/filenames.h2
-rw-r--r--src/globbing.c4
-rw-r--r--src/lexgrog.l10
-rw-r--r--src/man.c88
-rw-r--r--src/man.h2
-rw-r--r--src/mandb.c6
-rw-r--r--src/manp.c13
-rw-r--r--src/manp.h4
-rw-r--r--src/manpath.c10
-rw-r--r--src/whatis.c10
14 files changed, 106 insertions, 103 deletions
diff --git a/src/accessdb.c b/src/accessdb.c
index 3ccaa56f..3123628d 100644
--- a/src/accessdb.c
+++ b/src/accessdb.c
@@ -59,7 +59,7 @@ extern char *strchr();
#endif /* HAVE_GETOPT_H */
char *program_name;
-char *cat_root;
+const char *cat_root;
int debug;
static const struct option long_options[] =
diff --git a/src/catman.c b/src/catman.c
index 0f7f8071..ffea8ea5 100644
--- a/src/catman.c
+++ b/src/catman.c
@@ -218,7 +218,7 @@ static void do_catman (char *argp[], int arg_no, int first_arg)
/* The last argument must be NULL */
argp[arg_no] = NULL;
-
+
catman (argp, arg_no);
/* don't free the last entry, it's NULL */
@@ -250,7 +250,7 @@ static __inline__ void reset_cursor (datum key)
/* find all pages that are in the supplied manpath and section and that are
ultimate source files. */
-static __inline__ int parse_for_sec (char *manpath, char *section)
+static int parse_for_sec (const char *manpath, const char *section)
{
char *argp[MAX_ARGS];
datum key;
@@ -260,23 +260,23 @@ static __inline__ int parse_for_sec (char *manpath, char *section)
if (rdopen_db () || dbver_rd (dbf))
return 1;
- argp[arg_no++] = "man"; /* Name of program */
+ argp[arg_no++] = xstrdup ("man"); /* Name of program */
#ifdef HAVE_SETLOCALE
/* As we supply a NULL environment to save precious execve() space,
we must also supply a locale if necessary */
if (locale) {
- argp[arg_no++] = "-L"; /* locale option */
- argp[arg_no++] = locale; /* The locale */
+ argp[arg_no++] = xstrdup ("-L"); /* locale option */
+ argp[arg_no++] = xstrdup (locale); /* The locale */
initial_bit += sizeof "-L" + strlen (locale) + 1;
} else
initial_bit = 0;
#endif /* HAVE_SETLOCALE */
- argp[arg_no++] = "-caM"; /* options */
- argp[arg_no++] = manpath; /* particular manpath */
- argp[arg_no++] = section; /* particular section */
+ argp[arg_no++] = xstrdup ("-caM"); /* options */
+ argp[arg_no++] = xstrdup (manpath); /* particular manpath */
+ argp[arg_no++] = xstrdup (section); /* particular section */
first_arg = arg_no; /* first pagename argument */
@@ -365,6 +365,10 @@ static __inline__ int parse_for_sec (char *manpath, char *section)
if (arg_no > first_arg)
do_catman (argp, arg_no, first_arg);
+ arg_no = first_arg - 1;
+ while (arg_no >= 0)
+ free (argp[arg_no--]);
+
return 0;
}
@@ -382,7 +386,8 @@ int main (int argc, char *argv[])
{
int c;
char *sys_manp;
- char **mp, **sections;
+ char **mp;
+ const char **sections;
int option_index; /* not used, but required by getopt_long() */
@@ -394,7 +399,7 @@ int main (int argc, char *argv[])
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
+ locale = xstrdup ("C");
}
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -428,10 +433,10 @@ int main (int argc, char *argv[])
/* If we were supplied sections: sort them out */
if (optind != argc) {
- char **sp;
+ const char **sp;
- sections = sp = (char **) xmalloc ((argc - optind + 1) *
- sizeof (char *));
+ sections = sp = xmalloc ((argc - optind + 1) *
+ sizeof *sections);
while (optind != argc)
*sp++ = argv[optind++];
*sp = NULL;
@@ -441,28 +446,29 @@ int main (int argc, char *argv[])
mansect = getenv ("MANSECT");
if (mansect && *mansect) {
/* MANSECT contains sections */
- char *sec;
+ const char *sec;
int i = 0;
mansect = xstrdup (mansect);
sections = NULL;
for (sec = strtok (mansect, ":"); sec;
sec = strtok (NULL, ":")) {
- sections = (char **) xrealloc (sections,
- (i + 2) *
- sizeof (char *));
+ sections = xrealloc (sections,
+ (i + 2) *
+ sizeof *sections);
sections[i++] = sec;
}
sections[i] = NULL;
+ free (mansect);
} else {
/* use default sections */
- static char *std_sections[] = STD_SECTIONS;
+ static const char *std_sections[] = STD_SECTIONS;
sections = std_sections;
}
}
if (debug) {
- char **sp;
+ const char **sp;
for (sp = sections; *sp; sp++)
fprintf (stderr, "sections: %s\n", *sp);
@@ -487,7 +493,8 @@ int main (int argc, char *argv[])
create_pathlist (manp, manpathlist);
for (mp = manpathlist; *mp; mp++) {
- char *catpath, **sp;
+ char *catpath;
+ const char **sp;
size_t len;
catpath = get_catpath (*mp, SYSTEM_CAT | USER_CAT);
diff --git a/src/check_mandirs.c b/src/check_mandirs.c
index b2f2e1ff..e4259e20 100644
--- a/src/check_mandirs.c
+++ b/src/check_mandirs.c
@@ -429,7 +429,7 @@ void update_db_time (void)
datum key1, content1;
#endif /* FAST_BTREE */
- key.dptr = KEY;
+ key.dptr = xstrdup (KEY);
key.dsize = sizeof KEY;
content.dptr = (char *) xmalloc (16); /* 11 is max long with '\0' */
(void) sprintf (content.dptr, "%ld", (long) time (NULL));
@@ -462,6 +462,7 @@ void update_db_time (void)
#endif /* !FAST_BTREE */
MYDBM_CLOSE (dbf);
+ free (key.dptr);
free (content.dptr);
}
@@ -471,7 +472,7 @@ void reset_db_time (void)
{
datum key;
- key.dptr = KEY;
+ key.dptr = xstrdup (KEY);
key.dsize = sizeof KEY;
/* we don't really care if we can't open it RW - it's not fatal */
@@ -488,6 +489,7 @@ void reset_db_time (void)
if (debug)
fprintf (stderr, "reset_db_time()\n");
MYDBM_CLOSE (dbf);
+ free (key.dptr);
}
/* routine to prepare/create the db prior to calling testmandirs() */
@@ -540,10 +542,11 @@ short update_db (const char *manpath)
datum key, content;
short new;
- key.dptr = KEY;
+ key.dptr = xstrdup (KEY);
key.dsize = sizeof KEY;
content = MYDBM_FETCH (dbf, key);
MYDBM_CLOSE (dbf);
+ free (key.dptr);
if (debug)
fprintf (stderr, "update_db(): %ld\n",
diff --git a/src/filenames.c b/src/filenames.c
index 1235385e..6844c43b 100644
--- a/src/filenames.c
+++ b/src/filenames.c
@@ -54,7 +54,7 @@ static void gripe_bogus_manpage (const char *manpage)
}
char *make_filename (const char *path, const char *name,
- struct mandata *in, char *type)
+ struct mandata *in, const char *type)
{
static char *file;
diff --git a/src/filenames.h b/src/filenames.h
index 26bac7b3..7192ce57 100644
--- a/src/filenames.h
+++ b/src/filenames.h
@@ -23,6 +23,6 @@
#include "libdb/db_storage.h"
extern char *make_filename (const char *path, const char *name,
- struct mandata *in, char *type);
+ struct mandata *in, const char *type);
extern char *filename_info (const char *file, struct mandata *info,
const char *req_name);
diff --git a/src/globbing.c b/src/globbing.c
index 398e10c6..fb1cc61f 100644
--- a/src/globbing.c
+++ b/src/globbing.c
@@ -64,8 +64,8 @@ extern char *strrchr();
#include "lib/error.h"
#include "lib/hashtable.h"
-char *extension;
-static char *mandir_layout = MANDIR_LAYOUT;
+const char *extension;
+static const char *mandir_layout = MANDIR_LAYOUT;
#ifdef TEST
diff --git a/src/lexgrog.l b/src/lexgrog.l
index 7a39a3b8..fb84e6ab 100644
--- a/src/lexgrog.l
+++ b/src/lexgrog.l
@@ -73,7 +73,8 @@ static void add_separator_to_whatis (void);
static void newline_found (void);
static char newname[MAX_NAME];
-static char *p_name, *fname;
+static char *p_name;
+static const char *fname;
static char filters[MAX_FILTERS];
static int fill_mode;
@@ -87,7 +88,7 @@ static int fill_mode;
# include "lib/getopt.h"
#endif /* HAVE_GETOPT_H */
-char *program_name = "lexgrog";
+char *program_name;
int debug = 0;
static const struct option long_options[] =
@@ -367,7 +368,7 @@ static void newline_found (void)
}
}
-int find_name (const char *file, char *filename, lexgrog *p_lg)
+int find_name (const char *file, const char *filename, lexgrog *p_lg)
{
int ret;
@@ -468,6 +469,9 @@ int main (int argc, char **argv)
int type = 0;
int parse_man = 0, parse_cat = 0, show_whatis = 0, show_filters = 0;
int some_failed = 0;
+
+ program_name = xstrdup (basename (argv[0]));
+
while ((c = getopt_long (argc, argv, args,
long_options, &option_index)) != -1) {
switch (c) {
diff --git a/src/man.c b/src/man.c
index 4e534b2d..b90a4f7b 100644
--- a/src/man.c
+++ b/src/man.c
@@ -230,13 +230,13 @@ static FILE *checked_popen (const char *command, const char *type)
}
#endif /* MAN_CATS */
-char *lang_dir (const char *filename)
+static char *lang_dir (const char *filename)
{
char *ld; /* the lang dir: point to static data */
const char *fm; /* the first "/man/" dir */
const char *sm; /* the second "/man?/" dir */
- ld = "";
+ ld = xstrdup ("");
if (!filename)
return ld;
@@ -254,15 +254,15 @@ char *lang_dir (const char *filename)
/* If there's no lang dir element, it's an English man page. */
if (sm == fm + 4)
- return "C";
+ return xstrdup ("C");
/* found a lang dir */
fm += 5;
sm = strchr (fm, '/');
if (!sm)
return ld;
- ld = xstrdup (fm);
- ld[sm - fm] = '\0';
+ free (ld);
+ ld = xstrndup (fm, sm - fm);
if (debug)
fprintf (stderr, "found lang dir element %s\n", ld);
return ld;
@@ -295,23 +295,23 @@ int quiet = 1;
char *program_name;
char *database;
MYDBM_FILE dbf;
-extern char *extension; /* for globbing.c */
+extern const char *extension; /* for globbing.c */
extern char *user_config_file; /* defined in manp.c */
/* locals */
-static char *alt_system_name;
-static char **section_list;
+static const char *alt_system_name;
+static const char **section_list;
static const char *section;
static char *colon_sep_section_list;
-static char *preprocessors;
-static char *pager;
-static char *locale;
+static const char *preprocessors;
+static const char *pager;
+static const char *locale;
static char *internal_locale;
static char *prompt_string;
static char *less;
-static char *std_sections[] = STD_SECTIONS;
+static const char *std_sections[] = STD_SECTIONS;
static char *manp;
-static char *external;
+static const char *external;
static struct hashtable *db_hash = NULL;
static int troff;
@@ -381,9 +381,9 @@ static const char args[] = "7DlM:P:S:adfhH::kVum:p:tT::wWe:L:Zcr:X::E:iIC:";
# ifdef TROFF_IS_GROFF
static int ditroff;
-static char *gxditview;
+static const char *gxditview;
static int htmlout;
-static char *html_pager;
+static const char *html_pager;
# endif /* TROFF_IS_GROFF */
#else /* !HAS_TROFF */
@@ -565,7 +565,7 @@ static int get_roff_line_length (void)
return 0;
}
-static char *add_roff_line_length (char *filter, int *save_cat)
+static char *add_roff_line_length (const char *filter, int *save_cat)
{
int length = get_roff_line_length ();
if (length) {
@@ -576,7 +576,7 @@ static char *add_roff_line_length (char *filter, int *save_cat)
sprintf (options, " -rLL=%dn -rLT=%dn", length, length);
return strappend (NULL, filter, options, NULL);
}
- return filter;
+ return xstrdup (filter);
}
#ifdef UNDOC_COMMAND
@@ -654,7 +654,8 @@ static __inline__ void gripe_no_man (const char *name, const char *sec)
static void do_extern (char *argv[])
{
/* privs are already dropped */
- argv[0] = basename (external);
+ char *external_copy = xstrdup (external);
+ argv[0] = basename (external_copy);
execv (external, argv);
exit (FATAL);
}
@@ -888,10 +889,7 @@ int main (int argc, char *argv[])
if (multiple_locale)
internal_locale = multiple_locale;
}
- if (internal_locale != NULL)
- internal_locale = xstrdup (internal_locale);
- else
- internal_locale = "C";
+ internal_locale = xstrdup (internal_locale ? internal_locale : "C");
/* export argv, it might be needed when invoking the vendor supplied browser */
#if defined _AIX || defined __sgi
@@ -952,11 +950,11 @@ int main (int argc, char *argv[])
/* close this locale and reinitialise if a new locale was
issued as an argument or in $MANOPT */
if (locale) {
- internal_locale = setlocale (LC_ALL, locale);
+ free (internal_locale);
+ internal_locale = xstrdup (setlocale (LC_ALL, locale));
if (internal_locale == NULL)
- internal_locale = locale;
+ internal_locale = xstrdup (locale);
- internal_locale = xstrdup (internal_locale);
if (debug)
fprintf(stderr,
"main(): locale = %s, internal_locale = %s\n",
@@ -1274,7 +1272,7 @@ static void man_getopt (int argc, char *argv[])
break;
case 'H':
#ifdef TROFF_IS_GROFF
- html_pager = (optarg ? optarg : 0);
+ html_pager = (optarg ? optarg : NULL);
htmlout = 1;
troff = 1;
roff_device = "html";
@@ -1313,9 +1311,9 @@ static void man_getopt (int argc, char *argv[])
html_pager = NULL;
#endif
roff_device = extension = pager = locale
- = colon_sep_section_list
= alt_system_name = external
- = preprocessors = manp = NULL;
+ = preprocessors = NULL;
+ colon_sep_section_list = manp = NULL;
break;
case 'h':
usage(OK);
@@ -1351,7 +1349,7 @@ static void man_getopt (int argc, char *argv[])
*/
static __inline__ const char *is_section (const char *name)
{
- char **vs;
+ const char **vs;
for (vs = section_list; *vs; vs++) {
if (STREQ (*vs, name))
@@ -1469,8 +1467,8 @@ static __inline__ void create_stdintmp (void)
}
/* Return command (malloced string) to format file to stdout */
-static __inline__ char *make_roff_command (const char *dir, const char *file,
- const char *dbfilters)
+static char *make_roff_command (const char *dir, const char *file,
+ const char *dbfilters)
{
const char *pp_string;
char *fmt_prog;
@@ -1681,10 +1679,10 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
else if (roff_device)
dev = strappend (NULL, " -T", roff_device, NULL);
else
- dev = "";
+ dev = xstrdup ("");
do {
- char *filter;
+ const char *filter = NULL;
int wants_dev = 0; /* filter wants a dev argument */
/* set filter according to *pp_string, on
@@ -1715,6 +1713,7 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
/* done with preprocessors, now add roff */
#ifdef TROFF_IS_GROFF
if (troff && ditroff)
+ /* TODO: leak */
filter = strappend (NULL,
get_def ("troff",
TROFF),
@@ -1726,6 +1725,7 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
else {
filter = get_def ("nroff", NROFF);
#ifdef TROFF_IS_GROFF
+ /* TODO: leak */
filter = add_roff_line_length
(filter, &save_cat);
#endif
@@ -1733,11 +1733,9 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
wants_dev = 1;
break;
- default:
- filter = "";
}
- if (*filter) {
+ if (filter && *filter) {
command = strappend (command,
" | ",
filter,
@@ -1757,8 +1755,7 @@ static __inline__ char *make_roff_command (const char *dir, const char *file,
command = strappend (command, " | ", COL, NULL);
#endif /* GNU_NROFF */
- if (roff_device || gxditview)
- free (dev);
+ free (dev);
} else {
/* use external formatter script, it takes arguments
input file, preprocessor string, and (optional)
@@ -2652,7 +2649,6 @@ static int compare_candidates (const struct mandata *left,
const struct mandata *right,
const char *req_name)
{
- char **sp;
int sec_left = 0, sec_right = 0, cmp;
/* If one candidate matches the requested name exactly, sort it
@@ -2672,6 +2668,7 @@ static int compare_candidates (const struct mandata *left,
/* Find out whether left->ext is ahead of right->ext in
* section_list.
*/
+ const char **sp;
for (sp = section_list; *sp; sp++) {
if (!*(*sp + 1)) {
/* No extension */
@@ -3342,7 +3339,7 @@ static int man (const char *name, int *found)
for (mp = manpathlist; *mp; mp++)
*found += locate_page (*mp, section, name, &candidates);
} else {
- char **sp;
+ const char **sp;
for (sp = section_list; *sp; sp++) {
char **mp;
@@ -3360,12 +3357,12 @@ static int man (const char *name, int *found)
}
-static __inline__ char **get_section_list (void)
+static const char **get_section_list (void)
{
int i = 0;
- char **config_sections;
- char **sections = NULL;
- char *sec;
+ const char **config_sections;
+ const char **sections = NULL;
+ const char *sec;
/* Section list from configuration file, or STD_SECTIONS if it's
* empty.
@@ -3381,8 +3378,7 @@ static __inline__ char **get_section_list (void)
for (sec = strtok (colon_sep_section_list, ":"); sec;
sec = strtok (NULL, ":")) {
- sections = (char **) xrealloc (sections,
- (i + 2) * sizeof (char *));
+ sections = xrealloc (sections, (i + 2) * sizeof *sections);
sections[i++] = sec;
}
diff --git a/src/man.h b/src/man.h
index 5d1fdfae..9c7ff620 100644
--- a/src/man.h
+++ b/src/man.h
@@ -25,7 +25,7 @@
/* man.c */
static void man_getopt (int argc, char *argv[]);
static __inline__ const char *is_section (const char *name);
-static __inline__ char **get_section_list (void);
+static const char **get_section_list (void);
static int man (const char *name, int *found);
static int display (const char *dir, const char *man_file,
const char *cat_file, const char *title,
diff --git a/src/mandb.c b/src/mandb.c
index 4ef181c1..d92b7c35 100644
--- a/src/mandb.c
+++ b/src/mandb.c
@@ -420,7 +420,6 @@ int main (int argc, char *argv[])
int purged = 0;
int quiet_temp = 0;
char **mp;
- char *locale;
int option_index; /* not used, but required by getopt_long() */
@@ -436,13 +435,10 @@ int main (int argc, char *argv[])
program_name = xstrdup (basename (argv[0]));
/* initialise the locale */
- locale = xstrdup (setlocale (LC_ALL, ""));
- if (!locale) {
+ if (!setlocale (LC_ALL, ""))
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
- }
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
diff --git a/src/manp.c b/src/manp.c
index db0aaf1d..d6e37ebe 100644
--- a/src/manp.c
+++ b/src/manp.c
@@ -144,7 +144,7 @@ static void add_to_list (const char *key, const char *cont, int flag)
namestore = list;
}
-static char *get_from_list (char *key, int flag)
+static const char *get_from_list (const char *key, int flag)
{
struct list *list;
@@ -166,9 +166,9 @@ static struct list *iterate_over_list (struct list *prev, char *key, int flag)
return NULL;
}
-char *get_def (char *thing, char *def)
+const char *get_def (const char *thing, const char *def)
{
- char *config_def = get_from_list (thing, DEFINE);
+ const char *config_def = get_from_list (thing, DEFINE);
return config_def ? config_def : def;
}
@@ -197,11 +197,11 @@ static void add_sections (char *sections)
}
}
-char **get_sections (void)
+const char **get_sections (void)
{
struct list *list;
int length = 0;
- char **sections, **sectionp;
+ const char **sections, **sectionp;
for (list = namestore; list; list = list->next)
if (list->flag == SECTION)
@@ -354,7 +354,8 @@ static __inline__ void gripe_not_directory (const char *dir)
catpath list */
char *cat_manpath (char *manp)
{
- char *catp = NULL, *path, *catdir;
+ char *catp = NULL;
+ const char *path, *catdir;
for (path = strsep (&manp, ":"); path; path = strsep (&manp, ":")) {
catdir = get_from_list (path, MANDB_MAP_USER);
diff --git a/src/manp.h b/src/manp.h
index 8b9ee0a2..279915dd 100644
--- a/src/manp.h
+++ b/src/manp.h
@@ -31,5 +31,5 @@ extern char *get_mandb_manpath (void);
extern char *get_catpath (const char *name, int cattype);
extern int is_global_mandir (const char *dir);
extern void read_config_file (void);
-extern char *get_def (char *thing, char *def);
-extern char **get_sections (void);
+extern const char *get_def (const char *thing, const char *def);
+extern const char **get_sections (void);
diff --git a/src/manpath.c b/src/manpath.c
index 32bb9211..cba81bfc 100644
--- a/src/manpath.c
+++ b/src/manpath.c
@@ -113,22 +113,16 @@ static void usage (int status)
int main (int argc, char *argv[])
{
int c, global = 0, cat = 0;
- char *alt_system = "";
+ const char *alt_system = "";
char *path_string;
int option_index; /* not used, but required by getopt_long() */
- char *locale;
program_name = xstrdup (basename (argv[0]));
/* initialise the locale */
- locale = setlocale (LC_ALL, "");
- if (locale)
- locale = xstrdup (locale);
- else {
+ if (!setlocale (LC_ALL, ""))
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
- }
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
diff --git a/src/whatis.c b/src/whatis.c
index 4ddec94e..c9d05f54 100644
--- a/src/whatis.c
+++ b/src/whatis.c
@@ -183,7 +183,8 @@ static __inline__ int use_grep (char *page, char *manpath)
if (access (whatis_file, R_OK) == 0) {
char *esc_page = escape_shell (page);
char *esc_file = escape_shell (whatis_file);
- char *flags, *anchor, *command;
+ const char *flags, *anchor;
+ char *command;
#if defined(WHATIS)
flags = get_def ("whatis_grep_flags", WHATIS_GREP_FLAGS);
anchor = "^";
@@ -599,8 +600,8 @@ static void search (char *page)
int main (int argc, char *argv[])
{
int c;
- char *manp = NULL, *alt_systems = "";
- char *llocale = 0, *locale;
+ const char *manp = NULL, *alt_systems = "";
+ char *llocale = NULL, *locale;
int option_index;
program_name = xstrdup (basename (argv[0]));
@@ -611,7 +612,7 @@ int main (int argc, char *argv[])
/* Obviously can't translate this. */
error (0, 0, "can't set the locale; make sure $LC_* and $LANG "
"are correct");
- locale = "C";
+ locale = xstrdup ("C");
}
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
@@ -674,6 +675,7 @@ int main (int argc, char *argv[])
issued as an argument or in $MANOPT */
if (llocale) {
setlocale (LC_ALL, llocale);
+ free (locale);
locale = xstrdup (llocale);
if (debug)
fprintf(stderr,