source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: merge reproducible build support including compat glue to 1.13
@ 2016-10-20 18:52 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2016-10-20 18:52 UTC (permalink / raw)
  To: source

Log Message:
-----------
merge reproducible build support including compat glue to 1.13 branch:
mandocdb.c 1.231 & 1.232; configure 1.52 & 1.53; configure.local.example 1.21

Tags:
----
VERSION_1_13

Modified Files:
--------------
    mdocml:
        configure
        configure.local.example
        mandocdb.c

Revision Data
-------------
Index: configure
===================================================================
RCS file: /home/cvs/mdocml/mdocml/configure,v
retrieving revision 1.43.2.5
retrieving revision 1.43.2.6
diff -Lconfigure -Lconfigure -u -p -r1.43.2.5 -r1.43.2.6
--- configure
+++ configure
@@ -54,6 +54,7 @@ HAVE_DIRENT_NAMLEN=
 HAVE_EFTYPE=
 HAVE_ERR=
 HAVE_FTS=
+HAVE_FTS_COMPARE_CONST=
 HAVE_GETLINE=
 HAVE_GETSUBOPT=
 HAVE_ISBLANK=
@@ -132,9 +133,9 @@ COMP="${CC} ${CFLAGS} -Wno-unused -Werro
 # If yes, use the override, if no, do not decide anything yet.
 # Arguments: lower-case test name, manual value
 ismanual() {
-	[ -z "${2}" ] && return 1
-	echo "${1}: manual (${2})" 1>&2
-	echo "${1}: manual (${2})" 1>&3
+	[ -z "${3}" ] && return 1
+	echo "${1}: manual (HAVE_${2}=${3})" 1>&2
+	echo "${1}: manual (HAVE_${2}=${3})" 1>&3
 	echo 1>&3
 	return 0
 }
