]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
server: Convert com_check() to lopsub.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 20 Mar 2016 18:40:50 +0000 (18:40 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 26 Mar 2017 09:02:28 +0000 (11:02 +0200)
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
afs.cmd
m4/lls/server_cmd.suite.m4

diff --git a/afs.c b/afs.c
index 92c58cc8cbe142a4f403b6bd0654c21f8136757e..1084b715354d3532d5a3be038186a04fdd41f1c8 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -18,6 +18,7 @@
 #include <netdb.h>
 #include <lopsub.h>
 
+#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 5a265d6164678d2758ab3d2cdb512d91f9750dee..807e1e6e9e247dae7cdf1e2d3fb9464ab24952b2 100644 (file)
--- 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).
index fdc8ff4f349881ca68b8c42e1800f56779267a3e..b246db48537d1032c413ed0571cc7c813f70482e 100644 (file)
@@ -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[-]