Пример #1
0
/* ARGSUSED */
int
main(int ac __unused, char *av[])
{
	static STRFILE tbl;		/* description table */

	getargs(av);
	if ((Inf = fopen(Infile, "r")) == NULL) {
		perror(Infile);
		exit(1);
	}
	if ((Dataf = fopen(Datafile, "r")) == NULL) {
		perror(Datafile);
		exit(1);
	}
	fread((char *)&tbl, sizeof(tbl), 1, Dataf);
	tbl.str_version = ntohl(tbl.str_version);
	tbl.str_numstr = ntohl(tbl.str_numstr);
	tbl.str_longlen = ntohl(tbl.str_longlen);
	tbl.str_shortlen = ntohl(tbl.str_shortlen);
	tbl.str_flags = ntohl(tbl.str_flags);
	if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM))) {
		fprintf(stderr, "nothing to do -- table in file order\n");
		exit(1);
	}
	Delimch = tbl.str_delim;
	order_unstr(&tbl);
	fclose(Inf);
	fclose(Dataf);
	exit(0);
}
Пример #2
0
/* ARGSUSED */
int
main(int argc, char *argv[])
{
	static STRFILE tbl;		/* description table */

	if (argc != 2) {
		fprintf(stderr, "usage: unstr datafile\n");
		exit(1);
	}
	Infile = argv[1];
	if ((size_t)snprintf(Datafile, sizeof(Datafile), "%s.dat", Infile) >=
	    sizeof(Datafile))
		errx(1, "%s name too long", Infile);
	if ((Inf = fopen(Infile, "r")) == NULL)
		err(1, "%s", Infile);
	if ((Dataf = fopen(Datafile, "r")) == NULL)
		err(1, "%s", Datafile);
	if (fread((char *)&tbl, sizeof(tbl), 1, Dataf) != 1) {
		if (feof(Dataf))
			errx(1, "%s read EOF", Datafile);
		else
			err(1, "%s read", Datafile);
	}
	tbl.str_version = ntohl(tbl.str_version);
	tbl.str_numstr = ntohl(tbl.str_numstr);
	tbl.str_longlen = ntohl(tbl.str_longlen);
	tbl.str_shortlen = ntohl(tbl.str_shortlen);
	tbl.str_flags = ntohl(tbl.str_flags);
	if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM)))
		errx(1, "nothing to do -- table in file order");
	Delimch = tbl.str_delim;
	order_unstr(&tbl);
	fclose(Inf);
	fclose(Dataf);
	exit(0);
}