This commit was manufactured by cvs2svn to create tag

'debian_version_2_14-8'.

git-svn-id: file:///srv/svn/joey/bsdgames-tags/debian_version_2_14-8@5231 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
unknown
2003-12-09 18:41:53 +00:00
parent ec93f45476
commit 4c4a7ab9ef
98 changed files with 1511 additions and 95189 deletions

View File

@@ -1,17 +1,7 @@
# $NetBSD: Makefile,v 1.7 1997/05/07 15:59:10 mycroft Exp $
# $NetBSD: Makefile,v 1.8 2000/04/14 04:12:19 simonb Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= strfile
MAN= strfile.8
HOSTPROG= strfile
MAN= strfile.8
# only needed during build
proginstall::
# Override these rules for cross-compilation
.c.o:
${HOST_COMPILE.c} ${.IMPSRC}
${PROG}: ${OBJS}
${HOST_LINK.c} -o ${.TARGET} ${OBJS}
.include <bsd.prog.mk>
.include <bsd.hostprog.mk>

View File

@@ -1,4 +1,30 @@
# Makefrag - makefile fragment for fortune/strfile
#
# Copyright (c) 1997, 1998 Joseph Samuel Myers.
# 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. 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.
fortune_strfile_DIRS := $(USRBINDIR) $(MAN8DIR)

View File

@@ -1,149 +0,0 @@
.\" $NetBSD: strfile.8,v 1.4 1998/02/03 20:45:00 perry Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Ken Arnold.
.\"
.\" 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 the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
.\"
.\" @(#)strfile.8 8.1 (Berkeley) 6/9/93
.\"
.Dd June 9, 1993
.Dt STRFILE 8
.Os BSD 4
.Sh NAME
.Nm strfile ,
.Nm unstr
.Nd "create a random access file for storing strings"
.Sh SYNOPSIS
.Nm strfile
.Op Fl iorsx
.Op Fl c Ar char
.Ar source_file
.Op Ar output_file
.Nm unstr
.Ar source_file
.Sh DESCRIPTION
.Nm Strfile
reads a file containing groups of lines separated by a line containing
a single percent
.Ql \&%
sign and creates a data file which contains
a header structure and a table of file offsets for each group of lines.
This allows random access of the strings.
.Pp
The output file, if not specified on the command line, is named
.Ar source_file Ns Sy .out .
.Pp
The options are as follows:
.Bl -tag -width "-c char"
.It Fl c Ar char
Change the delimiting character from the percent sign to
.Ar char .
.It Fl i
Ignore case when ordering the strings.
.It Fl o
Order the strings in alphabetical order.
The offset table will be sorted in the alphabetical order of the
groups of lines referenced.
Any initial non-alphanumeric characters are ignored.
This option causes the
.Dv STR_ORDERED
bit in the header
.Ar str_flags
field to be set.
.It Fl r
Randomize access to the strings.
Entries in the offset table will be randomly ordered.
This option causes the
.Dv STR_RANDOM
bit in the header
.Ar str_flags
field to be set.
.It Fl s
Run silently; don't give a summary message when finished.
.It Fl x
Note that each alphabetic character in the groups of lines is rotated
13 positions in a simple caesar cypher.
This option causes the
.Dv STR_ROTATED
bit in the header
.Ar str_flags
field to be set.
.El
.Pp
The format of the header is:
.Bd -literal
#define VERSION 1
unsigned long str_version; /* version number */
unsigned long str_numstr; /* # of strings in the file */
unsigned long str_longlen; /* length of longest string */
unsigned long str_shortlen; /* length of shortest string */
#define STR_RANDOM 0x1 /* randomized pointers */
#define STR_ORDERED 0x2 /* ordered pointers */
#define STR_ROTATED 0x4 /* rot-13'd text */
unsigned long str_flags; /* bit field for flags */
char str_delim; /* delimiting character */
.Ed
.Pp
All fields are written in network byte order.
.Pp
The purpose of
.Nm unstr
is to undo the work of
.Nm strfile .
It prints out the strings contained in the file
.Ar source_file
in the order that they are listed in
the header file
.Ar source_file Ns Pa .dat
to standard output.
It is possible to create sorted versions of input files by using
.Fl o
when
.Nm strfile
is run and then using
.Nm unstr
to dump them out in the table order.
.Sh SEE ALSO
.Xr byteorder 3 ,
.Xr fortune 6
.Sh FILES
.Bl -tag -width strfile.out -compact
.It Pa strfile.out
default output file.
.El
.Sh HISTORY
The
.Nm strfile
utility first appeared in
.Bx 4.4 .

View File

