stamen

Static Menu Generator
git clone git://git.dimitrijedobrota.com/stamen.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit 223faf962edad1fc475af8a65afc8319d683bc0e
parent cd12b2fea38be76fe6bd2c607598c785d979c25e
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Fri, 14 Jun 2024 11:27:37 +0200

Add support for custom free function header

Diffstat:
M demo/main.cpp | + -
M src/generate.cpp | ++++++++++++++ -------------

2 files changed, 15 insertions(+), 14 deletions(-)


diff --git a/ demo/main.cpp b/ demo/main.cpp

@@ -1,5 +1,5 @@ #include "demo_menu.hpp"
#include "stamen.h"
#include "stamen.hpp"
#include <iostream>

diff --git a/ src/generate.cpp b/ src/generate.cpp

@@ -11,26 +11,18 @@ struct arguments_t { std::string config; std::string display;
std::string header = "shared.h";
bool cpp = false; bool user = false; } opt; void generateIncludeHeaders(std::ostream &os) {
if (opt.user) {
if (opt.cpp) os << "#include \"stamen.hpp\"\n\n";
else os << "#include \"stamen.h\"\n\n";
} else {
if (opt.cpp) os << "#include <stamen/stamen.hpp>\n\n";
else os << "#include <stamen/stamen.h>\n\n";
}
} void generateInclude(std::ostream &os) { os << "#ifndef STAMEN_MENU_H\n"; os << "#define STAMEN_MENU_H\n\n";
generateIncludeHeaders(os);
for (const auto &[code, menu] : stamen::menu::menu_lookup) { os << std::format("int {}(int);\n", menu.getCode()); }

@@ -39,8 +31,14 @@ void generateInclude(std::ostream &os) { } void generateSource(std::ostream &os) {
os << "#include \"shared.h\"\n";
generateIncludeHeaders(os);
os << std::format("#include \"{}\"\n", opt.header);
if (opt.user) {
if (opt.cpp) os << "#include \"stamen.hpp\"\n\n";
else os << "#include \"stamen.h\"\n\n";
} else {
if (opt.cpp) os << "#include <stamen/stamen.hpp>\n\n";
else os << "#include <stamen/stamen.h>\n\n";
}
os << std::format("extern int {}(const char *title, ", opt.display); if (opt.cpp) os << "const stamen::item_t itemv[], int size);\n\n";

@@ -68,13 +66,15 @@ void generateSource(std::ostream &os) { int parse_opt(int key, const char *arg, args::Parser *parser) { auto arguments = (arguments_t *)parser->input(); switch (key) {
case 'u': arguments->user = true; break;
case 'd': arguments->display = arg; break;
case 'h': arguments->header = arg; break;
case 'u': arguments->user = true; break;
case 666: arguments->cpp = false; break; case 777: arguments->cpp = true; break; case args::ARG: if (!arguments->config.empty()) {
args::failure(parser, 1, 0, "Too many arguments");
args::failure(parser, 0, 0, "Too many arguments");
args::help(parser, stderr, args::STD_USAGE);
} arguments->config = arg; break;

@@ -98,6 +98,7 @@ static const args::option_t options[]{ {0, 0, 0, 0, "Output settings", 2}, {"display", 'd', "FUNC", 0, "Set display function to be called"}, {"user", 'u', 0, 0, "Include user stamen headers"},
{"header", 'h', "FUNC", 0, "Header with free functions, default: shared.h"},
{0, 0, 0, 0, "Informational Options", -1}, {0}, };