OSDN Git Service

Implement foundation for future NLS enabled diagnostics.
[mingw/mingw-get.git] / src / dmhmsgs.h
1 #ifndef DMHMSGS_H
2 /*
3  * dmhmsgs.h
4  *
5  * $Id$
6  *
7  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8  * Copyright (C) 2013, MinGW.org Project
9  *
10  *
11  * Public declarations for predefined diagnostic messages.
12  *
13  *
14  * This is free software.  Permission is granted to copy, modify and
15  * redistribute this software, under the provisions of the GNU General
16  * Public License, Version 3, (or, at your option, any later version),
17  * as published by the Free Software Foundation; see the file COPYING
18  * for licensing details.
19  *
20  * Note, in particular, that this software is provided "as is", in the
21  * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
22  * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
23  * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
24  * MinGW Project, accept liability for any damages, however caused,
25  * arising from the use of this software.
26  *
27  */
28 #define DMHMSGS_H  1
29
30 /* Ensure that we can identify extern "C" interfaces,
31  * when compiling C++ code...
32  */
33 #ifdef __cplusplus
34 /* ...defining the following in the C++ case...
35  */
36 # define EXTERN_C       extern "C"
37 # define BEGIN_C_DECLS  extern "C" {
38 # define END_C_DECLS    }
39 #else
40 /* ...whilst ensuring that they have no effect in C.
41  */
42 # define EXTERN_C
43 # define BEGIN_C_DECLS
44 # define END_C_DECLS
45 #endif
46
47 /* Within the interface definition, and its implementation, we need
48  * a mechanism to represent the "void" data type, which will become
49  * invisible at point of use.
50  */
51 #undef  DMH_VOID
52 #define DMH_VOID  void
53
54 /* Generic macros for defining both the message catalogue interface,
55  * and its default (embedded code level) implementation.
56  */
57 #define DMHMSG( SET, MSG )  dmhmsg_##SET##_##MSG( DMH_VOID )
58 #define MSGDEF( DEF, TXT )  const char *DMHMSG( DEF )GETMSG( DEF, TXT )
59
60 /* The following macro provides a convenience mechanism for referring
61  * to any message implementation via its symbolic ID.
62  */
63 #define DMHTXT( DEF )       DMHMSG( DEF )
64
65 /* Discriminate between interface (header file) and implementation...
66  */
67 #if DMHMSGS_IMPLEMENTATION
68  /* We are compiling the implementation; we need to set up _GETMSG,
69   * so that it generates a function body for each message reference...
70   */
71 # undef  GETMSG
72 # if DMH_NLS_ENABLED
73   /* ...directing the request to catgets(), to possibly retrieve the
74    * message text from an external catalogue, when NLS is enabled...
75    */
76 #  define GETMSG( SET, MSG, TXT )   { return catgets( MSGCAT, SET, MSG, TXT ); }
77
78 # else
79   /* ...otherwise, simply returning the default (compiled in) text.
80    */
81 #  define GETMSG( SET, MSG, TXT )   { return TXT; }
82 # endif
83
84 #else
85  /* ...this isn't implementation: we adjust the definition of _GETMSG,
86   * so that MSGDEF compiles as a function prototype.
87   */
88 # define GETMSG( SET, MSG, TXT )    ;
89 #endif
90
91 /* Each of the message definitions must be compiled with an extern "C"
92  * interface.
93  */
94 BEGIN_C_DECLS
95
96 /* Each individual message requires a definition for its catgets() ID tuple,
97  * (which identifies both set ID and message ID, as a comma separated pair),
98  * and an invocation of MSGDEF, to define the interface and implementation;
99  * this may also be accompanied by a further symbolic name definition, to
100  * facilitate references to the text provided by the implementation.
101  */
102 #define MSG_SPECIFICATION_ERROR     1, 1
103 MSGDEF( MSG_SPECIFICATION_ERROR,   "internal package specification error\n" )
104 #define PKGMSG_SPECIFICATION_ERROR  DMHTXT( MSG_SPECIFICATION_ERROR )
105
106 END_C_DECLS
107
108 /* At point of use, we need DMH_VOID to represent nothing.
109  */
110 #undef  DMH_VOID
111 #define DMH_VOID
112
113 #endif /* DMHMSGS_H: $RCSfile$: end of file */