summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorwl <wl>2006-02-11 17:54:28 +0000
committerwl <wl>2006-02-11 17:54:28 +0000
commit6a7f55cf47c291790cf08aaba36a947d7f6d5ab3 (patch)
treefc171f6c3d6e915556b8b4b5b6c9bfb92a611cfd /src/include
parentc9659c4c72fea5884dce76a33c72b7f3124794c8 (diff)
downloadgroff-6a7f55cf47c291790cf08aaba36a947d7f6d5ab3.tar.gz
New accessor method glyph_t::glyph_name().
* src/include/ptable.h (declare_ptable): Add a return value to the 'define' method, and declare a 'lookupassoc' method. (implement_ptable): Return the stored key in 'define'. Implement lookupassoc. * src/include/font.h (glyph_t): Add 'name' field. Add an argument to the constructor. (glyph_t::glyph_name): New method. * src/libs/libgroff/nametoindex.cpp (character_indexer): Change return type of methods and field member type to glyph_t. (character_indexer::character_indexer): Update. (character_indexer::ascii_char_index): Allocate a name for the glyph. Return a glyph_t with name. (character_indexer::numbered_char_index): Return a glyph_t without a name. (character_indexer::named_char_index): Return a glyph_t with a name. (font::number_to_index, font::name_to_index): Update. * src/roff/troff/input.cpp (charinfo::charinfo): Use the symbol as the glyph's name.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/font.h24
-rw-r--r--src/include/ptable.h34
2 files changed, 48 insertions, 10 deletions
diff --git a/src/include/font.h b/src/include/font.h
index 43b95c93..05918114 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -29,33 +29,42 @@ typedef void (*FONT_COMMAND_HANDLER)(const char *, // command
// A glyph is represented by a font-independent glyph_t object.
// The functions font::name_to_index and font::number_to_index return such
// an object.
+// There are two types of glyphs:
+// - those with a name, and among these in particular:
+// "charNNN" denoting a single 'char' in the input character set,
+// "uXXXX" denoting a Unicode character,
+// - those with a number, referring to the the font-dependent glyph with
+// the given number.
struct glyph_t {
private:
int index; // A font-independent integer value.
+ const char *name; // Glyph name, statically allocated.
friend class font;
+ friend class character_indexer;
friend class charinfo;
- glyph_t(int); // Glyph with given index.
+ glyph_t(int, const char *); // Glyph with given index and name.
public:
glyph_t(); // Uninitialized glyph.
static glyph_t undefined_glyph(); // Undefined glyph.
int glyph_index();
+ const char *glyph_name();
int operator==(const glyph_t&) const;
int operator!=(const glyph_t&) const;
};
-inline glyph_t::glyph_t(int idx)
-: index (idx)
+inline glyph_t::glyph_t(int idx, const char *nm)
+: index (idx), name (nm)
{
}
inline glyph_t::glyph_t()
-: index (0xdeadbeef)
+: index (0xdeadbeef), name (NULL)
{
}
inline glyph_t glyph_t::undefined_glyph()
{
- return glyph_t(-1);
+ return glyph_t(-1, NULL);
}
#define UNDEFINED_GLYPH glyph_t::undefined_glyph()
@@ -64,6 +73,11 @@ inline int glyph_t::glyph_index()
return index;
}
+inline const char *glyph_t::glyph_name()
+{
+ return name;
+}
+
inline int glyph_t::operator==(const glyph_t &other) const
{
return index == other.index;
diff --git a/src/include/ptable.h b/src/include/ptable.h
index fadb158d..b0470e54 100644
--- a/src/include/ptable.h
+++ b/src/include/ptable.h
@@ -88,11 +88,20 @@ public: \
PTABLE(T)(); /* Create an empty table. */ \
~PTABLE(T)(); /* Delete a table, including its \
values. */ \
- void define(const char *, T *); /* Define the value (arg2) for a key \
- (arg1). */ \
+ const char *define(const char *, T *);/* Define the value (arg2) for a key \
+ (arg1). Return the copy in the \
+ table of the key (arg1), or \
+ possibly NULL if the value (arg2) \
+ is NULL. */ \
T *lookup(const char *); /* Return a pointer to the value of \
the given key, if found in the \
table, or NULL otherwise. */ \
+ T *lookupassoc(const char **); /* Return a pointer to the value of \
+ the given key, passed by reference,\
+ and replace the key argument with \
+ the copy found in the table, if \
+ the key is found in the table. \
+ Return NULL otherwise. */ \
friend class PTABLE_ITERATOR(T); \
};
@@ -125,7 +134,7 @@ PTABLE(T)::~PTABLE(T)() \
a_delete v; \
} \
\
-void PTABLE(T)::define(const char *key, T *val) \
+const char *PTABLE(T)::define(const char *key, T *val) \
{ \
assert(key != 0); \
unsigned long h = hash_string(key); \
@@ -136,10 +145,10 @@ void PTABLE(T)::define(const char *key, T *val) \
if (strcmp(v[n].key, key) == 0) { \
a_delete v[n].val; \
v[n].val = val; \
- return; \
+ return v[n].key; \
} \
if (val == 0) \
- return; \
+ return 0; \
if (used*FULL_DEN >= size*FULL_NUM) { \
PASSOC(T) *oldv = v; \
unsigned old_size = size; \
@@ -170,6 +179,7 @@ void PTABLE(T)::define(const char *key, T *val) \
v[n].key = temp; \
v[n].val = val; \
used++; \
+ return temp; \
} \
\
T *PTABLE(T)::lookup(const char *key) \
@@ -183,6 +193,20 @@ T *PTABLE(T)::lookup(const char *key) \
return 0; \
} \
\
+T *PTABLE(T)::lookupassoc(const char **keyptr) \
+{ \
+ const char *key = *keyptr; \
+ assert(key != 0); \
+ for (unsigned n = unsigned(hash_string(key) % size); \
+ v[n].key != 0; \
+ n = (n == 0 ? size - 1 : n - 1)) \
+ if (strcmp(v[n].key, key) == 0) { \
+ *keyptr = v[n].key; \
+ return v[n].val; \
+ } \
+ return 0; \
+} \
+ \
PTABLE_ITERATOR(T)::PTABLE_ITERATOR(T)(PTABLE(T) *t) \
: p(t), i(0) \
{ \