Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Immigrate to POSIX NLS; drop the db-based catalog.

  • Loading branch information...
commit b52560b9faa06e4a5e9b2631404b2826b7ca9eb8 1 parent 5454b75
@lichray authored
Showing with 43 additions and 66 deletions.
  1. +4 −2 common/gs.h
  2. +2 −1  common/main.c
  3. +37 −63 common/msg.c
View
6 common/gs.h
@@ -6,11 +6,13 @@
*
* See the LICENSE file for redistribution information.
*
- * $Id: gs.h,v 10.36 2011/12/02 18:45:06 zy Exp $
+ * $Id: gs.h,v 11.0 2012/10/17 06:34:37 zy Exp $
*/
#define TEMPORARY_FILE_STRING "/tmp" /* Default temporary file name. */
+#include <nl_types.h>
+
/*
* File reference structure (FREF). The structure contains the name of the
* file, along with the information that follows the name.
@@ -72,7 +74,7 @@ struct _gs {
#define GO_TERM 3 /* Global options: terminal type. */
OPTION opts[GO_TERM + 1];
- DB *msg; /* Message catalog DB. */
+ nl_catd catd; /* Message catalog descriptor. */
MSGH msgq[1]; /* User message list. */
#define DEFAULT_NOPRINT '\1' /* Emergency non-printable character. */
int noprint; /* Cached, unprintable character. */
View
3  common/main.c
@@ -18,7 +18,7 @@ static const char copyright[] =
#endif /* not lint */
#ifndef lint
-static const char sccsid[] = "$Id: main.c,v 10.64 2011/07/04 14:33:38 zy Exp $";
+static const char sccsid[] = "$Id: main.c,v 11.0 2012/10/17 06:34:37 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -73,6 +73,7 @@ editor(
/* Initialize the message routine, if not defined by the screen. */
if (gp->scr_msg == NULL)
gp->scr_msg = vs_msg;
+ gp->catd = (nl_catd)-1;
/* Common global structure initialization. */
TAILQ_INIT(gp->dq);
View
100 common/msg.c
@@ -10,7 +10,7 @@
#include "config.h"
#ifndef lint
-static const char sccsid[] = "$Id: msg.c,v 10.53 2012/04/12 07:00:49 zy Exp $";
+static const char sccsid[] = "$Id: msg.c,v 11.0 2012/10/17 06:34:37 zy Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -22,6 +22,7 @@ static const char sccsid[] = "$Id: msg.c,v 10.53 2012/04/12 07:00:49 zy Exp $";
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -721,64 +722,49 @@ msg_open(
* message will be repeated every time nvi is started up.
*/
static int first = 1;
- DB *db;
- DBT data, key;
- recno_t msgno;
- char *p, *t;
- int nf = 0;
+ nl_catd catd;
+ char *p;
int rval = 0;
- if ((p = strrchr(file, '/')) != NULL && p[1] == '\0' &&
- (((t = getenv("LC_MESSAGES")) != NULL && t[0] != '\0') ||
- ((t = getenv("LANG")) != NULL && t[0] != '\0'))) {
- if ((p = join(file, t)) == NULL) {
+ if ((p = strrchr(file, '/')) != NULL && p[1] == '\0') {
+ /* Confirms to XPG4. */
+ if ((p = join(file, setlocale(LC_MESSAGES, NULL))) == NULL) {
msgq(sp, M_SYSERR, NULL);
return (1);
}
- nf = 1;
- } else
- p = file;
- if ((db = dbopen(p,
- O_NONBLOCK | O_RDONLY, 0, DB_RECNO, NULL)) == NULL) {
- if (first) {
- first = 0;
- rval = 1;
- goto ret;
+ } else {
+ /* Make sure it's recognized as a path by catopen(3). */
+ if ((p = join(".", file)) == NULL) {
+ msgq(sp, M_SYSERR, NULL);
+ return (1);
}
- msgq_str(sp, M_SYSERR, p, "%s");
- rval = 1;
- goto ret;
}
-
- /*
- * Test record 1 for the magic string. The msgq call is here so
- * the message catalog build finds it.
- */
-#define VMC "VI_MESSAGE_CATALOG"
- key.data = &msgno;
- key.size = sizeof(recno_t);
- msgno = 1;
- if (db->get(db, &key, &data, 0) != 0 ||
- data.size != sizeof(VMC) - 1 ||
- memcmp(data.data, VMC, sizeof(VMC) - 1)) {
- (void)db->close(db);
+ errno = 0;
+ if ((catd = catopen(p, NL_CAT_LOCALE)) == (nl_catd)-1) {
if (first) {
first = 0;
rval = 1;
goto ret;
}
- msgq_str(sp, M_ERR, p,
- "030|The file %s is not a message catalog");
+
+ /*
+ * POSIX.1-2008 gives no instruction on how to report a
+ * corrupt catalog file. Errno == 0 is not rare; add
+ * EFTYPE, which is seen on FreeBSD, for a good measure.
+ */
+ if (errno == 0 || errno == EFTYPE)
+ msgq_str(sp, M_ERR, p,
+ "030|The file %s is not a message catalog");
+ else
+ msgq_str(sp, M_SYSERR, p, "%s");
rval = 1;
goto ret;
}
first = 0;
- if (sp->gp->msg != NULL)
- (void)sp->gp->msg->close(sp->gp->msg);
- sp->gp->msg = db;
-ret: if (nf)
- free(p);
+ msg_close(sp->gp);
+ sp->gp->catd = catd;
+ret: free(p);
return (rval);
}
@@ -791,8 +777,8 @@ ret: if (nf)
void
msg_close(GS *gp)
{
- if (gp->msg != NULL)
- (void)gp->msg->close(gp->msg);
+ if (gp->catd != (nl_catd)-1)
+ (void)catclose(gp->catd);
}
/*
@@ -846,8 +832,8 @@ msg_cat(
size_t *lenp)
{
GS *gp;
- DBT data, key;
- recno_t msgno;
+ char *p;
+ int msgno;
/*
* If it's not a catalog message, i.e. has doesn't have a leading
@@ -855,28 +841,16 @@ msg_cat(
*/
if (isdigit(str[0]) &&
isdigit(str[1]) && isdigit(str[2]) && str[3] == '|') {
- key.data = &msgno;
- key.size = sizeof(recno_t);
msgno = atoi(str);
+ str = &str[4];
- /*
- * XXX
- * Really sleazy hack -- we put an extra character on the
- * end of the format string, and then we change it to be
- * the nul termination of the string. There ought to be
- * a better way. Once we can allocate multiple temporary
- * memory buffers, maybe we can use one of them instead.
- */
gp = sp == NULL ? NULL : sp->gp;
- if (gp != NULL && gp->msg != NULL &&
- gp->msg->get(gp->msg, &key, &data, 0) == 0 &&
- data.size != 0) {
+ if (gp != NULL && gp->catd != (nl_catd)-1 &&
+ (p = catgets(gp->catd, 1, msgno, str)) != NULL) {
if (lenp != NULL)
- *lenp = data.size - 1;
- ((char *)data.data)[data.size - 1] = '\0';
- return (data.data);
+ *lenp = strlen(p);
+ return (p);
}
- str = &str[4];
}
if (lenp != NULL)
*lenp = strlen(str);
Please sign in to comment.
Something went wrong with that request. Please try again.