move header include info from Makefile.in to *.cmd
[paraslash.git] / command_util.sh
index ea952e5..b757b2e 100755 (executable)
@@ -20,6 +20,46 @@ dump_array_member()
        echo '},'
 }
 
+read_header()
+{
+       local key value i
+
+       while read key value; do
+               case "$key" in
+               ---)
+                       break
+                       ;;
+               HC:)
+                       header_comment="$value"
+                       ;;
+               CC:)
+                       c_file_comment="$value"
+                       ;;
+               FN:)
+                       file_name="$value"
+                       ;;
+               AT:)
+                       array_type="$value"
+                       ;;
+               AN:)
+                       array_name="$value"
+                       ;;
+               IN:)
+                       for i in $value; do
+                               includes="$includes
+#include \"$i.h\""
+                       done
+                       includes="$includes
+#include \"$file_name.h\""
+                       ;;
+               esac
+       done
+       if test -z "$header_comment" -o -z "$c_file_comment" \
+                       -o -z "$file_name"; then
+               echo "header error" 1&>2
+               exit 1
+       fi
+}
 
 read_one_command()
 {
@@ -140,6 +180,9 @@ com_man()
 
 com_array()
 {
+       echo "/** \file $file_name.c $c_file_comment */"
+       echo "$includes"
+       echo "struct $array_type $array_name[] = {"
        while : ; do
                read_one_command
                if test $ret -lt 0; then
@@ -150,19 +193,39 @@ com_array()
                fi
                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 " * synopsis: $syn_txt"
+       echo ' * '
+       echo "$help_txt" | sed -e 's/^/ * /g'
+       echo ' */'
        if test $line_handler -eq 0; then
-               echo "int com_$name_txt(int, int, char **);"
+               echo "int com_$name_txt(int fd, int argc, char **argv);"
        else
-               echo "int com_$name_txt(int, char *);"
+               echo "int com_$name_txt(int fd, char *cmdline);"
        fi
+       echo
 }
 
 com_proto()
 {
+       echo "/** \file $file_name.h $header_comment */"
+       echo
+       echo "extern struct $array_type $array_name[];"
        while : ; do
                read_one_command
                if test $ret -lt 0; then
@@ -175,6 +238,7 @@ com_proto()
        done
 }
 
+read_header
 arg="$1"
 shift
 case "$arg" in