source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Simplification, no functional change: Delete the "argc" argument
Date: Sun, 28 Jul 2019 14:41:51 -0500 (EST)	[thread overview]
Message-ID: <862a4227043b801c@mandoc.bsd.lv> (raw)

Log Message:
-----------
Simplification, no functional change:
Delete the "argc" argument from fs_search() which is now always 1,
and move error reporting to the main() program where it is more
logically placed and easier to see.

Modified Files:
--------------
    mandoc:
        main.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.339
retrieving revision 1.340
diff -Lmain.c -Lmain.c -u -p -r1.339 -r1.340
--- main.c
+++ main.c
@@ -95,7 +95,7 @@ static	int		  fs_lookup(const struct man
 				const char *, const char *,
 				struct manpage **, size_t *);
 static	int		  fs_search(const struct mansearch *,
-				const struct manpaths *, int, char**,
+				const struct manpaths *, const char *,
 				struct manpage **, size_t *);
 static	void		  outdata_alloc(struct outstate *, struct manoutput *);
 static	void		  parse(struct mparse *, int, const char *,
@@ -443,12 +443,23 @@ main(int argc, char *argv[])
 			    1, argv, &resn, &resnsz);
 			if (resnsz == 0)
 				(void)fs_search(&search, &conf.manpath,
-				    1, argv, &resn, &resnsz);
+				    *argv, &resn, &resnsz);
+			if (resnsz == 0 && strchr(*argv, '/') == NULL) {
+				if (search.arch != NULL &&
+				    arch_valid(search.arch, OSENUM) == 0)
+					warnx("Unknown architecture \"%s\".",
+					    search.arch);
+				else if (search.sec != NULL)
+					warnx("No entry for %s in "
+					    "section %s of the manual.",
+					    *argv, search.sec);
+				else
+					warnx("No entry for %s in "
+					    "the manual.", *argv);
+				mandoc_msg_setrc(MANDOCLEVEL_BADARG);
+				continue;
+			}
 			if (resnsz == 0) {
-				if (strchr(*argv, '/') == NULL) {
-					mandoc_msg_setrc(MANDOCLEVEL_BADARG);
-					continue;
-				}
 				if (access(*argv, R_OK) == -1) {
 					mandoc_msg_setinfilename(*argv);
 					mandoc_msg(MANDOCERR_BADARG_BAD,
@@ -718,48 +729,30 @@ found:
 
 static int
 fs_search(const struct mansearch *cfg, const struct manpaths *paths,
-	int argc, char **argv, struct manpage **res, size_t *ressz)
+	const char *name, struct manpage **res, size_t *ressz)
 {
 	const char *const sections[] =
 	    {"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
 	const size_t nsec = sizeof(sections)/sizeof(sections[0]);
 
-	size_t		 ipath, isec, lastsz;
+	size_t		 ipath, isec;
 
 	assert(cfg->argmode == ARG_NAME);
-
 	if (res != NULL)
 		*res = NULL;
-	*ressz = lastsz = 0;
-	while (argc) {
-		for (ipath = 0; ipath < paths->sz; ipath++) {
-			if (cfg->sec != NULL) {
-				if (fs_lookup(paths, ipath, cfg->sec,
-				    cfg->arch, *argv, res, ressz) != -1 &&
-				    cfg->firstmatch)
-					return 0;
-			} else for (isec = 0; isec < nsec; isec++)
+	*ressz = 0;
+	for (ipath = 0; ipath < paths->sz; ipath++) {
+		if (cfg->sec != NULL) {
+			if (fs_lookup(paths, ipath, cfg->sec, cfg->arch,
+			    name, res, ressz) != -1 && cfg->firstmatch)
+				return 0;
+		} else {
+			for (isec = 0; isec < nsec; isec++)
 				if (fs_lookup(paths, ipath, sections[isec],
-				    cfg->arch, *argv, res, ressz) != -1 &&
+				    cfg->arch, name, res, ressz) != -1 &&
 				    cfg->firstmatch)
 					return 0;
 		}
-		if (res != NULL && *ressz == lastsz &&
-		    strchr(*argv, '/') == NULL) {
-			if (cfg->arch != NULL &&
-			    arch_valid(cfg->arch, OSENUM) == 0)
-				warnx("Unknown architecture \"%s\".",
-				    cfg->arch);
-			else if (cfg->sec == NULL)
-				warnx("No entry for %s in the manual.",
-				    *argv);
-			else
-				warnx("No entry for %s in section %s "
-				    "of the manual.", *argv, cfg->sec);
-		}
-		lastsz = *ressz;
-		argv++;
-		argc--;
 	}
 	return -1;
 }
@@ -934,7 +927,7 @@ check_xr(void)
 		search.firstmatch = 1;
 		if (mansearch(&search, &paths, 1, &xr->name, NULL, &sz))
 			continue;
-		if (fs_search(&search, &paths, 1, &xr->name, NULL, &sz) != -1)
+		if (fs_search(&search, &paths, xr->name, NULL, &sz) != -1)
 			continue;
 		if (xr->count == 1)
 			mandoc_msg(MANDOCERR_XR_BAD, xr->line,
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2019-07-28 19:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=862a4227043b801c@mandoc.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).