Nuke MAX_OSPATH and clean up the mess.

This commit is contained in:
Bill Currie 2010-08-24 16:20:07 +09:00
parent baede61f4f
commit a51e888a1b
26 changed files with 202 additions and 179 deletions

View file

@ -41,8 +41,6 @@
//============================================================================
#define MAX_OSPATH 128 // max length of a filesystem pathname
#define MAX_GAMEDIR_CALLBACKS 128 // most QFS_GamedirCallback calls.
typedef struct filelist_s {
@ -52,7 +50,7 @@ typedef struct filelist_s {
} filelist_t;
typedef struct searchpath_s {
char filename[MAX_OSPATH];
char *filename;
struct pack_s *pack; // only one of filename / pack will be used
struct searchpath_s *next;
} searchpath_t;
@ -115,7 +113,8 @@ int QFS_NextFilename (struct dstring_s *filename, const char *prefix,
const char *ext);
char *QFS_FileBase (const char *in);
void QFS_DefaultExtension (char *path, const char *extension);
void QFS_DefaultExtension (struct dstring_s *path, const char *extension);
void QFS_SetExtension (struct dstring_s *path, const char *extension);
void QFS_StripExtension (const char *in, char *out);
char *QFS_CompressPath (const char *pth);
const char *QFS_SkipPath (const char *pathname);

View file

@ -252,7 +252,7 @@ Condump_f (void)
int line = con->current - con->numlines;
const char *start, *end;
QFile *file;
char name[MAX_OSPATH];
char *name;
if (Cmd_Argc () != 2) {
Sys_Printf ("usage: condump <filename>\n");
@ -263,8 +263,7 @@ Condump_f (void)
Sys_Printf ("invalid character in filename\n");
return;
}
snprintf (name, sizeof (name), "%s/%s.txt", qfs_gamedir->dir.def,
Cmd_Argv (1));
name = va ("%s/%s.txt", qfs_gamedir->dir.def, Cmd_Argv (1));
if (!(file = QFS_WOpen (name, 0))) {
Sys_Printf ("could not open %s for writing: %s\n", name,
@ -777,15 +776,13 @@ C_ProcessInput (void)
static void
C_NewMap (void)
{
static int first_time = 1;
static char old_gamedir[MAX_OSPATH];
static dstring_t *old_gamedir = 0;
if (first_time || !strequal (old_gamedir, qfs_gamedir->gamedir)) {
first_time = 0;
if (!old_gamedir || !strequal (old_gamedir->str, qfs_gamedir->gamedir))
Menu_Load ();
}
strncpy (old_gamedir, qfs_gamedir->gamedir, sizeof (old_gamedir));
old_gamedir[sizeof (old_gamedir) - 1] = 0;
if (!old_gamedir)
old_gamedir = dstring_newstr ();
dstring_copystr (old_gamedir, qfs_gamedir->gamedir);
}
static void

View file

@ -498,6 +498,9 @@ qfs_build_gamedir (const char **list)
free (qfs_searchpaths->pack->files);
free (qfs_searchpaths->pack);
}
if (qfs_searchpaths->filename)
free (qfs_searchpaths->filename);
next = qfs_searchpaths->next;
free (qfs_searchpaths);
qfs_searchpaths = next;
@ -1036,7 +1039,6 @@ QFS_LoadPackFile (char *packfile)
}
#define FBLOCK_SIZE 32
#define FNAME_SIZE MAX_OSPATH
// Note, this is /NOT/ a work-alike strcmp, this groups numbers sanely.
static int
@ -1109,12 +1111,9 @@ QFS_LoadGameDirectory (const char *dir)
pakfiles[i] = NULL;
}
pakfiles[count] = malloc (FNAME_SIZE);
pakfiles[count] = nva ("%s/%s", dir, dirent->d_name);
if (!pakfiles[count])
Sys_Error ("QFS_LoadGameDirectory: MemoryAllocationFailure");
snprintf (pakfiles[count], FNAME_SIZE - 1, "%s/%s", dir,
dirent->d_name);
pakfiles[count][FNAME_SIZE - 1] = '\0';
count++;
}
}
@ -1131,7 +1130,8 @@ QFS_LoadGameDirectory (const char *dir)
if (!pak) {
Sys_Error ("Bad pakfile %s!!", pakfiles[i]);
} else {
search = calloc (1, sizeof (searchpath_t));
search = malloc (sizeof (searchpath_t));
search->filename = 0;
search->pack = pak;
search->next = qfs_searchpaths;
qfs_searchpaths = search;
@ -1156,8 +1156,9 @@ QFS_AddDirectory (const char *dir)
searchpath_t *search;
// add the directory to the search path
search = calloc (1, sizeof (searchpath_t));
strcpy (search->filename, dir);
search = malloc (sizeof (searchpath_t));
search->filename = strdup (dir);
search->pack = 0;
search->next = qfs_searchpaths;
qfs_searchpaths = search;
@ -1359,21 +1360,33 @@ QFS_FileExtension (const char *in)
}
VISIBLE void
QFS_DefaultExtension (char *path, const char *extension)
QFS_DefaultExtension (dstring_t *path, const char *extension)
{
char *src;
const char *src;
// if path doesn't have a .EXT, append extension
// (extension should include the .)
src = path + strlen (path) - 1;
src = path->str + strlen (path->str) - 1;
while (*src != '/' && src != path) {
while (*src != '/' && src != path->str) {
if (*src == '.')
return; // it has an extension
src--;
}
strncat (path, extension, MAX_OSPATH - strlen (path));
dstring_appendstr (path, extension);
}
VISIBLE void
QFS_SetExtension (struct dstring_s *path, const char *extension)
{
const char *ext = QFS_FileExtension (path->str);
if (ext != path->str) {
path->str[ext - path->str] = 0;
path->size = ext - path->str + 1;
}
dstring_appendstr (path, extension);
}
VISIBLE int
@ -1503,7 +1516,6 @@ QFS_FilelistFill (filelist_t *list, const char *path, const char *ext,
searchpath_t *search;
DIR *dir_ptr;
struct dirent *dirent;
char buf[MAX_OSPATH];
for (search = qfs_searchpaths; search != NULL; search = search->next) {
if (search->pack) {
@ -1518,8 +1530,7 @@ QFS_FilelistFill (filelist_t *list, const char *path, const char *ext,
QFS_FilelistAdd (list, name, strip ? ext : 0);
}
} else {
snprintf (buf, sizeof (buf), "%s/%s", search->filename, path);
dir_ptr = opendir (buf);
dir_ptr = opendir (va ("%s/%s", search->filename, path));
if (!dir_ptr)
continue;
while ((dirent = readdir (dir_ptr)))

View file

@ -46,6 +46,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/quakefs.h"
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
#include "QF/GL/qf_explosions.h"
@ -191,7 +192,8 @@ R_InitParticles (void)
void
R_ReadPointFile_f (void)
{
char name[MAX_OSPATH], *mapname, *t1;
const char *name;
char *mapname;
int c, r;
vec3_t org;
QFile *f;
@ -199,12 +201,9 @@ R_ReadPointFile_f (void)
mapname = strdup (r_worldentity.model->name);
if (!mapname)
Sys_Error ("Can't duplicate mapname!");
t1 = strrchr (mapname, '.');
if (!t1)
Sys_Error ("Can't find .!");
t1[0] = '\0';
QFS_StripExtension (mapname, mapname);
snprintf (name, sizeof (name), "%s.pts", mapname);
name = va ("%s.pts", mapname);
free (mapname);
QFS_FOpenFile (name, &f);

View file

@ -32,12 +32,19 @@ static __attribute__ ((used)) const char rcsid[] =
"$Id$";
#include <stdlib.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "QF/cvar.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "compat.h"
#include "r_cvar.h"
@ -75,9 +82,16 @@ R_ReadPointFile_f (void)
vec3_t org;
int c, r;
particle_t *p;
char name[MAX_OSPATH];
const char *name;
char *mapname;
// FIXME snprintf (name, sizeof (name), "maps/%s.pts", sv.name);
mapname = strdup (r_worldentity.model->name);
if (!mapname)
Sys_Error ("Can't duplicate mapname!");
QFS_StripExtension (mapname, mapname);
name = va ("maps/%s.pts", mapname);
free (mapname);
QFS_FOpenFile (name, &f);
if (!f) {

View file

@ -32,12 +32,19 @@ static __attribute__ ((used)) const char rcsid[] =
"$Id$";
#include <stdlib.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "QF/cvar.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "compat.h"
#include "r_cvar.h"
@ -76,9 +83,16 @@ R_ReadPointFile_f (void)
int r;
int c;
particle_t *p;
char name[MAX_OSPATH];
const char *name;
char *mapname;
// FIXME snprintf (name, sizeof (name), "maps/%s.pts", sv.name);
mapname = strdup (r_worldentity.model->name);
if (!mapname)
Sys_Error ("Can't duplicate mapname!");
QFS_StripExtension (mapname, mapname);
name = va ("maps/%s.pts", mapname);
free (mapname);
QFS_FOpenFile (name, &f);
if (!f) {

View file

@ -106,8 +106,8 @@ typedef struct
// file transfer from server
QFile *download;
char downloadtempname[MAX_OSPATH];
char downloadname[MAX_OSPATH];
char *downloadtempname;
char *downloadname;
int downloadnumber;
dltype_t downloadtype;
int downloadpercent;

View file

@ -40,6 +40,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/keys.h"
#include "QF/msg.h"
#include "QF/qendian.h"
@ -222,7 +223,7 @@ void
CL_Record_f (void)
{
int c;
char name[MAX_OSPATH];
dstring_t *name;
int track;
if (cmd_source != src_command)
@ -251,8 +252,8 @@ CL_Record_f (void)
} else
track = -1;
snprintf (name, sizeof (name), "%s/%s",
qfs_gamedir->dir.def, Cmd_Argv (1));
name = dstring_new ();
dsprintf (name, "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1));
// start the map up
//
@ -264,32 +265,31 @@ CL_Record_f (void)
#ifdef HAVE_ZLIB
if (demo_gzip->int_val) {
QFS_DefaultExtension (name, ".dem.gz");
cls.demofile = QFS_WOpen (name, demo_gzip->int_val);
cls.demofile = QFS_WOpen (name->str, demo_gzip->int_val);
} else
#endif
{
QFS_DefaultExtension (name, ".dem");
cls.demofile = QFS_WOpen (name, 0);
cls.demofile = QFS_WOpen (name->str, 0);
}
if (!cls.demofile) {
Sys_Printf ("ERROR: couldn't open.\n");
return;
} else {
Sys_Printf ("recording to %s.\n", name->str);
cls.demorecording = true;
cls.forcetrack = track;
Qprintf (cls.demofile, "%i\n", cls.forcetrack);
}
Sys_Printf ("recording to %s.\n", name);
cls.demorecording = true;
cls.forcetrack = track;
Qprintf (cls.demofile, "%i\n", cls.forcetrack);
dstring_delete (name);
}
static void
CL_StartDemo (void)
{
char name[256];
dstring_t *name;
int c;
qboolean neg = false;
@ -299,11 +299,12 @@ CL_StartDemo (void)
// open the demo file
//
strncpy (name, demoname, sizeof (name));
name = dstring_strdup (demoname);
QFS_DefaultExtension (name, ".dem");
Sys_Printf ("Playing demo from %s.\n", name);
QFS_FOpenFile (name, &cls.demofile);
Sys_Printf ("Playing demo from %s.\n", name->str);
QFS_FOpenFile (name->str, &cls.demofile);
dstring_delete (name);
if (!cls.demofile) {
Sys_Printf ("ERROR: couldn't open.\n");
cls.demonum = -1; // stop demo loop
@ -324,9 +325,8 @@ CL_StartDemo (void)
if (neg)
cls.forcetrack = -cls.forcetrack;
// ZOID, fscanf is evil
// fscanf (cls.demofile, "%i\n", &cls.forcetrack);
}
/*
CL_PlayDemo_f

View file

@ -533,7 +533,7 @@ convert_to_game_dict (script_t *script)
static void
Host_Savegame_f (void)
{
char name[256];
dstring_t *name;
char *save_text;
QFile *f;
int i;
@ -574,12 +574,13 @@ Host_Savegame_f (void)
}
}
snprintf (name, sizeof (name), "%s/%s",
qfs_gamedir->dir.def, Cmd_Argv (1));
name = dstring_newstr ();
dsprintf (name, "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1));
QFS_DefaultExtension (name, ".sav");
Sys_Printf ("Saving game to %s...\n", name);
f = QFS_WOpen (name, 0);
Sys_Printf ("Saving game to %s...\n", name->str);
f = QFS_WOpen (name->str, 0);
dstring_delete (name);
if (!f) {
Sys_Printf ("ERROR: couldn't open.\n");
return;
@ -622,10 +623,7 @@ Host_Loadgame_f (void)
name = dstring_newstr ();
dsprintf (name, "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1));
name->size += 4;
dstring_adjust (name);
QFS_DefaultExtension (name->str, ".sav");
QFS_DefaultExtension (name, ".sav");
// we can't call SCR_BeginLoadingPlaque, because too much stack space has
// been used. The menu calls it before stuffing loadgame command

View file

@ -145,7 +145,7 @@ typedef struct
// private userinfo for sending to masterless servers
struct info_s *userinfo;
char servername[MAX_OSPATH]; // name of server from original connect
struct dstring_s *servername; // name of server from original connect
netadr_t server_addr; // address of server
int qport;

View file

@ -49,6 +49,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/cbuf.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/msg.h"
#include "QF/qendian.h"
#include "QF/sys.h"
@ -514,12 +515,11 @@ void
CL_Record (const char *argv1)
{
byte buf_data[MAX_MSGLEN + 10]; // + 10 for header
char name[MAX_OSPATH];
dstring_t *name;
char *s;
char timestring[20];
char mapname[MAX_OSPATH];
int n, i, j, l=0;
int n, i, j;
size_t k;
int seq = 1;
entity_t *ent;
@ -529,20 +529,14 @@ CL_Record (const char *argv1)
time_t tim;
if (!argv1) {
char *mapname;
// Get time to a useable format
time (&tim);
strftime (timestring, 19, "%Y-%m-%d-%H-%M", localtime (&tim));
// the leading path-name is to be removed from cl.worldmodel->name
for (k = 0; k <= strlen (cl.worldmodel->name); k++) {
if (cl.worldmodel->name[k] == '/') {
l = 0;
mapname[l] = '\0';
continue;
}
mapname[l] = cl.worldmodel->name[k];
l++;
}
mapname = strdup (QFS_SkipPath (cl.worldmodel->name));
// the map name is cut off after any "." because this would prevent
// ".qwd" from being appended
@ -551,29 +545,33 @@ CL_Record (const char *argv1)
if (mapname[k] == '.')
mapname[k] = '\0';
snprintf (name, sizeof (name), "%s/%s-%s", qfs_gamedir->dir.def,
timestring, mapname);
name = dstring_new ();
dsprintf (name, "%s/%s-%s", qfs_gamedir->dir.def, timestring, mapname);
free (mapname);
} else {
snprintf (name, sizeof (name), "%s/%s", qfs_gamedir->dir.def, argv1);
name = dstring_new ();
dsprintf (name, "%s/%s", qfs_gamedir->dir.def, argv1);
}
// open the demo file
#ifdef HAVE_ZLIB
if (demo_gzip->int_val) {
QFS_DefaultExtension (name, ".qwd.gz");
cls.demofile = QFS_WOpen (name, demo_gzip->int_val);
cls.demofile = QFS_WOpen (name->str, demo_gzip->int_val);
} else
#endif
{
QFS_DefaultExtension (name, ".qwd");
cls.demofile = QFS_WOpen (name, 0);
cls.demofile = QFS_WOpen (name->str, 0);
}
if (!cls.demofile) {
Sys_Printf ("ERROR: couldn't open.\n");
dstring_delete (name);
return;
}
Sys_Printf ("recording to %s.\n", name);
Sys_Printf ("recording to %s.\n", name->str);
dstring_delete (name);
cls.demorecording = true;
/*-------------------------------------------------*/
@ -843,7 +841,7 @@ CL_Record_f (void)
void
CL_ReRecord_f (void)
{
char name[MAX_OSPATH];
dstring_t *name;
int c;
c = Cmd_Argc ();
@ -852,53 +850,54 @@ CL_ReRecord_f (void)
return;
}
if (!*cls.servername) {
Sys_Printf ("No server to reconnect to...\n");
if (!cls.servername || !cls.servername->str) {
Sys_Printf ("No server to which to reconnect...\n");
return;
}
if (cls.demorecording)
CL_Stop_f ();
snprintf (name, sizeof (name), "%s/%s",
qfs_gamedir->dir.def, Cmd_Argv (1));
name = dstring_newstr ();
dsprintf (name, "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1));
// open the demo file
QFS_DefaultExtension (name, ".qwd");
cls.demofile = QFS_WOpen (name, 0);
cls.demofile = QFS_WOpen (name->str, 0);
if (!cls.demofile) {
Sys_Printf ("ERROR: couldn't open.\n");
return;
} else {
Sys_Printf ("recording to %s.\n", name->str);
cls.demorecording = true;
CL_Disconnect ();
CL_BeginServerConnect ();
}
Sys_Printf ("recording to %s.\n", name);
cls.demorecording = true;
CL_Disconnect ();
CL_BeginServerConnect ();
dstring_delete (name);
}
static void
CL_StartDemo (void)
{
char name[MAX_OSPATH];
dstring_t *name = dstring_newstr ();
// open the demo file
strncpy (name, demoname, sizeof (name));
dstring_copystr (name, demoname);
QFS_DefaultExtension (name, ".qwd");
Sys_Printf ("Playing demo from %s.\n", name);
QFS_FOpenFile (name, &cls.demofile);
Sys_Printf ("Playing demo from %s.\n", name->str);
QFS_FOpenFile (name->str, &cls.demofile);
if (!cls.demofile) {
Sys_Printf ("ERROR: couldn't open.\n");
cls.demonum = -1; // stop demo loop
dstring_delete (name);
return;
}
cls.demoplayback = true;
net_blocksend = 1;
if (strequal (QFS_FileExtension (name), ".mvd")) {
if (strequal (QFS_FileExtension (name->str), ".mvd")) {
cls.demoplayback2 = true;
Sys_Printf ("mvd\n");
} else {
@ -915,6 +914,8 @@ CL_StartDemo (void)
demotime_cached = 0;
nextdemotime = 0;
CL_ClearPredict ();
dstring_delete (name);
}
/*

View file

@ -274,7 +274,7 @@ CL_SendConnectPacket (void)
t1 = Sys_DoubleTime ();
if (!NET_StringToAdr (cls.servername, &cls.server_addr)) {
if (!NET_StringToAdr (cls.servername->str, &cls.server_addr)) {
Sys_Printf ("Bad server address\n");
connect_time = -1;
return;
@ -315,7 +315,7 @@ CL_CheckForResend (void)
return;
t1 = Sys_DoubleTime ();
if (!NET_StringToAdr (cls.servername, &cls.server_addr)) {
if (!NET_StringToAdr (cls.servername->str, &cls.server_addr)) {
Sys_Printf ("Bad server address\n");
connect_time = -1;
return;
@ -327,8 +327,8 @@ CL_CheckForResend (void)
connect_time = realtime + t2 - t1; // for retransmit requests
VID_SetCaption (va ("Connecting to %s", cls.servername));
Sys_Printf ("Connecting to %s...\n", cls.servername);
VID_SetCaption (va ("Connecting to %s", cls.servername->str));
Sys_Printf ("Connecting to %s...\n", cls.servername->str);
Netchan_SendPacket (strlen (getchallenge), (void *) getchallenge,
cls.server_addr);
}
@ -355,7 +355,7 @@ CL_Connect_f (void)
CL_Disconnect ();
CL_Chat_Flush_Ignores ();
strncpy (cls.servername, server, sizeof (cls.servername) - 1);
dstring_copystr (cls.servername, server);
CL_BeginServerConnect ();
}
@ -837,8 +837,8 @@ CL_Reconnect_f (void)
return;
}
if (!*cls.servername) {
Sys_Printf ("No server to reconnect to...\n");
if (!*cls.servername->str) {
Sys_Printf ("No server to which to reconnect...\n");
return;
}
@ -1158,7 +1158,7 @@ CL_SetState (cactive_t state)
CL_Stop_f ();
} else if (state == ca_active) {
// entering active state
VID_SetCaption (cls.servername);
VID_SetCaption (cls.servername->str);
IN_ClearStates ();
R_ClearEnts ();
r_active = true;
@ -1762,6 +1762,7 @@ Host_Init (void)
pr_gametype = "quakeworld";
cls.userinfo = Info_ParseString ("", MAX_INFO_STRING, 0);
cls.servername = dstring_newstr ();
cls.downloadtempname = dstring_newstr ();
cls.downloadname = dstring_newstr ();
cls.downloadurl = dstring_newstr ();

View file

@ -422,7 +422,7 @@ void
CL_FinishDownload (void)
{
Qclose (cls.download);
VID_SetCaption (va ("Connecting to %s", cls.servername));
VID_SetCaption (va ("Connecting to %s", cls.servername->str));
// rename the temp file to it's final name
if (strcmp (cls.downloadtempname->str, cls.downloadname->str)) {

View file

@ -43,6 +43,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/draw.h"
#include "QF/dstring.h"
#include "QF/image.h"
#include "QF/msg.h"
#include "QF/pcx.h"
@ -146,7 +147,7 @@ CL_RSShot_f (void)
SCR_DrawStringToSnap (st, tex, tex->width - strlen (st) * 8,
tex->height - 1);
strncpy (st, cls.servername, sizeof (st));
strncpy (st, cls.servername->str, sizeof (st));
st[sizeof (st) - 1] = 0;
SCR_DrawStringToSnap (st, tex, tex->width - strlen (st) * 8,
tex->height - 11);

View file

@ -65,6 +65,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/quakeio.h"
#include "QF/sys.h"
#include "QF/va.h"
@ -428,8 +429,8 @@ static void
SL_Connect (server_entry_t *sldata, int slitemno)
{
CL_Disconnect ();
strncpy (cls.servername, SL_Get_By_Num (sldata, (slitemno - 1))->server,
sizeof (cls.servername) - 0);
dstring_copystr (cls.servername,
SL_Get_By_Num (sldata, (slitemno - 1))->server);
CL_BeginServerConnect ();
}

View file

@ -48,6 +48,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/qtypes.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "client.h"
#include "compat.h"
@ -193,16 +194,13 @@ locs_reset (void)
void
locs_save (const char *filename, qboolean gz)
{
char locfile[MAX_OSPATH];
int i;
QFile *locfd;
if (gz) {
if (strncmp (filename + strlen (filename) - 3,".gz", 3) != 0)
snprintf (locfile, sizeof (locfile), "%s.gz", filename);
else
strcpy (locfile, filename);
locfd = QFS_Open (locfile, "z9w+");
if (strcmp (QFS_FileExtension (filename), ".gz") != 0)
filename = va ("%s.gz", filename);
locfd = QFS_Open (filename, "z9w+");
} else
locfd = QFS_Open (filename, "w+");
if (locfd == 0) {

View file

@ -1096,7 +1096,7 @@ Sbar_LogFrags (void)
if (t)
Qwrite (file, t, strlen (t));
Qprintf (file, "%s\n%s %s\n", cls.servername, cl.worldmodel->name,
Qprintf (file, "%s\n%s %s\n", cls.servername->str, cl.worldmodel->name,
cl.levelname);
// scores

View file

@ -655,9 +655,7 @@ SV_Record_f (void)
sv_demoSuffix->string);
// open the demo file
name->size += 4;
dstring_adjust (name);
QFS_DefaultExtension (name->str, ".mvd");
QFS_DefaultExtension (name, ".mvd");
SV_Record (name->str);

View file

@ -249,23 +249,18 @@ LoadBSP (void)
static char *
output_file (const char *ext)
{
char *name;
dstring_t *name;
name = dstring_newstr ();
if (options.output_file) {
if (strcmp (options.output_file, "-") == 0)
return options.output_file;
name = malloc (strlen (options.output_file) + strlen (ext) + 1);
strcpy (name, options.output_file);
QFS_DefaultExtension (name, ext);
dstring_copystr (name, options.output_file);
if (strcmp (options.output_file, "-") != 0)
QFS_DefaultExtension (name, ext);
} else {
name = malloc (strlen (options.bspfile) + strlen (ext) + 1);
QFS_StripExtension (options.bspfile, name);
if (strcmp (QFS_FileExtension (options.bspfile), ".gz") == 0) {
QFS_StripExtension (name, name);
}
strcat (name, ext);
dstring_copystr (name, options.bspfile);
QFS_StripExtension (name->str, name->str);
}
return name;
return dstring_freeze (name);
}
void

View file

@ -48,7 +48,7 @@ typedef struct {
} options_t;
extern options_t options;
extern char *bspfile;
extern struct dstring_s *bspfile;
extern const char *this_program;
int DecodeArgs (int argc, char **argv);

View file

@ -41,6 +41,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include <errno.h>
#include <stdlib.h>
#include "QF/dstring.h"
#include "QF/qtypes.h"
#include "compat.h"
@ -184,7 +185,7 @@ DecodeArgs (int argc, char **argv)
usage (1);
break;
case 'f':
bspfile = strdup (optarg);
bspfile = dstring_strdup (optarg);
break;
case 'P':
options.properties_filename = strdup (optarg);
@ -195,7 +196,7 @@ DecodeArgs (int argc, char **argv)
}
options.extrascale = 1.0 / (1 << (options.extrabit * 2));
if ((!bspfile) && argv[optind] && *(argv[optind]))
bspfile = strdup (argv[optind++]);
bspfile = dstring_strdup (argv[optind++]);
return optind;
}

View file

@ -65,7 +65,7 @@ static __attribute__ ((used)) const char rcsid[] =
options_t options;
bsp_t *bsp;
char *bspfile;
dstring_t *bspfile;
dstring_t *litfile;
float scalecos = 0.5;
@ -176,7 +176,6 @@ int
main (int argc, char **argv)
{
double start, stop;
char *e;
QFile *f;
start = Sys_DoubleTime ();
@ -192,20 +191,17 @@ main (int argc, char **argv)
InitThreads ();
QFS_StripExtension (bspfile, bspfile);
QFS_DefaultExtension (bspfile, ".bsp");
QFS_SetExtension (bspfile, ".bsp");
litfile = dstring_new ();
dstring_copystr (litfile, bspfile);
e = strrchr (litfile->str, '.');
dstring_replace (litfile, e - litfile->str, -1, ".lit", 5);
litfile = dstring_strdup (bspfile->str);
QFS_SetExtension (litfile, ".lit");
if (options.properties_filename)
LoadProperties (options.properties_filename);
f = Qopen (bspfile, "rbz");
f = Qopen (bspfile->str, "rbz");
if (!f)
Sys_Error ("could not open %s for reading", bspfile);
Sys_Error ("could not open %s for reading", bspfile->str);
bsp = LoadBSPFile (f, Qfilesize (f));
Qclose (f);
LoadEntities ();
@ -216,9 +212,9 @@ main (int argc, char **argv)
WriteEntitiesToString ();
f = Qopen (bspfile, "wb");
f = Qopen (bspfile->str, "wb");
if (!f)
Sys_Error ("could not open %s for writing", bspfile);
Sys_Error ("could not open %s for writing", bspfile->str);
WriteBSPFile (bsp, f);
Qclose (f);

View file

@ -1011,10 +1011,10 @@ ParseScript (void)
int
main (int argc, char **argv)
{
int i, bytes;
char path[1024];
QFile *file;
char *buf;
int i, bytes;
dstring_t *path;
QFile *file;
char *buf;
if (argc != 2)
Sys_Error ("usage: modelgen file.qc");
@ -1022,19 +1022,19 @@ main (int argc, char **argv)
i = 1;
// load the script
strcpy (path, argv[i]);
path = dstring_strdup (argv[i]);
QFS_DefaultExtension (path, ".qc");
SetQdirFromPath (path);
SetQdirFromPath (path->str);
file = Qopen (path, "rt");
file = Qopen (path->str, "rt");
if (!file)
Sys_Error ("couldn't open %s. %s", path, strerror(errno));
Sys_Error ("couldn't open %s. %s", path->str, strerror(errno));
bytes = Qfilesize (file);
buf = malloc (bytes + 1);
bytes = Qread (file, buf, bytes);
buf[bytes] = 0;
Qclose (file);
Script_Start (&scr, path, buf);
Script_Start (&scr, path->str, buf);
// parse it

View file

@ -36,7 +36,7 @@ typedef struct {
int threads;
qboolean minimal;
int level;
char *bspfile;
struct dstring_s *bspfile;
} options_t;
extern options_t options;

View file

@ -41,6 +41,8 @@ static __attribute__ ((used)) const char rcsid[] =
#include <stdio.h>
#include <getopt.h>
#include "QF/dstring.h"
#include "options.h"
const char *this_program;
@ -122,14 +124,14 @@ DecodeArgs (int argc, char **argv)
options.level = atoi (optarg);
break;
case 'f': // set filename
options.bspfile = strdup (optarg);
options.bspfile = dstring_strdup (optarg);
break;
default:
usage (1);
}
}
if ((!options.bspfile) && argv[optind] && *(argv[optind]))
options.bspfile = strdup (argv[optind++]);
options.bspfile = dstring_strdup (argv[optind++]);
return optind;
}

View file

@ -824,21 +824,18 @@ main (int argc, char **argv)
Sys_Error ("%s: no bsp file specified.", this_program);
}
QFS_StripExtension (options.bspfile, options.bspfile);
QFS_DefaultExtension (options.bspfile, ".bsp");
QFS_SetExtension (options.bspfile, ".bsp");
f = Qopen (options.bspfile, "rb");
f = Qopen (options.bspfile->str, "rb");
if (!f)
Sys_Error ("couldn't open %s for reading.", options.bspfile);
Sys_Error ("couldn't open %s for reading.", options.bspfile->str);
bsp = LoadBSPFile (f, Qfilesize (f));
Qclose (f);
visdata = dstring_new ();
portalfile->size = strlen (options.bspfile) + 1;
dstring_adjust (portalfile);
QFS_StripExtension (options.bspfile, portalfile->str);
dstring_appendstr (portalfile, ".prt");
dstring_copystr (portalfile, options.bspfile->str);
QFS_SetExtension (portalfile, ".prt");
LoadPortals (portalfile->str);
uncompressed = calloc (bitbytes_l, portalclusters);
@ -856,9 +853,9 @@ main (int argc, char **argv)
CalcAmbientSounds ();
f = Qopen (options.bspfile, "wb");
f = Qopen (options.bspfile->str, "wb");
if (!f)
Sys_Error ("couldn't open %s for writing.", options.bspfile);
Sys_Error ("couldn't open %s for writing.", options.bspfile->str);
WriteBSPFile (bsp, f);
Qclose (f);