@@ -1,4 +1,4 @@
/* $NetBSD: strfile.c,v 1.8 1998/09/13 15:27:28 hubertf Exp $ */
/* $NetBSD: strfile.c,v 1.21 2001/07/22 13:34:00 wiz Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -36,6 +36,7 @@
* SUCH DAMAGE.
*/
#if 1
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
@@ -46,28 +47,46 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
#if 0
static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: strfile.c,v 1.8 1998/09/13 15:27:28 hubertf Exp $");
__RCSID("$NetBSD: strfile.c,v 1.21 2001/07/22 13:34:00 wiz Exp $");
#endif
#endif /* not lint */
#endif /* __NetBSD__ */
# include <sys/types.h>
# include <sys/param.h>
# include <err.h>
# include <ctype.h>
# include <netinet/in.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
# include <unistd.h>
# ifndef u_int32_t
# define u_int32_t unsigned int
# endif
# include "strfile.h"
# ifndef MAXPATHLEN
# define MAXPATHLEN 1024
# endif /* MAXPATHLEN */
static u_int32_t
h2nl(u_int32_t h)
{
unsigned char c[4];
u_int32_t rv;
c[0] = (h >> 24) & 0xff;
c[1] = (h >> 16) & 0xff;
c[2] = (h >> 8) & 0xff;
c[3] = (h >> 0) & 0xff;
memcpy(&rv, c, sizeof rv);
return (rv);
}
/*
* This program takes a file composed of strings seperated by
* This program takes a file composed of strings separated by
* lines starting with two consecutive delimiting character (default
* character is '%') and creates another file which consists of a table
* describing the file (structure from "strfile.h"), a table of seek
@@ -95,24 +114,15 @@ __RCSID("$NetBSD: strfile.c,v 1.8 1998/09/13 15:27:28 hubertf Exp $");
# define STORING_PTRS (Oflag || Rflag)
# define CHUNKSIZE 512
#ifdef lint
# define ALWAYS atoi("1")
#else
# define ALWAYS 1
#endif
# define ALLOC(ptr,sz) do { \
if (ptr == NULL) \
ptr = malloc((unsigned int) (CHUNKSIZE * sizeof *ptr)); \
ptr = malloc(CHUNKSIZE * sizeof *ptr); \
else if (((sz) + 1) % CHUNKSIZE == 0) \
ptr = realloc((void *) ptr, ((unsigned int) ((sz) + CHUNKSIZE) * sizeof *ptr)); \
ptr = realloc(ptr, ((sz) + CHUNKSIZE) * sizeof *ptr); \
if (ptr == NULL) \
errx(1, "out of space"); \
die("out of space"); \
} while (0)
#ifdef NO_VOID
# define void char
#endif
typedef struct {
char first;
off_t pos;
@@ -137,14 +147,22 @@ STRFILE Tbl; /* statistics table */
STR *Firstch; /* first chars of each string */
void add_offset __P((FILE *, off_t));
int cmp_str __P((const void *, const void *));
void do_order __P((void));
void getargs __P((int, char *[]));
int main __P((int, char *[]));
void randomize __P((void));
char *unctrl __P((char));
void usage __P((void)) __attribute__((__noreturn__));
#ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__))
#else
#define NORETURN
#endif
void add_offset(FILE *, off_t);
int cmp_str(const void *, const void *);
void die(const char *) NORETURN;
void dieperror(const char *, char *) NORETURN;
void do_order(void);
void fwrite_be_offt(off_t, FILE *);
void getargs(int, char *[]);
int main(int, char *[]);
void randomize(void);
void usage(void) NORETURN;
/*
@@ -169,22 +187,26 @@ main(ac, av)
STR *fp;
static char string[257];
/* sanity test */
if (sizeof(u_int32_t) != 4)
die("sizeof(unsigned int) != 4");
getargs(ac, av); /* evalute arguments */
dc = Delimch;
if ((inf = fopen(Infile, "r")) == NULL)
err(1, "open `%s'", Infile);
dieperror("open `%s'", Infile);
if ((outf = fopen(Outfile, "w")) == NULL)
err(1, "open `%s'", Outfile);
dieperror("open `%s'", Outfile);
if (!STORING_PTRS)
(void) fseek(outf, sizeof Tbl, 0);
(void) fseek(outf, sizeof Tbl, SEEK_SET);
/*
* Write the strings onto the file
*/
Tbl.str_longlen = 0;
Tbl.str_shortlen = (unsigned int) 0xffffffff;
Tbl.str_shortlen = (unsigned int) 0x7fffffff;
Tbl.str_delim = dc;
Tbl.str_version = VERSION;
first = Oflag;
@@ -239,24 +261,26 @@ main(ac, av)
puts("There was 1 string");
else
printf("There were %d strings\n", (int)(Num_pts - 1));
printf("Longest string: %lu byte%s\n", Tbl.str_longlen,
printf("Longest string: %lu byte%s\n", (unsigned long)Tbl.str_longlen,
Tbl.str_longlen == 1 ? "" : "s");
printf("Shortest string: %lu byte%s\n", Tbl.str_shortlen,
printf("Shortest string: %lu byte%s\n", (unsigned long)Tbl.str_shortlen,
Tbl.str_shortlen == 1 ? "" : "s");
}
(void) fseek(outf, (off_t) 0, 0);
Tbl.str_version = htonl(Tbl.str_version);
Tbl.str_numstr = htonl(Num_pts - 1);
Tbl.str_longlen = htonl(Tbl.str_longlen);
Tbl.str_shortlen = htonl(Tbl.str_shortlen);
Tbl.str_flags = htonl(Tbl.str_flags);
(void) fseek(outf, (off_t) 0, SEEK_SET);
Tbl.str_version = h2nl(Tbl.str_version);
Tbl.str_numstr = h2nl(Num_pts - 1);
Tbl.str_longlen = h2nl(Tbl.str_longlen);
Tbl.str_shortlen = h2nl(Tbl.str_shortlen);
Tbl.str_flags = h2nl(Tbl.str_flags);
(void) fwrite((char *) &Tbl, sizeof Tbl, 1, outf);
if (STORING_PTRS) {
for (p = Seekpts, cnt = Num_pts; cnt--; ++p)
*p = htonl(*p);
(void) fwrite((char *) Seekpts, sizeof *Seekpts, (int) Num_pts, outf);
fwrite_be_offt(*p, outf);
}
fflush(outf);
if (ferror(outf))
dieperror("fwrite %s", Outfile);
(void) fclose(outf);
exit(0);
}
@@ -270,6 +294,8 @@ getargs(argc, argv)
char **argv;
{
int ch;
extern int optind;
extern char *optarg;
while ((ch = getopt(argc, argv, "c:iorsx")) != -1)
switch(ch) {
@@ -324,6 +350,26 @@ usage()
exit(1);
}
void
die(str)
const char *str;
{
fprintf(stderr, "strfile: %s\n", str);
exit(1);
}
void
dieperror(fmt, file)
const char *fmt;
char *file;
{
fprintf(stderr, "strfile: ");
fprintf(stderr, fmt, file);
fprintf(stderr, ": ");
perror(NULL);
exit(1);
}
/*
* add_offset:
* Add an offset to the list, or write it out, as appropriate.
@@ -333,11 +379,9 @@ add_offset(fp, off)
FILE *fp;
off_t off;
{
off_t net;
if (!STORING_PTRS) {
net = htonl(off);
fwrite(&net, 1, sizeof net, fp);
fwrite_be_offt(off, fp);
} else {
ALLOC(Seekpts, Num_pts + 1);
Seekpts[Num_pts] = off;
@@ -369,31 +413,6 @@ do_order()
Tbl.str_flags |= STR_ORDERED;
}
/*
* cmp_str:
* Compare two strings in the file
*/
char *
unctrl(c)
char c;
{
static char buf[3];
if (isprint(c)) {
buf[0] = c;
buf[1] = '\0';
}
else if (c == 0177) {
buf[0] = '^';
buf[1] = '?';
}
else {
buf[0] = '^';
buf[1] = c + 'A' - 1;
}
return buf;
}
int
cmp_str(vp1, vp2)
const void *vp1, *vp2;
@@ -413,8 +432,8 @@ cmp_str(vp1, vp2)
if (c1 != c2)
return c1 - c2;
(void) fseek(Sort_1, p1->pos, 0);
(void) fseek(Sort_2, p2->pos, 0);
(void) fseek(Sort_1, p1->pos, SEEK_SET);
(void) fseek(Sort_2, p2->pos, SEEK_SET);
n1 = FALSE;
n2 = FALSE;
@@ -473,3 +492,23 @@ randomize()
sp[i] = tmp;
}
}
/*
* fwrite_be_offt:
* Write out the off paramater as a 64 bit big endian number
*/
void
fwrite_be_offt(off, f)
off_t off;
FILE *f;
{
int i;
unsigned char c[8];
for (i = 7; i >= 0; i--) {
c[i] = off & 0xff;
off >>= 8;
}
fwrite(c, sizeof(c), 1, f);
}

View File

@@ -1,4 +1,4 @@
/* $NetBSD: strfile.h,v 1.3 1995/03/23 08:28:49 cgd Exp $ */
/* $NetBSD: strfile.h,v 1.5 1999/12/30 01:26:44 simonb Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -38,19 +38,21 @@
* @(#)strfile.h 8.1 (Berkeley) 5/31/93
*/
#include <sys/types.h>
#define STR_ENDSTRING(line,tbl) \
((line)[0] == (tbl).str_delim && (line)[1] == '\n')
typedef struct { /* information table */
#define VERSION 1
unsigned long str_version; /* version number */
unsigned long str_numstr; /* # of strings in the file */
unsigned long str_longlen; /* length of longest string */
unsigned long str_shortlen; /* length of shortest string */
u_int32_t str_version; /* version number */
u_int32_t str_numstr; /* # of strings in the file */
u_int32_t str_longlen; /* length of longest string */
u_int32_t str_shortlen; /* length of shortest string */
#define STR_RANDOM 0x1 /* randomized pointers */
#define STR_ORDERED 0x2 /* ordered pointers */
#define STR_ROTATED 0x4 /* rot-13'd text */
unsigned long str_flags; /* bit field for flags */
u_int32_t str_flags; /* bit field for flags */
unsigned char stuff[4]; /* long aligned space */
#define str_delim stuff[0] /* delimiting character */
} STRFILE;