(void) fseek(outf, sizeof Tbl, 0);
(void) fseek(outf, sizeof Tbl, SEEK_SET);
main(ac, av)int	ac;char	**av;{	register char		*sp, dc;	register FILE		*inf, *outf;	register int32_t	last_off, length, pos;	register int32_t	*p;	register int		first, cnt;	register char		*nsp;	register STR		*fp;	static char		string[257];	getargs(ac, av);		/* evalute arguments */	dc = Delimch;	if ((inf = fopen(Infile, "r")) == NULL) {		perror(Infile);		exit(1);	}	if ((outf = fopen(Outfile, "w")) == NULL) {		perror(Outfile);		exit(1);	}	if (!STORING_PTRS)		(void) fseek(outf, sizeof Tbl, 0);	/*	 * 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);		if (sp == NULL || sp[0] == dc && sp[1] == '\n') {			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			printf("There were %d strings\n", Num_pts - 1);		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");	}	(void) fseek(outf, (long) 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) fwrite(&Tbl.str_version,  sizeof(Tbl.str_version),  1, outf);	(void) fwrite(&Tbl.str_numstr,   sizeof(Tbl.str_numstr),   1, outf);	(void) fwrite(&Tbl.str_longlen,  sizeof(Tbl.str_longlen),  1, outf);	(void) fwrite(&Tbl.str_shortlen, sizeof(Tbl.str_shortlen), 1, outf);	(void) fwrite(&Tbl.str_flags,    sizeof(Tbl.str_flags),    1, outf);	(void) fwrite( Tbl.stuff,	 sizeof(Tbl.stuff),	   1, outf);	if (STORING_PTRS)		for (p = Seekpts, cnt = Num_pts; cnt--; ++p) {			*p = htonl(*p);			(void) fwrite(p, sizeof(*p), 1, outf);		}	(void) fclose(outf);	exit(0);}