OSDN Git Service

Implement foundation for future NLS enabled diagnostics.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 18 Oct 2013 04:11:30 +0000 (05:11 +0100)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Fri, 18 Oct 2013 04:11:30 +0000 (05:11 +0100)
ChangeLog
Makefile.in
src/dmhmsgs.c [new file with mode: 0644]
src/dmhmsgs.h [new file with mode: 0644]
src/pkgname.cpp

index b9af848..7d80264 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2013-10-18  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Implement foundation for future NLS enabled diagnostics.
+
+       * src/dmhmsgs.h: New file; it declares the NLS capable DMH interface.
+       * src/dmhmsgs.c: New file; it implements rudimentary NLS hooks, (but
+       currently does not direct them to any NLS provider), together with an
+       initial subset of a default (compiled in) message catalogue.
+
+       * Makefile.in (CORE_DLL_OBJECTS): Add dmhmsgs.$OBJEXT
+
+       * src/pkgname.cpp (pkgArchiveName): Modify diagnostics, to use...
+       (PKGMSG_SPECIFICATION_ERROR): ...this dmhmsgs.h declared message.
+
 2013-10-15  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Add automated build time configuration management.
index 93fe9f6..70cd6f3 100644 (file)
@@ -160,7 +160,8 @@ LIBS = -Wl,-Bstatic -llua -lz -lbz2 -llzma -Wl,-Bdynamic -lwininet
 
 # Define the content of package deliverables.
 #
-CORE_DLL_OBJECTS  =  climain.$(OBJEXT) pkgshow.$(OBJEXT) dmhcore.$(OBJEXT) \
+CORE_DLL_OBJECTS  =  \
+   climain.$(OBJEXT) pkgshow.$(OBJEXT) dmhcore.$(OBJEXT) dmhmsgs.$(OBJEXT) \
    pkgbind.$(OBJEXT) pkginet.$(OBJEXT) pkgstrm.$(OBJEXT) pkgname.$(OBJEXT) \
    pkgexec.$(OBJEXT) pkgfind.$(OBJEXT) pkginfo.$(OBJEXT) pkgspec.$(OBJEXT) \
    pkgopts.$(OBJEXT) sysroot.$(OBJEXT) pkghash.$(OBJEXT) pkgkeys.$(OBJEXT) \
