WARNS=3
This commit is contained in:
parent
4acb374aa2
commit
97ccbe263d
|
@ -1,8 +1,8 @@
|
|||
# $NetBSD: Makefile,v 1.1 2005/06/29 20:58:50 perry Exp $
|
||||
# $NetBSD: Makefile,v 1.2 2005/06/30 16:23:29 christos Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# OpenBSD: Makefile,v 1.1 2002/02/28 06:58:21 millert Exp
|
||||
|
||||
PROG= deroff
|
||||
WARNS= 0
|
||||
WARNS= 3
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: deroff.c,v 1.1 2005/06/29 20:58:50 perry Exp $ */
|
||||
/* $NetBSD: deroff.c,v 1.2 2005/06/30 16:23:29 christos Exp $ */
|
||||
|
||||
/* taken from: OpenBSD: deroff.c,v 1.6 2004/06/02 14:58:46 tom Exp */
|
||||
|
||||
|
@ -74,7 +74,7 @@ static const char copyright[] =
|
|||
#if 0
|
||||
static const char sccsid[] = "@(#)deroff.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
static const char rcsid[] = "$NetBSD: deroff.c,v 1.1 2005/06/29 20:58:50 perry Exp $";
|
||||
static const char rcsid[] = "$NetBSD: deroff.c,v 1.2 2005/06/30 16:23:29 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -139,33 +139,33 @@ char *mactab[] = { "-ms", "-mm", "-me", "-ma" };
|
|||
|
||||
#define MAXFILES 20
|
||||
|
||||
int iflag;
|
||||
int wordflag;
|
||||
int msflag; /* processing a source written using a mac package */
|
||||
int mac; /* which package */
|
||||
int disp;
|
||||
int parag;
|
||||
int inmacro;
|
||||
int intable;
|
||||
int keepblock; /* keep blocks of text; normally false when msflag */
|
||||
static int iflag;
|
||||
static int wordflag;
|
||||
static int msflag; /* processing a source written using a mac package */
|
||||
static int mac; /* which package */
|
||||
static int disp;
|
||||
static int parag;
|
||||
static int inmacro;
|
||||
static int intable;
|
||||
static int keepblock; /* keep blocks of text; normally false when msflag */
|
||||
|
||||
char chars[128]; /* SPECIAL, PUNCT, APOS, DIGIT, or LETTER */
|
||||
static char chars[128]; /* SPECIAL, PUNCT, APOS, DIGIT, or LETTER */
|
||||
|
||||
char line[LINE_MAX];
|
||||
char *lp;
|
||||
static char line[LINE_MAX];
|
||||
static char *lp;
|
||||
|
||||
int c;
|
||||
int pc;
|
||||
int ldelim;
|
||||
int rdelim;
|
||||
static int c;
|
||||
static int pc;
|
||||
static int ldelim;
|
||||
static int rdelim;
|
||||
|
||||
char fname[PATH_MAX];
|
||||
FILE *files[MAXFILES];
|
||||
FILE **filesp;
|
||||
FILE *infile;
|
||||
static char fname[PATH_MAX];
|
||||
static FILE *files[MAXFILES];
|
||||
static FILE **filesp;
|
||||
static FILE *infile;
|
||||
|
||||
int argc;
|
||||
char **argv;
|
||||
static int argc;
|
||||
static char **argv;
|
||||
|
||||
/*
|
||||
* Macro processing
|
||||
|
@ -173,23 +173,23 @@ char **argv;
|
|||
* Macro table definitions
|
||||
*/
|
||||
typedef int pacmac; /* compressed macro name */
|
||||
int argconcat = 0; /* concat arguments together (-me only) */
|
||||
static int argconcat = 0; /* concat arguments together (-me only) */
|
||||
|
||||
#define tomac(c1, c2) ((((c1) & 0xFF) << 8) | ((c2) & 0xFF))
|
||||
#define frommac(src, c1, c2) (((c1)=((src)>>8)&0xFF),((c2) =(src)&0xFF))
|
||||
|
||||
struct mactab{
|
||||
struct mactab {
|
||||
int condition;
|
||||
pacmac macname;
|
||||
int (*func)(); /* XXX - args */
|
||||
int (*func)(pacmac);
|
||||
};
|
||||
|
||||
struct mactab troffmactab[];
|
||||
struct mactab ppmactab[];
|
||||
struct mactab msmactab[];
|
||||
struct mactab mmmactab[];
|
||||
struct mactab memactab[];
|
||||
struct mactab manmactab[];
|
||||
static const struct mactab troffmactab[];
|
||||
static const struct mactab ppmactab[];
|
||||
static const struct mactab msmactab[];
|
||||
static const struct mactab mmmactab[];
|
||||
static const struct mactab memactab[];
|
||||
static const struct mactab manmactab[];
|
||||
|
||||
/*
|
||||
* Macro table initialization
|
||||
|
@ -215,59 +215,61 @@ struct mactab manmactab[];
|
|||
#define COMX 1 /* goto comx */
|
||||
#define COM 2 /* goto com */
|
||||
|
||||
int skeqn(void);
|
||||
int eof(void);
|
||||
int _C1(void);
|
||||
int _C(void);
|
||||
int EQ(void);
|
||||
int domacro(void);
|
||||
int PS(void);
|
||||
int skip(void);
|
||||
int intbl(void);
|
||||
int outtbl(void);
|
||||
int so(void);
|
||||
int nx(void);
|
||||
int skiptocom(void);
|
||||
int PP(pacmac);
|
||||
int AU(void);
|
||||
int SH(pacmac);
|
||||
int UX(void);
|
||||
int MMHU(pacmac);
|
||||
int mesnblock(pacmac);
|
||||
int mssnblock(pacmac);
|
||||
int nf(void);
|
||||
int ce(void);
|
||||
int meip(pacmac);
|
||||
int mepp(pacmac);
|
||||
int mesh(pacmac);
|
||||
int mefont(pacmac);
|
||||
int manfont(pacmac);
|
||||
int manpp(pacmac);
|
||||
int macsort(const void *, const void *);
|
||||
int sizetab(struct mactab *);
|
||||
void getfname(void);
|
||||
void textline(char *, int);
|
||||
void work(void);
|
||||
void regline(void (*)(char *, int), int);
|
||||
void macro(void);
|
||||
void tbl(void);
|
||||
void stbl(void);
|
||||
void eqn(void);
|
||||
void backsl(void);
|
||||
void sce(void);
|
||||
void refer(int);
|
||||
void inpic(void);
|
||||
void msputmac(char *, int);
|
||||
void msputwords(int);
|
||||
void meputmac(char *, int);
|
||||
void meputwords(int);
|
||||
void noblock(char, char);
|
||||
void defcomline(pacmac);
|
||||
void comline(void);
|
||||
void buildtab(struct mactab **, int *);
|
||||
FILE *opn(char *);
|
||||
struct mactab *macfill(struct mactab *, struct mactab *);
|
||||
__dead void usage(void);
|
||||
static int skeqn(void);
|
||||
static int eof(void);
|
||||
#ifdef DEBUG
|
||||
static int _C1(void);
|
||||
static int _C(void);
|
||||
#endif
|
||||
static int EQ(pacmac);
|
||||
static int domacro(pacmac);
|
||||
static int PS(pacmac);
|
||||
static int skip(pacmac);
|
||||
static int intbl(pacmac);
|
||||
static int outtbl(pacmac);
|
||||
static int so(pacmac);
|
||||
static int nx(pacmac);
|
||||
static int skiptocom(pacmac);
|
||||
static int PP(pacmac);
|
||||
static int AU(pacmac);
|
||||
static int SH(pacmac);
|
||||
static int UX(pacmac);
|
||||
static int MMHU(pacmac);
|
||||
static int mesnblock(pacmac);
|
||||
static int mssnblock(pacmac);
|
||||
static int nf(pacmac);
|
||||
static int ce(pacmac);
|
||||
static int meip(pacmac);
|
||||
static int mepp(pacmac);
|
||||
static int mesh(pacmac);
|
||||
static int mefont(pacmac);
|
||||
static int manfont(pacmac);
|
||||
static int manpp(pacmac);
|
||||
static int macsort(const void *, const void *);
|
||||
static int sizetab(const struct mactab *);
|
||||
static void getfname(void);
|
||||
static void textline(char *, int);
|
||||
static void work(void);
|
||||
static void regline(void (*)(char *, int), int);
|
||||
static void macro(void);
|
||||
static void tbl(void);
|
||||
static void stbl(void);
|
||||
static void eqn(void);
|
||||
static void backsl(void);
|
||||
static void sce(void);
|
||||
static void refer(int);
|
||||
static void inpic(void);
|
||||
static void msputmac(char *, int);
|
||||
static void msputwords(int);
|
||||
static void meputmac(char *, int);
|
||||
static void meputwords(int);
|
||||
static void noblock(char, char);
|
||||
static void defcomline(pacmac);
|
||||
static void comline(void);
|
||||
static void buildtab(const struct mactab **, int *);
|
||||
static FILE *opn(char *);
|
||||
static struct mactab *macfill(struct mactab *, const struct mactab *);
|
||||
static void usage(void) __attribute__((__noreturn__));
|
||||
|
||||
int
|
||||
main(int ac, char **av)
|
||||
|
@ -369,10 +371,10 @@ main(int ac, char **av)
|
|||
chars['?'] = PUNCT;
|
||||
chars[':'] = PUNCT;
|
||||
work();
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
skeqn(void)
|
||||
{
|
||||
|
||||
|
@ -388,11 +390,11 @@ skeqn(void)
|
|||
}
|
||||
}
|
||||
if (msflag)
|
||||
return((c = 'x'));
|
||||
return((c = ' '));
|
||||
return c == 'x';
|
||||
return c == ' ';
|
||||
}
|
||||
|
||||
FILE *
|
||||
static FILE *
|
||||
opn(char *p)
|
||||
{
|
||||
FILE *fd;
|
||||
|
@ -400,10 +402,10 @@ opn(char *p)
|
|||
if ((fd = fopen(p, "r")) == NULL)
|
||||
err(1, "fopen %s", p);
|
||||
|
||||
return(fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
eof(void)
|
||||
{
|
||||
|
||||
|
@ -417,10 +419,10 @@ eof(void)
|
|||
++argv;
|
||||
} else
|
||||
exit(0);
|
||||
return(C);
|
||||
return C;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
getfname(void)
|
||||
{
|
||||
char *p;
|
||||
|
@ -458,7 +460,7 @@ getfname(void)
|
|||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
static void
|
||||
textline(char *str, int constant)
|
||||
{
|
||||
|
||||
|
@ -485,7 +487,7 @@ work(void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
regline(void (*pfunc)(char *, int), int constant)
|
||||
{
|
||||
|
||||
|
@ -514,7 +516,7 @@ regline(void (*pfunc)(char *, int), int constant)
|
|||
(*pfunc)(line, constant);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
macro(void)
|
||||
{
|
||||
|
||||
|
@ -530,7 +532,7 @@ macro(void)
|
|||
inmacro = YES;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
tbl(void)
|
||||
{
|
||||
|
||||
|
@ -540,7 +542,7 @@ tbl(void)
|
|||
intable = YES;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
stbl(void)
|
||||
{
|
||||
|
||||
|
@ -555,7 +557,7 @@ stbl(void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
eqn(void)
|
||||
{
|
||||
int c1, c2;
|
||||
|
@ -613,7 +615,7 @@ eqn(void)
|
|||
}
|
||||
|
||||
/* skip over a complete backslash construction */
|
||||
void
|
||||
static void
|
||||
backsl(void)
|
||||
{
|
||||
int bdelim;
|
||||
|
@ -686,7 +688,7 @@ sw:
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
sce(void)
|
||||
{
|
||||
char *ap;
|
||||
|
@ -732,7 +734,7 @@ sce(void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
refer(int c1)
|
||||
{
|
||||
int c2;
|
||||
|
@ -757,7 +759,7 @@ refer(int c1)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
inpic(void)
|
||||
{
|
||||
int c1;
|
||||
|
@ -816,25 +818,25 @@ inpic(void)
|
|||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
int
|
||||
static int
|
||||
_C1(void)
|
||||
{
|
||||
|
||||
return(C1get);
|
||||
return C1get);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
_C(void)
|
||||
{
|
||||
|
||||
return(Cget);
|
||||
return Cget);
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
/*
|
||||
* Put out a macro line, using ms and mm conventions.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
msputmac(char *s, int constant)
|
||||
{
|
||||
char *t;
|
||||
|
@ -881,7 +883,7 @@ msputmac(char *s, int constant)
|
|||
/*
|
||||
* put out words (for the -w option) with ms and mm conventions
|
||||
*/
|
||||
void
|
||||
static void
|
||||
msputwords(int macline)
|
||||
{
|
||||
char *p, *p1;
|
||||
|
@ -921,7 +923,7 @@ msputwords(int macline)
|
|||
#define SKIPBLANK(cp) while (*cp == ' ' || *cp == '\t') { cp++; }
|
||||
#define SKIPNONBLANK(cp) while (*cp !=' ' && *cp !='\cp' && *cp !='\0') { cp++; }
|
||||
|
||||
void
|
||||
static void
|
||||
meputmac(char *cp, int constant)
|
||||
{
|
||||
char *np;
|
||||
|
@ -1013,7 +1015,7 @@ meputmac(char *cp, int constant)
|
|||
/*
|
||||
* put out words (for the -w option) with ms and mm conventions
|
||||
*/
|
||||
void
|
||||
static void
|
||||
meputwords(int macline)
|
||||
{
|
||||
|
||||
|
@ -1039,7 +1041,7 @@ meputwords(int macline)
|
|||
* for me:
|
||||
* ([lqbzcdf]
|
||||
*/
|
||||
void
|
||||
static void
|
||||
noblock(char a1, char a2)
|
||||
{
|
||||
int c1,c2;
|
||||
|
@ -1099,24 +1101,27 @@ noblock(char a1, char a2)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
EQ(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
EQ(pacmac unused)
|
||||
{
|
||||
|
||||
eqn();
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
domacro(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
domacro(pacmac unused)
|
||||
{
|
||||
|
||||
macro();
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
PS(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
PS(pacmac unused)
|
||||
{
|
||||
|
||||
for (C; c == ' ' || c == '\t'; C)
|
||||
|
@ -1124,44 +1129,48 @@ PS(void)
|
|||
|
||||
if (c == '<') { /* ".PS < file" -- don't expect a .PE */
|
||||
SKIP;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
if (!msflag)
|
||||
inpic();
|
||||
else
|
||||
noblock('P', 'E');
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
skip(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
skip(pacmac unused)
|
||||
{
|
||||
|
||||
SKIP;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
intbl(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
intbl(pacmac unused)
|
||||
{
|
||||
|
||||
if (msflag)
|
||||
stbl();
|
||||
else
|
||||
tbl();
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
outtbl(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
outtbl(pacmac unused)
|
||||
{
|
||||
|
||||
intable = NO;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
so(void)
|
||||
/*ARGSUSED*/
|
||||
so(pacmac unused)
|
||||
{
|
||||
|
||||
if (!iflag) {
|
||||
|
@ -1173,11 +1182,12 @@ so(void)
|
|||
infile = *filesp = opn(fname);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nx(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
nx(pacmac unused)
|
||||
{
|
||||
|
||||
if (!iflag) {
|
||||
|
@ -1188,18 +1198,19 @@ nx(void)
|
|||
fclose(infile);
|
||||
infile = *filesp = opn(fname);
|
||||
}
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
skiptocom(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
skiptocom(pacmac unused)
|
||||
{
|
||||
|
||||
SKIP_TO_COM;
|
||||
return(COMX);
|
||||
return COMX;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
PP(pacmac c12)
|
||||
{
|
||||
int c1, c2;
|
||||
|
@ -1209,20 +1220,21 @@ PP(pacmac c12)
|
|||
while (C != '\n')
|
||||
putchar(c);
|
||||
putchar('\n');
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
AU(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
AU(pacmac unused)
|
||||
{
|
||||
|
||||
if (mac == MM)
|
||||
return(0);
|
||||
return 0;
|
||||
SKIP_TO_COM;
|
||||
return(COMX);
|
||||
return COMX;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
SH(pacmac c12)
|
||||
{
|
||||
int c1, c2;
|
||||
|
@ -1240,29 +1252,30 @@ SH(pacmac c12)
|
|||
putchar(c);
|
||||
putchar('\n');
|
||||
if (C == '.')
|
||||
return(COM);
|
||||
return COM;
|
||||
putchar('!');
|
||||
putchar(c);
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
} else {
|
||||
SKIP_TO_COM;
|
||||
return(COMX);
|
||||
return COMX;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
UX(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
UX(pacmac unused)
|
||||
{
|
||||
|
||||
if (wordflag)
|
||||
printf("UNIX\n");
|
||||
else
|
||||
printf("UNIX ");
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
MMHU(pacmac c12)
|
||||
{
|
||||
int c1, c2;
|
||||
|
@ -1276,46 +1289,48 @@ MMHU(pacmac c12)
|
|||
} else {
|
||||
SKIP;
|
||||
}
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
mesnblock(pacmac c12)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
frommac(c12, c1, c2);
|
||||
noblock(')', c2);
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
mssnblock(pacmac c12)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
frommac(c12, c1, c2);
|
||||
noblock(c1, 'E');
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nf(void)
|
||||
static int
|
||||
/*ARGUSED*/
|
||||
nf(pacmac unused)
|
||||
{
|
||||
|
||||
noblock('f', 'i');
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ce(void)
|
||||
static int
|
||||
/*ARGUSED*/
|
||||
ce(pacmac unused)
|
||||
{
|
||||
|
||||
sce();
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
meip(pacmac c12)
|
||||
{
|
||||
|
||||
|
@ -1325,24 +1340,24 @@ meip(pacmac c12)
|
|||
regline(meputmac, ONE);
|
||||
else
|
||||
SKIP;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* only called for -me .pp or .sh, when parag is on
|
||||
*/
|
||||
int
|
||||
static int
|
||||
mepp(pacmac c12)
|
||||
{
|
||||
|
||||
PP(c12); /* eats the line */
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start of a section heading; output the section name if doing words
|
||||
*/
|
||||
int
|
||||
static int
|
||||
mesh(pacmac c12)
|
||||
{
|
||||
|
||||
|
@ -1352,37 +1367,37 @@ mesh(pacmac c12)
|
|||
defcomline(c12);
|
||||
else
|
||||
SKIP;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* process a font setting
|
||||
*/
|
||||
int
|
||||
static int
|
||||
mefont(pacmac c12)
|
||||
{
|
||||
|
||||
argconcat = 1;
|
||||
defcomline(c12);
|
||||
argconcat = 0;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
manfont(pacmac c12)
|
||||
{
|
||||
|
||||
return(mefont(c12));
|
||||
return mefont(c12);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
manpp(pacmac c12)
|
||||
{
|
||||
|
||||
return(mepp(c12));
|
||||
return mepp(c12);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
defcomline(pacmac c12)
|
||||
{
|
||||
int c1, c2;
|
||||
|
@ -1424,7 +1439,7 @@ defcomline(pacmac c12)
|
|||
--inmacro;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
comline(void)
|
||||
{
|
||||
int c1;
|
||||
|
@ -1434,8 +1449,8 @@ comline(void)
|
|||
int lb, ub;
|
||||
int hit;
|
||||
static int tabsize = 0;
|
||||
static struct mactab *mactab = (struct mactab *)0;
|
||||
struct mactab *mp;
|
||||
static const struct mactab *mactab = NULL;
|
||||
const struct mactab *mp;
|
||||
|
||||
if (mactab == 0)
|
||||
buildtab(&mactab, &tabsize);
|
||||
|
@ -1526,17 +1541,17 @@ comx:
|
|||
defcomline(c12);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
macsort(const void *p1, const void *p2)
|
||||
{
|
||||
struct mactab *t1 = (struct mactab *)p1;
|
||||
struct mactab *t2 = (struct mactab *)p2;
|
||||
const struct mactab *t1 = p1;
|
||||
const struct mactab *t2 = p2;
|
||||
|
||||
return(t1->macname - t2->macname);
|
||||
return t1->macname - t2->macname;
|
||||
}
|
||||
|
||||
int
|
||||
sizetab(struct mactab *mp)
|
||||
static int
|
||||
sizetab(const struct mactab *mp)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -1545,21 +1560,21 @@ sizetab(struct mactab *mp)
|
|||
for (; mp->macname; mp++, i++)
|
||||
/*VOID*/ ;
|
||||
}
|
||||
return(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
struct mactab *
|
||||
macfill(struct mactab *dst, struct mactab *src)
|
||||
static struct mactab *
|
||||
macfill(struct mactab *dst, const struct mactab *src)
|
||||
{
|
||||
|
||||
if (src) {
|
||||
while (src->macname)
|
||||
*dst++ = *src++;
|
||||
}
|
||||
return(dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
__dead void
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
extern char *__progname;
|
||||
|
@ -1568,12 +1583,12 @@ usage(void)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
buildtab(struct mactab **r_back, int *r_size)
|
||||
static void
|
||||
buildtab(const struct mactab **r_back, int *r_size)
|
||||
{
|
||||
int size;
|
||||
struct mactab *p, *p1, *p2;
|
||||
struct mactab *back;
|
||||
size_t size;
|
||||
const struct mactab *p1, *p2;
|
||||
struct mactab *back, *p;
|
||||
|
||||
size = sizetab(troffmactab) + sizetab(ppmactab);
|
||||
p1 = p2 = NULL;
|
||||
|
@ -1598,7 +1613,7 @@ buildtab(struct mactab **r_back, int *r_size)
|
|||
}
|
||||
size += sizetab(p1);
|
||||
size += sizetab(p2);
|
||||
back = (struct mactab *)calloc(size+2, sizeof(struct mactab));
|
||||
back = calloc(size + 2, sizeof(struct mactab));
|
||||
if (back == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
|
@ -1615,7 +1630,7 @@ buildtab(struct mactab **r_back, int *r_size)
|
|||
/*
|
||||
* troff commands
|
||||
*/
|
||||
struct mactab troffmactab[] = {
|
||||
static const struct mactab troffmactab[] = {
|
||||
M(NONE, '\\','"', skip), /* comment */
|
||||
M(NOMAC, 'd','e', domacro), /* define */
|
||||
M(NOMAC, 'i','g', domacro), /* ignore till .. */
|
||||
|
@ -1634,7 +1649,7 @@ struct mactab troffmactab[] = {
|
|||
/*
|
||||
* Preprocessor output
|
||||
*/
|
||||
struct mactab ppmactab[] = {
|
||||
static const struct mactab ppmactab[] = {
|
||||
M(FNEST, 'E','Q', EQ), /* equation starting */
|
||||
M(FNEST, 'T','S', intbl), /* table starting */
|
||||
M(FNEST, 'T','C', intbl), /* alternative table? */
|
||||
|
@ -1647,7 +1662,7 @@ struct mactab ppmactab[] = {
|
|||
/*
|
||||
* Particular to ms and mm
|
||||
*/
|
||||
struct mactab msmactab[] = {
|
||||
static const struct mactab msmactab[] = {
|
||||
M(NONE, 'T','L', skiptocom), /* title follows */
|
||||
M(NONE, 'F','S', skiptocom), /* start footnote */
|
||||
M(NONE, 'O','K', skiptocom), /* Other kws */
|
||||
|
@ -1672,7 +1687,7 @@ struct mactab msmactab[] = {
|
|||
M(NONE, 0,0, 0)
|
||||
};
|
||||
|
||||
struct mactab mmmactab[] = {
|
||||
static const struct mactab mmmactab[] = {
|
||||
M(NONE, 'H',' ', MMHU), /* -mm ? */
|
||||
M(NONE, 'H','U', MMHU), /* -mm ? */
|
||||
M(PARAG, 'P',' ', PP), /* paragraph for -mm */
|
||||
|
@ -1680,7 +1695,7 @@ struct mactab mmmactab[] = {
|
|||
M(NONE, 0,0, 0)
|
||||
};
|
||||
|
||||
struct mactab memactab[] = {
|
||||
static const struct mactab memactab[] = {
|
||||
M(PARAG, 'p','p', mepp),
|
||||
M(PARAG, 'l','p', mepp),
|
||||
M(PARAG, 'n','p', mepp),
|
||||
|
@ -1710,7 +1725,7 @@ struct mactab memactab[] = {
|
|||
M(NONE, 0,0, 0)
|
||||
};
|
||||
|
||||
struct mactab manmactab[] = {
|
||||
static const struct mactab manmactab[] = {
|
||||
M(PARAG, 'B','I', manfont),
|
||||
M(PARAG, 'B','R', manfont),
|
||||
M(PARAG, 'I','B', manfont),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# $NetBSD: Makefile,v 1.1 2005/06/29 21:06:12 perry Exp $
|
||||
# $NetBSD: Makefile,v 1.2 2005/06/30 16:25:05 christos Exp $
|
||||
|
||||
PROG= spellprog
|
||||
WARNS= 3
|
||||
NOMAN= 1
|
||||
SRCS= spellprog.c look.c
|
||||
BINDIR= /usr/libexec
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
int look(u_char *, u_char *, u_char *);
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: look.c,v 1.1 2005/06/29 21:06:12 perry Exp $ */
|
||||
/* $NetBSD: look.c,v 1.2 2005/06/30 16:25:05 christos Exp $ */
|
||||
|
||||
/* derived from: OpenBSD: look.c,v 1.3 2003/06/03 02:56:16 millert Exp */
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
|||
#if 0
|
||||
static const char sccsid[] = "@(#)look.c 8.2 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] = "$NetBSD: look.c,v 1.1 2005/06/29 21:06:12 perry Exp $";
|
||||
static const char rcsid[] = "$NetBSD: look.c,v 1.2 2005/06/30 16:25:05 christos Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -48,10 +48,11 @@ static const char rcsid[] = "$NetBSD: look.c,v 1.1 2005/06/29 21:06:12 perry Exp
|
|||
#include <string.h>
|
||||
#include <err.h>
|
||||
|
||||
u_char *binary_search(u_char *, u_char *, u_char *);
|
||||
u_char *linear_search(u_char *, u_char *, u_char *);
|
||||
int compare(u_char *, u_char *, u_char *);
|
||||
int look(u_char *, u_char *, u_char *);
|
||||
#include "extern.h"
|
||||
|
||||
static u_char *binary_search(u_char *, u_char *, u_char *);
|
||||
static u_char *linear_search(u_char *, u_char *, u_char *);
|
||||
static int compare(u_char *, u_char *, u_char *);
|
||||
|
||||
int
|
||||
look(u_char *string, u_char *front, u_char *back)
|
||||
|
@ -109,9 +110,10 @@ look(u_char *string, u_char *front, u_char *back)
|
|||
* more trouble than it's worth.
|
||||
*/
|
||||
#define SKIP_PAST_NEWLINE(p, back) \
|
||||
while (p < back && *p++ != '\n');
|
||||
while (p < back && *p++ != '\n') \
|
||||
continue;
|
||||
|
||||
u_char *
|
||||
static u_char *
|
||||
binary_search(u_char *string, u_char *front, u_char *back)
|
||||
{
|
||||
u_char *p;
|
||||
|
@ -145,7 +147,7 @@ binary_search(u_char *string, u_char *front, u_char *back)
|
|||
* o front points at the first character in a line.
|
||||
* o front is before or at the first line to be printed.
|
||||
*/
|
||||
u_char *
|
||||
static u_char *
|
||||
linear_search(u_char *string, u_char *front, u_char *back)
|
||||
{
|
||||
int result;
|
||||
|
@ -162,7 +164,7 @@ linear_search(u_char *string, u_char *front, u_char *back)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
compare(u_char *s1, u_char *s2, u_char *back)
|
||||
{
|
||||
int ch;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: spellprog.c,v 1.1 2005/06/29 21:06:12 perry Exp $ */
|
||||
/* $NetBSD: spellprog.c,v 1.2 2005/06/30 16:25:05 christos Exp $ */
|
||||
|
||||
/* derived from OpenBSD: spellprog.c,v 1.4 2003/06/03 02:56:16 millert Exp */
|
||||
|
||||
|
@ -95,97 +95,98 @@ static const char rcsid[] = "$OpenBSD: spellprog.c,v 1.4 2003/06/03 02:56:16 mil
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define DLEV 2
|
||||
|
||||
int an(char *, char *, char *, int);
|
||||
int bility(char *, char *, char *, int);
|
||||
int es(char *, char *, char *, int);
|
||||
int dict(char *, char *);
|
||||
int i_to_y(char *, char *, char *, int);
|
||||
int ily(char *, char *, char *, int);
|
||||
int ize(char *, char *, char *, int);
|
||||
int metry(char *, char *, char *, int);
|
||||
int monosyl(char *, char *);
|
||||
int ncy(char *, char *, char *, int);
|
||||
int nop(void);
|
||||
int trypref(char *, char *, int);
|
||||
int tryword(char *, char *, int);
|
||||
int s(char *, char *, char *, int);
|
||||
int strip(char *, char *, char *, int);
|
||||
int suffix(char *, int);
|
||||
int tion(char *, char *, char *, int);
|
||||
int vowel(int);
|
||||
int y_to_e(char *, char *, char *, int);
|
||||
int CCe(char *, char *, char *, int);
|
||||
int VCe(char *, char *, char *, int);
|
||||
char *lookuppref(char **, char *);
|
||||
char *skipv(char *);
|
||||
char *estrdup(const char *);
|
||||
void ise(void);
|
||||
void print_word(FILE *);
|
||||
void ztos(char *);
|
||||
__dead void usage(void);
|
||||
static int dict(char *, char *);
|
||||
static int trypref(char *, const char *, size_t);
|
||||
static int tryword(char *, char *, size_t);
|
||||
static int suffix(char *, size_t);
|
||||
static int vowel(int);
|
||||
static const char *lookuppref(char **, char *);
|
||||
static char *skipv(char *);
|
||||
static char *estrdup(const char *);
|
||||
static void ise(void);
|
||||
static void print_word(FILE *);
|
||||
static void ztos(char *);
|
||||
static int monosyl(char *, char *);
|
||||
static void usage(void) __attribute__((__noreturn__));
|
||||
static void getderiv(size_t);
|
||||
|
||||
/* from look.c */
|
||||
int look(unsigned char *, unsigned char *, unsigned char *);
|
||||
static int an(char *, const char *, const char *, size_t);
|
||||
static int bility(char *, const char *, const char *, size_t);
|
||||
static int es(char *, const char *, const char *, size_t);
|
||||
static int i_to_y(char *, const char *, const char *, size_t);
|
||||
static int ily(char *, const char *, const char *, size_t);
|
||||
static int ize(char *, const char *, const char *, size_t);
|
||||
static int metry(char *, const char *, const char *, size_t);
|
||||
static int ncy(char *, const char *, const char *, size_t);
|
||||
static int nop(char *, const char *, const char *, size_t);
|
||||
static int s(char *, const char *, const char *, size_t);
|
||||
static int strip(char *, const char *, const char *, size_t);
|
||||
static int tion(char *, const char *, const char *, size_t);
|
||||
static int y_to_e(char *, const char *, const char *, size_t);
|
||||
static int CCe(char *, const char *, const char *, size_t);
|
||||
static int VCe(char *, const char *, const char *, size_t);
|
||||
|
||||
struct suftab {
|
||||
char *suf;
|
||||
int (*p1)(); /* XXX - variable args */
|
||||
static struct suftab {
|
||||
const char *suf;
|
||||
int (*p1)(char *, const char *, const char *, size_t);
|
||||
int n1;
|
||||
char *d1;
|
||||
char *a1;
|
||||
int (*p2)(); /* XXX - variable args */
|
||||
const char *d1;
|
||||
const char *a1;
|
||||
int (*p2)(char *, const char *, const char *, size_t);
|
||||
int n2;
|
||||
char *d2;
|
||||
char *a2;
|
||||
const char *d2;
|
||||
const char *a2;
|
||||
} suftab[] = {
|
||||
{"ssen", ily, 4, "-y+iness", "+ness" },
|
||||
{"ssel", ily, 4, "-y+i+less", "+less" },
|
||||
{"se", s, 1, "", "+s", es, 2, "-y+ies", "+es" },
|
||||
{"s'", s, 2, "", "+'s"},
|
||||
{"s", s, 1, "", "+s"},
|
||||
{"ecn", ncy, 1, "", "-t+ce"},
|
||||
{"ycn", ncy, 1, "", "-cy+t"},
|
||||
{"ytilb", nop, 0, "", ""},
|
||||
{"ytilib", bility, 5, "-le+ility", ""},
|
||||
{"elbaif", i_to_y, 4, "-y+iable", ""},
|
||||
{"elba", CCe, 4, "-e+able", "+able"},
|
||||
{"yti", CCe, 3, "-e+ity", "+ity"},
|
||||
{"ylb", y_to_e, 1, "-e+y", ""},
|
||||
{"yl", ily, 2, "-y+ily", "+ly"},
|
||||
{"laci", strip, 2, "", "+al"},
|
||||
{"latnem", strip, 2, "", "+al"},
|
||||
{"lanoi", strip, 2, "", "+al"},
|
||||
{"tnem", strip, 4, "", "+ment"},
|
||||
{"gni", CCe, 3, "-e+ing", "+ing"},
|
||||
{"reta", nop, 0, "", ""},
|
||||
{"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
|
||||
{"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
|
||||
{"citsi", strip, 2, "", "+ic"},
|
||||
{"cihparg", i_to_y, 1, "-y+ic", ""},
|
||||
{"tse", strip, 2, "", "+st", i_to_y, 3, "-y+iest", "+est"},
|
||||
{"cirtem", i_to_y, 1, "-y+ic", ""},
|
||||
{"yrtem", metry, 0, "-ry+er", ""},
|
||||
{"cigol", i_to_y, 1, "-y+ic", ""},
|
||||
{"tsigol", i_to_y, 2, "-y+ist", ""},
|
||||
{"tsi", VCe, 3, "-e+ist", "+ist"},
|
||||
{"msi", VCe, 3, "-e+ism", "+ist"},
|
||||
{"ssen", ily, 4, "-y+iness", "+ness" },
|
||||
{"ssel", ily, 4, "-y+i+less", "+less" },
|
||||
{"se", s, 1, "", "+s", es, 2, "-y+ies", "+es" },
|
||||
{"s'", s, 2, "", "+'s"},
|
||||
{"s", s, 1, "", "+s"},
|
||||
{"ecn", ncy, 1, "", "-t+ce"},
|
||||
{"ycn", ncy, 1, "", "-cy+t"},
|
||||
{"ytilb", nop, 0, "", ""},
|
||||
{"ytilib", bility, 5, "-le+ility", ""},
|
||||
{"elbaif", i_to_y, 4, "-y+iable", ""},
|
||||
{"elba", CCe, 4, "-e+able", "+able"},
|
||||
{"yti", CCe, 3, "-e+ity", "+ity"},
|
||||
{"ylb", y_to_e, 1, "-e+y", ""},
|
||||
{"yl", ily, 2, "-y+ily", "+ly"},
|
||||
{"laci", strip, 2, "", "+al"},
|
||||
{"latnem", strip, 2, "", "+al"},
|
||||
{"lanoi", strip, 2, "", "+al"},
|
||||
{"tnem", strip, 4, "", "+ment"},
|
||||
{"gni", CCe, 3, "-e+ing", "+ing"},
|
||||
{"reta", nop, 0, "", ""},
|
||||
{"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
|
||||
{"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
|
||||
{"citsi", strip, 2, "", "+ic"},
|
||||
{"cihparg", i_to_y, 1, "-y+ic", ""},
|
||||
{"tse", strip, 2, "", "+st", i_to_y, 3, "-y+iest", "+est"},
|
||||
{"cirtem", i_to_y, 1, "-y+ic", ""},
|
||||
{"yrtem", metry, 0, "-ry+er", ""},
|
||||
{"cigol", i_to_y, 1, "-y+ic", ""},
|
||||
{"tsigol", i_to_y, 2, "-y+ist", ""},
|
||||
{"tsi", VCe, 3, "-e+ist", "+ist"},
|
||||
{"msi", VCe, 3, "-e+ism", "+ist"},
|
||||
{"noitacif", i_to_y, 6, "-y+ication", ""},
|
||||
{"noitazi", ize, 5, "-e+ation", ""},
|
||||
{"rota", tion, 2, "-e+or", ""},
|
||||
{"noit", tion, 3, "-e+ion", "+ion"},
|
||||
{"naino", an, 3, "", "+ian"},
|
||||
{"na", an, 1, "", "+n"},
|
||||
{"evit", tion, 3, "-e+ive", "+ive"},
|
||||
{"ezi", CCe, 3, "-e+ize", "+ize"},
|
||||
{"pihs", strip, 4, "", "+ship"},
|
||||
{"dooh", ily, 4, "-y+hood", "+hood"},
|
||||
{"ekil", strip, 4, "", "+like"},
|
||||
{ NULL }
|
||||
{"noitazi", ize, 5, "-e+ation", ""},
|
||||
{"rota", tion, 2, "-e+or", ""},
|
||||
{"noit", tion, 3, "-e+ion", "+ion"},
|
||||
{"naino", an, 3, "", "+ian"},
|
||||
{"na", an, 1, "", "+n"},
|
||||
{"evit", tion, 3, "-e+ive", "+ive"},
|
||||
{"ezi", CCe, 3, "-e+ize", "+ize"},
|
||||
{"pihs", strip, 4, "", "+ship"},
|
||||
{"dooh", ily, 4, "-y+hood", "+hood"},
|
||||
{"ekil", strip, 4, "", "+like"},
|
||||
{ NULL, }
|
||||
};
|
||||
|
||||
char *preftab[] = {
|
||||
static const char *preftab[] = {
|
||||
"anti",
|
||||
"bio",
|
||||
"dis",
|
||||
|
@ -223,18 +224,21 @@ char *preftab[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
struct wlist {
|
||||
static struct wlist {
|
||||
int fd;
|
||||
unsigned char *front;
|
||||
unsigned char *back;
|
||||
} *wlists;
|
||||
|
||||
int vflag;
|
||||
int xflag;
|
||||
char word[LINE_MAX];
|
||||
char original[LINE_MAX];
|
||||
char *deriv[40];
|
||||
char affix[40];
|
||||
static int vflag;
|
||||
static int xflag;
|
||||
static char word[LINE_MAX];
|
||||
static char original[LINE_MAX];
|
||||
static char affix[LINE_MAX];
|
||||
static struct {
|
||||
const char **buf;
|
||||
size_t maxlev;
|
||||
} deriv;
|
||||
|
||||
/*
|
||||
* The spellprog utility accepts a newline-delimited list of words
|
||||
|
@ -296,6 +300,7 @@ main(int argc, char **argv)
|
|||
/* Open and mmap the word/stop lists. */
|
||||
if ((wlists = malloc(sizeof(struct wlist) * (argc + 1))) == NULL)
|
||||
err(1, "malloc");
|
||||
|
||||
for (i = 0; argc--; i++) {
|
||||
wlists[i].fd = open(argv[i], O_RDONLY, 0);
|
||||
if (wlists[i].fd == -1 || fstat(wlists[i].fd, &sb) != 0)
|
||||
|
@ -306,7 +311,7 @@ main(int argc, char **argv)
|
|||
MAP_PRIVATE, wlists[i].fd, (off_t)0);
|
||||
if (wlists[i].front == MAP_FAILED)
|
||||
err(1, "%s", argv[i]);
|
||||
wlists[i].back = wlists[i].front + sb.st_size;
|
||||
wlists[i].back = wlists[i].front + (size_t)sb.st_size;
|
||||
}
|
||||
wlists[i].fd = -1;
|
||||
|
||||
|
@ -357,11 +362,9 @@ lcase:
|
|||
}
|
||||
file = stdout;
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
print_word(FILE *f)
|
||||
{
|
||||
|
||||
|
@ -377,15 +380,17 @@ print_word(FILE *f)
|
|||
* For each matching suffix in suftab, call the function associated
|
||||
* with that suffix (p1 and p2).
|
||||
*/
|
||||
int
|
||||
suffix(char *ep, int lev)
|
||||
static int
|
||||
suffix(char *ep, size_t lev)
|
||||
{
|
||||
struct suftab *t;
|
||||
char *cp, *sp;
|
||||
char *cp;
|
||||
const char *sp;
|
||||
|
||||
lev += DLEV;
|
||||
deriv[lev] = deriv[lev-1] = 0;
|
||||
for (t = suftab; (sp = t->suf); t++) {
|
||||
getderiv(lev + 1);
|
||||
deriv.buf[lev] = deriv.buf[lev - 1] = 0;
|
||||
for (t = suftab; (sp = t->suf) != NULL; t++) {
|
||||
cp = ep;
|
||||
while (*sp) {
|
||||
if (*--cp != *sp++)
|
||||
|
@ -394,160 +399,165 @@ suffix(char *ep, int lev)
|
|||
for (sp = cp; --sp >= word && !vowel(*sp);)
|
||||
; /* nothing */
|
||||
if (sp < word)
|
||||
return (0);
|
||||
if ((*t->p1)(ep-t->n1, t->d1, t->a1, lev+1))
|
||||
return (1);
|
||||
return 0;
|
||||
if ((*t->p1)(ep - t->n1, t->d1, t->a1, lev + 1))
|
||||
return 1;
|
||||
if (t->p2 != NULL) {
|
||||
deriv[lev] = deriv[lev+1] = '\0';
|
||||
return ((*t->p2)(ep-t->n2, t->d2, t->a2, lev));
|
||||
deriv.buf[lev] = deriv.buf[lev + 1] = '\0';
|
||||
return (*t->p2)(ep - t->n2, t->d2, t->a2, lev);
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
next: ;
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nop(void)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
nop(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
strip(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
strip(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
return (trypref(ep, a, lev) || suffix(ep, lev));
|
||||
return trypref(ep, a, lev) || suffix(ep, lev);
|
||||
}
|
||||
|
||||
int
|
||||
s(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
s(char *ep, const char *d, const char *a, const size_t lev)
|
||||
{
|
||||
|
||||
if (lev > DLEV + 1)
|
||||
return (0);
|
||||
return 0;
|
||||
if (*ep == 's' && ep[-1] == 's')
|
||||
return (0);
|
||||
return (strip(ep, d, a, lev));
|
||||
return 0;
|
||||
return strip(ep, d, a, lev);
|
||||
}
|
||||
|
||||
int
|
||||
an(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
an(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
if (!isupper((unsigned char)*word)) /* must be proper name */
|
||||
return (0);
|
||||
return (trypref(ep,a,lev));
|
||||
return 0;
|
||||
return trypref(ep, a, lev);
|
||||
}
|
||||
|
||||
int
|
||||
ize(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
ize(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
*ep++ = 'e';
|
||||
return (strip(ep ,"", d, lev));
|
||||
return strip(ep ,"", d, lev);
|
||||
}
|
||||
|
||||
int
|
||||
y_to_e(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
/*ARGSUSED*/
|
||||
y_to_e(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
char c = *ep;
|
||||
|
||||
*ep++ = 'e';
|
||||
if (strip(ep, "", d, lev))
|
||||
return (1);
|
||||
return 1;
|
||||
ep[-1] = c;
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ily(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
ily(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
if (ep[-1] == 'i')
|
||||
return (i_to_y(ep, d, a, lev));
|
||||
return i_to_y(ep, d, a, lev);
|
||||
else
|
||||
return (strip(ep, d, a, lev));
|
||||
return strip(ep, d, a, lev);
|
||||
}
|
||||
|
||||
int
|
||||
ncy(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
ncy(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
if (skipv(skipv(ep-1)) < word)
|
||||
return (0);
|
||||
if (skipv(skipv(ep - 1)) < word)
|
||||
return 0;
|
||||
ep[-1] = 't';
|
||||
return (strip(ep, d, a, lev));
|
||||
return strip(ep, d, a, lev);
|
||||
}
|
||||
|
||||
int
|
||||
bility(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
bility(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
*ep++ = 'l';
|
||||
return (y_to_e(ep, d, a, lev));
|
||||
return y_to_e(ep, d, a, lev);
|
||||
}
|
||||
|
||||
int
|
||||
i_to_y(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
i_to_y(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
if (ep[-1] == 'i') {
|
||||
ep[-1] = 'y';
|
||||
a = d;
|
||||
}
|
||||
return (strip(ep, "", a, lev));
|
||||
return strip(ep, "", a, lev);
|
||||
}
|
||||
|
||||
int
|
||||
es(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
es(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
if (lev > DLEV)
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
switch (ep[-1]) {
|
||||
default:
|
||||
return (0);
|
||||
return 0;
|
||||
case 'i':
|
||||
return (i_to_y(ep, d, a, lev));
|
||||
return i_to_y(ep, d, a, lev);
|
||||
case 's':
|
||||
case 'h':
|
||||
case 'z':
|
||||
case 'x':
|
||||
return (strip(ep, d, a, lev));
|
||||
return strip(ep, d, a, lev);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
metry(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
metry(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
ep[-2] = 'e';
|
||||
ep[-1] = 'r';
|
||||
return (strip(ep, d, a, lev));
|
||||
return strip(ep, d, a, lev);
|
||||
}
|
||||
|
||||
int
|
||||
tion(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
tion(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
switch (ep[-2]) {
|
||||
case 'c':
|
||||
case 'r':
|
||||
return (trypref(ep, a, lev));
|
||||
return trypref(ep, a, lev);
|
||||
case 'a':
|
||||
return (y_to_e(ep, d, a, lev));
|
||||
return y_to_e(ep, d, a, lev);
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Possible consonant-consonant-e ending.
|
||||
*/
|
||||
int
|
||||
CCe(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
CCe(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
|
||||
switch (ep[-1]) {
|
||||
|
@ -560,56 +570,59 @@ CCe(char *ep, char *d, char *a, int lev)
|
|||
case 'w':
|
||||
break;
|
||||
default:
|
||||
return (y_to_e(ep, d, a, lev));
|
||||
return y_to_e(ep, d, a, lev);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
if (ep[-2] == 's')
|
||||
break;
|
||||
/*FALLTHROUGH*/
|
||||
case 'c':
|
||||
case 'g':
|
||||
if (*ep == 'a')
|
||||
return (0);
|
||||
return 0;
|
||||
/*FALLTHROUGH*/
|
||||
case 'v':
|
||||
case 'z':
|
||||
if (vowel(ep[-2]))
|
||||
break;
|
||||
/*FALLTHROUGH*/
|
||||
case 'u':
|
||||
if (y_to_e(ep, d, a, lev))
|
||||
return (1);
|
||||
return 1;
|
||||
if (!(ep[-2] == 'n' && ep[-1] == 'g'))
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
return (VCe(ep, d, a, lev));
|
||||
return VCe(ep, d, a, lev);
|
||||
}
|
||||
|
||||
/*
|
||||
* Possible consonant-vowel-consonant-e ending.
|
||||
*/
|
||||
int
|
||||
VCe(char *ep, char *d, char *a, int lev)
|
||||
static int
|
||||
VCe(char *ep, const char *d, const char *a, size_t lev)
|
||||
{
|
||||
char c;
|
||||
|
||||
c = ep[-1];
|
||||
if (c == 'e')
|
||||
return (0);
|
||||
return 0;
|
||||
if (!vowel(c) && vowel(ep[-2])) {
|
||||
c = *ep;
|
||||
*ep++ = 'e';
|
||||
if (trypref(ep, d, lev) || suffix(ep, lev))
|
||||
return (1);
|
||||
return 1;
|
||||
ep--;
|
||||
*ep = c;
|
||||
}
|
||||
return (strip(ep, d, a, lev));
|
||||
return strip(ep, d, a, lev);
|
||||
}
|
||||
|
||||
char *
|
||||
static const char *
|
||||
lookuppref(char **wp, char *ep)
|
||||
{
|
||||
char **sp;
|
||||
char *bp,*cp;
|
||||
const char **sp, *cp;
|
||||
char *bp;
|
||||
|
||||
for (sp = preftab; *sp; sp++) {
|
||||
bp = *wp;
|
||||
|
@ -620,105 +633,108 @@ lookuppref(char **wp, char *ep)
|
|||
for (cp = bp; cp < ep; cp++) {
|
||||
if (vowel(*cp)) {
|
||||
*wp = bp;
|
||||
return (*sp);
|
||||
return *sp;
|
||||
}
|
||||
}
|
||||
next: ;
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the word is not in the dictionary, try stripping off prefixes
|
||||
* until the word is found or we run out of prefixes to check.
|
||||
*/
|
||||
int
|
||||
trypref(char *ep, char *a, int lev)
|
||||
static int
|
||||
trypref(char *ep, const char *a, size_t lev)
|
||||
{
|
||||
char *cp;
|
||||
const char *cp;
|
||||
char *bp;
|
||||
char *pp;
|
||||
int val = 0;
|
||||
char space[20];
|
||||
|
||||
deriv[lev] = a;
|
||||
getderiv(lev + 2);
|
||||
deriv.buf[lev] = a;
|
||||
if (tryword(word, ep, lev))
|
||||
return (1);
|
||||
return 1;
|
||||
bp = word;
|
||||
pp = space;
|
||||
deriv[lev+1] = pp;
|
||||
while ((cp = lookuppref(&bp, ep))) {
|
||||
deriv.buf[lev + 1] = pp;
|
||||
while ((cp = lookuppref(&bp, ep)) != NULL) {
|
||||
*pp++ = '+';
|
||||
while ((*pp = *cp++))
|
||||
pp++;
|
||||
if (tryword(bp, ep, lev+1)) {
|
||||
if (tryword(bp, ep, lev + 1)) {
|
||||
val = 1;
|
||||
break;
|
||||
}
|
||||
if (pp - space >= sizeof(space))
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
deriv[lev+1] = deriv[lev+2] = '\0';
|
||||
return (val);
|
||||
deriv.buf[lev + 1] = deriv.buf[lev + 2] = '\0';
|
||||
return val;
|
||||
}
|
||||
|
||||
int
|
||||
tryword(char *bp, char *ep, int lev)
|
||||
static int
|
||||
tryword(char *bp, char *ep, size_t lev)
|
||||
{
|
||||
int i, j;
|
||||
size_t i, j;
|
||||
char duple[3];
|
||||
|
||||
if (ep-bp <= 1)
|
||||
return (0);
|
||||
return 0;
|
||||
if (vowel(*ep) && monosyl(bp, ep))
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
i = dict(bp, ep);
|
||||
if (i == 0 && vowel(*ep) && ep[-1] == ep[-2] && monosyl(bp, ep-1)) {
|
||||
if (i == 0 && vowel(*ep) && ep[-1] == ep[-2] &&
|
||||
monosyl(bp, ep - 1)) {
|
||||
ep--;
|
||||
deriv[++lev] = duple;
|
||||
getderiv(++lev);
|
||||
deriv.buf[lev] = duple;
|
||||
duple[0] = '+';
|
||||
duple[1] = *ep;
|
||||
duple[2] = '\0';
|
||||
i = dict(bp, ep);
|
||||
}
|
||||
if (vflag == 0 || i == 0)
|
||||
return (i);
|
||||
return i;
|
||||
|
||||
/* Also tack on possible derivations. (XXX - warn on truncation?) */
|
||||
for (j = lev; j > 0; j--) {
|
||||
if (deriv[j])
|
||||
strlcat(affix, deriv[j], sizeof(affix));
|
||||
if (deriv.buf[j])
|
||||
(void)strlcat(affix, deriv.buf[j], sizeof(affix));
|
||||
}
|
||||
return (i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
monosyl(char *bp, char *ep)
|
||||
{
|
||||
|
||||
if (ep < bp + 2)
|
||||
return (0);
|
||||
return 0;
|
||||
if (vowel(*--ep) || !vowel(*--ep) || ep[1] == 'x' || ep[1] == 'w')
|
||||
return (0);
|
||||
return 0;
|
||||
while (--ep >= bp)
|
||||
if (vowel(*ep))
|
||||
return (0);
|
||||
return (1);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *
|
||||
skipv(char *s)
|
||||
static char *
|
||||
skipv(char *st)
|
||||
{
|
||||
|
||||
if (s >= word && vowel(*s))
|
||||
s--;
|
||||
while (s >= word && !vowel(*s))
|
||||
s--;
|
||||
return (s);
|
||||
if (st >= word && vowel(*st))
|
||||
st--;
|
||||
while (st >= word && !vowel(*st))
|
||||
st--;
|
||||
return st;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
vowel(int c)
|
||||
{
|
||||
|
||||
|
@ -729,60 +745,61 @@ vowel(int c)
|
|||
case 'o':
|
||||
case 'u':
|
||||
case 'y':
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Crummy way to Britishise.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
ise(void)
|
||||
{
|
||||
struct suftab *tab;
|
||||
char *cp;
|
||||
|
||||
for (tab = suftab; tab->suf; tab++) {
|
||||
/* Assume that suffix will contain 'z' if a1 or d1 do */
|
||||
if (strchr(tab->suf, 'z')) {
|
||||
tab->suf = estrdup(tab->suf);
|
||||
ztos(tab->suf);
|
||||
tab->suf = cp = estrdup(tab->suf);
|
||||
ztos(cp);
|
||||
if (strchr(tab->d1, 'z')) {
|
||||
tab->d1 = estrdup(tab->d1);
|
||||
ztos(tab->d1);
|
||||
tab->d1 = cp = estrdup(tab->d1);
|
||||
ztos(cp);
|
||||
}
|
||||
if (strchr(tab->a1, 'z')) {
|
||||
tab->a1 = estrdup(tab->a1);
|
||||
ztos(tab->a1);
|
||||
tab->a1 = cp = estrdup(tab->a1);
|
||||
ztos(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ztos(char *s)
|
||||
static void
|
||||
ztos(char *st)
|
||||
{
|
||||
|
||||
for (; *s; s++)
|
||||
if (*s == 'z')
|
||||
*s = 's';
|
||||
for (; *st; st++)
|
||||
if (*st == 'z')
|
||||
*st = 's';
|
||||
}
|
||||
|
||||
char *
|
||||
estrdup(const char *s)
|
||||
static char *
|
||||
estrdup(const char *st)
|
||||
{
|
||||
char *d;
|
||||
|
||||
if ((d = strdup(s)) == NULL)
|
||||
if ((d = strdup(st)) == NULL)
|
||||
err(1, "strdup");
|
||||
return (d);
|
||||
return d;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up a word in the dictionary.
|
||||
* Returns 1 if found, 0 if not.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
dict(char *bp, char *ep)
|
||||
{
|
||||
char c;
|
||||
|
@ -798,15 +815,27 @@ dict(char *bp, char *ep)
|
|||
break;
|
||||
}
|
||||
*ep = c;
|
||||
return (rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
__dead void
|
||||
static void
|
||||
getderiv(size_t lev)
|
||||
{
|
||||
if (deriv.maxlev < lev) {
|
||||
void *p = realloc(deriv.buf, sizeof(*deriv.buf) * lev);
|
||||
if (p == NULL)
|
||||
err(1, "Cannot grow array");
|
||||
deriv.buf = p;
|
||||
deriv.maxlev = lev;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
extern char *__progname;
|
||||
|
||||
fprintf(stderr, "usage: %s [-bvx] [-o found-words] word-list ...\n",
|
||||
__progname);
|
||||
(void)fprintf(stderr,
|
||||
"Usage: %s [-bvx] [-o found-words] word-list ...\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue