home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / strings.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.4 KB  |  165 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #define RESOURCE_STR
  20. #include "xfe_err.h"
  21.  
  22. #include "mozilla.h"
  23. #include "xfe.h"
  24.  
  25.  
  26. char *XP_GetBuiltinString(int16 i);
  27.  
  28.  
  29. static XrmDatabase    database;
  30.  
  31.  
  32. char *
  33. XP_GetString(int16 i)
  34. {
  35.     static char    buf[128];
  36.     static char    class[128];
  37.     char        *ret;
  38.     char        *type;
  39.     XrmValue    value;
  40.  
  41. #ifdef notdef
  42.     char        *file;
  43.     if (!database)
  44.     {
  45.         char    *path;
  46.         Boolean    deallocate = False;
  47.  
  48.         database = XrmGetStringDatabase("");
  49.  
  50.         if (!(path = getenv("XUSERFILESEARCHPATH")))
  51.         {
  52.             char    *old_path;
  53.             char    *homedir;
  54.  
  55.             homedir = getenv("HOME");
  56.             if (!homedir)
  57.             {
  58.                 homedir = "/";
  59.             }
  60.             if (!(old_path = getenv("XAPPLRESDIR")))
  61.             {
  62.                 char *path_default =
  63.                     "%s/%%L/%%N%%C%%S"
  64.                     ":%s/%%l/%%N%%C%%S"
  65.                     ":%s/%%N%%C%%S"
  66.                     ":%s/%%L/%%N%%S"
  67.                     ":%s/%%l/%%N%%S"
  68.                     ":%s/%%N%%S";
  69.  
  70.                 if (!(path = malloc(6*strlen(homedir) +
  71.                     strlen(path_default))))
  72.                 {
  73.                     _XtAllocError(NULL);
  74.                 }
  75.                 (void) PR_snprintf(path, sizeof (path),
  76.                            path_default, homedir,
  77.                            homedir, homedir, homedir,
  78.                            homedir, homedir);
  79.             }
  80.             else
  81.             {
  82.                 char *path_default =
  83.                     "%s/%%L/%%N%%C%%S"
  84.                     ":%s/%%l/%%N%%C%%S"
  85.                     ":%s/%%N%%C%%S"
  86.                     ":%s/%%N%%C%%S"
  87.                     ":%s/%%L/%%N%%S"
  88.                     ":%s/%%l/%%N%%S"
  89.                     ":%s/%%N%%S"
  90.                     ":%s/%%N%%S";
  91.  
  92.                 if (!(path = malloc( 6*strlen(old_path) +
  93.                     2*strlen(homedir) + strlen(path_default))))
  94.                 {
  95.                     _XtAllocError(NULL);
  96.                 }
  97.                 (void) PR_snprintf(path, sizeof (path),
  98.                            path_default, old_path,
  99.                            old_path, old_path,
  100.                            homedir, old_path, old_path,
  101.                            old_path, homedir );
  102.             }
  103.             deallocate = True;
  104.         }
  105.  
  106.         file = (char *) XtResolvePathname
  107.         (
  108.             fe_display,
  109.             NULL,
  110.             NULL,
  111.             ".dat",
  112.             path,
  113.             NULL,
  114.             0,
  115.             NULL
  116.         );
  117.         if (file)
  118.         {
  119.             (void) XrmCombineFileDatabase(file, &database, False);
  120.             XtFree(file);
  121.         }
  122.  
  123.         if (deallocate)
  124.         {
  125.             free(path);
  126.         }
  127.  
  128.  
  129.         file = (char *) XtResolvePathname
  130.         (
  131.             fe_display,
  132.             "app-defaults",
  133.             NULL,
  134.             ".dat",
  135.             NULL,
  136.             NULL,
  137.             0,
  138.             NULL
  139.         );
  140.         if (file)
  141.         {
  142.             (void) XrmCombineFileDatabase(file, &database, False);
  143.             XtFree(file);
  144.         }
  145.     }
  146. #endif /* notdef */
  147.  
  148.     (void) PR_snprintf(buf, sizeof (buf),
  149.             "%s.strings.%d", fe_progclass, i + RES_OFFSET);
  150.     (void) PR_snprintf(class, sizeof (class), 
  151.             "%s.Strings.Number", fe_progclass);
  152.     if (fe_display && ((database = XtDatabase(fe_display))) &&
  153.         XrmGetResource(database, buf, class, &type, &value))
  154.     {
  155.         return value.addr;
  156.     }
  157.  
  158.     if ((ret = mcom_cmd_xfe_xfe_err_h_strings (i + RES_OFFSET)))
  159.     {
  160.         return ret;
  161.     }
  162.  
  163.     return XP_GetBuiltinString(i);
  164. }
  165.