Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #658079 ยป 0040-Registry-Add-support-for-comment-entries.patch

Marko Lindqvist, 2021-04-03 07:02 AM

View differences:

client/options.c
case ENTRY_FILEREFERENCE:
/* Not supported yet */
break;
case ENTRY_LONG_COMMENT:
fc_assert(entry_type_get(pentry) != ENTRY_LONG_COMMENT);
break;
case ENTRY_ILLEGAL:
fc_assert(entry_type_get(pentry) != ENTRY_ILLEGAL);
break;
server/ruleset.c
case ENTRY_FILEREFERENCE:
fc_assert(entry_type_get(pentry) != ENTRY_FILEREFERENCE);
break;
case ENTRY_LONG_COMMENT:
fc_assert(entry_type_get(pentry) != ENTRY_LONG_COMMENT);
break;
case ENTRY_ILLEGAL:
fc_assert(entry_type_get(pentry) != ENTRY_ILLEGAL);
break;
server/savegame/savecompat.c
case ENTRY_FILEREFERENCE:
fc_assert(entries[j].type != ENTRY_FILEREFERENCE);
break;
case ENTRY_LONG_COMMENT:
fc_assert(entries[j].type != ENTRY_LONG_COMMENT);
break;
case ENTRY_ILLEGAL:
fc_assert(entries[j].type != ENTRY_ILLEGAL);
break;
utility/registry_ini.c
};
static struct entry *section_entry_filereference_new(struct section *psection,
const char *name, const char *value);
const char *name,
const char *value);
static struct entry *section_entry_comment_new(struct section *psection,
const char *comment);
/**********************************************************************//**
Simplification of fileinfoname().
......
break;
}
if (pentry->type == ENTRY_LONG_COMMENT) {
break;
}
sz_strlcpy(pentry_name, entry_name(pentry));
c = first = pentry_name;
if (*c == '\0' || !is_legal_table_entry_name(*c, FALSE)) {
......
col_iter = save_iter;
for (; (col_pentry = entry_list_link_data(col_iter));
col_iter = entry_list_link_next(col_iter)) {
if (col_pentry->type == ENTRY_LONG_COMMENT) {
continue;
}
col_entry_name = entry_name(col_pentry);
if (strncmp(col_entry_name, first, offset) != 0) {
break;
......
pentry = entry_list_link_data(ent_iter);
col_pentry = entry_list_link_data(col_iter);
fc_snprintf(expect, sizeof(expect), "%s%d.%s",
base, irow, entry_name(col_pentry) + offset);
/* break out of tabular if doesn't match: */
if ((!pentry) || (strcmp(entry_name(pentry), expect) != 0)) {
if (icol != 0) {
/* If the second or later row of a table is missing some
* entries that the first row had, we drop out of the tabular
* format. This is inefficient so we print a warning message;
* the calling code probably needs to be fixed so that it can
* use the more efficient tabular format.
*
* FIXME: If the first row is missing some entries that the
* second or later row has, then we'll drop out of tabular
* format without an error message. */
bugreport_request("In file %s, there is no entry in the registry for\n"
"%s.%s (or the entries are out of order). This means\n"
"a less efficient non-tabular format will be used.\n"
"To avoid this make sure all rows of a table are\n"
"filled out with an entry for every column.",
real_filename, section_name(psection), expect);
fz_fprintf(fs, "\n");
if (pentry && pentry->type == ENTRY_LONG_COMMENT) {
if (icol == 0) {
entry_to_file(pentry, fs);
} else {
bugreport_request("In file %s, section %s there was\n"
"an attempt to insert comment in the middle of table row.",
real_filename, section_name(psection));
}
ent_iter = entry_list_link_next(ent_iter);
continue;
} else {
fc_snprintf(expect, sizeof(expect), "%s%d.%s",
base, irow, entry_name(col_pentry) + offset);
/* break out of tabular if doesn't match: */
if ((!pentry) || (strcmp(entry_name(pentry), expect) != 0)) {
if (icol != 0) {
/* If the second or later row of a table is missing some
* entries that the first row had, we drop out of the tabular
* format. This is inefficient so we print a warning message;
* the calling code probably needs to be fixed so that it can
* use the more efficient tabular format.
*
* FIXME: If the first row is missing some entries that the
* second or later row has, then we'll drop out of tabular
* format without an error message. */
bugreport_request("In file %s, there is no entry in the registry for\n"
"%s.%s (or the entries are out of order). This means\n"
"a less efficient non-tabular format will be used.\n"
"To avoid this make sure all rows of a table are\n"
"filled out with an entry for every column.",
real_filename, section_name(psection), expect);
fz_fprintf(fs, "\n");
}
fz_fprintf(fs, "}\n");
break;
}
fz_fprintf(fs, "}\n");
break;
}
if (icol > 0) {
......
break;
}
/* Classic entry. */
col_entry_name = entry_name(pentry);
fz_fprintf(fs, "%s=", col_entry_name);
entry_to_file(pentry, fs);
/* Check for vector. */
for (i = 1;; i++) {
col_iter = entry_list_link_next(ent_iter);
col_pentry = entry_list_link_data(col_iter);
if (NULL == col_pentry) {
break;
}
fc_snprintf(pentry_name, sizeof(pentry_name),
"%s,%d", col_entry_name, i);
if (0 != strcmp(pentry_name, entry_name(col_pentry))) {
break;
if (pentry->type == ENTRY_LONG_COMMENT) {
entry_to_file(pentry, fs);
} else {
/* Classic entry. */
col_entry_name = entry_name(pentry);
fz_fprintf(fs, "%s=", col_entry_name);
entry_to_file(pentry, fs);
/* Check for vector. */
for (i = 1;; i++) {
col_iter = entry_list_link_next(ent_iter);
col_pentry = entry_list_link_data(col_iter);
if (NULL == col_pentry || col_pentry->type == ENTRY_LONG_COMMENT) {
break;
}
fc_snprintf(pentry_name, sizeof(pentry_name),
"%s,%d", col_entry_name, i);
if (0 != strcmp(pentry_name, entry_name(col_pentry))) {
break;
}
fz_fprintf(fs, ",");
entry_to_file(col_pentry, fs);
ent_iter = col_iter;
}
fz_fprintf(fs, ",");
entry_to_file(col_pentry, fs);
ent_iter = col_iter;
}
comment = entry_comment(pentry);
if (comment) {
fz_fprintf(fs, " # %s\n", comment);
} else {
fz_fprintf(fs, "\n");
comment = entry_comment(pentry);
if (comment) {
fz_fprintf(fs, " # %s\n", comment);
} else {
fz_fprintf(fs, "\n");
}
}
}
}
......
}
/**********************************************************************//**
Insert a long comment entry.
Insert a long comment section.
**************************************************************************/
struct section *secfile_insert_long_comment(struct section_file *secfile,
const char *comment)
......
return pentry;
}
/**********************************************************************//**
Insert a comment entry.
**************************************************************************/
struct entry *secfile_insert_comment(struct section_file *secfile,
const char *str,
const char *path, ...)
{
char fullpath[MAX_LEN_SECPATH];
const char *ent_name;
struct section *psection;
struct entry *pentry = NULL;
va_list args;
SECFILE_RETURN_VAL_IF_FAIL(secfile, NULL, NULL != secfile, NULL);
va_start(args, path);
fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
va_end(args);
sz_strlcat(fullpath, ".#");
psection = secfile_insert_base(secfile, fullpath, &ent_name);
if (!psection) {
return NULL;
}
if (psection->special != EST_NORMAL) {
log_error("Tried to insert wrong type of entry to section");
return NULL;
}
pentry = section_entry_comment_new(psection, str);
return pentry;
}
/**********************************************************************//**
Insert 'dim' string entries at 'path,0', 'path,1' etc. Returns
the number of entries inserted or replaced.
......
{
struct section_file *secfile;
struct entry *pentry;
bool long_comment = !strcmp("#", name);
SECFILE_RETURN_VAL_IF_FAIL(NULL, psection, NULL != psection, NULL);
......
return NULL;
}
if (!is_secfile_entry_name_valid(name)) {
if (!is_secfile_entry_name_valid(name) && !long_comment) {
SECFILE_LOG(secfile, psection, "\"%s\" is not a valid entry name.",
name);
return NULL;
......
}
pentry = fc_malloc(sizeof(struct entry));
pentry->name = fc_strdup(name);
if (long_comment) {
pentry->name = NULL;
} else {
pentry->name = fc_strdup(name);
}
pentry->type = -1; /* Invalid case. */
pentry->used = 0;
pentry->comment = NULL;
......
Returns a new entry of type ENTRY_FILEREFERENCE.
**************************************************************************/
static struct entry *section_entry_filereference_new(struct section *psection,
const char *name, const char *value)
const char *name,
const char *value)
{
struct entry *pentry = entry_new(psection, name);
......
return pentry;
}
/**********************************************************************//**
Returns a new entry of type ENTRY_LONG_COMMENT.
**************************************************************************/
static struct entry *section_entry_comment_new(struct section *psection,
const char *comment)
{
struct entry *pentry = entry_new(psection, "#");
if (NULL != pentry) {
pentry->type = ENTRY_LONG_COMMENT;
pentry->comment = fc_strdup(NULL != comment ? comment : "");
}
return pentry;
}
/**********************************************************************//**
Entry structure destructor.
**************************************************************************/
......
case ENTRY_BOOL:
case ENTRY_INT:
case ENTRY_FLOAT:
case ENTRY_LONG_COMMENT:
break;
case ENTRY_STR:
......
case ENTRY_FILEREFERENCE:
fz_fprintf(fs, "*%s*", pentry->string.value);
break;
case ENTRY_LONG_COMMENT:
fz_fprintf(fs, "%s\n", pentry->comment);
break;
case ENTRY_ILLEGAL:
fc_assert(pentry->type != ENTRY_ILLEGAL);
break;
utility/registry_ini.h
char *filename, char *path, ...)
fc__attribute((__format__ (__printf__, 3, 4)));
struct entry *secfile_insert_comment(struct section_file *secfile,
const char *str,
const char *path, ...)
fc__attribute((__format__ (__printf__, 3, 4)));
/* Deletion function. */
bool secfile_entry_delete(struct section_file *secfile,
const char *path, ...)
......
ENTRY_FLOAT,
ENTRY_STR,
ENTRY_FILEREFERENCE,
ENTRY_LONG_COMMENT,
ENTRY_ILLEGAL
};
    (1-1/1)