Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/tools/generate-cmdlist.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / tools / generate-cmdlist.sh` 120 lines ยท 1879 bytes Raw Blame History 1 #!/bin/sh 2 3 die () { 4 echo "$@" >&2 5 exit 1 6 } 7 8 command_list () { 9 while read cmd rest 10 do 11 case "$cmd" in 12 "#"* | '') 13 # Ignore comments and allow empty lines 14 continue 15 ;; 16 *) 17 case "$exclude_programs" in 18 *":$cmd:"*) 19 ;; 20 *) 21 echo "$cmd $rest" 22 ;; 23 esac 24 esac 25 done <"$1" 26 } 27 28 category_list () { 29 echo "$1" | 30 cut -d' ' -f2- | 31 tr ' ' '\012' | 32 grep -v '^$' | 33 LC_ALL=C sort -u 34 } 35 36 define_categories () { 37 echo 38 echo "/* Command categories */" 39 bit=0 40 echo "$1" | 41 while read cat 42 do 43 echo "#define CAT_$cat (1UL << $bit)" 44 bit=$(($bit+1)) 45 done 46 test "$bit" -gt 32 && die "Urgh.. too many categories?" 47 } 48 49 define_category_names () { 50 echo 51 echo "/* Category names */" 52 echo "static const char *category_names[] = {" 53 bit=0 54 echo "$1" | 55 while read cat 56 do 57 echo " \"$cat\", /* (1UL << $bit) */" 58 bit=$(($bit+1)) 59 done 60 echo " NULL" 61 echo "};" 62 } 63 64 print_command_list () { 65 echo "static struct cmdname_help command_list[] = {" 66 67 echo "$2" | 68 while read cmd rest 69 do 70 synopsis= 71 while read line 72 do 73 case "$line" in 74 "$cmd - "*) 75 synopsis=${line#$cmd - } 76 break 77 ;; 78 esac 79 done <"$1/Documentation/$cmd.adoc" 80 81 printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis" 82 printf " | CAT_%s" $rest 83 echo " }," 84 done 85 echo "};" 86 } 87 88 exclude_programs=: 89 while test "--exclude-program" = "$1" 90 do 91 shift 92 exclude_programs="$exclude_programs$1:" 93 shift 94 done 95 96 if test "$#" -ne 2 97 then 98 die "USAGE: $0 " 99 fi 100 101 SOURCE_DIR="$1" 102 OUTPUT="$2" 103 104 { 105 commands="$(command_list "$SOURCE_DIR"/command-list.txt)" 106 categories="$(category_list "$commands")" 107 108 echo "/* Automatically generated by generate-cmdlist.sh */ 109 struct cmdname_help { 110 const char *name; 111 const char *help; 112 uint32_t category; 113 }; 114 " 115 define_categories "$categories" 116 echo 117 define_category_names "$categories" 118 echo 119 print_command_list "$SOURCE_DIR" "$commands" 120 } >"$OUTPUT"