Skip to content

Commit

Permalink
Add Makefile target to produce and re-embed character lookup tables.
Browse files Browse the repository at this point in the history
* src/Makefile.in (update-tables, .PHONY): New targets.

* src/ne_string.c: Regenerate character lookup tables.

* src/mktable.c: Print the list of table names if executed without
  any arguments.
  • Loading branch information
notroj committed Jan 1, 2025
1 parent 1e7c960 commit 577c6c4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
22 changes: 19 additions & 3 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ OBJECTS = @NEONOBJS@ @NEON_EXTRAOBJS@
.SUFFIXES:
.SUFFIXES: .c .lo .o

.PHONY: all all-@NEON_BUILD_BUNDLED@ check-c++ check-incl update-tables \
update-deps

NEON_TARGET = @NEON_TARGET@

# Thanks to gettext for this neat trick.
Expand Down Expand Up @@ -93,11 +96,24 @@ check-c++: c++.c
c++ -I. c++.c

check-incl:
@for f in ne_*.h; do \
echo Checking $$f...; \
echo "#include \"$$f\"" > checkincl.c; \
@for f in ne_*.h; do \
[ x"$$f" != "xne_internal.h" ] || continue; \
echo Checking $$f...; \
echo "#include \"$$f\"" > checkincl.c; \
$(COMPILE) -c checkincl.c -o checkincl.o || exit 1; done

# Update generated character lookup tables.
update-tables: mktable
@for n in `./mktable`; do \
for f in `grep -l "mktable $$n" ne*.c`; do \
new=`mktemp`; \
(sed "/.* Generated with .mktable $$n/,\$$d" $$f; \
./mktable $$n; \
sed "0,/.* Generated code from .mktable $$n. ends/d" $$f) > $$new; \
mv $$new $$f; \
done \
done

# Update generated dependencies below; requires cc -MM as in gcc.
update-deps:
for f in `echo $(OBJECTS) | sed 's/\\.@NEON_OBJEXT@/.c/g;s/ne_openssl.c//;s/ne_gnutls.c//;s/ne_pkcs11.c//;s/ne_stubssl.c//'`; do \
Expand Down
5 changes: 4 additions & 1 deletion src/mktable.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ int main(int argc, const char **argv)
unsigned n, wrap, flags = 0;

if (argc != 2) {
fail("No generator given", "missing argument");
for (n = 0; n < sizeof(generators) / sizeof(generators[0]); n++) {
puts(generators[n].name);
}
return 0;
}

for (n = 0; n < sizeof(generators) / sizeof(generators[0]); n++) {
Expand Down
34 changes: 17 additions & 17 deletions src/ne_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static const unsigned char table_quote[256] = {
/* xD0 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
/* xE0 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
/* xF0 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
}; /* -- Generated code ends. */
}; /* -- Generated code from 'mktable quote' ends. */

static const char hex_chars[16] = "0123456789abcdef";

Expand Down Expand Up @@ -417,7 +417,7 @@ static const unsigned char table_validb64[256] = {
/* xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; /* -- Generated code ends. */
}; /* -- Generated code from 'mktable validb64' ends. */

/* Generated with 'mktable decodeb64', do not alter here -- */
static const unsigned char table_decodeb64[256] = {
Expand Down Expand Up @@ -453,7 +453,7 @@ static const unsigned char table_decodeb64[256] = {
/* xE8 */ 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
/* xF0 */ 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0,
/* xF8 */ 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8
}; /* -- Generated code ends. */
}; /* -- Generated code from 'mktable decodeb64' ends. */

#define DECODE_B64(ch) table_decodeb64[ch]
#define VALID_B64(ch) table_validb64[ch]
Expand Down Expand Up @@ -528,7 +528,7 @@ static const unsigned char table_strclean[256] = {
/* xE8 */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
/* xF0 */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
/* xF8 */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
}; /* -- Generated code ends. */
}; /* -- Generated code from 'mktable strclean' ends. */

char *ne_strclean(char *str)
{
Expand Down Expand Up @@ -612,19 +612,19 @@ static const unsigned char table_tolower[256] = {
/* x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
/* x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
/* x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
/* xa0 */ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
/* xa8 */ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
/* xb0 */ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
/* xb8 */ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
/* xc0 */ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
/* xc8 */ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
/* xd0 */ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
/* xd8 */ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
/* xe0 */ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
/* xe8 */ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
/* xf0 */ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
/* xf8 */ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
}; /* -- Generated code ends. */
/* xA0 */ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
/* xA8 */ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
/* xB0 */ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
/* xB8 */ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
/* xC0 */ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
/* xC8 */ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
/* xD0 */ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
/* xD8 */ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
/* xE0 */ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
/* xE8 */ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
/* xF0 */ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
/* xF8 */ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
}; /* -- Generated code from 'mktable tolower' ends. */

#define TOLOWER(ch) table_tolower[ch]

Expand Down

0 comments on commit 577c6c4

Please sign in to comment.