mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
Char buffer audit.
Get rid of most static char buffers. The few remaining are either in file structs or messy code that needs further analysis.
This commit is contained in:
parent
1b7be81f11
commit
997df6c310
8 changed files with 84 additions and 103 deletions
|
@ -1,3 +1,5 @@
|
|||
#include "QF/dstring.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "Dict.h"
|
||||
|
||||
|
@ -203,21 +205,18 @@ JDC
|
|||
{
|
||||
int i;
|
||||
int max;
|
||||
char tempstr[4096];
|
||||
dstring_t *tempstr;
|
||||
char *s;
|
||||
char *newstr;
|
||||
|
||||
max =[list count];
|
||||
tempstr[0] = 0;
|
||||
tempstr = dstring_newstr ();
|
||||
for (i = 0; i < max; i++) {
|
||||
s =[list elementAt:i];
|
||||
strcat (tempstr, s);
|
||||
strcat (tempstr, " ");
|
||||
dstring_appendstr (tempstr, s);
|
||||
dstring_appendstr (tempstr, " ");
|
||||
}
|
||||
newstr = malloc (strlen (tempstr) + 1);
|
||||
strcpy (newstr, tempstr);
|
||||
|
||||
return newstr;
|
||||
return dstring_freeze (tempstr);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -270,17 +269,12 @@ JDC
|
|||
-addString:(const char *) string toValue:(const char *) key
|
||||
{
|
||||
char *newstr;
|
||||
char spacing[] = "\t";
|
||||
dict_t *d;
|
||||
|
||||
d =[self findKeyword:key];
|
||||
if (d == NULL)
|
||||
return NULL;
|
||||
newstr =
|
||||
malloc (strlen (string) + strlen (d->value) + strlen (spacing) + 1);
|
||||
strcpy (newstr, d->value);
|
||||
strcat (newstr, spacing);
|
||||
strcat (newstr, string);
|
||||
newstr = nva ("%s\t%s", d->value, string);
|
||||
free (d->value);
|
||||
d->value = newstr;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/script.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "Entity.h"
|
||||
#include "EntityClass.h"
|
||||
|
@ -55,8 +55,8 @@ vec3_t bad_maxs = { 8, 8, 8 };
|
|||
{
|
||||
id new;
|
||||
esize_t esize;
|
||||
char value[80];
|
||||
vec3_t min, max;
|
||||
int org[3];
|
||||
float *v;
|
||||
|
||||
self = [super init];
|
||||
|
@ -78,9 +78,9 @@ vec3_t bad_maxs = { 8, 8, 8 };
|
|||
v =[new mins];
|
||||
[[map_i selectedBrush] getMins: min maxs:max];
|
||||
VectorSubtract (min, v, min);
|
||||
VectorCopy (min, org); // convert to integer
|
||||
|
||||
sprintf (value, "%i %i %i", (int) min[0], (int) min[1], (int) min[2]);
|
||||
[self setKey: "origin" toValue:value];
|
||||
[self setKey:"origin" toValue:va ("%i %i %i", org[0], org[1], org[2])];
|
||||
|
||||
[self createFixedBrush:min];
|
||||
} else
|
||||
|
@ -246,7 +246,6 @@ If the entity does not have a "targetname" key, a unique one is generated
|
|||
int i, count;
|
||||
id ent;
|
||||
int tval, maxt;
|
||||
char name[20];
|
||||
|
||||
t =[self valueForQKey:"targetname"];
|
||||
if (t && t[0])
|
||||
|
@ -265,12 +264,9 @@ If the entity does not have a "targetname" key, a unique one is generated
|
|||
maxt = tval;
|
||||
}
|
||||
|
||||
sprintf (name, "t%i", maxt + 1);
|
||||
[self setKey: "targetname" toValue:va ("t%i", maxt + 1)];
|
||||
|
||||
[self setKey: "targetname" toValue:name];
|
||||
|
||||
return[self valueForQKey:"targetname"];
|
||||
// so it's not on the stack
|
||||
return [self valueForQKey:"targetname"];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -372,27 +368,23 @@ int nument;
|
|||
f region:(BOOL) reg;
|
||||
{
|
||||
epair_t *e;
|
||||
int i;
|
||||
int i, ang;
|
||||
id new;
|
||||
char value[80];
|
||||
vec3_t mins, maxs, org;
|
||||
vec3_t mins, maxs;
|
||||
int org[3];
|
||||
const vec_t *v;
|
||||
BOOL temporg;
|
||||
char oldang[80];
|
||||
char *oldang = 0;
|
||||
|
||||
temporg = NO;
|
||||
if (reg) {
|
||||
if (!strcmp ([self valueForQKey:"classname"], "info_player_start")) {
|
||||
// move the playerstart
|
||||
// temporarily to the camera
|
||||
// position
|
||||
temporg = YES;
|
||||
strcpy (oldang,[self valueForQKey:"angle"]);
|
||||
sprintf (value, "%i", (int) ([cameraview_i yawAngle] * 180 / M_PI));
|
||||
[self setKey: "angle" toValue:value];
|
||||
} else if (self !=[map_i objectAtIndex:0]
|
||||
&&[[self objectAtIndex:0] regioned])
|
||||
// move the playerstart temporarily to the camera position
|
||||
oldang = strdup ([self valueForQKey:"angle"]);
|
||||
ang = (int) ([cameraview_i yawAngle] * 180 / M_PI);
|
||||
[self setKey: "angle" toValue: va ("%i", ang)];
|
||||
} else if (self != [map_i objectAtIndex:0]
|
||||
&& [[self objectAtIndex:0] regioned]) {
|
||||
return self; // skip the entire entity definition
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (f, "{\n");
|
||||
|
@ -400,7 +392,7 @@ f region:(BOOL) reg;
|
|||
// set an origin epair
|
||||
if (!modifiable) {
|
||||
[[self objectAtIndex: 0] getMins: mins maxs:maxs];
|
||||
if (temporg) {
|
||||
if (oldang) {
|
||||
[cameraview_i getOrigin:mins];
|
||||
mins[0] -= 16;
|
||||
mins[1] -= 16;
|
||||
|
@ -414,8 +406,8 @@ f region:(BOOL) reg;
|
|||
v = vec3_origin;
|
||||
|
||||
VectorSubtract (mins, v, org);
|
||||
sprintf (value, "%i %i %i", (int) org[0], (int) org[1], (int) org[2]);
|
||||
[self setKey: "origin" toValue:value];
|
||||
[self setKey: "origin"
|
||||
toValue: va ("%i %i %i", org[0], org[1], org[2])];
|
||||
}
|
||||
|
||||
for (e = epairs; e; e = e->next)
|
||||
|
@ -429,8 +421,10 @@ f region:(BOOL) reg;
|
|||
|
||||
fprintf (f, "}\n");
|
||||
|
||||
if (temporg)
|
||||
if (oldang) {
|
||||
[self setKey: "angle" toValue:oldang];
|
||||
free (oldang);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -182,10 +182,10 @@ scanFile
|
|||
char *data;
|
||||
id cl;
|
||||
int i;
|
||||
char path[1024];
|
||||
const char *path;
|
||||
QFile *file;
|
||||
|
||||
sprintf (path, "%s/%s", source_path, filename);
|
||||
path = va ("%s/%s", source_path, filename);
|
||||
|
||||
file = Qopen (path, "rt");
|
||||
if (!file)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "Preferences.h"
|
||||
#include "Map.h"
|
||||
|
@ -26,10 +27,7 @@ WriteStringDefault (id prefs, const char *name, const char *value)
|
|||
void
|
||||
WriteNumericDefault (id prefs, const char *name, float value)
|
||||
{
|
||||
char str[128];
|
||||
|
||||
sprintf (str, "%f", value);
|
||||
WriteStringDefault (prefs, name, str);
|
||||
WriteStringDefault (prefs, name, va ("%f", value));
|
||||
}
|
||||
|
||||
-init
|
||||
|
@ -155,7 +153,7 @@ _atof (const char *c)
|
|||
// XXX ExtractFilePath (bspSound, path);
|
||||
// XXX ExtractFileBase (bspSound, file);
|
||||
|
||||
rtn =[panel runModalForDirectory: [NSString stringWithCString:path]
|
||||
rtn = [panel runModalForDirectory: [NSString stringWithCString:path]
|
||||
file: [NSString stringWithCString:file]
|
||||
types: [NSArray arrayWithObjects: types count:1]];
|
||||
|
||||
|
@ -348,8 +346,8 @@ Grab all the current UI state
|
|||
{
|
||||
Sys_Printf ("defaults updated\n");
|
||||
|
||||
[self setProjectPath:(char *)[startproject_i stringValue]];
|
||||
[self setBspSoundPath:(char *)[bspSoundField_i stringValue]];
|
||||
[self setProjectPath:[[startproject_i stringValue] cString]];
|
||||
[self setBspSoundPath:[[bspSoundField_i stringValue] cString]];
|
||||
[self setShowBSP:[showBSP_i intValue]];
|
||||
[self setBrushOffset:[brushOffset_i intValue]];
|
||||
[self setStartWad:[startwad_i selectedRow]];
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "Project.h"
|
||||
#include "Map.h"
|
||||
|
@ -237,13 +238,14 @@ id project_i;
|
|||
{
|
||||
id matrix;
|
||||
int row;
|
||||
char fname[1024];
|
||||
const char *fname;
|
||||
id panel;
|
||||
NSModalSession session;
|
||||
|
||||
matrix =[sender matrixInColumn:0];
|
||||
row =[matrix selectedRow];
|
||||
sprintf (fname, "%s/%s.map", path_mapdirectory, (char *)[mapList elementAt:row]);
|
||||
fname = va ("%s/%s.map", path_mapdirectory,
|
||||
(const char *) [mapList elementAt:row]); //XXX Storage
|
||||
|
||||
panel = NSGetAlertPanel (@"Loading...",
|
||||
@"Loading map. Please wait.", NULL, NULL, NULL);
|
||||
|
@ -263,14 +265,14 @@ id project_i;
|
|||
-setTextureWad:(const char *) wf
|
||||
{
|
||||
int i, c;
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
Sys_Printf ("loading %s\n", wf);
|
||||
|
||||
// set the row in the settings inspector wad browser
|
||||
c =[wadList count];
|
||||
for (i = 0; i < c; i++) {
|
||||
name = (char *)[wadList elementAt:i];
|
||||
name = (const char *)[wadList elementAt:i]; // XXX Storage
|
||||
if (!strcmp (name, wf)) {
|
||||
[[pis_wads_i matrixInColumn: 0] selectCellAtRow: i column:0];
|
||||
break;
|
||||
|
@ -299,7 +301,7 @@ id project_i;
|
|||
matrix =[sender matrixInColumn:0];
|
||||
row =[matrix selectedRow];
|
||||
|
||||
name = (char *)[wadList elementAt:row];
|
||||
name = (char *)[wadList elementAt:row]; // XXX Storage
|
||||
[self setTextureWad:name];
|
||||
|
||||
return self;
|
||||
|
@ -363,7 +365,7 @@ Sys_Printf ("openProjectFile: %s\n", path);
|
|||
//
|
||||
-openProject
|
||||
{
|
||||
char path[128];
|
||||
const char *path;
|
||||
id openpanel;
|
||||
int rtn;
|
||||
NSString *projtypes[] = { @"qpr" };
|
||||
|
@ -378,7 +380,7 @@ Sys_Printf ("openProjectFile: %s\n", path);
|
|||
filenames =[openpanel filenames];
|
||||
dir =[[openpanel directory] cString];
|
||||
dir = "";
|
||||
sprintf (path, "%s/%s", dir,[[filenames objectAtIndex:0] cString]);
|
||||
path = va ("%s/%s", dir,[[filenames objectAtIndex:0] cString]);
|
||||
strcpy (path_projectinfo, path);
|
||||
[self openProjectFile:path];
|
||||
return self;
|
||||
|
@ -395,11 +397,11 @@ Sys_Printf ("openProjectFile: %s\n", path);
|
|||
{
|
||||
int i;
|
||||
int max;
|
||||
char *s;
|
||||
const char *s;
|
||||
|
||||
max =[obj count];
|
||||
for (i = 0; i < max; i++) {
|
||||
s = (char *)[obj elementAt:i];
|
||||
s = (const char *)[obj elementAt:i]; // XXX Storage?
|
||||
if (!strcmp (s, str))
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -832,7 +832,7 @@ open
|
|||
NSOKButton)
|
||||
return self;
|
||||
|
||||
[self doOpen:(char *)[[openpanel filename] cString]];
|
||||
[self doOpen: [[openpanel filename] cString]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "QF/quakeio.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/wadfile.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "TexturePalette.h"
|
||||
#include "Preferences.h"
|
||||
|
@ -177,27 +178,25 @@ void
|
|||
TEX_InitFromWad (const char *path)
|
||||
{
|
||||
int i;
|
||||
char newpath[1024];
|
||||
const char *newpath;
|
||||
float start, stop;
|
||||
wad_t *wad;
|
||||
lumpinfo_t *lumpinfo;
|
||||
|
||||
start = Sys_DoubleTime ();
|
||||
|
||||
strcpy (newpath,[preferences_i getProjectPath]);
|
||||
if (newpath[0])
|
||||
strcat (newpath, "/");
|
||||
strcat (newpath, path);
|
||||
newpath = [preferences_i getProjectPath];
|
||||
newpath = va ("%s%s%s", newpath, newpath[0] ? "/" : "", path); //XXX safe?
|
||||
|
||||
// free any textures
|
||||
// free any textures
|
||||
for (i = 0; i < tex_count; i++)
|
||||
[qtextures[i].rep release];
|
||||
tex_count = 0;
|
||||
|
||||
// try and use the cached wadfile
|
||||
// try to use the cached wadfile
|
||||
|
||||
Sys_Printf ("TEX_InitFromWad %s\n", newpath);
|
||||
wad = wad_open (newpath);
|
||||
wad = wad_open (newpath); //FIXME error checking
|
||||
|
||||
lumpinfo = wad->lumps;
|
||||
|
||||
|
@ -437,7 +436,6 @@ TEX_ForName (const char *name)
|
|||
{
|
||||
texpal_t *t;
|
||||
NSRect r;
|
||||
char string[16];
|
||||
|
||||
// wipe the fields
|
||||
[self clearTexinfo:self];
|
||||
|
@ -453,9 +451,10 @@ TEX_ForName (const char *name)
|
|||
r.origin.y -= TEX_INDENT;
|
||||
[textureView_i scrollRectToVisible:r];
|
||||
[textureView_i display];
|
||||
sprintf (string, "%d x %d", (int) t->r.size.width,
|
||||
(int) t->r.size.height - TEX_SPACING);
|
||||
[sizeField_i setStringValue: [NSString stringWithCString:string]];
|
||||
[sizeField_i setStringValue:
|
||||
[NSString stringWithFormat:@"%d x %d",
|
||||
(int) t->r.size.width,
|
||||
(int) t->r.size.height - TEX_SPACING]];
|
||||
}
|
||||
|
||||
[self texturedefChanged:self];
|
||||
|
@ -537,17 +536,18 @@ TEX_ForName (const char *name)
|
|||
int i;
|
||||
int max;
|
||||
int len;
|
||||
char name[32], *n;
|
||||
NSMutableString *strname;
|
||||
const char *name;
|
||||
texpal_t *t;
|
||||
|
||||
if (selectedTexture == -1)
|
||||
return self;
|
||||
|
||||
max =[textureList_i count];
|
||||
strcpy (name, (const char *)[sender stringValue]);
|
||||
for (n = name; *n; n++)
|
||||
*n = toupper (*n);
|
||||
[sender setStringValue: [NSString stringWithCString:name]];
|
||||
max = [textureList_i count];
|
||||
strname = [[sender stringValue] mutableCopy];
|
||||
[strname uppercaseString];
|
||||
[sender setStringValue: strname];
|
||||
name = [strname cString];
|
||||
len = strlen (name);
|
||||
|
||||
for (i = selectedTexture - 1; i >= 0; i--) {
|
||||
|
@ -724,18 +724,16 @@ field by:(int) amount
|
|||
{
|
||||
int i;
|
||||
int max;
|
||||
char name[32];
|
||||
texpal_t *t;
|
||||
|
||||
if (selectedTexture == -1)
|
||||
return -1;
|
||||
|
||||
max =[textureList_i count];
|
||||
strcpy (name, texture);
|
||||
|
||||
for (i = 0; i < max; i++) {
|
||||
t =[textureList_i elementAt:i];
|
||||
if (!strcmp (t->name, name))
|
||||
if (!strcmp (t->name, texture))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "Things.h"
|
||||
#include "QuakeEd.h"
|
||||
|
@ -93,7 +94,7 @@ id things_i;
|
|||
EntityClass *ent;
|
||||
const char *path;
|
||||
|
||||
path = (char *)[prog_path_i stringValue];
|
||||
path = [[prog_path_i stringValue] cString];
|
||||
if (!path || !path[0]) {
|
||||
path =[project_i getProgDirectory];
|
||||
[prog_path_i setStringValue: [NSString stringWithCString:path]];
|
||||
|
@ -206,10 +207,10 @@ id things_i;
|
|||
|
||||
-addPair:sender
|
||||
{
|
||||
char *key, *value;
|
||||
const char *key, *value;
|
||||
|
||||
key = (char *)[keyInput_i stringValue];
|
||||
value = (char *)[valueInput_i stringValue];
|
||||
key = [[keyInput_i stringValue] cString];
|
||||
value = [[valueInput_i stringValue] cString];
|
||||
|
||||
[[map_i currentEntity] setKey: key toValue:value];
|
||||
|
||||
|
@ -226,7 +227,7 @@ id things_i;
|
|||
{
|
||||
[quakeed_i makeFirstResponder:quakeed_i];
|
||||
|
||||
[[map_i currentEntity] removeKeyPair:(char *)[keyInput_i stringValue]];
|
||||
[[map_i currentEntity] removeKeyPair:[[keyInput_i stringValue] cString]];
|
||||
|
||||
[keypairview_i calcViewSize];
|
||||
[keypairview_i display];
|
||||
|
@ -244,19 +245,16 @@ id things_i;
|
|||
//
|
||||
-setAngle:sender
|
||||
{
|
||||
const char *title;
|
||||
char value[10];
|
||||
NSString *value;
|
||||
|
||||
title =[[[sender selectedCell] title] cString];
|
||||
if (!strcmp (title, "Up"))
|
||||
strcpy (value, "-1");
|
||||
else if (!strcmp (title, "Dn"))
|
||||
strcpy (value, "-2");
|
||||
else
|
||||
strcpy (value, title);
|
||||
value = [[sender selectedCell] title];
|
||||
if (![value compare:@"Up"])
|
||||
value = @"-1";
|
||||
else if (![value compare:@"Dn"])
|
||||
value = @"-2";
|
||||
|
||||
[keyInput_i setStringValue:@"angle"];
|
||||
[valueInput_i setStringValue: [NSString stringWithCString:value]];
|
||||
[valueInput_i setStringValue: value];
|
||||
[self addPair:NULL];
|
||||
|
||||
[self clearInputs];
|
||||
|
@ -271,7 +269,6 @@ id things_i;
|
|||
int flags;
|
||||
int r, c, i;
|
||||
id cell;
|
||||
char str[20];
|
||||
|
||||
[self clearInputs];
|
||||
flags = 0;
|
||||
|
@ -285,10 +282,8 @@ id things_i;
|
|||
|
||||
if (!flags)
|
||||
[[map_i currentEntity] removeKeyPair:"spawnflags"];
|
||||
else {
|
||||
sprintf (str, "%i", flags);
|
||||
[[map_i currentEntity] setKey: "spawnflags" toValue:str];
|
||||
}
|
||||
else
|
||||
[[map_i currentEntity] setKey: "spawnflags" toValue:va ("%i", flags)];
|
||||
|
||||
[keypairview_i calcViewSize];
|
||||
[keypairview_i display];
|
||||
|
|
Loading…
Reference in a new issue