[Freeciv-Dev] Re: (PR#13302) Show changed
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13302 >
Am Samstag, 25. Juni 2005 14:18 schrieb Thomas Müller:
> Am Samstag, 25. Juni 2005 09:43 schrieb Jason Short:
> > <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13302 >
> >
> > More technically, the main issue is that SSET_CHANGED has been added as
> > a new "level" but outside of the enumeration this new "classification"
> > isn't treated like the other levels. For instance it's not in the
> > sset_level_names[] array.
>
> When i first looked at the code, i didnt quite understand it, so i created
> a working ugly hack. After you mentioned sset_level_names i looked for it,
> and i guess i now understand how this code is ment to work ;)
>
> I created another patch (
> show_changed_one.diff stays the same as in the last patch,
> show_changed_two_V2.diff replaces the old
> show_changed_two.diffshow_changed_three.diff is new, since i have to edit
> settings.c too now.
> )
>
> This time, i used the SSET-levels and code looks at least cleaner now (now
> strcmps anymore).
>
> I tested them again, seem to work fine, BUT: autocompletion for commands
> doesnt work for me, neither before nor after the patch, neither on 2.0.2 or
> CVS.
>
> /show situ or /show ra gives unknown command
> /show al gives no settings at all, but no error
> so /show chang does give an error, like all the others too. When you look
> at the code, its obvious why, maybe i can fix that later, once this patch
> is done.
>
> Thomas
Forgetting patches is a really bad habbit.
--- orig.settings.h 2005-06-21 00:35:40.000000000 +0200
+++ settings.h 2005-06-21 00:35:57.000000000 +0200
@@ -68,7 +68,8 @@
SSET_ALL,
SSET_VITAL,
SSET_SITUATIONAL,
- SSET_RARE
+ SSET_RARE,
+ SSET_CHANGED
};
extern const char *sset_level_names[];
--- orig.settings.c 2005-06-25 10:04:30.000000000 +0200
+++ settings.c 2005-06-25 10:08:14.000000000 +0200
@@ -41,7 +41,8 @@
N_("All"),
N_("Vital"),
N_("Situational"),
- N_("Rare")};
+ N_("Rare"),
+ N_("Changed")};
const int OLEVELS_NUM = ARRAY_SIZE(sset_level_names);
--- orig.stdinhand.c 2005-06-20 23:46:46.000000000 +0200
+++ stdinhand.c 2005-06-25 14:10:35.000000000 +0200
@@ -1442,7 +1442,7 @@
{
enum sset_level i;
- for (i = SSET_ALL; i <= SSET_RARE; i++) {
+ for (i = SSET_ALL; i <= SSET_CHANGED; i++) {
if (0 == mystrcasecmp(name, sset_level_names[i])) {
return i;
}
@@ -1909,6 +1909,8 @@
return FALSE;
}
}
+
+
if (cmd == -1) {
cmd_reply(CMD_SHOW, caller, C_FAIL, _("Unknown option '%s'."), command);
return FALSE;
@@ -1929,11 +1931,15 @@
#define OPTION_NAME_SPACE 13
/* under 16, so it fits into 80 cols more easily - rp */
+
cmd_reply_show(horiz_line);
switch(level) {
case SSET_NONE:
break;
+ case SSET_CHANGED:
+ cmd_reply_show(_("All options with non-default values"));
+ break;
case SSET_ALL:
cmd_reply_show(_("All options"));
break;
@@ -1961,25 +1967,31 @@
buf[0] = '\0';
for (i = 0; settings[i].name; i++) {
- if (may_view_option(caller, i)
- && (cmd == -1 || cmd == -3 || cmd == i
- || (cmd == -2
- && mystrncasecmp(settings[i].name, command, clen) == 0))) {
+
+ if (may_view_option(caller, i)
+ && (cmd == -1 || cmd == -3 || level == SSET_CHANGED || cmd == i || (cmd
== -2 && mystrncasecmp(settings[i].name, command, clen) == 0))) {
/* in the cmd==i case, this loop is inefficient. never mind - rp */
struct settings_s *op = &settings[i];
int len = 0;
- if (level == SSET_ALL || op->level == level || cmd >= 0) {
- switch (op->type) {
- case SSET_BOOL:
+
+ if ((level == SSET_ALL || op->level == level || cmd >= 0 || level ==
SSET_CHANGED)) {
+int is_changed = 0;
+ switch (op->type) {
+ case SSET_BOOL:
+ if (*op->bool_value != op->bool_default_value) {
+ is_changed = 1; }
len = my_snprintf(buf, sizeof(buf),
"%-*s %c%c%-5d (0,1)", OPTION_NAME_SPACE, op->name,
may_set_option_now(caller, i) ? '+' : ' ',
((*op->bool_value == op->bool_default_value) ?
'=' : ' '), (*op->bool_value) ? 1 : 0);
+
break;
- case SSET_INT:
+ case SSET_INT:
+ if (*op->int_value != op->int_default_value) {
+ is_changed = 1; }
len = my_snprintf(buf, sizeof(buf),
"%-*s %c%c%-5d (%d,%d)", OPTION_NAME_SPACE,
op->name, may_set_option_now(caller,
@@ -1987,16 +1999,17 @@
((*op->int_value == op->int_default_value) ?
'=' : ' '),
*op->int_value, op->int_min_value,
- op->int_max_value);
+ op->int_max_value);
break;
- case SSET_STRING:
+ case SSET_STRING: if (strcmp(op->string_value,
op->string_default_value) != 0) {
+ is_changed = 1; }
len = my_snprintf(buf, sizeof(buf),
"%-*s %c%c\"%s\"", OPTION_NAME_SPACE, op->name,
may_set_option_now(caller, i) ? '+' : ' ',
((strcmp(op->string_value,
op->string_default_value) == 0) ?
- '=' : ' '), op->string_value);
+ '=' : ' '), op->string_value);
break;
}
if (len == -1) {
@@ -2009,7 +2022,7 @@
sz_strlcat(buf, " ");
}
sz_strlcat(buf, _(op->short_help));
- cmd_reply_show(buf);
+ if ((is_changed == 1)|| (level != SSET_CHANGED)) {cmd_reply_show(buf);}
}
}
}
|
|