mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 21:05:08 +00:00
Optimize gencat(1) sources in same manner as its libc part some time ago:
. remove SYSV compatibility bits . sort #include's . ifdef unused code . cleanup BDECFLAGS warnings . fixed few typos in diagnostics messages . style(9) fixes as part of this cleanup I have changed all K&R declarations to ANSI style. Main reason for doing that was great mix of declarations used here - clean ASNI , clean K&R, ifdef'ed (both). Reviewed by: ache (mostly)
This commit is contained in:
parent
2992e4e37f
commit
75c84bca41
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=72164
|
@ -1,3 +1,4 @@
|
||||||
|
/* $FreeBSD$ */
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
||||||
|
@ -31,26 +32,12 @@ up-to-date. Many thanks.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
/* Edit History
|
|
||||||
|
|
||||||
01/18/91 3 hamilton #if not reparsed
|
|
||||||
01/12/91 2 schulert conditionally use prototypes
|
|
||||||
12/23/90 2 hamilton Fix fd == NULL to fd < 0
|
|
||||||
11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste
|
|
||||||
08/13/90 1 schulert move from ua to omu
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
|
||||||
#ifdef SYSV
|
|
||||||
#include <sys/fcntl.h>
|
|
||||||
#define L_SET SEEK_SET
|
|
||||||
#define L_INCR SEEK_CUR
|
|
||||||
#endif
|
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "gencat.h"
|
#include "gencat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -67,39 +54,25 @@ up-to-date. Many thanks.
|
||||||
* will be in C syntax, in bar.H in C++ syntax.
|
* will be in C syntax, in bar.H in C++ syntax.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if ANSI_C || defined(__cplusplus)
|
static void writeIfChanged(char *, int, int);
|
||||||
# define P_(x) x
|
|
||||||
#else
|
|
||||||
# define P_(x) /**/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void writeIfChanged P_((char *fname, int lang, int orConsts));
|
|
||||||
|
|
||||||
#undef P_
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage()
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: gencat [-new] [-or] [-lang C|C++|ANSIC]\n");
|
fprintf(stderr, "usage: gencat [-new] [-or] [-lang C|C++|ANSIC]\n"
|
||||||
fprintf(stderr, " catfile msgfile [-h <header-file>]...\n");
|
" catfile msgfile [-h <header-file>]...\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(
|
int
|
||||||
#if ANSI_C || defined(__cplusplus)
|
main(int argc, char *argv[])
|
||||||
int argc, char *argv[])
|
|
||||||
#else
|
|
||||||
argc, argv)
|
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int ofd, ifd, i;
|
int ofd, ifd, i;
|
||||||
char *catfile = NULL;
|
char *catfile = NULL;
|
||||||
char *input = NULL;
|
char *input = NULL;
|
||||||
int lang = MCLangC;
|
int lang = MCLangC;
|
||||||
int new = False;
|
int new = FALSE;
|
||||||
int orConsts = False;
|
int orConsts = FALSE;
|
||||||
|
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
if (argv[i][0] == '-') {
|
if (argv[i][0] == '-') {
|
||||||
|
@ -119,7 +92,7 @@ char *argv[];
|
||||||
} else if (strcmp(argv[i], "-new") == 0) {
|
} else if (strcmp(argv[i], "-new") == 0) {
|
||||||
if (catfile)
|
if (catfile)
|
||||||
errx(1, "you must specify -new before the catalog file name");
|
errx(1, "you must specify -new before the catalog file name");
|
||||||
new = True;
|
new = TRUE;
|
||||||
} else if (strcmp(argv[i], "-or") == 0) {
|
} else if (strcmp(argv[i], "-or") == 0) {
|
||||||
orConsts = ~orConsts;
|
orConsts = ~orConsts;
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,20 +131,13 @@ char *argv[];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeIfChanged(
|
static void
|
||||||
#if ANSI_C || defined(__cplusplus)
|
writeIfChanged(char *fname, int lang, int orConsts)
|
||||||
char *fname, int lang, int orConsts)
|
|
||||||
#else
|
|
||||||
fname, lang, orConsts)
|
|
||||||
char *fname;
|
|
||||||
int lang;
|
|
||||||
int orConsts;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
char tmpname[32];
|
char tmpname[32];
|
||||||
char buf[BUFSIZ], tbuf[BUFSIZ], *cptr, *tptr;
|
char buf[BUFSIZ], tbuf[BUFSIZ], *cptr, *tptr;
|
||||||
int fd, tfd;
|
int fd, tfd;
|
||||||
int diff = False;
|
int diff = FALSE;
|
||||||
int len, tlen;
|
int len, tlen;
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
|
|
||||||
|
@ -198,32 +164,32 @@ int orConsts;
|
||||||
errx(1, "unable to read header file: %s", fname);
|
errx(1, "unable to read header file: %s", fname);
|
||||||
|
|
||||||
/* Backup to the start of the temp file */
|
/* Backup to the start of the temp file */
|
||||||
if (lseek(tfd, 0L, L_SET) < 0)
|
if (lseek(tfd, (off_t)0, L_SET) < 0)
|
||||||
errx(1, "unable to seek in tempfile: %s", tmpname);
|
errx(1, "unable to seek in tempfile: %s", tmpname);
|
||||||
|
|
||||||
/* Now compare them */
|
/* Now compare them */
|
||||||
while ((tlen = read(tfd, tbuf, BUFSIZ)) > 0) {
|
while ((tlen = read(tfd, tbuf, BUFSIZ)) > 0) {
|
||||||
if ((len = read(fd, buf, BUFSIZ)) != tlen) {
|
if ((len = read(fd, buf, BUFSIZ)) != tlen) {
|
||||||
diff = True;
|
diff = TRUE;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
for (cptr = buf, tptr = tbuf; cptr < buf+len; ++cptr, ++tptr) {
|
for (cptr = buf, tptr = tbuf; cptr < buf+len; ++cptr, ++tptr) {
|
||||||
if (*tptr != *cptr) {
|
if (*tptr != *cptr) {
|
||||||
diff = True;
|
diff = TRUE;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
if (diff) {
|
if (diff) {
|
||||||
if (lseek(tfd, 0L, L_SET) < 0)
|
if (lseek(tfd, (off_t)0, L_SET) < 0)
|
||||||
errx(1, "unable to seek in tempfile: %s", tmpname);
|
errx(1, "unable to seek in tempfile: %s", tmpname);
|
||||||
close(fd);
|
close(fd);
|
||||||
if ((fd = open(fname, O_WRONLY|O_TRUNC)) < 0)
|
if ((fd = open(fname, O_WRONLY|O_TRUNC)) < 0)
|
||||||
errx(1, "unable to truncate header file: %s", fname);
|
errx(1, "unable to truncate header file: %s", fname);
|
||||||
while ((len = read(tfd, buf, BUFSIZ)) > 0) {
|
while ((len = read(tfd, buf, BUFSIZ)) > 0) {
|
||||||
if (write(fd, buf, len) != len)
|
if (write(fd, buf, (size_t)len) != len)
|
||||||
warnx("error writing to header file: %s", fname);
|
warnx("error writing to header file: %s", fname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
/* $FreeBSD$ */
|
||||||
|
|
||||||
|
#ifndef GENCAT_H
|
||||||
|
#define GENCAT_H
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
||||||
|
@ -31,18 +35,6 @@ up-to-date. Many thanks.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
/* Edit History
|
|
||||||
|
|
||||||
02/25/91 2 nazgul Added MCGetByteOrder
|
|
||||||
01/18/91 2 hamilton #if not reparsed
|
|
||||||
01/12/91 2 schulert conditionally use prototypes
|
|
||||||
11/03/90 1 hamilton Alphalpha->Alfalfa & OmegaMail->Poste
|
|
||||||
08/13/90 1 schulert move from ua to omu
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef gencat_h
|
|
||||||
#define gencat_h
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $set n comment
|
* $set n comment
|
||||||
* My extension: If the comment begins with # treat the next string
|
* My extension: If the comment begins with # treat the next string
|
||||||
|
@ -79,29 +71,17 @@ up-to-date. Many thanks.
|
||||||
|
|
||||||
#define MAXTOKEN 1024
|
#define MAXTOKEN 1024
|
||||||
|
|
||||||
#if !defined(ANSI_C) && (defined(__STDC__) || defined(_AIX))
|
#define TRUE 1
|
||||||
# define ANSI_C 1
|
#define FALSE 0
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ANSI_C || defined(__cplusplus)
|
extern void MCAddSet(int, char *);
|
||||||
# define P_(x) x
|
extern void MCDelSet(int);
|
||||||
#else
|
extern void MCAddMsg(int, const char *, char *);
|
||||||
# define P_(x) /**/
|
extern void MCDelMsg(int);
|
||||||
#endif
|
extern void MCParse(int);
|
||||||
|
extern void MCReadCat(int);
|
||||||
|
extern void MCWriteConst(int, int, int);
|
||||||
|
extern void MCWriteCat(int);
|
||||||
|
extern long MCGetByteOrder(void);
|
||||||
|
|
||||||
extern void MCAddSet P_((int setId, char *c));
|
#endif /* GENCAT_H */
|
||||||
extern void MCDelSet P_((int setId));
|
|
||||||
extern void MCAddMsg P_((int msgId, char *msg, char *c));
|
|
||||||
extern void MCDelMsg P_((int msgId));
|
|
||||||
extern void MCParse P_((int fd));
|
|
||||||
extern void MCReadCat P_((int fd));
|
|
||||||
extern void MCWriteConst P_((int fd, int type, int orConsts));
|
|
||||||
extern void MCWriteCat P_((int fd));
|
|
||||||
extern long MCGetByteOrder P_((void));
|
|
||||||
|
|
||||||
#ifndef True
|
|
||||||
# define True ~0
|
|
||||||
# define False 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/* -*-c++-*- */
|
/* $FreeBSD$ */
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts.
|
||||||
|
@ -31,50 +30,24 @@ up-to-date. Many thanks.
|
||||||
Cambridge, MA 02139 USA
|
Cambridge, MA 02139 USA
|
||||||
nazgul@alfalfa.com
|
nazgul@alfalfa.com
|
||||||
|
|
||||||
$FreeBSD$
|
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
/* Edit History
|
#include <sys/types.h>
|
||||||
|
#include <sys/file.h>
|
||||||
02/25/91 5 nazgul Added flag for MS byteorder
|
#include <err.h>
|
||||||
01/14/91 4 nazgul Off by one on number specified entries
|
#include <ctype.h>
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef SYSV
|
|
||||||
#define L_SET SEEK_SET
|
|
||||||
#define L_INCR SEEK_CUR
|
|
||||||
#include <memory.h>
|
|
||||||
static int bcopy(src, dst, length)
|
|
||||||
char *src, *dst;
|
|
||||||
int length;
|
|
||||||
{
|
|
||||||
memcpy(dst, src, length);
|
|
||||||
}
|
|
||||||
static int bzero(b, length)
|
|
||||||
char *b;
|
|
||||||
int length;
|
|
||||||
{
|
|
||||||
memset(b, '\0', length);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#include <sys/file.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <err.h>
|
|
||||||
#include "msgcat.h"
|
#include "msgcat.h"
|
||||||
#include "gencat.h"
|
#include "gencat.h"
|
||||||
|
|
||||||
static char *curline = NULL;
|
static char *curline = NULL;
|
||||||
static long lineno = 0;
|
static long lineno = 0;
|
||||||
|
|
||||||
static void warning(cptr, msg)
|
static void
|
||||||
char *cptr;
|
warning(char *cptr, const char *msg)
|
||||||
char *msg;
|
|
||||||
{
|
{
|
||||||
warnx("%s on line %ld\n%s", msg, lineno, curline);
|
warnx("%s on line %ld\n%s", msg, lineno, curline);
|
||||||
if (cptr) {
|
if (cptr) {
|
||||||
|
@ -84,25 +57,27 @@ char *msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void error(cptr, msg)
|
static void
|
||||||
char *cptr;
|
error(char *cptr, const char *msg)
|
||||||
char *msg;
|
|
||||||
{
|
{
|
||||||
warning(cptr, msg);
|
warning(cptr, msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void corrupt() {
|
static void
|
||||||
|
corrupt(void) {
|
||||||
error(NULL, "corrupt message catalog");
|
error(NULL, "corrupt message catalog");
|
||||||
}
|
}
|
||||||
static void nomem() {
|
|
||||||
|
static void
|
||||||
|
nomem(void) {
|
||||||
error(NULL, "out of memory");
|
error(NULL, "out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *getline(fd)
|
static char *
|
||||||
int fd;
|
getline(int fd)
|
||||||
{
|
{
|
||||||
static long curlen = BUFSIZ;
|
static size_t curlen = BUFSIZ;
|
||||||
static char buf[BUFSIZ], *bptr = buf, *bend = buf;
|
static char buf[BUFSIZ], *bptr = buf, *bend = buf;
|
||||||
char *cptr, *cend;
|
char *cptr, *cend;
|
||||||
long buflen;
|
long buflen;
|
||||||
|
@ -115,7 +90,7 @@ int fd;
|
||||||
|
|
||||||
cptr = curline;
|
cptr = curline;
|
||||||
cend = curline + curlen;
|
cend = curline + curlen;
|
||||||
while (True) {
|
while (TRUE) {
|
||||||
for (; bptr < bend && cptr < cend; ++cptr, ++bptr) {
|
for (; bptr < bend && cptr < cend; ++cptr, ++bptr) {
|
||||||
if (*bptr == '\n') {
|
if (*bptr == '\n') {
|
||||||
*cptr = '\0';
|
*cptr = '\0';
|
||||||
|
@ -142,9 +117,8 @@ int fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
static char *token(cptr)
|
token(char *cptr)
|
||||||
char *cptr;
|
|
||||||
{
|
{
|
||||||
static char tok[MAXTOKEN+1];
|
static char tok[MAXTOKEN+1];
|
||||||
char *tptr = tok;
|
char *tptr = tok;
|
||||||
|
@ -154,8 +128,9 @@ char *cptr;
|
||||||
*tptr = '\0';
|
*tptr = '\0';
|
||||||
return(tok);
|
return(tok);
|
||||||
}
|
}
|
||||||
static char *wskip(cptr)
|
|
||||||
char *cptr;
|
static char *
|
||||||
|
wskip(char *cptr)
|
||||||
{
|
{
|
||||||
if (!*cptr || !isspace((unsigned char)*cptr)) {
|
if (!*cptr || !isspace((unsigned char)*cptr)) {
|
||||||
warning(cptr, "expected a space");
|
warning(cptr, "expected a space");
|
||||||
|
@ -164,8 +139,9 @@ char *cptr;
|
||||||
while (*cptr && isspace((unsigned char)*cptr)) ++cptr;
|
while (*cptr && isspace((unsigned char)*cptr)) ++cptr;
|
||||||
return(cptr);
|
return(cptr);
|
||||||
}
|
}
|
||||||
static char *cskip(cptr)
|
|
||||||
char *cptr;
|
static char *
|
||||||
|
cskip(char *cptr)
|
||||||
{
|
{
|
||||||
if (!*cptr || isspace((unsigned char)*cptr)) {
|
if (!*cptr || isspace((unsigned char)*cptr)) {
|
||||||
warning(cptr, "wasn't expecting a space");
|
warning(cptr, "wasn't expecting a space");
|
||||||
|
@ -175,22 +151,19 @@ char *cptr;
|
||||||
return(cptr);
|
return(cptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *getmsg(fd, cptr, quote)
|
static char *
|
||||||
int fd;
|
getmsg(int fd, char *cptr, char quote)
|
||||||
char *cptr;
|
|
||||||
char quote;
|
|
||||||
{
|
{
|
||||||
static char *msg = NULL;
|
static char *msg = NULL;
|
||||||
static long msglen = 0;
|
static size_t msglen = 0;
|
||||||
long clen, i;
|
size_t clen, i;
|
||||||
char *tptr;
|
char *tptr;
|
||||||
|
int needq;
|
||||||
int needq;
|
|
||||||
|
|
||||||
if (quote && *cptr == quote) {
|
if (quote && *cptr == quote) {
|
||||||
needq = True;
|
needq = TRUE;
|
||||||
++cptr;
|
++cptr;
|
||||||
} else needq = False;
|
} else needq = FALSE;
|
||||||
|
|
||||||
clen = strlen(cptr) + 1;
|
clen = strlen(cptr) + 1;
|
||||||
if (clen > msglen) {
|
if (clen > msglen) {
|
||||||
|
@ -205,7 +178,7 @@ char quote;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
tmp = cptr+1;
|
tmp = cptr+1;
|
||||||
if (*tmp && (!isspace((unsigned char)*tmp) || *wskip(tmp))) {
|
if (*tmp && (!isspace((unsigned char)*tmp) || *wskip(tmp))) {
|
||||||
warning(cptr, "unexpected quote character, ignoreing");
|
warning(cptr, "unexpected quote character, ignoring");
|
||||||
*tptr++ = *cptr++;
|
*tptr++ = *cptr++;
|
||||||
} else {
|
} else {
|
||||||
*cptr = '\0';
|
*cptr = '\0';
|
||||||
|
@ -221,42 +194,23 @@ char quote;
|
||||||
msg = (char *) realloc(msg, msglen);
|
msg = (char *) realloc(msg, msglen);
|
||||||
tptr = msg + i;
|
tptr = msg + i;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
|
||||||
*tptr++ = '\n';
|
#define CASEOF(CS, CH) \
|
||||||
++cptr;
|
case CS: \
|
||||||
break;
|
*tptr++ = CH; \
|
||||||
case 't':
|
++cptr; \
|
||||||
*tptr++ = '\t';
|
|
||||||
++cptr;
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
*tptr++ = '\v';
|
|
||||||
++cptr;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
*tptr++ = '\b';
|
|
||||||
++cptr;
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
*tptr++ = '\r';
|
|
||||||
++cptr;
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
*tptr++ = '\f';
|
|
||||||
++cptr;
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
*tptr++ = '"';
|
|
||||||
++cptr;
|
|
||||||
break;
|
|
||||||
case '\'':
|
|
||||||
*tptr++ = '\'';
|
|
||||||
++cptr;
|
|
||||||
break;
|
|
||||||
case '\\':
|
|
||||||
*tptr++ = '\\';
|
|
||||||
++cptr;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
CASEOF('n', '\n')
|
||||||
|
CASEOF('t', '\t')
|
||||||
|
CASEOF('v', '\v')
|
||||||
|
CASEOF('b', '\b')
|
||||||
|
CASEOF('r', '\r')
|
||||||
|
CASEOF('f', '\f')
|
||||||
|
CASEOF('"', '"')
|
||||||
|
CASEOF('\'', '\'')
|
||||||
|
CASEOF('\\', '\\')
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (isdigit((unsigned char)*cptr)) {
|
if (isdigit((unsigned char)*cptr)) {
|
||||||
*tptr = 0;
|
*tptr = 0;
|
||||||
|
@ -280,25 +234,20 @@ char quote;
|
||||||
return(msg);
|
return(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
dupstr(const char *ostr)
|
||||||
static char *dupstr(ostr)
|
|
||||||
char *ostr;
|
|
||||||
{
|
{
|
||||||
char *nstr;
|
char *nstr;
|
||||||
|
|
||||||
nstr = (char *) malloc(strlen(ostr) + 1);
|
nstr = strdup(ostr);
|
||||||
if (!nstr) error(NULL, "unable to allocate storage");
|
if (!nstr) error(NULL, "unable to allocate storage");
|
||||||
strcpy(nstr, ostr);
|
|
||||||
return(nstr);
|
return(nstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The Global Stuff
|
* The Global Stuff
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
typedef struct _msgT {
|
typedef struct _msgT {
|
||||||
long msgId;
|
long msgId;
|
||||||
char *str;
|
char *str;
|
||||||
|
@ -306,12 +255,14 @@ typedef struct _msgT {
|
||||||
long offset;
|
long offset;
|
||||||
struct _msgT *prev, *next;
|
struct _msgT *prev, *next;
|
||||||
} msgT;
|
} msgT;
|
||||||
|
|
||||||
typedef struct _setT {
|
typedef struct _setT {
|
||||||
long setId;
|
long setId;
|
||||||
char *hconst;
|
char *hconst;
|
||||||
msgT *first, *last;
|
msgT *first, *last;
|
||||||
struct _setT *prev, *next;
|
struct _setT *prev, *next;
|
||||||
} setT;
|
} setT;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
setT *first, *last;
|
setT *first, *last;
|
||||||
} catT;
|
} catT;
|
||||||
|
@ -320,10 +271,11 @@ static setT *curSet;
|
||||||
static catT *cat;
|
static catT *cat;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the current byte order. There are of course some others, but this will do
|
* Find the current byte order. There are of course some others, but
|
||||||
* for now. Note that all we care about is "long".
|
* this will do for now. Note that all we care about is "long".
|
||||||
*/
|
*/
|
||||||
long MCGetByteOrder() {
|
long
|
||||||
|
MCGetByteOrder(void) {
|
||||||
long l = 0x00010203;
|
long l = 0x00010203;
|
||||||
char *cptr = (char *) &l;
|
char *cptr = (char *) &l;
|
||||||
|
|
||||||
|
@ -332,17 +284,11 @@ long MCGetByteOrder() {
|
||||||
else return MCn86ByteOrder;
|
else return MCn86ByteOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
void MCParse(
|
MCParse(int fd)
|
||||||
#if PROTO
|
|
||||||
int fd)
|
|
||||||
#else
|
|
||||||
fd)
|
|
||||||
int fd;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
char *cptr, *str;
|
char *cptr, *str;
|
||||||
int setid, msgid = 0;
|
int setid, msgid = 0;
|
||||||
char hconst[MAXTOKEN+1];
|
char hconst[MAXTOKEN+1];
|
||||||
char quote = 0;
|
char quote = 0;
|
||||||
|
|
||||||
|
@ -354,7 +300,7 @@ int fd;
|
||||||
|
|
||||||
hconst[0] = '\0';
|
hconst[0] = '\0';
|
||||||
|
|
||||||
while (cptr = getline(fd)) {
|
while ((cptr = getline(fd)) != NULL) {
|
||||||
if (*cptr == '$') {
|
if (*cptr == '$') {
|
||||||
++cptr;
|
++cptr;
|
||||||
if (strncmp(cptr, "set", 3) == 0) {
|
if (strncmp(cptr, "set", 3) == 0) {
|
||||||
|
@ -427,13 +373,8 @@ int fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCReadCat(
|
void
|
||||||
#if PROTO
|
MCReadCat(int fd)
|
||||||
int fd)
|
|
||||||
#else
|
|
||||||
fd)
|
|
||||||
int fd;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
MCHeaderT mcHead;
|
MCHeaderT mcHead;
|
||||||
MCMsgT mcMsg;
|
MCMsgT mcMsg;
|
||||||
|
@ -454,7 +395,7 @@ int fd;
|
||||||
|
|
||||||
if (lseek(fd, mcHead.firstSet, L_SET) == -1) corrupt();
|
if (lseek(fd, mcHead.firstSet, L_SET) == -1) corrupt();
|
||||||
|
|
||||||
while (True) {
|
while (TRUE) {
|
||||||
if (read(fd, &mcSet, sizeof(mcSet)) != sizeof(mcSet)) corrupt();
|
if (read(fd, &mcSet, sizeof(mcSet)) != sizeof(mcSet)) corrupt();
|
||||||
if (mcSet.invalid) continue;
|
if (mcSet.invalid) continue;
|
||||||
|
|
||||||
|
@ -471,10 +412,10 @@ int fd;
|
||||||
|
|
||||||
/* Get the data */
|
/* Get the data */
|
||||||
if (mcSet.dataLen) {
|
if (mcSet.dataLen) {
|
||||||
data = (char *) malloc(mcSet.dataLen);
|
data = (char *) malloc((size_t)mcSet.dataLen);
|
||||||
if (!data) nomem();
|
if (!data) nomem();
|
||||||
if (lseek(fd, mcSet.data.off, L_SET) == -1) corrupt();
|
if (lseek(fd, mcSet.data.off, L_SET) == -1) corrupt();
|
||||||
if (read(fd, data, mcSet.dataLen) != mcSet.dataLen) corrupt();
|
if (read(fd, data, (size_t)mcSet.dataLen) != mcSet.dataLen) corrupt();
|
||||||
if (lseek(fd, mcSet.u.firstMsg, L_SET) == -1) corrupt();
|
if (lseek(fd, mcSet.u.firstMsg, L_SET) == -1) corrupt();
|
||||||
|
|
||||||
for (i = 0; i < mcSet.numMsgs; ++i) {
|
for (i = 0; i < mcSet.numMsgs; ++i) {
|
||||||
|
@ -504,35 +445,30 @@ int fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void printS(fd, str)
|
static void
|
||||||
int fd;
|
printS(int fd, const char *str)
|
||||||
char *str;
|
|
||||||
{
|
{
|
||||||
write(fd, str, strlen(str));
|
write(fd, str, strlen(str));
|
||||||
}
|
}
|
||||||
static void printL(fd, l)
|
|
||||||
int fd;
|
static void
|
||||||
long l;
|
printL(int fd, long l)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
sprintf(buf, "%ld", l);
|
sprintf(buf, "%ld", l);
|
||||||
write(fd, buf, strlen(buf));
|
write(fd, buf, strlen(buf));
|
||||||
}
|
}
|
||||||
static void printLX(fd, l)
|
|
||||||
int fd;
|
static void
|
||||||
long l;
|
printLX(int fd, long l)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
sprintf(buf, "%lx", l);
|
sprintf(buf, "%lx", l);
|
||||||
write(fd, buf, strlen(buf));
|
write(fd, buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void genconst(fd, type, setConst, msgConst, val)
|
static void
|
||||||
int fd;
|
genconst(int fd, int type, char *setConst, char *msgConst, long val)
|
||||||
int type;
|
|
||||||
char *setConst;
|
|
||||||
char *msgConst;
|
|
||||||
long val;
|
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MCLangC:
|
case MCLangC:
|
||||||
|
@ -569,15 +505,8 @@ long val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCWriteConst(
|
void
|
||||||
#if PROTO
|
MCWriteConst(int fd, int type, int orConsts)
|
||||||
int fd, int type, int orConsts)
|
|
||||||
#else
|
|
||||||
fd, type, orConsts)
|
|
||||||
int fd;
|
|
||||||
int type;
|
|
||||||
int orConsts;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
msgT *msg;
|
msgT *msg;
|
||||||
setT *set;
|
setT *set;
|
||||||
|
@ -613,13 +542,8 @@ int orConsts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCWriteCat(
|
void
|
||||||
#if PROTO
|
MCWriteCat(int fd)
|
||||||
int fd)
|
|
||||||
#else
|
|
||||||
fd)
|
|
||||||
int fd;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
MCHeaderT mcHead;
|
MCHeaderT mcHead;
|
||||||
int cnt;
|
int cnt;
|
||||||
|
@ -638,38 +562,38 @@ int fd;
|
||||||
for (cnt = 0, set = cat->first; set; set = set->next) ++cnt;
|
for (cnt = 0, set = cat->first; set; set = set->next) ++cnt;
|
||||||
mcHead.numSets = cnt;
|
mcHead.numSets = cnt;
|
||||||
|
|
||||||
lseek(fd, 0L, L_SET);
|
lseek(fd, (off_t)0L, L_SET);
|
||||||
write(fd, &mcHead, sizeof(mcHead));
|
write(fd, &mcHead, sizeof(mcHead));
|
||||||
mcHead.firstSet = lseek(fd, 0, L_INCR);
|
mcHead.firstSet = lseek(fd, (off_t)0L, L_INCR);
|
||||||
lseek(fd, 0L, L_SET);
|
lseek(fd, (off_t)0L, L_SET);
|
||||||
write(fd, &mcHead, sizeof(mcHead));
|
write(fd, &mcHead, sizeof(mcHead));
|
||||||
|
|
||||||
for (set = cat->first; set; set = set->next) {
|
for (set = cat->first; set; set = set->next) {
|
||||||
bzero(&mcSet, sizeof(mcSet));
|
bzero(&mcSet, sizeof(mcSet));
|
||||||
|
|
||||||
mcSet.setId = set->setId;
|
mcSet.setId = set->setId;
|
||||||
mcSet.invalid = False;
|
mcSet.invalid = FALSE;
|
||||||
|
|
||||||
/* The rest we'll have to come back and change in a moment */
|
/* The rest we'll have to come back and change in a moment */
|
||||||
pos = lseek(fd, 0, L_INCR);
|
pos = lseek(fd, (off_t)0L, L_INCR);
|
||||||
write(fd, &mcSet, sizeof(mcSet));
|
write(fd, &mcSet, sizeof(mcSet));
|
||||||
|
|
||||||
/* Now write all the string data */
|
/* Now write all the string data */
|
||||||
mcSet.data.off = lseek(fd, 0, L_INCR);
|
mcSet.data.off = lseek(fd, (off_t)0L, L_INCR);
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
for (msg = set->first; msg; msg = msg->next) {
|
for (msg = set->first; msg; msg = msg->next) {
|
||||||
msg->offset = lseek(fd, 0, L_INCR) - mcSet.data.off;
|
msg->offset = lseek(fd, (off_t)0L, L_INCR) - mcSet.data.off;
|
||||||
mcSet.dataLen += write(fd, msg->str, strlen(msg->str) + 1);
|
mcSet.dataLen += write(fd, msg->str, strlen(msg->str) + 1);
|
||||||
++cnt;
|
++cnt;
|
||||||
}
|
}
|
||||||
mcSet.u.firstMsg = lseek(fd, 0, L_INCR);
|
mcSet.u.firstMsg = lseek(fd, (off_t)0L, L_INCR);
|
||||||
mcSet.numMsgs = cnt;
|
mcSet.numMsgs = cnt;
|
||||||
|
|
||||||
/* Now write the message headers */
|
/* Now write the message headers */
|
||||||
for (msg = set->first; msg; msg = msg->next) {
|
for (msg = set->first; msg; msg = msg->next) {
|
||||||
mcMsg.msgId = msg->msgId;
|
mcMsg.msgId = msg->msgId;
|
||||||
mcMsg.msg.off = msg->offset;
|
mcMsg.msg.off = msg->offset;
|
||||||
mcMsg.invalid = False;
|
mcMsg.invalid = FALSE;
|
||||||
write(fd, &mcMsg, sizeof(mcMsg));
|
write(fd, &mcMsg, sizeof(mcMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,7 +604,7 @@ int fd;
|
||||||
lseek(fd, pos, L_SET);
|
lseek(fd, pos, L_SET);
|
||||||
write(fd, &mcSet, sizeof(mcSet));
|
write(fd, &mcSet, sizeof(mcSet));
|
||||||
} else {
|
} else {
|
||||||
mcSet.nextSet = lseek(fd, 0, L_INCR);
|
mcSet.nextSet = lseek(fd, (off_t)0L, L_INCR);
|
||||||
lseek(fd, pos, L_SET);
|
lseek(fd, pos, L_SET);
|
||||||
write(fd, &mcSet, sizeof(mcSet));
|
write(fd, &mcSet, sizeof(mcSet));
|
||||||
lseek(fd, mcSet.nextSet, L_SET);
|
lseek(fd, mcSet.nextSet, L_SET);
|
||||||
|
@ -688,15 +612,8 @@ int fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
void MCAddSet(
|
MCAddSet(int setId, char *hconst)
|
||||||
#if PROTO
|
|
||||||
int setId, char *hconst)
|
|
||||||
#else
|
|
||||||
setId, hconst)
|
|
||||||
int setId;
|
|
||||||
char *hconst;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
setT *set;
|
setT *set;
|
||||||
|
|
||||||
|
@ -746,19 +663,13 @@ char *hconst;
|
||||||
curSet = set;
|
curSet = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCAddMsg(
|
void
|
||||||
#if PROTO
|
MCAddMsg(int msgId, const char *str, char *hconst)
|
||||||
int msgId, char *str, char *hconst)
|
|
||||||
#else
|
|
||||||
msgId, str, hconst)
|
|
||||||
int msgId;
|
|
||||||
char *str;
|
|
||||||
char *hconst;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
msgT *msg;
|
msgT *msg;
|
||||||
|
|
||||||
if (!curSet) error(NULL, "can't specify a message when no set exists");
|
if (!curSet)
|
||||||
|
error(NULL, "can't specify a message when no set exists");
|
||||||
|
|
||||||
if (msgId <= 0) {
|
if (msgId <= 0) {
|
||||||
error(NULL, "msgId's must be greater than zero");
|
error(NULL, "msgId's must be greater than zero");
|
||||||
|
@ -807,13 +718,8 @@ char *hconst;
|
||||||
msg->str = dupstr(str);
|
msg->str = dupstr(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCDelSet(
|
void
|
||||||
#if PROTO
|
MCDelSet(int setId)
|
||||||
int setId)
|
|
||||||
#else
|
|
||||||
setId)
|
|
||||||
int setId;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
setT *set;
|
setT *set;
|
||||||
msgT *msg;
|
msgT *msg;
|
||||||
|
@ -840,17 +746,13 @@ int setId;
|
||||||
warning(NULL, "specified set doesn't exist");
|
warning(NULL, "specified set doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCDelMsg(
|
void
|
||||||
#if PROTO
|
MCDelMsg(int msgId)
|
||||||
int msgId)
|
|
||||||
#else
|
|
||||||
msgId)
|
|
||||||
int msgId;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
msgT *msg;
|
msgT *msg;
|
||||||
|
|
||||||
if (!curSet) error(NULL, "you can't delete a message before defining the set");
|
if (!curSet)
|
||||||
|
error(NULL, "you can't delete a message before defining the set");
|
||||||
|
|
||||||
for (msg = curSet->first; msg; msg = msg->next) {
|
for (msg = curSet->first; msg; msg = msg->next) {
|
||||||
if (msg->msgId == msgId) {
|
if (msg->msgId == msgId) {
|
||||||
|
@ -870,14 +772,17 @@ int msgId;
|
||||||
warning(NULL, "specified msg doesn't exist");
|
warning(NULL, "specified msg doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCDumpcat(fp)
|
#if 0 /* this function is unsed and looks like debug thing */
|
||||||
|
|
||||||
|
void
|
||||||
|
MCDumpcat(fp)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
{
|
{
|
||||||
msgT *msg;
|
msgT *msg;
|
||||||
setT *set;
|
setT *set;
|
||||||
|
|
||||||
if (!cat)
|
if (!cat)
|
||||||
errx(1, "no catalog open");
|
errx(1, "no catalog open");
|
||||||
|
|
||||||
for (set = cat->first; set; set = set->next) {
|
for (set = cat->first; set; set = set->next) {
|
||||||
fprintf(fp, "$set %ld", set->setId);
|
fprintf(fp, "$set %ld", set->setId);
|
||||||
|
@ -894,3 +799,4 @@ FILE *fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif /* 0 */
|
||||||
|
|
Loading…
Reference in a new issue