@@ -145,27 +146,27 @@ ismanual() {
 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
 singletest() {
 	cat 1>&3 << __HEREDOC__
-${1}: testing...
+${1}${3}: testing...
 ${COMP} ${3} -o test-${1} test-${1}.c
 __HEREDOC__
 
 	if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
-		echo "${1}: ${CC} succeeded" 1>&3
+		echo "${1}${3}: ${CC} succeeded" 1>&3
 	else
-		echo "${1}: ${CC} failed with $?" 1>&3
+		echo "${1}${3}: ${CC} failed with $?" 1>&3
 		echo 1>&3
 		return 1
 	fi
 
 	if ./test-${1} 1>&3 2>&3; then
-		echo "${1}: yes" 1>&2
-		echo "${1}: yes" 1>&3
+		echo "${1}${3}: yes" 1>&2
+		echo "${1}${3}: yes" 1>&3
 		echo 1>&3
 		eval HAVE_${2}=1
 		rm "test-${1}"
 		return 0
 	else
-		echo "${1}: execution failed with $?" 1>&3
+		echo "${1}${3}: execution failed with $?" 1>&3
 		echo 1>&3
 		rm "test-${1}"
 		return 1
@@ -177,9 +178,9 @@ __HEREDOC__
 # Arguments: lower case name, upper case name, additional CFLAGS
 runtest() {
 	eval _manual=\${HAVE_${2}}
-	ismanual "${1}" "${_manual}" && return 0
+	ismanual "${1}" "${2}" "${_manual}" && return 0
 	singletest "${1}" "${2}" "${3}" && return 0
-	echo "${1}: no" 1>&2
+	echo "${1}${3}: no" 1>&2
 	eval HAVE_${2}=0
 	return 1
 }
@@ -187,7 +188,7 @@ runtest() {
 # Select a UTF-8 locale.
 get_locale() {
 	[ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
-	ismanual UTF8_LOCALE "$UTF8_LOCALE" && return 0
+	ismanual UTF8_LOCALE UTF8_LOCALE "$UTF8_LOCALE" && return 0
 	echo "UTF8_LOCALE: testing..." 1>&3
 	UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
 	if [ -z "${UTF8_LOCALE}" ]; then
@@ -205,7 +206,6 @@ get_locale() {
 runtest dirent-namlen	DIRENT_NAMLEN	|| true
 runtest EFTYPE		EFTYPE		|| true
 runtest err		ERR		|| true
-runtest fts		FTS		|| true
 runtest getline		GETLINE		|| true
 runtest getsubopt	GETSUBOPT	|| true
 runtest isblank		ISBLANK		|| true
@@ -227,6 +227,14 @@ runtest strsep		STRSEP		|| true
 runtest strtonum	STRTONUM	|| true
 runtest vasprintf	VASPRINTF	|| true
 
+if ismanual fts FTS ${HAVE_FTS}; then
+	HAVE_FTS_COMPARE_CONST=0
+elif runtest fts FTS_COMPARE_CONST -DFTS_COMPARE_CONST; then
+	HAVE_FTS=1
+else
+	runtest fts FTS || true
+fi
+
 # --- wide character and locale support ---
 if get_locale; then
 	runtest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
@@ -242,7 +250,7 @@ if [ ${BUILD_DB} -eq 0 ]; then
 	echo "BUILD_DB=0 (manual)" 1>&3
 	echo 1>&3
 	HAVE_SQLITE3=0
-elif ismanual sqlite3 "${HAVE_SQLITE3}"; then
+elif ismanual sqlite3 SQLITE3 "${HAVE_SQLITE3}"; then
 	if [ -z "${LD_SQLITE3}" ]; then
 		LD_SQLITE3="-lsqlite3"
 	fi
@@ -268,7 +276,7 @@ fi
 # --- sqlite3_errstr ---
 if [ ${BUILD_DB} -eq 0 ]; then
 	HAVE_SQLITE3_ERRSTR=1
-elif ismanual sqlite3_errstr "${HAVE_SQLITE3_ERRSTR}"; then
+elif ismanual sqlite3_errstr SQLITE3_ERRSTR "${HAVE_SQLITE3_ERRSTR}"; then
 	:
 else
 	runtest sqlite3_errstr SQLITE3_ERRSTR "${LD_SQLITE3}" || true
@@ -289,7 +297,7 @@ if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
 fi
 
 # --- ohash ---
-if ismanual ohash "${HAVE_OHASH}"; then
+if ismanual ohash OHASH "${HAVE_OHASH}"; then
 	:
 elif [ -n "${LD_OHASH}" ]; then
 	runtest ohash OHASH "${LD_OHASH}" || true
@@ -309,7 +317,7 @@ echo "LDADD=\"${LDADD}\"" 1>&3
 echo 1>&3
 
 # --- manpath ---
-if ismanual manpath "${HAVE_MANPATH}"; then
+if ismanual manpath MANPATH "${HAVE_MANPATH}"; then
 	:
 elif manpath 1>&3 2>&3; then
 	echo "manpath: yes" 1>&2
@@ -361,6 +369,7 @@ cat << __HEREDOC__
 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
 #define HAVE_ERR ${HAVE_ERR}
 #define HAVE_FTS ${HAVE_FTS}
+#define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
 #define HAVE_GETLINE ${HAVE_GETLINE}
 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
 #define HAVE_ISBLANK ${HAVE_ISBLANK}
Index: configure.local.example
===================================================================
RCS file: /home/cvs/mdocml/mdocml/configure.local.example,v
retrieving revision 1.14.2.4
retrieving revision 1.14.2.5
diff -Lconfigure.local.example -Lconfigure.local.example -u -p -r1.14.2.4 -r1.14.2.5
--- configure.local.example
+++ configure.local.example
@@ -267,7 +267,8 @@ CFLAGS="-g"
 HAVE_DIRENT_NAMLEN=0
 HAVE_EFTYPE=0
 HAVE_ERR=0
-HAVE_FTS=0
+HAVE_FTS=0  # Setting this implies HAVE_FTS_COMPARE_CONST=0.
+HAVE_FTS_COMPARE_CONST=0  # Setting this implies HAVE_FTS=1.
 HAVE_GETLINE=0
 HAVE_GETSUBOPT=0
 HAVE_ISBLANK=0
Index: mandocdb.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandocdb.c,v
retrieving revision 1.220.2.2
retrieving revision 1.220.2.3
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.220.2.2 -r1.220.2.3
--- mandocdb.c
+++ mandocdb.c
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011-2016 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2016 Ed Maste <emaste@freebsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -103,6 +104,7 @@ struct	mpage {
 	char		*arch;    /* architecture from file content */
 	char		*title;   /* title from file content */
 	char		*desc;    /* description from file content */
+	struct mpage	*next;    /* singly linked list */
 	struct mlink	*mlinks;  /* singly linked list */
 	int		 form;    /* format from file content */
 	int		 name_head_done;
@@ -149,6 +151,11 @@ static	void	 dbadd_mlink_name(const stru
 static	int	 dbopen(int);
 static	void	 dbprune(void);
 static	void	 filescan(const char *);
+#if HAVE_FTS_COMPARE_CONST
+static	int	 fts_compare(const FTSENT *const *, const FTSENT *const *);
+#else
+static	int	 fts_compare(const FTSENT **, const FTSENT **);
+#endif
 static	void	 mlink_add(struct mlink *, const struct stat *);
 static	void	 mlink_check(struct mpage *, struct mlink *);
 static	void	 mlink_free(struct mlink *);
@@ -201,6 +208,7 @@ static	int		 write_utf8; /* write UTF-8 
 static	int		 exitcode; /* to be returned by main */
 static	enum op		 op; /* operational mode */
 static	char		 basedir[PATH_MAX]; /* current base directory */
+static	struct mpage	*mpage_head; /* list of distinct manual pages */
 static	struct ohash	 mpages; /* table of distinct manual pages */
 static	struct ohash	 mlinks; /* table of directory entries */
 static	struct ohash	 names; /* table of all names */
@@ -576,6 +584,20 @@ usage:
 }
 
 /*
+ * To get a singly linked list in alpha order while inserting entries
+ * at the beginning, process directory entries in reverse alpha order.
+ */
+static int
+#if HAVE_FTS_COMPARE_CONST
+fts_compare(const FTSENT *const *a, const FTSENT *const *b)
+#else
+fts_compare(const FTSENT **a, const FTSENT **b)
+#endif
+{
+	return -strcmp((*a)->fts_name, (*b)->fts_name);
+}
+
+/*
  * Scan a directory tree rooted at "basedir" for manpages.
  * We use fts(), scanning directory parts along the way for clues to our
  * section and architecture.
@@ -604,8 +626,8 @@ treescan(void)
 	argv[0] = ".";
 	argv[1] = (char *)NULL;
 
-	f = fts_open((char * const *)argv,
-	    FTS_PHYSICAL | FTS_NOCHDIR, NULL);
+	f = fts_open((char * const *)argv, FTS_PHYSICAL | FTS_NOCHDIR,
+	    fts_compare);
 	if (f == NULL) {
 		exitcode = (int)MANDOCLEVEL_SYSERR;
 		say("", "&fts_open");
@@ -970,6 +992,8 @@ mlink_add(struct mlink *mlink, const str
 		mpage = mandoc_calloc(1, sizeof(struct mpage));
 		mpage->inodev.st_ino = inodev.st_ino;
 		mpage->inodev.st_dev = inodev.st_dev;
+		mpage->next = mpage_head;
+		mpage_head = mpage;
 		ohash_insert(&mpages, slot, mpage);
 	} else
 		mlink->next = mpage->mlinks;
@@ -993,20 +1017,18 @@ mpages_free(void)
 {
 	struct mpage	*mpage;
 	struct mlink	*mlink;
-	unsigned int	 slot;
 
-	mpage = ohash_first(&mpages, &slot);
-	while (NULL != mpage) {
-		while (NULL != (mlink = mpage->mlinks)) {
+	while ((mpage = mpage_head) != NULL) {
+		while ((mlink = mpage->mlinks) != NULL) {
 			mpage->mlinks = mlink->next;
 			mlink_free(mlink);
 		}
+		mpage_head = mpage->next;
 		free(mpage->sec);
 		free(mpage->arch);
 		free(mpage->title);
 		free(mpage->desc);
 		free(mpage);
-		mpage = ohash_next(&mpages, &slot);
 	}
 }
 
@@ -1127,18 +1149,14 @@ mpages_merge(struct mparse *mp)
 	char			*sodest;
 	char			*cp;
 	int			 fd;
-	unsigned int		 pslot;
 
 	if ( ! nodb)
 		SQL_EXEC("BEGIN TRANSACTION");
 
-	mpage = ohash_first(&mpages, &pslot);
-	while (mpage != NULL) {
+	for (mpage = mpage_head; mpage != NULL; mpage = mpage->next) {
 		mlinks_undupe(mpage);
-		if ((mlink = mpage->mlinks) == NULL) {
-			mpage = ohash_next(&mpages, &pslot);
+		if ((mlink = mpage->mlinks) == NULL)
 			continue;
-		}
 
 		name_mask = NAME_MASK;
 		mandoc_ohash_init(&names, 4, offsetof(struct str, key));
@@ -1260,7 +1278,6 @@ mpages_merge(struct mparse *mp)
 nextpage:
 		ohash_delete(&strings);
 		ohash_delete(&names);
-		mpage = ohash_next(&mpages, &pslot);
 	}
 
 	if (0 == nodb)
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-20 18:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-20 18:52 mdocml: merge reproducible build support including compat glue to 1.13 schwarze

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).