mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
This commit is contained in:
parent
498ccae27a
commit
b2ae5b197e
1
Makefile
1
Makefile
|
@ -624,6 +624,7 @@ C_SOURCES += sprite.c
|
|||
C_SOURCES += spritecache.c
|
||||
C_SOURCES += station_cmd.c
|
||||
C_SOURCES += station_gui.c
|
||||
C_SOURCES += string.c
|
||||
C_SOURCES += strings.c
|
||||
C_SOURCES += subsidy_gui.c
|
||||
C_SOURCES += terraform_gui.c
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "debug.h"
|
||||
#include "engine.h"
|
||||
#include "functions.h"
|
||||
#include "string.h"
|
||||
#include "variables.h"
|
||||
#include "network_data.h"
|
||||
#include "network_client.h"
|
||||
|
|
|
@ -249,9 +249,6 @@ enum {
|
|||
};
|
||||
void ShowSaveLoadDialog(int mode);
|
||||
|
||||
void ttd_strlcpy(char *dst, const char *src, size_t size);
|
||||
void ttd_strlcat(char *dst, const char *src, size_t size);
|
||||
|
||||
// callback from drivers that is called if the game size changes dynamically
|
||||
void GameSizeChanged(void);
|
||||
bool FileExists(const char *filename);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "table/strings.h"
|
||||
#include "command.h"
|
||||
#include "player.h"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "map.h"
|
||||
#include "network_data.h"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "network_data.h"
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "network.h"
|
||||
#include "saveload.h"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "network_data.h"
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
#include "network_data.h"
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
|
|
1
os2.c
1
os2.c
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "table/strings.h"
|
||||
#include "hal.h"
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "table/strings.h"
|
||||
#include "map.h"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "sound.h"
|
||||
#include "string.h"
|
||||
#include "table/currency.h"
|
||||
#include "network.h"
|
||||
#include "settings.h"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "strings.h" // XXX GetCurrentCurrencyRate()
|
||||
#include "table/strings.h"
|
||||
#include "window.h"
|
||||
|
|
1
stdafx.h
1
stdafx.h
|
@ -214,6 +214,7 @@ assert_compile(sizeof(uint8) == 1);
|
|||
|
||||
#define lengthof(x) (sizeof(x)/sizeof(x[0]))
|
||||
#define endof(x) (&x[lengthof(x)])
|
||||
#define lastof(x) (&x[lengthof(x) - 1])
|
||||
#ifndef offsetof
|
||||
#define offsetof(s,m) (size_t)&(((s *)0)->m)
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
#include "stdafx.h"
|
||||
#include "string.h"
|
||||
|
||||
void ttd_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
assert(size > 0);
|
||||
for (; size > 0 && *dst != '\0'; --size, ++dst) {}
|
||||
assert(size > 0);
|
||||
while (--size > 0 && *src != '\0') *dst++ = *src++;
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
|
||||
void ttd_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
assert(size > 0);
|
||||
while (--size > 0 && *src != '\0') *dst++ = *src++;
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
|
||||
char* strecat(char* dst, const char* src, const char* last)
|
||||
{
|
||||
assert(last == NULL || dst <= last);
|
||||
for (; *dst != '\0'; ++dst)
|
||||
if (dst == last) return dst;
|
||||
for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src;
|
||||
*dst = '\0';
|
||||
return strecpy(dst, src, last);
|
||||
}
|
||||
|
||||
|
||||
char* strecpy(char* dst, const char* src, const char* last)
|
||||
{
|
||||
assert(last == NULL || dst <= last);
|
||||
for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src;
|
||||
*dst = '\0';
|
||||
return dst;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
/*
|
||||
* dst: destination buffer
|
||||
* src: string to copy/concatenate
|
||||
* size: size of the destination buffer
|
||||
* usage: ttd_strlcpy(dst, src, lengthof(dst));
|
||||
*/
|
||||
void ttd_strlcat(char *dst, const char *src, size_t size);
|
||||
void ttd_strlcpy(char *dst, const char *src, size_t size);
|
||||
|
||||
/*
|
||||
* dst: destination buffer
|
||||
* src: string to copy
|
||||
* last: pointer to the last element in the dst array
|
||||
* if NULL no boundary check is performed
|
||||
* returns a pointer to the terminating \0 in the destination buffer
|
||||
* usage: strecpy(dst, src, lastof(dst));
|
||||
*/
|
||||
char* strecat(char* dst, const char* src, const char* last);
|
||||
char* strecpy(char* dst, const char* src, const char* last);
|
||||
|
||||
#endif
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "strings.h"
|
||||
#include "table/strings.h"
|
||||
#include "namegen.h"
|
||||
|
|
25
ttd.c
25
ttd.c
|
@ -1,4 +1,5 @@
|
|||
#include "stdafx.h"
|
||||
#include "string.h"
|
||||
#include "table/strings.h"
|
||||
#include "debug.h"
|
||||
#include "strings.h"
|
||||
|
@ -197,27 +198,6 @@ static const DriverDesc *ChooseDefaultDriver(const DriverDesc *dd)
|
|||
return best;
|
||||
}
|
||||
|
||||
void ttd_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
assert(size > 0);
|
||||
while (--size > 0 && *src != '\0') *dst++ = *src++;
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
void ttd_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
assert(size > 0);
|
||||
for (; size > 0 && *dst != '\0'; --size, ++dst) {}
|
||||
assert(size > 0);
|
||||
while (--size > 0 && *src != '\0') *dst++ = *src++;
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
static char *strecpy(char *dst, const char *src)
|
||||
{
|
||||
while ( (*dst++ = *src++) != 0) {}
|
||||
return dst - 1;
|
||||
}
|
||||
|
||||
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
|
||||
{
|
||||
|
@ -318,7 +298,8 @@ static void showhelp(void)
|
|||
" -f = Fork into the background (dedicated only)\n"
|
||||
#endif
|
||||
" -i = Force to use the DOS palette (use this if you see a lot of pink)\n"
|
||||
" -p #player = Player as #player (deprecated) (network only)\n"
|
||||
" -p #player = Player as #player (deprecated) (network only)\n",
|
||||
lastof(buf)
|
||||
);
|
||||
|
||||
for(i=0; i!=lengthof(_driver_classes); i++,dc++) {
|
||||
|
|
1
unix.c
1
unix.c
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "table/strings.h"
|
||||
#include "hal.h"
|
||||
|
||||
|
|
1
w32dm.c
1
w32dm.c
|
@ -29,6 +29,7 @@
|
|||
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
|
||||
|
||||
#include "ttd.h"
|
||||
#include "string.h"
|
||||
#include "sound.h"
|
||||
#include "hal.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue