1 /*
2 **
3 ** resource.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING.  If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author:   Johannes Plass (plass@thep.physik.uni-mainz.de)
24 **           Department of Physics
25 **           Johannes Gutenberg-University
26 **           Mainz, Germany
27 **
28 **           Jose E. Marchesi (jemarch@gnu.org)
29 **           GNU Project
30 **
31 */
32 #include "ac_config.h"
33 
34 #define _GV_RESOURCE_C_
35 
36 /*
37   #define MESSAGES
38 */
39 #include "message.h"
40 
41 #include <ac_config.h>
42 #include "config.h"
43 
44 #include <stdlib.h>
45 #include <stdio.h>
46 
47 #include "paths.h"
48 #include INC_X11(Intrinsic.h)
49 
50 #include "types.h"
51 #include "config.h"
52 #include "file.h"
53 #include "main_resources.h"
54 #include "main_globals.h"
55 #include "resource.h"
56 
57 #   include <sys/types.h>
58 #   include <sys/stat.h>
59 #   include <unistd.h>
60 
61 # ifndef USER_DEFAULTS
62 #   define USER_DEFAULTS "~/.gv"
63 # endif
64 
65 extern char versionCompatibility[];
66 
67 static String class_resources[] = {
68 #   include "gv_class.h"
69   NULL
70 };
71 
72 #include "gv-i18n.h"
73 
74 String intern_resources[] = {
75 #   include INTERN_RESOURCES_H
76   NULL
77 };
78 
79 #ifdef USE_FALLBACK_STYLES
80 #  ifdef FALLBACK_STYLE_1_H
81 static String fallback_style_1[] = {
82 #      include FALLBACK_STYLE_1_H
83   NULL
84 };
85 #  endif
86 #  ifdef FALLBACK_STYLE_2_H
87 static String fallback_style_2[] = {
88 #      include FALLBACK_STYLE_2_H
89   NULL
90 };
91 #  endif
92 #  ifdef FALLBACK_STYLE_3_H
93 static String fallback_style_3[] = {
94 #      include FALLBACK_STYLE_3_H
95   NULL
96 };
97 #  endif
98 #endif
99 
100 static String resource_system_file = NULL;
101 static String resource_user_file   = NULL;
102 static String resource_user_file_symb   = NULL;
103 static int haveXUSERFILESEARCHPATH;
104 static String resource_style_file  = NULL;
105 static String resource_ad_file     = NULL;
106 static char* resource_mergeFileIntoDatabase(XrmDatabase*,char*);
107 
108 
109 extern int debug_p;
110 
111 
112 /*#######################################################
113   resource_freeData
114   #######################################################*/
115 
resource_freeData()116 void resource_freeData()
117 {
118   BEGINMESSAGE(resource_freeData)
119   XtFree(resource_system_file);
120   XtFree(resource_user_file);
121   XtFree(resource_style_file);
122   XtFree(resource_ad_file);
123   ENDMESSAGE(resource_freeData)
124     }
125 
126 /*#######################################################
127   resource_buildDatabase
128   #######################################################*/
129 
130 XrmDatabase
resource_buildDatabase(Display * display,char * app_class,char * app_name,int * argcP _GL_UNUSED,char ** argv _GL_UNUSED)131 resource_buildDatabase (
132                         Display *display,
133                         char *app_class,
134                         char *app_name,
135                         int *argcP _GL_UNUSED,
136                         char **argv _GL_UNUSED)
137 {
138   XrmDatabase gvdb = XtDatabase(display);
139   XrmDatabase db = NULL;
140   String *sP;
141   String s,t, rpath;
142   String tildeGv;
143   char* locale;
144   int i18n;
145   char tmp[GV_MAX_FILENAME_LENGTH];
146   char locale1[100], locale2[100], locale3[100];
147   char loc_lang[100], loc_terr[100], loc_cs[100], loc_mod[100];
148 
149   BEGINMESSAGE(resource_buildDatabase)
150 
151   /* ### class resources ################# */
152   INFMESSAGE(merging class resources into database)
153   sP = class_resources;
154   while (*sP) XrmPutLineResource(&db,*sP++);
155 
156   /* ### system resources ################# */
157   INFMESSAGE(checking for system resources)
158 
159   rpath = XtMalloc (strlen (GV_LIBDIR) + strlen ("/gv_system.ad") + 1);
160   rpath[0] = '\0';
161   strcat (rpath, GV_LIBDIR);
162   strcat (rpath, "/gv_system.ad");
163   if (rpath) {
164     INFSMESSAGE(merging system resource file into database,rpath)
165       XrmCombineFileDatabase(rpath,&db,True);
166     resource_system_file = rpath;
167   }
168 
169   XrmCombineDatabase (gvdb, &db, True);
170   /* CombineDatabase destroyed gvdb==XtDatabase(display), which
171    * XtResolvePathname will access soon, so repair it: */
172   XrmSetDatabase (display, db);
173 
174   /* ### user resources ################# */
175   INFMESSAGE(checking for user resources)
176 
177   strcpy(tmp,USER_DEFAULTS);
178   file_translateTildeInPath(tmp, sizeof(tmp));
179   if (!file_fileIsNotUseful(tmp)) {
180     s = XtNewString(tmp);
181     tildeGv = USER_DEFAULTS;
182     haveXUSERFILESEARCHPATH = 0;
183   } else {
184     s = getenv("XUSERFILESEARCHPATH");
185     if (s) s = XtResolvePathname(display,NULL,NULL,NULL,s,NULL,0,NULL);
186     tildeGv = s;
187     haveXUSERFILESEARCHPATH = 1;
188   }
189   if (s) {
190     INFSMESSAGE(merging user resource file into database,s)
191       XrmPutLineResource(&db,"GV.version: gv 0.0.0");
192       XrmCombineFileDatabase(s,&db,True);
193     resource_user_file = s;
194     resource_user_file_symb = tildeGv;
195   } else {
196     resource_user_file = XtNewString(tmp);
197   }
198 
199   /* ### Loading localisation ### */
200   i18n = 0;
201   locale = 0;
202   locale = getenv("LC_ALL");
203   if ( !locale || !*locale )
204      locale = getenv("LC_MESSAGES");
205   if ( !locale || !*locale )
206      locale = getenv("LANG");
207   if ( !locale || !*locale )
208      locale = "C";
209 
210   {
211      char* cL, * cP;
212 
213      cP = loc_lang;
214      cL = locale;
215 
216      *loc_terr = 0;
217      *loc_cs = 0;
218      *loc_mod = 0;
219 
220      while (*cL)
221      {
222         if ( *cL == '_' ) { *cP = 0; cP = loc_terr; }
223         if ( *cL == '.' ) { *cP = 0; cP = loc_cs; }
224         if ( *cL == '@' ) { *cP = 0; cP = loc_mod; }
225 	*cP++ = *cL++;
226      }
227      *cP = 0;
228   }
229 
230   s = resource_getResource(db,app_class,app_name, "international",0);
231   if (s == NULL || !strcasecmp(s, "False"))
232   {
233      sprintf(locale1, "noint:%s%s", loc_lang, loc_terr);
234      sprintf(locale2, "noint:%s", loc_lang);
235      strcpy(locale3, "C");
236   }
237   else
238   {
239      strcpy(locale1, locale);
240      sprintf(locale2, "%s%s%s", loc_lang, loc_terr, loc_cs);
241      sprintf(locale3, "%s%s", loc_lang, loc_cs);
242   }
243 
244   if (debug_p)
245   {
246      printf("Locale1=%s\n", locale1);
247      printf("Locale2=%s\n", locale2);
248      printf("Locale3=%s\n", locale3);
249   }
250 
251   if (!i18n)
252   {
253      struct stat buf;
254 
255      strcpy(tmp,USER_DEFAULTS "-");
256      strcat(tmp, locale1);
257      file_translateTildeInPath(tmp, sizeof(tmp));
258      if (!stat(tmp, &buf))
259      {
260         i18n = 1;
261         XrmCombineFileDatabase(tmp,&db,True);
262      }
263   }
264 
265   if (!i18n)
266   {
267      struct stat buf;
268 
269      strcpy(tmp,GV_LIBDIR "/nls/");
270      strcat(tmp, locale1);
271      strcat(tmp, ".dat");
272      if (!stat(tmp, &buf))
273      {
274         i18n = 1;
275         XrmCombineFileDatabase(tmp,&db,True);
276      }
277   }
278 
279   if (!i18n)
280   {
281      sP = getI18N(locale1);
282      if (sP)
283      {
284         i18n = 1;
285 	while (*sP) XrmPutLineResource(&db,*sP++);
286      }
287   }
288 
289 
290 
291 
292 
293 
294 
295 
296 
297 
298 
299 
300 
301   if (!i18n)
302   {
303      struct stat buf;
304 
305      strcpy(tmp,USER_DEFAULTS "-");
306      strcat(tmp, locale2);
307      file_translateTildeInPath(tmp, sizeof(tmp));
308      if (!stat(tmp, &buf))
309      {
310         i18n = 1;
311         XrmCombineFileDatabase(tmp,&db,True);
312      }
313   }
314 
315   if (!i18n)
316   {
317      struct stat buf;
318 
319      strcpy(tmp,GV_LIBDIR "/nls/");
320      strcat(tmp, locale2);
321      strcat(tmp, ".dat");
322      if (!stat(tmp, &buf))
323      {
324         i18n = 1;
325         XrmCombineFileDatabase(tmp,&db,True);
326      }
327   }
328 
329   if (!i18n)
330   {
331      sP = getI18N(locale2);
332      if (sP)
333      {
334         i18n = 1;
335 	while (*sP) XrmPutLineResource(&db,*sP++);
336      }
337   }
338 
339 
340 
341 
342 
343 
344 
345 
346   if (!i18n)
347   {
348      struct stat buf;
349 
350      strcpy(tmp,USER_DEFAULTS "-");
351      strcat(tmp, locale3);
352      file_translateTildeInPath(tmp, sizeof(tmp));
353      if (!stat(tmp, &buf))
354      {
355         i18n = 1;
356         XrmCombineFileDatabase(tmp,&db,True);
357      }
358   }
359 
360   if (!i18n)
361   {
362      struct stat buf;
363 
364      strcpy(tmp,GV_LIBDIR "/nls/");
365      strcat(tmp, locale3);
366      strcat(tmp, ".dat");
367      if (!stat(tmp, &buf))
368      {
369         i18n = 1;
370         XrmCombineFileDatabase(tmp,&db,True);
371      }
372   }
373 
374   if (!i18n)
375   {
376      sP = getI18N(locale3);
377      if (sP)
378      {
379         i18n = 1;
380 	while (*sP) XrmPutLineResource(&db,*sP++);
381      }
382   }
383 
384 
385 
386 
387   orientations[0] = resource_getResource(db,app_class,app_name, "portrait.Label",0);
388   orientations[1] = resource_getResource(db,app_class,app_name, "landscape.Label",0);
389   orientations[2] = resource_getResource(db,app_class,app_name, "upsidedown.Label",0);
390   orientations[3] = resource_getResource(db,app_class,app_name, "seascape.Label",0);
391 
392   popupVerb[0] = resource_getResource(db,app_class,app_name, "gs.errors.none.Label",0);
393   popupVerb[1] = resource_getResource(db,app_class,app_name, "gs.errors.errors.Label",0);
394   popupVerb[2] = resource_getResource(db,app_class,app_name, "gs.errors.all.Label",0);
395 
396   confirm_quit_styles[0] = resource_getResource(db,app_class,app_name, "quitstyle.never.Label",0);
397   confirm_quit_styles[1] = resource_getResource(db,app_class,app_name, "quitstyle.whenprocessing.Label",0);
398   confirm_quit_styles[2] = resource_getResource(db,app_class,app_name, "quitstyle.always.Label",0);
399 
400   title_styles[0] = resource_getResource(db,app_class,app_name, "title.notitle.Label",0);
401   title_styles[1] = resource_getResource(db,app_class,app_name, "title.documenttitle.Label",0);
402   title_styles[2] = resource_getResource(db,app_class,app_name, "title.filename.Label",0);
403 
404   automaticLabel = resource_getResource(db,app_class,app_name, "automatic.Label",0);
405   saveCurrentPageLabel = resource_getResource(db,app_class,app_name, "strings.saveCurrentPage",0);
406   saveMarkedPagesLabel = resource_getResource(db,app_class,app_name, "strings.saveMarkedPages",0);
407   saveDocumentLabel = resource_getResource(db,app_class,app_name, "strings.saveDocument",0);
408   saveAsPDFLabel = resource_getResource(db,app_class,app_name, "strings.saveAsPDF",0);
409   openFileLabel = resource_getResource(db,app_class,app_name, "strings.openFile",0);
410   passwordPromptLabel = resource_getResource(db,app_class,app_name, "strings.passwordPrompt",0);
411   passwordRequiredLabel = resource_getResource(db,app_class,app_name, "strings.passwordRequired",0);
412   quitConfirmLabel = resource_getResource(db,app_class,app_name, "strings.quitConfirm",0);
413   putTexCommandLabel = resource_getResource(db,app_class,app_name, "strings.putTexCommand",0);
414   texCommandLabel = resource_getResource(db,app_class,app_name, "strings.texCommand",0);
415   stillInProgressLabel = resource_getResource(db,app_class,app_name, "strings.stillInProgress",0);
416   execOfFailedLabel = resource_getResource(db,app_class,app_name, "strings.execOfFailed",0);
417   copyrightTranslationLabel = resource_getResource(db,app_class,app_name, "strings.copyrightTranslation",0);
418 
419   /* ### command line resources ################# */
420 
421   /*
422    * When managing --[no]feature options, please put the
423    * --nofeature management _after_ the --feature one.
424    *
425    * -jemarch
426    */
427 
428   if (antialias_p)
429     {
430       resource_putResource (&db, app_name, ".antialias", "True");
431     }
432   if (noantialias_p)
433     {
434       resource_putResource (&db, app_name, ".antialias", "False");
435     }
436   if (safer_p)
437     {
438       resource_putResource (&db, app_name, ".gsSafer", "True");
439     }
440   if (nosafer_p)
441     {
442       resource_putResource (&db, app_name, ".gsSafer", "False");
443     }
444   if (safedir_p)
445     {
446       resource_putResource (&db, app_name, ".gsSafeDir", "True");
447     }
448   if (nosafedir_p)
449     {
450       resource_putResource (&db, app_name, ".gsSafeDir", "False");
451     }
452   if (pixmap_p)
453     {
454       resource_putResource (&db, app_name, ".useBackingPixmap", "True");
455     }
456   if (nopixmap_p)
457     {
458       resource_putResource (&db, app_name, ".useBackingPixmap", "False");
459     }
460   if (color_p)
461     {
462       resource_putResource (&db, app_name, "*Ghostview.palette", "Color");
463     }
464   if (grayscale_p)
465     {
466       resource_putResource (&db, app_name, "*Ghostview.palette", "Grayscale");
467     }
468   if (spartan_p)
469     {
470       char *spartan_filename = (char *)
471 	XtMalloc (strlen(GV_LIBDIR) + strlen ("/gv_spartan.dat") + 1);
472       spartan_filename[0] = '\0';
473       strcat(spartan_filename, GV_LIBDIR);
474       strcat(spartan_filename, "/gv_spartan.dat");
475       resource_putResource (&db, app_name, ".style", spartan_filename);
476       XtFree (spartan_filename);
477     }
478   if (widgetless_p)
479     {
480       char *widgetless_filename = (char *)
481 	XtMalloc (strlen(GV_LIBDIR) + strlen ("/gv_widgetless.dat") + 1);
482       widgetless_filename[0] = '\0';
483       strcat(widgetless_filename, GV_LIBDIR);
484       strcat(widgetless_filename, "/gv_widgetless.dat");
485       resource_putResource (&db, app_name, ".style", widgetless_filename);
486       XtFree (widgetless_filename);
487     }
488   if (quiet_p)
489     {
490       resource_putResource (&db, app_name, ".gsQuiet", "True");
491     }
492   if (infoverbose_p != -1)
493     {
494       if (infoverbose_p == 0) resource_putResource (&db, app_name, ".infoVerbose", "Silent");
495       if (infoverbose_p == 1) resource_putResource (&db, app_name, ".infoVerbose", "Errors");
496       if (infoverbose_p == 2) resource_putResource (&db, app_name, ".infoVerbose", "All");
497     }
498   if (monochrome_p)
499     {
500       resource_putResource (&db, app_name, "*Ghostview.palette", "Monochrome");
501     }
502   if (noquiet_p)
503     {
504       resource_putResource (&db, app_name, ".gsQuiet", "False");
505     }
506    if (media_p)
507      {
508        resource_putResource (&db, app_name, ".pageMedia", media_value);
509      }
510    if (orientation_p)
511      {
512        resource_putResource (&db, app_name, ".orientation", orientation_value);
513      }
514    if (page_p)
515      {
516        resource_putResource (&db, app_name, ".page", page_value);
517      }
518 
519    if (center_p)
520      {
521        resource_putResource (&db, app_name, ".autoCenter", "True");
522      }
523    if (nocenter_p)
524      {
525        resource_putResource (&db, app_name, ".autoCenter", "False");
526      }
527    if (scale_p)
528      {
529        resource_putResource (&db, app_name, ".scale", scale_value);
530      }
531    if (magstep_p)
532      {
533        resource_putResource (&db, app_name, ".scale", magstep_value);
534      }
535    if (scalebase_p)
536      {
537        resource_putResource (&db, app_name, ".scaleBase", scalebase_value);
538      }
539    if (resize_p)
540      {
541        resource_putResource (&db, app_name, ".autoResize", "True");
542      }
543    if (noresize_p)
544      {
545        resource_putResource (&db, app_name, ".autoResize", "False");
546      }
547    if (swap_p)
548      {
549        resource_putResource (&db, app_name, ".swapLandscape", "True");
550      }
551    if (noswap_p)
552      {
553        resource_putResource (&db, app_name, ".swapLandscape", "False");
554      }
555    if (dsc_p)
556      {
557        resource_putResource (&db, app_name, ".respectDSC", "True");
558      }
559    if (nodsc_p)
560      {
561        resource_putResource (&db, app_name, ".respectDSC", "False");
562      }
563    if (eof_p)
564      {
565        resource_putResource (&db, app_name, ".ignoreEOF", "True");
566      }
567    if (noeof_p)
568      {
569        resource_putResource (&db, app_name, ".ignoreEOF", "False");
570      }
571    if (watch_p)
572      {
573        resource_putResource (&db, app_name, ".watchFile", "True");
574      }
575    if (nowatch_p)
576      {
577        resource_putResource (&db, app_name, ".watchFile", "False");
578      }
579    if (ad_p)
580      {
581        resource_putResource (&db, app_name, ".ad", ad_value);
582      }
583    if (style_p)
584      {
585        resource_putResource (&db, app_name, ".style", style_value);
586      }
587    if (arguments_p)
588      {
589        resource_putResource (&db, app_name, ".arguments", arguments_value);
590      }
591 
592   /* ### style resources ######################## */
593   INFMESSAGE(checking for style resources)
594     s = resource_getResource(db,app_class,app_name,"style","Style");
595   if (s) {
596     t=NULL;
597 #   ifdef USE_FALLBACK_STYLES
598     sP = NULL;
599 #     ifdef FALLBACK_STYLE_1_DAT
600     if (!strcmp(GV_LIBDIR "/" FALLBACK_STYLE_1_DAT,s)) sP = fallback_style_1;
601     if (!strcmp(FALLBACK_STYLE_1_DAT,s)) sP = fallback_style_1;
602 #     endif
603 #     ifdef FALLBACK_STYLE_2_DAT
604     if (!strcmp(GV_LIBDIR "/" FALLBACK_STYLE_2_DAT,s)) sP = fallback_style_2;
605     if (!strcmp(FALLBACK_STYLE_2_DAT,s)) sP = fallback_style_2;
606 #     endif
607 #     ifdef FALLBACK_STYLE_3_DAT
608     if (!strcmp(GV_LIBDIR "/" FALLBACK_STYLE_3_DAT,s)) sP = fallback_style_3;
609     if (!strcmp(FALLBACK_STYLE_3_DAT,s)) sP = fallback_style_3;
610 #     endif
611     if (sP) {
612       INFMESSAGE(merging fallback style resources into database)
613 	while (*sP) XrmPutLineResource(&db,*sP++);
614       s = NULL;
615     } else {
616       INFSMESSAGE(merging style resource file into database,s)
617         t = resource_mergeFileIntoDatabase(&db,s);
618       if (!t) {
619 	fprintf(stderr,"%s: Style file '%s' not found - ignored\n",app_name,s);
620 	s=NULL;
621       } else s = t;
622     }
623 #   else
624 
625     /*
626      * Do not use fallback styles
627      *
628      */
629 
630     INFSMESSAGE(merging style resource file into database,s)
631       t = resource_mergeFileIntoDatabase(&db,s);
632     if (!t) {
633       fprintf(stderr,"%s: Style file '%s' not found - ignored\n",app_name,s);
634       s=NULL;
635     } else s = t;
636 #   endif
637     if (s) {
638       s = XtNewString(s);
639       resource_style_file = s;
640     }
641     XtFree(t);
642   }
643 
644   /* ### ad resources ######################## */
645   INFMESSAGE(checking for ad resources)
646     s = resource_getResource(db,app_class,app_name,"ad","Ad");
647   if (s) {
648     INFSMESSAGE(merging ad resource file into database,s)
649       t = resource_mergeFileIntoDatabase(&db,s);
650     if (!t) {
651       fprintf(stderr,"%s: ad file '%s' not found - ignored\n",app_name,s);
652       s=NULL;
653     } else s = t;
654     if (s) {
655       s = XtNewString(s);
656       resource_ad_file = s;
657     }
658     XtFree(t);
659   }
660 
661   ENDMESSAGE(resource_buildDatabase)
662   return (db);
663 }
664 
665 /*#######################################################
666   resource_putResource
667   #######################################################*/
668 
669 void
resource_putResource(XrmDatabase * db,char * app_name,char * resource_class,char * resource_value)670 resource_putResource (XrmDatabase *db,
671 		      char *app_name,
672 		      char *resource_class,
673 		      char *resource_value)
674 {
675   char resource_name[GV_MAX_FILENAME_LENGTH];
676 
677   sprintf(resource_name, "%s%s", app_name, resource_class);
678   XrmPutStringResource (db,
679 			resource_name,
680 			resource_value);
681 
682 }
683 
684 /*#######################################################
685   resource_getResource
686   #######################################################*/
687 
resource_getResource(db,app_class,app_name,name_val,class_val)688 char *resource_getResource(db,app_class,app_name,name_val,class_val)
689      XrmDatabase db;
690      char *app_class;
691      char *app_name;
692      char *name_val;
693      char *class_val;
694 {
695   char *result=NULL;
696   XrmValue rm_value;
697   String str_type;
698   char str_name[GV_MAX_FILENAME_LENGTH],str_class[GV_MAX_FILENAME_LENGTH];
699   Bool success=False;
700 
701   BEGINMESSAGE(resource_getResource)
702     if (!class_val) class_val=name_val;
703   sprintf(str_name, "%s.%s",app_name,name_val);
704   sprintf(str_class,"%s.%s",app_class,class_val);
705   INFSMESSAGE(looking for,str_class)
706     success = XrmGetResource(db,str_name,str_class,&str_type,&rm_value);
707   if  (success && rm_value.size>1) { result = (char*) rm_value.addr; INFSMESSAGE(found entry,result) }
708   else                             { result = NULL;                  INFMESSAGE(no entry found)      }
709   ENDMESSAGE(resource_getResource)
710     return(result);
711 }
712 
713 /*#######################################################
714   resource_checkGeometryResource
715   #######################################################*/
716 
717 #ifdef max
718 #   undef max
719 #endif
720 #define max(a,b) ((a)>(b)?(a):(b))
721 
resource_checkGeometryResource(dbP,app_class,app_name)722 int resource_checkGeometryResource(dbP,app_class,app_name)
723      XrmDatabase *dbP;
724      char *app_class;
725      char *app_name;
726 {
727   char tmp[GV_MAX_FILENAME_LENGTH];
728   char *pos;
729   int gx=0,gy=0;
730   int flag;
731   int dim_forced=0;
732   char g[20];
733   unsigned int gwidth=0,gheight=0;
734 
735   BEGINMESSAGE(resource_checkGeometryResource)
736     pos = resource_getResource(*dbP,app_class,app_name,"geometry","Geometry");
737   if (!pos) {
738     ENDMESSAGE(resource_checkGeometryResource)
739       return(dim_forced);
740   }
741   INFSMESSAGE(found geometry resource,pos)
742     flag=XParseGeometry(pos,&gx,&gy,&gwidth,&gheight);
743   IIMESSAGE(gx,gy) IIMESSAGE(gwidth,gheight)
744     if (gwidth)  gwidth   = max(gwidth,GV_MINIMUM_SIZE);
745   if (gheight) gheight  = max(gheight,GV_MINIMUM_SIZE);
746   tmp[0]='\0';
747   if (flag&WidthValue) {
748     sprintf(g,"%d",(Dimension)gwidth); strcat(tmp,g);
749     dim_forced=1;
750   }
751   if (flag&HeightValue) {
752     sprintf(g,"x%d",(Dimension)gheight); strcat(tmp,g);
753     dim_forced=1;
754   }
755   if (flag&XValue) {
756     sprintf(g,"%s%d",((flag&XNegative) ? (gx ? "":"-") : "+"),gx);   strcat(tmp,g);
757   }
758   if (flag&YValue) {
759     sprintf(g,"%s%d",((flag&YNegative) ? (gy ? "":"-") : "+"),gy);   strcat(tmp,g);
760   }
761   if (tmp[0]) {
762     char s[50];
763     INFSMESSAGE(corrected geometry,tmp)
764       sprintf(s,"%s.geometry",app_name);
765     SMESSAGE(s) SMESSAGE(tmp)
766       XrmPutStringResource(dbP,s,tmp);
767 #   ifdef MESSAGES
768     pos = resource_getResource(*dbP,app_class,app_name,"geometry","Geometry");
769     if (pos) { INFSMESSAGE(check:,pos) }
770 #   endif
771   }
772   ENDMESSAGE(resource_checkGeometryResource)
773     return(dim_forced);
774 }
775 
776 /*#######################################################
777   resource_checkResources
778   #######################################################*/
779 
resource_checkResources(app_name,v,vc)780 int resource_checkResources(app_name,v,vc)
781      char *app_name;
782      char *v;
783      char *vc;
784 {
785   int n,nc,v1,v2,v3,v4,v1c,v2c,v3c,v4c,r=1;
786 
787   BEGINMESSAGE(resource_checkResources)
788     v1 = v2 = v3 = v4 = v1c = v2c = v3c = v4c = 0;
789   n  = sscanf(v,"%*s %d.%d.%d.%d",&v1,&v2,&v3,&v4);
790   nc = sscanf(vc,"%*s %d.%d.%d.%d",&v1c,&v2c,&v3c,&v4c);
791   if ((n < 2) || (nc < 2)
792       || (v1 < v1c)
793       || (v1 == v1c && v2 < v2c)
794       || (v1 == v1c && v2 == v2c && v3 < v3c)
795       || (v1 == v1c && v2 == v2c && v3 == v3c && v4 < v4c)) {
796     fprintf(stderr,"%s Error: incompatible resources.\n",app_name);
797     fprintf(stderr,"One of the files\n");
798     if (resource_system_file) fprintf(stderr,"    %s\n",resource_system_file);
799     if (resource_user_file)   fprintf(stderr,"    %s\n",resource_user_file);
800     if (resource_style_file)  fprintf(stderr,"    %s\n",resource_style_file);
801     if (resource_ad_file)     fprintf(stderr,"    %s\n",resource_ad_file);
802     fprintf(stderr,"belongs to an older version of gv and cannot be used.\n");
803     if (resource_user_file) fprintf(stderr,"Quite probably your %s is too old.\n", resource_user_file_symb);
804     if (resource_user_file) {
805        if (haveXUSERFILESEARCHPATH)
806        {
807           if (access(resource_user_file, W_OK))
808 	  {
809              fprintf(stderr, "For a correct installation the following restrictions must be met:\n\n");
810 	     fprintf(stderr, "* Every directory contained in XUSERFILESEARCHPATH where the system also\nsearches for app-defaults does not contain a file 'GV'.\n\n");
811 
812 	     fprintf(stderr, "* GV is contained just in direectories of XUSERFILESEARCHPATH where the system\ndoes not search for app-defaults, and the GV.version resource is contained in\nthis GV file (this file is used instead of ~/.gv if ~/.gv is not present).\n\n");
813 
814 	     fprintf(stderr, "* The systems app-defaults directories which are not comntained in\nXUSERFILESEARCHPATH may contain a GV file.If so, it SHOULD not contain a\n'GV.version' resource.\n\n");
815 
816 	     fprintf(stderr, "If necessary, ask your system administrator for assistence.\n\n");
817 
818 	     fprintf(stderr,"A workaround to make GNU gv working is\nto provide ~/.gv by running 'touch ~/.gv && gv-update-userconfig'.\n");
819 
820           }
821 	  else
822 	  {
823              fprintf(stderr,"Please remove or update the outdated file.\n");
824              fprintf(stderr,"Running gv-update-userconfig %s should help\nby removing all incompatible resources.\n", resource_user_file);
825 
826              fprintf(stderr,"Another option that non-admins can do to make GNU gv working is\nto provide ~/.gv by running 'touch ~/.gv && gv-update-userconfig'.\n");
827 
828           }
829        }
830        else
831        {
832           fprintf(stderr,"Please remove or update the outdated file.\n");
833           fprintf(stderr,"Running gv-update-userconfig should help\nby removing all incompatible resources.\n");
834        }
835     }
836     r=0;
837   }
838   ENDMESSAGE(resource_checkResources)
839     return(r);
840 }
841 
842 
843 /*#######################################################
844   resource_userResourceFile()
845   #######################################################*/
846 
resource_userDefaultsFile()847 char *resource_userDefaultsFile()
848 {
849   char *s;
850   BEGINMESSAGE(resource_userResourceFile)
851     if      (resource_ad_file)   s = resource_ad_file;
852     else if (resource_user_file) s = resource_user_file;
853     else                         s = USER_DEFAULTS;
854   s = XtNewString(s);
855   return(s);
856   ENDMESSAGE(resource_userResourceFile)
857     }
858 
859 
860 /*---------------------------------------------------------------
861   resource_mergeFileIntoDatabase
862   ---------------------------------------------------------------*/
863 
resource_mergeFileIntoDatabase(dbP,name)864 static char* resource_mergeFileIntoDatabase(dbP,name)
865      XrmDatabase *dbP;
866      char *name;
867 {
868   char tmp[GV_MAX_FILENAME_LENGTH];
869 
870   BEGINMESSAGE(resource_mergeFileIntoDatabase)
871 
872     if (!name) {
873       ENDMESSAGE(resource_mergeFileIntoDatabase)
874 	return(name);
875     }
876 
877   strcpy(tmp,name);
878   file_translateTildeInPath(tmp, sizeof(tmp));
879 
880   if (tmp[0] != '/') {
881     fprintf(stderr, "Ignoring resource file '%s'='%s' as no absolute path!\n",
882 		    name, tmp);
883     name = NULL;
884   } else if (file_fileIsNotUseful(tmp)) {
885     INFSMESSAGE(not useful,tmp)
886     name = NULL;
887   } else {
888     INFSMESSAGE(merging,tmp)
889       XrmCombineFileDatabase(tmp,dbP,True);
890     name = XtNewString(tmp);
891   }
892   ENDMESSAGE(resource_mergeFileIntoDatabase)
893     return(name);
894 }
895 
896 String automaticLabel;
897 String saveCurrentPageLabel;
898 String saveMarkedPagesLabel;
899 String saveDocumentLabel;
900 String saveAsPDFLabel;
901 String openFileLabel;
902 String passwordPromptLabel;
903 String passwordRequiredLabel;
904 String quitConfirmLabel;
905 String putTexCommandLabel, texCommandLabel;
906 String stillInProgressLabel;
907 String execOfFailedLabel;
908 String copyrightTranslationLabel;
909