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