Skip to content

Commit 7868344

Browse files
committed
vdisp/gl: parse_fmt - return bool
returning the pointer was a bit tricky - very slightly more correct but needlessly more complicated
1 parent 14b4185 commit 7868344

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/video_display/gl.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,15 @@ list_hints()
732732
"Example usage: " TBOLD("-d gl:init_hint=platform=x11") "\n\n");
733733
}
734734

735-
static void *display_gl_parse_fmt(struct state_gl *s, char *ptr) {
735+
static bool
736+
display_gl_parse_fmt(struct state_gl *s, char *ptr)
737+
{
736738
char *tok, *save_ptr = NULL;
737739

738740
while((tok = strtok_r(ptr, ":", &save_ptr)) != NULL) {
739741
if (strcmp(tok, "help") == 0 || strcmp(tok, "fullhelp") == 0) {
740742
gl_show_help(strcmp(tok, "fullhelp") == 0);
741-
return INIT_NOERR;
743+
return false;
742744
}
743745
if (!strcmp(tok, "d") || !strcmp(tok, "dforce")) {
744746
s->deinterlace = !strcmp(tok, "d") ? state_gl::deint::on : state_gl::deint::force;
@@ -784,7 +786,7 @@ static void *display_gl_parse_fmt(struct state_gl *s, char *ptr) {
784786
}
785787
#else
786788
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Syphon/Spout support not compiled in.\n");
787-
return nullptr;
789+
return false;
788790
#endif
789791
} else if (strstr(tok, "gamma=") == tok) {
790792
s->gamma = stof(strchr(tok, '=') + 1);
@@ -798,7 +800,7 @@ static void *display_gl_parse_fmt(struct state_gl *s, char *ptr) {
798800
} else if (strstr(tok, "size=") == tok ||
799801
strstr(tok, "fixed_size=") == tok) {
800802
if (!set_size(s, tok)) {
801-
return nullptr;
803+
return false;
802804
}
803805
} else if (strcmp(tok, "fixed_size") == 0) {
804806
s->fixed_size = true;
@@ -810,15 +812,15 @@ static void *display_gl_parse_fmt(struct state_gl *s, char *ptr) {
810812
parse_hints(s, false, strchr(tok, '=') + 1);
811813
} else if (strcmp(tok, "list_hints") == 0) {
812814
list_hints();
813-
return nullptr;
815+
return false;
814816
} else {
815817
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unknown option: %s\n", tok);
816-
return nullptr;
818+
return false;
817819
}
818820
ptr = NULL;
819821
}
820822

821-
return s;
823+
return true;
822824
}
823825

824826
static void * display_gl_init(struct module *parent, const char *fmt, unsigned int flags) {
@@ -833,16 +835,16 @@ static void * display_gl_init(struct module *parent, const char *fmt, unsigned i
833835

834836
if (fmt != NULL) {
835837
char *tmp = strdup(fmt);
836-
void *ret = nullptr;
838+
bool ret = false;
837839
try {
838840
ret = display_gl_parse_fmt(s, tmp);
839841
} catch (std::invalid_argument &e) {
840842
LOG(LOG_LEVEL_ERROR) << MOD_NAME << "Invalid numeric value for an option!\n";
841843
}
842844
free(tmp);
843-
if (ret != s) { // ret is either nullptr or INIT_NOERR (help requested)
845+
if (!ret) {
844846
delete s;
845-
return ret;
847+
return strstr(fmt, "help") == nullptr ? nullptr : INIT_NOERR;
846848
}
847849
}
848850

@@ -1302,7 +1304,6 @@ static void gl_process_frames(struct state_gl *s)
13021304
free_message(msg, r);
13031305
}
13041306

1305-
13061307
if (s->show_cursor == state_gl::SC_AUTOHIDE) {
13071308
if (s->cursor_shown_from != steady_clock::time_point()) {
13081309
const auto now = steady_clock::now();

0 commit comments

Comments
 (0)