From 8252c763c9c961cf4fd02437396950538424ead9 Mon Sep 17 00:00:00 2001 From: Keith Marshall Date: Fri, 18 Oct 2013 05:11:30 +0100 Subject: [PATCH] Implement foundation for future NLS enabled diagnostics. --- ChangeLog | 14 +++++++ Makefile.in | 3 +- src/dmhmsgs.c | 44 ++++++++++++++++++++++ src/dmhmsgs.h | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pkgname.cpp | 3 +- 5 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 src/dmhmsgs.c create mode 100644 src/dmhmsgs.h diff --git a/ChangeLog b/ChangeLog index b9af848..7d80264 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2013-10-18 Keith Marshall + + 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 Add automated build time configuration management. diff --git a/Makefile.in b/Makefile.in index 93fe9f6..70cd6f3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 index 0000000..9a04af8 --- /dev/null +++ b/src/dmhmsgs.c @@ -0,0 +1,44 @@ +/* + * dmhmsgs.c + * + * $Id$ + * + * Written by Keith Marshall + * 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 index 0000000..8c60c76 --- /dev/null +++ b/src/dmhmsgs.h @@ -0,0 +1,113 @@ +#ifndef DMHMSGS_H +/* + * dmhmsgs.h + * + * $Id$ + * + * Written by Keith Marshall + * 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 */ diff --git a/src/pkgname.cpp b/src/pkgname.cpp index 3fff7b1..a61a11a 100644 --- a/src/pkgname.cpp +++ b/src/pkgname.cpp @@ -31,6 +31,7 @@ #include #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 ); -- 2.11.0