1995-03-30 12:47:27 +00:00
|
|
|
/***********************************************************
|
|
|
|
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
|
|
|
provided that the above copyright notice appear in all copies and that
|
|
|
|
both that copyright notice and this permission notice appear in
|
|
|
|
supporting documentation, and that Alfalfa's name not be used in
|
|
|
|
advertising or publicity pertaining to distribution of the software
|
|
|
|
without specific, written prior permission.
|
|
|
|
|
|
|
|
ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
If you make any modifications, bugfixes or other changes to this software
|
|
|
|
we'd appreciate it if you could send a copy to us so we can keep things
|
|
|
|
up-to-date. Many thanks.
|
|
|
|
Kee Hinckley
|
|
|
|
Alfalfa Software, Inc.
|
|
|
|
267 Allston St., #3
|
|
|
|
Cambridge, MA 02139 USA
|
|
|
|
nazgul@alfalfa.com
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-03-30 12:47:27 +00:00
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2001-08-13 14:06:34 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$FreeBSD$";
|
1995-03-30 12:47:27 +00:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need a better way of handling errors than printing text. I need
|
|
|
|
* to add an error handling routine.
|
|
|
|
*/
|
|
|
|
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "namespace.h"
|
1995-03-30 12:47:27 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2000-09-01 12:19:00 +00:00
|
|
|
#include <sys/syslimits.h>
|
1998-07-14 18:27:43 +00:00
|
|
|
#include <errno.h>
|
1995-03-30 12:47:27 +00:00
|
|
|
#include <fcntl.h>
|
1998-04-30 11:06:12 +00:00
|
|
|
#include <locale.h>
|
2000-09-01 12:19:00 +00:00
|
|
|
#include <nl_types.h>
|
1995-03-30 12:47:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "un-namespace.h"
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2000-09-01 12:19:00 +00:00
|
|
|
#include "msgcat.h"
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
#define _DEFAULT_NLS_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L"
|
|
|
|
|
|
|
|
#define TRUE 1
|
|
|
|
#define FALSE 0
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
#define NLERR ((nl_catd) -1)
|
|
|
|
#define NLRETERR(errc) errno = errc; return(NLERR);
|
1995-03-30 12:47:27 +00:00
|
|
|
|
|
|
|
static nl_catd loadCat();
|
1998-04-30 10:14:55 +00:00
|
|
|
static int loadSet();
|
2000-09-04 12:09:40 +00:00
|
|
|
static void __nls_free_resources();
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
nl_catd
|
|
|
|
catopen( name, type)
|
|
|
|
__const char *name;
|
|
|
|
int type;
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
2000-09-04 12:09:40 +00:00
|
|
|
int spcleft;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char *nlspath, *lang, *base, *cptr, *pathP, *tmpptr;
|
2000-09-05 14:04:21 +00:00
|
|
|
char *cptr1, *plang, *pter, *pcode;
|
2000-09-04 12:09:40 +00:00
|
|
|
struct stat sbuf;
|
|
|
|
|
|
|
|
if (name == NULL || *name == '\0') {
|
|
|
|
NLRETERR(ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is it absolute path ? if yes, load immidiately */
|
|
|
|
if (strchr(name, '/'))
|
|
|
|
return loadCat(name);
|
|
|
|
|
|
|
|
if (type == NL_CAT_LOCALE)
|
|
|
|
lang = setlocale(LC_MESSAGES, NULL);
|
|
|
|
else
|
|
|
|
lang = getenv("LANG");
|
|
|
|
if (lang == NULL || *lang == '\0' || strchr(lang, '/') != NULL)
|
|
|
|
lang = "C";
|
2000-09-05 14:04:21 +00:00
|
|
|
|
|
|
|
if ((plang = cptr1 = strdup(lang)) == NULL)
|
|
|
|
return (NLERR);
|
|
|
|
if ((cptr = strchr(cptr1, '@')) != NULL)
|
|
|
|
*cptr = '\0';
|
|
|
|
pter = pcode = "";
|
|
|
|
if ((cptr = strchr(cptr1, '_')) != NULL) {
|
|
|
|
*cptr++ = '\0';
|
|
|
|
pter = cptr1 = cptr;
|
|
|
|
}
|
|
|
|
if ((cptr = strchr(cptr1, '.')) != NULL) {
|
|
|
|
*cptr++ = '\0';
|
|
|
|
pcode = cptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nlspath = getenv("NLSPATH")) == NULL
|
1998-01-15 09:58:08 +00:00
|
|
|
#ifndef __NETBSD_SYSCALLS
|
2000-09-04 12:09:40 +00:00
|
|
|
|| issetugid()
|
1998-01-15 09:58:08 +00:00
|
|
|
#endif
|
2000-09-04 12:09:40 +00:00
|
|
|
)
|
|
|
|
nlspath = _DEFAULT_NLS_PATH;
|
|
|
|
|
2000-09-05 14:04:21 +00:00
|
|
|
if ((base = cptr = strdup(nlspath)) == NULL) {
|
|
|
|
free(plang);
|
|
|
|
return (NLERR);
|
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
|
2000-09-05 14:04:21 +00:00
|
|
|
while ((nlspath = strsep(&cptr, ":")) != NULL) {
|
|
|
|
pathP = path;
|
|
|
|
if (*nlspath) {
|
|
|
|
for ( ; *nlspath; ++nlspath) {
|
2000-09-04 12:09:40 +00:00
|
|
|
if (*nlspath == '%') {
|
|
|
|
switch (*(nlspath + 1)) {
|
2000-09-05 14:04:21 +00:00
|
|
|
case 'l':
|
|
|
|
tmpptr = plang;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tmpptr = pter;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
tmpptr = pcode;
|
|
|
|
break;
|
2000-09-04 12:09:40 +00:00
|
|
|
case 'L':
|
|
|
|
tmpptr = lang;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
tmpptr = (char*)name;
|
|
|
|
break;
|
2000-09-05 14:04:21 +00:00
|
|
|
case '%':
|
|
|
|
++nlspath;
|
|
|
|
/* fallthrough */
|
2000-09-04 12:09:40 +00:00
|
|
|
default:
|
2000-09-08 11:42:37 +00:00
|
|
|
if (pathP - path >= sizeof(path) - 1)
|
|
|
|
goto too_long;
|
2000-09-04 12:09:40 +00:00
|
|
|
*(pathP++) = *nlspath;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++nlspath;
|
2000-09-05 14:04:21 +00:00
|
|
|
put_tmpptr:
|
2000-09-04 12:09:40 +00:00
|
|
|
spcleft = sizeof(path) - (pathP - path) - 1;
|
|
|
|
if (strlcpy(pathP, tmpptr, spcleft) >= spcleft) {
|
2000-09-08 11:42:37 +00:00
|
|
|
too_long:
|
2000-09-05 14:04:21 +00:00
|
|
|
free(plang);
|
2000-09-01 11:56:31 +00:00
|
|
|
free(base);
|
2000-09-04 12:09:40 +00:00
|
|
|
NLRETERR(ENAMETOOLONG);
|
|
|
|
}
|
|
|
|
pathP += strlen(tmpptr);
|
2000-09-08 11:42:37 +00:00
|
|
|
} else {
|
|
|
|
if (pathP - path >= sizeof(path) - 1)
|
|
|
|
goto too_long;
|
2000-09-04 12:09:40 +00:00
|
|
|
*(pathP++) = *nlspath;
|
2000-09-08 11:42:37 +00:00
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
*pathP = '\0';
|
|
|
|
if (stat(path, &sbuf) == 0) {
|
2000-09-05 14:04:21 +00:00
|
|
|
free(plang);
|
2000-09-04 12:09:40 +00:00
|
|
|
free(base);
|
|
|
|
return loadCat(path);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
2000-09-05 14:04:21 +00:00
|
|
|
} else {
|
|
|
|
tmpptr = (char*)name;
|
|
|
|
--nlspath;
|
|
|
|
goto put_tmpptr;
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
}
|
2000-09-05 14:04:21 +00:00
|
|
|
free(plang);
|
2000-09-04 12:09:40 +00:00
|
|
|
free(base);
|
|
|
|
NLRETERR(ENOENT);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've got an odd situation here. The odds are real good that the
|
|
|
|
* number we are looking for is almost the same as the index. We could
|
|
|
|
* use the index, check the difference and do something intelligent, but
|
|
|
|
* I haven't quite figured out what's intelligent.
|
|
|
|
*
|
|
|
|
* Here's a start.
|
|
|
|
* Take an id N. If there are > N items in the list, then N cannot
|
|
|
|
* be more than N items from the start, since otherwise there would
|
|
|
|
* have to be duplicate items. So we can safely set the top to N+1
|
|
|
|
* (after taking into account that ids start at 1, and arrays at 0)
|
|
|
|
*
|
|
|
|
* Let's say we are at position P, and we are looking for N, but have
|
|
|
|
* V. If N > V, then the furthest away that N could be is
|
|
|
|
* P + (N-V). So we can safely set hi to P+(N-V)+1. For example:
|
|
|
|
* We are looking for 10, but have 8
|
|
|
|
* 8 ? ? ? ?
|
|
|
|
* >=9 >=10 >=11
|
|
|
|
*
|
|
|
|
*/
|
2000-09-04 12:09:40 +00:00
|
|
|
|
|
|
|
#define LOOKUP(PARENT, CHILD, ID, NUM, SET) { \
|
|
|
|
lo = 0; \
|
|
|
|
if (ID - 1 < PARENT->NUM) { \
|
|
|
|
cur = ID - 1; hi = ID; \
|
|
|
|
} else { \
|
|
|
|
hi = PARENT->NUM; cur = (hi - lo) / 2; \
|
|
|
|
} \
|
|
|
|
while (TRUE) { \
|
|
|
|
CHILD = PARENT->SET + cur; \
|
|
|
|
if (CHILD->ID == ID) break; \
|
|
|
|
if (CHILD->ID < ID) { \
|
|
|
|
lo = cur+1; \
|
|
|
|
if (hi > cur+(ID-CHILD->ID)+1) \
|
|
|
|
hi = cur+(ID-CHILD->ID)+1; \
|
|
|
|
dir = 1; \
|
|
|
|
} else { \
|
|
|
|
hi = cur; dir = -1; \
|
|
|
|
} \
|
|
|
|
if (lo >= hi) return(NULL); \
|
|
|
|
if (hi - lo == 1) cur += dir; \
|
|
|
|
else cur += ((hi - lo) / 2) * dir; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCSetT*
|
|
|
|
MCGetSet( cat, setId)
|
|
|
|
MCCatT *cat;
|
|
|
|
int setId;
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
|
|
|
MCSetT *set;
|
|
|
|
long lo, hi, cur, dir;
|
|
|
|
|
2000-08-30 11:44:44 +00:00
|
|
|
if (cat == NULL || setId <= 0) return(NULL);
|
2000-09-04 12:09:40 +00:00
|
|
|
LOOKUP(cat, set, setId, numSets, sets);
|
2000-08-30 11:44:44 +00:00
|
|
|
if (set->invalid && loadSet(cat, set) <= 0)
|
|
|
|
return(NULL);
|
1995-03-30 12:47:27 +00:00
|
|
|
return(set);
|
|
|
|
}
|
|
|
|
|
1995-05-30 05:51:47 +00:00
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
static MCMsgT*
|
|
|
|
MCGetMsg( set, msgId)
|
|
|
|
MCSetT *set;
|
|
|
|
int msgId;
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
|
|
|
MCMsgT *msg;
|
|
|
|
long lo, hi, cur, dir;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
2000-08-30 11:44:44 +00:00
|
|
|
if (set == NULL || set->invalid || msgId <= 0) return(NULL);
|
2000-09-04 12:09:40 +00:00
|
|
|
LOOKUP(set, msg, msgId, numMsgs, u.msgs);
|
1995-03-30 12:47:27 +00:00
|
|
|
return(msg);
|
|
|
|
}
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
char*
|
|
|
|
catgets( catd, setId, msgId, dflt)
|
|
|
|
nl_catd catd;
|
|
|
|
int setId;
|
|
|
|
int msgId;
|
|
|
|
__const char *dflt;
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
|
|
|
MCMsgT *msg;
|
|
|
|
MCCatT *cat = (MCCatT *) catd;
|
1998-04-30 10:14:55 +00:00
|
|
|
__const char *cptr;
|
1995-03-30 12:47:27 +00:00
|
|
|
|
1998-04-30 12:25:05 +00:00
|
|
|
if (catd == NULL || catd == NLERR)
|
|
|
|
return((char *)dflt);
|
1995-03-30 12:47:27 +00:00
|
|
|
msg = MCGetMsg(MCGetSet(cat, setId), msgId);
|
2000-09-03 21:05:10 +00:00
|
|
|
if (msg != NULL) cptr = msg->msg.str;
|
1995-03-30 12:47:27 +00:00
|
|
|
else cptr = dflt;
|
1998-04-30 10:14:55 +00:00
|
|
|
return((char *)cptr);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
int
|
|
|
|
catclose( catd)
|
|
|
|
nl_catd catd;
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
|
|
|
MCCatT *cat = (MCCatT *) catd;
|
|
|
|
|
1998-07-14 18:27:43 +00:00
|
|
|
if (catd == NULL || catd == NLERR) {
|
2000-09-04 12:09:40 +00:00
|
|
|
errno = EBADF; return(-1);
|
1998-07-14 18:27:43 +00:00
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
#if 0
|
2000-09-03 21:05:10 +00:00
|
|
|
if (cat->loadType != MCLoadAll)
|
2000-09-04 12:09:40 +00:00
|
|
|
#endif
|
2000-09-03 21:05:10 +00:00
|
|
|
(void) fclose(cat->fp);
|
2000-09-04 12:09:40 +00:00
|
|
|
__nls_free_resources(cat, cat->numSets);
|
1995-03-30 12:47:27 +00:00
|
|
|
free(cat);
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
return(0);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Note that only malloc failures are allowed to return an error */
|
2000-09-04 12:09:40 +00:00
|
|
|
static char* _errowner = "Message Catalog System";;
|
2000-09-05 12:23:08 +00:00
|
|
|
#define CORRUPT() { \
|
2000-09-27 18:24:31 +00:00
|
|
|
fprintf(stderr, "%s: corrupt file.", _errowner); \
|
2000-09-05 12:23:08 +00:00
|
|
|
free(cat); \
|
|
|
|
NLRETERR(EINVAL); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NOSPACE() { \
|
|
|
|
fprintf(stderr, "%s: no more memory.", _errowner); \
|
|
|
|
free(cat); \
|
|
|
|
return(NLERR); \
|
2000-09-04 12:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__nls_free_resources(cat, i)
|
|
|
|
MCCatT *cat;
|
|
|
|
int i;
|
|
|
|
{
|
|
|
|
MCSetT *set;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
set = cat->sets + j;
|
|
|
|
if (!set->invalid) {
|
|
|
|
free(set->data.str);
|
|
|
|
free(set->u.msgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(cat->sets);
|
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
static nl_catd
|
|
|
|
loadCat(catpath)
|
|
|
|
__const char *catpath;
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
|
|
|
MCHeaderT header;
|
|
|
|
MCCatT *cat;
|
|
|
|
MCSetT *set;
|
2000-09-04 12:09:40 +00:00
|
|
|
long i;
|
1995-03-30 12:47:27 +00:00
|
|
|
off_t nextSet;
|
|
|
|
|
|
|
|
cat = (MCCatT *) malloc(sizeof(MCCatT));
|
2000-08-30 11:44:44 +00:00
|
|
|
if (cat == NULL) return(NLERR);
|
1998-04-30 11:39:08 +00:00
|
|
|
cat->loadType = MCLoadBySet;
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2000-09-03 21:05:10 +00:00
|
|
|
if ((cat->fp = fopen(catpath, "r")) == NULL) {
|
1997-05-10 04:28:17 +00:00
|
|
|
free(cat);
|
1998-04-30 10:14:55 +00:00
|
|
|
return(NLERR);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
2000-09-03 21:05:10 +00:00
|
|
|
(void) _fcntl(fileno(cat->fp), F_SETFD, FD_CLOEXEC);
|
1995-03-30 12:47:27 +00:00
|
|
|
|
2000-09-03 21:05:10 +00:00
|
|
|
if (fread(&header, sizeof(header), 1, cat->fp) != 1)
|
2000-01-12 09:23:48 +00:00
|
|
|
CORRUPT();
|
1995-03-30 12:47:27 +00:00
|
|
|
|
|
|
|
if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT();
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-03-30 12:47:27 +00:00
|
|
|
if (header.majorVer != MCMajorVer) {
|
1997-05-10 04:28:17 +00:00
|
|
|
free(cat);
|
2000-09-04 12:09:40 +00:00
|
|
|
fprintf(stderr, "%s: %s is version %ld, we need %ld.\n", _errowner,
|
1995-03-30 12:47:27 +00:00
|
|
|
catpath, header.majorVer, MCMajorVer);
|
2000-09-04 12:09:40 +00:00
|
|
|
NLRETERR(EINVAL);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-03-30 12:47:27 +00:00
|
|
|
if (header.numSets <= 0) {
|
1997-05-10 04:28:17 +00:00
|
|
|
free(cat);
|
2000-09-04 12:09:40 +00:00
|
|
|
fprintf(stderr, "%s: %s has %ld sets!\n", _errowner, catpath,
|
1995-03-30 12:47:27 +00:00
|
|
|
header.numSets);
|
2000-09-04 12:09:40 +00:00
|
|
|
NLRETERR(EINVAL);
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cat->numSets = header.numSets;
|
|
|
|
cat->sets = (MCSetT *) malloc(sizeof(MCSetT) * header.numSets);
|
2000-08-30 11:44:44 +00:00
|
|
|
if (cat->sets == NULL) NOSPACE();
|
1995-03-30 12:47:27 +00:00
|
|
|
|
|
|
|
nextSet = header.firstSet;
|
|
|
|
for (i = 0; i < cat->numSets; ++i) {
|
2000-09-03 21:05:10 +00:00
|
|
|
if (fseeko(cat->fp, nextSet, SEEK_SET) == -1) {
|
2000-09-04 12:09:40 +00:00
|
|
|
__nls_free_resources(cat, i);
|
1997-05-10 04:40:40 +00:00
|
|
|
CORRUPT();
|
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
|
|
|
|
/* read in the set header */
|
|
|
|
set = cat->sets + i;
|
2000-09-03 21:05:10 +00:00
|
|
|
if (fread(set, sizeof(*set), 1, cat->fp) != 1) {
|
2000-09-04 12:09:40 +00:00
|
|
|
__nls_free_resources(cat, i);
|
1997-05-10 04:40:40 +00:00
|
|
|
CORRUPT();
|
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
|
|
|
|
/* if it's invalid, skip over it (and backup 'i') */
|
|
|
|
if (set->invalid) {
|
|
|
|
--i;
|
|
|
|
nextSet = set->nextSet;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
#if 0
|
1995-03-30 12:47:27 +00:00
|
|
|
if (cat->loadType == MCLoadAll) {
|
1998-04-30 10:14:55 +00:00
|
|
|
int res;
|
1997-05-10 04:40:40 +00:00
|
|
|
|
1995-03-30 12:47:27 +00:00
|
|
|
if ((res = loadSet(cat, set)) <= 0) {
|
2000-09-04 12:09:40 +00:00
|
|
|
__nls_free_resources(cat, i);
|
1998-04-30 10:14:55 +00:00
|
|
|
if (res < 0) NOSPACE();
|
1995-03-30 12:47:27 +00:00
|
|
|
CORRUPT();
|
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
set->invalid = TRUE;
|
1995-03-30 12:47:27 +00:00
|
|
|
nextSet = set->nextSet;
|
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
#if 0
|
1995-03-30 12:47:27 +00:00
|
|
|
if (cat->loadType == MCLoadAll) {
|
2000-09-03 21:05:10 +00:00
|
|
|
(void) fclose(cat->fp);
|
|
|
|
cat->fp = NULL;
|
1995-03-30 12:47:27 +00:00
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
#endif
|
1995-03-30 12:47:27 +00:00
|
|
|
return((nl_catd) cat);
|
|
|
|
}
|
|
|
|
|
2000-09-04 12:09:40 +00:00
|
|
|
static int
|
|
|
|
loadSet(cat, set)
|
|
|
|
MCCatT *cat;
|
|
|
|
MCSetT *set;
|
1995-03-30 12:47:27 +00:00
|
|
|
{
|
|
|
|
MCMsgT *msg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Get the data */
|
2000-09-03 21:05:10 +00:00
|
|
|
if (fseeko(cat->fp, set->data.off, SEEK_SET) == -1) return(0);
|
1998-04-30 10:14:55 +00:00
|
|
|
if ((set->data.str = malloc(set->dataLen)) == NULL) return(-1);
|
2000-09-03 21:05:10 +00:00
|
|
|
if (fread(set->data.str, set->dataLen, 1, cat->fp) != 1) {
|
1997-05-10 04:28:17 +00:00
|
|
|
free(set->data.str); return(0);
|
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
|
|
|
|
/* Get the messages */
|
2000-09-03 21:05:10 +00:00
|
|
|
if (fseeko(cat->fp, set->u.firstMsg, SEEK_SET) == -1) {
|
1997-05-10 04:28:17 +00:00
|
|
|
free(set->data.str); return(0);
|
|
|
|
}
|
|
|
|
if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) {
|
|
|
|
free(set->data.str); return(-1);
|
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-03-30 12:47:27 +00:00
|
|
|
for (i = 0; i < set->numMsgs; ++i) {
|
|
|
|
msg = set->u.msgs + i;
|
2000-09-03 21:05:10 +00:00
|
|
|
if (fread(msg, sizeof(*msg), 1, cat->fp) != 1) {
|
1997-05-10 04:28:17 +00:00
|
|
|
free(set->u.msgs); free(set->data.str); return(0);
|
|
|
|
}
|
1995-03-30 12:47:27 +00:00
|
|
|
if (msg->invalid) {
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
msg->msg.str = (char *) (set->data.str + msg->msg.off);
|
|
|
|
}
|
2000-09-04 12:09:40 +00:00
|
|
|
set->invalid = FALSE;
|
1995-03-30 12:47:27 +00:00
|
|
|
return(1);
|
|
|
|
}
|