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

[PATCH v2 2/3] Fix C syntactic errors for the Plan 9 C compiler

From
LGlufia via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 27, 2019, 13:46 UTC
Message-ID
<7abbd36e1ddc2037925c3ff148f62f0352a8954b.1566913575.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.305.v2.git.gitgitgadget@gmail.com>
From: lufia <lufia@lufia.org>
Signed-off-by: lufia <lufia@lufia.org>
---
 compat/plan9/openssl/crypto.h |  5 +++++
 compat/regex/regex_internal.h |  3 +++
 config.c                      |  3 ++-
 git-compat-util.h             |  9 ++++++++-
 parse-options.h               | 18 +++++++++---------
 remove-bitfields.sh           | 17 +++++++++++++++++
 6 files changed, 44 insertions(+), 11 deletions(-)
 create mode 100644 compat/plan9/openssl/crypto.h
 create mode 100755 remove-bitfields.sh
diff --git a/compat/plan9/openssl/crypto.h b/compat/plan9/openssl/crypto.h
new file mode 100644
index 0000000000..9d1ef43422
--- /dev/null
+++ b/compat/plan9/openssl/crypto.h
@@ -0,0 +1,5 @@
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+
+#include_next <openssl/crypto.h>
diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h
index 3ee8aae59d..7313c747a6 100644
--- a/compat/regex/regex_internal.h
+++ b/compat/regex/regex_internal.h
@@ -26,6 +26,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef NEEDS_SYS_PARAM_H
+#include <sys/param.h>
+#endif
 #if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC
 # include <langinfo.h>
 #endif
diff --git a/config.c b/config.c
index 14de96ee6d..0024b767e5 100644
--- a/config.c
+++ b/config.c
@@ -2462,7 +2462,8 @@ static int store_aux_event(enum config_event_t type,
 			return error(_("invalid section name '%s'"), cf->var.buf);
 
 		if (cf->subsection_case_sensitive)
-			cmpfn = strncasecmp;
+			/* Plan 9's strncasecmp is typed (char*, char*, int) */
+			cmpfn = (int (*)(const char*, const char*, size_t))strncasecmp;
 		else
 			cmpfn = strncmp;
 
diff --git a/git-compat-util.h b/git-compat-util.h
index f8fdd79591..1aa7877af4 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -164,7 +164,11 @@
 #define GIT_WINDOWS_NATIVE
 #endif
 
+#include <sys/types.h>
 #include <unistd.h>
+#ifdef __PLAN9__
+#include <libv.h>
+#endif
 #include <stdio.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -180,7 +184,6 @@
 #ifdef NEEDS_SYS_PARAM_H
 #include <sys/param.h>
 #endif
-#include <sys/types.h>
 #include <dirent.h>
 #include <sys/time.h>
 #include <time.h>
@@ -282,6 +285,10 @@ char *gitbasename(char *);
 char *gitdirname(char *);
 #endif
 
+#ifdef __PLAN9__
+#include <machine/endian.h>
+#endif
+
 #ifndef NO_ICONV
 #include <iconv.h>
 #endif
diff --git a/parse-options.h b/parse-options.h
index a4bd40bb6a..38a33a087e 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -46,6 +46,15 @@ enum parse_opt_option_flags {
 	PARSE_OPT_COMP_ARG = 1024
 };
 
+enum parse_opt_result {
+	PARSE_OPT_COMPLETE = -3,
+	PARSE_OPT_HELP = -2,
+	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
+	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
+	PARSE_OPT_NON_OPTION,
+	PARSE_OPT_UNKNOWN
+};
+
 struct option;
 typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
 
@@ -241,15 +250,6 @@ const char *optname(const struct option *opt, int flags);
 
 /*----- incremental advanced APIs -----*/
 
-enum parse_opt_result {
-	PARSE_OPT_COMPLETE = -3,
-	PARSE_OPT_HELP = -2,
-	PARSE_OPT_ERROR = -1,	/* must be the same as error() */
-	PARSE_OPT_DONE = 0,	/* fixed so that "return 0" works */
-	PARSE_OPT_NON_OPTION,
-	PARSE_OPT_UNKNOWN
-};
-
 /*
  * It's okay for the caller to consume argv/argc in the usual way.
  * Other fields of that structure are private to parse-options and should not
diff --git a/remove-bitfields.sh b/remove-bitfields.sh
new file mode 100755
index 0000000000..952bd34f12
--- /dev/null
+++ b/remove-bitfields.sh
@@ -0,0 +1,17 @@
+#!/bin/ape/sh
+# Plan 9 C compiler rejects initialization a structure including bit field.
+# usage: remove-bitfields.sh [dir ...]
+
+if ! echo abc | sed 's/(ab)c/\1/' >/dev/null 2>&1
+then
+	alias sed='sed -E'
+fi
+
+trap 'rm -f /tmp/remove-bitfields.$pid; exit 1' 1 2 3 15 EXIT
+
+files=$(du -a $* | awk '/\.[ch]$/ { print $2 }')
+for i in $files
+do
+	sed '/(^[ 	]*\*|\?)/!s/([a-z]+[a-z0-9]*) *: *[0-9]+([,;])/\1\2/g' $i >/tmp/remove-bitfields.$pid
+	cp /tmp/remove-bitfields.$pid $i
+done
-- 
gitgitgadget
Previous: lufia via GitGitGadgetNext: lufia via GitGitGadget
Message 16 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.