diff mbox series

AT&T Unix PC : 10-ctype

Message ID 8f418d92-faa7-467f-bcc2-441f188b0ee4@knaff.lu (mailing list archive)
State New
Headers show
Series AT&T Unix PC : 10-ctype | expand

Commit Message

Alain Knaff Nov. 17, 2024, 5:23 p.m. UTC
Hi,

The 10th patch fixes the handling of the "functions" supplied by
ctype.h

On many older platforms, those are not real functions but preprocessor
macros, so it is not possible to take a function pointer of them.

Dash's current approach of wrapping them into real functions would
work if prototypes for these functions were available somewhere.

I took a different approach, which is to replace the table of names
and function pointers with a cascade of ifs, makes for shorter code as
well.

Regards,

Alain
diff mbox series

Patch

diff -X ../exclude.txt -urN dash-0.5.12+09-type-sizes/src/expand.c dash-0.5.12+10-ctype/src/expand.c
--- dash-0.5.12+09-type-sizes/src/expand.c	2024-10-20 21:19:22.613459913 +0000
+++ dash-0.5.12+10-ctype/src/expand.c	2024-11-09 23:08:05.018189584 +0000
@@ -1568,37 +1568,18 @@ 
 #ifndef HAVE_FNMATCH
 STATIC int ccmatch(const char *p, int chr, const char **r)
 {
-	static const struct class {
-		char name[10];
-		int (*fn)(int);
-	} classes[] = {
-		{ .name = ":alnum:]", .fn = isalnum },
-		{ .name = ":cntrl:]", .fn = iscntrl },
-		{ .name = ":lower:]", .fn = islower },
-		{ .name = ":space:]", .fn = isspace },
-		{ .name = ":alpha:]", .fn = isalpha },
-		{ .name = ":digit:]", .fn = isdigit },
-		{ .name = ":print:]", .fn = isprint },
-		{ .name = ":upper:]", .fn = isupper },
-		{ .name = ":blank:]", .fn = isblank },
-		{ .name = ":graph:]", .fn = isgraph },
-		{ .name = ":punct:]", .fn = ispunct },
-		{ .name = ":xdigit:]", .fn = isxdigit },
-	};
-	const struct class *class, *end;
-
-	end = classes + sizeof(classes) / sizeof(classes[0]);
-	for (class = classes; class < end; class++) {
-		const char *q;
-
-		q = prefix(p, class->name);
-		if (!q)
-			continue;
-		*r = q;
-		return class->fn(chr);
-	}
-
-	*r = 0;
+	if(( *r=prefix(p, ":alnum:]") )) return isalnum(chr); else
+	if(( *r=prefix(p, ":cntrl:]") )) return iscntrl(chr); else
+	if(( *r=prefix(p, ":lower:]") )) return islower(chr); else
+	if(( *r=prefix(p, ":space:]") )) return isspace(chr); else
+	if(( *r=prefix(p, ":alpha:]") )) return isalpha(chr); else
+	if(( *r=prefix(p, ":digit:]") )) return isdigit(chr); else
+	if(( *r=prefix(p, ":print:]") )) return isprint(chr); else
+	if(( *r=prefix(p, ":upper:]") )) return isupper(chr); else
+	if(( *r=prefix(p, ":blank:]") )) return isblank(chr); else
+	if(( *r=prefix(p, ":graph:]") )) return isgraph(chr); else
+	if(( *r=prefix(p, ":punct:]") )) return ispunct(chr); else
+	if(( *r=prefix(p, ":xdigit:]") )) return isxdigit(chr); else
 	return 0;
 }
 
diff -X ../exclude.txt -urN dash-0.5.12+09-type-sizes/src/system.c dash-0.5.12+10-ctype/src/system.c
--- dash-0.5.12+09-type-sizes/src/system.c	2024-11-10 16:54:50.548225768 +0000
+++ dash-0.5.12+10-ctype/src/system.c	2024-11-10 16:56:47.395004664 +0000
@@ -27,31 +27,7 @@ 
  */
 
 #ifndef HAVE_ISALPHA
-#define isalnum _isalnum
-#define iscntrl _iscntrl
-#define islower _islower
-#define isspace _isspace
-#define isalpha _isalpha
-#define isdigit _isdigit
-#define isprint _isprint
-#define isupper _isupper
-#define isblank _isblank
-#define isgraph _isgraph
-#define ispunct _ispunct
-#define isxdigit _isxdigit
 #include <ctype.h>
-#undef isalnum
-#undef iscntrl
-#undef islower
-#undef isspace
-#undef isalpha
-#undef isdigit
-#undef isprint
-#undef isupper
-#undef isblank
-#undef isgraph
-#undef ispunct
-#undef isxdigit
 #endif
 
 #include <signal.h>
@@ -157,69 +133,6 @@ 
 }
 #endif
 
-#ifndef HAVE_ISALPHA
-int isalnum(int c) {
-	return _isalnum(c);
-}
-
-
-int iscntrl(int c) {
-	return _iscntrl(c);
-}
-
-
-int islower(int c) {
-	return _islower(c);
-}
-
-
-int isspace(int c) {
-	return _isspace(c);
-}
-
-
-int isalpha(int c) {
-	return _isalpha(c);
-}
-
-
-int isdigit(int c) {
-	return _isdigit(c);
-}
-
-
-int isprint(int c) {
-	return _isprint(c);
-}
-
-
-int isupper(int c) {
-	return _isupper(c);
-}
-
-
-#if HAVE_DECL_ISBLANK
-int isblank(int c) {
-	return _isblank(c);
-}
-#endif
-
-
-int isgraph(int c) {
-	return _isgraph(c);
-}
-
-
-int ispunct(int c) {
-	return _ispunct(c);
-}
-
-
-int isxdigit(int c) {
-	return _isxdigit(c);
-}
-#endif
-
 #if !HAVE_DECL_ISBLANK
 int isblank(int c) {
 	return c == ' ' || c == '\t';