X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command_util.sh;h=76b3445fc1557b607ef72ae9408dec38f8a54507;hp=822cad2af5a74037867e95d5613c27e8eb56f2ee;hb=85094cd802bdb606d4e2bf7ed66dec51db2a0953;hpb=5e54609eda6f4417e8b7042db59ecf47fd720751 diff --git a/command_util.sh b/command_util.sh index 822cad2a..76b3445f 100755 --- a/command_util.sh +++ b/command_util.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash read_header() @@ -26,6 +26,12 @@ read_header() AT:) array_type="$value" ;; + SI:) + for i in $value; do + system_includes="$system_includes +#include <$i.h>" + done + ;; IN:) for i in $value; do includes="$includes @@ -57,7 +63,6 @@ read_one_command() usage_txt="" help_txt="" perms_txt="" - line_handler=0 template=0 template_name="" template_prototype="" @@ -84,9 +89,6 @@ read_one_command() D:) desc_txt="$value" ;; - L:) - line_handler=1 - ;; U:) usage_txt="$value" ;; @@ -148,7 +150,7 @@ dump_man() local t_name_txt=$(echo $name_txt | $sed_cmd) echo ".SS \"$t_name_txt\"" done - echo "$desc_txt" + echo "$desc_txt" | sed -e "s/@member@/{$(echo $template_members | sed -e 's/ / | /g')}/g" echo echo "\\fBUsage: \\fP" echo @@ -198,14 +200,6 @@ 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' @@ -227,24 +221,25 @@ dump_proto() dump_array_member() { + local TAB=' ' 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 + echo ".handler = com_$name_txt," if test -n "$perms_txt"; then echo ".perms = $perms_txt," fi echo ".description = \"$desc_txt\"," echo ".usage = \"$usage_txt\"," echo ".help = " - printf "%s\n" "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g' + printf "%s\n" "$help_txt" | sed -e 's/^/\"/g' -e 's/$/\\n\"/g' \ + -e "s/$TAB/\\\t/g" echo '},' } +dump_completion() +{ + echo " {.name = \"$name_txt\", .completer = ${name_txt}_completer}, \\" +} template_loop() { @@ -258,12 +253,12 @@ template_loop() 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=$(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=$(printf "%s" "$t_help" | $sed_cmd) + perms_txt=$(echo "$t_perms" | $sed_cmd) + desc_txt=$(echo "$t_desc" | $sed_cmd) + usage_txt=$(echo "$t_usage" | $sed_cmd) + help_txt=$(printf "%s\n" "$t_help" | $sed_cmd) prototype=$(echo "$template_prototype" | $sed_cmd) $1 done @@ -273,6 +268,7 @@ template_loop() com_c_file() { echo "/** \file $output_file.c $c_file_comment */" + echo "$system_includes" echo "$includes" echo "struct $array_type $array_name[] = {" while : ; do @@ -313,6 +309,27 @@ com_header() done } +com_completion() +{ + + echo "#define $1 \\" + while : ; do + read_one_command + if test $ret -lt 0; then + exit 1 + fi + if test $ret -eq 0; then + break + fi + if test $template -eq 0; then + dump_completion + continue + fi + template_loop dump_completion + done + echo +} + read_header arg="$1" shift @@ -326,4 +343,7 @@ case "$arg" in "man") com_man $* ;; + "compl") + com_completion $* + ;; esac