Make STRINGPTR a 'char *'; GetStringContents() removed; minor header path changes

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3452 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-12-20 02:02:24 +00:00
parent 5b15514f18
commit 044e59dd66
13 changed files with 57 additions and 55 deletions
+7 -4
View File
@@ -19,6 +19,7 @@
#ifndef _GFXLIB_H #ifndef _GFXLIB_H
#define _GFXLIB_H #define _GFXLIB_H
#include "port.h"
#include "libs/compiler.h" #include "libs/compiler.h"
typedef struct Color Color; typedef struct Color Color;
@@ -220,11 +221,13 @@ typedef struct text
COUNT CharCount; COUNT CharCount;
} TEXT; } TEXT;
#include "strlib.h" #include "libs/strlib.h"
typedef STRING_TABLE COLORMAP_REF; typedef STRING_TABLE COLORMAP_REF;
typedef STRING COLORMAP; typedef STRING COLORMAP;
typedef STRINGPTR COLORMAPPTR; // COLORMAPPTR is really a pointer to colortable entry structure
// which is documented in doc/devel/strtab, .ct files section
typedef void *COLORMAPPTR;
#include "graphics/prim.h" #include "graphics/prim.h"
@@ -374,8 +377,8 @@ extern void FlushColorXForms (void);
#define SetAbsColorMapIndex SetAbsStringTableIndex #define SetAbsColorMapIndex SetAbsStringTableIndex
#define SetRelColorMapIndex SetRelStringTableIndex #define SetRelColorMapIndex SetRelStringTableIndex
#define GetColorMapLength GetStringLengthBin #define GetColorMapLength GetStringLengthBin
#define GetColorMapAddress GetStringAddress
#define GetColorMapContents GetStringContents extern COLORMAPPTR GetColorMapAddress (COLORMAP);
void SetSystemRect (const RECT *pRect); void SetSystemRect (const RECT *pRect);
void ClearSystemRect (void); void ClearSystemRect (void);
+11 -1
View File
@@ -20,6 +20,8 @@
#include "libs/threadlib.h" #include "libs/threadlib.h"
#include "libs/timelib.h" #include "libs/timelib.h"
#include "libs/inplib.h" #include "libs/inplib.h"
#include "libs/strlib.h"
// for GetStringAddress()
#include "libs/log.h" #include "libs/log.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@@ -543,7 +545,7 @@ XFormPLUT (COLORMAPPTR ColorMapPtr, SIZE TimeInterval)
DWORD Now; DWORD Now;
Now = GetTimeCounter (); Now = GetTimeCounter ();
index = *ColorMapPtr; index = *(UBYTE*)ColorMapPtr;
LockMutex (XFormControl.Lock); LockMutex (XFormControl.Lock);
// Find an available slot, or reuse if required // Find an available slot, or reuse if required
@@ -619,3 +621,11 @@ FlushColorXForms (void)
FlushFadeXForms (); FlushFadeXForms ();
FlushPLUTXForms (); FlushPLUTXForms ();
} }
// The type conversions are implicit and will generate errors
// or warnings if types change imcompatibly
COLORMAPPTR
GetColorMapAddress (COLORMAP colormap)
{
return GetStringAddress (colormap);
}
+2 -4
View File
@@ -78,13 +78,12 @@ void *GetResourceData (uio_Stream *fp, DWORD length);
#define AllocResourceData HMalloc #define AllocResourceData HMalloc
BOOLEAN FreeResourceData (void *); BOOLEAN FreeResourceData (void *);
#include "strlib.h" #include "libs/strlib.h"
#include "gfxlib.h" #include "libs/gfxlib.h"
// For Color // For Color
typedef STRING_TABLE DIRENTRY_REF; typedef STRING_TABLE DIRENTRY_REF;
typedef STRING DIRENTRY; typedef STRING DIRENTRY;
typedef STRINGPTR DIRENTRYPTR;
extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle,
const char *path, const char *pattern, match_MatchType matchType); const char *path, const char *pattern, match_MatchType matchType);
@@ -98,7 +97,6 @@ extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle,
#define SetRelDirEntryTableIndex SetRelStringTableIndex #define SetRelDirEntryTableIndex SetRelStringTableIndex
#define GetDirEntryLength GetStringLengthBin #define GetDirEntryLength GetStringLengthBin
#define GetDirEntryAddress GetStringAddress #define GetDirEntryAddress GetStringAddress
#define GetDirEntryContents GetStringContents
/* Key-Value resources */ /* Key-Value resources */
+5 -3
View File
@@ -19,11 +19,13 @@
#ifndef _SNDLIB_H #ifndef _SNDLIB_H
#define _SNDLIB_H #define _SNDLIB_H
#include "port.h"
#include "libs/strlib.h" #include "libs/strlib.h"
typedef STRING_TABLE SOUND_REF; typedef STRING_TABLE SOUND_REF;
typedef STRING SOUND; typedef STRING SOUND;
typedef STRINGPTR SOUNDPTR; // SOUNDPTR is really a TFB_SoundSample**
typedef void *SOUNDPTR;
typedef struct soundposition typedef struct soundposition
{ {
@@ -39,8 +41,8 @@ typedef struct soundposition
#define GetSoundIndex GetStringTableIndex #define GetSoundIndex GetStringTableIndex
#define SetAbsSoundIndex SetAbsStringTableIndex #define SetAbsSoundIndex SetAbsStringTableIndex
#define SetRelSoundIndex SetRelStringTableIndex #define SetRelSoundIndex SetRelStringTableIndex
#define GetSoundAddress GetStringAddress
#define GetSoundContents GetStringContents extern SOUNDPTR GetSoundAddress (SOUND sound);
typedef struct tfb_soundsample TFB_SoundSample; typedef struct tfb_soundsample TFB_SoundSample;
typedef TFB_SoundSample **MUSIC_REF; typedef TFB_SoundSample **MUSIC_REF;
+12 -1
View File
@@ -19,7 +19,10 @@
#include "sndintrn.h" #include "sndintrn.h"
#include "libs/reslib.h" #include "libs/reslib.h"
#include "libs/log.h" #include "libs/log.h"
#include "libs/strlib.h"
// for GetStringAddress()
#include "libs/strings/strintrn.h" #include "libs/strings/strintrn.h"
// for AllocStringTable(), FreeStringTable()
#include "libs/memlib.h" #include "libs/memlib.h"
#include <math.h> #include <math.h>
@@ -31,7 +34,7 @@ void
PlayChannel (COUNT channel, SOUND snd, SoundPosition pos, PlayChannel (COUNT channel, SOUND snd, SoundPosition pos,
void *positional_object, unsigned char priority) void *positional_object, unsigned char priority)
{ {
void *snd_ptr = GetSoundAddress (snd); SOUNDPTR snd_ptr = GetSoundAddress (snd);
TFB_SoundSample *sample; TFB_SoundSample *sample;
StopSource (channel); StopSource (channel);
@@ -293,3 +296,11 @@ DestroySound(SOUND_REF target)
{ {
return _ReleaseSoundBankData (target); return _ReleaseSoundBankData (target);
} }
// The type conversions are implicit and will generate errors
// or warnings if types change imcompatibly
SOUNDPTR
GetSoundAddress (SOUND sound)
{
return GetStringAddress (sound);
}
+1 -1
View File
@@ -470,7 +470,7 @@ _GetBinaryTableData (uio_Stream *fp, DWORD length)
stringptr = (BYTE *)(fileData + 2 + size + fileData[1]); stringptr = (BYTE *)(fileData + 2 + size + fileData[1]);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
set_strtab_entry (lpST, i, stringptr, fileData[2+i]); set_strtab_entry (lpST, i, (char *)stringptr, fileData[2+i]);
stringptr += fileData[2+i]; stringptr += fileData[2+i];
} }
} }
-22
View File
@@ -285,25 +285,3 @@ GetStringAddress (STRING String)
} }
return String->data; return String->data;
} }
BOOLEAN
GetStringContents (STRING String, STRINGPTR StringBuf, BOOLEAN
AppendSpace)
{
STRINGPTR StringAddr;
COUNT StringLength;
if ((StringAddr = GetStringAddress (String)) != 0 &&
(StringLength = GetStringLengthBin (String)) != 0)
{
memcpy (StringBuf, StringAddr, StringLength);
if (AppendSpace)
StringBuf[StringLength++] = ' ';
StringBuf[StringLength] = '\0';
return (TRUE);
}
*StringBuf = '\0';
return (FALSE);
}
+2 -4
View File
@@ -31,10 +31,10 @@ typedef struct string_table STRING_TABLE_DESC;
typedef STRING_TABLE_DESC *STRING_TABLE; typedef STRING_TABLE_DESC *STRING_TABLE;
typedef STRING_TABLE_ENTRY_DESC *STRING; typedef STRING_TABLE_ENTRY_DESC *STRING;
typedef BYTE *STRINGPTR; typedef char *STRINGPTR;
/* This has to go here because reslib requires the above typedefs. */ /* This has to go here because reslib requires the above typedefs. */
#include "reslib.h" #include "libs/reslib.h"
extern BOOLEAN InstallStringTableResType (void); extern BOOLEAN InstallStringTableResType (void);
extern STRING_TABLE LoadStringTableInstance (RESOURCE res); extern STRING_TABLE LoadStringTableInstance (RESOURCE res);
@@ -55,8 +55,6 @@ extern COUNT GetStringLengthBin (STRING String);
extern STRINGPTR GetStringAddress (STRING String); extern STRINGPTR GetStringAddress (STRING String);
extern STRINGPTR GetStringSoundClip (STRING String); extern STRINGPTR GetStringSoundClip (STRING String);
extern STRINGPTR GetStringTimeStamp (STRING String); extern STRINGPTR GetStringTimeStamp (STRING String);
extern BOOLEAN GetStringContents (STRING String, STRINGPTR StringBuf,
BOOLEAN AppendSpace);
#define UNICHAR_DEGREE_SIGN 0x00b0 #define UNICHAR_DEGREE_SIGN 0x00b0
#define STR_DEGREE_SIGN "\xC2\xB0" #define STR_DEGREE_SIGN "\xC2\xB0"
+4 -3
View File
@@ -299,10 +299,11 @@ InitCyborg (STARSHIP *StarShipPtr)
Index >>= 1; Index >>= 1;
#ifdef PRINT_MI #ifdef PRINT_MI
{ {
char buf[40]; char *shipName;
GetStringContents (StarShipPtr->RaceDescPtr->ship_data.race_strings, buf, FALSE); shipName = GetStringAddress (
log_add (log_Debug, "MI(%s) -- <%u:%u> = %u", buf, StarShipPtr->RaceDescPtr->ship_data.race_strings);
log_add (log_Debug, "MI(%s) -- <%u:%u> = %u", shipName,
StarShipPtr->RaceDescPtr->characteristics.max_thrust * StarShipPtr->RaceDescPtr->characteristics.max_thrust *
StarShipPtr->RaceDescPtr->characteristics.thrust_increment, StarShipPtr->RaceDescPtr->characteristics.thrust_increment,
Divisor, Index); Divisor, Index);
+2 -2
View File
@@ -555,8 +555,8 @@ UninitEncounter (void)
BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F)); BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F));
SetContextFont (TinyFont); SetContextFont (TinyFont);
GetStringContents (FragPtr->race_strings, utf8StringCopy (buf, sizeof buf,
(STRINGPTR)buf, FALSE); GetStringAddress (FragPtr->race_strings));
// XXX: this will not work with UTF-8 strings // XXX: this will not work with UTF-8 strings
strupr (buf); strupr (buf);
+7 -9
View File
@@ -36,7 +36,7 @@ LoadMasterShipList (void (* YieldProcessing)(void))
while (num_entries--) while (num_entries--)
{ {
HMASTERSHIP hBuiltShip; HMASTERSHIP hBuiltShip;
char built_buf[30]; char *builtName;
HMASTERSHIP hStarShip, hNextShip; HMASTERSHIP hStarShip, hNextShip;
MASTER_SHIP_INFO *BuiltPtr; MASTER_SHIP_INFO *BuiltPtr;
RACE_DESC *RDPtr; RACE_DESC *RDPtr;
@@ -65,9 +65,8 @@ LoadMasterShipList (void (* YieldProcessing)(void))
BuiltPtr->Fleet = RDPtr->fleet; BuiltPtr->Fleet = RDPtr->fleet;
free_ship (RDPtr, FALSE, FALSE); free_ship (RDPtr, FALSE, FALSE);
GetStringContents (SetAbsStringTableIndex ( builtName = GetStringAddress (SetAbsStringTableIndex (
BuiltPtr->ShipInfo.race_strings, 2 BuiltPtr->ShipInfo.race_strings, 2));
), (STRINGPTR)built_buf, FALSE);
UnlockMasterShip (&master_q, hBuiltShip); UnlockMasterShip (&master_q, hBuiltShip);
// Insert the ship in the master queue in the right location // Insert the ship in the master queue in the right location
@@ -75,17 +74,16 @@ LoadMasterShipList (void (* YieldProcessing)(void))
for (hStarShip = GetHeadLink (&master_q); for (hStarShip = GetHeadLink (&master_q);
hStarShip; hStarShip = hNextShip) hStarShip; hStarShip = hNextShip)
{ {
char ship_buf[30]; char *curName;
MASTER_SHIP_INFO *MasterPtr; MASTER_SHIP_INFO *MasterPtr;
MasterPtr = LockMasterShip (&master_q, hStarShip); MasterPtr = LockMasterShip (&master_q, hStarShip);
hNextShip = _GetSuccLink (MasterPtr); hNextShip = _GetSuccLink (MasterPtr);
GetStringContents (SetAbsStringTableIndex ( curName = GetStringAddress (SetAbsStringTableIndex (
MasterPtr->ShipInfo.race_strings, 2 MasterPtr->ShipInfo.race_strings, 2));
), (STRINGPTR)ship_buf, FALSE);
UnlockMasterShip (&master_q, hStarShip); UnlockMasterShip (&master_q, hStarShip);
if (strcmp (built_buf, ship_buf) < 0) if (strcmp (builtName, curName) < 0)
break; break;
} }
InsertQueue (&master_q, hBuiltShip, hStarShip); InsertQueue (&master_q, hBuiltShip, hStarShip);
+3
View File
@@ -194,6 +194,9 @@ enum
#define NUMBER_OF_ROCKY_WORLDS (NUMBER_OF_SMALL_ROCKY_WORLDS + NUMBER_OF_LARGE_ROCKY_WORLDS) #define NUMBER_OF_ROCKY_WORLDS (NUMBER_OF_SMALL_ROCKY_WORLDS + NUMBER_OF_LARGE_ROCKY_WORLDS)
#define NUMBER_OF_GAS_GIANTS (LAST_GAS_GIANT - FIRST_GAS_GIANT + 1) #define NUMBER_OF_GAS_GIANTS (LAST_GAS_GIANT - FIRST_GAS_GIANT + 1)
// TODO: This struct is highly alignment and padding dependent and
// should not be used! The data is loaded as binary from files and
// cast to this struct.
typedef struct typedef struct
{ {
const SIZE level_tab[3]; const SIZE level_tab[3];
+1 -1
View File
@@ -199,7 +199,7 @@ struct solarsys_state
BYTE max_ship_speed; BYTE max_ship_speed;
STRING XlatRef; STRING XlatRef;
STRINGPTR XlatPtr; void *XlatPtr;
COLORMAP OrbitalCMap; COLORMAP OrbitalCMap;
SYSTEM_INFO SysInfo; SYSTEM_INFO SysInfo;