diff --git a/src/dmhmsgs.c b/src/dmhmsgs.c
new file mode 100644 (file)
index 0000000..9a04af8
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * dmhmsgs.c
+ *
+ * $Id$
+ *
+ * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
+ * Copyright (C) 2013, MinGW.org Project
+ *
+ *
+ * Implementation module for predefined diagnostic messages.
+ *
+ *
+ * This is free software.  Permission is granted to copy, modify and
+ * redistribute this software, under the provisions of the GNU General
+ * Public License, Version 3, (or, at your option, any later version),
+ * as published by the Free Software Foundation; see the file COPYING
+ * for licensing details.
+ *
+ * Note, in particular, that this software is provided "as is", in the
+ * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
+ * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
+ * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
+ * MinGW Project, accept liability for any damages, however caused,
+ * arising from the use of this software.
+ *
+ */
+#include "dmhmsgs.h"
+
+/* FIXME: although we've provided supporting infrastructure, we are not
+ * yet ready to provide an NLS enabled implementation; ensure that we do
+ * not accidentally attempt to do this.
+ */
+#undef DMH_NLS_ENABLED
+
+/* To provide the message catalogue implementation, we must parse the
+ * header file again, with its multiple include guard disabled, and with
+ * DMHMSGS_IMPLEMENTATION defined, (with a non-zero value).
+ */
+#undef  DMHMSGS_H
+#define DMHMSGS_IMPLEMENTATION  1
+
+#include "dmhmsgs.h"
+
+/* $RCSfile$: end of file */
diff --git a/src/dmhmsgs.h b/src/dmhmsgs.h
new file mode 100644 (file)
index 0000000..8c60c76
--- /dev/null
@@ -0,0 +1,113 @@
+#ifndef DMHMSGS_H
+/*
+ * dmhmsgs.h
+ *
+ * $Id$
+ *
+ * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
+ * Copyright (C) 2013, MinGW.org Project
+ *
+ *
+ * Public declarations for predefined diagnostic messages.
+ *
+ *
+ * This is free software.  Permission is granted to copy, modify and
+ * redistribute this software, under the provisions of the GNU General
+ * Public License, Version 3, (or, at your option, any later version),
+ * as published by the Free Software Foundation; see the file COPYING
+ * for licensing details.
+ *
+ * Note, in particular, that this software is provided "as is", in the
+ * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
+ * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
+ * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
+ * MinGW Project, accept liability for any damages, however caused,
+ * arising from the use of this software.
+ *
+ */
+#define DMHMSGS_H  1
+
+/* Ensure that we can identify extern "C" interfaces,
+ * when compiling C++ code...
+ */
+#ifdef __cplusplus
+/* ...defining the following in the C++ case...
+ */
+# define EXTERN_C       extern "C"
+# define BEGIN_C_DECLS  extern "C" {
+# define END_C_DECLS    }
+#else
+/* ...whilst ensuring that they have no effect in C.
+ */
+# define EXTERN_C
+# define BEGIN_C_DECLS
+# define END_C_DECLS
+#endif
+
+/* Within the interface definition, and its implementation, we need
+ * a mechanism to represent the "void" data type, which will become
+ * invisible at point of use.
+ */
+#undef  DMH_VOID
+#define DMH_VOID  void
+
+/* Generic macros for defining both the message catalogue interface,
+ * and its default (embedded code level) implementation.
+ */
+#define DMHMSG( SET, MSG )  dmhmsg_##SET##_##MSG( DMH_VOID )
+#define MSGDEF( DEF, TXT )  const char *DMHMSG( DEF )GETMSG( DEF, TXT )
+
+/* The following macro provides a convenience mechanism for referring
+ * to any message implementation via its symbolic ID.
+ */
+#define DMHTXT( DEF )      DMHMSG( DEF )
+
+/* Discriminate between interface (header file) and implementation...
+ */
+#if DMHMSGS_IMPLEMENTATION
+ /* We are compiling the implementation; we need to set up _GETMSG,
+  * so that it generates a function body for each message reference...
+  */
+# undef  GETMSG
+# if DMH_NLS_ENABLED
+  /* ...directing the request to catgets(), to possibly retrieve the
+   * message text from an external catalogue, when NLS is enabled...
+   */
+#  define GETMSG( SET, MSG, TXT )   { return catgets( MSGCAT, SET, MSG, TXT ); }
+
+# else
+  /* ...otherwise, simply returning the default (compiled in) text.
+   */
+#  define GETMSG( SET, MSG, TXT )   { return TXT; }
+# endif
+
+#else
+ /* ...this isn't implementation: we adjust the definition of _GETMSG,
+  * so that MSGDEF compiles as a function prototype.
+  */
+# define GETMSG( SET, MSG, TXT )    ;
+#endif
+
+/* Each of the message definitions must be compiled with an extern "C"
+ * interface.
+ */
+BEGIN_C_DECLS
+
+/* Each individual message requires a definition for its catgets() ID tuple,
+ * (which identifies both set ID and message ID, as a comma separated pair),
+ * and an invocation of MSGDEF, to define the interface and implementation;
+ * this may also be accompanied by a further symbolic name definition, to
+ * facilitate references to the text provided by the implementation.
+ */
+#define MSG_SPECIFICATION_ERROR     1, 1
+MSGDEF( MSG_SPECIFICATION_ERROR,   "internal package specification error\n" )
+#define PKGMSG_SPECIFICATION_ERROR  DMHTXT( MSG_SPECIFICATION_ERROR )
+
+END_C_DECLS
+
+/* At point of use, we need DMH_VOID to represent nothing.
+ */
+#undef  DMH_VOID
+#define DMH_VOID
+
+#endif /* DMHMSGS_H: $RCSfile$: end of file */
index 3fff7b1..a61a11a 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 
 #include "dmh.h"
+#include "dmhmsgs.h"
 #include "pkgbase.h"
 #include "pkgkeys.h"
 #include "pkginfo.h"
@@ -56,7 +57,7 @@ const char *pkgArchiveName( pkgXmlNode *rel, const char *tag, unsigned opt )
     /* Complain that this XML element type is invalid, in this context...
      */
     dmh_control( DMH_BEGIN_DIGEST );
-    dmh_notify( DMH_ERROR, "internal package specification error\n" );
+    dmh_notify( DMH_ERROR, PKGMSG_SPECIFICATION_ERROR );
     dmh_notify( DMH_ERROR, "can't get 'tarname' for non-release element %s\n", reftype );
     dmh_notify( DMH_ERROR, "please report this to the package maintainer\n" );
     dmh_control( DMH_END_DIGEST );