예제 #1
0
int
main(int argc, char **argv)
{
    char buf[16384];

    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, "r")) == NULL) {
            fprintf(stderr, "%s: unable to open input file.\n", argv[0]);
            return 0;
        }
    }

    while (fgets(buf, sizeof(buf), infile)) {
        buf[sizeof(buf) - 1] = '\0';
        fputs((char *) old_uncompress(buf), stdout);
    }
    exit(0);
    return 0;
}
예제 #2
0
int
db_get_single_prop(FILE * f, dbref obj, int pos)
{
    char getprop_buf[BUFFER_LEN * 3];
    char *name, *flags, *value, *p;
    int tpos = 0;
    bool do_diskbase_propvals;
    PData pdat;

#ifdef DISKBASE
    do_diskbase_propvals = tp_diskbase_propvals;
#else
    do_diskbase_propvals = 0;
#endif

    if (pos) {
        fseek(f, pos, 0);
    } else if (do_diskbase_propvals) {
        tpos = ftell(f);
    }
    name = fgets(getprop_buf, sizeof(getprop_buf), f);
    if (!name) {
        fprintf(stderr, "PANIC: Error reading property in from db file.\n");
        abort();
    }
    if (*name == '*') {
        if (!strcmp(name, "*End*\n")) {
            return 0;
        }
    }

    flags = index(name, PROP_DELIMITER);
    if (!flags) {               /* this usually means the db file has new lines in the
                                 * middle of properties. Something like this can be
                                 * salvaged by editing the props in question.
                                 */
        fprintf(stderr,
                "PANIC: Unable to find prop flags while loading props.\n");
        abort();
    }
    *flags++ = '\0';

    value = index(flags, PROP_DELIMITER);
    if (!value) {
        fprintf(stderr,
                "PANIC: Unable to find prop value while loading props.\n");
        abort();
    }
    *value++ = '\0';

    p = index(value, '\n');
    if (p)
        *p = '\0';

    if (!number(flags)) {
        fprintf(stderr, "PANIC: Prop flag was not a number. DB error.\n");
        abort();
    }

    pdat.flags = atoi(flags);

    switch (pdat.flags & PROP_TYPMASK) {
        case PROP_STRTYP:
            if (!do_diskbase_propvals || pos) {
                pdat.flags &= ~PROP_ISUNLOADED;
#if defined(COMPRESS) && defined(ARCHAIC_DATABASES)
                if (!(pdat.flags & PROP_COMPRESSED))
                    value = (char *) old_uncompress(value);
#endif
                pdat.data.str = value;
            } else {
                pdat.flags |= PROP_ISUNLOADED;
                pdat.data.pos = tpos;
            }
            break;
        case PROP_LOKTYP:
            if (!do_diskbase_propvals || pos) {
                pdat.flags &= ~PROP_ISUNLOADED;
                pdat.data.lok = parse_boolexp(-1, (dbref) 1, value, 32767);
            } else {
                pdat.flags |= PROP_ISUNLOADED;
                pdat.data.pos = tpos;
            }
            break;
        case PROP_INTTYP:
            if (!number(value)) {
                fprintf(stderr, "PANIC: INT prop had non-int value in db.\n");
                abort();
            }
            pdat.data.val = atoi(value);
            break;
        case PROP_FLTTYP:
            if (!number(value) && !ifloat(value)) {
                char *tpnt = value;
                int dtemp = 0;

                if ((*tpnt == '+') || (*tpnt == '-')) {
                    if (*tpnt == '+') {
                        dtemp = 0;
                    } else {
                        dtemp = 1;
                    }
                    tpnt++;
                }
                tpnt[0] = toupper(tpnt[0]);
                tpnt[1] = toupper(tpnt[1]);
                tpnt[2] = toupper(tpnt[2]);
                if (!strncmp(tpnt, "INF", 3)) {
                    if (!dtemp)
                        pdat.data.fval = INF;
                    else
                        pdat.data.fval = NINF;
                } else {
                    if (!strncmp(tpnt, "NAN", 3)) {
                        pdat.data.fval = NAN;
                    } else {
                        fprintf(stderr,
                                "PANIC:Float prop contained invalid value.\n");
                        abort();
                    }
                }
            } else {
                sscanf(value, "%lg", (double *) &pdat.data.fval);
            }
            break;
        case PROP_REFTYP:
            if (!number(value)) {
                fprintf(stderr,
                        "PANIC:Ref prop contained non-numeric value.\n");
                abort();
            }
            pdat.data.ref = atoi(value);
            break;
        case PROP_DIRTYP:
            break;
    }
    set_property_nofetch(obj, name, &pdat, 1);

    return 1;
}
예제 #3
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;
}