Back to index

plt-scheme  4.2.1
Functions | Variables
cat-compat.c File Reference
#include <stdio.h>
#include "libgettext.h"

Go to the source code of this file.

Functions

char * getenv ()
static int msg_to_cat_id PARAMS ((const char *msg))
static char *stpcpy PARAMS ((char *dest, const char *src))
char * textdomain (char *domainname) const
char * bindtextdomain (char *domainname, const char *dirname) const
char * gettext (char *msg) const
static int msg_to_cat_id (char *msg) const
static char * stpcpy (char *dest, const char *src)

Variables

static nl_catd catalog = (nl_catd) -1
static const char default_catalog_name [] = "messages"
static const char * catalog_name = default_catalog_name

Function Documentation

char* bindtextdomain ( char *  domainname,
const char *  dirname 
) const

Definition at line 131 of file cat-compat.c.

{
#if HAVE_SETENV || HAVE_PUTENV
  char *old_val, *new_val, *cp;
  size_t new_val_len;

  /* This does not make much sense here but to be compatible do it.  */
  if (domainname == NULL)
    return NULL;

  /* Compute length of added path element.  If we use setenv we don't need
     the first byts for NLSPATH=, but why complicate the code for this
     peanuts.  */
  new_val_len = sizeof ("NLSPATH=") - 1 + strlen (dirname)
              + sizeof ("/%L/LC_MESSAGES/%N.cat");

  old_val = getenv ("NLSPATH");
  if (old_val == NULL || old_val[0] == '\0')
    {
      old_val = NULL;
      new_val_len += 1 + sizeof (LOCALEDIR) - 1
                    + sizeof ("/%L/LC_MESSAGES/%N.cat");
    }
  else
    new_val_len += strlen (old_val);

  new_val = (char *) malloc (new_val_len);
  if (new_val == NULL)
    return NULL;

# if HAVE_SETENV
  cp = new_val;
# else
  cp = stpcpy (new_val, "NLSPATH=");
# endif

  cp = stpcpy (cp, dirname);
  cp = stpcpy (cp, "/%L/LC_MESSAGES/%N.cat:");

  if (old_val == NULL)
    {
# if __STDC__
      stpcpy (cp, LOCALEDIR "/%L/LC_MESSAGES/%N.cat");
# else

      cp = stpcpy (cp, LOCALEDIR);
      stpcpy (cp, "/%L/LC_MESSAGES/%N.cat");
# endif
    }
  else
    stpcpy (cp, old_val);

# if HAVE_SETENV
  setenv ("NLSPATH", new_val, 1);
  free (new_val);
# else
  putenv (new_val);
  /* Do *not* free the environment entry we just entered.  It is used
     from now on.   */
# endif

#endif

  return (char *) domainname;
}

Here is the call graph for this function:

char* getenv ( )

Here is the caller graph for this function:

char* gettext ( char *  msg) const

Definition at line 201 of file cat-compat.c.

{
  int msgid;

  if (msg == NULL || catalog == (nl_catd) -1)
    return (char *) msg;

  /* Get the message from the catalog.  We always use set number 1.
     The message ID is computed by the function `msg_to_cat_id'
     which works on the table generated by `po-to-tbl'.  */
  msgid = msg_to_cat_id (msg);
  if (msgid == -1)
    return (char *) msg;

  return catgets (catalog, 1, msgid, (char *) msg);
}

Here is the call graph for this function:

static int msg_to_cat_id ( char *  msg) const [static]

Definition at line 223 of file cat-compat.c.

{
  int cnt;

  for (cnt = 0; cnt < _msg_tbl_length; ++cnt)
    if (strcmp (msg, _msg_tbl[cnt]._msg) == 0)
      return _msg_tbl[cnt]._msg_number;

  return -1;
}

Here is the caller graph for this function:

static int msg_to_cat_id PARAMS ( (const char *msg)  ) [static]
static char* stpcpy PARAMS ( (char *dest, const char *src ) [static]
static char* stpcpy ( char *  dest,
const char *  src 
) [static]

Definition at line 244 of file cat-compat.c.

{
  while ((*dest++ = *src++) != '\0')
    /* Do nothing. */ ;
  return dest - 1;
}

Here is the caller graph for this function:

char* textdomain ( char *  domainname) const

Definition at line 63 of file cat-compat.c.

{
  nl_catd new_catalog;
  char *new_name;
  size_t new_name_len;
  char *lang;

#if HAVE_SETLOCALE && HAVE_LC_MESSAGES && HAVE_SETLOCALE_NULL
  lang = setlocale (LC_MESSAGES, NULL);
#else
  lang = getenv ("LC_ALL");
  if (lang == NULL || lang[0] == '\0')
    {
      lang = getenv ("LC_MESSAGES");
      if (lang == NULL || lang[0] == '\0')
       lang = getenv ("LANG");
    }
#endif
  if (lang == NULL || lang[0] == '\0')
    lang = "C";

  /* See whether name of currently used domain is asked.  */
  if (domainname == NULL)
    return (char *) catalog_name;

  if (domainname[0] == '\0')
    domainname = default_catalog_name;

  /* Compute length of added path element.  */
  new_name_len = sizeof (LOCALEDIR) - 1 + 1 + strlen (lang)
               + sizeof ("/LC_MESSAGES/") - 1 + sizeof (PACKAGE) - 1
               + sizeof (".cat");

  new_name = (char *) malloc (new_name_len);
  if (new_name == NULL)
    return NULL;

  strcpy (new_name, PACKAGE);
  new_catalog = catopen (new_name, 0);

  if (new_catalog == (nl_catd) -1)
    {
      /* NLSPATH search didn't work, try absolute path */
      sprintf (new_name, "%s/%s/LC_MESSAGES/%s.cat", LOCALEDIR, lang,
              PACKAGE);
      new_catalog = catopen (new_name, 0);

      if (new_catalog == (nl_catd) -1)
       {
         free (new_name);
         return (char *) catalog_name;
       }
    }

  /* Close old catalog.  */
  if (catalog != (nl_catd) -1)
    catclose (catalog);
  if (catalog_name != default_catalog_name)
    free ((char *) catalog_name);

  catalog = new_catalog;
  catalog_name = new_name;

  return (char *) catalog_name;
}

Here is the call graph for this function:


Variable Documentation

nl_catd catalog = (nl_catd) -1 [static]

Definition at line 44 of file cat-compat.c.

Definition at line 50 of file cat-compat.c.

const char default_catalog_name[] = "messages" [static]

Definition at line 47 of file cat-compat.c.