Tools.mk | 27 -- configure.ac | 1 doc/Makefile.am | 23 -- doc/edit-sgml.c | 546 ----------------------------------------------- fc-case/fc-case.c | 363 ------------------------------- fc-lang/Makefile.am | 2 fc-lang/fc-lang.c | 595 ---------------------------------------------------- 7 files changed, 18 insertions(+), 1539 deletions(-) New commits: commit ef28c78350f84cb92cf86eb6110e8ebac617ceb6 Author: Akira TAGOH <akira@xxxxxxxxx> Date: Wed Aug 26 13:33:07 2020 +0000 Integrate python scripts to autotools build Recently some python scripts has been added to the build toolchain for meson build support. but we don't want to maintain multiple files for one purpose. since autotools build support will be guradually discontinued, integrating those scripts into autotools would be better. diff --git a/Tools.mk b/Tools.mk index f0fa0ec..bc91e4e 100644 --- a/Tools.mk +++ b/Tools.mk @@ -27,28 +27,15 @@ DIR=fc-$(TAG) OUT=fc$(TAG) TMPL=$(OUT).tmpl.h TARG=$(OUT).h -TSRC=$(DIR).c -TOOL=./$(DIR)$(EXEEXT_FOR_BUILD) +TOOL=$(srcdir)/$(DIR).py -EXTRA_DIST = $(TARG) $(TMPL) $(TSRC) $(DIST) +noinst_SCRIPTS = $(TOOL) +EXTRA_DIST = $(TARG) $(TMPL) $(DIST) -AM_CPPFLAGS = \ - -I$(builddir) \ - -I$(srcdir) \ - -I$(top_builddir)/src \ - -I$(top_srcdir)/src \ - -I$(top_builddir) \ - -I$(top_srcdir) \ - -DHAVE_CONFIG_H \ - $(WARN_CFLAGS) - -$(TOOL): $(TSRC) $(ALIAS_FILES) - $(AM_V_GEN) $(CC_FOR_BUILD) -o $(TOOL) $< $(AM_CPPFLAGS) - -$(TARG): $(TMPL) $(TSRC) $(DEPS) - $(AM_V_GEN) $(MAKE) $(TOOL) && \ +$(TARG): $(TMPL) $(TOOL) + $(AM_V_GEN) \ $(RM) $(TARG) && \ - $(TOOL) $(ARGS) < $< > $(TARG).tmp && \ + $(PYTHON) $(TOOL) $(ARGS) --template $< --output $(TARG).tmp && \ mv $(TARG).tmp $(TARG) || ( $(RM) $(TARG).tmp && false ) noinst_HEADERS=$(TARG) @@ -59,6 +46,6 @@ BUILT_SOURCES = $(ALIAS_FILES) $(ALIAS_FILES): $(AM_V_GEN) touch $@ -CLEANFILES = $(ALIAS_FILES) $(TOOL) +CLEANFILES = $(ALIAS_FILES) MAINTAINERCLEANFILES = $(TARG) diff --git a/configure.ac b/configure.ac index 2e48952..fd11ab6 100644 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,7 @@ m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR], AC_SUBST([pkgconfigdir], ${libdir}/ AM_MISSING_PROG([GIT], [git]) AM_MISSING_PROG([GPERF], [gperf]) +AM_PATH_PYTHON AC_MSG_CHECKING([for RM macro]) _predefined_rm=`make -p -f /dev/null 2>/dev/null|grep '^RM ='|sed -e 's/^RM = //'` diff --git a/doc/Makefile.am b/doc/Makefile.am index c1d2a4a..02831b1 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -26,13 +26,16 @@ NULL = EXTRA_DIST = \ $(BUILT_DOCS) \ $(DOC_FUNCS_FNCS) \ - $(DOC_FUNCS_SGML) \ $(HTML_DIR)/* \ $(SGML_FILES) \ $(check_SCRIPTS) \ confdir.sgml.in \ func.sgml \ $(NULL) +BUILT_SOURCES = \ + $(DOC_FUNCS_SGML) \ + $(NULL) + if USEDOCBOOK maintainerdoccleanfiles = \ $(NULL) @@ -133,15 +136,10 @@ HTML_DIR = fontconfig-devel # noinst_PROGRAMS = \ $(NULL) -## -edit_sgml_SOURCES = \ - edit-sgml.c \ +noinst_SCRIPTS = \ + edit-sgml.py \ $(NULL) -$(edit_sgml_OBJECTS) : CC:=$(CC_FOR_BUILD) -$(edit_sgml_OBJECTS) : CFLAGS:=$(CFLAGS_FOR_BUILD) -$(edit_sgml_OBJECTS) : CPPFLAGS:=$(CPPFLAGS_FOR_BUILD) -edit_sgml_LINK = $(CC_FOR_BUILD) -o $@ -# +## check_SCRIPTS = \ check-missing-doc \ $(NULL) @@ -167,15 +165,12 @@ if USEDOCBOOK BUILT_SOURCES += \ $(LOCAL_SGML_FILES) \ $(NULL) -noinst_PROGRAMS += \ - edit-sgml \ - $(NULL) htmldoc_DATA += $(HTML_DIR)/* ## .fncs.sgml: $(AM_V_GEN) $(RM) $@; \ - $(builddir)/edit-sgml$(EXEEXT) $(srcdir)/func.sgml < '$(srcdir)/$*.fncs' > $*.sgml + $(PYTHON) $(srcdir)/edit-sgml.py $(srcdir)/func.sgml '$(srcdir)/$*.fncs' $*.sgml .sgml.txt: $(AM_V_GEN) $(RM) $@; \ $(DOC2TXT) $*.sgml @@ -202,7 +197,7 @@ func.refs: local-fontconfig-devel.sgml $(DOCS_DEPS) confdir.sgml: $(srcdir)/confdir.sgml.in $(AM_V_GEN) sed -e 's,@BASECONFIGDIR\@,${BASECONFIGDIR},' $(srcdir)/$@.in | awk '{if (NR > 1) printf("\n"); printf("%s", $$0);}' > $@ ## -$(DOC_FUNCS_SGML): $(DOC_FUNCS_FNCS) edit-sgml$(EXEEXT) $(srcdir)/func.sgml +$(DOC_FUNCS_SGML): $(DOC_FUNCS_FNCS) $(srcdir)/edit-sgml.py $(srcdir)/func.sgml $(TXT_FILES): $(DOCS_DEPS) $(PDF_FILES): $(DOCS_DEPS) $(HTML_FILES): $(DOCS_DEPS) diff --git a/doc/edit-sgml.c b/doc/edit-sgml.c deleted file mode 100644 index cc2ee76..0000000 --- a/doc/edit-sgml.c +++ /dev/null @@ -1,546 +0,0 @@ -/* - * fontconfig/doc/edit-sgml.c - * - * Copyright © 2003 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of the author(s) not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. The authors make no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -static void * -New (int size); - -static void * -Reallocate (void *p, int size); - -static void -Dispose (void *p); - -typedef enum { False, True } Bool; - -typedef struct { - char *buf; - int size; - int len; -} String; - -static String * -StringNew (void); - -static void -StringAdd (String *s, char c); - -static void -StringAddString (String *s, char *buf); - -static String * -StringMake (char *buf); - -static void -StringDel (String *s); - -static void -StringPut (FILE *f, String *s); - -static void -StringDispose (String *s); - -typedef struct { - String *tag; - String *text; -} Replace; - -static Replace * -ReplaceNew (void); - -static void -ReplaceDispose (Replace *r); - -static void -Bail (const char *format, int line, const char *arg); - -static Replace * -ReplaceRead (FILE *f, int *linep); - -typedef struct _replaceList { - struct _replaceList *next; - Replace *r; -} ReplaceList; - -static ReplaceList * -ReplaceListNew (Replace *r, ReplaceList *next); - -static void -ReplaceListDispose (ReplaceList *l); - -typedef struct { - ReplaceList *head; -} ReplaceSet; - -static ReplaceSet * -ReplaceSetNew (void); - -static void -ReplaceSetDispose (ReplaceSet *s); - -static void -ReplaceSetAdd (ReplaceSet *s, Replace *r); - -static Replace * -ReplaceSetFind (ReplaceSet *s, char *tag); - -static ReplaceSet * -ReplaceSetRead (FILE *f, int *linep); - -typedef struct _skipStack { - struct _skipStack *prev; - int skipping; -} SkipStack; - -static SkipStack * -SkipStackPush (SkipStack *prev, int skipping); - -static SkipStack * -SkipStackPop (SkipStack *prev); - -typedef struct _loopStack { - struct _loopStack *prev; - String *tag; - String *extra; - long pos; -} LoopStack; - -static LoopStack * -LoopStackPush (LoopStack *prev, FILE *f, char *tag); - -static LoopStack * -LoopStackLoop (ReplaceSet *rs, LoopStack *ls, FILE *f); - -static void -LineSkip (FILE *f, int *linep); - -static void -DoReplace (FILE *f, int *linep, ReplaceSet *s); - -#define STRING_INIT 128 - -static void * -New (int size) -{ - void *m = malloc (size); - if (!m) - abort (); - return m; -} - -static void * -Reallocate (void *p, int size) -{ - void *r = realloc (p, size); - - if (!r) - abort (); - return r; -} - -static void -Dispose (void *p) -{ - free (p); -} - -static String * -StringNew (void) -{ - String *s; - - s = New (sizeof (String)); - s->buf = New (STRING_INIT); - s->size = STRING_INIT - 1; - s->buf[0] = '\0'; - s->len = 0; - return s; -} - -static void -StringAdd (String *s, char c) -{ - if (s->len == s->size) - s->buf = Reallocate (s->buf, (s->size *= 2) + 1); - s->buf[s->len++] = c; - s->buf[s->len] = '\0'; -} - -static void -StringAddString (String *s, char *buf) -{ - while (*buf) - StringAdd (s, *buf++); -} - -static String * -StringMake (char *buf) -{ - String *s = StringNew (); - StringAddString (s, buf); - return s; -} - -static void -StringDel (String *s) -{ - if (s->len) - s->buf[--s->len] = '\0'; -} - -static void -StringPut (FILE *f, String *s) -{ - char *b = s->buf; - - while (*b) - putc (*b++, f); -} - -#define StringLast(s) ((s)->len ? (s)->buf[(s)->len - 1] : '\0') - -static void -StringDispose (String *s) -{ - Dispose (s->buf); - Dispose (s); -} - -static Replace * -ReplaceNew (void) -{ - Replace *r = New (sizeof (Replace)); - r->tag = StringNew (); - r->text = StringNew (); - return r; -} - -static void -ReplaceDispose (Replace *r) -{ - StringDispose (r->tag); - StringDispose (r->text); - Dispose (r); -} - -static void -Bail (const char *format, int line, const char *arg) -{ - fprintf (stderr, "fatal: "); - fprintf (stderr, format, line, arg); - fprintf (stderr, "\n"); - exit (1); -} - -static int -Getc (FILE *f, int *linep) -{ - int c = getc (f); - if (c == '\n') - ++(*linep); - return c; -} - -static void -Ungetc (int c, FILE *f, int *linep) -{ - if (c == '\n') - --(*linep); - ungetc (c, f); -} - -static Replace * -ReplaceRead (FILE *f, int *linep) -{ - int c; - Replace *r; - - while ((c = Getc (f, linep)) != '@') - { - if (c == EOF) - return 0; - } - r = ReplaceNew(); - while ((c = Getc (f, linep)) != '@') - { - if (c == EOF) - { - ReplaceDispose (r); - return 0; - } - if (isspace (c)) - Bail ("%d: invalid character after tag %s", *linep, r->tag->buf); - StringAdd (r->tag, c); - } - if (r->tag->buf[0] == '\0') - { - ReplaceDispose (r); - return 0; - } - while (isspace ((c = Getc (f, linep)))) - ; - Ungetc (c, f, linep); - while ((c = Getc (f, linep)) != '@' && c != EOF) - StringAdd (r->text, c); - if (c == '@') - Ungetc (c, f, linep); - while (isspace (StringLast (r->text))) - StringDel (r->text); - if (StringLast(r->text) == '%') - { - StringDel (r->text); - StringAdd (r->text, ' '); - } - return r; -} - -static ReplaceList * -ReplaceListNew (Replace *r, ReplaceList *next) -{ - ReplaceList *l = New (sizeof (ReplaceList)); - l->r = r; - l->next = next; - return l; -} - -static void -ReplaceListDispose (ReplaceList *l) -{ - if (l) - { - ReplaceListDispose (l->next); - ReplaceDispose (l->r); - Dispose (l); - } -} - -static ReplaceSet * -ReplaceSetNew (void) -{ - ReplaceSet *s = New (sizeof (ReplaceSet)); - s->head = 0; - return s; -} - -static void -ReplaceSetDispose (ReplaceSet *s) -{ - ReplaceListDispose (s->head); - Dispose (s); -} - -static void -ReplaceSetAdd (ReplaceSet *s, Replace *r) -{ - s->head = ReplaceListNew (r, s->head); -} - -static Replace * -ReplaceSetFind (ReplaceSet *s, char *tag) -{ - ReplaceList *l; - - for (l = s->head; l; l = l->next) - if (!strcmp (tag, l->r->tag->buf)) - return l->r; - return 0; -} - -static ReplaceSet * -ReplaceSetRead (FILE *f, int *linep) -{ - ReplaceSet *s = ReplaceSetNew (); - Replace *r; - - while ((r = ReplaceRead (f, linep))) - { - while (ReplaceSetFind (s, r->tag->buf)) - StringAdd (r->tag, '+'); - ReplaceSetAdd (s, r); - } - if (!s->head) - { - ReplaceSetDispose (s); - s = 0; - } - return s; -} - -static SkipStack * -SkipStackPush (SkipStack *prev, int skipping) -{ - SkipStack *ss = New (sizeof (SkipStack)); - ss->prev = prev; - ss->skipping = skipping; - return ss; -} - -static SkipStack * -SkipStackPop (SkipStack *prev) -{ - SkipStack *ss = prev->prev; - Dispose (prev); - return ss; -} - -static LoopStack * -LoopStackPush (LoopStack *prev, FILE *f, char *tag) -{ - LoopStack *ls = New (sizeof (LoopStack)); - ls->prev = prev; - ls->tag = StringMake (tag); - ls->extra = StringNew (); - ls->pos = ftell (f); - return ls; -} - -static LoopStack * -LoopStackLoop (ReplaceSet *rs, LoopStack *ls, FILE *f) -{ - String *s = StringMake (ls->tag->buf); - LoopStack *ret = ls; - Bool loop; - - StringAdd (ls->extra, '+'); - StringAddString (s, ls->extra->buf); - loop = ReplaceSetFind (rs, s->buf) != 0; - StringDispose (s); - if (loop) - fseek (f, ls->pos, SEEK_SET); - else - { - ret = ls->prev; - StringDispose (ls->tag); - StringDispose (ls->extra); - Dispose (ls); - } - return ret; -} - -static void -LineSkip (FILE *f, int *linep) -{ - int c; - - while ((c = Getc (f, linep)) == '\n') - ; - Ungetc (c, f, linep); -} - -static void -DoReplace (FILE *f, int *linep, ReplaceSet *s) -{ - int c; - String *tag; - Replace *r; - SkipStack *ss = 0; - LoopStack *ls = 0; - int skipping = 0; - - while ((c = Getc (f, linep)) != EOF) - { - if (c == '@') - { - tag = StringNew (); - while ((c = Getc (f, linep)) != '@') - { - if (c == EOF) - abort (); - StringAdd (tag, c); - } - if (ls) - StringAddString (tag, ls->extra->buf); - switch (tag->buf[0]) { - case '?': - ss = SkipStackPush (ss, skipping); - if (!ReplaceSetFind (s, tag->buf + 1)) - skipping++; - LineSkip (f, linep); - break; - case ':': - if (!ss) - abort (); - if (ss->skipping == skipping) - ++skipping; - else - --skipping; - LineSkip (f, linep); - break; - case ';': - skipping = ss->skipping; - ss = SkipStackPop (ss); - LineSkip (f, linep); - break; - case '{': - ls = LoopStackPush (ls, f, tag->buf + 1); - LineSkip (f, linep); - break; - case '}': - ls = LoopStackLoop (s, ls, f); - LineSkip (f, linep); - break; - default: - r = ReplaceSetFind (s, tag->buf); - if (r && !skipping) - StringPut (stdout, r->text); - break; - } - StringDispose (tag); - } - else if (!skipping) - putchar (c); - } -} - -int -main (int argc, char **argv) -{ - FILE *f; - ReplaceSet *s; - int iline, oline; - - if (!argv[1]) - Bail ("usage: %*s <template.sgml>", 0, argv[0]); - f = fopen (argv[1], "r"); - if (!f) - { - Bail ("can't open file %s", 0, argv[1]); - exit (1); - } - iline = 1; - while ((s = ReplaceSetRead (stdin, &iline))) - { - oline = 1; - DoReplace (f, &oline, s); - ReplaceSetDispose (s); - rewind (f); - } - if (ferror (stdout)) - Bail ("%s", 0, "error writing output"); - exit (0); -} diff --git a/fc-case/fc-case.c b/fc-case/fc-case.c deleted file mode 100644 index 236bff5..0000000 --- a/fc-case/fc-case.c +++ /dev/null @@ -1,363 +0,0 @@ -/* - * fontconfig/fc-case/fc-case.c - * - * Copyright © 2004 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of the author(s) not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. The authors make no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include "fcint.h" -#include <ctype.h> - -#define MAX_OUT 32 -#define MAX_LINE 8192 - -typedef enum _caseFoldClass { CaseFoldCommon, CaseFoldFull, CaseFoldSimple, CaseFoldTurkic } CaseFoldClass; - -typedef struct _caseFoldClassMap { - const char *name; - CaseFoldClass class; -} CaseFoldClassMap; - -static const CaseFoldClassMap caseFoldClassMap[] = { - { "C", CaseFoldCommon }, - { "F", CaseFoldFull }, - { "S", CaseFoldSimple }, - { "T", CaseFoldTurkic }, - { 0, 0 } -}; - -typedef struct _caseFoldRaw { - FcChar32 upper; - CaseFoldClass class; - int nout; - FcChar32 lower[MAX_OUT]; -} CaseFoldRaw; - -static void -panic (const char *reason) -{ - fprintf (stderr, "fc-case: panic %s\n", reason); - exit (1); -} - -int maxExpand; -static FcCaseFold *folds; -int nfolds; - -static FcCaseFold * -addFold (void) -{ - if (folds) - folds = realloc (folds, (nfolds + 1) * sizeof (FcCaseFold)); - else - folds = malloc (sizeof (FcCaseFold)); - if (!folds) - panic ("out of memory"); - return &folds[nfolds++]; -} - -static int -ucs4_to_utf8 (FcChar32 ucs4, - FcChar8 dest[FC_UTF8_MAX_LEN]) -{ - int bits; - FcChar8 *d = dest; - - if (ucs4 < 0x80) { *d++= ucs4; bits= -6; } - else if (ucs4 < 0x800) { *d++= ((ucs4 >> 6) & 0x1F) | 0xC0; bits= 0; } - else if (ucs4 < 0x10000) { *d++= ((ucs4 >> 12) & 0x0F) | 0xE0; bits= 6; } - else if (ucs4 < 0x200000) { *d++= ((ucs4 >> 18) & 0x07) | 0xF0; bits= 12; } - else if (ucs4 < 0x4000000) { *d++= ((ucs4 >> 24) & 0x03) | 0xF8; bits= 18; } - else if (ucs4 < 0x80000000) { *d++= ((ucs4 >> 30) & 0x01) | 0xFC; bits= 24; } - else return 0; - - for ( ; bits >= 0; bits-= 6) { - *d++= ((ucs4 >> bits) & 0x3F) | 0x80; - } - return d - dest; -} - -static int -utf8_size (FcChar32 ucs4) -{ - FcChar8 utf8[FC_UTF8_MAX_LEN]; - return ucs4_to_utf8 (ucs4, utf8 ); -} - -static FcChar8 *foldChars; -static int nfoldChars; -static int maxFoldChars; -static FcChar32 minFoldChar; -static FcChar32 maxFoldChar; - -static void -addChar (FcChar32 c) -{ - FcChar8 utf8[FC_UTF8_MAX_LEN]; - int len; - int i; - - len = ucs4_to_utf8 (c, utf8); - if (foldChars) - foldChars = realloc (foldChars, (nfoldChars + len) * sizeof (FcChar8)); - else - foldChars = malloc (sizeof (FcChar8) * len); - if (!foldChars) - panic ("out of memory"); - for (i = 0; i < len; i++) - foldChars[nfoldChars + i] = utf8[i]; - nfoldChars += len; -} - -static int -foldExtends (FcCaseFold *fold, CaseFoldRaw *raw) -{ - switch (fold->method) { - case FC_CASE_FOLD_RANGE: - if ((short) (raw->lower[0] - raw->upper) != fold->offset) - return 0; - if (raw->upper != fold->upper + fold->count) - return 0; - return 1; - case FC_CASE_FOLD_EVEN_ODD: - if ((short) (raw->lower[0] - raw->upper) != 1) - return 0; - if (raw->upper != fold->upper + fold->count + 1) - return 0; - return 1; - case FC_CASE_FOLD_FULL: - break; - } - return 0; -} - -static const char * -case_fold_method_name (FcChar16 method) -{ - switch (method) { - case FC_CASE_FOLD_RANGE: return "FC_CASE_FOLD_RANGE,"; - case FC_CASE_FOLD_EVEN_ODD: return "FC_CASE_FOLD_EVEN_ODD,"; - case FC_CASE_FOLD_FULL: return "FC_CASE_FOLD_FULL,"; - default: return "unknown"; - } -} - -static void -dump (void) -{ - int i; - - printf ( "#define FC_NUM_CASE_FOLD %d\n", nfolds); - printf ( "#define FC_NUM_CASE_FOLD_CHARS %d\n", nfoldChars); - printf ( "#define FC_MAX_CASE_FOLD_CHARS %d\n", maxFoldChars); - printf ( "#define FC_MAX_CASE_FOLD_EXPAND %d\n", maxExpand); - printf ( "#define FC_MIN_FOLD_CHAR 0x%08x\n", minFoldChar); - printf ( "#define FC_MAX_FOLD_CHAR 0x%08x\n", maxFoldChar); - printf ( "\n"); - - /* - * Dump out ranges - */ - printf ("static const FcCaseFold fcCaseFold[FC_NUM_CASE_FOLD] = {\n"); - for (i = 0; i < nfolds; i++) - { - printf (" { 0x%08x, %-22s 0x%04x, %6d },\n", - folds[i].upper, case_fold_method_name (folds[i].method), - folds[i].count, folds[i].offset); - } - printf ("};\n\n"); - - /* - * Dump out "other" values - */ - - printf ("static const FcChar8 fcCaseFoldChars[FC_NUM_CASE_FOLD_CHARS] = {\n"); - for (i = 0; i < nfoldChars; i++) - { - printf ("0x%02x", foldChars[i]); - if (i != nfoldChars - 1) - { - if ((i & 0xf) == 0xf) - printf (",\n"); - else - printf (","); - } - } - printf ("\n};\n"); -} - -/* - * Read the standard Unicode CaseFolding.txt file - */ -#define SEP "; \t\n" - -static int -parseRaw (char *line, CaseFoldRaw *raw) -{ - char *tok, *end; - int i; - - if (!isxdigit (line[0])) - return 0; - /* - * Get upper case value - */ - tok = strtok (line, SEP); - if (!tok || tok[0] == '#') - return 0; - raw->upper = strtol (tok, &end, 16); - if (end == tok) - return 0; - /* - * Get class - */ - tok = strtok (NULL, SEP); - if (!tok || tok[0] == '#') - return 0; - for (i = 0; caseFoldClassMap[i].name; i++) - if (!strcmp (tok, caseFoldClassMap[i].name)) - { - raw->class = caseFoldClassMap[i].class; - break; - } - if (!caseFoldClassMap[i].name) - return 0; - - /* - * Get list of result characters - */ - for (i = 0; i < MAX_OUT; i++) - { - tok = strtok (NULL, SEP); - if (!tok || tok[0] == '#') - break; - raw->lower[i] = strtol (tok, &end, 16); - if (end == tok) - break; - } - if (i == 0) - return 0; - raw->nout = i; - return 1; -} - -static int -caseFoldReadRaw (FILE *in, CaseFoldRaw *raw) -{ - char line[MAX_LINE]; - - for (;;) - { - if (!fgets (line, sizeof (line) - 1, in)) - return 0; - if (parseRaw (line, raw)) - return 1; - } -} - -int -main (int argc, char **argv) -{ - FcCaseFold *fold = 0; - CaseFoldRaw raw; - int i; - FILE *caseFile; - char line[MAX_LINE]; - int expand; - - if (argc != 2) - panic ("usage: fc-case CaseFolding.txt"); - caseFile = fopen (argv[1], "r"); - if (!caseFile) - panic ("can't open case folding file"); - - while (caseFoldReadRaw (caseFile, &raw)) - { - if (!minFoldChar) - minFoldChar = raw.upper; - maxFoldChar = raw.upper; - switch (raw.class) { - case CaseFoldCommon: - case CaseFoldFull: - if (raw.nout == 1) - { - if (fold && foldExtends (fold, &raw)) - fold->count = raw.upper - fold->upper + 1; - else - { - fold = addFold (); - fold->upper = raw.upper; - fold->offset = raw.lower[0] - raw.upper; - if (fold->offset == 1) - fold->method = FC_CASE_FOLD_EVEN_ODD; - else - fold->method = FC_CASE_FOLD_RANGE; - fold->count = 1; - } - expand = utf8_size (raw.lower[0]) - utf8_size(raw.upper); - } - else - { - fold = addFold (); - fold->upper = raw.upper; - fold->method = FC_CASE_FOLD_FULL; - fold->offset = nfoldChars; - for (i = 0; i < raw.nout; i++) - addChar (raw.lower[i]); - fold->count = nfoldChars - fold->offset; - if (fold->count > maxFoldChars) - maxFoldChars = fold->count; - expand = fold->count - utf8_size (raw.upper); - } - if (expand > maxExpand) - maxExpand = expand; - break; - case CaseFoldSimple: - break; - case CaseFoldTurkic: - break; - } - } - /* - * Scan the input until the marker is found - */ - - while (fgets (line, sizeof (line), stdin)) - { - if (!strncmp (line, "@@@", 3)) - break; - fputs (line, stdout); - } - - /* - * Dump these tables - */ - dump (); - - /* - * And flush out the rest of the input file - */ - - while (fgets (line, sizeof (line), stdin)) - fputs (line, stdout); - - fflush (stdout); - exit (ferror (stdout)); -} diff --git a/fc-lang/Makefile.am b/fc-lang/Makefile.am index 54bdb20..eaa5249 100644 --- a/fc-lang/Makefile.am +++ b/fc-lang/Makefile.am @@ -25,7 +25,7 @@ TAG = lang DEPS = $(ORTH) -ARGS = -d $(srcdir) $(ORTH) +ARGS = --directory $(srcdir) $(ORTH) DIST = $(ORTH) include $(top_srcdir)/Tools.mk diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c deleted file mode 100644 index 503d712..0000000 --- a/fc-lang/fc-lang.c +++ /dev/null @@ -1,595 +0,0 @@ -/* - * fontconfig/fc-lang/fc-lang.c - * - * Copyright © 2002 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of the author(s) not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. The authors make no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#include "fccharset.c" -#include "fcstr.c" -#include "fcserialize.c" - -/* - * fc-lang - * - * Read a set of language orthographies and build C declarations for - * charsets which can then be used to identify which languages are - * supported by a given font. Note that this uses some utilities - * from the fontconfig library, so the necessary file is simply - * included in this compilation. A couple of extra utility - * functions are also needed in slightly modified form - */ - -FcPrivate void -FcCacheObjectReference (void *object FC_UNUSED) -{ -} - -FcPrivate void -FcCacheObjectDereference (void *object FC_UNUSED) -{ -} - -FcPrivate FcChar8 * -FcLangNormalize (const FcChar8 *lang FC_UNUSED) -{ - return NULL; -} - -int FcDebugVal; - -FcChar8 * -FcConfigHome (void) -{ - return (FcChar8 *) getenv ("HOME"); -} - -static void -fatal (const char *file, int lineno, const char *msg) -{ - if (lineno) - fprintf (stderr, "%s:%d: %s\n", file, lineno, msg); - else - fprintf (stderr, "%s: %s\n", file, msg); - exit (1); -} - -static char * -get_line (FILE *f, char *buf, int *lineno) -{ - char *hash; - char *line; - int end; - -next: - line = buf; - if (!fgets (line, 1024, f)) - return 0; - ++(*lineno); - hash = strchr (line, '#'); - if (hash) - *hash = '\0'; - - while (line[0] && isspace (line[0])) - line++; - end = strlen (line); - while (end > 0 && isspace (line[end-1])) - line[--end] = '\0'; - - if (line[0] == '\0' || line[0] == '\n' || line[0] == '\r') - goto next; - - return line; -} - -static char *dir = 0; - -static FILE * -scanopen (char *file) -{ - FILE *f; - - f = fopen (file, "r"); - if (!f && dir) - { - char path[1024]; - - strcpy (path, dir); - strcat (path, "/"); - strcat (path, file); - f = fopen (path, "r"); - } - return f; -} - -/* - * build a single charset from a source file - * - * The file format is quite simple, either - * a single hex value or a pair separated with a dash - * - * Comments begin with '#' - */ - -static FcCharSet * -scan (FILE *f, char *file, FcCharSetFreezer *freezer) -{ - FcCharSet *c = 0; - FcCharSet *n; - FcBool del; - int start, end, ucs4; - char buf[1024]; - char *line; - int lineno = 0; - - while ((line = get_line (f, buf, &lineno))) - { - if (!strncmp (line, "include", 7)) - { - FILE *included_f; - char *included_file; - included_file = strchr (line, ' '); - if (!included_file) - fatal (file, lineno, - "invalid syntax, expected: include filename"); - while (isspace(*included_file)) - included_file++; - included_f = scanopen (included_file); - if (!included_f) - fatal (included_file, 0, "can't open"); - n = scan (included_f, included_file, freezer); - fclose (included_f); - if (!c) - c = FcCharSetCreate (); - if (!FcCharSetMerge (c, n, NULL)) - fatal (file, lineno, "out of memory"); - FcCharSetDestroy (n); - continue; - } - del = FcFalse; - if (line[0] == '-') - { - del = FcTrue; - line++; - } - if (strchr (line, '-')) - { - if (sscanf (line, "%x-%x", &start, &end) != 2) - fatal (file, lineno, "parse error"); - } - else if (strstr (line, "..")) - { - if (sscanf (line, "%x..%x", &start, &end) != 2) - fatal (file, lineno, "parse error"); - } - else - { - if (sscanf (line, "%x", &start) != 1) - fatal (file, lineno, "parse error"); - end = start; - } - if (!c) - c = FcCharSetCreate (); - for (ucs4 = start; ucs4 <= end; ucs4++) - { - if (!((del ? FcCharSetDelChar : FcCharSetAddChar) (c, ucs4))) - fatal (file, lineno, "out of memory"); - } - } - n = (FcCharSet *) FcCharSetFreeze (freezer, c); - FcCharSetDestroy (c); - return n; -} - -/* - * Convert a file name into a name suitable for C declarations - */ -static char * -get_name (char *file) -{ - char *name; - char *dot; - - dot = strchr (file, '.'); - if (!dot) - dot = file + strlen(file); - name = malloc (dot - file + 1); - strncpy (name, file, dot - file); - name[dot-file] = '\0'; - return name; -} - -/* - * Convert a C name into a language name - */ -static char * -get_lang (char *name) -{ - char *lang = malloc (strlen (name) + 1); - char *l = lang; - char c; - - while ((c = *name++)) - { - if (isupper ((int) (unsigned char) c)) - c = tolower ((int) (unsigned char) c); - if (c == '_') - c = '-'; - if (c == ' ') - continue; - *l++ = c; - } - *l++ = '\0'; - return lang; -} - -typedef struct _Entry { - int id; - char *file; -} Entry; - -static int compare (const void *a, const void *b) -{ - const Entry *as = a, *bs = b; - return FcStrCmpIgnoreCase ((const FcChar8 *) as->file, (const FcChar8 *) bs->file); -} - -#define MAX_LANG 1024 -#define MAX_LANG_SET_MAP ((MAX_LANG + 31) / 32) - -#define BitSet(map, i) ((map)[(entries[i].id)>>5] |= ((FcChar32) 1U << ((entries[i].id) & 0x1f))) - -int -main (int argc FC_UNUSED, char **argv) -{ - static Entry entries[MAX_LANG + 1]; - static FcCharSet *sets[MAX_LANG]; - static int duplicate[MAX_LANG]; - static int country[MAX_LANG]; - static char *names[MAX_LANG]; - static char *langs[MAX_LANG]; - static int off[MAX_LANG]; - FILE *f; - int ncountry = 0; - int i = 0; - int nsets = 0; - int argi; - FcCharLeaf **leaves; - int total_leaves = 0; - int l, sl, tl, tn; - static char line[1024]; - static FcChar32 map[MAX_LANG_SET_MAP]; - int num_lang_set_map; - int setRangeStart[26]; - int setRangeEnd[26]; - FcChar8 setRangeChar; - FcCharSetFreezer *freezer; - - freezer = FcCharSetFreezerCreate (); - if (!freezer) - fatal (argv[0], 0, "out of memory"); - argi = 1; - while (argv[argi]) - { - if (!strcmp (argv[argi], "-d")) - { - argi++; - dir = argv[argi++]; - continue; - } - if (i == MAX_LANG) - fatal (argv[0], 0, "Too many languages"); - entries[i].id = i; - entries[i].file = argv[argi++]; - i++; - } - entries[i].file = 0; - qsort (entries, i, sizeof (Entry), compare); - i = 0; - while (entries[i].file) - { - f = scanopen (entries[i].file); - if (!f) - fatal (entries[i].file, 0, strerror (errno)); - sets[i] = scan (f, entries[i].file, freezer); - names[i] = get_name (entries[i].file); - langs[i] = get_lang(names[i]); - if (strchr (langs[i], '-')) - country[ncountry++] = i; - - total_leaves += sets[i]->num; - i++; - fclose (f); - } - nsets = i; - sets[i] = 0; - leaves = malloc (total_leaves * sizeof (FcCharLeaf *)); - tl = 0; - /* - * Find unique leaves - */ - for (i = 0; sets[i]; i++) - { - for (sl = 0; sl < sets[i]->num; sl++) - { - for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetLeaf(sets[i], sl)) - break; - if (l == tl) - leaves[tl++] = FcCharSetLeaf(sets[i], sl); - } - } - - /* - * Scan the input until the marker is found - */ - - while (fgets (line, sizeof (line), stdin)) - { - if (!strncmp (line, "@@@", 3)) - break; - fputs (line, stdout); - } - - printf ("/* total size: %d unique leaves: %d */\n\n", - total_leaves, tl); - - /* - * Find duplicate charsets - */ - duplicate[0] = -1; - for (i = 1; sets[i]; i++) - { - int j; - - duplicate[i] = -1; - for (j = 0; j < i; j++) - if (sets[j] == sets[i]) - { - duplicate[i] = j; - break; - } - } - - tn = 0; - for (i = 0; sets[i]; i++) { - if (duplicate[i] >= 0) - continue; - off[i] = tn; - tn += sets[i]->num; - } - - printf ("#define LEAF0 (%d * sizeof (FcLangCharSet))\n", nsets); - printf ("#define OFF0 (LEAF0 + %d * sizeof (FcCharLeaf))\n", tl); - printf ("#define NUM0 (OFF0 + %d * sizeof (uintptr_t))\n", tn); - printf ("#define SET(n) (n * sizeof (FcLangCharSet) + offsetof (FcLangCharSet, charset))\n"); - printf ("#define OFF(s,o) (OFF0 + o * sizeof (uintptr_t) - SET(s))\n"); - printf ("#define NUM(s,n) (NUM0 + n * sizeof (FcChar16) - SET(s))\n"); - printf ("#define LEAF(o,l) (LEAF0 + l * sizeof (FcCharLeaf) - (OFF0 + o * sizeof (intptr_t)))\n"); - printf ("#define fcLangCharSets (fcLangData.langCharSets)\n"); - printf ("#define fcLangCharSetIndices (fcLangData.langIndices)\n"); - printf ("#define fcLangCharSetIndicesInv (fcLangData.langIndicesInv)\n"); - printf ("\n"); - - printf ("static const struct {\n" - " FcLangCharSet langCharSets[%d];\n" - " FcCharLeaf leaves[%d];\n" - " uintptr_t leaf_offsets[%d];\n" - " FcChar16 numbers[%d];\n" - " FcChar%s langIndices[%d];\n" - " FcChar%s langIndicesInv[%d];\n" - "} fcLangData = {\n", - nsets, tl, tn, tn, - nsets < 256 ? "8 " : "16", nsets, nsets < 256 ? "8 " : "16", nsets); - - /* - * Dump sets - */ - - printf ("{\n"); - for (i = 0; sets[i]; i++) - { - int j = duplicate[i]; - - if (j < 0) - j = i; - - printf (" { \"%s\", " - " { FC_REF_CONSTANT, %d, OFF(%d,%d), NUM(%d,%d) } }, /* %d */\n", - langs[i], - sets[j]->num, i, off[j], i, off[j], i); - } - printf ("},\n"); - - /* - * Dump leaves - */ - printf ("{\n"); - for (l = 0; l < tl; l++) - { - printf (" { { /* %d */", l); - for (i = 0; i < 256/32; i++) - { - if (i % 4 == 0) - printf ("\n "); - printf (" 0x%08x,", leaves[l]->map[i]); - } - printf ("\n } },\n"); - } - printf ("},\n"); - - /* - * Dump leaves - */ - printf ("{\n"); - for (i = 0; sets[i]; i++) - { - int n; - - if (duplicate[i] >= 0) - continue; - printf (" /* %s */\n", names[i]); - for (n = 0; n < sets[i]->num; n++) - { - if (n % 4 == 0) - printf (" "); - for (l = 0; l < tl; l++) - if (leaves[l] == FcCharSetLeaf(sets[i], n)) - break; - if (l == tl) - fatal (names[i], 0, "can't find leaf"); - printf (" LEAF(%3d,%3d),", off[i], l); - if (n % 4 == 3) - printf ("\n"); - } - if (n % 4 != 0) - printf ("\n"); - } - printf ("},\n"); - - - printf ("{\n"); - for (i = 0; sets[i]; i++) - { - int n; - - if (duplicate[i] >= 0) - continue; - printf (" /* %s */\n", names[i]); - for (n = 0; n < sets[i]->num; n++) - { - if (n % 8 == 0) - printf (" "); - printf (" 0x%04x,", FcCharSetNumbers (sets[i])[n]); - if (n % 8 == 7) - printf ("\n"); - } - if (n % 8 != 0) - printf ("\n"); - } - printf ("},\n"); - - /* langIndices */ - printf ("{\n"); - for (i = 0; sets[i]; i++) - { - printf (" %d, /* %s */\n", entries[i].id, names[i]); - } - printf ("},\n"); - - /* langIndicesInv */ - printf ("{\n"); - { - static int entries_inv[MAX_LANG]; - for (i = 0; sets[i]; i++) - entries_inv[entries[i].id] = i; - for (i = 0; sets[i]; i++) - printf (" %d, /* %s */\n", entries_inv[i], names[entries_inv[i]]); - } - printf ("}\n"); - - printf ("};\n\n"); - - printf ("#define NUM_LANG_CHAR_SET %d\n", i); - num_lang_set_map = (i + 31) / 32; - printf ("#define NUM_LANG_SET_MAP %d\n", num_lang_set_map); - /* - * Dump indices with country codes - */ - if (ncountry) - { - int c; - int ncountry_ent = 0; - printf ("\n"); - printf ("static const FcChar32 fcLangCountrySets[][NUM_LANG_SET_MAP] = {\n"); - for (c = 0; c < ncountry; c++) - { - i = country[c]; - if (i >= 0) - { - int lang = strchr (langs[i], '-') - langs[i]; - int d, k; - - for (k = 0; k < num_lang_set_map; k++) - map[k] = 0; - - BitSet (map, i); - for (d = c + 1; d < ncountry; d++) - { - int j = country[d]; - if (j >= 0 && !strncmp (langs[j], langs[i], lang + 1)) - { - BitSet(map, j); - country[d] = -1; - } - } - printf (" {"); - for (k = 0; k < num_lang_set_map; k++) - printf (" 0x%08x,", map[k]); - printf (" }, /* %*.*s */\n", - lang, lang, langs[i]); - ++ncountry_ent; - } - } - printf ("};\n\n"); - printf ("#define NUM_COUNTRY_SET %d\n", ncountry_ent); - } - - - /* - * Find ranges for each letter for faster searching - */ - setRangeChar = 'a'; - memset(setRangeStart, '\0', sizeof (setRangeStart)); - memset(setRangeEnd, '\0', sizeof (setRangeEnd)); - for (i = 0; sets[i]; i++) - { - char c = names[i][0]; - - while (setRangeChar <= c && c <= 'z') - setRangeStart[setRangeChar++ - 'a'] = i; - } - while (setRangeChar <= 'z') /* no language code starts with these letters */ - setRangeStart[setRangeChar++ - 'a'] = i; - - for (setRangeChar = 'a'; setRangeChar < 'z'; setRangeChar++) - setRangeEnd[setRangeChar - 'a'] = setRangeStart[setRangeChar+1-'a'] - 1; - setRangeEnd[setRangeChar - 'a'] = i - 1; - - /* - * Dump sets start/finish for the fastpath - */ - printf ("\n"); - printf ("static const FcLangCharSetRange fcLangCharSetRanges[] = {\n"); - printf ("\n"); - for (setRangeChar = 'a'; setRangeChar <= 'z' ; setRangeChar++) - { - printf (" { %d, %d }, /* %c */\n", - setRangeStart[setRangeChar - 'a'], - setRangeEnd[setRangeChar - 'a'], setRangeChar); - } - printf ("};\n\n"); - - while (fgets (line, sizeof (line), stdin)) - fputs (line, stdout); - - fflush (stdout); - exit (ferror (stdout)); -} _______________________________________________ Fontconfig mailing list Fontconfig@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/fontconfig