<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40202 >
At the start of handle_stdin_input, parse the inputline into a vector of dynamically allocated strings (or I suppose there could be constants MAX_LEN_ARGUMENT and MAX_NUM_ARGUMENTS for auto arrays...). The first element of the vector gives the command name; in case of a comment or empty line, the vector is empty. If the command name start with "/", it should be removed. All elements of the vector are parsed assuming that they may be quoted, and internal quotes must be escaped. Unquoted arguments are separated by whitespace; quoted arguments need not be. Examples (quote character is "'"): Inputline: "# blah blah" Vector: (empty) Inputline: "/" Vector: [0]="" Inputline: " /start " Vector: [0]="start" Inputline: "set timeo 56 # a comment" Vector: [0]="set" [1]="timeo" [2]="56" Inputline: "metam 'some message'" Vector: [0]="metam" [1]="some message" Inputline: "/wall 'internal \'quotes\''" Vector: [0]="wall" [1]="internal 'quotes'" Inputline: "/take 'foo' 'bar baz'" Vector: [0]="take" [1]="foo" [2]="bar baz" Inputline: "'/quit'" Vector: [0]="quit" Inputline: "/'debug'" Vector: [0]="" [1]="debug" Inputline: "''a'b'''c''" Vector: [0]="" [1]="a" [2]="b" [3]="" [4]="c" [5]="" Inputline: "'" Vector: NULL (i.e. parse/syntax error: unterminated quote) So a possible function signature could be: string_vector *parse_inputline(const char *inputline, char *errbuf, int errbuflen); where errbuf could be used to give a helpful description and explanation of any error encountered. Now when the full command name is looked up, the first argument is replaced by it. Similarly, the *_command functions should replace partial arguments with the full strings. So for example [0]="se" [1]="timeo" [2]="120" becomes [0]="set" [1]="timeout" [2]="120" so that when the command line is echoed back or presented in a vote, it is clear what is happening. Thus commands would need to changed to something like bool foo_command(string_vector *args, bool check); though perhaps some care would need to be taken not to re- replace arguments needlessly the second time around (i.e. when check is FALSE)... ---------------------------------------------------------------------- ちょっと面倒くさい事です。しかし、誰もしなければいけません _______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev