From 2a03f7eebcd08222f771611679d2914e8b48e935 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 20 Mar 2016 18:40:50 +0000 Subject: [PATCH] server: Convert com_check() to lopsub. Gets rid of enum com_check_flags and the open-coded option parser of com_check(). Also streamlines the help text of the options a bit. --- afs.c | 67 ++++++++------------------------------ afs.cmd | 26 --------------- m4/lls/server_cmd.suite.m4 | 33 +++++++++++++++++++ 3 files changed, 47 insertions(+), 79 deletions(-) diff --git a/afs.c b/afs.c index 92c58cc8..1084b715 100644 --- a/afs.c +++ b/afs.c @@ -18,6 +18,7 @@ #include #include +#include "server_cmd.lsg.h" #include "server.cmdline.h" #include "para.h" #include "error.h" @@ -1148,76 +1149,35 @@ static int com_init(struct command_context *cc, struct lls_parse_result *lpr) } EXPORT_SERVER_CMD_HANDLER(init); -/** - * Flags for the check command. - * - * \sa com_check(). - */ -enum com_check_flags { - /** Check the audio file table. */ - CHECK_AFT = 1, - /** Check the mood table. */ - CHECK_MOODS = 2, - /** Check the playlist table. */ - CHECK_PLAYLISTS = 4, - /** Check the attribute table against the audio file table. */ - CHECK_ATTS = 8 -}; - -int com_check(struct command_context *cc) +static int com_check(struct command_context *cc, struct lls_parse_result *lpr) { - unsigned flags = 0; - int i, ret; + const struct lls_opt_result *r_a = SERVER_CMD_OPT_RESULT(CHECK, AFT, lpr); + const struct lls_opt_result *r_A = SERVER_CMD_OPT_RESULT(CHECK, ATTRIBUTE, lpr); + const struct lls_opt_result *r_m = SERVER_CMD_OPT_RESULT(CHECK, MOOD, lpr); + const struct lls_opt_result *r_p = SERVER_CMD_OPT_RESULT(CHECK, PLAYLIST, lpr); + bool noopt = !lls_opt_given(r_a) && !lls_opt_given(r_A) + && !lls_opt_given(r_m) && !lls_opt_given(r_p); + int ret; - for (i = 1; i < cc->argc; i++) { - const char *arg = cc->argv[i]; - if (arg[0] != '-') - break; - if (!strcmp(arg, "--")) { - i++; - break; - } - if (!strcmp(arg, "-a")) { - flags |= CHECK_AFT; - continue; - } - if (!strcmp(arg, "-A")) { - flags |= CHECK_ATTS; - continue; - } - if (!strcmp(arg, "-p")) { - flags |= CHECK_PLAYLISTS; - continue; - } - if (!strcmp(arg, "-m")) { - flags |= CHECK_MOODS; - continue; - } - return -E_AFS_SYNTAX; - } - if (i < cc->argc) - return -E_AFS_SYNTAX; - if (!flags) - flags = ~0U; - if (flags & CHECK_AFT) { + if (noopt || lls_opt_given(r_a)) { ret = send_callback_request(aft_check_callback, NULL, afs_cb_result_handler, cc); if (ret < 0) return ret; } - if (flags & CHECK_ATTS) { + if (noopt || lls_opt_given(r_A)) { ret = send_callback_request(attribute_check_callback, NULL, afs_cb_result_handler, cc); if (ret < 0) return ret; } - if (flags & CHECK_PLAYLISTS) { + if (noopt || lls_opt_given(r_p)) { ret = send_callback_request(playlist_check_callback, NULL, afs_cb_result_handler, cc); if (ret < 0) return ret; } - if (flags & CHECK_MOODS) { + if (noopt || lls_opt_given(r_m)) { ret = send_callback_request(mood_check_callback, NULL, afs_cb_result_handler, cc); if (ret < 0) @@ -1225,6 +1185,7 @@ int com_check(struct command_context *cc) } return 1; } +EXPORT_SERVER_CMD_HANDLER(check); /** * The afs event dispatcher. diff --git a/afs.cmd b/afs.cmd index 5a265d61..807e1e6e 100644 --- a/afs.cmd +++ b/afs.cmd @@ -59,32 +59,6 @@ U: addatt attribute1... H: This adds new attributes to the attribute table. At most 64 H: attributes may be defined. --- -N: check -P: AFS_READ -D: Run integrity checks against osl tables. -U: check [-a] [-A] [-m] [-p] -H: Check the audio file table, the attribute table, the mood definitions -H: and all defined playlists. Report any inconsistencies. -H: -H: Options: -H: -H: -a Run audio file table checks. Checks for entries in the audio file -H: table which are not present in the file system. Moreover, it checks -H: whether the lyrics id and all entries in the audio file table are -H: valid. -H: -H: -A Check the attribute table against the afs attribute bitmask of -H: each audio file in the audio file table. Reports audio files -H: whose attribute bitmask is invalid, i.e., has a bit set which -H: does not correspond to any attribute of the attribute table. -H: -H: -m Run syntax checks on all defined moods in the mood table. -H: -H: -p Check all playlists for lines that correspond to files not contained -H: in the audio file table. -H: -H: If called without arguments, all checks are run. ---- N: rmatt P: AFS_READ | AFS_WRITE D: Remove attribute(s). diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index fdc8ff4f..b246db48 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -52,6 +52,39 @@ aux_info_prefix = Permissions: Print what is being done. [/help] +[subcommand check] + purpose = run integrity checks on database tables + aux_info = AFS_READ + [description] + If no options are given, all checks are run. + [/description] + [option aft] + short_opt = a + summary = run audio file table checks + [help] + Report stale paths and invalid image and lyrics ids of the audio + file table. + [/help] + [option attribute] + short_opt = A + summary = check for invalid attributes + [help] + Report audio files whose attribute bitmask is invalid, i.e., has a bit + set which does not correspond to any attribute of the attribute table. + [/help] + [option mood] + short_opt = m + summary = check for invalid mood definitions + [help] + Run syntax checks on all moods of the mood table. + [/help] + [option playlist] + short_opt = p + summary = find invalid paths in playlists + [help] + Check all playlists for paths not contained in the audio file table. + [/help] + [subcommand ff] purpose = jump N seconds forward or backward synopsis = n[-] -- 2.39.2