Adding check-argument code breaks default -M value

Adding check-argument code breaks default -M value

Return to topic list

Wed Aug 14 04:55:08 2024   by   Mizuki
Since we have added the reportError input validation code - the -M option must now be accompanied with a value. The default of 0.1 when not specifying a value no longer work.

We can either relax the -M check input option to just matchMap = 1, or document in the manual that relying on default value no longer work and we have to manually specify it now.

This happens with values that rely on default values and which *also* must be specified to enable a feature - so even though -w, -h, -v, -V etc is affected also, from an user standpoint you would never specify those options with no value because they are "standard" features that are applied even if we don't explicitly set it.
 
Wed Aug 14 04:59:13 2024   by   Mizuki
However relaxing the -M switch to before input validation makes the program again segfault when specifying -M at the end...
 
Wed Aug 14 05:15:15 2024   by   Mizuki
This is how I would solve it: by adding a check to see if reportError failed on -M, then printf a line suggesting the solution.

void reportError(char c) {
  fprintf(stderr,"Missing or bad argument to option -%c\n",c);
  if (c == 'M') {
    fprintf(stderr, "Tip: Pass '-M 0.1' to use the default value.\n");
  }
  printerror();
}
 
Wed Aug 14 05:15:15 2024   by   Mizuki
This is how I would solve it: by adding a check to see if reportError failed on -M, then printf a line suggesting the solution.

void reportError(char c) {
  fprintf(stderr,"Missing or bad argument to option -%c\n",c);
  if (c == 'M') {
    fprintf(stderr, "Tip: Pass '-M 0.1' to use the default value.\n");
  }
  printerror();
}
 
Wed Aug 14 17:19:26 2024   by   Torben
I found another solution: If -M is last in the input or the following string is not a number, the default is used.
 
Thu Aug 15 12:34:17 2024   by   Mizuki
Also, since we now have input validation, is char filename[256] = "planet-map" and char biocolorsname[256] = "default.bio" redundant? They are defaults that will never be read because you now need to specify a filename explicitly.
 
Thu Aug 15 13:22:30 2024   by   Torben
They are probably redundant, yes.  I will remove this later.
 

Return to topic list



New message:
Topic:
Posted by:

Type the values of the dice shown below:

Return to topic list