-static int parse_title (struct lexer *, enum text_item_type);
-static void set_title (const char *title, enum text_item_type);
+static int
+parse_title (struct lexer *lexer, void (*set_title) (const char *))
+{
+ if (lex_token (lexer) == T_STRING)
+ {
+ set_title (lex_tokcstr (lexer));
+ lex_get (lexer);
+ }
+ else if (lex_token (lexer) == T_ENDCMD)
+ {
+ /* This would be a bad special case below because n-1 would be
+ SIZE_MAX. */
+ set_title ("");
+ }
+ else
+ {
+ /* Count the tokens in the title. */
+ size_t n = 0;
+ while (lex_next (lexer, n)->type != T_ENDCMD)
+ n++;
+
+ /* Get the raw representation of all the tokens, including any space
+ between them, and use it as the title. */
+ char *title = lex_next_representation (lexer, 0, n - 1);
+ set_title (title);
+ free (title);
+
+ /* Skip past the tokens. */
+ for (size_t i = 0; i < n; i++)
+ lex_get (lexer);
+ }
+ return CMD_SUCCESS;
+}