]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Introduce template commands for command_util.sh.
authorAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 19:50:57 +0000 (21:50 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 8 Sep 2007 19:50:57 +0000 (21:50 +0200)
And use them to produce afs_command_list.[ch] which also contains all
blob commands without duplicating all the common information in the
new afs.cmd file.

Change para_server's help command to display the new commands. These
are not yet working because the callback code is not yet functional.

afs.c
afs.h
aft.c
command.c
command_util.sh
configure.ac

diff --git a/afs.c b/afs.c
index b5cf9f792e955d8c7df53483a3aeb7ec6970d1a1..0a3d1038560f8591fddc8072d59dd3ef3df7fd78 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -799,7 +799,7 @@ static int create_all_tables(void)
 }
 
 /* TODO load tables after init */
-static int com_init(__a_unused int fd, int argc, const char **argv)
+int com_init(__a_unused int fd, int argc, const char **argv)
 {
        int i, j, ret;
        if (argc == 1)
@@ -824,6 +824,7 @@ static int com_init(__a_unused int fd, int argc, const char **argv)
        return 1;
 }
 
+#if 0
 /** Describes a command of para_server. */
 struct command {
        /** The name of the command. */
@@ -954,7 +955,6 @@ static struct command afs_cmds[] = {
 }
 };
 
-#if 0
 static void call_callback(void)
 {
        struct osl_object query, result = {.data = NULL};
diff --git a/afs.h b/afs.h
index 0ba203a6944217ba50f9e811f42a93722f7062d5..aa94ac7282a27755cf6b43bd4773443f5a511a53 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -126,10 +126,6 @@ int attribute_init(struct table_info *ti);
 void attribute_shutdown(enum osl_close_flags flags);
 void get_attribute_bitmap(uint64_t *atts, char *buf);
 int get_attribute_bitnum_by_name(const char *att_name, unsigned char *bitnum);
-int com_lsatt(int fd, int argc, const char **argv);
-int com_setatt(int fd, int argc, const char **argv);
-int com_addatt(int fd, int argc, const char **argv);
-int com_rmatt(int fd, int argc, const char **argv);
 int get_attribute_text(uint64_t *atts, const char *delim, char **text);
 
 /* aft */
@@ -143,10 +139,6 @@ int get_afsi_of_row(const struct osl_row *row, struct afs_info *afsi);
 int get_audio_file_path_of_row(const struct osl_row *row, char **path);
 int get_afsi_object_of_row(const void *row, struct osl_object *obj);
 int audio_file_loop(void *private_data, osl_rbtree_loop_func *func);
-int com_touch(int fd, int argc, const char **argv);
-int com_add(int fd, int argc, const char **argv);
-int com_afs_ls(int fd, int argc, const char **argv);
-int com_afs_rm(int fd, int argc, const char **argv);
 
 /* mood */
 int mood_open(char *mood_name);
@@ -168,11 +160,6 @@ int playlist_update_audio_file(struct osl_row *aft_row);
 #define DECLARE_BLOB_SYMBOLS(table_name, cmd_prefix) \
        int table_name ## _init(struct table_info *ti); \
        void table_name ## _shutdown(enum osl_close_flags flags); \
-       int com_add ## cmd_prefix(int fd, int argc, const char **argv); \
-       int com_rm ## cmd_prefix(int fd, int argc, const char **argv); \
-       int com_cat ## cmd_prefix(int fd, int argc, const char **argv); \
-       int com_ls ## cmd_prefix(int fd, int argc, const char **argv); \
-       int com_mv ## cmd_prefix(int fd, int argc, const char **argv); \
        int cmd_prefix ## _get_name_by_id(uint32_t id, char **name); \
        extern struct osl_table *table_name ## _table;
 
diff --git a/aft.c b/aft.c
index 503105efabafb1cba792231d767c6c142197889a..06ff805c7f6ac4f5ec1adb6fa8e827d0a0d49608 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1436,7 +1436,7 @@ out_free:
        return ret;
 }
 
-int com_add(int fd, int argc, const char **argv)
+int com_add(int fd, int argc, char **argv)
 {
        int i, ret;
        struct private_add_data pad = {.fd = fd, .flags = 0};
index 9873fdd34867d01efab9cfa84a8b755c48f8a3fa..0434a80f3826cfacc8cacb028062b6ac80749499 100644 (file)
--- a/command.c
+++ b/command.c
@@ -25,6 +25,7 @@
 #include "list.h"
 #include "user_list.h"
 #include "server_command_list.h"
+#include "afs_command_list.h"
 
 /** commands including options must be shorter than this */
 #define MAX_COMMAND_LEN 4096
@@ -471,6 +472,10 @@ static struct server_command *get_cmd_ptr(char *name, char **handler)
        for (; cmd->name; cmd++)
                if (!strcmp(cmd->name, name))
                        return cmd;
+       /* not found, look for commands supported by afs */
+       for (cmd = afs_cmds; cmd; cmd++)
+               if (!strcmp(cmd->name, name))
+                       return cmd;
        return NULL;
 }
 
@@ -491,7 +496,10 @@ int com_help(int fd, int argc, char **argv)
                mmd_unlock();
                ret = send_list_of_commands(fd, cmd, handler);
                free(handler);
-               return ret;
+               if (ret < 0)
+                       return ret;
+               cmd = afs_cmds;
+               ret = send_list_of_commands(fd, cmd, "afs");
        }
        /* argument given for help */
        cmd = get_cmd_ptr(argv[1], &handler);
index 4a9a03cc77f9637e20fc797d99f655ca3ce90a30..a71bb6518f9194c999298e114b25636086d19ba8 100755 (executable)
@@ -1,26 +1,6 @@
 #!/bin/bash
 
 
-dump_array_member()
-{
-       echo '{'
-       echo ".name = \"$name_txt\","
-       if test $line_handler -eq 0; then
-               echo ".handler = com_$name_txt,"
-       else
-               echo ".handler = NULL,"
-               echo ".line_handler = com_$name_txt,"
-       fi
-       if test -n "$perms_txt"; then
-               echo ".perms = $perms_txt,"
-       fi
-       echo ".description = \"$desc_txt\","
-       echo ".usage = \"$usage_txt\","
-       echo ".help = "
-       echo "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g'
-       echo '},'
-}
-
 read_header()
 {
        local key value i
@@ -41,7 +21,7 @@ read_header()
                        array_name=${value%command_list}cmds
                        ;;
                SF:)
-                       source_file="$value"
+                       source_files="$value"
                        ;;
                AT:)
                        array_type="$value"
@@ -56,6 +36,9 @@ read_header()
                        ;;
                SN:)
                        section_name="$value"
+                       ;;
+               TM:)
+                       template_members="$value"
                esac
        done
        if test -z "$header_comment" -o -z "$c_file_comment" \
@@ -75,6 +58,9 @@ read_one_command()
        help_txt=""
        perms_txt=""
        line_handler=0
+       template=0
+       template_name=""
+       template_prototype=""
        mkdir -p man/man1
        while read key value; do
                case "$key" in
@@ -84,6 +70,14 @@ read_one_command()
                N:)
                        name_txt="$value"
                        ;;
+               T:)
+                       template_name="$value"
+                       template=1
+                       ;;
+               O:)
+                       template_prototype="$value"
+                       template=1
+                       ;;
                P:)
                        perms_txt="$value"
                        ;;
@@ -110,10 +104,20 @@ ${line# }"
                        ;;
                esac
        done
-       if test -n "$name_txt" -a -n "$desc_txt" -a -n "$usage_txt" \
-                       -a -n "$help_txt"; then
-               ret=1
-               return
+       if test $template -eq 0; then
+               if test -n "$name_txt" -a -n "$desc_txt" -a -n "$usage_txt" \
+                               -a -n "$help_txt"; then
+                       ret=1
+                       return
+               fi
+       else
+               if test -n "$template_name" -a -n "$template_prototype" \
+                               -a -n "$name_txt " -a -n "$template_members" \
+                               -a -n "$desc_txt" -a -n "$usage_txt" \
+                               -a -n "$help_txt"; then
+                       ret=1
+                       return
+               fi
        fi
        if test -z "$name_txt" -a -z "$desc_txt" -a -z "$usage_txt" \
                        -a -z "$help_txt"; then
@@ -121,13 +125,14 @@ ${line# }"
                return
        fi
        ret=-1
-       return
+       #return
        echo "!ERROR!"
        echo "N: $name_txt"
        echo "D: $desc_txt"
        echo "S: $usage_txt"
        echo "P: $perms_txt"
        echo "H: $help_txt"
+       echo "O: $template_prototype"
 }
 
 dump_man()
@@ -167,6 +172,85 @@ com_man()
        done
 }
 
