summaryrefslogtreecommitdiff
path: root/src/settingsgen
diff options
context:
space:
mode:
authorHenry Wilson <m3henry@googlemail.com>2019-04-10 22:07:06 +0100
committerMichael Lutz <michi@icosahedron.de>2019-04-10 23:22:20 +0200
commit7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch)
tree99f134b7e66367cf11e10bc5061896eab4a3264f /src/settingsgen
parent3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff)
downloadopenttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/settingsgen')
-rw-r--r--src/settingsgen/settingsgen.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp
index 02a0d1a9a..7f024b2dc 100644
--- a/src/settingsgen/settingsgen.cpp
+++ b/src/settingsgen/settingsgen.cpp
@@ -160,10 +160,10 @@ private:
struct SettingsIniFile : IniLoadFile {
/**
* Construct a new ini loader.
- * @param list_group_names A \c NULL terminated list with group names that should be loaded as lists instead of variables. @see IGT_LIST
- * @param seq_group_names A \c NULL terminated list with group names that should be loaded as lists of names. @see IGT_SEQUENCE
+ * @param list_group_names A \c nullptr terminated list with group names that should be loaded as lists instead of variables. @see IGT_LIST
+ * @param seq_group_names A \c nullptr terminated list with group names that should be loaded as lists of names. @see IGT_SEQUENCE
*/
- SettingsIniFile(const char * const *list_group_names = NULL, const char * const *seq_group_names = NULL) :
+ SettingsIniFile(const char * const *list_group_names = nullptr, const char * const *seq_group_names = nullptr) :
IniLoadFile(list_group_names, seq_group_names)
{
}
@@ -173,7 +173,7 @@ struct SettingsIniFile : IniLoadFile {
/* Open the text file in binary mode to prevent end-of-line translations
* done by ftell() and friends, as defined by K&R. */
FILE *in = fopen(filename, "rb");
- if (in == NULL) return NULL;
+ if (in == nullptr) return nullptr;
fseek(in, 0L, SEEK_END);
*size = ftell(in);
@@ -202,9 +202,9 @@ static const char *DEFAULTS_GROUP_NAME = "defaults"; ///< Name of the group c
*/
static IniLoadFile *LoadIniFile(const char *filename)
{
- static const char * const seq_groups[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, NULL};
+ static const char * const seq_groups[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, nullptr};
- IniLoadFile *ini = new SettingsIniFile(NULL, seq_groups);
+ IniLoadFile *ini = new SettingsIniFile(nullptr, seq_groups);
ini->LoadFromDisk(filename, NO_DIRECTORY);
return ini;
}
@@ -217,8 +217,8 @@ static IniLoadFile *LoadIniFile(const char *filename)
static void DumpGroup(IniLoadFile *ifile, const char * const group_name)
{
IniGroup *grp = ifile->GetGroup(group_name, 0, false);
- if (grp != NULL && grp->type == IGT_SEQUENCE) {
- for (IniItem *item = grp->item; item != NULL; item = item->next) {
+ if (grp != nullptr && grp->type == IGT_SEQUENCE) {
+ for (IniItem *item = grp->item; item != nullptr; item = item->next) {
if (item->name) {
_stored_output.Add(item->name);
_stored_output.Add("\n", 1);
@@ -231,14 +231,14 @@ static void DumpGroup(IniLoadFile *ifile, const char * const group_name)
* Find the value of a template variable.
* @param name Name of the item to find.
* @param grp Group currently being expanded (searched first).
- * @param defaults Fallback group to search, \c NULL skips the search.
- * @return Text of the item if found, else \c NULL.
+ * @param defaults Fallback group to search, \c nullptr skips the search.
+ * @return Text of the item if found, else \c nullptr.
*/
static const char *FindItemValue(const char *name, IniGroup *grp, IniGroup *defaults)
{
IniItem *item = grp->GetItem(name, false);
- if (item == NULL && defaults != NULL) item = defaults->GetItem(name, false);
- if (item == NULL || item->value == NULL) return NULL;
+ if (item == nullptr && defaults != nullptr) item = defaults->GetItem(name, false);
+ if (item == nullptr || item->value == nullptr) return nullptr;
return item->value;
}
@@ -249,30 +249,30 @@ static const char *FindItemValue(const char *name, IniGroup *grp, IniGroup *defa
static void DumpSections(IniLoadFile *ifile)
{
static const int MAX_VAR_LENGTH = 64;
- static const char * const special_group_names[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, DEFAULTS_GROUP_NAME, TEMPLATES_GROUP_NAME, NULL};
+ static const char * const special_group_names[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, DEFAULTS_GROUP_NAME, TEMPLATES_GROUP_NAME, nullptr};
IniGroup *default_grp = ifile->GetGroup(DEFAULTS_GROUP_NAME, 0, false);
IniGroup *templates_grp = ifile->GetGroup(TEMPLATES_GROUP_NAME, 0, false);
- if (templates_grp == NULL) return;
+ if (templates_grp == nullptr) return;
/* Output every group, using its name as template name. */
- for (IniGroup *grp = ifile->group; grp != NULL; grp = grp->next) {
+ for (IniGroup *grp = ifile->group; grp != nullptr; grp = grp->next) {
const char * const *sgn;
- for (sgn = special_group_names; *sgn != NULL; sgn++) if (strcmp(grp->name, *sgn) == 0) break;
- if (*sgn != NULL) continue;
+ for (sgn = special_group_names; *sgn != nullptr; sgn++) if (strcmp(grp->name, *sgn) == 0) break;
+ if (*sgn != nullptr) continue;
IniItem *template_item = templates_grp->GetItem(grp->name, false); // Find template value.
- if (template_item == NULL || template_item->value == NULL) {
+ if (template_item == nullptr || template_item->value == nullptr) {
fprintf(stderr, "settingsgen: Warning: Cannot find template %s\n", grp->name);
continue;
}
/* Prefix with #if/#ifdef/#ifndef */
- static const char * const pp_lines[] = {"if", "ifdef", "ifndef", NULL};
+ static const char * const pp_lines[] = {"if", "ifdef", "ifndef", nullptr};
int count = 0;
- for (const char * const *name = pp_lines; *name != NULL; name++) {
+ for (const char * const *name = pp_lines; *name != nullptr; name++) {
const char *condition = FindItemValue(*name, grp, default_grp);
- if (condition != NULL) {
+ if (condition != nullptr) {
_stored_output.Add("#", 1);
_stored_output.Add(*name);
_stored_output.Add(" ", 1);
@@ -311,7 +311,7 @@ static void DumpSections(IniLoadFile *ifile)
if (i > 0) {
/* Find the text to output. */
const char *valitem = FindItemValue(variable, grp, default_grp);
- if (valitem != NULL) _stored_output.Add(valitem);
+ if (valitem != nullptr) _stored_output.Add(valitem);
} else {
_stored_output.Add("$", 1);
}
@@ -331,10 +331,10 @@ static void DumpSections(IniLoadFile *ifile)
*/
static void CopyFile(const char *fname, FILE *out_fp)
{
- if (fname == NULL) return;
+ if (fname == nullptr) return;
FILE *in_fp = fopen(fname, "r");
- if (in_fp == NULL) {
+ if (in_fp == nullptr) {
fprintf(stderr, "settingsgen: Warning: Cannot open file %s for copying\n", fname);
return;
}
@@ -361,10 +361,10 @@ static void CopyFile(const char *fname, FILE *out_fp)
static bool CompareFiles(const char *n1, const char *n2)
{
FILE *f2 = fopen(n2, "rb");
- if (f2 == NULL) return false;
+ if (f2 == nullptr) return false;
FILE *f1 = fopen(n1, "rb");
- if (f1 == NULL) {
+ if (f1 == nullptr) {
fclose(f2);
error("can't open %s", n1);
}
@@ -392,7 +392,7 @@ static bool CompareFiles(const char *n1, const char *n2)
static const OptionData _opts[] = {
GETOPT_NOVAL( 'v', "--version"),
GETOPT_NOVAL( 'h', "--help"),
- GETOPT_GENERAL('h', '?', NULL, ODF_NO_VALUE),
+ GETOPT_GENERAL('h', '?', nullptr, ODF_NO_VALUE),
GETOPT_VALUE( 'o', "--output"),
GETOPT_VALUE( 'b', "--before"),
GETOPT_VALUE( 'a', "--after"),
@@ -435,9 +435,9 @@ static void ProcessIniFile(const char *fname)
*/
int CDECL main(int argc, char *argv[])
{
- const char *output_file = NULL;
- const char *before_file = NULL;
- const char *after_file = NULL;
+ const char *output_file = nullptr;
+ const char *before_file = nullptr;
+ const char *after_file = nullptr;
GetOptData mgo(argc - 1, argv + 1, _opts);
for (;;) {
@@ -483,7 +483,7 @@ int CDECL main(int argc, char *argv[])
for (int i = 0; i < mgo.numleft; i++) ProcessIniFile(mgo.argv[i]);
/* Write output. */
- if (output_file == NULL) {
+ if (output_file == nullptr) {
CopyFile(before_file, stdout);
_stored_output.Write(stdout);
CopyFile(after_file, stdout);
@@ -491,7 +491,7 @@ int CDECL main(int argc, char *argv[])
static const char * const tmp_output = "tmp2.xxx";
FILE *fp = fopen(tmp_output, "w");
- if (fp == NULL) {
+ if (fp == nullptr) {
fprintf(stderr, "settingsgen: Warning: Cannot open file %s\n", tmp_output);
return 1;
}