/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* AT&T Research and SCO
* ast l10n message translation
*/
#include "lclib.h"
#include <cdt.h>
#include <error.h>
#include <mc.h>
#include <nl_types.h>
#ifndef DEBUG_trace
#define DEBUG_trace 0
#endif
typedef struct
{
} Catalog_t;
typedef struct
{
} Message_t;
typedef struct
{
} Temp_t;
typedef struct
{
} State_t;
{
};
static int
{
}
static char*
{
}
/*
* add msg to dict
*/
static int
{
return 0;
{
return 0;
}
#if DEBUG_trace > 1
#endif
return 1;
}
/*
* find catalog in locale and return catopen() descriptor
*/
static nl_catd
{
char* o;
nl_catd d;
if (!mcfind(locale, catalog, LC_MESSAGES, 0, path, sizeof(path)) || (d = catopen(path, NL_CAT_LOCALE)) == NOCAT)
{
o = 0;
{
}
if (o)
{
setlocale(LC_MESSAGES, o);
}
}
return d;
}
/*
* initialize the catalog s by loading in the default locale messages
*/
static Catalog_t*
init(register char* s)
{
register int n;
register int m;
register int set;
nl_catd d;
/*
* insert into the catalog dictionary
*/
return 0;
{
return 0;
}
/*
* locate the default locale catalog
*/
{
/*
* load the default locale messages
* this assumes one mesage set for ast (AST_MESSAGE_SET or fallback to 1)
* different packages can share the same message catalog
* name by using different message set numbers
* see <mc.h> mcindex()
*
* this method requires a scan of each catalog, and the
* catalogs do not advertise the max message number, so
* we assume there are no messages after a gap of GAP
* missing messages
*/
{
n = m = 0;
for (;;)
{
n++;
if (((s = catgets(d, set = AST_MESSAGE_SET, n, state.null)) && *s || (s = catgets(d, set = 1, n, state.null)) && *s) && entry(cp->messages, set, n, s))
m = n;
else if ((n - m) > GAP)
break;
}
if (!m)
{
}
}
catclose(d);
}
return cp;
}
/*
* return the C locale message pointer for msg in cat
* cat may be a : separated list of candidate names
*/
static Message_t*
{
register char* s;
register char* t;
size_t n;
s = (char*)cat;
for (;;)
{
if (t = strchr(s, ':'))
{
if (s == (char*)cat)
{
n = sizeof(buf) - 1;
s[n] = 0;
t = strchr(s, ':');
}
*t = 0;
}
if (*s && ((cp = (Catalog_t*)dtmatch(state.catalogs, s)) || (cp = init(s))) && cp->messages && (mp = (Message_t*)dtmatch(cp->messages, msg)))
{
return mp;
}
if (!t)
break;
s = t + 1;
}
return 0;
}
/*
* translate() is called with four arguments:
*
* loc the LC_MESSAGES locale name
* cmd the calling command name
* cat the catalog name, possibly a : separated list
* "libFOO" FOO library messages
* "libshell" ksh command messages
* "SCRIPT" script SCRIPT application messages
* msg message text to be translated
*
* the translated message text is returned on success
* otherwise the original msg is returned
*
* The first time translate() is called (for a non-C locale)
* it creates the state.catalogs dictionary. A dictionary entry
* (Catalog_t) is made each time translate() is called with a new
* cmd:cat argument.
*
* message. Its arguments include the message catalog name
* dictionary, with entries of type Message_t, is needed for
* needed by catgets(). A separate Message_t dictionary is maintained
* for each Catalog_t.
*/
char*
{
register char* r;
char* t;
int p;
int oerrno;
static char* nlspath;
r = (char*)msg;
/*
* quick out
*/
goto done;
cmd = (const char*)(t + 1);
/*
* initialize the catalogs dictionary
*/
{
goto done;
{
goto done;
}
{
goto done;
}
}
/*
* get the message
* or do we have to spell it out for you
*/
{
#if DEBUG_trace > 1
sfprintf(sfstderr, "AHA#%d:%s cmd %s cat %s:%s id %s msg `%s'\n", __LINE__, __FILE__, cmd, cat, error_info.catalog, ast.id, msg);
#endif
cp = 0;
goto done;
}
/*
* adjust for the current locale
*/
#if DEBUG_trace
sfprintf(sfstderr, "AHA#%d:%s cp->locale `%s' %p loc `%s' %p\n", __LINE__, __FILE__, cp->locale, cp->locale, loc, loc);
#endif
{
}
{
else
#if DEBUG_trace
sfprintf(sfstderr, "AHA#%d:%s cp->cat %p cp->debug %d NOCAT %p\n", __LINE__, __FILE__, cp->cat, cp->debug, NOCAT);
#endif
}
{
{
}
{
}
}
else
{
/*
* get the translated message
*/
if (r != (char*)msg)
{
r = (char*)msg;
{
sfprintf(sfstderr, "locale %s catalog %s message %d.%d \"%s\" does not match \"%s\"\n", cp->locale, cp->name, mp->set, mp->seq, r, msg);
r = (char*)msg;
}
}
{
}
}
sfprintf(sfstderr, "translate locale=%s catalog=%s set=%d seq=%d \"%s\" => \"%s\"\n", cp->locale, cp->name, mp->set, mp->seq, msg, r == (char*)msg ? "NOPE" : r);
done:
{
}
return r;
}