+dump_proto()
+{
+       local source_file match=""
+
+       echo '/**'
+       echo " * $desc_txt"
+       echo ' *'
+       echo ' * \param fd The file descriptor to send output to.'
+       if test $line_handler -eq 0; then
+               echo ' * \param argc The number of arguments.'
+               echo ' * \param argv The argument vector.'
+       else
+               echo ' * \param cmdline The full command line.'
+       fi
+       echo ' * '
+       echo " * Usage: $usage_txt"
+       echo ' * '
+       echo "$help_txt" | sed -e 's/^/ * /g'
+       echo ' */'
+       if test -n "$prototype"; then
+               echo "$prototype"
+               echo
+               return
+       fi
+       for source_file in $source_files; do
+               match=$(grep "^\(__noreturn \)*int com_$name_txt(" $source_file | head -n 1 | sed -e 's/$/;/1')
+               if test -n "$match"; then
+                       echo "$match"
+                       break
+               fi
+       done
+       echo
+}
+
+dump_array_member()
+{
+       echo '{'
+       echo ".name = \"$name_txt\","
+       if test $line_handler -eq 0; then
+               echo ".handler = com_$name_txt,"
+       else
+               echo ".handler = NULL,"
+               echo ".line_handler = com_$name_txt,"
+       fi
+       if test -n "$perms_txt"; then
+               echo ".perms = $perms_txt,"
+       fi
+       echo ".description = \"$desc_txt\","
+       echo ".usage = \"$usage_txt\","
+       echo ".help = "
+       echo "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g'
+       echo '},'
+}
+
+
+template_loop()
+{
+       local t_name="$name_txt"
+       local t_perms="$perms_txt"
+       local t_desc="$desc_txt"
+       local t_usage="$usage_txt"
+       local t_help="$help_txt"
+       local t_source_files="$source_files"
+       local member
+       for member in $template_members; do
+               local sed_cmd="sed -e s/@member@/$member/g"
+               #echo "sed_cmd: $sed_cmd"
+               name_txt=$(echo $t_name | $sed_cmd)
+               #name_txt="$tname"
+               perms_txt=$(echo $t_perms | $sed_cmd)
+               desc_txt=$(echo $t_desc | $sed_cmd)
+               usage_txt=$(echo $t_usage | $sed_cmd)
+               help_txt=$(echo $t_help | $sed_cmd)
+               prototype=$(echo "$template_prototype" | $sed_cmd)
+               $1
+       done
+
+}
+
 com_c_file()
 {
        echo "/** \file $output_file.c $c_file_comment */"
@@ -180,32 +264,15 @@ com_c_file()
                if test $ret -eq 0; then
                        break
                fi
-               dump_array_member
+               if test $template -eq 0; then
+                       dump_array_member
+                       continue
+               fi
+               template_loop dump_array_member
        done
        echo '{.name = NULL}};'
 }
 
-dump_proto()
-{
-       echo '/**'
-       echo " * $desc_txt"
-       echo ' *'
-       echo ' * \param fd the file descriptor to send output to'
-       if test $line_handler -eq 0; then
-               echo ' * \param argc the number of arguments'
-               echo ' * \param argv the argument vector'
-       else
-               echo ' * \param cmdline the full command line'
-       fi
-       echo ' * '
-       echo " * usage: $usage_txt"
-       echo ' * '
-       echo "$help_txt" | sed -e 's/^/ * /g'
-       echo ' */'
-       grep "^\(__noreturn \)*int com_$name_txt(" $source_file | sed -e 's/$/;/1'
-       echo
-}
-
 com_header()
 {
        echo "/** \file $output_file.h $header_comment */"
@@ -219,7 +286,11 @@ com_header()
                if test $ret -eq 0; then
                        break
                fi
-               dump_proto
+               if test $template -eq 0; then
+                       dump_proto
+                       continue
+               fi
+               template_loop dump_proto
        done
 }
 
index 7449cde186b8178f86dedde43e8ea0a71d4e7ea7..1c9bee43d757fc5152c7bdbc587a63ee86ff86a8 100644 (file)
@@ -106,7 +106,7 @@ audiod_ldflags=""
 audiod_audio_formats=""
 
 server_cmdline_objs="server.cmdline server_command_list random_selector_command_list
-       playlist_selector_command_list"
+       playlist_selector_command_list afs_command_list"
 server_errlist_objs="server mp3_afh vss command net string signal random_selector
        time daemon stat crypt http_send afs_common close_on_fork playlist_selector
        ipc dccp dccp_send fd user_list chunk_queue afs osl aft mood score attribute