summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2015-09-02 00:04:32 -0700
committerKeith Packard <keithp@keithp.com>2015-12-08 20:37:48 -0800
commit135fb032e940ce226c9feb13e6e903f3ecbc5eb0 (patch)
treeb6cea9b925c7be27a13964924b7811823f52f2e2 /src/util
parenteb67d10ae82b364a4324e96ce53baaa4e5e75f97 (diff)
Eliminate calls back to X server or font server functions by name (v4)libXfont2-2.0.0
This eliminates the weak symbol adventures and makes all of the calls back to the X server or Font server go through a table of functions instead, clarifying the required API. As this is a rather major change to the API for the library, it now installs itself as libXfont2 instead of libXfont, and the package config file is now xfont2.pc. All of the installed headers remain the same as the original library; there's now a new include file, libxfont2.h, which defines the X server and Font server interfaces. This moves util/atom.c to stubs/atom.c and reformats that file, hence the diff being larger than it would otherwise be. v2: Rename to libXfont2 instead of libXfont_2 as suggested by Emil Velikov Fix whitespace in stubs/atom.c, which was moved from util/ v3: Remove select masks from API. Expose single 'font_init' function for all library initialization. v4: Change name of distributed tarballs to libXfont2 as well Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am1
-rw-r--r--src/util/atom.c250
-rw-r--r--src/util/fontaccel.c1
-rw-r--r--src/util/fontnames.c9
-rw-r--r--src/util/fontutil.c38
-rw-r--r--src/util/fontxlfd.c1
-rw-r--r--src/util/format.c1
-rw-r--r--src/util/miscutil.c23
-rw-r--r--src/util/patcache.c35
-rw-r--r--src/util/private.c5
-rw-r--r--src/util/utilbitmap.c1
11 files changed, 47 insertions, 318 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 32a8f37..d802b59 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -7,7 +7,6 @@ AM_CFLAGS = $(XFONT_CFLAGS) $(OS_CFLAGS) $(CWARNFLAGS)
noinst_LTLIBRARIES = libutil.la
libutil_la_SOURCES = \
- atom.c \
fontaccel.c \
fontnames.c \
fontutil.c \
diff --git a/src/util/atom.c b/src/util/atom.c
deleted file mode 100644
index 5f7f1c6..0000000
--- a/src/util/atom.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
-
-Copyright 1990, 1994, 1998 The Open Group
-
-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.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/*
- * Author: Keith Packard, MIT X Consortium
- */
-
-/* lame atom replacement routines for font applications */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/fonts/fontmisc.h>
-#include "stubs.h"
-
-typedef struct _AtomList {
- char *name;
- int len;
- int hash;
- Atom atom;
-} AtomListRec, *AtomListPtr;
-
-static AtomListPtr *hashTable;
-
-static int hashSize, hashUsed;
-static int hashMask;
-static int rehash;
-
-static AtomListPtr *reverseMap;
-static int reverseMapSize;
-static Atom lastAtom;
-
-static int
-Hash(const char *string, int len)
-{
- int h;
-
- h = 0;
- while (len--)
- h = (h << 3) ^ *string++;
- if (h < 0)
- return -h;
- return h;
-}
-
-static int
-ResizeHashTable (void)
-{
- int newHashSize;
- int newHashMask;
- AtomListPtr *newHashTable;
- int i;
- int h;
- int newRehash;
- int r;
-
- if (hashSize == 0)
- newHashSize = 1024;
- else
- newHashSize = hashSize * 2;
- newHashTable = calloc (newHashSize, sizeof (AtomListPtr));
- if (!newHashTable) {
- fprintf(stderr, "ResizeHashTable(): Error: Couldn't allocate"
- " newHashTable (%ld)\n",
- newHashSize * (unsigned long)sizeof (AtomListPtr));
- return FALSE;
- }
- newHashMask = newHashSize - 1;
- newRehash = (newHashMask - 2);
- for (i = 0; i < hashSize; i++)
- {
- if (hashTable[i])
- {
- h = (hashTable[i]->hash) & newHashMask;
- if (newHashTable[h])
- {
- r = hashTable[i]->hash % newRehash | 1;
- do {
- h += r;
- if (h >= newHashSize)
- h -= newHashSize;
- } while (newHashTable[h]);
- }
- newHashTable[h] = hashTable[i];
- }
- }
- free (hashTable);
- hashTable = newHashTable;
- hashSize = newHashSize;
- hashMask = newHashMask;
- rehash = newRehash;
- return TRUE;
-}
-
-static int
-ResizeReverseMap (void)
-{
- AtomListPtr *newMap;
- int newMapSize;
-
- if (reverseMapSize == 0)
- newMapSize = 1000;
- else
- newMapSize = reverseMapSize * 2;
- newMap = realloc (reverseMap, newMapSize * sizeof (AtomListPtr));
- if (newMap == NULL) {
- fprintf(stderr, "ResizeReverseMap(): Error: Couldn't reallocate"
- " reverseMap (%ld)\n",
- newMapSize * (unsigned long)sizeof(AtomListPtr));
- return FALSE;
- }
- reverseMap = newMap;
- reverseMapSize = newMapSize;
- return TRUE;
-}
-
-static int
-NameEqual (const char *a, const char *b, int l)
-{
- while (l--)
- if (*a++ != *b++)
- return FALSE;
- return TRUE;
-}
-
-#ifdef __SUNPRO_C
-#pragma weak MakeAtom
-#endif
-
-weak Atom
-MakeAtom(const char *string, unsigned len, int makeit)
-{
- AtomListPtr a;
- int hash;
- int h = 0;
- int r;
-
- OVERRIDE_SYMBOL(MakeAtom, string, len, makeit);
-
- hash = Hash (string, len);
- if (hashTable)
- {
- h = hash & hashMask;
- if (hashTable[h])
- {
- if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
- NameEqual (hashTable[h]->name, string, len))
- {
- return hashTable[h]->atom;
- }
- r = (hash % rehash) | 1;
- for (;;)
- {
- h += r;
- if (h >= hashSize)
- h -= hashSize;
- if (!hashTable[h])
- break;
- if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
- NameEqual (hashTable[h]->name, string, len))
- {
- return hashTable[h]->atom;
- }
- }
- }
- }
- if (!makeit)
- return None;
- a = malloc (sizeof (AtomListRec) + len + 1);
- if (a == NULL) {
- fprintf(stderr, "MakeAtom(): Error: Couldn't allocate AtomListRec"
- " (%ld)\n", (unsigned long)sizeof (AtomListRec) + len + 1);
- return None;
- }
- a->name = (char *) (a + 1);
- a->len = len;
- strncpy (a->name, string, len);
- a->name[len] = '\0';
- a->atom = ++lastAtom;
- a->hash = hash;
- if (hashUsed >= hashSize / 2)
- {
- ResizeHashTable ();
- h = hash & hashMask;
- if (hashTable[h])
- {
- r = (hash % rehash) | 1;
- do {
- h += r;
- if (h >= hashSize)
- h -= hashSize;
- } while (hashTable[h]);
- }
- }
- hashTable[h] = a;
- hashUsed++;
- if (reverseMapSize <= a->atom) {
- if (!ResizeReverseMap())
- return None;
- }
- reverseMap[a->atom] = a;
- return a->atom;
-}
-
-#ifdef __SUNPRO_C
-#pragma weak ValidAtom
-#endif
-
-weak int
-ValidAtom(Atom atom)
-{
- OVERRIDE_SYMBOL(ValidAtom, atom);
- return (atom != None) && (atom <= lastAtom);
-}
-
-#ifdef __SUNPRO_C
-#pragma weak NameForAtom
-#endif
-
-weak char *
-NameForAtom(Atom atom)
-{
- OVERRIDE_SYMBOL(NameForAtom, atom);
- if (atom != None && atom <= lastAtom)
- return reverseMap[atom]->name;
- return NULL;
-}
diff --git a/src/util/fontaccel.c b/src/util/fontaccel.c
index db03e73..c8395c4 100644
--- a/src/util/fontaccel.c
+++ b/src/util/fontaccel.c
@@ -33,6 +33,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
#include <X11/fonts/fontutil.h>
diff --git a/src/util/fontnames.c b/src/util/fontnames.c
index ceafce5..b292480 100644
--- a/src/util/fontnames.c
+++ b/src/util/fontnames.c
@@ -34,11 +34,12 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
void
-FreeFontNames(FontNamesPtr pFN)
+xfont2_free_font_names(FontNamesPtr pFN)
{
int i;
@@ -53,7 +54,7 @@ FreeFontNames(FontNamesPtr pFN)
}
FontNamesPtr
-MakeFontNamesRecord(unsigned int size)
+xfont2_make_font_names_record(unsigned size)
{
FontNamesPtr pFN;
@@ -82,7 +83,9 @@ MakeFontNamesRecord(unsigned int size)
}
int
-AddFontNamesName(FontNamesPtr names, char *name, int length)
+xfont2_add_font_names_name(FontNamesPtr names,
+ char *name,
+ int length)
{
int index = names->nnames;
char *nelt;
diff --git a/src/util/fontutil.c b/src/util/fontutil.c
index 2c5ea6f..d1b845b 100644
--- a/src/util/fontutil.c
+++ b/src/util/fontutil.c
@@ -33,6 +33,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
#include <X11/fonts/FSproto.h>
@@ -44,25 +45,14 @@ from The Open Group.
static int defaultGlyphCachingMode = DEFAULT_GLYPH_CACHING_MODE;
int glyphCachingMode = DEFAULT_GLYPH_CACHING_MODE;
-void
-GetGlyphs(FontPtr font,
- unsigned long count,
- unsigned char *chars,
- FontEncoding fontEncoding,
- unsigned long *glyphcount, /* RETURN */
- CharInfoPtr *glyphs) /* RETURN */
-{
- (*font->get_glyphs) (font, count, chars, fontEncoding, glyphcount, glyphs);
-}
-
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
void
-QueryGlyphExtents(FontPtr pFont,
- CharInfoPtr *charinfo,
- unsigned long count,
- ExtentInfoRec *info)
+xfont2_query_glyph_extents(FontPtr pFont,
+ CharInfoPtr *charinfo,
+ unsigned long count,
+ ExtentInfoRec *info)
{
register unsigned long i;
xCharInfo *pCI;
@@ -131,10 +121,10 @@ QueryGlyphExtents(FontPtr pFont,
}
Bool
-QueryTextExtents(FontPtr pFont,
- unsigned long count,
- unsigned char *chars,
- ExtentInfoRec *info)
+xfont2_query_text_extents(FontPtr pFont,
+ unsigned long count,
+ unsigned char *chars,
+ ExtentInfoRec *info)
{
xCharInfo **charinfo;
unsigned long n;
@@ -182,15 +172,15 @@ QueryTextExtents(FontPtr pFont,
}
cm = pFont->info.constantMetrics;
pFont->info.constantMetrics = FALSE;
- QueryGlyphExtents(pFont, (CharInfoPtr*) charinfo + firstReal,
- n - firstReal, info);
+ xfont2_query_glyph_extents(pFont, (CharInfoPtr*) charinfo + firstReal,
+ n - firstReal, info);
pFont->info.constantMetrics = cm;
free(charinfo);
return TRUE;
}
Bool
-ParseGlyphCachingMode(char *str)
+xfont2_parse_glyph_caching_mode(char *str)
{
if (!strcmp(str, "none")) defaultGlyphCachingMode = CACHING_OFF;
else if (!strcmp(str, "all")) defaultGlyphCachingMode = CACHE_ALL_GLYPHS;
@@ -200,7 +190,7 @@ ParseGlyphCachingMode(char *str)
}
void
-InitGlyphCaching(void)
+xfont2_init_glyph_caching(void)
{
/* Set glyphCachingMode to the mode the server hopes to
support. DDX drivers that do not support the requested level
@@ -215,7 +205,7 @@ InitGlyphCaching(void)
* caching they can support.
*/
void
-SetGlyphCachingMode(int newmode)
+xfont2_set_glyph_caching_mode(int newmode)
{
if ( (glyphCachingMode > newmode) && (newmode >= 0) )
glyphCachingMode = newmode;
diff --git a/src/util/fontxlfd.c b/src/util/fontxlfd.c
index 99a3679..0bd1140 100644
--- a/src/util/fontxlfd.c
+++ b/src/util/fontxlfd.c
@@ -33,6 +33,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
#include <X11/fonts/fontxlfd.h>
diff --git a/src/util/format.c b/src/util/format.c
index c1f9762..0baeb3a 100644
--- a/src/util/format.c
+++ b/src/util/format.c
@@ -53,6 +53,7 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/FSproto.h>
#include <X11/fonts/font.h>
#include <X11/fonts/fontstruct.h>
diff --git a/src/util/miscutil.c b/src/util/miscutil.c
index 61c9d11..e015972 100644
--- a/src/util/miscutil.c
+++ b/src/util/miscutil.c
@@ -29,38 +29,19 @@ from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/Xosdefs.h>
#include <stdlib.h>
#include <X11/fonts/fontmisc.h>
-#include "stubs.h"
#define XK_LATIN1
#include <X11/keysymdef.h>
-
-#ifdef __SUNPRO_C
-#pragma weak serverGeneration
-#pragma weak register_fpe_functions
-#endif
-
extern void BuiltinRegisterFpeFunctions(void);
-/* make sure everything initializes themselves at least once */
-weak unsigned long serverGeneration = 1;
-
-unsigned long __GetServerGeneration (void);
-
-unsigned long
-__GetServerGeneration (void)
-{
- OVERRIDE_DATA(serverGeneration);
- return serverGeneration;
-}
-
-weak void
+void
register_fpe_functions (void)
{
- OVERRIDE_SYMBOL(register_fpe_functions);
BuiltinRegisterFpeFunctions();
FontFileRegisterFpeFunctions();
#ifdef XFONT_FC
diff --git a/src/util/patcache.c b/src/util/patcache.c
index 2101015..e76f1f4 100644
--- a/src/util/patcache.c
+++ b/src/util/patcache.c
@@ -31,6 +31,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
@@ -55,15 +56,15 @@ typedef struct _FontPatternCacheEntry {
FontPtr pFont; /* associated font */
} FontPatternCacheEntryRec, *FontPatternCacheEntryPtr;
-typedef struct _FontPatternCache {
+typedef struct _xfont2_pattern_cache {
FontPatternCacheEntryPtr buckets[NBUCKETS];
FontPatternCacheEntryRec entries[NENTRIES];
FontPatternCacheEntryPtr free;
-} FontPatternCacheRec;
+} xfont2_pattern_cache_rec;
/* Empty cache (for rehash) */
void
-EmptyFontPatternCache (FontPatternCachePtr cache)
+xfont2_empty_font_pattern_cache(xfont2_pattern_cache_ptr cache)
{
int i;
@@ -83,10 +84,10 @@ EmptyFontPatternCache (FontPatternCachePtr cache)
}
/* Create and initialize cache */
-FontPatternCachePtr
-MakeFontPatternCache (void)
+xfont2_pattern_cache_ptr
+xfont2_make_font_pattern_cache(void)
{
- FontPatternCachePtr cache;
+ xfont2_pattern_cache_ptr cache;
int i;
cache = malloc (sizeof *cache);
if (!cache)
@@ -96,13 +97,13 @@ MakeFontPatternCache (void)
cache->entries[i].pattern = 0;
cache->entries[i].pFont = 0;
}
- EmptyFontPatternCache (cache);
+ xfont2_empty_font_pattern_cache (cache);
return cache;
}
/* toss cache */
void
-FreeFontPatternCache (FontPatternCachePtr cache)
+xfont2_free_font_pattern_cache(xfont2_pattern_cache_ptr cache)
{
int i;
@@ -127,10 +128,10 @@ Hash (const char *string, int len)
/* add entry */
void
-CacheFontPattern (FontPatternCachePtr cache,
- const char *pattern,
- int patlen,
- FontPtr pFont)
+xfont2_cache_font_pattern(xfont2_pattern_cache_ptr cache,
+ const char * pattern,
+ int patlen,
+ FontPtr pFont)
{
FontPatternCacheEntryPtr e;
char *newpat;
@@ -173,9 +174,9 @@ CacheFontPattern (FontPatternCachePtr cache,
/* find matching entry */
FontPtr
-FindCachedFontPattern (FontPatternCachePtr cache,
- const char *pattern,
- int patlen)
+xfont2_find_cached_font_pattern(xfont2_pattern_cache_ptr cache,
+ const char * pattern,
+ int patlen)
{
int hash;
int i;
@@ -195,8 +196,8 @@ FindCachedFontPattern (FontPatternCachePtr cache,
}
void
-RemoveCachedFontPattern (FontPatternCachePtr cache,
- FontPtr pFont)
+xfont2_remove_cached_font_pattern(xfont2_pattern_cache_ptr cache,
+ FontPtr pFont)
{
FontPatternCacheEntryPtr e;
int i;
diff --git a/src/util/private.c b/src/util/private.c
index e55e193..92075c2 100644
--- a/src/util/private.c
+++ b/src/util/private.c
@@ -31,13 +31,14 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
static int _FontPrivateAllocateIndex = 0;
int
-AllocateFontPrivateIndex (void)
+xfont2_allocate_font_private_index (void)
{
return _FontPrivateAllocateIndex++;
}
@@ -77,7 +78,7 @@ ResetFontPrivateIndex (void)
}
Bool
-_FontSetNewPrivate (FontPtr pFont, int n, pointer ptr)
+xfont2_font_set_private(FontPtr pFont, int n, pointer ptr)
{
pointer *new;
diff --git a/src/util/utilbitmap.c b/src/util/utilbitmap.c
index ec726b8..fe1c412 100644
--- a/src/util/utilbitmap.c
+++ b/src/util/utilbitmap.c
@@ -31,6 +31,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "libxfontint.h"
#include <X11/fonts/fontmisc.h>
/* Utility functions for reformating font bitmaps */