-/* Parse the command name and return a pointer to the corresponding
- struct command if successful.
- If not successful, return a null pointer. */
+static bool
+parse_command_word (struct lexer *lexer, struct string *s, int n)
+{
+ bool need_space = ds_last (s) != EOF && ds_last (s) != '-';
+
+ switch (lex_next_token (lexer, n))
+ {
+ case T_DASH:
+ ds_put_byte (s, '-');
+ return true;
+
+ case T_ID:
+ if (need_space)
+ ds_put_byte (s, ' ');
+ ds_put_cstr (s, lex_next_tokcstr (lexer, n));
+ return true;
+
+ case T_POS_NUM:
+ if (lex_next_is_integer (lexer, n))
+ {
+ int integer = lex_next_integer (lexer, n);
+ if (integer >= 0)
+ {
+ if (need_space)
+ ds_put_byte (s, ' ');
+ ds_put_format (s, "%ld", lex_next_integer (lexer, n));
+ return true;
+ }
+ }
+ return false;
+
+ default:
+ return false;
+ }
+}
+
+/* Parses the command name. On success returns a pointer to the corresponding
+ struct command and stores the number of tokens in the command name into
+ *N_TOKENS. On failure, returns a null pointer and stores the number of
+ tokens required to determine that no command name was present into
+ *N_TOKENS. */