summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-06-30 22:08:26 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-06-30 22:08:26 +0000
commitb49e8181c16e91afc0b2e771243f9adab9bc8b5d (patch)
treef3b463eec927649a43bd0b22464a5118f0b0d4a7
parent036da71c38c9d81a087f20079cc7b96154fc5a3c (diff)
downloadpango-b49e8181c16e91afc0b2e771243f9adab9bc8b5d.tar.gz
A bunch of simple functions for reading from files, manipulating strings
Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com> * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions for reading from files, manipulating strings as necessary for config files. Also, a simple gnome-config/win.ini style config file reader. * pango/modules.c: Remove DOTFILES stuff. Instead, read names of modules file from pangorc. (Which can be set from PANGO_RC_FILE). Rewrite parsing code using pango-utils.c. * pango/pangox-fontmap.c: Read list of files from PangoX/AliasFiles key. Rewrite parsing code for alias files using pango-utils.c. * examples/pangox.aliases: Move to new name from pangox_aliases, reformat using new parsing code. * examples/pangorc (AliasFiles) examples/pango-viewer: Add a pangorc file for in-place testing. * pango/querymodules.c (main): Add comment to the top of the output indicating that the file should not be hand-edited.
-rw-r--r--ChangeLog24
-rw-r--r--ChangeLog.pre-1-024
-rw-r--r--ChangeLog.pre-1-1024
-rw-r--r--ChangeLog.pre-1-224
-rw-r--r--ChangeLog.pre-1-424
-rw-r--r--ChangeLog.pre-1-624
-rw-r--r--ChangeLog.pre-1-824
-rw-r--r--examples/Makefile.am4
-rw-r--r--examples/pangorc10
-rw-r--r--examples/pangox.aliases24
-rw-r--r--examples/pangox_aliases8
-rw-r--r--examples/viewer-qt.cc4
-rw-r--r--pango.spec.in7
-rw-r--r--pango/Makefile.am6
-rw-r--r--pango/modules.c220
-rw-r--r--pango/pangox-fontmap.c254
-rw-r--r--pango/querymodules.c80
17 files changed, 441 insertions, 344 deletions
diff --git a/ChangeLog b/ChangeLog
index dc99f44c..3aa24c7d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
+ for reading from files, manipulating strings as necessary for
+ config files. Also, a simple gnome-config/win.ini style
+ config file reader.
+
+ * pango/modules.c: Remove DOTFILES stuff. Instead, read names
+ of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
+ Rewrite parsing code using pango-utils.c.
+
+ * pango/pangox-fontmap.c: Read list of files from
+ PangoX/AliasFiles key. Rewrite parsing code for alias files using
+ pango-utils.c.
+
+ * examples/pangox.aliases: Move to new name from pangox_aliases,
+ reformat using new parsing code.
+
+ * examples/pangorc (AliasFiles) examples/pango-viewer: Add a
+ pangorc file for in-place testing.
+
+ * pango/querymodules.c (main): Add comment to the top of
+ the output indicating that the file should not be hand-edited.
+
Thu Jun 29 18:13:47 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-coverage.c: Fix various aspects of expanding
diff --git a/ChangeLog.pre-1-0 b/ChangeLog.pre-1-0
index dc99f44c..3aa24c7d 100644
--- a/ChangeLog.pre-1-0
+++ b/ChangeLog.pre-1-0
@@ -1,3 +1,27 @@
+Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
+ for reading from files, manipulating strings as necessary for
+ config files. Also, a simple gnome-config/win.ini style
+ config file reader.
+
+ * pango/modules.c: Remove DOTFILES stuff. Instead, read names
+ of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
+ Rewrite parsing code using pango-utils.c.
+
+ * pango/pangox-fontmap.c: Read list of files from
+ PangoX/AliasFiles key. Rewrite parsing code for alias files using
+ pango-utils.c.
+
+ * examples/pangox.aliases: Move to new name from pangox_aliases,
+ reformat using new parsing code.
+
+ * examples/pangorc (AliasFiles) examples/pango-viewer: Add a
+ pangorc file for in-place testing.
+
+ * pango/querymodules.c (main): Add comment to the top of
+ the output indicating that the file should not be hand-edited.
+
Thu Jun 29 18:13:47 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-coverage.c: Fix various aspects of expanding
diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10
index dc99f44c..3aa24c7d 100644
--- a/ChangeLog.pre-1-10
+++ b/ChangeLog.pre-1-10
@@ -1,3 +1,27 @@
+Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
+ for reading from files, manipulating strings as necessary for
+ config files. Also, a simple gnome-config/win.ini style
+ config file reader.
+
+ * pango/modules.c: Remove DOTFILES stuff. Instead, read names
+ of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
+ Rewrite parsing code using pango-utils.c.
+
+ * pango/pangox-fontmap.c: Read list of files from
+ PangoX/AliasFiles key. Rewrite parsing code for alias files using
+ pango-utils.c.
+
+ * examples/pangox.aliases: Move to new name from pangox_aliases,
+ reformat using new parsing code.
+
+ * examples/pangorc (AliasFiles) examples/pango-viewer: Add a
+ pangorc file for in-place testing.
+
+ * pango/querymodules.c (main): Add comment to the top of
+ the output indicating that the file should not be hand-edited.
+
Thu Jun 29 18:13:47 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-coverage.c: Fix various aspects of expanding
diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2
index dc99f44c..3aa24c7d 100644
--- a/ChangeLog.pre-1-2
+++ b/ChangeLog.pre-1-2
@@ -1,3 +1,27 @@
+Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
+ for reading from files, manipulating strings as necessary for
+ config files. Also, a simple gnome-config/win.ini style
+ config file reader.
+
+ * pango/modules.c: Remove DOTFILES stuff. Instead, read names
+ of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
+ Rewrite parsing code using pango-utils.c.
+
+ * pango/pangox-fontmap.c: Read list of files from
+ PangoX/AliasFiles key. Rewrite parsing code for alias files using
+ pango-utils.c.
+
+ * examples/pangox.aliases: Move to new name from pangox_aliases,
+ reformat using new parsing code.
+
+ * examples/pangorc (AliasFiles) examples/pango-viewer: Add a
+ pangorc file for in-place testing.
+
+ * pango/querymodules.c (main): Add comment to the top of
+ the output indicating that the file should not be hand-edited.
+
Thu Jun 29 18:13:47 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-coverage.c: Fix various aspects of expanding
diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4
index dc99f44c..3aa24c7d 100644
--- a/ChangeLog.pre-1-4
+++ b/ChangeLog.pre-1-4
@@ -1,3 +1,27 @@
+Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
+ for reading from files, manipulating strings as necessary for
+ config files. Also, a simple gnome-config/win.ini style
+ config file reader.
+
+ * pango/modules.c: Remove DOTFILES stuff. Instead, read names
+ of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
+ Rewrite parsing code using pango-utils.c.
+
+ * pango/pangox-fontmap.c: Read list of files from
+ PangoX/AliasFiles key. Rewrite parsing code for alias files using
+ pango-utils.c.
+
+ * examples/pangox.aliases: Move to new name from pangox_aliases,
+ reformat using new parsing code.
+
+ * examples/pangorc (AliasFiles) examples/pango-viewer: Add a
+ pangorc file for in-place testing.
+
+ * pango/querymodules.c (main): Add comment to the top of
+ the output indicating that the file should not be hand-edited.
+
Thu Jun 29 18:13:47 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-coverage.c: Fix various aspects of expanding
diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6
index dc99f44c..3aa24c7d 100644
--- a/ChangeLog.pre-1-6
+++ b/ChangeLog.pre-1-6
@@ -1,3 +1,27 @@
+Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
+ for reading from files, manipulating strings as necessary for
+ config files. Also, a simple gnome-config/win.ini style
+ config file reader.
+
+ * pango/modules.c: Remove DOTFILES stuff. Instead, read names
+ of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
+ Rewrite parsing code using pango-utils.c.
+
+ * pango/pangox-fontmap.c: Read list of files from
+ PangoX/AliasFiles key. Rewrite parsing code for alias files using
+ pango-utils.c.
+
+ * examples/pangox.aliases: Move to new name from pangox_aliases,
+ reformat using new parsing code.
+
+ * examples/pangorc (AliasFiles) examples/pango-viewer: Add a
+ pangorc file for in-place testing.
+
+ * pango/querymodules.c (main): Add comment to the top of
+ the output indicating that the file should not be hand-edited.
+
Thu Jun 29 18:13:47 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-coverage.c: Fix various aspects of expanding
diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8
index dc99f44c..3aa24c7d 100644
--- a/ChangeLog.pre-1-8
+++ b/ChangeLog.pre-1-8
@@ -1,3 +1,27 @@
+Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
+ for reading from files, manipulating strings as necessary for
+ config files. Also, a simple gnome-config/win.ini style
+ config file reader.
+
+ * pango/modules.c: Remove DOTFILES stuff. Instead, read names
+ of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
+ Rewrite parsing code using pango-utils.c.
+
+ * pango/pangox-fontmap.c: Read list of files from
+ PangoX/AliasFiles key. Rewrite parsing code for alias files using
+ pango-utils.c.
+
+ * examples/pangox.aliases: Move to new name from pangox_aliases,
+ reformat using new parsing code.
+
+ * examples/pangorc (AliasFiles) examples/pango-viewer: Add a
+ pangorc file for in-place testing.
+
+ * pango/querymodules.c (main): Add comment to the top of
+ the output indicating that the file should not be hand-edited.
+
Thu Jun 29 18:13:47 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-coverage.c: Fix various aspects of expanding
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 4c3ae795..225498d1 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -34,7 +34,7 @@ pango.modules:
( cd ../modules && \
../pango/pango-querymodules `find . -name '*.so'` > ../examples/pango.modules )
-EXTRA_DIST=HELLO.utf8 muru.utf pangox_aliases
+EXTRA_DIST=HELLO.utf8 muru.utf pangox.aliases
-alias_DATA = pangox_aliases
+alias_DATA = pangox.aliases
diff --git a/examples/pangorc b/examples/pangorc
new file mode 100644
index 00000000..bfbecbd6
--- /dev/null
+++ b/examples/pangorc
@@ -0,0 +1,10 @@
+#
+# pangorc file for uninstalled operation. If pango-viewer is run with
+# this file in the current directory it will set it as PANGO_RC_FILE
+#
+
+[Pango]
+ModuleFiles = ./pango.modules
+
+[PangoX]
+AliasFiles = ./pangox.aliases \ No newline at end of file
diff --git a/examples/pangox.aliases b/examples/pangox.aliases
new file mode 100644
index 00000000..3ab9bf45
--- /dev/null
+++ b/examples/pangox.aliases
@@ -0,0 +1,24 @@
+# File defining aliases of PangoFontDescription to X font set
+#
+# family style variant weight stretch XLFD
+
+sans normal normal normal normal "-*-helvetica-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -*-fixed-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -kaist-iyagi-bold-r-normal--*-*-*-*-*-*-johab-1,\
+ -*-song ti-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -tamil-tscakaram-medium-r-normal--*-*-*-*-*-*-tscii-0,\
+ -*-devanagari-medium-r-normal--*-*-*-*-*-*-iso10646-dev"
+
+serif normal normal normal normal "-*-times-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -*-fixed-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -kaist-iyagi-bold-r-normal--*-*-*-*-*-*-johab-1,\
+ -*-song ti-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -tamil-tscakaram-medium-r-normal--*-*-*-*-*-*-tscii-0,\
+ -*-devanagari-medium-r-normal--*-*-*-*-*-*-iso10646-dev"
+
+monospace normal normal normal normal "-*-fixed-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -*-fixed-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -kaist-iyagi-bold-r-normal--*-*-*-*-*-*-johab-1,\
+ -*-song ti-medium-r-normal--*-*-*-*-*-*-*-*,\
+ -tamil-tscakaram-medium-r-normal--*-*-*-*-*-*-tscii-0,\
+ -*-devanagari-medium-r-normal--*-*-*-*-*-*-iso10646-dev"
diff --git a/examples/pangox_aliases b/examples/pangox_aliases
deleted file mode 100644
index 5926511d..00000000
--- a/examples/pangox_aliases
+++ /dev/null
@@ -1,8 +0,0 @@
-# File defining aliases of PangoFontDescription to X font set
-#
-# family style variant weight stretch XLFD
-
-sans normal normal normal normal "-*-helvetica-medium-r-normal--*-*-*-*-*-*-*-*,-*-fixed-medium-r-normal--*-*-*-*-*-*-*-*,-kaist-iyagi-bold-r-normal--*-*-*-*-*-*-johab-1,-*-song ti-medium-r-normal--*-*-*-*-*-*-*-*,-tamil-tscakaram-medium-r-normal--*-*-*-*-*-*-tscii-0,-*-devanagari-medium-r-normal--*-*-*-*-*-*-iso10646-dev"
-serif normal normal normal normal "-*-times-medium-r-normal--*-*-*-*-*-*-*-*,-*-fixed-medium-r-normal--*-*-*-*-*-*-*-*,-kaist-iyagi-bold-r-normal--*-*-*-*-*-*-johab-1,-*-song ti-medium-r-normal--*-*-*-*-*-*-*-*,-tamil-tscakaram-medium-r-normal--*-*-*-*-*-*-tscii-0,-*-devanagari-medium-r-normal--*-*-*-*-*-*-iso10646-dev"
-monospace normal normal normal normal "-*-fixed-medium-r-normal--*-*-*-*-*-*-*-*,-kaist-iyagi-bold-r-normal--*-*-*-*-*-*-johab-1,-*-song ti-medium-r-normal--*-*-*-*-*-*-*-*,-tamil-tscakaram-medium-r-normal--*-*-*-*-*-*-tscii-0,-*-devanagari-medium-r-normal--*-*-*-*-*-*-iso10646-dev"
-
diff --git a/examples/viewer-qt.cc b/examples/viewer-qt.cc
index b2522063..0f5aeae0 100644
--- a/examples/viewer-qt.cc
+++ b/examples/viewer-qt.cc
@@ -27,6 +27,7 @@
#include <qcdestyle.h>
#include <qcombobox.h>
#include <qfile.h>
+#include <qfileinfo.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qspinbox.h>
@@ -502,6 +503,9 @@ main (int argc, char **argv)
QApplication::setStyle (new QCDEStyle());
+ if (QFileInfo ("./pangorc").exists ())
+ putenv ("PANGO_RC_FILE=./pangorc");
+
ViewerWindow *vw = new ViewerWindow ();
vw->show();
diff --git a/pango.spec.in b/pango.spec.in
index dccdaca0..853a9e4b 100644
--- a/pango.spec.in
+++ b/pango.spec.in
@@ -49,10 +49,7 @@ rm -rf $RPM_BUILD_ROOT
%post
/sbin/ldconfig
-if ! test -d /var/lib/pango ; then
- mkdir -p /var/lib/pango/
-fi
-/usr/bin/pango-querymodules /usr/lib/pango/modules/*.so > /var/lib/pango/pango.modules
+/usr/bin/pango-querymodules > /etc/pango/pango.modules
%postun -p /sbin/ldconfig
@@ -63,7 +60,7 @@ fi
%{prefix}/bin/pango-querymodules
%{prefix}/bin/pango-viewer
%{prefix}/lib/pango/modules/*
-%config /etc/pango/pangox_aliases
+%config /etc/pango/pangox.aliases
%files devel
%defattr(-, root, root)
diff --git a/pango/Makefile.am b/pango/Makefile.am
index ea86de71..ee0961bc 100644
--- a/pango/Makefile.am
+++ b/pango/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to create Makefile.in.
-INCLUDES=-DDOTMODULEDIR=\"$(sysconfdir)/pango\" -DSYSCONFDIR=\"$(sysconfdir)\" \
- -DLOCALSTATEDIR=\"$(localstatedir)\" -I$(top_srcdir)
+INCLUDES=-DSYSCONFDIR=\"$(sysconfdir)\" -DLIBDIR=\"$(libdir)\"
+ -I$(top_srcdir)
lib_LTLIBRARIES = libpango.la libpangox.la
bin_PROGRAMS = pango-querymodules
@@ -20,6 +20,7 @@ libpango_la_SOURCES = \
pango-fontmap.c \
pango-item.c \
pango-layout.c \
+ pango-utils.c \
reorder-items.c \
shape.c
@@ -53,6 +54,7 @@ pangoinclude_HEADERS = \
pango-layout.h \
pango-modules.h \
pango-types.h \
+ pango-utils.h \
pangox.h
#
diff --git a/pango/modules.c b/pango/modules.c
index fcd42813..b7572aac 100644
--- a/pango/modules.c
+++ b/pango/modules.c
@@ -22,12 +22,13 @@
#include <ctype.h>
#include <stdio.h>
#include <string.h>
-#include <dirent.h>
#include <limits.h>
+#include <errno.h>
#include <gmodule.h>
#include "pango-modules.h"
+#include "pango-utils.h"
#include "modules.h"
typedef struct _PangoMapInfo PangoMapInfo;
@@ -165,31 +166,6 @@ pango_engine_pair_get_engine (PangoEnginePair *pair)
return pair->engine;
}
-
-static char *
-readline(FILE *file)
-{
- static GString *bufstring = NULL;
- int c;
-
- if (!bufstring)
- bufstring = g_string_new (NULL);
- else
- g_string_truncate (bufstring, 0);
-
- while ((c = getc(file)) != EOF)
- {
- g_string_append_c (bufstring, c);
- if (c == '\n')
- break;
- }
-
- if (bufstring->len == 0)
- return NULL;
- else
- return g_strdup (bufstring->str);
-}
-
static void
add_included_modules (void)
{
@@ -217,87 +193,88 @@ add_included_modules (void)
}
static gboolean /* Returns true if succeeded, false if failed */
-process_module_file(FILE *module_file)
+process_module_file (FILE *module_file)
{
- char *line;
+ GString *line_buf = g_string_new (NULL);
+ GString *tmp_buf = g_string_new (NULL);
+ gboolean have_error = FALSE;
- while ((line = readline (module_file)))
+ while (pango_read_line (module_file, line_buf))
{
PangoEnginePair *pair = g_new (PangoEnginePair, 1);
PangoEngineRange *range;
- GList *ranges;
+ GList *ranges = NULL;
GList *tmp_list;
- char *p, *q;
+
+ const char *p, *q;
int i;
- int start;
- int end;
+ int start, end;
pair->included = FALSE;
- p = line;
- q = line;
- ranges = NULL;
+ p = line_buf->str;
+
+ if (!pango_skip_space (&p))
+ continue;
/* Break line into words on whitespace */
i = 0;
while (1)
{
- if (!*p || isspace(*p))
+ if (!pango_scan_string (&p, tmp_buf))
{
- switch (i)
- {
- case 0:
- pair->load_info = g_strndup (q, p-q);
- break;
- case 1:
- pair->info.id = g_strndup (q, p-q);
- break;
- case 2:
- pair->info.engine_type = g_strndup (q, p-q);
- break;
- case 3:
- pair->info.render_type = g_strndup (q, p-q);
- break;
- default:
- range = g_new (PangoEngineRange, 1);
- if (sscanf(q, "%d-%d:", &start, &end) != 2)
- {
- fprintf(stderr, "Error reading pango.modules");
- return FALSE;
- }
- q = strchr (q, ':');
- if (!q)
- {
- fprintf(stderr, "Error reading pango.modules");
- return FALSE;
- }
- q++;
- range->start = start;
- range->end = end;
- range->langs = g_strndup (q, p-q);
+ have_error = TRUE;
+ goto error;
+ }
- ranges = g_list_prepend (ranges, range);
+ switch (i)
+ {
+ case 0:
+ pair->load_info = g_strdup (tmp_buf->str);
+ break;
+ case 1:
+ pair->info.id = g_strdup (tmp_buf->str);
+ break;
+ case 2:
+ pair->info.engine_type = g_strdup (tmp_buf->str);
+ break;
+ case 3:
+ pair->info.render_type = g_strdup (tmp_buf->str);
+ break;
+ default:
+ range = g_new (PangoEngineRange, 1);
+ if (sscanf(tmp_buf->str, "%d-%d:", &start, &end) != 2)
+ {
+ fprintf(stderr, "Error reading modules file");
+ have_error = TRUE;
+ goto error;
+ }
+ q = strchr (tmp_buf->str, ':');
+ if (!q)
+ {
+ fprintf(stderr, "Error reading modules file");
+ have_error = TRUE;
+ goto error;
}
+ q++;
+ range->start = start;
+ range->end = end;
+ range->langs = g_strdup (tmp_buf->str);
- i++;
-
- do
- p++;
- while (*p && isspace(*p));
-
- if (!*p)
- break;
-
- q = p;
+ ranges = g_list_prepend (ranges, range);
}
- else
- p++;
- }
+ if (!pango_skip_space (&p))
+ break;
+
+ i++;
+ }
+
if (i<3)
{
- fprintf(stderr, "Error reading pango.modules");
- return FALSE;
+ fprintf(stderr, "Error reading modules file");
+ have_error = TRUE;
+ goto error;
}
ranges = g_list_reverse (ranges);
@@ -311,13 +288,19 @@ process_module_file(FILE *module_file)
tmp_list = tmp_list->next;
}
+ pair->engine = NULL;
+
+ engines = g_list_prepend (engines, pair);
+
+ error:
g_list_foreach (ranges, (GFunc)g_free, NULL);
g_list_free (ranges);
- g_free (line);
-
- pair->engine = NULL;
- engines = g_list_prepend (engines, pair);
+ if (have_error)
+ {
+ g_free(pair);
+ return FALSE;
+ }
}
return TRUE;
@@ -327,57 +310,32 @@ static void
read_modules (void)
{
FILE *module_file;
- gboolean read_module_file = FALSE;
- /* FIXME FIXME FIXME - this is a potential security problem from leaving
- * pango.modules files scattered around to trojan modules.
- */
- module_file = fopen ("pango.modules", "r");
- if(module_file)
- {
- read_module_file = read_module_file || process_module_file(module_file);
- process_module_file(module_file);
- fclose(module_file);
- }
- else
- {
- DIR *dirh;
-
- dirh = opendir(DOTMODULEDIR);
- if(dirh)
- {
- struct dirent *dent;
+ char *file_str = pango_config_key_get ("Pango/ModuleFiles");
+ char **files;
+ int n;
- while((dent = readdir(dirh)))
- {
- char fullfn[PATH_MAX];
- char *ctmp;
+ if (!file_str)
+ file_str = g_strdup (SYSCONFDIR "/pango/pango.modules");
- if(dent->d_name[0] == '.')
- continue;
+ files = pango_split_file_list (file_str);
- ctmp = strrchr(dent->d_name, '.');
- if(!ctmp || strcmp(ctmp, ".modules") != 0)
- continue;
+ n = 0;
+ while (files[n])
+ n++;
- g_snprintf(fullfn, sizeof(fullfn), DOTMODULEDIR "/%s", dent->d_name);
- module_file = fopen(fullfn, "r");
- if(module_file)
- {
- read_module_file = read_module_file || process_module_file(module_file);
- fclose(module_file);
- }
- }
- }
+ while (n-- > 0)
+ {
+ module_file = fopen (files[n], "r");
+ if (!module_file)
+ g_warning ("Error opening module file '%s': %s\n", files[n], g_strerror (errno));
- closedir(dirh);
+ process_module_file(module_file);
+ fclose(module_file);
}
- if (!read_module_file)
- {
- fprintf(stderr, "Could not load any module files!\n");
- /* FIXME: Error */
- }
+ g_strfreev (files);
+ g_free (file_str);
}
static void
diff --git a/pango/pangox-fontmap.c b/pango/pangox-fontmap.c
index 7f20a52a..6b0c90bb 100644
--- a/pango/pangox-fontmap.c
+++ b/pango/pangox-fontmap.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include "pango-fontmap.h"
+#include "pango-utils.h"
#include "pangox-private.h"
#define PANGO_TYPE_X_FONT_MAP (pango_x_font_map_get_type ())
@@ -546,129 +547,31 @@ pango_x_font_map_load_font (PangoFontMap *fontmap,
return result;
}
-/* Similar to GNU libc's getline, but buffer is g_malloc'd */
-static size_t
-pango_getline (char **lineptr, size_t *n, FILE *stream)
-{
-#define EXPAND_CHUNK 16
-
- int n_read = 0;
- int result = -1;
-
- g_return_val_if_fail (lineptr != NULL, -1);
- g_return_val_if_fail (n != NULL, -1);
- g_return_val_if_fail (*lineptr != NULL || *n == 0, -1);
-
-#ifdef HAVE_FLOCKFILE
- flockfile (stream);
-#endif
-
- while (1)
- {
- int c;
-
-#ifdef HAVE_FLOCKFILE
- c = getc_unlocked (stream);
-#else
- c = getc (stream);
-#endif
-
- if (c == EOF)
- {
- if (n_read > 0)
- {
- result = n_read;
- (*lineptr)[n_read] = '\0';
- }
- break;
- }
-
- if (n_read + 2 >= *n)
- {
- *n += EXPAND_CHUNK;
- *lineptr = g_realloc (*lineptr, *n);
- }
-
- (*lineptr)[n_read] = c;
- n_read++;
-
- if (c == '\n' || c == '\r')
- {
- result = n_read;
- (*lineptr)[n_read] = '\0';
- break;
- }
- }
-
-#ifdef HAVE_FLOCKFILE
- funlockfile (stream);
-#endif
-
- return n_read - 1;
-}
-
-static int
-find_tok (char **start, char **tok)
-{
- char *p = *start;
-
- while (*p && (*p == ' ' || *p == '\t'))
- p++;
-
- if (*p == 0 || *p == '\n' || *p == '\r')
- return -1;
-
- if (*p == '"')
- {
- p++;
- *tok = p;
-
- while (*p && *p != '"')
- p++;
-
- if (*p != '"')
- return -1;
-
- *start = p + 1;
- return p - *tok;
- }
- else
- {
- *tok = p;
-
- while (*p && *p != ' ' && *p != '\t' && *p != '\r' && *p != '\n')
- p++;
-
- *start = p;
- return p - *tok;
- }
-}
-
static gboolean
-get_style (char *tok, int toksize, PangoFontDescription *desc)
+get_style (GString *str, PangoFontDescription *desc)
{
- if (toksize == 0)
+ if (str->len == 0)
return FALSE;
- switch (tok[0])
+ switch (str->str[0])
{
case 'n':
case 'N':
- if (strncasecmp (tok, "normal", toksize) == 0)
+ if (strncasecmp (str->str, "normal", str->len) == 0)
{
desc->style = PANGO_STYLE_NORMAL;
return TRUE;
}
break;
case 'i':
- if (strncasecmp (tok, "italic", toksize) == 0)
+ if (strncasecmp (str->str, "italic", str->len) == 0)
{
desc->style = PANGO_STYLE_ITALIC;
return TRUE;
}
break;
case 'o':
- if (strncasecmp (tok, "oblique", toksize) == 0)
+ if (strncasecmp (str->str, "oblique", str->len) == 0)
{
desc->style = PANGO_STYLE_OBLIQUE;
return TRUE;
@@ -681,16 +584,16 @@ get_style (char *tok, int toksize, PangoFontDescription *desc)
}
static gboolean
-get_variant (char *tok, int toksize, PangoFontDescription *desc)
+get_variant (GString *str, PangoFontDescription *desc)
{
- if (toksize == 0)
+ if (str->len == 0)
return FALSE;
- switch (tok[0])
+ switch (str->str[0])
{
case 'n':
case 'N':
- if (strncasecmp (tok, "normal", toksize) == 0)
+ if (strncasecmp (str->str, "normal", str->len) == 0)
{
desc->variant = PANGO_VARIANT_NORMAL;
return TRUE;
@@ -698,7 +601,7 @@ get_variant (char *tok, int toksize, PangoFontDescription *desc)
break;
case 's':
case 'S':
- if (strncasecmp (tok, "small_caps", toksize) == 0)
+ if (strncasecmp (str->str, "small_caps", str->len) == 0)
{
desc->variant = PANGO_VARIANT_SMALL_CAPS;
return TRUE;
@@ -711,16 +614,16 @@ get_variant (char *tok, int toksize, PangoFontDescription *desc)
}
static gboolean
-get_weight (char *tok, int toksize, PangoFontDescription *desc)
+get_weight (GString *str, PangoFontDescription *desc)
{
- if (toksize == 0)
+ if (str->len == 0)
return FALSE;
- switch (tok[0])
+ switch (str->str[0])
{
case 'n':
case 'N':
- if (strncasecmp (tok, "normal", toksize) == 0)
+ if (strncasecmp (str->str, "normal", str->len) == 0)
{
desc->weight = PANGO_WEIGHT_NORMAL;
return TRUE;
@@ -728,7 +631,7 @@ get_weight (char *tok, int toksize, PangoFontDescription *desc)
break;
case 'b':
case 'B':
- if (strncasecmp (tok, "bold", toksize) == 0)
+ if (strncasecmp (str->str, "bold", str->len) == 0)
{
desc->weight = PANGO_WEIGHT_BOLD;
return TRUE;
@@ -747,7 +650,7 @@ get_weight (char *tok, int toksize, PangoFontDescription *desc)
{
char *numstr, *end;
- numstr = g_strndup (tok, toksize);
+ numstr = g_strndup (str->str, str->len);
desc->weight = strtol (numstr, &end, 0);
if (*end != '\0')
@@ -767,16 +670,16 @@ get_weight (char *tok, int toksize, PangoFontDescription *desc)
}
static gboolean
-get_stretch (char *tok, int toksize, PangoFontDescription *desc)
+get_stretch (GString *str, PangoFontDescription *desc)
{
- if (toksize == 0)
+ if (str->len == 0)
return FALSE;
- switch (tok[0])
+ switch (str->str[0])
{
case 'c':
case 'C':
- if (strncasecmp (tok, "condensed", toksize) == 0)
+ if (strncasecmp (str->str, "condensed", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_CONDENSED;
return TRUE;
@@ -784,17 +687,17 @@ get_stretch (char *tok, int toksize, PangoFontDescription *desc)
break;
case 'e':
case 'E':
- if (strncasecmp (tok, "extra_condensed", toksize) == 0)
+ if (strncasecmp (str->str, "extra_condensed", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_EXTRA_CONDENSED;
return TRUE;
}
- if (strncasecmp (tok, "extra_expanded", toksize) == 0)
+ if (strncasecmp (str->str, "extra_expanded", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_EXTRA_EXPANDED;
return TRUE;
}
- if (strncasecmp (tok, "expanded", toksize) == 0)
+ if (strncasecmp (str->str, "expanded", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_EXPANDED;
return TRUE;
@@ -802,7 +705,7 @@ get_stretch (char *tok, int toksize, PangoFontDescription *desc)
break;
case 'n':
case 'N':
- if (strncasecmp (tok, "normal", toksize) == 0)
+ if (strncasecmp (str->str, "normal", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_NORMAL;
return TRUE;
@@ -810,12 +713,12 @@ get_stretch (char *tok, int toksize, PangoFontDescription *desc)
break;
case 's':
case 'S':
- if (strncasecmp (tok, "semi_condensed", toksize) == 0)
+ if (strncasecmp (str->str, "semi_condensed", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_SEMI_CONDENSED;
return TRUE;
}
- if (strncasecmp (tok, "semi_expanded", toksize) == 0)
+ if (strncasecmp (str->str, "semi_expanded", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_SEMI_EXPANDED;
return TRUE;
@@ -823,12 +726,12 @@ get_stretch (char *tok, int toksize, PangoFontDescription *desc)
break;
case 'u':
case 'U':
- if (strncasecmp (tok, "ultra_condensed", toksize) == 0)
+ if (strncasecmp (str->str, "ultra_condensed", str->len) == 0)
{
desc->stretch = PANGO_STRETCH_ULTRA_CONDENSED;
return TRUE;
}
- if (strncasecmp (tok, "ultra_expanded", toksize) == 0)
+ if (strncasecmp (str->str, "ultra_expanded", str->len) == 0)
{
desc->variant = PANGO_STRETCH_ULTRA_EXPANDED;
return TRUE;
@@ -846,8 +749,6 @@ pango_x_font_map_read_alias_file (PangoXFontMap *xfontmap,
{
FILE *infile;
char **xlfds;
- char *buf = NULL;
- size_t bufsize = 0;
int lineno = 0;
int i;
PangoXFontEntry *font_entry = NULL;
@@ -855,78 +756,74 @@ pango_x_font_map_read_alias_file (PangoXFontMap *xfontmap,
infile = fopen (filename, "r");
if (infile)
{
- while (pango_getline (&buf, &bufsize, infile) != EOF)
+ GString *line_buf = g_string_new (NULL);
+ GString *tmp_buf = g_string_new (NULL);
+
+ while (pango_read_line (infile, line_buf))
{
PangoXFamilyEntry *family_entry;
- char *tok;
- char *p = buf;
+ const char *p = line_buf->str;
- int toksize;
lineno++;
- while (*p && (*p == ' ' || *p == '\t'))
- p++;
-
- if (*p == 0 || *p == '#' || *p == '\n' || *p == '\r')
+ if (!pango_skip_space (&p))
continue;
- toksize = find_tok (&p, &tok);
- if (toksize == -1)
+ if (!pango_scan_string (&p, tmp_buf))
goto error;
font_entry = g_new (PangoXFontEntry, 1);
font_entry->xlfd = NULL;
- font_entry->description.family_name = g_strndup (tok, toksize);
+ font_entry->description.family_name = g_strdup (tmp_buf->str);
g_strdown (font_entry->description.family_name);
- toksize = find_tok (&p, &tok);
- if (toksize == -1)
+ if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_style (tok, toksize, &font_entry->description))
+ if (!get_style (tmp_buf, &font_entry->description))
goto error;
- toksize = find_tok (&p, &tok);
- if (toksize == -1)
+ if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_variant (tok, toksize, &font_entry->description))
+ if (!get_variant (tmp_buf, &font_entry->description))
goto error;
- toksize = find_tok (&p, &tok);
- if (toksize == -1)
+ if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_weight (tok, toksize, &font_entry->description))
+ if (!get_weight (tmp_buf, &font_entry->description))
goto error;
- toksize = find_tok (&p, &tok);
- if (toksize == -1)
+ if (!pango_scan_string (&p, tmp_buf))
goto error;
- if (!get_stretch (tok, toksize, &font_entry->description))
+ if (!get_stretch (tmp_buf, &font_entry->description))
goto error;
- toksize = find_tok (&p, &tok);
- if (toksize == -1)
+ if (!pango_scan_string (&p, tmp_buf))
goto error;
- font_entry->xlfd = g_strndup (tok, toksize);
+ /* Remove excess whitespace and check for complete fields */
- /* Check for complete fields */
-
- xlfds = g_strsplit (font_entry->xlfd, ",", -1);
+ xlfds = g_strsplit (tmp_buf->str, ",", -1);
for (i=0; xlfds[i]; i++)
- if (!pango_x_is_xlfd_font_name (xlfds[i]))
- {
- g_warning ("XLFD '%s' must be complete (14 fields)", xlfds[i]);
- g_strfreev (xlfds);
- goto error;
- }
+ {
+ char *trimmed = pango_trim_string (xlfds[i]);
+ g_free (xlfds[i]);
+ xlfds[i] = trimmed;
+
+ if (!pango_x_is_xlfd_font_name (xlfds[i]))
+ {
+ g_warning ("XLFD '%s' must be complete (14 fields)", xlfds[i]);
+ g_strfreev (xlfds);
+ goto error;
+ }
+ }
+ font_entry->xlfd = g_strjoinv (",", xlfds);
g_strfreev (xlfds);
-
/* Insert the font entry into our structures */
@@ -958,9 +855,10 @@ pango_x_font_map_read_alias_file (PangoXFontMap *xfontmap,
g_warning ("Error parsing line %d of alias file '%s'", lineno, filename);
out:
- g_free (buf);
+ g_string_free (tmp_buf, TRUE);
+ g_string_free (line_buf, TRUE);
+
fclose (infile);
- return;
}
}
@@ -968,16 +866,24 @@ pango_x_font_map_read_alias_file (PangoXFontMap *xfontmap,
static void
pango_x_font_map_read_aliases (PangoXFontMap *xfontmap)
{
- char *filename;
+ char **files;
+ char *files_str = pango_config_key_get ("PangoX/AliasFiles");
+ int n;
+
+ if (!files_str)
+ files_str = g_strdup ("~/.pangox_aliases:" SYSCONFDIR "/pango/pangox.aliases");
- pango_x_font_map_read_alias_file (xfontmap, SYSCONFDIR "/pango/pangox_aliases");
+ files = pango_split_file_list (files_str);
+
+ n = 0;
+ while (files[n])
+ n++;
- filename = g_strconcat (g_get_home_dir(), "/.pangox_aliases", NULL);
- pango_x_font_map_read_alias_file (xfontmap, filename);
- g_free (filename);
+ while (n-- > 0)
+ pango_x_font_map_read_alias_file (xfontmap, files[n]);
- /* FIXME: Remove this one */
- pango_x_font_map_read_alias_file (xfontmap, "pangox_aliases");
+ g_strfreev (files);
+ g_free (files_str);
}
/*
diff --git a/pango/querymodules.c b/pango/querymodules.c
index 9ddddb3d..051b41d7 100644
--- a/pango/querymodules.c
+++ b/pango/querymodules.c
@@ -20,8 +20,10 @@
*/
#include <glib.h>
+#include <dirent.h>
#include <gmodule.h>
#include "pango.h"
+#include "pango-utils.h"
#include <errno.h>
#include <string.h>
@@ -29,13 +31,27 @@
#include <stdio.h>
void
-query_module (GModule *module, gchar *name)
+query_module (const char *dir, const char *name)
{
void (*list) (PangoEngineInfo **engines, gint *n_engines);
PangoEngine *(*load) (const gchar *id);
void (*unload) (PangoEngine *engine);
+
+ GModule *module;
+ gchar *path;
+
+ if (name[0] == G_DIR_SEPARATOR)
+ path = g_strdup (name);
+ else
+ path = g_strconcat (dir, G_DIR_SEPARATOR_S, name, NULL);
- if (g_module_symbol (module, "script_engine_list", (gpointer)&list) &&
+ module = g_module_open (path, 0);
+
+ if (!module)
+ fprintf(stderr, "Cannot load module %s: %s\n", path, g_module_error());
+
+ if (module &&
+ g_module_symbol (module, "script_engine_list", (gpointer)&list) &&
g_module_symbol (module, "script_engine_load", (gpointer)&load) &&
g_module_symbol (module, "script_engine_unload", (gpointer)&unload))
{
@@ -47,7 +63,7 @@ query_module (GModule *module, gchar *name)
for (i=0; i<n_engines; i++)
{
- g_print ("%s %s %s %s ", name, engines[i].id, engines[i].engine_type, engines[i].render_type);
+ g_print ("%s %s %s %s ", path, engines[i].id, engines[i].engine_type, engines[i].render_type);
for (j=0; j < engines[i].n_ranges; j++)
{
if (j != 0)
@@ -62,40 +78,60 @@ query_module (GModule *module, gchar *name)
}
else
{
- fprintf (stderr, "%s does not export Pango module API\n", name);
+ fprintf (stderr, "%s does not export Pango module API\n", path);
}
+
+ g_free (path);
+ g_module_close (module);
}
int main (int argc, char **argv)
{
char cwd[PATH_MAX];
int i;
+ char *path;
- getcwd (cwd, PATH_MAX);
+ printf ("# Pango Modules file\n"
+ "# Automatically generated file, do not edit\n"
+ "#\n");
- for (i=1; i<argc; i++)
+ if (argc == 1) /* No arguments given */
{
- GModule *module;
- gchar *tmp;
+ char **dirs;
+ int i;
- if (argv[i][0] == '/')
- tmp = g_strdup (argv[i]);
- else
- tmp = g_strconcat (cwd, "/", argv[i], NULL);
+ path = pango_config_key_get ("Pango/ModulesPath");
+ if (!path)
+ path = g_strdup (LIBDIR "/pango/modules");
- module = g_module_open (tmp, 0);
- if (module)
- {
- query_module (module, tmp);
- g_module_close (module);
- }
- else
+ printf ("# ModulesPath = %s\n#\n", path);
+
+ dirs = pango_split_file_list (path);
+
+ for (i=0; dirs[i]; i++)
{
- fprintf(stderr, "Cannot load module %s: %s\n",
- tmp, g_module_error());
+ DIR *dir = opendir (dirs[i]);
+ if (dir)
+ {
+ struct dirent *dent;
+
+ while ((dent = readdir (dir)))
+ {
+ int len = strlen (dent->d_name);
+ if (len > 3 && strcmp (dent->d_name + len - 3, ".so") == 0)
+ query_module (dirs[i], dent->d_name);
+ }
+
+ closedir (dir);
+ }
}
+ }
+ else
+ {
+ getcwd (cwd, PATH_MAX);
- g_free (tmp);
+ for (i=1; i<argc; i++)
+ query_module (cwd, argv[i]);
}
return 0;