command_util: Write array definition in header mode.
[paraslash.git] / command_util.sh
index 875b5e6..abae4ec 100755 (executable)
@@ -10,6 +10,9 @@ read_header()
                ---)
                        break
                        ;;
+               BN:)
+                       base_name="$value"
+                       ;;
                OF:)
                        output_file="$value"
                        array_name=${value%command_list}cmds
@@ -248,10 +251,18 @@ template_loop()
                usage_txt=$(echo "$t_usage" | $sed_cmd)
                help_txt=$(printf "%s\n" "$t_help" | $sed_cmd)
                prototype=$(echo "$template_prototype" | $sed_cmd)
+               result=
                $1
                loop_result="$loop_result$result"
        done
        result="$loop_result"
+       # reset global variables
+       name_txt="$t_name"
+       perms_txt="$t_perms"
+       desc_txt="$t_desc"
+       usage_txt="$t_usage"
+       help_txt="$t_help"
+       source_files="$t_source_files"
 }
 
 com_c_file()
@@ -280,6 +291,9 @@ com_c_file()
 
 com_header()
 {
+       local array_members CR='
+'
+
        echo "extern struct $array_type $array_name[];"
        while : ; do
                read_one_command
@@ -292,11 +306,17 @@ com_header()
                if test $template -eq 0; then
                        make_proto
                        printf "%s" "$result"
+                       make_array_member
+                       array_members="$array_members$result"
                        continue
                fi
                template_loop make_proto
                printf "%s" "$result"
+               template_loop make_array_member
+               array_members="$array_members$result"
        done
+       array_members="$array_members{.name = NULL} \\$CR"
+       echo "#define DEFINE_$(tr 'a-z' 'A-Z' <<< "$base_name")_CMD_ARRAY $array_members"
 }
 
 com_completion()