tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Replacing __BEGIN_DECLS in curses
Hi List
It seems our beloved curses library has been made portable, to work on
Linux + musl libc.
https://github.com/sabotage-linux/netbsd-curses
I'm in discussions with one of their devs about pushing some of their
patches into NetBSD so it's easier for them to sync our changes back
down.
One such change is replacing __BEGIN_DECLS and __END_DECLS with expanded
macros like
#ifdef cplusplus
extern "C" {
#endif
Which is a lot more portable and very standard.
Suggested patch to curses, forms and panel attached.
Commentary welcome.
Roy
Index: libcurses/curses.h
===================================================================
RCS file: /cvsroot/src/lib/libcurses/curses.h,v
retrieving revision 1.115
diff -u -p -r1.115 curses.h
--- libcurses/curses.h 4 Jan 2017 03:51:29 -0000 1.115
+++ libcurses/curses.h 4 Jan 2017 10:39:12 -0000
@@ -283,11 +283,13 @@ typedef struct __screen SCREEN;
#define NUM_ACS 128
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
extern chtype _acs_char[NUM_ACS];
-__END_DECLS
#ifdef __cplusplus
#define __UC_CAST(a) static_cast<unsigned char>(a)
+}
#else
#define __UC_CAST(a) (unsigned char)(a)
#endif
@@ -329,9 +331,13 @@ __END_DECLS
#define ACS_STERLING _acs_char[__UC_CAST('}')]
#ifdef HAVE_WCHAR
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
extern cchar_t _wacs_char[NUM_ACS];
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
#define WACS_RARROW (&_wacs_char[(unsigned char)'+'])
#define WACS_LARROW (&_wacs_char[(unsigned char)','])
@@ -396,6 +402,7 @@ __END_DECLS
#ifdef __cplusplus
#define __UINT32_CAST(a) static_cast<u_int32_t>(a)
+extern "C" {
#else
#define __UINT32_CAST(a) (u_int32_t)(a)
#endif
@@ -403,7 +410,6 @@ __END_DECLS
#define PAIR_NUMBER(n) (((__UINT32_CAST(n)) & A_COLOR) >> 17)
/* Curses external declarations. */
-__BEGIN_DECLS
extern WINDOW *curscr; /* Current screen. */
extern WINDOW *stdscr; /* Standard screen. */
@@ -416,7 +422,9 @@ extern int COLOR_PAIRS; /* Max color p
extern int ESCDELAY; /* Delay between keys in esc seq's. */
extern int TABSIZE; /* Size of a tab. */
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
#ifndef OK
#define ERR (-1) /* Error return. */
@@ -533,7 +541,9 @@ __END_DECLS
#else
/* Use functions not macros... */
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
int addbytes(const char *, int);
int addch(chtype);
int addchnstr(const chtype *, int);
@@ -612,7 +622,9 @@ int mvwgetnstr(WINDOW *, int, int, char
int mvwgetstr(WINDOW *, int, int, char *);
chtype mvwinch(WINDOW *, int, int);
int mvwinsch(WINDOW *, int, int, chtype);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
#endif /* _CURSES_USE_MACROS */
#define getyx(w, y, x) (y) = getcury(w), (x) = getcurx(w)
@@ -639,7 +651,9 @@ __END_DECLS
/* Public function prototypes. */
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
int assume_default_colors(short, short);
int baudrate(void);
int beep(void);
@@ -962,6 +976,9 @@ int __waddbytes(WINDOW *, const char *,
#ifdef HAVE_WCHAR
int __cputwchar( wchar_t );
#endif /* HAVE_WCHAR */
-__END_DECLS
+
+#if defined(__cplusplus)
+}
+#endif
#endif /* !_CURSES_H_ */
Index: libform/form.h
===================================================================
RCS file: /cvsroot/src/lib/libform/form.h,v
retrieving revision 1.23
diff -u -p -r1.23 form.h
--- libform/form.h 7 Sep 2015 15:50:49 -0000 1.23
+++ libform/form.h 4 Jan 2017 10:39:12 -0000
@@ -238,16 +238,6 @@ struct _form_field {
FORM_STR *buffers; /* array of buffers for the field */
};
-/* define the types of fields we can have */
-extern FIELDTYPE *TYPE_ALNUM;
-extern FIELDTYPE *TYPE_ALPHA;
-extern FIELDTYPE *TYPE_ENUM;
-extern FIELDTYPE *TYPE_INTEGER;
-extern FIELDTYPE *TYPE_NUMERIC;
-extern FIELDTYPE *TYPE_REGEXP;
-extern FIELDTYPE *TYPE_IPV4;
-extern FIELDTYPE *TYPE_IPV6;
-extern FIELDTYPE *TYPE_USER;
/* definition of a field type. */
struct _form_fieldtype {
@@ -296,9 +286,23 @@ struct _form_struct {
FIELD **fields; /* array of fields attached to this form. */
};
-/* Public function prototypes. */
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* define the types of fields we can have */
+extern FIELDTYPE *TYPE_ALNUM;
+extern FIELDTYPE *TYPE_ALPHA;
+extern FIELDTYPE *TYPE_ENUM;
+extern FIELDTYPE *TYPE_INTEGER;
+extern FIELDTYPE *TYPE_NUMERIC;
+extern FIELDTYPE *TYPE_REGEXP;
+extern FIELDTYPE *TYPE_IPV4;
+extern FIELDTYPE *TYPE_IPV6;
+extern FIELDTYPE *TYPE_USER;
+
+/* Public function prototypes. */
FIELD *current_field(FORM *);
int data_ahead(FORM *);
int data_behind(FORM *);
@@ -377,6 +381,8 @@ int set_max_field(FIELD *, int)
int set_new_page(FIELD *, int);
int unpost_form(FORM *);
-__END_DECLS
+#ifdef __cplusplus
+}
+#endif
#endif /* FORM_H */
Index: libpanel/panel.h
===================================================================
RCS file: /cvsroot/src/lib/libpanel/panel.h,v
retrieving revision 1.2
diff -u -p -r1.2 panel.h
--- libpanel/panel.h 2 Nov 2015 01:06:15 -0000 1.2
+++ libpanel/panel.h 4 Jan 2017 10:39:12 -0000
@@ -33,7 +33,10 @@
typedef struct __panel PANEL;
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
+
PANEL *new_panel(WINDOW *);
int del_panel(PANEL *);
@@ -56,6 +59,9 @@ PANEL *panel_below(PANEL *);
int move_panel(PANEL *, int, int);
void update_panels(void);
-__END_DECLS
+
+#ifdef __cplusplus
+}
+#endif
#endif /* _PANEL_H_ */
Home |
Main Index |
Thread Index |
Old Index