source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: avoid repetitive code for asprintf error handling
Date: Sun, 23 Mar 2014 08:11:18 -0400 (EDT)	[thread overview]
Message-ID: <201403231211.s2NCBIbg024530@krisdoz.my.domain> (raw)

Log Message:
-----------
avoid repetitive code for asprintf error handling

Modified Files:
--------------
    mdocml:
        mandocdb.c
        mansearch.c
        mdoc.c
        mdoc_validate.c
        roff.c

Revision Data
-------------
Index: mansearch.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mansearch.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -Lmansearch.c -Lmansearch.c -u -p -r1.23 -r1.24
--- mansearch.c
+++ mansearch.c
@@ -338,11 +338,8 @@ buildnames(struct manpage *mpage, sqlite
 		    (strcmp(sec, prevsec) ||
 		     strcmp(arch, prevarch))) {
 			sep2 = '\0' == *prevarch ? "" : "/";
-			if (-1 == asprintf(&newnames, "%s(%s%s%s)",
-			    oldnames, prevsec, sep2, prevarch)) {
-				perror(0);
-				exit((int)MANDOCLEVEL_SYSERR);
-			}
+			mandoc_asprintf(&newnames, "%s(%s%s%s)",
+			    oldnames, prevsec, sep2, prevarch);
 			free(mpage->names);
 			oldnames = mpage->names = newnames;
 			free(prevsec);
@@ -359,11 +356,8 @@ buildnames(struct manpage *mpage, sqlite
 
 		/* Append the new name. */
 
-		if (-1 == asprintf(&newnames, "%s%s%s",
-		    oldnames, sep1, name)) {
-			perror(0);
-			exit((int)MANDOCLEVEL_SYSERR);
-		}
+		mandoc_asprintf(&newnames, "%s%s%s",
+		    oldnames, sep1, name);
 		free(mpage->names);
 		mpage->names = newnames;
 
@@ -380,11 +374,8 @@ buildnames(struct manpage *mpage, sqlite
 			fsec = "0";
 		}
 		sep2 = '\0' == *arch ? "" : "/";
-		if (-1 == asprintf(&mpage->file, "%s/%s%s%s%s/%s.%s",
-		    path, sep1, sec, sep2, arch, name, fsec)) {
-			perror(0);
-			exit((int)MANDOCLEVEL_SYSERR);
-		}
+		mandoc_asprintf(&mpage->file, "%s/%s%s%s%s/%s.%s",
+		    path, sep1, sec, sep2, arch, name, fsec);
 	}
 	if (SQLITE_DONE != c)
 		fprintf(stderr, "%s\n", sqlite3_errmsg(db));
@@ -394,11 +385,8 @@ buildnames(struct manpage *mpage, sqlite
 
 	if (NULL != prevsec) {
 		sep2 = '\0' == *prevarch ? "" : "/";
-		if (-1 == asprintf(&newnames, "%s(%s%s%s)",
-		    mpage->names, prevsec, sep2, prevarch)) {
-			perror(0);
-			exit((int)MANDOCLEVEL_SYSERR);
-		}
+		mandoc_asprintf(&newnames, "%s(%s%s%s)",
+		    mpage->names, prevsec, sep2, prevarch);
 		free(mpage->names);
 		mpage->names = newnames;
 		free(prevsec);
@@ -427,11 +415,8 @@ buildoutput(sqlite3 *db, sqlite3_stmt *s
 			sep1 = " # ";
 		}
 		data = sqlite3_column_text(s, 1);
-		if (-1 == asprintf(&newoutput, "%s%s%s",
-		    oldoutput, sep1, data)) {
-			perror(0);
-			exit((int)MANDOCLEVEL_SYSERR);
-		}
+		mandoc_asprintf(&newoutput, "%s%s%s",
+		    oldoutput, sep1, data);
 		free(output);
 		output = newoutput;
 	}
@@ -603,10 +588,7 @@ exprspec(struct expr *cur, uint64_t key,
 	if (NULL == value)
 		return(cur);
 
-	if (-1 == asprintf(&cp, format, value)) {
-		perror(0);
-		exit((int)MANDOCLEVEL_SYSERR);
-	}
+	mandoc_asprintf(&cp, format, value);
 	cur->next = mandoc_calloc(1, sizeof(struct expr));
 	cur = cur->next;
 	cur->and = 1;
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.203
retrieving revision 1.204
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.203 -r1.204
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -2395,11 +2395,9 @@ post_os(POST_ARGS)
 		if (-1 == uname(&utsname)) {
 			mdoc_nmsg(mdoc, n, MANDOCERR_UNAME);
                         defbuf = mandoc_strdup("UNKNOWN");
-                } else if (-1 == asprintf(&defbuf, "%s %s",
-		    utsname.sysname, utsname.release)) {
-			perror(NULL);
-			exit((int)MANDOCLEVEL_SYSERR);
-		}
+                } else
+			mandoc_asprintf(&defbuf, "%s %s",
+			    utsname.sysname, utsname.release);
 	}
 	mdoc->meta.os = mandoc_strdup(defbuf);
 #endif /*!OSNAME*/
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.119
retrieving revision 1.120
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.119 -r1.120
--- mandocdb.c
+++ mandocdb.c
@@ -1536,10 +1536,7 @@ parse_mdoc_Xr(struct mpage *mpage, const
 		return(0);
 	}
 
-	if (-1 == asprintf(&cp, "%s(%s)", n->string, n->next->string)) {
-		perror(NULL);
-		exit((int)MANDOCLEVEL_SYSERR);
-	}
+	mandoc_asprintf(&cp, "%s(%s)", n->string, n->next->string);
 	putkey(mpage, cp, TYPE_Xr);
 	free(cp);
 	return(0);
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.209
retrieving revision 1.210
diff -Lmdoc.c -Lmdoc.c -u -p -r1.209 -r1.210
--- mdoc.c
+++ mdoc.c
@@ -594,10 +594,7 @@ mdoc_word_append(struct mdoc *mdoc, cons
 
 	n = mdoc->last;
 	addstr = roff_strdup(mdoc->roff, p);
-	if (-1 == asprintf(&newstr, "%s %s", n->string, addstr)) {
-		perror(NULL);
-		exit((int)MANDOCLEVEL_SYSERR);
-	}
+	mandoc_asprintf(&newstr, "%s %s", n->string, addstr);
 	free(addstr);
 	free(n->string);
 	n->string = newstr;
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.201
retrieving revision 1.202
diff -Lroff.c -Lroff.c -u -p -r1.201 -r1.202
--- roff.c
+++ roff.c
@@ -656,11 +656,7 @@ roff_parsetext(char **bufp, size_t *szp,
 
 	/* Spring the input line trap. */
 	if (1 == roffit_lines) {
-		isz = asprintf(&p, "%s\n.%s", *bufp, roffit_macro);
-		if (-1 == isz) {
-			perror(NULL);
-			exit((int)MANDOCLEVEL_SYSERR);
-		}
+		isz = mandoc_asprintf(&p, "%s\n.%s", *bufp, roffit_macro);
 		free(*bufp);
 		*bufp = p;
 		*szp = isz + 1;
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-03-23 12:11 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=201403231211.s2NCBIbg024530@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.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).