git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] Port generate-cmdline.sh to rc

From
LGlufia via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 3, 2019, 23:52 UTC
Message-ID
<d25bcb43e1d8fe68717c6df57063427ab5a142f4.1564876327.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.305.git.gitgitgadget@gmail.com>
From: lufia <lufia@lufia.org>
Signed-off-by: lufia <lufia@lufia.org>
---
 generate-cmdlist.rc | 102 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100755 generate-cmdlist.rc
diff --git a/generate-cmdlist.rc b/generate-cmdlist.rc
new file mode 100755
index 0000000000..18699ea9c4
--- /dev/null
+++ b/generate-cmdlist.rc
@@ -0,0 +1,102 @@
+#!/bin/rc
+
+rfork e
+
+fn die {
+	echo $* >[1=2]
+	exit die
+}
+
+fn command_list {
+	grep -v '^#' $1
+}
+
+fn get_categories {
+	tr ' ' '\x0a'|
+	grep -v '^$' |
+	sort |
+	uniq
+}
+
+fn category_list {
+	command_list $1 |
+	awk '{ print substr($0, 40) }' |
+	get_categories
+}
+
+fn get_synopsis {
+	sed -n '
+		/^NAME/,/'$1'/h
+		${
+			x
+			s/.*'$1' - (.*)/N_\("\1"\)/
+			p
+		}' Documentation/$1.txt
+}
+
+fn define_categories {
+	echo
+	echo '/* Command categories */'
+	bit=0
+	category_list $1 |
+	while(cat=`{read}){
+		echo '#define CAT_'$"cat' (1UL << '$bit')'
+		bit=`{hoc -e $bit' + 1'}
+	}
+	test $bit -gt 32 && die 'Urgh.. too many categories?'
+}
+
+fn define_category_names {
+	echo
+	echo '/* Category names */'
+	echo 'static const char *category_names[] = {'
+	bit=0
+	category_list $1 |
+	while(cat=`{read}){
+		echo '	"'$"cat'", /* (1UL << '$bit') */'
+		bit=`{hoc -e $bit' + 1'}
+	}
+	echo '	NULL,'
+	echo '};'
+}
+
+fn print_command_list {
+	echo 'static struct cmdname_help command_list[] = {'
+
+	command_list $1 |
+	while(a=`{read}){
+		s=`{get_synopsis $a(1)}
+		q=`{seq 2 $#a}
+		echo -n '	{ "'^$a(1)^'", '$"s', 0'
+		for(cat in `{echo $a($q) | get_categories})
+			echo -n ' | CAT_'^$cat
+		echo ' },'
+	}
+	echo '};'
+}
+
+fn print_config_list {
+	echo 'static const char *config_name_list[] = {'
+	grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
+	sed '/deprecated/d; s/::$//; s/,  */\n/g' |
+	sort |
+	while(line=`{read})
+		echo '	"'$"line'",'
+	echo '	NULL'
+	echo '};'
+}
+
+echo '/* Automatically generated by generate-cmdlist.sh */
+struct cmdname_help {
+	const char *name;
+	const char *help;
+	uint32_t category;
+};
+'
+define_categories $1
+echo
+define_category_names $1
+echo
+print_command_list $1
+echo
+print_config_list
-- 
gitgitgadget
Previous: lufia via GitGitGadgetNext: lufia via GitGitGadget
Message 3 of 17 in “Port git to Plan 9”
  1. 0/6 Port git to Plan 9KADOTA, Kyohei via GitGitGadget, Aug 3, 2019
  2. 2/6 Fix C syntactic errors for the Plan 9 C compilerlufia via GitGitGadget, Aug 3, 2019
  3. 4/6 Port generate-cmdline.sh to rclufia via GitGitGadget, Aug 3, 2019
  4. 1/6 Change HOME, PATH, and .gitconfig paths to be customizablelufia via GitGitGadget, Aug 3, 2019
  5. 3/6 GIT-VERSION-GEN: Use sed instead of exprlufia via GitGitGadget, Aug 3, 2019
  6. Junio C HamanoAug 5, 2019
  7. 5/6 Add plan9/wrap.clufia via GitGitGadget, Aug 3, 2019
  8. brian m. carlsonAug 4, 2019
  9. Kyohei KadotaAug 4, 2019
  10. 6/6 Add mkfile to build git and subcommands for Plan 9lufia via GitGitGadget, Aug 3, 2019
  11. brian m. carlsonAug 4, 2019
  12. Kyohei KadotaAug 4, 2019
  13. Jonathan NiederAug 4, 2019
  14. 0/3 Port git to Plan 9KADOTA, Kyohei via GitGitGadget, Aug 27, 2019
  15. 1/3 Change HOME, PATH, and .gitconfig paths to be customizablelufia via GitGitGadget, Aug 27, 2019
  16. 2/3 Fix C syntactic errors for the Plan 9 C compilerlufia via GitGitGadget, Aug 27, 2019
  17. 3/3 Support Plan 9 dialectlufia via GitGitGadget, Aug 27, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.