diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/nls/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/nls/catclose.3 | 54 | ||||
-rw-r--r-- | lib/libc/nls/catclose.c | 25 | ||||
-rw-r--r-- | lib/libc/nls/catgets.3 | 67 | ||||
-rw-r--r-- | lib/libc/nls/catgets.c | 28 | ||||
-rw-r--r-- | lib/libc/nls/catopen.3 | 82 | ||||
-rw-r--r-- | lib/libc/nls/catopen.c | 26 | ||||
-rw-r--r-- | lib/libc/nls/msgcat.c | 396 | ||||
-rw-r--r-- | lib/libc/nls/msgcat.h | 170 |
9 files changed, 854 insertions, 0 deletions
diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc new file mode 100644 index 0000000..f72d091 --- /dev/null +++ b/lib/libc/nls/Makefile.inc @@ -0,0 +1,6 @@ +# $NetBSD: Makefile.inc,v 1.7 1995/02/27 13:06:20 cgd Exp $ + +.PATH: ${.CURDIR}/nls + +SRCS+= catclose.c catgets.c catopen.c msgcat.c +MAN+= catclose.3 catgets.3 catopen.3 diff --git a/lib/libc/nls/catclose.3 b/lib/libc/nls/catclose.3 new file mode 100644 index 0000000..f9803ff --- /dev/null +++ b/lib/libc/nls/catclose.3 @@ -0,0 +1,54 @@ +.\" $Id$ +.\" +.\" Copyright (c) 1994 Winning Strategies, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Winning Strategies, Inc. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd May 29, 1994 +.Dt CATCLOSE 3 +.Os +.Sh NAME +.Nm catclose +.Nd close message catalog +.Sh SYNOPSIS +.Fd #include <nl_types.h> +.Ft int +.Fn catclose "nl_catd catd" +.Sh DESCRIPTION +The +.Fn catclose +function closes the message catalog specified by the argument +.Fa catd . +.Sh SEE ALSO +.Xr catopen 3 , +.Xr catgets 3 +.Sh STANDARDS +The +.Fn catclose +function conforms to +.St -xpg3 . + diff --git a/lib/libc/nls/catclose.c b/lib/libc/nls/catclose.c new file mode 100644 index 0000000..341f664 --- /dev/null +++ b/lib/libc/nls/catclose.c @@ -0,0 +1,25 @@ +/* $Id$ */ + +/* + * Written by J.T. Conklin, 10/05/94 + * Public domain. + */ + +#include <sys/cdefs.h> + +#ifdef __indr_reference +__indr_reference(_catclose,catclose); +#else + +#include <nl_types.h> + +extern int _catclose __P((nl_catd)); + +int +catclose(catd) + nl_catd catd; +{ + return _catclose(catd); +} + +#endif diff --git a/lib/libc/nls/catgets.3 b/lib/libc/nls/catgets.3 new file mode 100644 index 0000000..3747d82 --- /dev/null +++ b/lib/libc/nls/catgets.3 @@ -0,0 +1,67 @@ +.\" $Id$ +.\" +.\" Copyright (c) 1994 Winning Strategies, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Winning Strategies, Inc. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd May 29, 1994 +.Dt CATGETS 3 +.Os +.Sh NAME +.Nm catgets +.Nd retrieve string from message catalog +.Sh SYNOPSIS +.Fd #include <nl_types.h> +.Ft char * +.Fn catgets "nl_catd catd" "int set_id" "int msg_id" "char *s" +.Sh DESCRIPTION +The +.Fn catgets +function attempts to retrieve message +.Fa msg_id +of set +.Fa set_id +from the message catalog referenced by the descriptor +.Fa catd . +The argument +.Fa s +points to a default message which is returned if the function +is unable to retrieve the specified message. +.Sh RETURN VALUE +If the specified message was retrieved successfully, +.Fn catgets +returns a pointer to an internal buffer containing the message string; +otherwise it returns +.Fa s . +.Sh SEE ALSO +.Xr catclose 3 , +.Xr catopen 3 +.Sh STANDARDS +The +.Fn catgets +function conforms to +.St -xpg3 . diff --git a/lib/libc/nls/catgets.c b/lib/libc/nls/catgets.c new file mode 100644 index 0000000..c29cf64 --- /dev/null +++ b/lib/libc/nls/catgets.c @@ -0,0 +1,28 @@ +/* $Id$ */ + +/* + * Written by J.T. Conklin, 10/05/94 + * Public domain. + */ + +#include <sys/cdefs.h> + +#ifdef __indr_reference +__indr_reference(_catgets,catgets); +#else + +#include <nl_types.h> + +extern char * _catgets __P((nl_catd, int, int, char *)); + +char * +catgets(catd, set_id, msg_id, s) + nl_catd catd; + int set_id; + int msg_id; + char *s; +{ + return _catgets(catd, set_id, msg_id, s); +} + +#endif diff --git a/lib/libc/nls/catopen.3 b/lib/libc/nls/catopen.3 new file mode 100644 index 0000000..f581baf --- /dev/null +++ b/lib/libc/nls/catopen.3 @@ -0,0 +1,82 @@ +.\" $Id$ +.\" +.\" Copyright (c) 1994 Winning Strategies, Inc. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Winning Strategies, Inc. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd May 29, 1994 +.Dt CATOPEN 3 +.Os +.Sh NAME +.Nm catopen +.Nd open message catalog +.Sh SYNOPSIS +.Fd #include <nl_types.h> +.Ft nl_catd +.Fn catopen "const char *name" "int oflag" +.Sh DESCRIPTION +The +.Fn catopen +function opens the message catalog specified by +.Fa name +and returns a message catalog descriptor. +If +.Fa name +contains a +.Sq / +then +.Fa name +specifies the full pathname for the message catalog, otherwise the value +of the environment variable +.Ev NLSPATH +is used with +.Fa name +substituted for %N. +.Pp +The +.Fa oflag +argument is reserved for future use and should be set to zero. +.Sh RETURN VALUE +Upon successful completion, +.Fn catopen +returns a message catalog descriptor. +Otherwise, (nl_catd) -1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory is availiable. +.El +.Sh SEE ALSO +.Xr catclose 3 , +.Xr catgets 3 +.Sh STANDARDS +The +.Fn catopen +function conforms to +.St -xpg3 . diff --git a/lib/libc/nls/catopen.c b/lib/libc/nls/catopen.c new file mode 100644 index 0000000..5dfb727 --- /dev/null +++ b/lib/libc/nls/catopen.c @@ -0,0 +1,26 @@ +/* $Id$ */ + +/* + * Written by J.T. Conklin, 10/05/94 + * Public domain. + */ + +#include <sys/cdefs.h> + +#ifdef __indr_reference +__indr_reference(_catopen,catopen); +#else + +#include <nl_types.h> + +extern nl_catd _catopen __P((__const char *, int)); + +nl_catd +catopen(name, oflag) + __const char *name; + int oflag; +{ + return _catopen(name, oflag); +} + +#endif diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c new file mode 100644 index 0000000..37a15e1 --- /dev/null +++ b/lib/libc/nls/msgcat.c @@ -0,0 +1,396 @@ +/* $Id$ */ + +/*********************************************************** +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 + +******************************************************************/ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: msgcat.c,v 1.11 1995/02/27 13:06:51 cgd Exp $"; +#endif /* LIBC_SCCS and not lint */ + +/* Edit History + +03/06/91 4 schulert remove working directory from nlspath +01/18/91 2 hamilton #if not rescanned +01/12/91 3 schulert conditionally use prototypes +11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste +10/15/90 2 schulert > #include <unistd.h> if MIPS +08/13/90 1 schulert move from ua to omu +*/ + +/* + * We need a better way of handling errors than printing text. I need + * to add an error handling routine. + */ + +#include "nl_types.h" +#include "msgcat.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#ifndef True +# define True ~0 +# define False 0 +#endif + +/* take care of sysv diffs */ +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +#ifndef FD_CLOEXEC +#define FD_CLOEXEC 1 +#endif + +#define NLERR ((nl_catd) -1) + +static nl_catd loadCat(); +static nl_catd loadSet(); + +nl_catd _catopen( name, type) +__const char *name; +int type; +{ + char path[MAXPATHLEN]; + __const char *catpath = NULL; + char *nlspath, *tmppath = NULL; + char *lang; + long len; + char *base, *cptr, *pathP; + struct stat sbuf; + + if (!name || !*name) return(NLERR); + + if (strchr(name, '/')) { + catpath = name; + if (stat(catpath, &sbuf)) return(0); + } else { + if ((lang = (char *) getenv("LANG")) == NULL) lang = "C"; + if ((nlspath = (char *) getenv("NLSPATH")) == NULL) { + nlspath = "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L"; + } + + len = strlen(nlspath); + base = cptr = (char *) malloc(len + 2); + if (!base) return(NLERR); + strcpy(cptr, nlspath); + cptr[len] = ':'; + cptr[len+1] = '\0'; + + for (nlspath = cptr; *cptr; ++cptr) { + if (*cptr == ':') { + *cptr = '\0'; + for (pathP = path; *nlspath; ++nlspath) { + if (*nlspath == '%') { + if (*(nlspath + 1) == 'L') { + ++nlspath; + strcpy(pathP, lang); + pathP += strlen(lang); + } else if (*(nlspath + 1) == 'N') { + ++nlspath; + strcpy(pathP, name); + pathP += strlen(name); + } else *(pathP++) = *nlspath; + } else *(pathP++) = *nlspath; + } + *pathP = '\0'; + if (stat(path, &sbuf) == 0) { + catpath = path; + break; + } + nlspath = cptr+1; + } + } + free(base); + if (tmppath) free(tmppath); + + if (!catpath) return(0); + } + + return(loadCat(catpath, type)); +} + +/* + * 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 + * + */ +static MCSetT *MCGetSet( cat, setId) +MCCatT *cat; +int setId; +{ + MCSetT *set; + long lo, hi, cur, dir; + + if (!cat || setId <= 0) return(NULL); + + lo = 0; + if (setId - 1 < cat->numSets) { + cur = setId - 1; + hi = setId; + } else { + hi = cat->numSets; + cur = (hi - lo) / 2; + } + + while (True) { + set = cat->sets + cur; + if (set->setId == setId) break; + if (set->setId < setId) { + lo = cur+1; + if (hi > cur + (setId - set->setId) + 1) hi = cur+(setId-set->setId)+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; + } + if (set->invalid) loadSet(cat, set); + return(set); +} + + +static MCMsgT *MCGetMsg( set, msgId) +MCSetT *set; +int msgId; +{ + MCMsgT *msg; + long lo, hi, cur, dir; + + if (!set || set->invalid || msgId <= 0) return(NULL); + + lo = 0; + if (msgId - 1 < set->numMsgs) { + cur = msgId - 1; + hi = msgId; + } else { + hi = set->numMsgs; + cur = (hi - lo) / 2; + } + + while (True) { + msg = set->u.msgs + cur; + if (msg->msgId == msgId) break; + if (msg->msgId < msgId) { + lo = cur+1; + if (hi > cur + (msgId - msg->msgId) + 1) hi = cur+(msgId-msg->msgId)+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; + } + return(msg); +} + +char *_catgets( catd, setId, msgId, dflt) +nl_catd catd; +int setId; +int msgId; +char *dflt; +{ + MCMsgT *msg; + MCCatT *cat = (MCCatT *) catd; + char *cptr; + + msg = MCGetMsg(MCGetSet(cat, setId), msgId); + if (msg) cptr = msg->msg.str; + else cptr = dflt; + return(cptr); +} + + +int _catclose( catd) +nl_catd catd; +{ + MCCatT *cat = (MCCatT *) catd; + MCSetT *set; + MCMsgT *msg; + int i, j; + + if (!cat) return -1; + + if (cat->loadType != MCLoadAll) close(cat->fd); + for (i = 0; i < cat->numSets; ++i) { + set = cat->sets + i; + if (!set->invalid) { + free(set->data.str); + free(set->u.msgs); + } + } + free(cat->sets); + free(cat); + + return 0; +} + +/* + * Internal routines + */ + +/* Note that only malloc failures are allowed to return an error */ +#define ERRNAME "Message Catalog System" +#define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); return(0);} +#define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); return(NLERR);} + +static nl_catd loadCat( catpath, type) +__const char *catpath; +int type; +{ + MCHeaderT header; + MCCatT *cat; + MCSetT *set; + MCMsgT *msg; + long i, j; + off_t nextSet; + + cat = (MCCatT *) malloc(sizeof(MCCatT)); + if (!cat) return(NLERR); + cat->loadType = type; + + if ((cat->fd = open(catpath, O_RDONLY)) < 0) { + return(0); + } + + fcntl(cat->fd, F_SETFD, FD_CLOEXEC); + + if (read(cat->fd, &header, sizeof(header)) != sizeof(header)) CORRUPT(); + + if (strncmp(header.magic, MCMagic, MCMagicLen) != 0) CORRUPT(); + + if (header.majorVer != MCMajorVer) { + fprintf(stderr, "%s: %s is version %d, we need %d.\n", ERRNAME, + catpath, header.majorVer, MCMajorVer); + return(0); + } + + if (header.numSets <= 0) { + fprintf(stderr, "%s: %s has %d sets!\n", ERRNAME, catpath, + header.numSets); + return(0); + } + + cat->numSets = header.numSets; + cat->sets = (MCSetT *) malloc(sizeof(MCSetT) * header.numSets); + if (!cat->sets) NOSPACE(); + + nextSet = header.firstSet; + for (i = 0; i < cat->numSets; ++i) { + if (lseek(cat->fd, nextSet, 0) == -1) CORRUPT(); + + /* read in the set header */ + set = cat->sets + i; + if (read(cat->fd, set, sizeof(*set)) != sizeof(*set)) CORRUPT(); + + /* if it's invalid, skip over it (and backup 'i') */ + + if (set->invalid) { + --i; + nextSet = set->nextSet; + continue; + } + + if (cat->loadType == MCLoadAll) { + nl_catd res; + if ((res = loadSet(cat, set)) <= 0) { + if (res == -1) NOSPACE(); + CORRUPT(); + } + } else set->invalid = True; + nextSet = set->nextSet; + } + if (cat->loadType == MCLoadAll) { + close(cat->fd); + cat->fd = -1; + } + return((nl_catd) cat); +} + +static nl_catd loadSet( cat, set) +MCCatT *cat; +MCSetT *set; +{ + MCMsgT *msg; + int i; + + /* Get the data */ + if (lseek(cat->fd, set->data.off, 0) == -1) return(0); + if ((set->data.str = (char *) malloc(set->dataLen)) == NULL) return(-1); + if (read(cat->fd, set->data.str, set->dataLen) != set->dataLen) return(0); + + /* Get the messages */ + if (lseek(cat->fd, set->u.firstMsg, 0) == -1) return(0); + if ((set->u.msgs = (MCMsgT *) malloc(sizeof(MCMsgT) * set->numMsgs)) == NULL) return(-1); + + for (i = 0; i < set->numMsgs; ++i) { + msg = set->u.msgs + i; + if (read(cat->fd, msg, sizeof(*msg)) != sizeof(*msg)) return(0); + if (msg->invalid) { + --i; + continue; + } + msg->msg.str = (char *) (set->data.str + msg->msg.off); + } + set->invalid = False; + return(1); +} + + + + + diff --git a/lib/libc/nls/msgcat.h b/lib/libc/nls/msgcat.h new file mode 100644 index 0000000..e6e5744 --- /dev/null +++ b/lib/libc/nls/msgcat.h @@ -0,0 +1,170 @@ +/* $Id$ */ + +/* -*-c++-*- */ + +#ifndef __msgcath + + +/*********************************************************** +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 + +******************************************************************/ + + +#include <sys/types.h> + +/* + * On disk data structures + */ + +/* Edit History + +02/25/91 2 nazgul Byte order flags, upped the version number +11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste +08/13/90 1 schulert move from ua to omu +*/ + +/* For or'd constants */ +#define MCMakeId(s,m) (unsigned long) ( ((unsigned short)s << (sizeof(short)*8)) \ + | (unsigned short)m ) +#define MCSetId(id) (unsigned int) ( id >> (sizeof(short) * 8) ) +#define MCMsgId(id) (unsigned int) ( (id << (sizeof(short) * 8)) \ + >> (sizeof(short) * 8) ) +#undef S +#undef UI +#undef UL + +#define MCMagicLen 8 +#define MCMagic "*nazgul*" +#define MCLastMsg 0 +#define MCLastSet 0 + +#define MCMajorVer 1 +#define MCMinorVer 0 + +/* + * Critical note here. Sets and Messages *MUST* be stored in ascending + * order. There are stored that way (by specification) in the original + * data file, however in the process of merging in new stuff you might + * mix that up. Don't! The catget stuff does a binary search and will + * totally lose it if these aren't in order (not contiguous mind you, just + * in order. If this turns out to be a major problem this could be enhanced + * by adding a 'sorted' flag to the db, and sorting msgs and sets at load + * time if things aren't sorted, but I'd like not to have to do that. + */ + +/* + * I have tried here to define data structures which can be used + * while the catalog is on disk, and at runtime. + * This is rather dangerous of course, but I think it can be done without + * overly increasing the memory usage, and it makes loading and storing + * somewhat simpler and less prone to accidents. I have also tried to + * define on disk data structures which can be updated in place, so that + * with a very large catalog (e.g. all system errors) you don't have to + * load everything in memory in order to add or update one set. With + * this in mind there are "invalid" flags which allow items to be + * invalidated and thus not loaded at runtime. Note however that although + * I pay attention to these when I load the DB, I do not currently use + * them in gencat (it just reads everything into memory), so there is + * no guarantee that this will all work. + */ + +/* These should be publicly available */ + +#define MCLoadBySet 0 /* Load entire sets as they are used */ +#define MCLoadAll 1 /* Load entire DB on catopen */ + +/* + * MCOffsetT - Union to handle both disk and runtime pointers + */ +typedef union { + off_t off; + char *str; + void *ptr; + struct _MCMsgT *msg; + struct _MCSetT *set; +} MCOffsetT; + +/* + * MCMsgT - Message structure (disk and runtime) + */ +typedef struct _MCMsgT { + long msgId; /* Id of this message */ + MCOffsetT msg; /* Relative offset on disk or pointer in memory */ + long invalid; /* Valid on disk, loaded in memory */ +} MCMsgT; + +/* + * MCSetT - Set structure (disk and runtime) + */ +typedef struct _MCSetT { + long setId; /* Id of this set */ + off_t nextSet; /* Offset of next set on disk */ + union { + off_t firstMsg; /* Offset to first Msg (while on disk) */ + MCMsgT *msgs; /* Pointer to array of msgs (in mem, loaded) */ + } u; + MCOffsetT data; /* Offset to data, or pointer to data */ + long dataLen; /* Length of data area on disk */ + long numMsgs; /* Number of messages */ + long invalid; /* Valid on disk, loaded in memory */ +} MCSetT; + +/* + * MCCatT - Runtime catalog pointer + */ +typedef struct { + long loadType; /* How to load the messages (see MSLoadType) */ + int fd; /* File descriptor of catalog (if load-on-demand) */ + long numSets; /* Number of sets */ + MCSetT *sets; /* Pointer to the sets */ + off_t firstSet; /* Offset of first set on disk */ +} MCCatT; + +/* + * MCHeaderT - Disk file header + */ +typedef struct { + char magic[MCMagicLen]; /* Magic cookie "*nazgul*" */ + long majorVer; /* ++ on incompatible changes */ + long minorVer; /* ++ on compatible changes */ + long flags; /* Informational flags */ + long numSets; /* Number of valid Sets */ + off_t firstSet; /* Offset of first set on disk */ +} MCHeaderT; + +/* Some flags */ +#define MC68KByteOrder 0x01 +#define MCn86ByteOrder 0x02 + + + + +#endif |