Codechange: Use null pointer literal instead of the NULL macro
This commit is contained in:

committed by
Michael Lutz

parent
3b4f224c0b
commit
7c8e7c6b6e
@@ -59,8 +59,8 @@ Case::~Case()
|
||||
* @param line The line this string was found on.
|
||||
*/
|
||||
LangString::LangString(const char *name, const char *english, int index, int line) :
|
||||
name(stredup(name)), english(stredup(english)), translated(NULL),
|
||||
hash_next(0), index(index), line(line), translated_case(NULL)
|
||||
name(stredup(name)), english(stredup(english)), translated(nullptr),
|
||||
hash_next(0), index(index), line(line), translated_case(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -77,10 +77,10 @@ LangString::~LangString()
|
||||
void LangString::FreeTranslation()
|
||||
{
|
||||
free(this->translated);
|
||||
this->translated = NULL;
|
||||
this->translated = nullptr;
|
||||
|
||||
delete this->translated_case;
|
||||
this->translated_case = NULL;
|
||||
this->translated_case = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ void StringData::FreeTranslation()
|
||||
{
|
||||
for (size_t i = 0; i < this->max_strings; i++) {
|
||||
LangString *ls = this->strings[i];
|
||||
if (ls != NULL) ls->FreeTranslation();
|
||||
if (ls != nullptr) ls->FreeTranslation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ void StringData::Add(const char *s, LangString *ls)
|
||||
/**
|
||||
* Find a LangString based on the string name.
|
||||
* @param s The string name to search on.
|
||||
* @return The LangString or NULL if it is not known.
|
||||
* @return The LangString or nullptr if it is not known.
|
||||
*/
|
||||
LangString *StringData::Find(const char *s)
|
||||
{
|
||||
@@ -152,7 +152,7 @@ LangString *StringData::Find(const char *s)
|
||||
if (strcmp(ls->name, s) == 0) return ls;
|
||||
idx = ls->hash_next;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,7 +181,7 @@ uint StringData::Version() const
|
||||
for (size_t i = 0; i < this->max_strings; i++) {
|
||||
const LangString *ls = this->strings[i];
|
||||
|
||||
if (ls != NULL) {
|
||||
if (ls != nullptr) {
|
||||
const CmdStruct *cs;
|
||||
const char *s;
|
||||
char buf[MAX_COMMAND_PARAM_SIZE];
|
||||
@@ -194,7 +194,7 @@ uint StringData::Version() const
|
||||
hash = this->VersionHashStr(hash, s + 1);
|
||||
|
||||
s = ls->english;
|
||||
while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != NULL) {
|
||||
while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != nullptr) {
|
||||
if (cs->flags & C_DONTCOUNT) continue;
|
||||
|
||||
hash ^= (cs - _cmd_structs) * 0x1234567;
|
||||
@@ -213,7 +213,7 @@ uint StringData::Version() const
|
||||
uint StringData::CountInUse(uint tab) const
|
||||
{
|
||||
int i;
|
||||
for (i = TAB_SIZE; --i >= 0;) if (this->strings[(tab * TAB_SIZE) + i] != NULL) break;
|
||||
for (i = TAB_SIZE; --i >= 0;) if (this->strings[(tab * TAB_SIZE) + i] != nullptr) break;
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ bool ParseRelNum(char **buf, int *value, int *offset)
|
||||
} else {
|
||||
*value = v;
|
||||
}
|
||||
if (offset != NULL && *end == ':') {
|
||||
if (offset != nullptr && *end == ':') {
|
||||
/* Take the Nth within */
|
||||
s = end + 1;
|
||||
*offset = strtol(s, &end, 0);
|
||||
@@ -337,13 +337,13 @@ bool ParseRelNum(char **buf, int *value, int *offset)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Parse out the next word, or NULL */
|
||||
/* Parse out the next word, or nullptr */
|
||||
char *ParseWord(char **buf)
|
||||
{
|
||||
char *s = *buf, *r;
|
||||
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (*s == '\0') return NULL;
|
||||
if (*s == '\0') return nullptr;
|
||||
|
||||
if (*s == '"') {
|
||||
r = ++s;
|
||||
@@ -399,8 +399,8 @@ void EmitPlural(Buffer *buffer, char *buf, int value)
|
||||
const CmdStruct *cmd = _cur_pcs.cmd[argidx];
|
||||
if (offset == -1) {
|
||||
/* Use default offset */
|
||||
if (cmd == NULL || cmd->default_plural_offset < 0) {
|
||||
strgen_fatal("Command '%s' has no (default) plural position", cmd == NULL ? "<empty>" : cmd->cmd);
|
||||
if (cmd == nullptr || cmd->default_plural_offset < 0) {
|
||||
strgen_fatal("Command '%s' has no (default) plural position", cmd == nullptr ? "<empty>" : cmd->cmd);
|
||||
}
|
||||
offset = cmd->default_plural_offset;
|
||||
}
|
||||
@@ -408,7 +408,7 @@ void EmitPlural(Buffer *buffer, char *buf, int value)
|
||||
/* Parse each string */
|
||||
for (nw = 0; nw < MAX_PLURALS; nw++) {
|
||||
words[nw] = ParseWord(&buf);
|
||||
if (words[nw] == NULL) break;
|
||||
if (words[nw] == nullptr) break;
|
||||
}
|
||||
|
||||
if (nw == 0) {
|
||||
@@ -462,13 +462,13 @@ void EmitGender(Buffer *buffer, char *buf, int value)
|
||||
if (!ParseRelNum(&buf, &argidx, &offset)) {}
|
||||
|
||||
const CmdStruct *cmd = _cur_pcs.cmd[argidx];
|
||||
if (cmd == NULL || (cmd->flags & C_GENDER) == 0) {
|
||||
strgen_fatal("Command '%s' can't have a gender", cmd == NULL ? "<empty>" : cmd->cmd);
|
||||
if (cmd == nullptr || (cmd->flags & C_GENDER) == 0) {
|
||||
strgen_fatal("Command '%s' can't have a gender", cmd == nullptr ? "<empty>" : cmd->cmd);
|
||||
}
|
||||
|
||||
for (nw = 0; nw < MAX_NUM_GENDERS; nw++) {
|
||||
words[nw] = ParseWord(&buf);
|
||||
if (words[nw] == NULL) break;
|
||||
if (words[nw] == nullptr) break;
|
||||
}
|
||||
if (nw != _lang.num_genders) strgen_fatal("Bad # of arguments for gender command");
|
||||
|
||||
@@ -484,7 +484,7 @@ static const CmdStruct *FindCmd(const char *s, int len)
|
||||
for (const CmdStruct *cs = _cmd_structs; cs != endof(_cmd_structs); cs++) {
|
||||
if (strncmp(cs->cmd, s, len) == 0 && cs->cmd[len] == '\0') return cs;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static uint ResolveCaseName(const char *str, size_t len)
|
||||
@@ -501,7 +501,7 @@ static uint ResolveCaseName(const char *str, size_t len)
|
||||
}
|
||||
|
||||
|
||||
/* returns NULL on eof
|
||||
/* returns nullptr on eof
|
||||
* else returns command struct */
|
||||
static const CmdStruct *ParseCommandString(const char **str, char *param, int *argno, int *casei)
|
||||
{
|
||||
@@ -513,7 +513,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
|
||||
|
||||
/* Scan to the next command, exit if there's no next command. */
|
||||
for (; *s != '{'; s++) {
|
||||
if (*s == '\0') return NULL;
|
||||
if (*s == '\0') return nullptr;
|
||||
}
|
||||
s++; // Skip past the {
|
||||
|
||||
@@ -532,9 +532,9 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
|
||||
} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0);
|
||||
|
||||
const CmdStruct *cmd = FindCmd(start, s - start - 1);
|
||||
if (cmd == NULL) {
|
||||
if (cmd == nullptr) {
|
||||
strgen_error("Undefined command '%.*s'", (int)(s - start - 1), start);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (c == '.') {
|
||||
@@ -552,7 +552,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
|
||||
|
||||
if (c == '\0') {
|
||||
strgen_error("Missing } from command '%s'", start);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -565,7 +565,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
|
||||
if (c == '}') break;
|
||||
if (c == '\0') {
|
||||
strgen_error("Missing } from command '%s'", start);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (s - start == MAX_COMMAND_PARAM_SIZE) error("param command too long");
|
||||
*param++ = c;
|
||||
@@ -609,7 +609,7 @@ static void ExtractCommandString(ParsedCommandStruct *p, const char *s, bool war
|
||||
/* read until next command from a. */
|
||||
const CmdStruct *ar = ParseCommandString(&s, param, &argno, &casei);
|
||||
|
||||
if (ar == NULL) break;
|
||||
if (ar == nullptr) break;
|
||||
|
||||
/* Sanity checking */
|
||||
if (argno != -1 && ar->consumes == 0) strgen_fatal("Non consumer param can't have a paramindex");
|
||||
@@ -617,7 +617,7 @@ static void ExtractCommandString(ParsedCommandStruct *p, const char *s, bool war
|
||||
if (ar->consumes) {
|
||||
if (argno != -1) argidx = argno;
|
||||
if (argidx < 0 || (uint)argidx >= lengthof(p->cmd)) strgen_fatal("invalid param idx %d", argidx);
|
||||
if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) strgen_fatal("duplicate param idx %d", argidx);
|
||||
if (p->cmd[argidx] != nullptr && p->cmd[argidx] != ar) strgen_fatal("duplicate param idx %d", argidx);
|
||||
|
||||
p->cmd[argidx++] = ar;
|
||||
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
|
||||
@@ -632,7 +632,7 @@ static void ExtractCommandString(ParsedCommandStruct *p, const char *s, bool war
|
||||
|
||||
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
|
||||
{
|
||||
if (a == NULL) return NULL;
|
||||
if (a == nullptr) return nullptr;
|
||||
|
||||
if (strcmp(a->cmd, "STRING1") == 0 ||
|
||||
strcmp(a->cmd, "STRING2") == 0 ||
|
||||
@@ -677,7 +677,7 @@ static bool CheckCommandsMatch(char *a, char *b, const char *name)
|
||||
if (templ.pairs[i].a == lang.pairs[j].a &&
|
||||
strcmp(templ.pairs[i].v, lang.pairs[j].v) == 0) {
|
||||
/* it was found in both. zero it out from lang so we don't find it again */
|
||||
lang.pairs[j].a = NULL;
|
||||
lang.pairs[j].a = nullptr;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -694,8 +694,8 @@ static bool CheckCommandsMatch(char *a, char *b, const char *name)
|
||||
for (uint i = 0; i < lengthof(templ.cmd); i++) {
|
||||
if (TranslateCmdForCompare(templ.cmd[i]) != lang.cmd[i]) {
|
||||
strgen_warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
|
||||
lang.cmd[i] == NULL ? "<empty>" : TranslateCmdForCompare(lang.cmd[i])->cmd,
|
||||
templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd);
|
||||
lang.cmd[i] == nullptr ? "<empty>" : TranslateCmdForCompare(lang.cmd[i])->cmd,
|
||||
templ.cmd[i] == nullptr ? "<empty>" : templ.cmd[i]->cmd);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
@@ -714,7 +714,7 @@ void StringReader::HandleString(char *str)
|
||||
if (*str == ';' || *str == ' ' || *str == '\0') return;
|
||||
|
||||
char *s = strchr(str, ':');
|
||||
if (s == NULL) {
|
||||
if (s == nullptr) {
|
||||
strgen_error("Line has no ':' delimiter");
|
||||
return;
|
||||
}
|
||||
@@ -747,23 +747,23 @@ void StringReader::HandleString(char *str)
|
||||
/* Check if the string has a case..
|
||||
* The syntax for cases is IDENTNAME.case */
|
||||
char *casep = strchr(str, '.');
|
||||
if (casep != NULL) *casep++ = '\0';
|
||||
if (casep != nullptr) *casep++ = '\0';
|
||||
|
||||
/* Check if this string already exists.. */
|
||||
LangString *ent = this->data.Find(str);
|
||||
|
||||
if (this->master) {
|
||||
if (casep != NULL) {
|
||||
if (casep != nullptr) {
|
||||
strgen_error("Cases in the base translation are not supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent != NULL) {
|
||||
if (ent != nullptr) {
|
||||
strgen_error("String name '%s' is used multiple times", str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->data.strings[this->data.next_string_id] != NULL) {
|
||||
if (this->data.strings[this->data.next_string_id] != nullptr) {
|
||||
strgen_error("String ID 0x%X for '%s' already in use by '%s'", this->data.next_string_id, str, this->data.strings[this->data.next_string_id]->name);
|
||||
return;
|
||||
}
|
||||
@@ -771,12 +771,12 @@ void StringReader::HandleString(char *str)
|
||||
/* Allocate a new LangString */
|
||||
this->data.Add(str, new LangString(str, s, this->data.next_string_id++, _cur_line));
|
||||
} else {
|
||||
if (ent == NULL) {
|
||||
if (ent == nullptr) {
|
||||
strgen_warning("String name '%s' does not exist in master file", str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->translated && casep == NULL) {
|
||||
if (ent->translated && casep == nullptr) {
|
||||
strgen_error("String name '%s' is used multiple times", str);
|
||||
return;
|
||||
}
|
||||
@@ -784,7 +784,7 @@ void StringReader::HandleString(char *str)
|
||||
/* make sure that the commands match */
|
||||
if (!CheckCommandsMatch(s, ent->english, str)) return;
|
||||
|
||||
if (casep != NULL) {
|
||||
if (casep != nullptr) {
|
||||
ent->translated_case = new Case(ResolveCaseName(casep, strlen(casep)), s, ent->translated_case);
|
||||
} else {
|
||||
ent->translated = stredup(s);
|
||||
@@ -830,7 +830,7 @@ void StringReader::ParseFile()
|
||||
strecpy(_lang.digit_decimal_separator, ".", lastof(_lang.digit_decimal_separator));
|
||||
|
||||
_cur_line = 1;
|
||||
while (this->ReadLine(buf, lastof(buf)) != NULL) {
|
||||
while (this->ReadLine(buf, lastof(buf)) != nullptr) {
|
||||
rstrip(buf);
|
||||
this->HandleString(buf);
|
||||
_cur_line++;
|
||||
@@ -845,7 +845,7 @@ void HeaderWriter::WriteHeader(const StringData &data)
|
||||
{
|
||||
int last = 0;
|
||||
for (size_t i = 0; i < data.max_strings; i++) {
|
||||
if (data.strings[i] != NULL) {
|
||||
if (data.strings[i] != nullptr) {
|
||||
this->WriteStringID(data.strings[i]->name, (int)i);
|
||||
last = (int)i;
|
||||
}
|
||||
@@ -862,18 +862,18 @@ static int TranslateArgumentIdx(int argidx, int offset)
|
||||
strgen_fatal("invalid argidx %d", argidx);
|
||||
}
|
||||
const CmdStruct *cs = _cur_pcs.cmd[argidx];
|
||||
if (cs != NULL && cs->consumes <= offset) {
|
||||
if (cs != nullptr && cs->consumes <= offset) {
|
||||
strgen_fatal("invalid argidx offset %d:%d", argidx, offset);
|
||||
}
|
||||
|
||||
if (_cur_pcs.cmd[argidx] == NULL) {
|
||||
if (_cur_pcs.cmd[argidx] == nullptr) {
|
||||
strgen_fatal("no command for this argidx %d", argidx);
|
||||
}
|
||||
|
||||
for (int i = sum = 0; i < argidx; i++) {
|
||||
const CmdStruct *cs = _cur_pcs.cmd[i];
|
||||
|
||||
sum += (cs != NULL) ? cs->consumes : 1;
|
||||
sum += (cs != nullptr) ? cs->consumes : 1;
|
||||
}
|
||||
|
||||
return sum + offset;
|
||||
@@ -901,7 +901,7 @@ static void PutCommandString(Buffer *buffer, const char *str)
|
||||
int argno;
|
||||
int casei;
|
||||
const CmdStruct *cs = ParseCommandString(&str, param, &argno, &casei);
|
||||
if (cs == NULL) break;
|
||||
if (cs == nullptr) break;
|
||||
|
||||
if (casei != -1) {
|
||||
buffer->AppendUtf8(SCC_SET_CASE); // {SET_CASE}
|
||||
@@ -918,7 +918,7 @@ static void PutCommandString(Buffer *buffer, const char *str)
|
||||
|
||||
/* Output the one from the master string... it's always accurate. */
|
||||
cs = _cur_pcs.cmd[_cur_argidx++];
|
||||
if (cs == NULL) {
|
||||
if (cs == nullptr) {
|
||||
strgen_fatal("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
|
||||
}
|
||||
}
|
||||
@@ -961,7 +961,7 @@ void LanguageWriter::WriteLang(const StringData &data)
|
||||
|
||||
for (uint j = 0; j != in_use[tab]; j++) {
|
||||
const LangString *ls = data.strings[(tab * TAB_SIZE) + j];
|
||||
if (ls != NULL && ls->translated == NULL) _lang.missing++;
|
||||
if (ls != nullptr && ls->translated == nullptr) _lang.missing++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -980,7 +980,7 @@ void LanguageWriter::WriteLang(const StringData &data)
|
||||
const char *cmdp;
|
||||
|
||||
/* For undefined strings, just set that it's an empty string */
|
||||
if (ls == NULL) {
|
||||
if (ls == nullptr) {
|
||||
this->WriteLength(0);
|
||||
continue;
|
||||
}
|
||||
@@ -989,7 +989,7 @@ void LanguageWriter::WriteLang(const StringData &data)
|
||||
_cur_line = ls->line;
|
||||
|
||||
/* Produce a message if a string doesn't have a translation. */
|
||||
if (_show_todo > 0 && ls->translated == NULL) {
|
||||
if (_show_todo > 0 && ls->translated == nullptr) {
|
||||
if ((_show_todo & 2) != 0) {
|
||||
strgen_warning("'%s' is untranslated", ls->name);
|
||||
}
|
||||
@@ -1002,17 +1002,17 @@ void LanguageWriter::WriteLang(const StringData &data)
|
||||
/* Extract the strings and stuff from the english command string */
|
||||
ExtractCommandString(&_cur_pcs, ls->english, false);
|
||||
|
||||
if (ls->translated_case != NULL || ls->translated != NULL) {
|
||||
if (ls->translated_case != nullptr || ls->translated != nullptr) {
|
||||
casep = ls->translated_case;
|
||||
cmdp = ls->translated;
|
||||
} else {
|
||||
casep = NULL;
|
||||
casep = nullptr;
|
||||
cmdp = ls->english;
|
||||
}
|
||||
|
||||
_translated = cmdp != ls->english;
|
||||
|
||||
if (casep != NULL) {
|
||||
if (casep != nullptr) {
|
||||
const Case *c;
|
||||
uint num;
|
||||
|
||||
@@ -1026,7 +1026,7 @@ void LanguageWriter::WriteLang(const StringData &data)
|
||||
buffer.AppendByte(num);
|
||||
|
||||
/* Write each case */
|
||||
for (c = casep; c != NULL; c = c->next) {
|
||||
for (c = casep; c != nullptr; c = c->next) {
|
||||
buffer.AppendByte(c->caseidx);
|
||||
/* Make some space for the 16-bit length */
|
||||
uint pos = (uint)buffer.size();
|
||||
@@ -1042,7 +1042,7 @@ void LanguageWriter::WriteLang(const StringData &data)
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdp != NULL) PutCommandString(&buffer, cmdp);
|
||||
if (cmdp != nullptr) PutCommandString(&buffer, cmdp);
|
||||
|
||||
this->WriteLength((uint)buffer.size());
|
||||
this->Write(buffer.data(), buffer.size());
|
||||
|
Reference in New Issue
Block a user