main: Give error message on invalid integer or float argument
This replaces the calls atoi/atof in main.cpp with a function that detects and prints an error when the value being parsed is invalid.
This change has the typical costs and benefits of a tightened specification: new users may get quick feedback that commands like gamescope --sharpness 1.5 aren't meaningful, but this change could (until someone fixes them) break badly written scripts which invoke gamescope with invalid arguments that happened to work.
We already haveParse<float> and Parse<int> that does those functions but better.
We already have
Parse<float>andParse<int>that does those functions but better.
Good point, better to stick to one set of string parsing routines (and avoid C's locale complications). I've updated the PR to use them, and have slightly adjusted the code style to match recent updates to the code.
(Note: like atoi/atof, gamescope::Parse<T> currently parses the prefix of the input string, and does not check that the entire string is consumed; it thus parses "1x2" as "1" instead of rejecting the value. Since Parse is used in many places, changing it to check that result.ptr == chars.end() would be risky---I think it breaks GetKernelVersion(), and it's used by too many ConVar's for me to review them all today---so I have not changed the way Parse works.)