1999-09-09 21:30:17 +04:00
|
|
|
/* $NetBSD: strfile.c,v 1.12 1999/09/09 17:30:19 jsm Exp $ */
|
1995-03-23 11:28:00 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1995-03-23 11:28:00 +03:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-10-11 11:48:58 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-10-11 11:48:58 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-23 11:28:00 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
1999-09-09 21:30:17 +04:00
|
|
|
__RCSID("$NetBSD: strfile.c,v 1.12 1999/09/09 17:30:19 jsm Exp $");
|
1995-03-23 11:28:00 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1996-10-13 04:01:05 +04:00
|
|
|
# include <sys/types.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
# include <sys/param.h>
|
1997-10-11 11:48:58 +04:00
|
|
|
# include <err.h>
|
|
|
|
# include <ctype.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
# include <stdio.h>
|
1997-10-11 11:48:58 +04:00
|
|
|
# include <stdlib.h>
|
1995-04-24 16:21:37 +04:00
|
|
|
# include <string.h>
|
1999-09-09 21:30:17 +04:00
|
|
|
# include <time.h>
|
1997-10-11 11:48:58 +04:00
|
|
|
# include <unistd.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
# include "strfile.h"
|
|
|
|
|
|
|
|
# ifndef MAXPATHLEN
|
|
|
|
# define MAXPATHLEN 1024
|
|
|
|
# endif /* MAXPATHLEN */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program takes a file composed of strings seperated 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
|
|
|
|
* pointers to the start of the strings, and the strings, each terminated
|
|
|
|
* by a null byte. Usage:
|
|
|
|
*
|
|
|
|
* % strfile [-iorsx] [ -cC ] sourcefile [ datafile ]
|
|
|
|
*
|
|
|
|
* c - Change delimiting character from '%' to 'C'
|
|
|
|
* s - Silent. Give no summary of data processed at the end of
|
|
|
|
* the run.
|
|
|
|
* o - order the strings in alphabetic order
|
|
|
|
* i - if ordering, ignore case
|
|
|
|
* r - randomize the order of the strings
|
|
|
|
* x - set rotated bit
|
|
|
|
*
|
|
|
|
* Ken Arnold Sept. 7, 1978 --
|
|
|
|
*
|
|
|
|
* Added ordering options.
|
|
|
|
*/
|
|
|
|
|
|
|
|
# define TRUE 1
|
|
|
|
# define FALSE 0
|
|
|
|
|
|
|
|
# define STORING_PTRS (Oflag || Rflag)
|
|
|
|
# define CHUNKSIZE 512
|
|
|
|
|
|
|
|
#ifdef lint
|
|
|
|
# define ALWAYS atoi("1")
|
|
|
|
#else
|
|
|
|
# define ALWAYS 1
|
|
|
|
#endif
|
|
|
|
# define ALLOC(ptr,sz) if (ALWAYS) { \
|
|
|
|
if (ptr == NULL) \
|
|
|
|
ptr = malloc((unsigned int) (CHUNKSIZE * sizeof *ptr)); \
|
|
|
|
else if (((sz) + 1) % CHUNKSIZE == 0) \
|
|
|
|
ptr = realloc((void *) ptr, ((unsigned int) ((sz) + CHUNKSIZE) * sizeof *ptr)); \
|
1997-10-11 11:48:58 +04:00
|
|
|
if (ptr == NULL) \
|
|
|
|
errx(1, "out of space"); \
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
|
|
|
|
#ifdef NO_VOID
|
|
|
|
# define void char
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char first;
|
|
|
|
off_t pos;
|
|
|
|
} STR;
|
|
|
|
|
|
|
|
char *Infile = NULL, /* input file name */
|
|
|
|
Outfile[MAXPATHLEN] = "", /* output file name */
|
|
|
|
Delimch = '%'; /* delimiting character */
|
|
|
|
|
|
|
|
int Sflag = FALSE; /* silent run flag */
|
|
|
|
int Oflag = FALSE; /* ordering flag */
|
|
|
|
int Iflag = FALSE; /* ignore case flag */
|
|
|
|
int Rflag = FALSE; /* randomize order flag */
|
|
|
|
int Xflag = FALSE; /* set rotated bit */
|
|
|
|
long Num_pts = 0; /* number of pointers/strings */
|
|
|
|
|
|
|
|
off_t *Seekpts;
|
|
|
|
|
|
|
|
FILE *Sort_1, *Sort_2; /* pointers for sorting */
|
|
|
|
|
|
|
|
STRFILE Tbl; /* statistics table */
|
|
|
|
|
|
|
|
STR *Firstch; /* first chars of each string */
|
|
|
|
|
1997-10-11 11:48:58 +04:00
|
|
|
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));
|
1998-09-13 19:27:25 +04:00
|
|
|
void usage __P((void)) __attribute__((__noreturn__));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* main:
|
|
|
|
* Drive the sucker. There are two main modes -- either we store
|
|
|
|
* the seek pointers, if the table is to be sorted or randomized,
|
|
|
|
* or we write the pointer directly to the file, if we are to stay
|
|
|
|
* in file order. If the former, we allocate and re-allocate in
|
|
|
|
* CHUNKSIZE blocks; if the latter, we just write each pointer,
|
|
|
|
* and then seek back to the beginning to write in the table.
|
|
|
|
*/
|
1997-10-11 11:48:58 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
main(ac, av)
|
1997-10-11 11:48:58 +04:00
|
|
|
int ac;
|
|
|
|
char *av[];
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-11 11:48:58 +04:00
|
|
|
char *sp, dc;
|
|
|
|
FILE *inf, *outf;
|
|
|
|
off_t last_off, length, pos, *p;
|
|
|
|
int first, cnt;
|
|
|
|
char *nsp;
|
|
|
|
STR *fp;
|
|
|
|
static char string[257];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
getargs(ac, av); /* evalute arguments */
|
|
|
|
dc = Delimch;
|
1997-10-11 11:48:58 +04:00
|
|
|
if ((inf = fopen(Infile, "r")) == NULL)
|
|
|
|
err(1, "open `%s'", Infile);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-11 11:48:58 +04:00
|
|
|
if ((outf = fopen(Outfile, "w")) == NULL)
|
|
|
|
err(1, "open `%s'", Outfile);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!STORING_PTRS)
|
1999-09-09 01:57:16 +04:00
|
|
|
(void) fseek(outf, sizeof Tbl, SEEK_SET);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the strings onto the file
|
|
|
|
*/
|
|
|
|
|
|
|
|
Tbl.str_longlen = 0;
|
|
|
|
Tbl.str_shortlen = (unsigned int) 0xffffffff;
|
|
|
|
Tbl.str_delim = dc;
|
|
|
|
Tbl.str_version = VERSION;
|
|
|
|
first = Oflag;
|
|
|
|
add_offset(outf, ftell(inf));
|
|
|
|
last_off = 0;
|
|
|
|
do {
|
|
|
|
sp = fgets(string, 256, inf);
|
1997-10-11 11:48:58 +04:00
|
|
|
if (sp == NULL || (sp[0] == dc && sp[1] == '\n')) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pos = ftell(inf);
|
|
|
|
length = pos - last_off - (sp ? strlen(sp) : 0);
|
|
|
|
last_off = pos;
|
|
|
|
if (!length)
|
|
|
|
continue;
|
|
|
|
add_offset(outf, pos);
|
|
|
|
if (Tbl.str_longlen < length)
|
|
|
|
Tbl.str_longlen = length;
|
|
|
|
if (Tbl.str_shortlen > length)
|
|
|
|
Tbl.str_shortlen = length;
|
|
|
|
first = Oflag;
|
|
|
|
}
|
|
|
|
else if (first) {
|
|
|
|
for (nsp = sp; !isalnum(*nsp); nsp++)
|
|
|
|
continue;
|
|
|
|
ALLOC(Firstch, Num_pts);
|
|
|
|
fp = &Firstch[Num_pts - 1];
|
|
|
|
if (Iflag && isupper(*nsp))
|
|
|
|
fp->first = tolower(*nsp);
|
|
|
|
else
|
|
|
|
fp->first = *nsp;
|
|
|
|
fp->pos = Seekpts[Num_pts - 1];
|
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
} while (sp != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write the tables in
|
|
|
|
*/
|
|
|
|
|
|
|
|
(void) fclose(inf);
|
|
|
|
|
|
|
|
if (Oflag)
|
|
|
|
do_order();
|
|
|
|
else if (Rflag)
|
|
|
|
randomize();
|
|
|
|
|
|
|
|
if (Xflag)
|
|
|
|
Tbl.str_flags |= STR_ROTATED;
|
|
|
|
|
|
|
|
if (!Sflag) {
|
|
|
|
printf("\"%s\" created\n", Outfile);
|
|
|
|
if (Num_pts == 2)
|
|
|
|
puts("There was 1 string");
|
|
|
|
else
|
1997-10-11 11:48:58 +04:00
|
|
|
printf("There were %d strings\n", (int)(Num_pts - 1));
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("Longest string: %lu byte%s\n", Tbl.str_longlen,
|
|
|
|
Tbl.str_longlen == 1 ? "" : "s");
|
|
|
|
printf("Shortest string: %lu byte%s\n", Tbl.str_shortlen,
|
|
|
|
Tbl.str_shortlen == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
|
1999-09-09 01:57:16 +04:00
|
|
|
(void) fseek(outf, (off_t) 0, SEEK_SET);
|
1999-08-21 11:02:46 +04:00
|
|
|
HTOBE32(Tbl.str_version);
|
|
|
|
Tbl.str_numstr = htobe32(Num_pts - 1);
|
|
|
|
HTOBE32(Tbl.str_longlen);
|
|
|
|
HTOBE32(Tbl.str_shortlen);
|
|
|
|
HTOBE32(Tbl.str_flags);
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) fwrite((char *) &Tbl, sizeof Tbl, 1, outf);
|
|
|
|
if (STORING_PTRS) {
|
|
|
|
for (p = Seekpts, cnt = Num_pts; cnt--; ++p)
|
1999-08-21 11:02:46 +04:00
|
|
|
HTOBE64(*p);
|
1993-03-21 12:45:37 +03:00
|
|
|
(void) fwrite((char *) Seekpts, sizeof *Seekpts, (int) Num_pts, outf);
|
|
|
|
}
|
|
|
|
(void) fclose(outf);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine evaluates arguments from the command line
|
|
|
|
*/
|
1997-10-11 11:48:58 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
getargs(argc, argv)
|
1997-10-11 11:48:58 +04:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
|
1997-10-10 17:04:33 +04:00
|
|
|
while ((ch = getopt(argc, argv, "c:iorsx")) != -1)
|
1993-03-21 12:45:37 +03:00
|
|
|
switch(ch) {
|
|
|
|
case 'c': /* new delimiting char */
|
|
|
|
Delimch = *optarg;
|
|
|
|
if (!isascii(Delimch)) {
|
|
|
|
printf("bad delimiting character: '\\%o\n'",
|
|
|
|
Delimch);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i': /* ignore case in ordering */
|
|
|
|
Iflag++;
|
|
|
|
break;
|
|
|
|
case 'o': /* order strings */
|
|
|
|
Oflag++;
|
|
|
|
break;
|
|
|
|
case 'r': /* randomize pointers */
|
|
|
|
Rflag++;
|
|
|
|
break;
|
|
|
|
case 's': /* silent */
|
|
|
|
Sflag++;
|
|
|
|
break;
|
|
|
|
case 'x': /* set the rotated bit */
|
|
|
|
Xflag++;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (*argv) {
|
|
|
|
Infile = *argv;
|
|
|
|
if (*++argv)
|
|
|
|
(void) strcpy(Outfile, *argv);
|
|
|
|
}
|
|
|
|
if (!Infile) {
|
|
|
|
puts("No input file name");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
if (*Outfile == '\0') {
|
|
|
|
(void) strcpy(Outfile, Infile);
|
|
|
|
(void) strcat(Outfile, ".dat");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-11 11:48:58 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"strfile [-iorsx] [-c char] sourcefile [datafile]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add_offset:
|
|
|
|
* Add an offset to the list, or write it out, as appropriate.
|
|
|
|
*/
|
1997-10-11 11:48:58 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
add_offset(fp, off)
|
1997-10-11 11:48:58 +04:00
|
|
|
FILE *fp;
|
|
|
|
off_t off;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
off_t net;
|
|
|
|
|
|
|
|
if (!STORING_PTRS) {
|
1999-08-21 11:02:46 +04:00
|
|
|
net = htobe64(off);
|
1993-03-21 12:45:37 +03:00
|
|
|
fwrite(&net, 1, sizeof net, fp);
|
|
|
|
} else {
|
|
|
|
ALLOC(Seekpts, Num_pts + 1);
|
|
|
|
Seekpts[Num_pts] = off;
|
|
|
|
}
|
|
|
|
Num_pts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do_order:
|
|
|
|
* Order the strings alphabetically (possibly ignoring case).
|
|
|
|
*/
|
1997-10-11 11:48:58 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
do_order()
|
|
|
|
{
|
1997-10-11 11:48:58 +04:00
|
|
|
int i;
|
|
|
|
off_t *lp;
|
|
|
|
STR *fp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
Sort_1 = fopen(Infile, "r");
|
|
|
|
Sort_2 = fopen(Infile, "r");
|
|
|
|
qsort((char *) Firstch, (int) Tbl.str_numstr, sizeof *Firstch, cmp_str);
|
|
|
|
i = Tbl.str_numstr;
|
|
|
|
lp = Seekpts;
|
|
|
|
fp = Firstch;
|
|
|
|
while (i--)
|
|
|
|
*lp++ = fp++->pos;
|
|
|
|
(void) fclose(Sort_1);
|
|
|
|
(void) fclose(Sort_2);
|
|
|
|
Tbl.str_flags |= STR_ORDERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cmp_str:
|
|
|
|
* Compare two strings in the file
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
unctrl(c)
|
1997-10-11 11:48:58 +04:00
|
|
|
char c;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1997-10-11 11:48:58 +04:00
|
|
|
int
|
|
|
|
cmp_str(vp1, vp2)
|
|
|
|
const void *vp1, *vp2;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const STR *p1, *p2;
|
1997-10-11 11:48:58 +04:00
|
|
|
int c1, c2;
|
|
|
|
int n1, n2;
|
|
|
|
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
p1 = (const STR *)vp1;
|
|
|
|
p2 = (const STR *)vp2;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
# define SET_N(nf,ch) (nf = (ch == '\n'))
|
|
|
|
# define IS_END(ch,nf) (ch == Delimch && nf)
|
|
|
|
|
|
|
|
c1 = p1->first;
|
|
|
|
c2 = p2->first;
|
|
|
|
if (c1 != c2)
|
|
|
|
return c1 - c2;
|
|
|
|
|
1999-09-09 01:57:16 +04:00
|
|
|
(void) fseek(Sort_1, p1->pos, SEEK_SET);
|
|
|
|
(void) fseek(Sort_2, p2->pos, SEEK_SET);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
n1 = FALSE;
|
|
|
|
n2 = FALSE;
|
|
|
|
while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0')
|
|
|
|
SET_N(n1, c1);
|
|
|
|
while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0')
|
|
|
|
SET_N(n2, c2);
|
|
|
|
|
|
|
|
while (!IS_END(c1, n1) && !IS_END(c2, n2)) {
|
|
|
|
if (Iflag) {
|
|
|
|
if (isupper(c1))
|
|
|
|
c1 = tolower(c1);
|
|
|
|
if (isupper(c2))
|
|
|
|
c2 = tolower(c2);
|
|
|
|
}
|
|
|
|
if (c1 != c2)
|
|
|
|
return c1 - c2;
|
|
|
|
SET_N(n1, c1);
|
|
|
|
SET_N(n2, c2);
|
|
|
|
c1 = getc(Sort_1);
|
|
|
|
c2 = getc(Sort_2);
|
|
|
|
}
|
|
|
|
if (IS_END(c1, n1))
|
|
|
|
c1 = 0;
|
|
|
|
if (IS_END(c2, n2))
|
|
|
|
c2 = 0;
|
|
|
|
return c1 - c2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* randomize:
|
|
|
|
* Randomize the order of the string table. We must be careful
|
|
|
|
* not to randomize across delimiter boundaries. All
|
|
|
|
* randomization is done within each block.
|
|
|
|
*/
|
1997-10-11 11:48:58 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
randomize()
|
|
|
|
{
|
1997-10-11 11:48:58 +04:00
|
|
|
int cnt, i;
|
|
|
|
off_t tmp;
|
|
|
|
off_t *sp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
srandom((int)(time((time_t *) NULL) + getpid()));
|
|
|
|
|
|
|
|
Tbl.str_flags |= STR_RANDOM;
|
|
|
|
cnt = Tbl.str_numstr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* move things around randomly
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (sp = Seekpts; cnt > 0; cnt--, sp++) {
|
|
|
|
i = random() % cnt;
|
|
|
|
tmp = sp[0];
|
|
|
|
sp[0] = sp[i];
|
|
|
|
sp[i] = tmp;
|
|
|
|
}
|
|
|
|
}
|