Ejemplo n.º 1
0
static void 
init_compress(void)
{
	FILE *dicto;
 
	if ((dicto = fopen(WORDLIST_FILE, "r")) == NULL)
	{
		fprintf(stderr, "Cannot open %s dictionary file.\n", WORDLIST_FILE);
		exit(5);
	}
	init_compress_from_file(dicto);
	fclose(dicto);
}
Ejemplo n.º 2
0
int
main(int argc, char **argv)
{
	char buf[16384];
	const char *version;
	int db_load_format, dbflags, parmcnt;
	dbref grow;

	/* See where input and output are coming from */
	if (argc > 2) {
		fprintf(stderr, "Usage: %s [infile]\n", argv[0]);
		return 0;
	}

	if (argc < 2) {
		infile = stdin;
	} else {
		in_filename = (char *) string_dup(argv[1]);
		if ((infile = fopen(in_filename, "rb")) == NULL) {
			fprintf(stderr, "%s: unable to open input file.\n", argv[0]);
			return 0;
		}
	}

	/* Now, reopen stdout with binary mode so Windows doesn't add the \r */
	outfile = fdopen(1,"wb");
	if (outfile == NULL) {
		perror("Cannot open stdout as binary, line endings may be wrong");
		outfile=stdout;
		/* Not a fatal error */
	}

	/* read the db header */
	dbflags = db_read_header( infile, &version, &db_load_format, &grow, &parmcnt );

	/* Now recreate a new header */

	/* Put the ***Foxen_ <etc>*** back */
	if( DB_ID_VERSIONSTRING ) {
		fprintf( outfile, "%s\n", version );
	}

	/* Put the grow parameter back */
	if ( dbflags & DB_ID_GROW ) {
		fprintf( outfile, "%d\n", grow );
	}

	/* Put the parms back, and copy the parm lines directly */
	if( dbflags & DB_ID_PARMSINFO ) {
		int i;
		fprintf( outfile, "%d\n", DB_PARMSINFO );
		fprintf( outfile, "%d\n", parmcnt );
		for( i=0; i<parmcnt; ++i ) {
			if( fgets(buf, sizeof(buf), infile) ) {
				buf[sizeof(buf) - 1] = '\0';
				fprintf(outfile, "%s", buf);
			}
		}
	}

	/* initialize the decompression dictionary */
	if( dbflags & DB_ID_CATCOMPRESS ) {
		init_compress_from_file( infile );
	}

	/* Now handle each line in the rest of the file */
	/* This looks like a security hole of buffer overruns
	   but the buffer size is 4x as big as the one from the
	   main driver itself. */
	while (fgets(buf, sizeof(buf), infile)) {
		buf[sizeof(buf) - 1] = '\0';
		if( dbflags & DB_ID_CATCOMPRESS ) {
			fprintf(outfile, "%s", uncompress(buf));
		} else if ( dbflags & DB_ID_OLDCOMPRESS ) {
			fprintf(outfile, "%s", old_uncompress(buf));
		} else {
			fprintf(outfile, "%s", buf);
		}
	}

	exit(0);
	return 0;
}