Cleanup of -Wpointer-compare warnings.
[oweals/cde.git] / cde / lib / DtPrint / PrintMsgs.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: PrintMsgs.c /main/14 1999/10/14 13:54:53 mgreess $ */
24 /*
25  * DtPrint/PrintMsgs.c
26  */
27 /*
28  * (c) Copyright 1996 Digital Equipment Corporation.
29  * (c) Copyright 1996 Hewlett-Packard Company.
30  * (c) Copyright 1996 International Business Machines Corp.
31  * (c) Copyright 1996 Sun Microsystems, Inc.
32  * (c) Copyright 1996 Novell, Inc. 
33  * (c) Copyright 1996 FUJITSU LIMITED.
34  * (c) Copyright 1996 Hitachi.
35  */
36
37 #ifdef I18N_MSG
38
39 #include <stdio.h>
40 #include <nl_types.h>
41 #include <X11/Intrinsic.h>
42 #include <Dt/PrintI.h>
43
44 #if !defined(NL_CAT_LOCALE)
45 #define NL_CAT_LOCALE 0
46 #endif 
47
48 #define _DTPRINT_CAT_NAME "DtPrint"
49
50 #endif /* I18N_MSG */
51
52 /*
53  * ------------------------------------------------------------------------
54  * PrintSetupB module messages
55  */
56 const char _DtPrMsgPrintSetupBox_0000[] =
57    "Invalid workAreaLocation resource setting.";
58 const char _DtPrMsgPrintSetupBox_0001[] =
59    "More Printers...";
60 const char _DtPrMsgPrintSetupBox_0002[] =
61    "Print to File";
62 const char _DtPrMsgPrintSetupBox_0003[] =
63    "Select File...";
64 const char _DtPrMsgPrintSetupBox_0004[] =
65    "Cancel";
66 const char _DtPrMsgPrintSetupBox_0005[] =
67    "Copies:";
68 const char _DtPrMsgPrintSetupBox_0006[] =
69    "Help";
70 const char _DtPrMsgPrintSetupBox_0007[] =
71    "Print";
72 const char _DtPrMsgPrintSetupBox_0008[] =
73    "Printer Name:";
74 const char _DtPrMsgPrintSetupBox_0009[] =
75    "Setup...";
76 const char _DtPrMsgPrintSetupBox_0010[] =
77    "Printer Description:";
78 const char _DtPrMsgPrintSetupBox_0011[] =
79    "Copy count out of range.";
80 const char _DtPrMsgPrintSetupBox_0012[] =
81    "Invalid print setup mode.";
82 const char _DtPrMsgPrintSetupBox_0013[] =
83    "Print setup mode cannot be changed.";
84 const char _DtPrMsgPrintSetupBox_0014[] =
85    "Printer Info...";
86 const char _DtPrMsgPrintSetupBox_0015[] =
87    "Invalid Printer";
88 const char _DtPrMsgPrintSetupBox_0016[] =
89    "Printer %s not found on X print server %s";
90 const char _DtPrMsgPrintSetupBox_0017[] =
91    "Unable to connect to X print server %s";
92 const char _DtPrMsgPrintSetupBox_0018[] =
93    "X server %s does not support printing";
94 const char _DtPrMsgPrintSetupBox_0019[] =
95    "A default printer could not be determined";
96 const char _DtPrMsgPrintSetupBox_0020[] =
97    "An X print server for %s could not be found";
98 const char _DtPrMsgPrintSetupBox_0021[] =
99    "Printer name missing from specifier: %s";
100 const char _DtPrMsgPrintSetupBox_0022[] =
101    "Invalid print destination.";
102 const char _DtPrMsgPrintSetupBox_0023[] =
103    "Unable to convert from compound text.";
104 const char _DtPrMsgPrintSetupBox_0024[] =
105    "Arguments not needed for resource conversion.";
106 const char _DtPrMsgPrintSetupBox_0025[] =
107    "Select Printer Error";
108 const char _DtPrMsgPrintSetupBox_0026[] =
109    "Unable to find any printers.";
110 const char _DtPrMsgPrintSetupBox_0027[] =
111    "description unavailable";
112 const char _DtPrMsgPrintSetupBox_0028[] =
113    "Select File";
114 const char _DtPrMsgPrintSetupBox_0029[] =
115    "Printer Information";
116 const char _DtPrMsgPrintSetupBox_0030[] =
117    "Format:";
118 const char _DtPrMsgPrintSetupBox_0031[] =
119    "Printer Model:";
120 const char _DtPrMsgPrintSetupBox_0032[] =
121    "Printers:";
122 const char _DtPrMsgPrintSetupBox_0033[] =
123    "More Printers";
124 const char _DtPrMsgPrintSetupBox_0034[] =
125    "Print to Printer";
126 const char _DtPrMsgPrintSetupBox_0035[] =
127    "File Name:";
128 const char _DtPrMsgPrintSetupBox_0036[] =
129    "Print Setup - Help";
130
131
132
133 /*
134  * ------------------------------------------------------------------------
135  * _DtPrint Frame widget messages
136  */
137 const char _DtPrMsgPrintOption_0000[] = "Margins";
138 const char _DtPrMsgPrintOption_0001[] = "Top:";
139 const char _DtPrMsgPrintOption_0002[] = "Right:";
140 const char _DtPrMsgPrintOption_0003[] = "Bottom:";
141 const char _DtPrMsgPrintOption_0004[] = "Left:";
142  
143 const char _DtPrMsgPrintOption_0005[] = "Headers and Footers";
144 const char _DtPrMsgPrintOption_0006[] = "Top Left:";
145 const char _DtPrMsgPrintOption_0007[] = "Top Right:";
146 const char _DtPrMsgPrintOption_0008[] = "Bottom Left:";
147 const char _DtPrMsgPrintOption_0009[] = "Bottom Right:";
148  
149 /*
150  * ------------------------------------------------------------------------
151  * Dt Print Dialog Manager module messages
152  */
153 const char _DtPrMsgPrintDlgMgr_0000[] = "Send Mail When Done";
154 const char _DtPrMsgPrintDlgMgr_0001[] = "Banner Page Title:";
155 const char _DtPrMsgPrintDlgMgr_0002[] = "Print Command Options:";
156
157 #if defined(I18N_MSG)
158
159 #if defined(hpV4)
160 /*
161  * Wrapper around catgets -- this makes sure the message string is saved
162  * in a safe location; so repeated calls to catgets() do not overwrite
163  * the catgets() internal buffer.  This has been a problem on HP systems.
164  */
165 static char *catgets_cached(nl_catd catd, int set, int num, char *dflt)
166 {
167 #define INITIAL_NMSGS_PER_SET   300
168 #define INITIAL_NSETS           50
169
170   /* array to hold messages from catalog */
171   static char   ***cached_msgs = NULL;
172   static int    nmsgs_per_set = INITIAL_NMSGS_PER_SET;
173   static int    nsets = INITIAL_NSETS;
174   
175   char          **setptr;
176   int           i, multiplier;
177   Cardinal      size;
178
179   char* message;
180
181   /* convert to a zero based index */
182   int           setIdx = set - 1;
183   int           numIdx = num - 1;
184
185   _DtPrintProcessLock();
186   
187   if (NULL == cached_msgs)
188   {
189       size = sizeof(char**) * nsets;
190       cached_msgs = (char***) XtMalloc(size);
191       memset((char*) cached_msgs, 0, size);
192   }
193   else if (setIdx >= nsets)
194   {
195       for (multiplier=2; setIdx > multiplier*nsets; multiplier++) {}
196       size = sizeof(char**) * nsets;
197       cached_msgs = (char***) XtRealloc((char*) cached_msgs, multiplier * size);
198       memset((char*) (cached_msgs + size), 0, multiplier * size);
199       nsets *= multiplier;
200   }
201
202   if (NULL == cached_msgs[setIdx])
203   {
204       size = sizeof(char*) * nmsgs_per_set;
205       cached_msgs[setIdx] = (char**) XtMalloc(size);
206       memset((char*) cached_msgs[setIdx], 0, size);
207   }
208   else if (numIdx >= nmsgs_per_set)
209   {
210       for (multiplier=2; numIdx > multiplier*nsets; multiplier++) {}
211       size = sizeof(char*) * nmsgs_per_set;
212
213       for (i=0; i<nmsgs_per_set; i++)
214       {
215           if (NULL != cached_msgs[i])
216           {
217               cached_msgs[i] =
218                 (char**) XtRealloc((char*) cached_msgs[i], multiplier * size);
219               memset((char*) (cached_msgs[i] + size), 0, multiplier * size);
220           }
221       }
222       nmsgs_per_set *= multiplier;
223   }
224
225   setptr = cached_msgs[setIdx];
226   if (NULL == setptr[numIdx])
227     setptr[numIdx] = strdup(catgets(catd, set, num, dflt));
228   
229   message = setptr[numIdx];
230
231   _DtPrintProcessUnlock();
232
233   return message;
234 }
235 #endif /* hpV4 */
236
237
238 /*
239  * ------------------------------------------------------------------------
240  * Name: _DtPrintGetMessage
241  *
242  * Parameters:
243  *
244  *   int        set -           The message catalog set number.
245  *
246  *   int        n -             The message number.
247  *
248  *   char       *s -            The default message if the message is not
249  *                              retrieved from a message catalog.
250  *
251  * Returns: the string for set 'set' and number 'n'.
252  */
253 char *
254 _DtPrintGetMessage(
255                    int set,
256                    int n,
257                    char * s)
258 {
259         char *msg;
260         nl_catd catopen();
261         char *catgets();
262         static int first = 1;
263         static nl_catd nlmsg_fd;
264
265         if(first)
266         {
267             _DtPrintProcessLock();
268             if(first) 
269             {
270                 first = 0;
271                 nlmsg_fd = catopen(_DTPRINT_CAT_NAME, NL_CAT_LOCALE);
272             }
273             _DtPrintProcessUnlock();
274         }
275 #if defined(hpV4)
276         msg=catgets_cached(nlmsg_fd,set,n,s);
277 #else
278         msg=catgets(nlmsg_fd,set,n,s);
279 #endif
280         return (msg);
281
282 }
283 #endif /* I18N_MSG */