groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff-commit] groff ./ChangeLog src/include/font.h src/includ...


From: Werner LEMBERG
Subject: [Groff-commit] groff ./ChangeLog src/include/font.h src/includ...
Date: Sat, 11 Feb 2006 17:54:28 +0000

CVSROOT:        /cvsroot/groff
Module name:    groff
Branch:         
Changes by:     Werner LEMBERG <address@hidden> 06/02/11 17:54:28

Modified files:
        .              : ChangeLog 
        src/include    : font.h ptable.h 
        src/libs/libgroff: nametoindex.cpp 
        src/roff/troff : input.cpp 

Log message:
        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.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/groff/groff/ChangeLog.diff?tr1=1.899&tr2=1.900&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/include/font.h.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/include/ptable.h.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/libs/libgroff/nametoindex.cpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/roff/troff/input.cpp.diff?tr1=1.28&tr2=1.29&r1=text&r2=text

Patches:
Index: groff/ChangeLog
diff -u groff/ChangeLog:1.899 groff/ChangeLog:1.900
--- groff/ChangeLog:1.899       Sat Feb 11 17:51:09 2006
+++ groff/ChangeLog     Sat Feb 11 17:54:28 2006
@@ -1,5 +1,27 @@
 2006-02-11  Bruno Haible  <address@hidden>
 
+       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.
+
+2006-02-11  Bruno Haible  <address@hidden>
+
        * src/devices/grotty/tty.cpp (output_character_t): New type.
        (tty_printer::make_bold, tty_printer::add_char, tty_printer::put_char):
        Change argument type to output_character_t.
Index: groff/src/include/font.h
diff -u groff/src/include/font.h:1.10 groff/src/include/font.h:1.11
--- groff/src/include/font.h:1.10       Sat Feb 11 17:48:09 2006
+++ groff/src/include/font.h    Sat Feb 11 17:54:28 2006
@@ -29,33 +29,42 @@
 // 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 @@
   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;
Index: groff/src/include/ptable.h
diff -u groff/src/include/ptable.h:1.5 groff/src/include/ptable.h:1.6
--- groff/src/include/ptable.h:1.5      Thu Jan 26 15:15:00 2006
+++ groff/src/include/ptable.h  Sat Feb 11 17:54:28 2006
@@ -88,11 +88,20 @@
   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 @@
   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 @@
     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 @@
   v[n].key = temp;                                                           \
   v[n].val = val;                                                            \
   used++;                                                                    \
+  return temp;                                                               \
 }                                                                            \
                                                                              \
 T *PTABLE(T)::lookup(const char *key)                                        \
@@ -183,6 +193,20 @@
   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)                                                                 \
 {                                                                            \
Index: groff/src/libs/libgroff/nametoindex.cpp
diff -u groff/src/libs/libgroff/nametoindex.cpp:1.4 
groff/src/libs/libgroff/nametoindex.cpp:1.5
--- groff/src/libs/libgroff/nametoindex.cpp:1.4 Sat Feb 11 17:48:09 2006
+++ groff/src/libs/libgroff/nametoindex.cpp     Sat Feb 11 17:54:28 2006
@@ -36,14 +36,14 @@
 public:
   character_indexer();
   ~character_indexer();
-  int ascii_char_index(unsigned char);
-  int named_char_index(const char *);
-  int numbered_char_index(int);
+  glyph_t ascii_char_index(unsigned char);
+  glyph_t named_char_index(const char *);
+  glyph_t numbered_char_index(int);
 private:
   enum { NSMALL = 256 };
   int next_index;
-  int ascii_index[256];
-  int small_number_index[NSMALL];
+  glyph_t ascii_index[256];
+  glyph_t small_number_index[NSMALL];
   PTABLE(int) table;
 };
 
@@ -52,45 +52,55 @@
 {
   int i;
   for (i = 0; i < 256; i++)
-    ascii_index[i] = -1;
+    ascii_index[i] = glyph_t(-1, NULL);
   for (i = 0; i < NSMALL; i++)
-    small_number_index[i] = -1;
+    small_number_index[i] = glyph_t(-1, NULL);
 }
 
 character_indexer::~character_indexer()
 {
 }
 
-int character_indexer::ascii_char_index(unsigned char c)
+glyph_t character_indexer::ascii_char_index(unsigned char c)
 {
-  if (ascii_index[c] < 0)
-    ascii_index[c] = next_index++;
+  if (ascii_index[c].index < 0) {
+    char buf[4+3+1];
+    memcpy(buf, "char", 4);
+    strcpy(buf + 4, i_to_a(c));
+    ascii_index[c] = glyph_t(next_index++, strsave(buf));
+  }
   return ascii_index[c];
 }
 
-int character_indexer::numbered_char_index(int n)
+glyph_t character_indexer::numbered_char_index(int n)
 {
   if (n >= 0 && n < NSMALL) {
-    if (small_number_index[n] < 0)
-      small_number_index[n] = next_index++;
+    if (small_number_index[n].index < 0)
+      small_number_index[n] = glyph_t(next_index++, NULL);
     return small_number_index[n];
   }
   // Not the most efficient possible implementation.
-  char buf[INT_DIGITS + 3];
+  char buf[1 + 1 + INT_DIGITS + 1];
   buf[0] = ' ';
   strcpy(buf + 1, i_to_a(n));
-  return named_char_index(buf);
+  int *np = table.lookup(buf);
+  if (!np) {
+    np = new int[1];
+    *np = next_index++;
+    table.define(buf, np);
+  }
+  return glyph_t(*np, NULL);
 }
 
-int character_indexer::named_char_index(const char *s)
+glyph_t character_indexer::named_char_index(const char *s)
 {
-  int *np = table.lookup(s);
+  int *np = table.lookupassoc(&s);
   if (!np) {
     np = new int[1];
     *np = next_index++;
-    table.define(s, np);
+    s = table.define(s, np);
   }
-  return *np;
+  return glyph_t(*np, s);
 }
 
 static character_indexer indexer;
Index: groff/src/roff/troff/input.cpp
diff -u groff/src/roff/troff/input.cpp:1.28 groff/src/roff/troff/input.cpp:1.29
--- groff/src/roff/troff/input.cpp:1.28 Sat Feb 11 17:48:09 2006
+++ groff/src/roff/troff/input.cpp      Sat Feb 11 17:54:28 2006
@@ -8094,7 +8094,7 @@
   not_found(0), transparent_translate(1), translate_input(0),
   mode(CHAR_NORMAL), nm(s)
 {
-  index = glyph_t(next_index++);
+  index = glyph_t(next_index++, s.contents());
 }
 
 void charinfo::set_hyphenation_code(unsigned char c)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]