JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Adding the FAQ entry for zsh.
[st.git] / st.c
diff --git a/st.c b/st.c
index 6dcf0c7..0ea51d9 100644 (file)
--- a/st.c
+++ b/st.c
 #define XEMBED_FOCUS_OUT 5
 
 /* Arbitrary sizes */
-#define ESC_BUF_SIZ   256
+#define UTF_SIZ       4
+#define ESC_BUF_SIZ   (128*UTF_SIZ)
 #define ESC_ARG_SIZ   16
-#define STR_BUF_SIZ   256
-#define STR_ARG_SIZ   16
+#define STR_BUF_SIZ   ESC_BUF_SIZ
+#define STR_ARG_SIZ   ESC_ARG_SIZ
 #define DRAW_BUF_SIZ  20*1024
-#define UTF_SIZ       4
 #define XK_ANY_MOD    UINT_MAX
 #define XK_NO_MOD     0
 
@@ -168,7 +168,7 @@ typedef struct {
        int len;               /* raw string length */
        char priv;
        int arg[ESC_ARG_SIZ];
-       int narg;             /* nb of args */
+       int narg;              /* nb of args */
        char mode;
 } CSIEscape;
 
@@ -436,7 +436,7 @@ typedef struct {
  * the current length of used elements.
  */
 
-static Fontcache frc[256];
+static Fontcache frc[1024];
 static int frccur = -1, frclen = 0;
 
 ssize_t
@@ -1390,7 +1390,7 @@ tsetattr(int *attr, int l) {
                case 1:
                        term.c.attr.mode |= ATTR_BOLD;
                        break;
-               case 3: /* enter standout (highlight) */
+               case 3:
                        term.c.attr.mode |= ATTR_ITALIC;
                        break;
                case 4:
@@ -1406,7 +1406,7 @@ tsetattr(int *attr, int l) {
                case 22:
                        term.c.attr.mode &= ~ATTR_BOLD;
                        break;
-               case 23: /* leave standout (highlight) mode */
+               case 23:
                        term.c.attr.mode &= ~ATTR_ITALIC;
                        break;
                case 24:
@@ -1911,12 +1911,13 @@ tputc(char *c, int len) {
 
        if(iofd != -1) {
                if (xwrite(iofd, c, len) < 0) {
-                       fprintf(stderr, "Error writting in %s:%s\n",
+                       fprintf(stderr, "Error writing in %s:%s\n",
                                opt_io, strerror(errno));
                        close(iofd);
                        iofd = -1;
                }
        }
+
        /*
         * STR sequences must be checked before anything else
         * because it can use some control codes as part of the sequence.
@@ -1931,10 +1932,23 @@ tputc(char *c, int len) {
                        strhandle();
                        break;
                default:
-                       strescseq.buf[strescseq.len++] = ascii;
-                       if(strescseq.len+1 >= STR_BUF_SIZ) {
-                               term.esc = 0;
-                               strhandle();
+                       if(strescseq.len + len < sizeof(strescseq.buf)) {
+                               memmove(&strescseq.buf[strescseq.len], c, len);
+                               strescseq.len += len;
+                       } else {
+                       /*
+                        * Here is a bug in terminals. If the user never sends
+                        * some code to stop the str or esc command, then st
+                        * will stop responding. But this is better than
+                        * silently failing with unknown characters. At least
+                        * then users will report back.
+                        *
+                        * In the case users ever get fixed, here is the code:
+                        */
+                       /*
+                        * term.esc = 0;
+                        * strhandle();
+                        */
                        }
                }
                return;
@@ -2497,15 +2511,23 @@ xinit(void) {
        /* double buffering */
        if(!XdbeQueryExtension(xw.dpy, &major, &minor))
                die("Xdbe extension is not present\n");
-       xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeCopied);
+       xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeBackground);
 
        /* Xft rendering context */
        xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
 
        /* input methods */
-       xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
-       if(xw.xim == NULL)
-               die("XOpenIM failed. Could not open input device.\n");
+       if((xw.xim =  XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
+               XSetLocaleModifiers("@im=local");
+               if((xw.xim =  XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
+                       XSetLocaleModifiers("@im=");
+                       if((xw.xim = XOpenIM(xw.dpy,
+                                       NULL, NULL, NULL)) == NULL) {
+                               die("XOpenIM failed. Could not open input"
+                                       " device.\n");
+                       }
+               }
+       }
        xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
                                           | XIMStatusNothing, XNClientWindow, xw.win,
                                           XNFocusWindow, xw.win, NULL);
@@ -2542,7 +2564,6 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
        FcPattern *fcpattern, *fontpattern;
        FcFontSet *fcsets[] = { NULL };
        FcCharSet *fccharset;
-       XGlyphInfo extents;
        Colour *fg = &dc.col[base.fg], *bg = &dc.col[base.bg],
                 *temp, revfg, revbg;
        XRenderColor colfg, colbg;