Skip to content

Commit 3a52512

Browse files
committed
server/deadbeef: fancy format license text
1 parent 3e4026f commit 3a52512

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

cpp/server/deadbeef/plugin.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#define CONF_AUTH_USER MSRV_PROJECT_ID ".auth_user"
1111
#define CONF_AUTH_PASSWORD MSRV_PROJECT_ID ".auth_password"
1212

13-
namespace msrv {
14-
namespace player_deadbeef {
13+
namespace msrv::player_deadbeef {
1514

1615
DB_misc_t PluginWrapper::definition_;
1716
Plugin* PluginWrapper::instance_;
1817

18+
char PluginWrapper::licenseText_[] = MSRV_LICENSE_TEXT;
19+
1920
const char PluginWrapper::configDialog_[] =
2021
"property \"Network port\" entry " CONF_PORT " " MSRV_STRINGIFY(MSRV_DEFAULT_PORT) ";"
2122
"property \"Allow remote connections\" checkbox " CONF_ALLOW_REMOTE " 1;"
@@ -123,6 +124,8 @@ void PluginWrapper::initDef()
123124
if (p.api_vmajor)
124125
return;
125126

127+
formatText(licenseText_, 60);
128+
126129
p.api_vmajor = 1;
127130
p.api_vminor = DDB_API_LEVEL;
128131
p.version_major = MSRV_VERSION_MAJOR;
@@ -131,7 +134,7 @@ void PluginWrapper::initDef()
131134
p.id = MSRV_PROJECT_ID;
132135
p.name = MSRV_PROJECT_NAME;
133136
p.descr = MSRV_PROJECT_DESC "\n\n" MSRV_VERSION_STRING_DETAILED;
134-
p.copyright = MSRV_LICENSE_TEXT;
137+
p.copyright = licenseText_;
135138
p.website = MSRV_PROJECT_URL;
136139
p.start = start;
137140
p.stop = stop;
@@ -191,4 +194,4 @@ extern "C" DB_plugin_t* MSRV_DEADBEEF_ENTRY(DB_functions_t* api)
191194
return PluginWrapper::load(api);
192195
}
193196

194-
}}
197+
}

cpp/server/deadbeef/plugin.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class PluginWrapper
5757
static DB_misc_t definition_;
5858
static Plugin* instance_;
5959
static const char configDialog_[];
60+
static char licenseText_[];
6061

6162
MSRV_NO_COPY_AND_ASSIGN(PluginWrapper);
6263
};

cpp/server/string_utils.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,39 @@ std::string formatString(const char* fmt, ...)
8787
return std::string(buf);
8888
}
8989

90+
void formatText(char* data, size_t maxWidth)
91+
{
92+
size_t width = 0;
93+
char* breakAt = nullptr;
94+
95+
while (*data != '\0')
96+
{
97+
if (*data == '\n')
98+
{
99+
breakAt = nullptr;
100+
width = 0;
101+
data++;
102+
continue;
103+
}
104+
105+
if (*data == ' ')
106+
{
107+
breakAt = data;
108+
}
109+
110+
width++;
111+
112+
if (width <= maxWidth || breakAt == nullptr)
113+
{
114+
data++;
115+
continue;
116+
}
117+
118+
*breakAt = '\n';
119+
data = breakAt + 1;
120+
breakAt = nullptr;
121+
width = 0;
122+
}
123+
}
124+
90125
}

cpp/server/string_utils.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ std::string formatString(const char* fmt, ...) MSRV_FORMAT_FUNC(1, 2);
4343
StringView trim(StringView str, char ch);
4444
StringView trimWhitespace(StringView str);
4545

46+
void formatText(char* data, size_t maxWidth);
47+
4648
}

0 commit comments

Comments
 (0)