]>
cvs.zerfleddert.de Git - micropolis/blob - src/tclx/src/tclxmsgc.c
4 * Contains commands for accessing XPG/3 message catalogs. If real XPG/3
5 * message catalogs are not available, the default string is returned.
6 *-----------------------------------------------------------------------------
7 * Copyright 1992 Karl Lehenbauer and Mark Diekhans.
9 * Permission to use, copy, modify, and distribute this software and its
10 * documentation for any purpose and without fee is hereby granted, provided
11 * that the above copyright notice appear in all copies. Karl Lehenbauer and
12 * Mark Diekhans make no representations about the suitability of this
13 * software for any purpose. It is provided "as is" without express or
15 *-----------------------------------------------------------------------------
16 * $Id: tclXmsgcat.c,v 2.0 1992/10/16 04:51:02 markd Rel $
17 *-----------------------------------------------------------------------------
22 #ifdef TCL_HAVE_CATGETS
30 #endif /* TCL_HAVE_CATGETS */
33 ParseFailOption
_ANSI_ARGS_((Tcl_Interp
*interp
,
34 CONST
char *optionStr
,
38 CatOpFailed
_ANSI_ARGS_((Tcl_Interp
*interp
,
39 CONST
char *errorMsg
));
42 * Message catalog table is global, so it is shared between all interpreters
43 * in the same process.
45 static void_pt msgCatTblPtr
= NULL
;
47 #ifndef TCL_HAVE_CATGETS
50 *-----------------------------------------------------------------------------
53 * A stub to use when message catalogs are not available.
56 * Always returns the default string.
58 *-----------------------------------------------------------------------------
69 *-----------------------------------------------------------------------------
72 * A stub to use when message catalogs are not available.
77 *-----------------------------------------------------------------------------
80 catgets (catd
, set_num
, msg_num
, defaultStr
)
89 *-----------------------------------------------------------------------------
92 * A stub to use when message catalogs are not available.
97 *-----------------------------------------------------------------------------
105 #endif /* TCL_HAVE_CATGETS */
108 *-----------------------------------------------------------------------------
111 * Parse the -fail/-nofail option, if specified.
114 * Standard Tcl results.
116 *-----------------------------------------------------------------------------
119 ParseFailOption (interp
, optionStr
, failPtr
)
121 CONST
char *optionStr
;
124 if (STREQU ("-fail", ((char *) optionStr
)))
126 else if (STREQU ("-nofail", ((char *) optionStr
)))
129 Tcl_AppendResult (interp
, "Expected option of `-fail' or ",
130 "`-nofail', got: `", optionStr
, "'",
138 *-----------------------------------------------------------------------------
141 * Handles failures of catopen and catclose. If message catalogs are
142 * available, if returns the supplied message. If message are not
143 * available, it returns a message indicating that message stubs are used.
144 * It is not specified by XPG/3 how to get the details of a message catalog
145 * open or close failure.
148 * Always returns TCL_ERROR;
150 *-----------------------------------------------------------------------------
153 CatOpFailed (interp
, errorMsg
)
155 CONST
char *errorMsg
;
157 #ifdef TCL_HAVE_CATGETS
159 Tcl_AppendResult (interp
, errorMsg
, (char *) NULL
);
163 Tcl_AppendResult (interp
, "the message catalog facility is not available,",
164 " default string is always returned", (char *) NULL
);
166 #endif /* TCL_HAVE_CATGETS */
172 *-----------------------------------------------------------------------------
175 * Implements the TCL echo command:
176 * catopen [-fail|-nofail] catname
179 * Standard Tcl results.
181 *-----------------------------------------------------------------------------
184 Tcl_CatopenCmd (clientData
, interp
, argc
, argv
)
185 ClientData clientData
;
194 if ((argc
< 2) || (argc
> 3)) {
195 Tcl_AppendResult (interp
, argv
[0], " [-fail|-nofail] catname",
200 if (ParseFailOption (interp
, argv
[1], &fail
) != TCL_OK
)
205 catDesc
= catopen (argv
[argc
- 1], 0);
206 if ((catDesc
== (nl_catd
) -1) && fail
)
207 return CatOpFailed (interp
, "open of message catalog failed");
209 catDescPtr
= Tcl_HandleAlloc (msgCatTblPtr
, interp
->result
);
210 *catDescPtr
= catDesc
;
216 *-----------------------------------------------------------------------------
219 * Implements the TCL echo command:
220 * catgets catHandle setnum msgnum defaultstr
223 * Standard Tcl results.
225 *-----------------------------------------------------------------------------
228 Tcl_CatgetsCmd (clientData
, interp
, argc
, argv
)
229 ClientData clientData
;
235 int msgSetNum
, msgNum
;
239 Tcl_AppendResult (interp
, argv
[0], " catHandle setnum msgnum ",
240 "defaultstr", (char *) NULL
);
243 catDescPtr
= Tcl_HandleXlate (interp
, msgCatTblPtr
, argv
[1]);
244 if (catDescPtr
== NULL
)
246 if (Tcl_GetInt (interp
, argv
[2], &msgSetNum
) != TCL_OK
)
248 if (Tcl_GetInt (interp
, argv
[3], &msgNum
) != TCL_OK
)
251 localMsg
= catgets (*catDescPtr
, msgSetNum
, msgNum
, argv
[4]);
253 Tcl_SetResult (interp
, localMsg
, TCL_VOLATILE
);
258 *-----------------------------------------------------------------------------
261 * Implements the TCL echo command:
262 * catclose [-fail|-nofail] catHandle
265 * Standard Tcl results.
267 *-----------------------------------------------------------------------------
270 Tcl_CatcloseCmd (clientData
, interp
, argc
, argv
)
271 ClientData clientData
;
279 if ((argc
< 2) || (argc
> 3)) {
280 Tcl_AppendResult (interp
, argv
[0], " [-fail|-nofail] catHandle",
285 if (ParseFailOption (interp
, argv
[1], &fail
) != TCL_OK
)
290 catDescPtr
= Tcl_HandleXlate (interp
, msgCatTblPtr
, argv
[argc
- 1]);
291 if (catDescPtr
== NULL
)
294 if ((catclose (*catDescPtr
) < 0) && fail
)
295 return CatOpFailed (interp
, "close of message catalog failed");
297 Tcl_HandleFree (msgCatTblPtr
, catDescPtr
);
302 *-----------------------------------------------------------------------------
305 * Decrements the use count on the globals when a command is deleted.
306 * If it goes to zero, all resources are released.
308 *-----------------------------------------------------------------------------
311 MsgCatCleanUp (clientData
)
312 ClientData clientData
;
317 if (Tcl_HandleTblUseCount (msgCatTblPtr
, -1) > 0)
321 while ((catDescPtr
= Tcl_HandleWalk (msgCatTblPtr
, &walkKey
)) != NULL
)
322 catclose (*catDescPtr
);
324 Tcl_HandleTblRelease (msgCatTblPtr
);
328 *-----------------------------------------------------------------------------
331 * Initialize the Tcl XPG/3 message catalog support faility.
333 *-----------------------------------------------------------------------------
336 Tcl_InitMsgCat (interp
)
340 if (msgCatTblPtr
== NULL
)
341 msgCatTblPtr
= Tcl_HandleTblInit ("msgcat", sizeof (nl_catd
), 6);
343 (void) Tcl_HandleTblUseCount (msgCatTblPtr
, 2); /* 3 commands total */
346 * Initialize the commands.
349 Tcl_CreateCommand (interp
, "catopen", Tcl_CatopenCmd
,
350 (ClientData
)NULL
, MsgCatCleanUp
);
351 Tcl_CreateCommand (interp
, "catgets", Tcl_CatgetsCmd
,
352 (ClientData
)NULL
, MsgCatCleanUp
);
353 Tcl_CreateCommand (interp
, "catclose", Tcl_CatcloseCmd
,
354 (ClientData
)NULL
, MsgCatCleanUp
);