On server, channel dprint through the readline-device. Also some refactors and quality improvements.

This commit is contained in:
2026-01-09 14:28:58 -05:00
parent 1087d18a2e
commit 7fa3f39d72
15 changed files with 258 additions and 253 deletions

View File

@@ -4,6 +4,7 @@
#include "slash-parser.hpp"
#endif
#include <charconv>
#include <sstream>
@@ -61,16 +62,18 @@ bool SlashCommandParser::Parse(std::string_view Command, std::string_view ArgTyp
args_.clear();
for (int i = 0; i < int(ArgTypes.size()); i++)
{
if (cursor_ == linelen_)
{
std::ostringstream oss;
oss << "Not enough arguments for " << Command << " (need " << ArgTypes.size() << ")";
error_ = oss.str();
return false;
}
switch(ArgTypes[i])
{
case 's':
{
std::string word = read_word();
if (word.empty())
{
error_ = "Expected string arg";
return false;
}
args_.emplace_back(word);
break;
}
@@ -82,8 +85,11 @@ bool SlashCommandParser::Parse(std::string_view Command, std::string_view ArgTyp
if ((p < last) && (*p == '+')) p++;
int64_t result;
auto r = std::from_chars(p, last, result, 10);
if ((r.ec != std::errc()) || (r.ptr != last)) {
error_ = "Expected int arg";
if ((r.ec != std::errc()) || (r.ptr != last))
{
std::ostringstream oss;
oss << Command << " expects arg " << i << " to be an int, not '" << word << "'";
error_ = oss.str();
return false;
}
args_.emplace_back(result);
@@ -91,15 +97,26 @@ bool SlashCommandParser::Parse(std::string_view Command, std::string_view ArgTyp
}
case 'd':
{
error_ = "Double args not implemented yet.";
std::string word = read_word();
const char *p = word.c_str();
const char *last = p + word.size();
double result;
auto r = std::from_chars(p, last, result);
if ((r.ec != std::errc()) || (r.ptr != last))
{
std::ostringstream oss;
oss << Command << " expects arg " << i << " to be a double, not '" << word << "'";
error_ = oss.str();
return false;
}
args_.emplace_back(result);
break;
}
default:
{
error_ = "Invalid argtypes ";
error_ += ArgTypes;
error_ += " parsing ";
error_ += Command;
std::ostringstream oss;
oss << "Invalid ArgTypes parameter (" << ArgTypes << ") to Parse routine for " << Command;
error_ = oss.str();
return false;
}
}