[vlc-commits] cli: pass argument array to command handlers
Rémi Denis-Courmont
git at videolan.org
Sat Oct 17 20:35:55 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct 17 14:51:16 2020 +0300| [0c255b457def0d0b542bfefc282fb48e21c02dfd] | committer: Rémi Denis-Courmont
cli: pass argument array to command handlers
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0c255b457def0d0b542bfefc282fb48e21c02dfd
---
modules/control/cli/cli.c | 12 +++----
modules/control/cli/cli.h | 14 ++++----
modules/control/cli/player.c | 72 ++++++++++++++++++++++++------------------
modules/control/cli/playlist.c | 31 +++++++++---------
4 files changed, 69 insertions(+), 60 deletions(-)
diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index 7e99fb9fff..839b990a77 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -150,11 +150,9 @@ static void Help( intf_thread_t *p_intf)
msg_rc("%s", _("+----[ end of help ]"));
}
-static void Intf(intf_thread_t *intf, char const *psz_cmd,
- vlc_value_t newval)
+static void Intf(intf_thread_t *intf, const char *const *args, size_t count)
{
- VLC_UNUSED(psz_cmd);
- intf_Create(vlc_object_instance(intf), newval.psz_string);
+ intf_Create(vlc_object_instance(intf), count == 1 ? "" : args[1]);
}
static void Quit(intf_thread_t *intf)
@@ -215,7 +213,7 @@ static const struct
static const struct
{
const char *name;
- void (*handler)(intf_thread_t *, const char *, vlc_value_t);
+ void (*handler)(intf_thread_t *, const char *const *, size_t);
} string_cmds[] =
{
{ "intf", Intf },
@@ -278,9 +276,9 @@ static void Process(intf_thread_t *intf, const char *line)
for (size_t i = 0; i < ARRAY_SIZE(string_cmds); i++)
if (strcmp(cmd, string_cmds[i].name) == 0)
{
- vlc_value_t n = { .psz_string = (char *)arg };
+ const char *argv[3] = { cmd, arg, NULL };
- string_cmds[i].handler(intf, cmd, n);
+ string_cmds[i].handler(intf, argv, 1 + (argv[1][0] != '\0'));
return;
}
diff --git a/modules/control/cli/cli.h b/modules/control/cli/cli.h
index c3be10a19b..9b77862abc 100644
--- a/modules/control/cli/cli.h
+++ b/modules/control/cli/cli.h
@@ -59,17 +59,17 @@ void PlayerChapterPrev(intf_thread_t *intf);
void PlayerChapterNext(intf_thread_t *intf);
void PlayerTitlePrev(intf_thread_t *intf);
void PlayerTitleNext(intf_thread_t *intf);
-void Input(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval);
+void Input(intf_thread_t *intf, const char *const *, size_t);
void PlayerItemInfo(intf_thread_t *intf);
void PlayerGetTime(intf_thread_t *intf);
void PlayerGetLength(intf_thread_t *intf);
void PlayerGetTitle(intf_thread_t *intf);
void PlayerVoutSnapshot(intf_thread_t *intf);
-void Volume(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval);
-void VolumeMove(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval);
-void VideoConfig(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval);
-void AudioDevice(intf_thread_t *intf, char const *cmd, vlc_value_t cur);
-void AudioChannel(intf_thread_t *intf, char const *cmd, vlc_value_t cur);
+void Volume(intf_thread_t *intf, const char *const *, size_t);
+void VolumeMove(intf_thread_t *intf, const char *const *, size_t);
+void VideoConfig(intf_thread_t *intf, const char *const *, size_t);
+void AudioDevice(intf_thread_t *intf, const char *const *, size_t);
+void AudioChannel(intf_thread_t *intf, const char *const *, size_t);
void Statistics(intf_thread_t *intf);
void IsPlaying(intf_thread_t *intf);
@@ -84,4 +84,4 @@ void PlaylistClear(intf_thread_t *intf);
void PlaylistSort(intf_thread_t *intf);
void PlaylistList(intf_thread_t *intf);
void PlaylistStatus(intf_thread_t *intf);
-void Playlist(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval);
+void Playlist(intf_thread_t *intf, const char *const *, size_t);
diff --git a/modules/control/cli/player.c b/modules/control/cli/player.c
index 3698f8fb25..6515767440 100644
--- a/modules/control/cli/player.c
+++ b/modules/control/cli/player.c
@@ -221,32 +221,33 @@ void PlayerTitleNext(intf_thread_t *intf)
PlayerDoVoid(intf, vlc_player_SelectNextTitle);
}
-void Input(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
+void Input(intf_thread_t *intf, const char *const *args, size_t n_args)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
+ const char *psz_cmd = args[0];
+ const char *arg = n_args > 1 ? args[1] : "";
vlc_player_Lock(player);
/* Parse commands that only require an input */
if( !strcmp( psz_cmd, "seek" ) )
{
- if( strlen( newval.psz_string ) > 0 &&
- newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
+ if( strlen( arg ) > 0 && arg[strlen( arg ) - 1] == '%' )
{
- float f = atof( newval.psz_string ) / 100.0;
+ float f = atof( arg ) / 100.0;
vlc_player_SetPosition(player, f);
}
else
{
- int t = atoi( newval.psz_string );
+ int t = atoi( arg );
vlc_player_SetTime(player, vlc_tick_from_sec(t));
}
}
else if( !strcmp( psz_cmd, "chapter" ) )
{
- if ( *newval.psz_string )
+ if ( *arg )
{
/* Set. */
- vlc_player_SelectChapterIdx(player, atoi(newval.psz_string));
+ vlc_player_SelectChapterIdx(player, atoi(arg));
}
else
{
@@ -264,10 +265,10 @@ void Input(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
}
else if( !strcmp( psz_cmd, "title" ) )
{
- if ( *newval.psz_string )
+ if ( *arg )
{
/* Set. */
- int idx = atoi(newval.psz_string);
+ int idx = atoi(arg);
if (idx >= 0)
vlc_player_SelectTitleIdx(player, (size_t)idx);
}
@@ -298,9 +299,9 @@ void Input(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
cat = VIDEO_ES;
else
cat = SPU_ES;
- if( newval.psz_string && *newval.psz_string )
+ if (n_args > 1)
{
- int idx = atoi(newval.psz_string);
+ int idx = atoi(arg);
if (idx < 0)
goto out;
size_t track_count = vlc_player_GetTrackCount(player, cat);
@@ -334,10 +335,10 @@ void Input(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
bool b_update = true;
bool b_value = vlc_player_IsRecording(player);
- if( newval.psz_string[0] != '\0' )
+ if (n_args > 1)
{
- if ( ( !strncmp( newval.psz_string, "on", 2 ) && b_value ) ||
- ( !strncmp( newval.psz_string, "off", 3 ) && !b_value ) )
+ if ( ( !strncmp( arg, "on", 2 ) && b_value ) ||
+ ( !strncmp( arg, "off", 3 ) && !b_value ) )
{
b_update = false;
}
@@ -426,15 +427,16 @@ void PlayerVoutSnapshot(intf_thread_t *intf)
PlayerDoVoid(intf, vlc_player_vout_Snapshot);
}
-void Volume(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
+void Volume(intf_thread_t *intf, const char *const *args, size_t count)
{
- VLC_UNUSED(psz_cmd);
+ const char *arg = count > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
+
vlc_player_Lock(player);
- if ( *newval.psz_string )
+ if ( *arg )
{
/* Set. */
- float volume = atol(newval.psz_string) / 100.f;
+ float volume = atol(arg) / 100.f;
vlc_player_aout_SetVolume(player, volume);
}
else
@@ -446,12 +448,14 @@ void Volume(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
vlc_player_Unlock(player);
}
-void VolumeMove(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
+void VolumeMove(intf_thread_t *intf, const char *const *args, size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
+ const char *psz_cmd = args[0];
+ const char *arg = count > 1 ? args[1] : "";
float volume;
- int i_nb_steps = atoi(newval.psz_string);
+ int i_nb_steps = atoi(arg);
if( !strcmp(psz_cmd, "voldown") )
i_nb_steps *= -1;
@@ -461,11 +465,13 @@ void VolumeMove(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
vlc_player_Unlock(player);
}
-void VideoConfig(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
+void VideoConfig(intf_thread_t *intf, const char *const *args, size_t n_args)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
vout_thread_t *p_vout = vlc_player_vout_Hold(player);
const char * psz_variable = NULL;
+ const char *psz_cmd = args[0];
+ const char *arg = n_args > 1 ? args[1] : "";
if( !strcmp( psz_cmd, "vcrop" ) )
psz_variable = "crop";
@@ -477,16 +483,16 @@ void VideoConfig(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
/* This case can't happen */
vlc_assert_unreachable();
- if( newval.psz_string && *newval.psz_string )
+ if (n_args > 1)
{
/* set */
if( !strcmp( psz_variable, "zoom" ) )
{
- float f_float = atof( newval.psz_string );
+ float f_float = atof( arg );
var_SetFloat( p_vout, psz_variable, f_float );
}
else
- var_SetString( p_vout, psz_variable, newval.psz_string );
+ var_SetString( p_vout, psz_variable, arg );
}
else
{
@@ -560,8 +566,10 @@ void VideoConfig(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
vout_Release(p_vout);
}
-void AudioDevice(intf_thread_t *intf, char const *cmd, vlc_value_t cur)
+void AudioDevice(intf_thread_t *intf, const char *const *args, size_t count)
{
+ const char *cmd = args[0];
+ const char *arg = count > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
audio_output_t *aout = vlc_player_aout_Hold(player);
if (aout == NULL)
@@ -572,15 +580,15 @@ void AudioDevice(intf_thread_t *intf, char const *cmd, vlc_value_t cur)
if (n < 0)
goto out;
- bool setdev = cur.psz_string && *cur.psz_string;
+ bool setdev = count > 1;
if (setdev)
- aout_DeviceSet(aout, cur.psz_string);
+ aout_DeviceSet(aout, arg);
if (setdev)
{
for (int i = 0; i < n; ++i)
{
- if (!strcmp(cur.psz_string, ids[i]))
+ if (!strcmp(arg, ids[i]))
vlc_player_osd_Message(player,
_("Audio device: %s"), names[i]);
@@ -615,14 +623,16 @@ out:
aout_Release(aout);
}
-void AudioChannel(intf_thread_t *intf, char const *cmd, vlc_value_t cur)
+void AudioChannel(intf_thread_t *intf, const char *const *args, size_t n_args)
{
+ const char *cmd = args[0];
+ const char *arg = n_args > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
audio_output_t *p_aout = vlc_player_aout_Hold(player);
if ( p_aout == NULL )
return;
- if ( !*cur.psz_string )
+ if ( !*arg )
{
/* Retrieve all registered ***. */
vlc_value_t *val;
@@ -651,7 +661,7 @@ void AudioChannel(intf_thread_t *intf, char const *cmd, vlc_value_t cur)
msg_print(intf, "+----[ end of %s ]", cmd);
}
else
- var_SetInteger( p_aout, "stereo-mode", atoi( cur.psz_string ) );
+ var_SetInteger(p_aout, "stereo-mode", atoi(arg));
out:
aout_Release(p_aout);
}
diff --git a/modules/control/cli/playlist.c b/modules/control/cli/playlist.c
index ea3a23166b..2deb05012b 100644
--- a/modules/control/cli/playlist.c
+++ b/modules/control/cli/playlist.c
@@ -283,9 +283,11 @@ void PlaylistStatus(intf_thread_t *intf)
msg_print(intf, STATUS_CHANGE "( %s state: %u )", stname, stnum);
}
-void Playlist(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
+void Playlist(intf_thread_t *intf, const char *const *args, size_t n_args)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
+ const char *psz_cmd = args[0];
+ const char *arg = n_args > 1 ? args[1] : "";
vlc_playlist_Lock(playlist);
@@ -297,10 +299,10 @@ void Playlist(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
vlc_playlist_GetPlaybackRepeat(playlist);
bool b_value = repeat_mode == VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
- if( strlen( newval.psz_string ) > 0 )
+ if( strlen( arg ) > 0 )
{
- if ( ( !strncmp( newval.psz_string, "on", 2 ) && b_value ) ||
- ( !strncmp( newval.psz_string, "off", 3 ) && !b_value ) )
+ if ( ( !strncmp( arg, "on", 2 ) && b_value ) ||
+ ( !strncmp( arg, "off", 3 ) && !b_value ) )
{
b_update = false;
}
@@ -323,10 +325,10 @@ void Playlist(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
vlc_playlist_GetPlaybackRepeat(playlist);
bool b_value = repeat_mode == VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;
- if( strlen( newval.psz_string ) > 0 )
+ if( strlen( arg ) > 0 )
{
- if ( ( !strncmp( newval.psz_string, "on", 2 ) && b_value ) ||
- ( !strncmp( newval.psz_string, "off", 3 ) && !b_value ) )
+ if ( ( !strncmp( arg, "on", 2 ) && b_value ) ||
+ ( !strncmp( arg, "off", 3 ) && !b_value ) )
{
b_update = false;
}
@@ -349,10 +351,10 @@ void Playlist(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
vlc_playlist_GetPlaybackOrder(playlist);
bool b_value = order_mode == VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM;
- if( strlen( newval.psz_string ) > 0 )
+ if( strlen( arg ) > 0 )
{
- if ( ( !strncmp( newval.psz_string, "on", 2 ) && b_value ) ||
- ( !strncmp( newval.psz_string, "off", 3 ) && !b_value ) )
+ if ( ( !strncmp( arg, "on", 2 ) && b_value ) ||
+ ( !strncmp( arg, "off", 3 ) && !b_value ) )
{
b_update = false;
}
@@ -370,7 +372,7 @@ void Playlist(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
}
else if (!strcmp( psz_cmd, "goto" ) )
{
- long long llindex = atoll(newval.psz_string);
+ long long llindex = atoll(arg);
size_t index = (size_t)llindex;
size_t count = vlc_playlist_Count(playlist);
if (llindex < 0)
@@ -384,14 +386,13 @@ void Playlist(intf_thread_t *intf, char const *psz_cmd, vlc_value_t newval)
count);
}
else if ((!strcmp(psz_cmd, "add") || !strcmp(psz_cmd, "enqueue")) &&
- newval.psz_string && *newval.psz_string)
+ n_args > 1)
{
- input_item_t *p_item = parse_MRL( newval.psz_string );
+ input_item_t *p_item = parse_MRL( arg );
if( p_item )
{
- msg_print(intf, "Trying to %s %s to playlist.", psz_cmd,
- newval.psz_string);
+ msg_print(intf, "Trying to %s %s to playlist.", psz_cmd, arg);
size_t count = vlc_playlist_Count(playlist);
int ret = vlc_playlist_InsertOne(playlist, count, p_item);
More information about the vlc-commits
mailing list