31b6d886cbdaf199a1e11246b2baf871dea97261
   1#!/bin/sh
   2
   3get_synopsis () {
   4        sed -n '
   5                /^NAME/,/'"$1"'/H
   6                ${
   7                        x
   8                        s/.*'"$1"' - \(.*\)/N_("\1")/
   9                        p
  10                }' "Documentation/$1.txt"
  11}
  12
  13echo "/* Automatically generated by generate-cmdlist.sh */
  14struct cmdname_help {
  15        char name[16];
  16        char help[80];
  17        unsigned char group;
  18};
  19
  20static const char *common_cmd_groups[] = {"
  21
  22grps=grps$$.tmp
  23match=match$$.tmp
  24trap "rm -f '$grps' '$match'" 0 1 2 3 15
  25
  26sed -n '
  27        1,/^### common groups/b
  28        /^### command list/q
  29        /^#/b
  30        /^[     ]*$/b
  31        h;s/^[^         ][^     ]*[     ][      ]*\(.*\)/       N_("\1"),/p
  32        g;s/^\([^       ][^     ]*\)[   ].*/\1/w '$grps'
  33        ' "$1"
  34printf '};\n\n'
  35
  36n=0
  37substnum=
  38while read grp
  39do
  40        echo "^git-..*[         ]$grp"
  41        substnum="$substnum${substnum:+;}s/[    ]$grp/$n/"
  42        n=$(($n+1))
  43done <"$grps" >"$match"
  44
  45printf 'static struct cmdname_help common_cmds[] = {\n'
  46grep -f "$match" "$1" |
  47sed 's/^git-//' |
  48sort |
  49while read cmd tags
  50do
  51        tag=$(echo "$tags" | sed "$substnum; s/[^0-9]//g")
  52        echo "  {\"$cmd\", $(get_synopsis git-$cmd), $tag},"
  53done
  54echo "};"