> Another solution would be to allow people to typedef the color index
> type used by Glyph in config.h, and move the definitions for Glyph,
> TCursor and Term below where config.h is included in st.c?
> 
> That way, it makes it easy to customize it for a low memory profile.

Here's another patch that does what I described. If the name for the
ColorIndex typdef isn't to your liking, please feel free to change it!

---
 config.def.h | 18 +++++++++++-----
 st.c         | 70 ++++++++++++++++++++++++++++++------------------------------
 2 files changed, 48 insertions(+), 40 deletions(-)

diff --git a/config.def.h b/config.def.h
index bb5596e..f0dbfa1 100644
--- a/config.def.h
+++ b/config.def.h
@@ -87,22 +87,30 @@ static const char *colorname[] = {
        "#cccccc",
 };
 
+/*
+ * Unsigned integral type large enough to hold color indices. It should be
+ * capable of indexing the full range of the colorname table. By default,
+ * it is defined to ushort so that it can handle the default extended colors
+ * above index 255, but if you restrict colorname to 256 or less colors in
+ * length you can define it to uchar to reduce memory consumption.
+ */
+typedef ushort ColorIndex;
 
 /*
  * Default colors (colorname index)
  * foreground, background, cursor
  */
-static unsigned int defaultfg = 7;
-static unsigned int defaultbg = 0;
-static unsigned int defaultcs = 256;
+static ColorIndex defaultfg = 7;
+static ColorIndex defaultbg = 0;
+static ColorIndex defaultcs = 256;
 
 /*
  * Colors used, when the specific fg == defaultfg. So in reverse mode this
  * will reverse too. Another logic would only make the simple feature too
  * complex.
  */
-static unsigned int defaultitalic = 11;
-static unsigned int defaultunderline = 7;
+static ColorIndex defaultitalic = 11;
+static ColorIndex defaultunderline = 7;
 
 /* Internal mouse shortcuts. */
 /* Beware that overloading Button1 will disable the selection. */
diff --git a/st.c b/st.c
index 0204b2e..f5c78e1 100644
--- a/st.c
+++ b/st.c
@@ -179,22 +179,6 @@ typedef unsigned short ushort;
 typedef XftDraw *Draw;
 typedef XftColor Color;
 
-typedef struct {
-       char c[UTF_SIZ]; /* character code */
-       ushort mode;      /* attribute flags */
-       uint32_t fg;      /* foreground  */
-       uint32_t bg;      /* background  */
-} Glyph;
-
-typedef Glyph *Line;
-
-typedef struct {
-       Glyph attr; /* current char attributes */
-       int x;
-       int y;
-       char state;
-} TCursor;
-
 /* CSI Escape sequence structs */
 /* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
 typedef struct {
@@ -216,25 +200,6 @@ typedef struct {
        int narg;              /* nb of args */
 } STREscape;
 
-/* Internal representation of the screen */
-typedef struct {
-       int row;      /* nb row */
-       int col;      /* nb col */
-       Line *line;   /* screen */
-       Line *alt;    /* alternate screen */
-       bool *dirty;  /* dirtyness of lines */
-       TCursor c;    /* cursor */
-       int top;      /* top    scroll limit */
-       int bot;      /* bottom scroll limit */
-       int mode;     /* terminal mode flags */
-       int esc;      /* escape state flags */
-       char trantbl[4]; /* charset table translation */
-       int charset;  /* current charset */
-       int icharset; /* selected charset for sequence */
-       bool numlock; /* lock numbers in keyboard */
-       bool *tabs;
-} Term;
-
 /* Purely graphic info */
 typedef struct {
        Display *dpy;
@@ -326,6 +291,41 @@ static void toggleprinter(const Arg *);
 /* Config.h for applying patches and the configuration. */
 #include "config.h"
 
+typedef struct {
+       char c[UTF_SIZ]; /* character code */
+       ushort mode;      /* attribute flags */
+       ColorIndex fg;    /* foreground  */
+       ColorIndex bg;    /* background  */
+} Glyph;
+
+typedef Glyph *Line;
+
+typedef struct {
+       Glyph attr; /* current char attributes */
+       int x;
+       int y;
+       char state;
+} TCursor;
+
+/* Internal representation of the screen */
+typedef struct {
+       int row;      /* nb row */
+       int col;      /* nb col */
+       Line *line;   /* screen */
+       Line *alt;    /* alternate screen */
+       bool *dirty;  /* dirtyness of lines */
+       TCursor c;    /* cursor */
+       int top;      /* top    scroll limit */
+       int bot;      /* bottom scroll limit */
+       int mode;     /* terminal mode flags */
+       int esc;      /* escape state flags */
+       char trantbl[4]; /* charset table translation */
+       int charset;  /* current charset */
+       int icharset; /* selected charset for sequence */
+       bool numlock; /* lock numbers in keyboard */
+       bool *tabs;
+} Term;
+
 /* Font structure */
 typedef struct {
        int height;
-- 
2.0.5

Attachment: signature.asc
Description: Digital signature

Reply via email to