groff-commit
[Top][All Lists]
Advanced

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

[Groff-commit] groff ./ChangeLog src/libs/libgroff/nametoindex...


From: Werner LEMBERG
Subject: [Groff-commit] groff ./ChangeLog src/libs/libgroff/nametoindex...
Date: Fri, 17 Feb 2006 16:47:24 +0000

CVSROOT:        /cvsroot/groff
Module name:    groff
Branch:         
Changes by:     Werner LEMBERG <address@hidden> 06/02/17 16:47:23

Modified files:
        .              : ChangeLog 
        src/libs/libgroff: nametoindex.cpp 

Log message:
        * src/libs/libgroff/nametoindex.cpp (character_indexer): Rename
        methods and fields from *_index to *_glyph.
        (character_indexer::named_char_glyph): Test for `charNNN' name
        here...
        (name_to_glyph): ... not here.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/groff/groff/ChangeLog.diff?tr1=1.906&tr2=1.907&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/groff/groff/src/libs/libgroff/nametoindex.cpp.diff?tr1=1.8&tr2=1.9&r1=text&r2=text

Patches:
Index: groff/ChangeLog
diff -u groff/ChangeLog:1.906 groff/ChangeLog:1.907
--- groff/ChangeLog:1.906       Fri Feb 17 16:39:42 2006
+++ groff/ChangeLog     Fri Feb 17 16:47:23 2006
@@ -1,5 +1,13 @@
 2006-02-17  Bruno Haible  <address@hidden>
 
+       * src/libs/libgroff/nametoindex.cpp (character_indexer): Rename
+       methods and fields from *_index to *_glyph.
+       (character_indexer::named_char_glyph): Test for `charNNN' name
+       here...
+       (name_to_glyph): ... not here.
+
+2006-02-17  Bruno Haible  <address@hidden>
+
        * src/include/font.h (name_to_glyph): Renamed from
        font::name_to_index.
        (number_to_glyph): Renamed from font::number_to_index.
@@ -5819,7 +5827,7 @@
 2002-10-13  Ruslan Ermilov  <address@hidden>
 
        Add the new -r option to grotty.  It is similar to the -i option
-       except it tells grotty(1) to use the "reverse video" attribute to
+       except it tells grotty(1) to use the `reverse video' attribute to
        render italic fonts.
 
        * src/devices/grotty/tty.cc (reverse_flag): New global variable.
Index: groff/src/libs/libgroff/nametoindex.cpp
diff -u groff/src/libs/libgroff/nametoindex.cpp:1.8 
groff/src/libs/libgroff/nametoindex.cpp:1.9
--- groff/src/libs/libgroff/nametoindex.cpp:1.8 Fri Feb 17 16:39:43 2006
+++ groff/src/libs/libgroff/nametoindex.cpp     Fri Feb 17 16:47:23 2006
@@ -39,26 +39,33 @@
   friend class glyph;
 };
 
+// PTABLE(charinfo) is a hash table mapping `const char *' to `charinfo *'.
 declare_ptable(charinfo)
 implement_ptable(charinfo)
 
+// ITABLE(charinfo) is a hash table mapping `int >= 0' to `charinfo *'.
 declare_itable(charinfo)
 implement_itable(charinfo)
 
+// This class is as a registry storing all named and numbered glyphs known
+// so far, and assigns a unique index to each glyph.
 class character_indexer {
 public:
   character_indexer();
   ~character_indexer();
-  glyph ascii_char_index(unsigned char);
-  glyph named_char_index(const char *);
-  glyph numbered_char_index(int);
+  // --------------------- Lookup or creation of a glyph.
+  glyph ascii_char_glyph(unsigned char);
+  glyph named_char_glyph(const char *);
+  glyph numbered_char_glyph(int);
 private:
+  int next_index;              // Number of glyphs already allocated.
+  PTABLE(charinfo) table;      // Table mapping name to glyph.
+  glyph ascii_glyph[256];      // Shorthand table for looking up "charNNN"
+                               // glyphs.
+  ITABLE(charinfo) ntable;     // Table mapping number to glyph.
   enum { NSMALL = 256 };
-  int next_index;
-  glyph ascii_index[256];
-  glyph small_number_index[NSMALL];
-  PTABLE(charinfo) table;
-  ITABLE(charinfo) ntable;
+  glyph small_number_glyph[NSMALL]; // Shorthand table for looking up
+                               // numbered glyphs with small numbers.
 };
 
 character_indexer::character_indexer()
