Skip to content

Commit 5696ee9

Browse files
committed
Move duplicate code to function
1 parent 8f56334 commit 5696ee9

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/main.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,20 @@ void request_next_frame()
678678
zwlr_screencopy_frame_v1_add_listener(frame, &frame_listener, NULL);
679679
}
680680

681+
static void parse_codec_opts(std::map<std::string, std::string>& options, const std::string param)
682+
{
683+
size_t pos;
684+
pos = param.find("=");
685+
if (pos != std::string::npos && pos != param.length() -1)
686+
{
687+
auto optname = param.substr(0, pos);
688+
auto optvalue = param.substr(pos + 1, param.length() - pos - 1);
689+
options.insert(std::pair<std::string, std::string>(optname, optvalue));
690+
} else
691+
{
692+
std::cerr << "Invalid codec option " + param << std::endl;
693+
}
694+
}
681695

682696
int main(int argc, char *argv[])
683697
{
@@ -802,17 +816,7 @@ int main(int argc, char *argv[])
802816
break;
803817

804818
case 'p':
805-
param = optarg;
806-
pos = param.find("=");
807-
if (pos != std::string::npos && pos != param.length() - 1)
808-
{
809-
auto optname = param.substr(0, pos);
810-
auto optvalue = param.substr(pos + 1, param.length() - pos - 1);
811-
params.codec_options[optname] = optvalue;
812-
} else
813-
{
814-
printf("Invalid codec option %s\n", optarg);
815-
}
819+
parse_codec_opts(params.codec_options, optarg);
816820
break;
817821

818822
case 'v':
@@ -824,17 +828,7 @@ int main(int argc, char *argv[])
824828
break;
825829

826830
case 'P':
827-
param = optarg;
828-
pos = param.find("=");
829-
if (pos != std::string::npos && pos != param.length() - 1)
830-
{
831-
auto optname = param.substr(0, pos);
832-
auto optvalue = param.substr(pos + 1, param.length() - pos - 1);
833-
params.audio_codec_options[optname] = optvalue;
834-
} else
835-
{
836-
printf("Invalid codec option %s\n", optarg);
837-
}
831+
parse_codec_opts(params.audio_codec_options, optarg);
838832
break;
839833

840834
default:

0 commit comments

Comments
 (0)