Skip to content

Commit

Permalink
Add conditional support for CLDR. (dm)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveMielke committed Oct 2, 2018
1 parent d1d20be commit a37febe
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions Programs/.gitignore
Expand Up @@ -2,6 +2,7 @@

/brltty
/brltty-atb
/brltty-cldr
/brltty-ctb
/brltty-ktb
/brltty-lscmds
Expand Down
10 changes: 5 additions & 5 deletions Programs/Makefile.in
Expand Up @@ -532,7 +532,7 @@ ctb_louis.$O:
BRLTTY_CTB_OBJECTS = brltty-ctb.$O $(PROGRAM_OBJECTS) $(PREFS_OBJECTS) dataarea.$O $(TTB_OBJECTS) $(CTB_OBJECTS)

brltty-ctb$X: $(BRLTTY_CTB_OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(BRLTTY_CTB_OBJECTS) $(LOUIS_LIBS) $(LDLIBS)
$(CC) $(LDFLAGS) -o $@ $(BRLTTY_CTB_OBJECTS) $(LOUIS_LIBS) $(EXPAT_LIBS) $(LDLIBS)

brltty-ctb.$O:
$(CC) $(CFLAGS) -c $(SRC_DIR)/brltty-ctb.c
Expand Down Expand Up @@ -666,7 +666,7 @@ uninstall-api-bindings:
BRLTTY_CLDR_OBJECTS = brltty-cldr.$O cldr.$O $(PROGRAM_OBJECTS)

brltty-cldr$X: $(BRLTTY_CLDR_OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(BRLTTY_CLDR_OBJECTS) -lexpat $(LDLIBS)
$(CC) $(LDFLAGS) -o $@ $(BRLTTY_CLDR_OBJECTS) $(EXPAT_LIBS) $(LDLIBS)

brltty-cldr.$O:
$(CC) $(LIBCFLAGS) -c $(SRC_DIR)/brltty-cldr.c
Expand Down Expand Up @@ -775,7 +775,7 @@ learn.$O:
###############################################################################

BRLTTY_OBJECTS = brltty.$O $(CORE_OBJECTS)
BRLTTY_LIBRARIES = $(BRAILLE_DRIVER_LIBRARIES) $(SPEECH_DRIVER_LIBRARIES) $(SCREEN_DRIVER_LIBRARIES) $(SERVICE_LIBS) $(PCM_LIBS) $(MIDI_LIBS) $(USB_LIBS) $(BLUETOOTH_LIBS) $(LOUIS_LIBS) $(POLKIT_LIBS) $(LDLIBS)
BRLTTY_LIBRARIES = $(BRAILLE_DRIVER_LIBRARIES) $(SPEECH_DRIVER_LIBRARIES) $(SCREEN_DRIVER_LIBRARIES) $(SERVICE_LIBS) $(PCM_LIBS) $(MIDI_LIBS) $(USB_LIBS) $(BLUETOOTH_LIBS) $(LOUIS_LIBS) $(EXPAT_LIBS) $(POLKIT_LIBS) $(LDLIBS)

brltty$X: $(BRLTTY_OBJECTS)
$(CC) $(LDFLAGS) -o $@ $(BRLTTY_OBJECTS) $(BRLTTY_LIBRARIES)
Expand Down Expand Up @@ -952,11 +952,11 @@ xbrlapi.$O:

###############################################################################

TBL2HEX_OBJECTS_FOR_BUILD = tbl2hex.$(O_FOR_BUILD) $(PROGRAM_OBJECTS_FOR_BUILD) dataarea.$(O_FOR_BUILD) ttb_compile.$(O_FOR_BUILD) ttb_native.$(O_FOR_BUILD) atb_compile.$(O_FOR_BUILD) ctb_compile.$(O_FOR_BUILD)
TBL2HEX_OBJECTS_FOR_BUILD = tbl2hex.$(O_FOR_BUILD) $(PROGRAM_OBJECTS_FOR_BUILD) dataarea.$(O_FOR_BUILD) ttb_compile.$(O_FOR_BUILD) ttb_native.$(O_FOR_BUILD) atb_compile.$(O_FOR_BUILD) ctb_compile.$(O_FOR_BUILD) cldr.$(O_FOR_BUILD)
TBL2HEX_OBJECTS = $(TBL2HEX_OBJECTS_FOR_BUILD:.$(O_FOR_BUILD)=.$B)

tbl2hex$(X_FOR_BUILD): $(TBL2HEX_OBJECTS)
$(CC_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ $(TBL2HEX_OBJECTS) $(LDLIBS_FOR_BUILD)
$(CC_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ $(TBL2HEX_OBJECTS) $(EXPAT_LIBS_FOR_BUILD) $(LDLIBS_FOR_BUILD)

###############################################################################

Expand Down
12 changes: 11 additions & 1 deletion Programs/cldr.c
Expand Up @@ -22,12 +22,14 @@
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <expat.h>

#include "log.h"
#include "cldr.h"
#include "file.h"

#ifdef HAVE_EXPAT
#include <expat.h>

const char cldrDefaultDirectory[] = "/usr/share/unicode/cldr/common/annotations";
const char cldrDefaultExtension[] = ".xml";

Expand Down Expand Up @@ -160,9 +162,11 @@ handleElementEnd (void *userData, const char *name) {

dpo->document.depth -= 1;
}
#endif /* HAVE_EXPAT */

CLDR_DocumentParserObject *
cldrNewDocumentParser (CLDR_AnnotationHandler *handler, void *data) {
#ifdef HAVE_EXPAT
CLDR_DocumentParserObject *dpo;

if ((dpo = malloc(sizeof(*dpo)))) {
Expand Down Expand Up @@ -190,12 +194,14 @@ cldrNewDocumentParser (CLDR_AnnotationHandler *handler, void *data) {
} else {
logMallocError();
}
#endif /* HAVE_EXPAT */

return NULL;
}

void
cldrDestroyDocumentParser (CLDR_DocumentParserObject *dpo) {
#ifdef HAVE_EXPAT
if (dpo->annotation.sequence) {
free(dpo->annotation.sequence);
dpo->annotation.sequence = NULL;
Expand All @@ -208,10 +214,12 @@ cldrDestroyDocumentParser (CLDR_DocumentParserObject *dpo) {

XML_ParserFree(dpo->document.parser);
free(dpo);
#endif /* HAVE_EXPAT */
}

int
cldrParseText (CLDR_DocumentParserObject *dpo, const char *text, size_t size, int final) {
#ifdef HAVE_EXPAT
enum XML_Status status = XML_Parse(dpo->document.parser, text, size, final);

switch (status) {
Expand All @@ -226,6 +234,7 @@ cldrParseText (CLDR_DocumentParserObject *dpo, const char *text, size_t size, in
logMessage(LOG_WARNING, "unrecognized CLDR parse status: %d", status);
break;
}
#endif /* HAVE_EXPAT */

return 0;
}
Expand Down Expand Up @@ -255,6 +264,7 @@ cldrParseFile (
char *path = makeFilePath(cldrDefaultDirectory, name, cldrDefaultExtension);

if (path) {
logMessage(LOG_DEBUG, "processing CLDR annotations file: %s", path);
int fd = open(path, O_RDONLY);

if (fd != -1) {
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Expand Up @@ -83,6 +83,9 @@ extern "C" {
/* Define this if the header file iconv.h exists. */
#undef HAVE_ICONV_H

/* Define this if XML parsing support is to be included. */
#undef HAVE_EXPAT

/* Define this if the header file pwd.h exists. */
#undef HAVE_PWD_H

Expand Down
3 changes: 3 additions & 0 deletions config.mk.in
Expand Up @@ -106,6 +106,9 @@ POLKIT_PACKAGE = @polkit_package@
POLKIT_INCLUDES = @polkit_includes@
POLKIT_LIBS = @polkit_libs@

EXPAT_INCLUDES = @expat_includes@
EXPAT_LIBS = @expat_libs@

LOUIS_INCLUDES = @louis_includes@
LOUIS_LIBS = @louis_libs@

Expand Down
17 changes: 16 additions & 1 deletion configure.ac
Expand Up @@ -1105,6 +1105,21 @@ BRLTTY_ARG_PACKAGE([system], [base system], [], [dnl
;;
])

expat_includes=""
expat_libs=""
BRLTTY_ARG_DISABLE(
[expat],
[support for XML parsing (CLDR)],
[],
[dnl
BRLTTY_HAVE_PACKAGE([expat], [expat], [dnl
AC_DEFINE_UNQUOTED([HAVE_EXPAT], [1],
[Define this if XML parsing support is to be included.])
])
])
AC_SUBST([expat_includes])
AC_SUBST([expat_libs])

BRLTTY_ARG_DISABLE(
[contracted-braille],
[in-line contracted braille],
Expand All @@ -1116,7 +1131,7 @@ BRLTTY_ARG_DISABLE(
all_brltty_ctb="all-brltty-ctb"
install_brltty_ctb="install-brltty-ctb"
contracted_braille_objects='ctb_compile.$O ctb_translate.$O ctb_native.$O ctb_external.$O'
contracted_braille_objects='ctb_compile.$O cldr.$O ctb_translate.$O ctb_native.$O ctb_external.$O'
install_contraction_tables=install-contraction-tables
louis_includes=""
Expand Down

0 comments on commit a37febe

Please sign in to comment.