@@ -66,18 +73,18 @@
 {
   int i;
   for (i = 0; i < 256; i++)
-    ascii_index[i] = UNDEFINED_GLYPH;
+    ascii_glyph[i] = UNDEFINED_GLYPH;
   for (i = 0; i < NSMALL; i++)
-    small_number_index[i] = UNDEFINED_GLYPH;
+    small_number_glyph[i] = UNDEFINED_GLYPH;
 }
 
 character_indexer::~character_indexer()
 {
 }
 
-glyph character_indexer::ascii_char_index(unsigned char c)
+glyph character_indexer::ascii_char_glyph(unsigned char c)
 {
-  if (ascii_index[c] == UNDEFINED_GLYPH) {
+  if (ascii_glyph[c] == UNDEFINED_GLYPH) {
     char buf[4+3+1];
     memcpy(buf, "char", 4);
     strcpy(buf + 4, i_to_a(c));
@@ -85,22 +92,42 @@
     ci->index = next_index++;
     ci->number = -1;
     ci->name = strsave(buf);
-    ascii_index[c] = glyph(ci);
+    ascii_glyph[c] = glyph(ci);
   }
-  return ascii_index[c];
+  return ascii_glyph[c];
 }
 
-glyph character_indexer::numbered_char_index(int n)
+inline glyph character_indexer::named_char_glyph(const char *s)
+{
+  // Glyphs with name `charNNN' are only stored in ascii_glyph[], not
+  // in the table.  Therefore treat them specially here.
+  if (s[0] == 'c' && s[1] == 'h' && s[2] == 'a' && s[3] == 'r') {
+    char *val;
+    long n = strtol(s + 4, &val, 10);
+    if (val != s + 4 && *val == '\0' && n >= 0 && n < 256)
+      return ascii_char_glyph((unsigned char)n);
+  }
+  charinfo *ci = table.lookupassoc(&s);
+  if (ci == NULL) {
+    ci = new charinfo[1];
+    ci->index = next_index++;
+    ci->number = -1;
+    ci->name = table.define(s, ci);
+  }
+  return glyph(ci);
+}
+
+inline glyph character_indexer::numbered_char_glyph(int n)
 {
   if (n >= 0 && n < NSMALL) {
-    if (small_number_index[n] == UNDEFINED_GLYPH) {
+    if (small_number_glyph[n] == UNDEFINED_GLYPH) {
       charinfo *ci = new charinfo;
       ci->index = next_index++;
       ci->number = n;
       ci->name = NULL;
-      small_number_index[n] = glyph(ci);
+      small_number_glyph[n] = glyph(ci);
     }
-    return small_number_index[n];
+    return small_number_glyph[n];
   }
   charinfo *ci = ntable.lookup(n);
   if (ci == NULL) {
@@ -113,38 +140,20 @@
   return glyph(ci);
 }
 
-glyph character_indexer::named_char_index(const char *s)
-{
-  charinfo *ci = table.lookupassoc(&s);
-  if (ci == NULL) {
-    ci = new charinfo[1];
-    ci->index = next_index++;
-    ci->number = -1;
-    ci->name = table.define(s, ci);
-  }
-  return glyph(ci);
-}
-
 static character_indexer indexer;
 
 glyph number_to_glyph(int n)
 {
-  return indexer.numbered_char_index(n);
+  return indexer.numbered_char_glyph(n);
 }
 
 glyph name_to_glyph(const char *s)
 {
   assert(s != 0 && s[0] != '\0' && s[0] != ' ');
   if (s[1] == '\0')
-    return indexer.ascii_char_index(s[0]);
-  /* char128 and \200 are synonyms */
-  if (s[0] == 'c' && s[1] == 'h' && s[2] == 'a' && s[3] == 'r') {
-    char *val;
-    long n = strtol(s + 4, &val, 10);
-    if (val != s + 4 && *val == '\0' && n >= 0 && n < 256)
-      return indexer.ascii_char_index((unsigned char)n);
-  }
-  return indexer.named_char_index(s);
+    // \200 and char128 are synonyms
+    return indexer.ascii_char_glyph(s[0]);
+  return indexer.named_char_glyph(s);
 }
 
 const char *glyph::glyph_name()




reply via email to

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