qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs Makefile arabic.c bufed.c buffer.c cfb.c...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs Makefile arabic.c bufed.c buffer.c cfb.c...
Date: Sun, 31 Dec 2006 19:34:01 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        06/12/31 19:34:01

Modified files:
        .              : Makefile arabic.c bufed.c buffer.c cfb.c 
                         charset.c charsetmore.c clang.c cutils.c 
                         cutils.h dired.c display.c display.h 
                         fbfrender.c fbftoqe.c hex.c html.c html2png.c 
                         image.c input.c latex-mode.c libfbf.c list.c 
                         qe.c qe.h qfribidi.c shell.c tty.c unihex.c 
                         util.c video.c win32.c x11.c xml.c 

Log message:
        include cflags.mk for extra gcc warnings if present
        utf8_encode now returns the number of characters copied, 
          simplified code accordingly
        made local functions static
        tagged unused function arguments
        fixed shadowing issues
        added support for GCC attributes for unused arguments and format strings
        use snprintf() instead of sprintf()
        moved scattered declarations to qe.h
        removed duplicate declarations in header files
        eb_write() payload argument is now const
        fixed crash bug: reset trace_buffer upon deletion
        improved trace_buffer readability: trace all pseudo tty streams 
separately
        added missing structure initializers
        removed buffered string handling from cutils.h
        added new buffered string API for statically allocated buffers (should 
unify)
        small improvements in X11 initialization
        improved consistency in tty.c (function names...)
          added STDIN and STDOUT streams in QEditScreen to stop using stdin and 
stdout
          use unlocked stream I/O if available (faster)
          changed and documented terminal setup and exit sequences
          improved charset handling 
        mode_line functions now return the character count (like snprintf)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/Makefile?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/arabic.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/bufed.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/qemacs/cfb.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/charsetmore.c?cvsroot=qemacs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.h?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/display.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/display.h?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/fbfrender.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/fbftoqe.c?cvsroot=qemacs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/html.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/html2png.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/image.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/input.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/qemacs/libfbf.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/list.c?cvsroot=qemacs&r1=1.1.1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/qemacs/qfribidi.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/qemacs/unihex.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/qemacs/video.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/win32.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/x11.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.3&r2=1.4

Patches:
Index: Makefile
===================================================================
RCS file: /cvsroot/qemacs/qemacs/Makefile,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- Makefile    8 Jul 2005 13:02:04 -0000       1.7
+++ Makefile    31 Dec 2006 19:34:00 -0000      1.8
@@ -29,11 +29,15 @@
 #
 CONFIG_ALL_KMAPS=y
 
-CFLAGS:=-Wall -g $(CFLAGS) -funsigned-char
+CFLAGS:= -Wall -g $(CFLAGS) -funsigned-char
+
+-include cflags.mk
+
 ifdef TARGET_GPROF
 CFLAGS+= -p
 LDFLAGS+= -p
 endif
+
 ifdef TARGET_ARCH_X86
 #CFLAGS+=-fomit-frame-pointer
 ifeq ($(GCC_MAJOR),2)
@@ -42,6 +46,7 @@
 CFLAGS+=-march=i386 -falign-functions=0
 endif
 endif
+
 DEFINES=-DHAVE_QE_CONFIG_H
 
 ########################################################
@@ -336,8 +341,8 @@
 unifont.fbf
 FONTS:=$(addprefix fonts/,$(FONTS))
 
-fbftoqe$(EXE): fbftoqe.c
-       $(CC) $(CFLAGS) -o $@ $<
+fbftoqe$(EXE): fbftoqe.o cutils.o
+       $(CC) $(CFLAGS) -o $@ $^
 
 fbffonts.c: fbftoqe$(EXE) $(FONTS)
        ./fbftoqe $(FONTS) > $@

Index: arabic.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/arabic.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- arabic.c    11 May 2005 15:12:14 -0000      1.3
+++ arabic.c    31 Dec 2006 19:34:01 -0000      1.4
@@ -215,7 +215,7 @@
 }
 
 /* ctog is NOT filled because it is not needed. We put it for homogoneity */
-int arab_join(unsigned int *line, unsigned int *ctog, int len)
+int arab_join(unsigned int *line, __unused__ unsigned int *ctog, int len)
 {
     int a, b, c, i, j, res;
     const ArabicChar *aa, *bb, *cc;

Index: bufed.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/bufed.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- bufed.c     11 Dec 2006 23:08:50 -0000      1.5
+++ bufed.c     31 Dec 2006 19:34:01 -0000      1.6
@@ -111,7 +111,7 @@
 
 /* iterate 'func_item' to selected items. If no selected items, then
    use current item */
-void string_selection_iterate(StringArray *cs, 
+static void string_selection_iterate(StringArray *cs, 
                               int current_index,
                               void (*func_item)(void *, StringItem *),
                               void *opaque)

Index: buffer.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/buffer.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- buffer.c    11 Dec 2006 23:10:33 -0000      1.11
+++ buffer.c    31 Dec 2006 19:34:01 -0000      1.12
@@ -24,8 +24,6 @@
 static void eb_addlog(EditBuffer *b, enum LogOperation op, 
                       int offset, int size);
 
-extern EditBufferDataType raw_data_type;
-
 EditBufferDataType *first_buffer_data_type = NULL;
 
 /************************************************************/
@@ -119,12 +117,12 @@
 }
 
 /* Note: eb_write can be used to insert after the end of the buffer */
-void eb_write(EditBuffer *b, int offset, void *buf_arg, int size)
+void eb_write(EditBuffer *b, int offset, const void *buf_arg, int size)
 {
     int len, left;
-    u8 *buf = buf_arg;
+    const u8 *buf = buf_arg;
     
-    len = eb_rw(b, offset, buf, size, 1);
+    len = eb_rw(b, offset, (void *)buf, size, 1);
     left = size - len;
     if (left > 0) {
         offset += len;
@@ -422,7 +420,7 @@
     pos = strlen(name);
     n = 2;
     while (eb_find(name) != NULL) {
-        sprintf(name + pos, "<%d>", n);
+        snprintf(name + pos, sizeof(b->name) - pos, "<%d>", n);
         n++;
     }
     pstrcpy(b->name, sizeof(b->name), name);
@@ -499,6 +497,9 @@
     }
     *pb = (*pb)->next;
 
+    if (b == trace_buffer)
+        trace_buffer = NULL;
+
     free(b);
 }
 
@@ -546,7 +547,7 @@
     return NULL;
 }
 
-void eb_trace_bytes(void *buf, int size, int state)
+void eb_trace_bytes(const void *buf, int size, int state)
 {
     EditBuffer *b = trace_buffer;
     EditState *e;
@@ -555,9 +556,36 @@
     if (b) {
         point = b->total_size;
         if (trace_buffer_state != state) {
+            const char *str = NULL;
+            switch (trace_buffer_state) {
+            case EB_TRACE_TTY:
+                str = "|\n";
+                break;
+            case EB_TRACE_PTY:
+                str = "|\n";
+                break;
+            case EB_TRACE_SHELL:
+                str = "|\n";
+                break;
+            }
+            if (str) {
+                eb_write(b, b->total_size, str, strlen(str));
+            }
             trace_buffer_state = state;
-            eb_write(b, b->total_size,
-                     state == EB_TRACE_TTY ? "\n--|" : "|--\n", 4);
+            switch (trace_buffer_state) {
+            case EB_TRACE_TTY:
+                str = "--|";
+                break;
+            case EB_TRACE_PTY:
+                str = ">>|";
+                break;
+            case EB_TRACE_SHELL:
+                str = "<<|";
+                break;
+            }
+            if (str) {
+                eb_write(b, b->total_size, str, strlen(str));
+            }
         }
 #if 0
         /* CG: could make traces more readable: */
@@ -609,7 +637,7 @@
 }
 
 /* standard callback to move offsets */
-void eb_offset_callback(EditBuffer *b,
+void eb_offset_callback(__unused__ EditBuffer *b,
                         void *opaque,
                         enum LogOperation op,
                         int offset,
@@ -682,8 +710,7 @@
     lb.offset = offset;
     lb.size = size;
     lb.was_modified = was_modified;
-    eb_write(b->log_buffer, b->log_new_index, 
-             (unsigned char *) &lb, sizeof(LogBuffer));
+    eb_write(b->log_buffer, b->log_new_index, &lb, sizeof(LogBuffer));
     b->log_new_index += sizeof(LogBuffer);
 
     /* data */
@@ -699,8 +726,7 @@
         break;
     }
     /* trailer */
-    eb_write(b->log_buffer, b->log_new_index, 
-             (unsigned char *)&size_trailer, sizeof(int));
+    eb_write(b->log_buffer, b->log_new_index, &size_trailer, sizeof(int));
     b->log_new_index += sizeof(int);
 
     b->nb_logs++;
@@ -1315,7 +1341,7 @@
     return 0;
 }
 
-static void raw_close_buffer(EditBuffer *b)
+static void raw_close_buffer(__unused__ EditBuffer *b)
 {
     /* nothing to do */
 }
@@ -1535,6 +1561,7 @@
     raw_load_buffer,
     raw_save_buffer,
     raw_close_buffer,
+    NULL, /* next */
 };
 
 /* init buffer handling */

Index: cfb.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cfb.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- cfb.c       13 May 2005 09:53:45 -0000      1.3
+++ cfb.c       31 Dec 2006 19:34:01 -0000      1.4
@@ -297,8 +297,9 @@
 }
 
 
-static void cfb_set_clip(QEditScreen *s,
-                         int x, int y, int w, int h)
+static void cfb_set_clip(__unused__ QEditScreen *s,
+                         __unused__ int x, __unused__ int y,
+                         __unused__ int w, __unused__ int h)
 {
 }
 

Index: charset.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/charset.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- charset.c   11 Dec 2006 23:17:03 -0000      1.6
+++ charset.c   31 Dec 2006 19:34:01 -0000      1.7
@@ -88,7 +88,7 @@
     s->table = table_idem;
 }
 
-static unsigned char *encode_8859_1(QECharset *charset, 
+static unsigned char *encode_8859_1(__unused__ QECharset *charset, 
                                     unsigned char *p, int c)
 {
     if (c <= 0xff) {
@@ -107,6 +107,7 @@
     decode_8859_1_init,
     NULL,
     encode_8859_1,
+    0, 0, 0, NULL, NULL,
 };
 
 /********************************************************/
@@ -117,7 +118,7 @@
     s->table = table_idem;
 }
 
-static unsigned char *encode_vt100(QECharset *charset, 
+static unsigned char *encode_vt100(__unused__ QECharset *charset, 
                                    unsigned char *p, int c)
 {
     if (c <= 0xff) {
@@ -134,12 +135,13 @@
     decode_vt100_init,
     NULL,
     encode_vt100,
+    0, 0, 0, NULL, NULL,
 };
 
 /********************************************************/
 /* 7 bit */
 
-static unsigned char *encode_7bit(QECharset *charset,
+static unsigned char *encode_7bit(__unused__ QECharset *charset,
                                   unsigned char *p, int c)
 {
     if (c <= 0x7f) {
@@ -158,6 +160,7 @@
     decode_8859_1_init,
     NULL,
     encode_7bit,
+    0, 0, 0, NULL, NULL,
 };
 
 /********************************************************/
@@ -201,10 +204,12 @@
     return INVALID_CHAR;
 }
 
-/* NOTE: the buffer must be at least 6 bytes long. Return the position
-   of the next char. */
-char *utf8_encode(char *q, int c)
+/* NOTE: the buffer must be at least 6 bytes long. Return number of
+ * bytes copied. */
+int utf8_encode(char *q0, int c)
 {
+    char *q = q0;
+
     if (c < 0x80) {
         *q++ = c;
     } else {
@@ -231,7 +236,7 @@
         }
         *q++ = (c & 0x3f) | 0x80;
     }
-    return q;
+    return q - q0;
 }
 
 int utf8_to_unicode(unsigned int *dest, int dest_length, 
@@ -263,14 +268,16 @@
     s->table = table_utf8;
 }
 
-static int decode_utf8_func(CharsetDecodeState *s, const unsigned char **pp)
+static int decode_utf8_func(__unused__ CharsetDecodeState *s,
+                            const unsigned char **pp)
 {
     return utf8_decode((const char **)(void *)pp);
 }
 
-unsigned char *encode_utf8(QECharset *charset, unsigned char *q, int c)
+static unsigned char *encode_utf8(__unused__ QECharset *charset,
+                                  unsigned char *q, int c)
 {
-    return (unsigned char*)utf8_encode((char*)q, c);
+    return q + utf8_encode((char*)q, c);
 }
 
 static const char *aliases_utf_8[] = { "utf8", NULL };
@@ -281,6 +288,7 @@
     decode_utf8_init,
     decode_utf8_func,
     encode_utf8,
+    0, 0, 0, NULL, NULL,
 };
 
 /********************************************************/
@@ -390,7 +398,7 @@
     q = (char *)charset->encode_func(charset, (unsigned char*)buf, c);
     if (!q) {
         q = buf;
-        *q++ ='?';
+        *q++ = '?';
     }
     *q = '\0';
     return q - buf;

Index: charsetmore.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/charsetmore.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- charsetmore.c       11 May 2005 15:12:14 -0000      1.2
+++ charsetmore.c       31 Dec 2006 19:34:01 -0000      1.3
@@ -21,31 +21,6 @@
 /********************************************************/
 /* 8 bit charsets */
 
-extern QECharset charset_8859_2;
-extern QECharset charset_cp1125;
-extern QECharset charset_cp737;
-extern QECharset charset_koi8_r;
-extern QECharset charset_8859_4;
-extern QECharset charset_cp1250;
-extern QECharset charset_cp850;
-extern QECharset charset_koi8_u;
-extern QECharset charset_viscii;
-extern QECharset charset_8859_13;
-extern QECharset charset_8859_5;
-extern QECharset charset_cp1251;
-extern QECharset charset_cp852;
-extern QECharset charset_mac_lat2;
-extern QECharset charset_8859_15;
-extern QECharset charset_8859_7;
-extern QECharset charset_cp1257;
-extern QECharset charset_cp866;
-extern QECharset charset_macroman;
-extern QECharset charset_8859_16;
-extern QECharset charset_8859_9;
-extern QECharset charset_cp437;
-extern QECharset charset_kamen;
-extern QECharset charset_tcvn5712;
-
 void decode_8bit_init(CharsetDecodeState *s)
 {
     QECharset *charset = s->charset;
@@ -161,7 +136,8 @@
 }
 
 /* XXX: add state */
-static int decode_euc_jp_func(CharsetDecodeState *s, const unsigned char **pp)
+static int decode_euc_jp_func(__unused__ CharsetDecodeState *s,
+                              const unsigned char **pp)
 {
     const unsigned char *p;
     int c, c2;
@@ -198,7 +174,8 @@
     return c;
 }
 
-static unsigned char *encode_euc_jp(QECharset *s, unsigned char *q, int c)
+static unsigned char *encode_euc_jp(__unused__ QECharset *s,
+                                    unsigned char *q, int c)
 {
     if (c <= 0x7f) {
         *q++ = c;
@@ -245,7 +222,8 @@
 }
 
 /* XXX: add state */
-static int decode_sjis_func(CharsetDecodeState *s, const unsigned char **pp)
+static int decode_sjis_func(__unused__ CharsetDecodeState *s,
+                            const unsigned char **pp)
 {
     const unsigned char *p;
     int c, c1, c2, adjust, row, col;
@@ -272,7 +250,8 @@
     return c;
 }
 
-static unsigned char *encode_sjis(QECharset *s, unsigned char *q, int c)
+static unsigned char *encode_sjis(__unused__ QECharset *s,
+                                  unsigned char *q, int c)
 {
     if (c <= 0x7f) {
         *q++ = c;
@@ -325,5 +304,3 @@
 }
 
 qe_module_init(charset_more_init);
-
-

Index: clang.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/clang.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- clang.c     11 May 2005 15:12:14 -0000      1.6
+++ clang.c     31 Dec 2006 19:34:01 -0000      1.7
@@ -61,7 +61,7 @@
 };
 
 void c_colorize_line(unsigned int *buf, int len, 
-                     int *colorize_state_ptr, int state_only)
+                     int *colorize_state_ptr, __unused__ int state_only)
 {
     int c, state, l, type_decl;
     unsigned int *p, *p_start, *p1;
@@ -481,7 +481,7 @@
     s->offset = offset;
 }
     
-void do_c_indent_region(EditState *s)
+static void do_c_indent_region(EditState *s)
 {
     int col_num, p1, p2, tmp;
 
@@ -501,7 +501,7 @@
     }
 }
 
-void do_c_electric(EditState *s, int key)
+static void do_c_electric(EditState *s, int key)
 {
     do_char(s, key);
     do_c_indent(s);
@@ -520,7 +520,7 @@
     return 0;
 }
 
-int c_mode_init(EditState *s, ModeSavedData *saved_data)
+static int c_mode_init(EditState *s, ModeSavedData *saved_data)
 {
     int ret;
 
@@ -545,7 +545,7 @@
 
 static ModeDef c_mode;
 
-int c_init(void)
+static int c_init(void)
 {
     /* c mode is almost like the text mode, so we copy and patch it */
     memcpy(&c_mode, &text_mode, sizeof(ModeDef));

Index: cutils.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- cutils.c    11 Dec 2006 23:03:21 -0000      1.6
+++ cutils.c    31 Dec 2006 19:34:01 -0000      1.7
@@ -176,4 +176,26 @@
     return buf;
 }
 
+/* copy the n first char of a string and truncate it. */
+char *pstrncpy(char *buf, int buf_size, const char *s, int len)
+{
+    char *q;
+    int c;
+
+    if (buf_size > 0) {
+        q = buf;
+        if (len >= buf_size)
+            len = buf_size - 1;
+        while (len > 0) {
+            c = *s++;
+            if (c == '\0')
+                break;
+            *q++ = c;
+            len--;
+        }
+        *q = '\0';
+    }
+    return buf;
+}
+
 #endif

Index: cutils.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- cutils.h    11 Dec 2006 23:03:21 -0000      1.6
+++ cutils.h    31 Dec 2006 19:34:01 -0000      1.7
@@ -14,29 +14,7 @@
  */
 char *pstrncpy(char *buf, int buf_size, const char *s, int len);
 
-/* simple dynamic strings wrappers. The strings are always terminated
-   by zero except if they are empty. */
-
-typedef struct QString {
-    unsigned char *data;
-    int len; /* string length excluding trailing '\0' */
-} QString;
-
-static inline void qstrinit(QString *q)
-{
-    q->data = NULL;
-    q->len = 0;
-}
-
-static inline void qstrfree(QString *q)
-{
-    free(q->data);
-    q->data = NULL;
-}
-
-int qmemcat(QString *q, const unsigned char *data1, int len1);
-int qstrcat(QString *q, const char *str);
-int qprintf(QString *q, const char *fmt, ...);
+/* list.c */
 
 /* Double linked lists. Same api as the linux kernel */
 

Index: dired.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/dired.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- dired.c     11 Dec 2006 23:08:50 -0000      1.6
+++ dired.c     31 Dec 2006 19:34:01 -0000      1.7
@@ -50,11 +50,11 @@
 
 static void dired_view_file(EditState *s, const char *filename);
 
-extern inline int dired_get_index(EditState *s) {
+static inline int dired_get_index(EditState *s) {
     return list_get_pos(s) - DIRED_HEADER;
 }
 
-void dired_free(EditState *s)
+static void dired_free(EditState *s)
 {
     DiredState *ds = s->mode_data;
     int i;
@@ -214,10 +214,10 @@
 
 #define MAX_COL_FILE_SIZE 32
 
-void build_dired_list(EditState *s, const char *path)
+static void build_dired_list(EditState *s, const char *path)
 {
     DiredState *hs = s->mode_data;
-    FindFileState *ffs;
+    FindFileState *ffst;
     char filename[MAX_FILENAME_SIZE];
     char line[1024], buf[1024];
     const char *p;
@@ -233,8 +233,8 @@
     set_filename(s->b, hs->path);
     s->b->flags |= BF_DIRED;
 
-    ffs = find_file_open(hs->path, "*");
-    while (!find_file_next(ffs, filename, sizeof(filename))) {
+    ffst = find_file_open(hs->path, "*");
+    while (!find_file_next(ffst, filename, sizeof(filename))) {
         if (lstat(filename, &st) < 0)
             continue;
         p = basename(filename);
@@ -269,14 +269,14 @@
         line[len] = '\0';
         /* add file size or file info */
         if (S_ISREG(st.st_mode)) {
-            sprintf(buf, "%9ld", (long)st.st_size);
+            snprintf(buf, sizeof(buf), "%9ld", (long)st.st_size);
         } else if (S_ISDIR(st.st_mode)) {
-            sprintf(buf, "%9s", "<dir>");
+            snprintf(buf, sizeof(buf), "%9s", "<dir>");
         } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
             int major, minor;
             major = (st.st_rdev >> 8) & 0xff;
             minor = st.st_rdev & 0xff;
-            sprintf(buf, "%c%4d%4d", 
+            snprintf(buf, sizeof(buf), "%c%4d%4d", 
                     S_ISCHR(st.st_mode) ? 'c' : 'b', 
                     major, minor);
         } else if (S_ISLNK(st.st_mode)) {
@@ -304,7 +304,7 @@
             item->opaque = dip;
         }
     }
-    find_file_close(ffs);
+    find_file_close(ffst);
     do_dired_sort(s);
 }
 

Index: display.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/display.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- display.c   9 Dec 2006 19:02:07 -0000       1.5
+++ display.c   31 Dec 2006 19:34:01 -0000      1.6
@@ -112,6 +112,7 @@
 int qe_register_display(QEDisplay *dpy)
 {
     QEDisplay **p;
+
     p = &first_dpy;
     while (*p != NULL)
         p = &(*p)->next;

Index: display.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/display.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- display.h   8 Jul 2005 09:30:44 -0000       1.6
+++ display.h   31 Dec 2006 19:34:01 -0000      1.7
@@ -78,10 +78,10 @@
     int linesize[4];
 } QEPicture;
 
-struct QEditScreen;
 typedef struct QEditScreen QEditScreen;
+typedef struct QEDisplay QEDisplay;
 
-typedef struct QEDisplay {
+struct QEDisplay {
     const char *name;
     int (*dpy_probe)(void);
     int (*dpy_init)(QEditScreen *s, int w, int h);
@@ -115,11 +115,12 @@
     void (*dpy_bmp_unlock)(QEditScreen *s, QEBitmap *b);
     /* full screen support */
     void (*dpy_full_screen)(QEditScreen *s, int full_screen);
-    struct QEDisplay *next;
-} QEDisplay;
+    QEDisplay *next;
+};
 
 struct QEditScreen {
     struct QEDisplay dpy;
+    FILE *STDIN, *STDOUT;
     int width, height;
     QECharset *charset; /* the charset of the TTY, XXX: suppress that,
                           use a system in fonts instead */
@@ -187,12 +188,12 @@
 QEDisplay *probe_display(void);
 QEFont *select_font(QEditScreen *s, int style, int size);
 
-static inline QEFont *lock_font(QEditScreen *s, QEFont *font) {
+static inline QEFont *lock_font(__unused__ QEditScreen *s, QEFont *font) {
     if (font && font->refcount)
         font->refcount++;
     return font;
 }
-static inline void release_font(QEditScreen *s, QEFont *font) {
+static inline void release_font(__unused__ QEditScreen *s, QEFont *font) {
     if (font && font->refcount)
         font->refcount--;
 }

Index: fbfrender.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/fbfrender.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- fbfrender.c 13 May 2005 10:05:24 -0000      1.3
+++ fbfrender.c 31 Dec 2006 19:34:01 -0000      1.4
@@ -36,7 +36,7 @@
 static int cache_size = 0;
 static GlyphCache first_cache_entry;
 
-void glyph_cache_init(void)
+static void glyph_cache_init(void)
 {
     first_cache_entry.next = &first_cache_entry;
     first_cache_entry.prev = &first_cache_entry;
@@ -121,7 +121,7 @@
     return p;
 }
 
-GlyphCache *fbf_decode_glyph1(QEFont *font, int code)
+static GlyphCache *fbf_decode_glyph1(QEFont *font, int code)
 {
     UniFontData *uf = font->private;
     int glyph_index, size, src_width, src_height;
@@ -228,7 +228,7 @@
 
 #define MAX_MATCHES 32
 
-QEFont *fbf_open_font(QEditScreen *s, int style, int size)
+QEFont *fbf_open_font(__unused__ QEditScreen *s, int style, int size)
 {
     QEFont *font;
     UniFontData *uf, *uf_found;
@@ -275,17 +275,17 @@
     return font;
 }
 
-void fbf_close_font(QEditScreen *s, QEFont *font)
+void fbf_close_font(__unused__ QEditScreen *s, QEFont *font)
 {
     free(font);
 }
 
-void *my_malloc(void *opaque, int size)
+static void *my_malloc(__unused__ void *opaque, int size)
 {
     return malloc(size);
 }
 
-void my_free(void *opaque, void *ptr)
+static void my_free(__unused__ void *opaque, void *ptr)
 {
     free(ptr);
 }
@@ -395,14 +395,14 @@
     int size;
 } MemoryFile;
 
-int my_fbf_seek(void *infile, long pos)
+static int my_fbf_seek(void *infile, long pos)
 {
     MemoryFile *f = infile;
     f->offset = pos;
     return pos;
 }
 
-int my_fbf_read(void *infile, unsigned char *buf, int len)
+static int my_fbf_read(void *infile, unsigned char *buf, int len)
 {
     MemoryFile *f = infile;
     int len1;
@@ -414,7 +414,7 @@
     return len;
 }
 
-int my_fbf_getc(void *infile)
+static int my_fbf_getc(void *infile)
 {
     MemoryFile *f = infile;
     if (f->offset < f->size)
@@ -473,7 +473,7 @@
 
 extern const void *fbf_fonts[];
 
-int fbf_render_init(const char *font_path)
+int fbf_render_init(__unused__ const char *font_path)
 {
     const void **pp;
 

Index: fbftoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/fbftoqe.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- fbftoqe.c   11 May 2005 15:12:14 -0000      1.2
+++ fbftoqe.c   31 Dec 2006 19:34:01 -0000      1.3
@@ -5,9 +5,10 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include "cutils.h"
 
 
-void dump_font(const char *filename, const char *name)
+static void dump_font(const char *filename, const char *name)
 {
     int c;
     FILE *f;
@@ -38,7 +39,7 @@
     fclose(f);
 }
 
-void getname(char *name, int name_size, const char *filename)
+static void getname(char *name, int name_size, const char *filename)
 {
     const char *p;
     char *q;
@@ -48,7 +49,7 @@
         p = filename;
     else
         p++;
-    strcpy(name, p);
+    pstrcpy(name, name_size, p);
     q = strrchr(name, '.');
     if (q)
         *q = '\0';

Index: hex.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/hex.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- hex.c       9 Dec 2006 19:02:07 -0000       1.7
+++ hex.c       31 Dec 2006 19:34:01 -0000      1.8
@@ -90,14 +90,14 @@
         return -1;
 }
 
-void do_goto_byte(EditState *s, int offset)
+static void do_goto_byte(EditState *s, int offset)
 {
     if (offset < 0 || offset >= s->b->total_size)
         return;
     s->offset = offset;
 }
 
-void do_set_width(EditState *s, int w)
+static void do_set_width(EditState *s, int w)
 {
     if (w >= 1) {
         s->disp_width = w;
@@ -105,7 +105,7 @@
     }
 }
 
-void do_incr_width(EditState *s, int incr)
+static void do_incr_width(EditState *s, int incr)
 {
     int w;
     w = s->disp_width + incr;
@@ -113,8 +113,7 @@
         do_set_width(s, w);
 }
 
-
-void do_toggle_hex(EditState *s)
+static void do_toggle_hex(EditState *s)
 {
     s->hex_mode = !s->hex_mode;
 }
@@ -167,7 +166,7 @@
     return 0;
 }
 
-int detect_binary(const unsigned char *buf, int size)
+static int detect_binary(const unsigned char *buf, int size)
 {
     int i, c;
 
@@ -189,19 +188,19 @@
         return 0;
 }
 
-void hex_move_bol(EditState *s)
+static void hex_move_bol(EditState *s)
 {
     s->offset = align(s->offset, s->disp_width);
 }
 
-void hex_move_eol(EditState *s)
+static void hex_move_eol(EditState *s)
 {
     s->offset = align(s->offset, s->disp_width) + s->disp_width - 1;
     if (s->offset >= s->b->total_size)
         s->offset = s->b->total_size;
 }
 
-void hex_move_left_right(EditState *s, int dir)
+static void hex_move_left_right(EditState *s, int dir)
 {
     s->offset += dir;
     if (s->offset < 0)
@@ -210,7 +209,7 @@
         s->offset = s->b->total_size;
 }
 
-void hex_move_up_down(EditState *s, int dir)
+static void hex_move_up_down(EditState *s, int dir)
 {
     s->offset += dir * s->disp_width;
     if (s->offset < 0)
@@ -279,19 +278,18 @@
     }
 }
 
-void hex_mode_line(EditState *s, char *buf, int buf_size)
+static int hex_mode_line(EditState *s, char *buf, int buf_size)
 {
-    char *q;
-    int percent;
+    int percent, pos;
 
-    basic_mode_line(s, buf, buf_size, '-');
-    q = buf + strlen(buf);
-    q += sprintf(q, "0x%x--0x%x", 
+    pos = basic_mode_line(s, buf, buf_size, '-');
+    pos += snprintf(buf + pos, buf_size - pos, "0x%x--0x%x", 
                  s->offset, s->b->total_size);
     percent = 0;
     if (s->b->total_size > 0)
         percent = (s->offset * 100) / s->b->total_size;
-    q += sprintf(q, "--%d%%", percent);
+    pos += snprintf(buf + pos, buf_size - pos, "--%d%%", percent);
+    return pos;
 }
 
 ModeDef ascii_mode = { 

Index: html.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/html.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- html.c      8 Jul 2005 09:30:44 -0000       1.5
+++ html.c      31 Dec 2006 19:34:01 -0000      1.6
@@ -55,7 +55,7 @@
 #define MAX_LINE_SIZE 256
 
 static int recompute_offset_func(void *opaque, CSSBox *box,
-                                 int x0, int y0)
+                                 __unused__ int x0, __unused__ int y0)
 {
     RecomputeOffsetData *data = opaque;
     int offsets[MAX_LINE_SIZE+1];
@@ -131,7 +131,7 @@
 
 #endif
 
-static int html_test_abort(void *opaque)
+static int html_test_abort(__unused__ void *opaque)
 {
     return is_user_input_pending();
 }
@@ -352,7 +352,7 @@
     int offsetc;
 } ScrollContext;
 
-static int scroll_func(void *opaque, CSSBox *box, int x, int y)
+static int scroll_func(void *opaque, CSSBox *box, __unused__ int x, int y)
 {
     ScrollContext *m = opaque;
     int y1;
@@ -373,8 +373,8 @@
             m->offset_found = box->u.buffer.start;
         }
     }
-    if (m->offsetc >= box->u.buffer.start && 
-        m->offsetc <= box->u.buffer.end &&
+    if ((unsigned long)m->offsetc >= box->u.buffer.start && 
+        (unsigned long)m->offsetc <= box->u.buffer.end &&
         y >= 0 && y1 <= m->height) {
         m->offset_found = m->offsetc;
         return 1;
@@ -756,11 +756,11 @@
 }
 
 /* invalidate the html data if modification done (XXX: be more precise) */
-static void html_callback(EditBuffer *b,
+static void html_callback(__unused__ EditBuffer *b,
                           void *opaque,
-                          enum LogOperation op,
-                          int offset,
-                          int size)
+                          __unused__ enum LogOperation op,
+                          __unused__ int offset,
+                          __unused__ int size)
 {
     EditState *s = opaque;
     HTMLState *hs = s->mode_data;

Index: html2png.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/html2png.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- html2png.c  24 Apr 2006 13:49:38 -0000      1.5
+++ html2png.c  31 Dec 2006 19:34:01 -0000      1.6
@@ -33,7 +33,7 @@
 
 /* file I/O for the qHTML library */
 
-CSSFile *css_open(CSSContext *s, const char *filename)
+CSSFile *css_open(__unused__ CSSContext *s, const char *filename)
 {
     FILE *f;
     f = fopen(filename, "rb");
@@ -73,7 +73,7 @@
     fprintf(stderr, "%s:%d: %s\n", filename, line_num, msg);
 }
 
-void put_error(EditState *s, const char *fmt, ...)
+void put_error(__unused__ EditState *s, const char *fmt, ...)
 {
     va_list ap;
 
@@ -85,14 +85,16 @@
 
 
 /* dummy functions */
-int eb_nextc(EditBuffer *b, int offset, int *next_ptr)
+int eb_nextc(__unused__ EditBuffer *b,
+             __unused__ int offset, __unused__ int *next_ptr)
 {
     return 0;
 }
 
 /* find a resource file */
 /* XXX: suppress that */
-int find_resource_file(char *path, int path_size, const char *pattern)
+int find_resource_file(__unused__ char *path, __unused__ int path_size,
+                       __unused__ const char *pattern)
 {
     return -1;
 }
@@ -107,10 +109,29 @@
     NULL,
     ppm_init,
     ppm_close,
+    NULL, /* dpy_cursor_at */
+    NULL, /* dpy_flush */
+    NULL, /* dpy_is_user_input_pending */
+    NULL, /* dpy_fill_rectangle */
+    NULL, /* dpy_open_font */
+    NULL, /* dpy_close_font */
+    NULL, /* dpy_text_metrics */
+    NULL, /* dpy_draw_text */
+    NULL, /* dpy_set_clip */
+    NULL, /* dpy_selection_activate */
+    NULL, /* dpy_selection_request */
+    NULL, /* dpy_invalidate */
+    NULL, /* dpy_bmp_alloc */
+    NULL, /* dpy_bmp_free */
+    NULL, /* dpy_bmp_draw */
+    NULL, /* dpy_bmp_lock */
+    NULL, /* dpy_bmp_unlock */
+    NULL, /* dpy_full_screen */
+    NULL, /* next */
 };
 
 /* realloc ppm bitmap */
-int ppm_resize(QEditScreen *s, int w, int h)
+static int ppm_resize(QEditScreen *s, int w, int h)
 {
     CFBContext *cfb = s->private;
     unsigned char *data;
@@ -164,7 +185,7 @@
     free(cfb);
 }
 
-int ppm_save(QEditScreen *s, const char *filename)
+static int ppm_save(QEditScreen *s, const char *filename)
 {
     CFBContext *cfb = s->private;
     int w, h, x, y;
@@ -197,9 +218,8 @@
 }
 
 #ifdef CONFIG_PNG_OUTPUT
-extern void png_write_init();
 
-int png_save(QEditScreen *s, const char *filename)
+static int png_save(QEditScreen *s, const char *filename)
 {
     CFBContext *cfb = s->private;
     struct png_save_data {
@@ -306,14 +326,14 @@
 
 extern const char html_style[];
 
-static int html_test_abort(void *opaque)
+static int html_test_abort(__unused__ void *opaque)
 {
     return 0;
 }
 
 #define IO_BUF_SIZE 4096
 
-int draw_html(QEditScreen *scr, 
+static int draw_html(QEditScreen *scr, 
               const char *filename, QECharset *charset, int flags)
 {
     CSSContext *s = NULL;
@@ -392,7 +412,7 @@
     return -1;
 }
 
-void help(void)
+static void help(void)
 {
     printf("html2png version %s (c) 2002 Fabrice Bellard\n"
            "\n"
@@ -411,15 +431,12 @@
            DEFAULT_OUTFILENAME);
 }
 
-/* XXX: use module system */
-extern int charset_more_init(void);
-
 int main(int argc, char **argv)
 {
     QEDisplay *dpy;
     QEditScreen screen1, *screen = &screen1;
     int page_width, c, strict_xml, flags;
-    char *outfilename, *infilename;
+    const char *outfilename, *infilename;
     QECharset *charset;
 
     charset_init();

Index: image.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/image.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- image.c     11 Dec 2006 23:07:58 -0000      1.8
+++ image.c     31 Dec 2006 19:34:01 -0000      1.9
@@ -766,15 +766,14 @@
     update_bmp(e);
 }
 
-void image_mode_line(EditState *s, char *buf, int buf_size)
+int image_mode_line(EditState *s, char *buf, int buf_size)
 {
-    char *q;
+    int pos;
     EditBuffer *b = s->b;
     ImageBuffer *ib = b->data;
     char alpha_mode;
     
-    basic_mode_line(s, buf, buf_size, '-');
-    q = buf + strlen(buf);
+    pos = basic_mode_line(s, buf, buf_size, '-');
     if (ib->alpha_info & FF_ALPHA_SEMI_TRANSP)
         alpha_mode = 'A';
     else if (ib->alpha_info & FF_ALPHA_TRANSP)
@@ -782,11 +781,12 @@
     else
         alpha_mode = ' ';
 
-    q += sprintf(q, "%dx%d %s %c%c", 
+    pos += snprintf(buf + pos, buf_size - pos, "%dx%d %s %c%c", 
                  ib->width, ib->height, 
                  avcodec_get_pix_fmt_name(ib->pix_fmt),
                  alpha_mode,
                  ib->interleaved ? 'I' : ' ');
+    return pos;
 }
 
 static void pixel_format_completion(StringArray *cs, const char *input)

Index: input.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/input.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- input.c     11 Dec 2006 23:07:58 -0000      1.5
+++ input.c     31 Dec 2006 19:34:01 -0000      1.6
@@ -23,14 +23,17 @@
 
 InputMethod *input_methods;
 
-static int default_input(int *match_len_ptr, 
-                         const u8 *data, const unsigned int *buf, int len)
+static int default_input(__unused__ int *match_len_ptr, 
+                         __unused__ const u8 *data,
+                         __unused__ const unsigned int *buf,
+                         __unused__ int len)
 {
     return INPUTMETHOD_NOMATCH;
 }
 
 static int unicode_input(int *match_len_ptr, 
-                         const u8 *data, const unsigned int *buf, int len)
+                         __unused__ const u8 *data,
+                         const unsigned int *buf, int len)
 {
     int i, h, c;
     if (buf[0] != 'x')
@@ -54,14 +57,14 @@
 }
 
 static InputMethod default_input_method = { 
-    "default", default_input, NULL,
+    "default", default_input, NULL, NULL,
 };
 
 static InputMethod unicode_input_method = { 
-    "unicode", unicode_input, NULL,
+    "unicode", unicode_input, NULL, NULL,
 };
 
-void register_input_method(InputMethod *m)
+static void register_input_method(InputMethod *m)
 {
     InputMethod **p;
     p = &input_methods;
@@ -75,7 +78,7 @@
 /* XXX: use an edit buffer to access the kmap !!!! */
 
 /* parse the internal compressed input method format */
-int kmap_input(int *match_len_ptr, 
+static int kmap_input(int *match_len_ptr, 
                const u8 *data, const unsigned int *buf, int len)
 {
     const u8 *p, *p1;
@@ -171,7 +174,7 @@
 
 static int input_method_fd;
 
-void load_input_methods(void)
+static void load_input_methods(void)
 {
     char buf[MAX_FILENAME_SIZE], *q;
     long file_size;
@@ -224,7 +227,7 @@
     input_method_fd = fd;
 }
 
-void unload_input_methods(void)
+static void unload_input_methods(void)
 {
     if (input_method_fd >= 0) {
         close(input_method_fd);
@@ -233,7 +236,7 @@
 }
 #endif
 
-void input_completion(StringArray *cs, const char *input)
+static void input_completion(StringArray *cs, const char *input)
 {
     InputMethod *m;
 

Index: latex-mode.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- latex-mode.c        12 May 2005 17:03:56 -0000      1.11
+++ latex-mode.c        31 Dec 2006 19:34:01 -0000      1.12
@@ -23,16 +23,14 @@
 
 #define MAX_BUF_SIZE    512
 
-/* CG: move to header file! */
-EditBuffer *new_shell_buffer(const char *name, const char *path,
-                             const char **argv, int is_shell);
 static ModeDef latex_mode;
 
 /* TODO: add state handling to allow colorization of elements longer
  * than one line (eg, multi-line functions and strings)
  */
-static void latex_colorize_line(unsigned int *buf, int len, 
-                                int *colorize_state_ptr, int state_only)
+static void latex_colorize_line(unsigned int *buf, __unused__ int len, 
+                                int *colorize_state_ptr,
+                                __unused__ int state_only)
 {
     int c, state;
     unsigned int *p, *p_start;
@@ -186,17 +184,19 @@
     StringArray history;
     EditState *es;
 } latex_funcs[] = {
-    {"AmSTeX", "amstex '\\nonstopmode\\input %s'", 0, 1},
-    {"PDFLaTeX", "pdflatex '\\nonstopmode\\input{%s}'", 0, 1},
-    {"PDFTeX", "pdftex '\\nonstopmode\\input %s'", 0, 1},
-    {"Check", "lacheck %s", 0, 1},
-    {"BibTeX", "bibtex %s", 0, 1},
-    {"LaTeX", "latex --src-specials '\\nonstopmode\\input{%s}'", 0, 1},
-    {"ThumbPDF", "thumbpdf %s", 0, 1},
-    {"View", "xdvi %s.dvi -paper a4", 1, 0},
-    {"Print", "dvips %s -Plp", 1, 0},
-    {"File", "dvips %s.dvi -o %s.ps", 1, 1},
-    {0, 0, 0, 0}
+#define INIT_TAIL  NULL_STRINGARRAY, NULL
+    { "AmSTeX", "amstex '\\nonstopmode\\input %s'", 0, 1, INIT_TAIL },
+    { "PDFLaTeX", "pdflatex '\\nonstopmode\\input{%s}'", 0, 1, INIT_TAIL },
+    { "PDFTeX", "pdftex '\\nonstopmode\\input %s'", 0, 1, INIT_TAIL },
+    { "Check", "lacheck %s", 0, 1, INIT_TAIL },
+    { "BibTeX", "bibtex %s", 0, 1, INIT_TAIL },
+    { "LaTeX", "latex --src-specials '\\nonstopmode\\input{%s}'", 0, 1, 
INIT_TAIL },
+    { "ThumbPDF", "thumbpdf %s", 0, 1, INIT_TAIL },
+    { "View", "xdvi %s.dvi -paper a4", 1, 0, INIT_TAIL },
+    { "Print", "dvips %s -Plp", 1, 0, INIT_TAIL },
+    { "File", "dvips %s.dvi -o %s.ps", 1, 1, INIT_TAIL },
+    { NULL, NULL, 0, 0, INIT_TAIL },
+#undef INIT_TAIL
 };
 
 static void latex_completion(StringArray *cs, const char *input)
@@ -287,7 +287,7 @@
             /* pass the EditState through to latex_cmd_run() */
             latex_funcs[i].es = e;
             /* construct the command line to run */
-            snprintf(buf, sizeof(buf), latex_funcs[i].fmt, bname, bname);
+            strsubst(buf, sizeof(buf), latex_funcs[i].fmt, "%s", bname);
             if (latex_funcs[i].ask) {
                 char prompt[128];
                 snprintf(prompt, sizeof(prompt), "%s command: ",

Index: libfbf.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libfbf.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- libfbf.c    8 Jul 2005 09:30:44 -0000       1.5
+++ libfbf.c    31 Dec 2006 19:34:01 -0000      1.6
@@ -17,6 +17,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
 #include <stdlib.h>
 #include <string.h>
 
@@ -312,9 +313,9 @@
     uf->alow |= uf->fbf_getc(uf->infile);
 }
 
-static inline int decode_ctx(UniFontData *uf, unsigned char *ctx)
+static inline unsigned int decode_ctx(UniFontData *uf, unsigned char *ctx)
 {
-    int ctxval, range, shift, b;
+    unsigned int ctxval, range, shift, b;
     unsigned int alow, arange;
 
     alow = uf->alow;
@@ -354,7 +355,7 @@
     uf->arange = arange;
     uf->alow = alow;
 #ifdef DEBUG
-    printf("b=%d\n", b);
+    printf("b=%u\n", b);
 #endif
     return b;
 }

Index: list.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/list.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- list.c      29 May 2004 10:18:32 -0000      1.1.1.1
+++ list.c      31 Dec 2006 19:34:01 -0000      1.2
@@ -19,7 +19,7 @@
 #include "qe.h"
 
 static int list_get_colorized_line(EditState *s, unsigned int *buf, int 
buf_size,
-                                   int offset, int line_num)
+                                   int offset, __unused__ int line_num)
 {
     QEmacsState *qs = s->qe_state;
     int len;
@@ -72,7 +72,7 @@
     text_move_up_down(s, 1);
 }
 
-static int list_mode_init(EditState *s, ModeSavedData *saved_data)
+static int list_mode_init(EditState *s, __unused__ ModeSavedData *saved_data)
 {
     s->wrap = WRAP_TRUNCATE;
     s->interactive = 1;
@@ -80,7 +80,7 @@
     return 0;
 }
 
-static void list_mode_close(EditState *s)
+static void list_mode_close(__unused__ EditState *s)
 {
 }
 

Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- qe.c        11 Dec 2006 23:21:04 -0000      1.29
+++ qe.c        31 Dec 2006 19:34:01 -0000      1.30
@@ -39,7 +39,6 @@
                    int x, int y, int width, int height,
                    const char *str, int style_index);
 static void do_cmd_set_mode(EditState *s, const char *name);
-void do_delete_window(EditState *s, int force);
 void do_end_macro(EditState *s);
 static void get_default_path(EditState *s, char *buf, int buf_size);
 static EditBuffer *predict_switch_to_buffer(EditState *s);
@@ -211,7 +210,7 @@
 
 static int backspace_is_control_h;
 
-void do_toggle_control_h(EditState *s, int set)
+void do_toggle_control_h(__unused__ EditState *s, int set)
 {
     KeyDef *p;
     int i;
@@ -269,7 +268,7 @@
     do_previous_window(s);
 }
 
-void do_cd(EditState *s, const char *name)
+void do_cd(__unused__ EditState *s, const char *name)
 {
     chdir(name);
     /* CG: Should issue diagnostics upon failure */
@@ -375,7 +374,8 @@
 
 #define MAX_KEYS 10
 
-void do_global_set_key(EditState *s, const char *keystr, const char *cmd_name)
+void do_global_set_key(__unused__ EditState *s,
+                       const char *keystr, const char *cmd_name)
 {
     int nb_keys;
     unsigned int keys[MAX_KEYS];
@@ -772,7 +772,7 @@
 
 int cursor_func(DisplayState *ds,
                 int offset1, int offset2, int line_num,
-                int x, int y, int w, int h, int hex_mode)
+                int x, int y, int w, int h, __unused__ int hex_mode)
 {
     CursorContext *m = ds->cursor_opaque;
 
@@ -795,7 +795,7 @@
     }
 }
 
-void get_cursor_pos(EditState *s, CursorContext *m)
+static void get_cursor_pos(EditState *s, CursorContext *m)
 {
     DisplayState ds1, *ds = &ds1;
     
@@ -817,8 +817,10 @@
 
 /* called each time the cursor could be displayed */
 static int down_cursor_func(DisplayState *ds,
-                            int offset1, int offset2, int line_num,
-                            int x, int y, int w, int h, int hex_mode)
+                            int offset1, __unused__ int offset2, int line_num,
+                            int x, __unused__ int y,
+                            __unused__ int w, __unused__ int h,
+                            __unused__ int hex_mode)
 {
     int d;
     MoveContext *m = ds->cursor_opaque;
@@ -909,8 +911,11 @@
 
 /* called each time the cursor could be displayed */
 static int scroll_cursor_func(DisplayState *ds,
-                              int offset1, int offset2, int line_num,
-                              int x, int y, int w, int h, int hex_mode)
+                              int offset1, int offset2,
+                              __unused__ int line_num,
+                              __unused__ int x, int y,
+                              __unused__ int w, int h,
+                              __unused__ int hex_mode)
 {
     ScrollContext *m = ds->cursor_opaque;
     int y1;
@@ -1035,8 +1040,11 @@
 } LeftRightMoveContext;
 
 static int left_right_cursor_func(DisplayState *ds,
-                                  int offset1, int offset2, int line_num,
-                                  int x, int y, int w, int h, int hex_mode)
+                                  int offset1, __unused__ int offset2,
+                                  int line_num,
+                                  int x, __unused__ int y,
+                                  __unused__ int w, __unused__ int h,
+                                  __unused__ int hex_mode)
 {
     int d;
     LeftRightMoveContext *m = ds->cursor_opaque;
@@ -1145,7 +1153,8 @@
 /* XXX: would need two passes in the general case (first search line,
    then colunm */
 static int mouse_goto_func(DisplayState *ds,
-                           int offset1, int offset2, int line_num,
+                           int offset1, __unused__ int offset2,
+                           __unused__ int line_num,
                            int x, int y, int w, int h, int hex_mode)
 {
     MouseGotoContext *m = ds->cursor_opaque;
@@ -1226,7 +1235,7 @@
         
     if (insert) {
         const InputMethod *m;
-        int match_len, offset, i, offset1;
+        int match_len, offset, i;
             
         /* use compose system only if insert mode */
         if (s->compose_len == 0) 
@@ -1288,7 +1297,7 @@
 }
 
 /* XXX: may be better to move it into qe_key_process() */
-static void quote_key(void *opaque, int key)
+static void quote_key(__unused__ void *opaque, int key)
 {
     /* CG: should pass s as opaque */
     QEmacsState *qs = &qe_state;
@@ -1341,7 +1350,7 @@
     s->offset++;
 }
 
-void do_break(EditState *s)
+void do_break(__unused__ EditState *s)
 {
     /* well, currently nothing needs to be aborted in global context */
     /* CG: Should remove popups, sidepanes, helppanes... */
@@ -1375,7 +1384,7 @@
     return b;
 }
 
-void do_kill_region(EditState *s, int kill)
+void do_kill_region(EditState *s, int killtype)
 {
     int len, p1, p2, tmp, offset1;
     QEmacsState *qs = s->qe_state;
@@ -1385,7 +1394,7 @@
         return;
 
     p2 = s->offset;
-    if (kill == 2) {
+    if (killtype == 2) {
         /* kill line */
         if (eb_nextc(s->b, p2, &offset1) == '\n') {
             p1 = offset1;
@@ -1408,7 +1417,7 @@
     len = p2 - p1;
     b = new_yank_buffer();
     eb_insert_buffer(b, 0, s->b, p1, len);
-    if (kill) {
+    if (killtype) {
         eb_delete(s->b, p1, len);
         s->offset = p1;
     }
@@ -1721,8 +1730,9 @@
                             (c + '@') & 127);
         } else
         if (c < 127 || c >= 160) {
+            /* CG: should protect against buffer overflow */
             buf[pos++] = '\'';
-            pos = utf8_encode(buf + pos, c) - buf;
+            pos += utf8_encode(buf + pos, c);
             buf[pos++] = '\'';
             buf[pos++] = ' ';
         }
@@ -1755,12 +1765,11 @@
 
 /* compute string for the first part of the mode line (flags,
    filename, modename) */
-void basic_mode_line(EditState *s, char *buf, int buf_size, int c1)
+int basic_mode_line(EditState *s, char *buf, int buf_size, int c1)
 {
-    int mod, state;
-    char *q;
+    int mod, state, pos;
 
-    q = buf;
+    pos = 0;
     mod = s->b->modified ? '*' : '-';
     if (s->b->flags & BF_LOADING)
         state = 'L';
@@ -1770,7 +1779,8 @@
         state = 'B';
     else
         state = '-';
-    q += sprintf(q, "%c%c:%c%c  %-20s  (%s", 
+
+    pos += snprintf(buf + pos, buf_size - pos, "%c%c:%c%c  %-20s  (%s", 
                      c1,
                  state,
                  s->b->flags & BF_READONLY ? '%' : mod,
@@ -1778,17 +1788,18 @@
                  s->b->name,
                  s->mode->name);
     if (!s->insert)
-        q += sprintf(q, " Ovwrt");
+        pos += snprintf(buf + pos, buf_size - pos, " Ovwrt");
     if (s->interactive)
-        q += sprintf(q, " Interactive");
-    q += sprintf(q, ")--");
+        pos += snprintf(buf + pos, buf_size - pos, " Interactive");
+    pos += snprintf(buf + pos, buf_size - pos, ")--");
+
+    return pos;
 }
 
-void text_mode_line(EditState *s, char *buf, int buf_size)
+int text_mode_line(EditState *s, char *buf, int buf_size)
 {
     int line_num, col_num, wrap_mode;
-    int percent;
-    char *q;
+    int percent, pos;
 
     wrap_mode = '-';
     if (!s->hex_mode) {
@@ -1797,26 +1808,28 @@
         else if (s->wrap == WRAP_WORD)
             wrap_mode = 'W';
     }
-    basic_mode_line(s, buf, buf_size, wrap_mode);
-    q = buf + strlen(buf);
+    pos = basic_mode_line(s, buf, buf_size, wrap_mode);
 
     eb_get_pos(s->b, &line_num, &col_num, s->offset);
-    q += sprintf(q, "L%d--C%d--%s", 
+    pos += snprintf(buf + pos, buf_size - pos, "L%d--C%d--%s", 
                  line_num + 1, col_num, s->b->charset->name);
     if (s->bidir) {
-        q += sprintf(q, "--%s", s->cur_rtl ? "RTL" : "LTR");
+        pos += snprintf(buf + pos, buf_size - pos, "--%s",
+                        s->cur_rtl ? "RTL" : "LTR");
     }
     if (s->input_method) {
-        q += sprintf(q, "--%s", s->input_method->name);
+        pos += snprintf(buf + pos, buf_size - pos, "--%s",
+                        s->input_method->name);
     }
 #if 0
-    q += sprintf(q, "--[%d,%d]-[%d]", s->x_disp[0], s->x_disp[1], s->y_disp);
+    pos += snprintf(buf + pos, buf_size - pos, "--[%d,%d]-[%d]",
+                    s->x_disp[0], s->x_disp[1], s->y_disp);
 #endif
     percent = 0;
     if (s->b->total_size > 0)
         percent = (s->offset * 100) / s->b->total_size;
-    q += sprintf(q, "--%d%%", percent);
-    *q = '\0';
+    pos += snprintf(buf + pos, buf_size - pos, "--%d%%", percent);
+    return pos;
 }
 
 
@@ -2026,7 +2039,7 @@
     }
 }
 
-void do_set_display_size(EditState *s, int w, int h)
+void do_set_display_size(__unused__ EditState *s, int w, int h)
 {
     if (w != NO_ARG && h != NO_ARG) {
         screen_width = w;
@@ -2101,7 +2114,8 @@
     release_font(e->screen, font);
 }
 
-void display_bol_bidir(DisplayState *s, DirType base, int embedding_level_max)
+static void display_bol_bidir(DisplayState *s, DirType base,
+                              int embedding_level_max)
 {
     s->base = base;
     s->x_disp = s->edit_state->x_disp[base];
@@ -2119,7 +2133,7 @@
     display_bol_bidir(s, DIR_LTR, 0);
 }
 
-void reverse_fragments(TextFragment *str, int len)
+static void reverse_fragments(TextFragment *str, int len)
 {
     int i, len2 = len / 2;
     
@@ -2324,27 +2338,27 @@
         }
 
         for (i = 0; i < nb_fragments; i++) {
-            int w, k, j, offset1, offset2;
+            int w, k, j, _offset1, _offset2;
 
             frag = &fragments[i];
 
             j = frag->line_index;
             for (k = 0; k < frag->len; k++) {
                 int hex_mode;
-                offset1 = s->line_offsets[j][0];
-                offset2 = s->line_offsets[j][1];
+                _offset1 = s->line_offsets[j][0];
+                _offset2 = s->line_offsets[j][1];
                 hex_mode = s->line_hex_mode[j];
                 w = s->line_char_widths[j];
                 if (hex_mode == s->hex_mode || s->hex_mode == -1) {
                     if (s->base == DIR_RTL) {
-                        if (offset1 >= 0 && offset2 >= 0 &&
-                            s->cursor_func(s, offset1, offset2, s->line_num,
+                        if (_offset1 >= 0 && _offset2 >= 0 &&
+                            s->cursor_func(s, _offset1, _offset2, s->line_num,
                                            x + w, s->y, -w, line_height, 
                                            hex_mode))
                             s->eod = 1;
                     } else {
-                        if (offset1 >= 0 && offset2 >= 0 &&
-                            s->cursor_func(s, offset1, offset2, s->line_num,
+                        if (_offset1 >= 0 && _offset2 >= 0 &&
+                            s->cursor_func(s, _offset1, _offset2, s->line_num,
                                            x, s->y, w, line_height,
                                            hex_mode))
                             s->eod = 1;
@@ -2823,11 +2837,11 @@
 }
 
 /* invalidate the colorize data */
-static void colorize_callback(EditBuffer *b,
+static void colorize_callback(__unused__ EditBuffer *b,
                               void *opaque,
-                              enum LogOperation op,
+                              __unused__ enum LogOperation op,
                               int offset,
-                              int size)
+                              __unused__ int size)
 {
     EditState *e = opaque;
 
@@ -3149,26 +3163,26 @@
  * should pass function signature for direct dispatch.
  */
 void call_func(void *func, int nb_args, void **args, 
-               unsigned char *args_type)
+               __unused__ unsigned char *args_type)
 {
     switch (nb_args) {
     case 0:
-        ((void (*)())func)();
+        ((void (*)(void))func)();
         break;
     case 1:
-        ((void (*)())func)(args[0]);
+        ((void (*)(void *))func)(args[0]);
         break;
     case 2:
-        ((void (*)())func)(args[0], args[1]);
+        ((void (*)(void *, void *))func)(args[0], args[1]);
         break;
     case 3:
-        ((void (*)())func)(args[0], args[1], args[2]);
+        ((void (*)(void *, void *, void *))func)(args[0], args[1], args[2]);
         break;
     case 4:
-        ((void (*)())func)(args[0], args[1], args[2], args[3]);
+        ((void (*)(void *, void *, void *, void *))func)(args[0], args[1], 
args[2], args[3]);
         break;
     case 5:
-        ((void (*)())func)(args[0], args[1], args[2], args[3], args[4]);
+        ((void (*)(void *, void *, void *, void *, void *))func)(args[0], 
args[1], args[2], args[3], args[4]);
         break;
     default:
         return;
@@ -3511,8 +3525,8 @@
     if (has_popups) {
         for (s = qs->first_window; s != NULL; s = s->next_window) {
             if (s->flags & WF_POPUP) {
-                if (qs->complete_refresh)
-                    /* refresh frame */;
+                //if (qs->complete_refresh)
+                //    /* refresh frame */;
                 window_display(s);
             }
         }
@@ -3521,7 +3535,7 @@
     qs->complete_refresh = 0;
 }
 
-void do_universal_argument(EditState *s)
+void do_universal_argument(__unused__ EditState *s)
 {
     /* nothing is done there (see qe_key_process()) */
 }
@@ -3578,7 +3592,7 @@
     put_status(s, "Keyboard macro defined");
 }
 
-static void do_call_macro_bh(void *opaque)
+static void do_call_macro_bh(__unused__ void *opaque)
 {
     QEmacsState *qs = &qe_state;
     int key;
@@ -3609,7 +3623,7 @@
     }
 }
 
-void do_execute_macro_keys(EditState *s, const char *keys)
+void do_execute_macro_keys(__unused__ EditState *s, const char *keys)
 {
     int key;
     const char *p;
@@ -3752,7 +3766,7 @@
     c->keys[c->nb_keys++] = key;
     s = qs->active_window;
     if (!s->minibuf) {
-        put_status(s, "");
+        put_status(s, " ");
         dpy_flush(&global_screen);
     }
 
@@ -3811,8 +3825,9 @@
                 }
             }
         }
-        if (!c->describe_key)
+        if (!c->describe_key) {
             /* CG: should beep */;
+        }
 
         put_status(s, "No command on %s", 
                    keys_to_str(buf1, sizeof(buf1), c->keys, c->nb_keys));
@@ -3894,11 +3909,9 @@
     set_clip_rectangle(screen, &rect);
 
     /* start rectangle */
-    fill_rectangle(screen, x, y, width, height, 
-                   style.bg_color);
+    fill_rectangle(screen, x, y, width, height, style.bg_color);
     font = select_font(screen, style.font_style, style.font_size);
-    draw_text(screen, font, x, y + font->ascent,
-              ubuf, len, style.fg_color);
+    draw_text(screen, font, x, y + font->ascent, ubuf, len, style.fg_color);
     release_font(screen, font);
 }
 
@@ -3930,7 +3943,7 @@
     }
 }
 
-void put_error(EditState *s, const char *fmt, ...)
+void put_error(__unused__ EditState *s, const char *fmt, ...)
 {
     /* CG: s is not used and may be NULL! */
     QEmacsState *qs = &qe_state;
@@ -3944,7 +3957,7 @@
     eb_format_message(qs, "*errors*", buf);
 }
 
-void put_status(EditState *s, const char *fmt, ...)
+void put_status(__unused__ EditState *s, const char *fmt, ...)
 {
     /* CG: s is not used and may be NULL! */
     QEmacsState *qs = &qe_state;
@@ -4154,7 +4167,7 @@
 
 void file_completion(StringArray *cs, const char *input)
 {
-    FindFileState *ffs;
+    FindFileState *ffst;
     char path[MAX_FILENAME_SIZE];
     char file[MAX_FILENAME_SIZE];
     char filename[MAX_FILENAME_SIZE];
@@ -4164,8 +4177,8 @@
     splitpath(path, sizeof(path), file, sizeof(file), input);
     pstrcat(file, sizeof(file), "*");
 
-    ffs = find_file_open(*path ? path : ".", file);
-    while (find_file_next(ffs, filename, sizeof(filename)) == 0) {
+    ffst = find_file_open(*path ? path : ".", file);
+    while (find_file_next(ffst, filename, sizeof(filename)) == 0) {
         struct stat sb;
 
         base = basename(filename);
@@ -4190,7 +4203,7 @@
         add_string(cs, filename);
     }
 
-    find_file_close(ffs);
+    find_file_close(ffst);
 }
 
 void buffer_completion(StringArray *cs, const char *input)
@@ -4348,7 +4361,7 @@
 }
 
 /* scroll in completion popup */
-void minibuf_complete_scroll_up_down(EditState *s, int dir)
+void minibuf_complete_scroll_up_down(__unused__ EditState *s, int dir)
 {
     if (completion_popup_window) {
         completion_popup_window->force_highlight = 1;
@@ -4433,7 +4446,7 @@
     }
 }
 
-void do_minibuffer_exit(EditState *s, int abort)
+void do_minibuffer_exit(EditState *s, int do_abort)
 {
     QEmacsState *qs = s->qe_state;
     EditBuffer *b = s->b;
@@ -4448,7 +4461,7 @@
     if (completion_popup_window && 
         completion_popup_window->force_highlight) {
         int offset;
-        char buf[1024];
+
         offset = list_get_offset(completion_popup_window);
         eb_get_strline(completion_popup_window->b, buf, sizeof(buf), &offset);
         if (buf[0] != '\0')
@@ -4458,9 +4471,9 @@
     /* remove completion popup if present */
     /* CG: assuming completion_popup_window != s */
     if (completion_popup_window) {
-        EditBuffer *b = completion_popup_window->b;
+        EditBuffer *b1 = completion_popup_window->b;
         edit_close(completion_popup_window);
-        eb_free(b);
+        eb_free(b1);
         do_refresh(s);
     }
 
@@ -4484,7 +4497,7 @@
 
     /* force status update */
     strcpy(qs->status_shadow, " ");
-    put_status(NULL, "");
+    put_status(NULL, " ");
 
     /* call the callback */
     cb = minibuffer_cb;
@@ -4492,7 +4505,7 @@
     minibuffer_cb = NULL;
     minibuffer_opaque = NULL;
 
-    if (abort) {
+    if (do_abort) {
         cb(opaque, NULL);
     } else {
         retstr = strdup(buf);
@@ -5175,7 +5188,7 @@
     quit_examine_buffers(is);
 }
 
-static void quit_confirm_cb(void *opaque, char *reply)
+static void quit_confirm_cb(__unused__ void *opaque, char *reply)
 {
     if (!reply)
         return;
@@ -5280,19 +5293,6 @@
     }
 }
 
-void usprintf(char **pp, const char *fmt, ...)
-{
-    char *q = *pp;
-    int len;
-    va_list ap;
-
-    va_start(ap, fmt);
-    len = vsprintf(q, fmt, ap);
-    q += len;
-    *pp = q;
-    va_end(ap);
-}
-
 #define SEARCH_LENGTH 80
 #define FOUND_TAG 0x80000000
 
@@ -5300,7 +5300,7 @@
 static unsigned int last_search_string[SEARCH_LENGTH];
 static int last_search_string_len = 0;
 
-int search_abort_func(void *opaque)
+int search_abort_func(__unused__ void *opaque)
 {
     return is_user_input_pending();
 }
@@ -5319,7 +5319,8 @@
 static void isearch_display(ISearchState *is)
 {
     EditState *s = is->s;
-    char ubuf[256], *uq;
+    char ubuf[256];
+    buf_t out;
     u8 buf[2*SEARCH_LENGTH], *q; /* XXX: incorrect size */
     int i, len, hex_nibble, h;
     unsigned int v;
@@ -5366,36 +5367,36 @@
     }
             
     /* display search string */
-    uq = ubuf;
+    buf_init(&out, ubuf, sizeof(ubuf));
     if (is->found_offset < 0 && len > 0)
-        usprintf(&uq, "Failing ");
+        buf_printf(&out, "Failing ");
     if (s->hex_mode) {
-        usprintf(&uq, "hex ");
+        buf_printf(&out, "hex ");
     } else {
         if (is->search_flags & SEARCH_FLAG_WORD)
-            usprintf(&uq, "word ");
+            buf_printf(&out, "word ");
         if (is->search_flags & SEARCH_FLAG_IGNORECASE)
-            usprintf(&uq, "case-insensitive ");
+            buf_printf(&out, "case-insensitive ");
         else if (!(is->search_flags & SEARCH_FLAG_SMARTCASE))
-            usprintf(&uq, "case-sensitive ");
+            buf_printf(&out, "case-sensitive ");
     }
-    usprintf(&uq, "I-search");
+    buf_printf(&out, "I-search");
     if (is->dir < 0)
-        usprintf(&uq, " backward");
-    usprintf(&uq, ": ");
+        buf_printf(&out, " backward");
+    buf_printf(&out, ": ");
     for (i = 0; i < is->pos; i++) {
         v = is->search_string[i];
         if (!(v & FOUND_TAG)) {
-            uq = utf8_encode(uq, v);
+            if (!buf_putc_utf8(&out, v))
+                break;
         }
     }
-    *uq = '\0';
 
         /* display text */
     center_cursor(s);
     edit_display(s->qe_state);
 
-    put_status(NULL, ubuf);
+    put_status(NULL, "%s", out.buf);
 
     dpy_flush(s->screen);
 }
@@ -5715,7 +5716,7 @@
     s->display_invalid = 1;
 }
 
-void do_refresh(EditState *s1)
+void do_refresh(__unused__ EditState *s1)
 {
     /* CG: s1 may be NULL */
     QEmacsState *qs = &qe_state;
@@ -5963,7 +5964,7 @@
 /* help */
 
 static void print_bindings(EditBuffer *b, const char *title,
-                           int type, ModeDef *mode)
+                           __unused__ int type, ModeDef *mode)
 {
     CmdDef *d;
     KeyDef *k;
@@ -5998,7 +5999,7 @@
     }
 }
 
-EditBuffer *new_help_buffer(int *show_ptr)
+static EditBuffer *new_help_buffer(int *show_ptr)
 {
     EditBuffer *b;
 
@@ -6040,7 +6041,7 @@
     key_ctx.describe_key = 1;
 }
 
-void do_help_for_help(EditState *s)
+void do_help_for_help(__unused__ EditState *s)
 {
     EditBuffer *b;
     int show;
@@ -6074,7 +6075,7 @@
 
 int __fast_test_event_poll_flag = 0;
 
-static void poll_action(int sig)
+static void poll_action(__unused__ int sig)
 {
     __fast_test_event_poll_flag = 1;
 }
@@ -6195,7 +6196,7 @@
 static EditState *motion_target;
 static int motion_x, motion_y;
 
-int check_motion_target(EditState *s)
+static int check_motion_target(__unused__ EditState *s)
 {
     QEmacsState *qs = &qe_state;
     EditState *e;
@@ -6316,7 +6317,7 @@
             break;
         case MOTION_TEXT:
             {
-                EditState *e = motion_target;
+                e = motion_target;
                 if (!check_motion_target(e)) {
                     e->show_selection = 0;
                     motion_type = MOTION_NONE;
@@ -6420,7 +6421,7 @@
     }
 }
 
-static int text_mode_probe(ModeProbeData *p)
+static int text_mode_probe(__unused__ ModeProbeData *p)
 {
     return 10;
 }
@@ -6487,15 +6488,15 @@
 /* find a resource file */
 int find_resource_file(char *path, int path_size, const char *pattern)
 {
-    FindFileState *ffs;
+    FindFileState *ffst;
     int ret;
 
-    ffs = find_file_open(qe_state.res_path, pattern);
-    if (!ffs)
+    ffst = find_file_open(qe_state.res_path, pattern);
+    if (!ffst)
         return -1;
-    ret = find_file_next(ffs, path, path_size);
+    ret = find_file_next(ffst, path, path_size);
 
-    find_file_close(ffs);
+    find_file_close(ffst);
 
     return ret;
 }
@@ -6507,7 +6508,7 @@
  * displayed as a popup upon start.
  */
 
-int expect_token(const char **pp, int tok)
+static int expect_token(const char **pp, int tok)
 {
     skip_spaces(pp);
     if (**pp == tok) {
@@ -6669,7 +6670,7 @@
 
             switch (args_type[i]) {
             case CMD_ARG_INT:
-                args[i] = (void *)strtol(p, (char**)&q, 0);
+                args[i] = (void *)(intptr_t)strtol(p, (char**)&q, 0);
                 if (q == p) {
                     put_status(s, "Number expected for arg %d", i);
                     goto fail;
@@ -6739,7 +6740,7 @@
 void parse_config(EditState *e, const char *file)
 {
     QEmacsState *qs = e->qe_state;
-    FindFileState *ffs;
+    FindFileState *ffst;
     char filename[MAX_FILENAME_SIZE];
 
     if (file && *file) {
@@ -6747,13 +6748,13 @@
         return;
     }
 
-    ffs = find_file_open(qs->res_path, "config");
-    if (!ffs)
+    ffst = find_file_open(qs->res_path, "config");
+    if (!ffst)
         return;
-    while (find_file_next(ffs, filename, sizeof(filename)) == 0) {
+    while (find_file_next(ffst, filename, sizeof(filename)) == 0) {
         parse_config_file(e, filename);
     }
-    find_file_close(ffs);
+    find_file_close(ffst);
     if (file)
         do_refresh(e);
 }
@@ -6841,20 +6842,20 @@
 
 int parse_command_line(int argc, char **argv)
 {
-    int optind;
+    int _optind;
 
-    optind = 1;
+    _optind = 1;
     for (;;) {
-        const char *r, *r1, *r2, *optarg;
+        const char *r, *r1, *r2, *_optarg;
         CmdOptionDef *p;
 
-        if (optind >= argc)
+        if (_optind >= argc)
             break;
-        r = argv[optind];
+        r = argv[_optind];
         /* stop before first non option */
         if (r[0] != '-') 
             break;
-        optind++;
+        _optind++;
 
         r2 = r1 = r + 1;
         if (r2[0] == '-') {
@@ -6870,23 +6871,23 @@
                 if (!strcmp(p->name, r2) ||
                     (p->shortname && !strcmp(p->shortname, r1))) {
                     if (p->flags & CMD_OPT_ARG) {
-                        if (optind >= argc) {
+                        if (_optind >= argc) {
                             put_status(NULL,
                                        "cmdline argument expected -- %s", r);
                             goto next_cmd;
                         }
-                        optarg = argv[optind++];
+                        _optarg = argv[_optind++];
                     } else {
-                        optarg = NULL;
+                        _optarg = NULL;
                     }
                     if (p->flags & CMD_OPT_BOOL) {
                         *p->u.int_ptr = 1;
                     } else if (p->flags & CMD_OPT_STRING) {
-                        *p->u.string_ptr = optarg;
+                        *p->u.string_ptr = _optarg;
                     } else if (p->flags & CMD_OPT_INT) {
-                        *p->u.int_ptr = strtol(optarg, NULL, 0);
+                        *p->u.int_ptr = strtol(_optarg, NULL, 0);
                     } else if (p->flags & CMD_OPT_ARG) {
-                        p->u.func_arg(optarg);
+                        p->u.func_arg(_optarg);
                     } else {
                         p->u.func_noarg();
                     }
@@ -6899,7 +6900,7 @@
         put_status(NULL, "unknown cmdline option '%s'", r);
     next_cmd: ;
     }
-    return optind;
+    return _optind;
 }
 
 void set_user_option(const char *user)
@@ -6937,7 +6938,7 @@
       {func_arg: set_user_option}},
     { "version", "V", NULL, 0, "display version information and exit", 
       {func_noarg: show_version}},
-    { NULL },
+    { NULL, NULL, NULL, 0, NULL, { NULL }},
 };
 
 /* default key bindings */
@@ -6953,7 +6954,7 @@
 
 extern QEDisplay dummy_dpy;
 
-static int dummy_dpy_init(QEditScreen *s, int w, int h)
+static int dummy_dpy_init(QEditScreen *s, __unused__ int w, __unused__ int h)
 {
     memcpy(&s->dpy, &dummy_dpy, sizeof(QEDisplay));
 
@@ -6962,56 +6963,66 @@
     return 0;
 }
 
-static void dummy_dpy_close(QEditScreen *s)
+static void dummy_dpy_close(__unused__ QEditScreen *s)
 {
 }
 
-static void dummy_dpy_cursor_at(QEditScreen *s, int x1, int y1, int w, int h)
+static void dummy_dpy_cursor_at(__unused__ QEditScreen *s,
+                                __unused__ int x1, __unused__ int y1,
+                                __unused__ int w, __unused__ int h)
 {
 }
 
-static int dummy_dpy_is_user_input_pending(QEditScreen *s)
+static int dummy_dpy_is_user_input_pending(__unused__ QEditScreen *s)
 {
     return 0;
 }
 
-static void dummy_dpy_fill_rectangle(QEditScreen *s,
-                                     int x1, int y1, int w, int h,
-                                     QEColor color)
+static void dummy_dpy_fill_rectangle(__unused__ QEditScreen *s,
+                                     __unused__ int x1, __unused__ int y1,
+                                     __unused__ int w, __unused__ int h,
+                                     __unused__ QEColor color)
 {
 }
 
-static QEFont *dummy_dpy_open_font(QEditScreen *s,
-                                   int style, int size)
+static QEFont *dummy_dpy_open_font(__unused__ QEditScreen *s,
+                                   __unused__ int style, __unused__ int size)
 {
     return NULL;
 }
 
-static void dummy_dpy_close_font(QEditScreen *s, QEFont *font)
+static void dummy_dpy_close_font(__unused__ QEditScreen *s,
+                                 __unused__ QEFont *font)
 {
 }
 
-static void dummy_dpy_text_metrics(QEditScreen *s, QEFont *font, 
+static void dummy_dpy_text_metrics(__unused__ QEditScreen *s,
+                                   __unused__ QEFont *font, 
                                    QECharMetrics *metrics,
-                                   const unsigned int *str, int len)
+                                   __unused__ const unsigned int *str,
+                                   __unused__ int len)
 {
     metrics->font_ascent = 1;
     metrics->font_descent = 0;
     metrics->width = len;
 }
         
-static void dummy_dpy_draw_text(QEditScreen *s, QEFont *font, 
-                                int x, int y, const unsigned int *str, int len,
-                                QEColor color)
+static void dummy_dpy_draw_text(__unused__ QEditScreen *s,
+                                __unused__ QEFont *font, 
+                                __unused__ int x, __unused__ int y,
+                                __unused__ const unsigned int *str,
+                                __unused__ int len,
+                                __unused__ QEColor color)
 {
 }
 
-static void dummy_dpy_set_clip(QEditScreen *s,
-                               int x, int y, int w, int h)
+static void dummy_dpy_set_clip(__unused__ QEditScreen *s,
+                               __unused__ int x, __unused__ int y,
+                               __unused__ int w, __unused__ int h)
 {
 }
 
-static void dummy_dpy_flush(QEditScreen *s)
+static void dummy_dpy_flush(__unused__ QEditScreen *s)
 {
 }
 
@@ -7029,8 +7040,17 @@
     dummy_dpy_text_metrics,
     dummy_dpy_draw_text,
     dummy_dpy_set_clip,
-    NULL, /* no selection handling */
-    NULL, /* no selection handling */
+
+    NULL, /* dpy_selection_activate */
+    NULL, /* dpy_selection_request */
+    NULL, /* dpy_invalidate */
+    NULL, /* dpy_bmp_alloc */
+    NULL, /* dpy_bmp_free */
+    NULL, /* dpy_bmp_draw */
+    NULL, /* dpy_bmp_lock */
+    NULL, /* dpy_bmp_unlock */
+    NULL, /* dpy_full_screen */
+    NULL, /* next */
 };
 
 
@@ -7134,21 +7154,21 @@
 
 #ifdef CONFIG_DLL
 
-void load_all_modules(QEmacsState *qs)
+static void load_all_modules(QEmacsState *qs)
 {
     QErrorContext ec = qs->ec;
-    FindFileState *ffs;
+    FindFileState *ffst;
     char filename[MAX_FILENAME_SIZE];
     void *h;
     int (*init_func)(void);
     
-    ffs = find_file_open(qs->res_path, "*.so");
-    if (!ffs)
+    ffst = find_file_open(qs->res_path, "*.so");
+    if (!ffst)
         return;
 
     qs->ec.function = "load-all-modules";
 
-    while (!find_file_next(ffs, filename, sizeof(filename))) {
+    while (!find_file_next(ffst, filename, sizeof(filename))) {
         h = dlopen(filename, RTLD_LAZY);
         if (!h) {
             char *error = dlerror();
@@ -7168,7 +7188,7 @@
         /* all is OK: we can init the module now */
         init_func();
     }
-    find_file_close(ffs);
+    find_file_close(ffst);
     qs->ec = ec;
 }
 
@@ -7180,7 +7200,7 @@
 } QEArgs;
 
 /* init function */
-void qe_init(void *opaque)
+static void qe_init(void *opaque)
 {
     QEmacsState *qs = &qe_state;
     QEArgs *args = opaque;
@@ -7189,7 +7209,7 @@
     EditState *s;
     EditBuffer *b;
     QEDisplay *dpy;
-    int i, optind, is_player;
+    int i, _optind, is_player;
 
     qs->ec.function = "qe-init";
     qs->macro_key_index = -1; /* no macro executing */
@@ -7259,7 +7279,7 @@
     dummy_dpy.dpy_init(&global_screen, screen_width, screen_height);
 
     /* handle options */
-    optind = parse_command_line(argc, argv);
+    _optind = parse_command_line(argc, argv);
 
     /* load config file unless command line option given */
     if (!no_init_file)
@@ -7285,13 +7305,13 @@
     do_refresh(s);
 
     /* load file(s) */
-    for (i = optind; i < argc; i++) {
+    for (i = _optind; i < argc; i++) {
         do_load(s, argv[i]);
         /* CG: handle +linenumber */
     }
     
 #ifndef CONFIG_TINY
-    if (is_player && optind >= argc) {
+    if (is_player && _optind >= argc) {
         /* if player, go to directory mode by default if no file selected */
         do_dired(s);
     }

Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- qe.h        11 Dec 2006 23:15:42 -0000      1.25
+++ qe.h        31 Dec 2006 19:34:01 -0000      1.26
@@ -45,6 +45,17 @@
 #define vsnprintf _vsnprintf
 #endif
 
+#if (defined(__GNUC__) || defined(__TINYC__))
+/* make sure that the keyword is not disabled by glibc (TINYC case) */
+#undef __attribute__
+#define __attr_printf(a, b)  __attribute__((format(printf, a, b)))
+#define __unused__           __attribute__((unused))
+#else
+#define __attribute__(l)
+#define __attr_printf(a, b)
+#define __unused__
+#endif
+
 /************************/
 
 #include "cutils.h"
@@ -78,6 +89,20 @@
 
 /* util.c */
 
+/* string arrays */
+typedef struct StringItem {
+    void *opaque; /* opaque data that the user can use */
+    char selected; /* true if selected */
+    char str[1];
+} StringItem;
+
+typedef struct StringArray {
+    int nb_allocated;
+    int nb_items;
+    StringItem **items;
+} StringArray;
+#define NULL_STRINGARRAY  { 0, 0, NULL }
+
 /* media definitions */
 #define CSS_MEDIA_TTY     0x0001
 #define CSS_MEDIA_SCREEN  0x0002
@@ -91,7 +116,6 @@
     int x1, y1, x2, y2;
 } CSSRect;
 
-struct FindFileState;
 typedef struct FindFileState FindFileState;
 
 FindFileState *find_file_open(const char *path, const char *pattern);
@@ -105,36 +129,35 @@
 void splitpath(char *dirname, int dirname_size,
                char *filename, int filename_size, const char *pathname);
 
-int find_resource_file(char *path, int path_size, const char *pattern);
 int strfind(const char *keytable, const char *str, int casefold);
-void umemmove(unsigned int *dest, unsigned int *src, int len);
 void skip_spaces(const char **pp);
 int ustristart(const unsigned int *str, const char *val, const unsigned int 
**ptr);
-void css_strtolower(char *buf, int buf_size);
-
+static inline void umemmove(unsigned int *dest, unsigned int *src, int len) {
+    memmove(dest, src, len * sizeof(unsigned int));
+}
 void get_str(const char **pp, char *buf, int buf_size, const char *stop);
+int css_get_enum(const char *str, const char *enum_str);
 int compose_keys(unsigned int *keys, int *nb_keys);
 int strtokey(const char **pp);
 int strtokeys(const char *keystr, unsigned int *keys, int max_keys);
 void keytostr(char *buf, int buf_size, int key);
+int to_hex(int key);
+void color_completion(StringArray *cs, const char *input);
 int css_define_color(const char *name, const char *value);
 int css_get_color(unsigned int *color_ptr, const char *p);
 int css_get_font_family(const char *str);
 void css_union_rect(CSSRect *a, const CSSRect *b);
-static inline int css_is_null_rect(const CSSRect *a)
-{
+static inline int css_is_null_rect(const CSSRect *a) {
     return (a->x2 <= a->x1 || a->y2 <= a->y1);
 }
-static inline void css_set_rect(CSSRect *a, int x1, int y1, int x2, int y2)
-{
+static inline void css_set_rect(CSSRect *a, int x1, int y1, int x2, int y2) {
     a->x1 = x1;
     a->y1 = y1;
     a->x2 = x2;
     a->y2 = y2;
 }
 /* return true if a and b intersect */
-static inline int css_is_inter_rect(const CSSRect *a, const CSSRect *b)
-{
+static inline int css_is_inter_rect(const CSSRect *a, const CSSRect *b) {
     return (!(a->x2 <= b->x1 ||
               a->x1 >= b->x2 ||
               a->y2 <= b->y1 ||
@@ -142,50 +165,81 @@
 }
 
 /* CG: what about \v and \f */
-static inline int css_is_space(int ch)
-{
+static inline int css_is_space(int ch) {
     return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t');
 }
 
-int css_get_enum(const char *str, const char *enum_str);
+void css_strtolower(char *buf, int buf_size);
+void set_color(unsigned int *buf, int len, int style);
 
 int get_clock_ms(void);
 
-typedef int (CSSAbortFunc)(void *);
+/* Various string packages: should unify these but keep API simple */
 
-static inline int max(int a, int b)
-{
-    if (a > b)
-        return a;
-    else
-        return b;
+StringItem *set_string(StringArray *cs, int index, const char *str);
+StringItem *add_string(StringArray *cs, const char *str);
+void free_strings(StringArray *cs);
+
+/* simple dynamic strings wrappers. The strings are always terminated
+   by zero except if they are empty. */
+typedef struct QString {
+    unsigned char *data;
+    int len; /* string length excluding trailing '\0' */
+} QString;
+
+static inline void qstrinit(QString *q) {
+    q->data = NULL;
+    q->len = 0;
 }
 
-static inline int min(int a, int b)
-{
-    if (a < b)
-        return a;
-    else
-        return b;
+static inline void qstrfree(QString *q) {
+    free(q->data);
+    q->data = NULL;
 }
 
-/* string arrays */
+int qmemcat(QString *q, const unsigned char *data1, int len1);
+int qstrcat(QString *q, const char *str);
+int qprintf(QString *q, const char *fmt, ...) __attr_printf(2,3);
+
+/* Dynamic buffers with static allocation */
+typedef struct buf_t buf_t;
+struct buf_t {
+    char *buf;
+    int size, len, pos;
+};
 
-typedef struct StringItem {
-    void *opaque; /* opaque data that the user can use */
-    char selected; /* true if selected */
-    char str[1];
-} StringItem;
+static inline buf_t *buf_init(buf_t *bp, char *buf, int size) {
+    if (size > 0) {
+        bp->buf = buf;
+        bp->size = size;
+        *buf = '\0';
+    } else {
+        bp->buf = NULL;
+        bp->size = 0;
+    }
+    bp->len = bp->pos = 0;
+    return bp;
+}
+static inline int buf_avail(buf_t *bp) {
+    return bp->size - bp->pos - 1;
+}
+static inline int buf_put_byte(buf_t *bp, int c) {
+    if (bp->len < bp->size - 1) {
+        bp->buf[bp->len++] = c;
+        bp->buf[bp->len] = '\0';
+    }
+    return bp->pos++;
+}
+int buf_write(buf_t *bp, const void *src, int size);
+static inline int buf_puts(buf_t *bp, const char *str) {
+    return buf_write(bp, str, strlen(str));
+}
 
-typedef struct StringArray {
-    int nb_allocated;
-    int nb_items;
-    StringItem **items;
-} StringArray;
+int buf_printf(buf_t *bp, const char *fmt, ...) __attr_printf(2,3);
+int buf_putc_utf8(buf_t *bp, int c);
 
-StringItem *set_string(StringArray *cs, int index, const char *str);
-StringItem *add_string(StringArray *cs, const char *str);
-void free_strings(StringArray *cs);
+int strsubst(char *buf, int buf_size, const char *from,
+             const char *s1, const char *s2);
 
 /* command line option */
 #define CMD_OPT_ARG      0x0001 /* argument */
@@ -202,7 +256,7 @@
     union {
         const char **string_ptr;
         int *int_ptr;
-        void (*func_noarg)();
+        void (*func_noarg)(void);
         void (*func_arg)(const char *);
         struct CmdOptionDef *next;
     } u;
@@ -210,6 +264,24 @@
 
 void qe_register_cmd_line_options(CmdOptionDef *table);
 
+int find_resource_file(char *path, int path_size, const char *pattern);
+
+typedef int (CSSAbortFunc)(void *);
+
+static inline int max(int a, int b) {
+    if (a > b)
+        return a;
+    else
+        return b;
+}
+
+static inline int min(int a, int b) {
+    if (a < b)
+        return a;
+    else
+        return b;
+}
+
 /* charset.c */
 
 /* maximum number of bytes for a character in all the supported charsets */
@@ -274,10 +346,11 @@
 #define ESCAPE_CHAR  0xffff
 
 void charset_init(void);
+int charset_more_init(void);
 
 void qe_register_charset(QECharset *charset);
 
-char *utf8_encode(char *q, int c);
+int utf8_encode(char *q, int c);
 int utf8_decode(const char **pp);
 extern unsigned char utf8_length[256];
 
@@ -576,11 +649,12 @@
 extern int trace_buffer_state;
 #define EB_TRACE_TTY    1
 #define EB_TRACE_SHELL  2
-void eb_trace_bytes(void *buf, int size, int state);
+#define EB_TRACE_PTY    4
+void eb_trace_bytes(const void *buf, int size, int state);
 
 void eb_init(void);
 int eb_read(EditBuffer *b, int offset, void *buf, int size);
-void eb_write(EditBuffer *b, int offset, void *buf, int size);
+void eb_write(EditBuffer *b, int offset, const void *buf, int size);
 void eb_insert_buffer(EditBuffer *dest, int dest_offset, 
                       EditBuffer *src, int src_offset, 
                       int size);
@@ -603,6 +677,7 @@
 void do_undo(EditState *s);
 
 int raw_load_buffer1(EditBuffer *b, FILE *f, int offset);
+int mmap_buffer(EditBuffer *b, const char *filename);
 int save_buffer(EditBuffer *b);
 void set_buffer_name(EditBuffer *b, const char *name1);
 void set_filename(EditBuffer *b, const char *filename);
@@ -615,7 +690,7 @@
                         enum LogOperation op,
                         int offset,
                         int size);
-void eb_printf(EditBuffer *b, const char *fmt, ...);
+void eb_printf(EditBuffer *b, const char *fmt, ...) __attr_printf(2,3);
 void eb_line_pad(EditBuffer *b, int n);
 int eb_get_str(EditBuffer *b, char *buf, int buf_size);
 int eb_get_line(EditBuffer *b, unsigned int *buf, int buf_size,
@@ -648,10 +723,6 @@
 #else /* QE_MODULE */
 
 #if (defined(__GNUC__) || defined(__TINYC__)) && defined(CONFIG_INIT_CALLS)
-
-/* make sure that the keyword is not disabled by glibc (TINYC case) */
-#undef __attribute__ 
-
 #if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3)
 /* same method as the linux kernel... */
 #define __init_call     __attribute__((unused, __section__ (".initcall.init")))
@@ -801,7 +872,6 @@
 
 #define SAVED_DATA_SIZE ((int)&((EditState *)0)->end_of_saved_data)
 
-int to_hex(int key);
 
 struct DisplayState;
 
@@ -853,7 +923,7 @@
     int mode_flags;
 #define MODEF_NOCMD 0x0001 /* do not register xxx-mode command automatically */
     EditBufferDataType *data_type; /* native buffer data type (NULL = raw) */
-    void (*mode_line)(EditState *s, char *buf, int buf_size); /* return mode 
line */
+    int (*mode_line)(EditState *s, char *buf, int buf_size); /* return mode 
line */
     struct ModeDef *next;
 } ModeDef;
 
@@ -967,11 +1037,12 @@
 #define CMDV(key, key_alt, name, func, val, args) { key, key_alt, name "\0" 
args, { (void *)(func) }, (void *)(val) },
 
 /* old macros for compatibility */
-#define CMD0(key, key_alt, name, func) { key, key_alt, name "\0", { (void 
*)(func) } },
+#define CMD0(key, key_alt, name, func) { key, key_alt, name "\0", { (void 
*)(func) }, NULL },
 #define CMD1(key, key_alt, name, func, val) { key, key_alt, name "\0v", { 
(void *)(func) }, (void*)(val) },
 #define CMD_DEF_END { 0, 0, NULL, { NULL }, 0 }
 
 void qe_register_mode(ModeDef *m);
+void mode_completion(StringArray *cs, const char *input);
 void qe_register_cmd_table(CmdDef *cmds, const char *mode);
 void qe_register_binding(int key, const char *cmd_name, 
                          const char *mode_names);
@@ -1059,7 +1130,7 @@
 void display_eol(DisplayState *s, int offset1, int offset2);
 
 void display_printf(DisplayState *ds, int offset1, int offset2,
-                    const char *fmt, ...);
+                    const char *fmt, ...) __attr_printf(4,5);
 void display_printhex(DisplayState *s, int offset1, int offset2, 
                       unsigned int h, int n);
 
@@ -1117,27 +1188,24 @@
 } CompletionEntry;
 
 void register_completion(const char *name, CompletionFunc completion_func);
-void put_status(EditState *s, const char *fmt, ...);
-void put_error(EditState *s, const char *fmt, ...);
+void put_status(EditState *s, const char *fmt, ...) __attr_printf(2,3);
+void put_error(EditState *s, const char *fmt, ...) __attr_printf(2,3);
 void minibuffer_edit(const char *input, const char *prompt, 
                      StringArray *hist, CompletionFunc completion_func,
                      void (*cb)(void *opaque, char *buf), void *opaque);
 void command_completion(StringArray *cs, const char *input);
 void file_completion(StringArray *cs, const char *input);
 void buffer_completion(StringArray *cs, const char *input);
-void color_completion(StringArray *cs, const char *input);
 
 #ifdef WIN32
-static inline int is_user_input_pending(void)
-{
+static inline int is_user_input_pending(void) {
     return 0;
 }
 #else
 extern int __fast_test_event_poll_flag;
 int __is_user_input_pending(void);
 
-static inline int is_user_input_pending(void)
-{
+static inline int is_user_input_pending(void) {
     if (__fast_test_event_poll_flag) {
         __fast_test_event_poll_flag = 0;
         return __is_user_input_pending();
@@ -1175,12 +1243,12 @@
 /* loading files */
 void do_quit(EditState *s);
 void do_load(EditState *s, const char *filename);
+void do_load_from_path(EditState *s, const char *filename);
 void do_switch_to_buffer(EditState *s, const char *bufname);
 void do_break(EditState *s);
 void do_insert_file(EditState *s, const char *filename);
 void do_save(EditState *s, int save_as);
 void do_isearch(EditState *s, int dir);
-void do_refresh(EditState *s);
 void do_refresh_complete(EditState *s);
 
 /* text mode */
@@ -1193,10 +1261,8 @@
 void set_colorize_func(EditState *s, ColorizeFunc colorize_func);
 int get_colorized_line(EditState *s, unsigned int *buf, int buf_size,
                        int offset1, int line_num);
-void set_color(unsigned int *buf, int len, int style);
 
 void do_char(EditState *s, int key);
-void do_switch_to_buffer(EditState *s, const char *bufname);
 void do_set_mode(EditState *s, ModeDef *m, ModeSavedData *saved_data);
 void text_move_left_right_visual(EditState *s, int dir);
 void text_move_word_left_right(EditState *s, int dir);
@@ -1211,19 +1277,119 @@
 void do_kill_buffer(EditState *s, const char *bufname1);
 void text_move_bol(EditState *s);
 void text_move_eol(EditState *s);
-void do_load(EditState *s, const char *filename);
-void do_load_from_path(EditState *s, const char *filename);
 void do_goto_line(EditState *s, int line);
 void switch_to_buffer(EditState *s, EditBuffer *b);
 void do_up_down(EditState *s, int dir);
+void do_left_right(EditState *s, int dir);
 void display_mode_line(EditState *s);
 void text_mouse_goto(EditState *s, int x, int y);
 EditBuffer *new_yank_buffer(void);
-void basic_mode_line(EditState *s, char *buf, int buf_size, int c1);
-void text_mode_line(EditState *s, char *buf, int buf_size);
+int basic_mode_line(EditState *s, char *buf, int buf_size, int c1);
+int text_mode_line(EditState *s, char *buf, int buf_size);
 void do_toggle_full_screen(EditState *s);
 void do_toggle_control_h(EditState *s, int set);
 
+/* misc */
+
+CmdDef *qe_find_cmd(const char *cmd_name);
+void do_set_emulation(EditState *s, const char *name);
+void do_set_trace(EditState *s);
+void do_cd(EditState *s, const char *name);
+void do_global_set_key(EditState *s, const char *keystr, const char *cmd_name);
+void do_bof(EditState *s);
+void do_eof(EditState *s);
+void do_bol(EditState *s);
+void do_eol(EditState *s);
+void do_word_right(EditState *s, int dir);
+int isword(int c);
+int eb_next_paragraph(EditBuffer *b, int offset);
+int eb_start_paragraph(EditBuffer *b, int offset);
+void do_backward_paragraph(EditState *s);
+void do_forward_paragraph(EditState *s);
+void do_fill_paragraph(EditState *s);
+void do_changecase_word(EditState *s, int up);
+void do_changecase_region(EditState *s, int up);
+void do_delete_word(EditState *s, int dir);
+int cursor_func(DisplayState *ds,
+                int offset1, int offset2, int line_num,
+                int x, int y, int w, int h, int hex_mode);
+void do_scroll_up_down(EditState *s, int dir);
+void perform_scroll_up_down(EditState *s, int h);
+void center_cursor(EditState *s);
+void do_quote(EditState *s);
+void do_insert(EditState *s);
+void do_open_line(EditState *s);
+void do_set_mark(EditState *s);
+void do_mark_whole_buffer(EditState *s);
+void do_yank(EditState *s);
+void do_yank_pop(EditState *s);
+void do_exchange_point_and_mark(EditState *s);
+QECharset *read_charset(EditState *s, const char *charset_str);
+void do_set_buffer_file_coding_system(EditState *s, const char *charset_str);
+void do_convert_buffer_file_coding_system(EditState *s, 
+    const char *charset_str);
+void do_toggle_bidir(EditState *s);
+void do_toggle_line_numbers(EditState *s);
+void do_toggle_truncate_lines(EditState *s);
+void do_word_wrap(EditState *s);
+void do_goto_char(EditState *s, int pos);
+void do_count_lines(EditState *s);
+void do_what_cursor_position(EditState *s);
+void do_set_tab_width(EditState *s, int tab_width);
+void do_set_indent_width(EditState *s, int indent_width);
+void do_set_indent_tabs_mode(EditState *s, int mode);
+void display_window_borders(EditState *e);
+QEStyleDef *find_style(const char *name);
+void style_completion(StringArray *cs, const char *input);
+void do_define_color(EditState *e, const char *name, const char *value);
+void do_set_style(EditState *e, const char *stylestr, 
+                  const char *propstr, const char *value);
+void do_set_display_size(EditState *s, int w, int h);
+void do_toggle_mode_line(EditState *s);
+void do_set_system_font(EditState *s, const char *qe_font_name, 
+                        const char *system_fonts);
+void call_func(void *func, int nb_args, void **args, 
+               unsigned char *args_type);
+void exec_command(EditState *s, CmdDef *d, int argval);
+void do_execute_command(EditState *s, const char *cmd, int argval);
+void window_display(EditState *s);
+void do_universal_argument(EditState *s);
+void do_start_macro(EditState *s);
+void do_call_macro(EditState *s);
+void do_execute_macro_keys(EditState *s, const char *keys);
+void do_define_kbd_macro(EditState *s, const char *name, const char *keys,
+                         const char *key_bind);
+void edit_attach(EditState *s, EditState **ep);
+void do_completion(EditState *s);
+void do_completion_space(EditState *s);
+void minibuf_complete_scroll_up_down(EditState *s, int dir);
+void do_history(EditState *s, int dir);
+void do_minibuffer_get_binary(EditState *s);
+void do_minibuffer_exit(EditState *s, int abort);
+void do_less_quit(EditState *s);
+void do_toggle_read_only(EditState *s);
+void do_not_modified(EditState *s);
+void do_find_alternate_file(EditState *s, const char *filename);
+void do_load_file_from_path(EditState *s, const char *filename);
+void do_set_visited_file_name(EditState *s, const char *filename,
+                              const char *renamefile);
+int eb_search(EditBuffer *b, int offset, int dir, u8 *buf, int size, 
+              int flags, CSSAbortFunc *abort_func, void *abort_opaque);
+int search_abort_func(void *opaque);
+void do_doctor(EditState *s);
+void do_delete_other_windows(EditState *s);
+void do_describe_bindings(EditState *s);
+void do_describe_key_briefly(EditState *s);
+void do_help_for_help(EditState *s);
+void qe_event_init(void);
+void window_get_min_size(EditState *s, int *w_ptr, int *h_ptr);
+void window_resize(EditState *s, int target_w, int target_h);
+void wheel_scroll_up_down(EditState *s, int dir);
+void mouse_event(QEEvent *ev);
+int parse_config_file(EditState *s, const char *filename);
+int parse_command_line(int argc, char **argv);
+void set_user_option(const char *user);
+
 /* hex.c */
 void hex_write_char(EditState *s, int key);
 
@@ -1258,6 +1424,10 @@
 void fill_border(EditState *s, int x, int y, int w, int h, int color);
 int qe_bitmap_format_to_pix_fmt(int format);
 
+/* shell.c */
+EditBuffer *new_shell_buffer(const char *name, const char *path,
+                             const char **argv, int is_shell);
+
 #define QASSERT(e)      do { if (!(e)) fprintf(stderr, "%s:%d: assertion 
failed: %s\n", __FILE__, __LINE__, #e); } while (0)
 
 #endif

Index: qfribidi.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qfribidi.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4

Index: shell.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/shell.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- shell.c     11 Dec 2006 23:35:45 -0000      1.19
+++ shell.c     31 Dec 2006 19:34:01 -0000      1.20
@@ -82,7 +82,7 @@
 /* move to mode */
 static int shell_launched = 0;
 
-static int shell_mode_init(EditState *s, ModeSavedData *saved_data)
+static int shell_mode_init(EditState *s, __unused__ ModeSavedData *saved_data)
 {
     s->tab_size = 8;
     s->wrap = WRAP_TRUNCATE;
@@ -329,6 +329,10 @@
 
     if (len < 0)
         len = strlen(buf);
+
+    if (trace_buffer)
+        eb_trace_bytes(buf, len, EB_TRACE_PTY);
+
     while (len > 0) {
         ret = write(s->pty_fd, buf, len);
         if (ret == -1 && (errno == EAGAIN || errno == EINTR))
@@ -352,6 +356,10 @@
 
     /* compute offset */
     eb_get_pos(s->b, &total_lines, &col_num, s->b->total_size);
+    if (s->cur_offset == s->b->total_size
+    ||  eb_prevc(s->b, s->b->total_size, NULL) != '\n')
+        total_lines++;
+
     line_num = total_lines - TTY_YSIZE;
     if (line_num < 0)
         line_num = 0;
@@ -458,7 +466,7 @@
 
 
 /* Well, almost a hack to update cursor */
-static void tty_update_cursor(ShellState *s)
+static void tty_update_cursor(__unused__ ShellState *s)
 {
 #if 0
     QEmacsState *qs = s->qe_state;
@@ -485,7 +493,7 @@
         e->offset = s->cur_offset;
 }
 
-void shell_key(void *opaque, int key)
+static void shell_key(void *opaque, int key)
 {
     ShellState *s = opaque;
     char buf[10];
@@ -583,7 +591,6 @@
         switch (c) {
             /* BEL            Bell (Ctrl-G) */
             /* FF             Form Feed or New Page (NP) (Ctrl-L) same as LF */
-            /* TAB            Horizontal Tab (HT) (Ctrl-I) */
             /* VT             Vertical Tab (Ctrl-K) same as LF */
 
         case 8:         /* ^H  BS = backspace */
@@ -593,10 +600,17 @@
                 if (c1 != '\n') {
                     s->cur_offset = offset;
                     /* back_color_erase */
-                    tty_put_char(s, ' ');
+                    //tty_put_char(s, ' ');
                 }
             }
             break;
+        case 9:        /* ^I  HT = horizontal tab */
+            {
+                int col_num, cur_line;
+                eb_get_pos(s->b, &cur_line, &col_num, s->cur_offset);
+                tty_goto_xy(s, (col_num + 8) & ~7, 0, 2);
+                break;
+            }
         case 10:        /* ^J  NL = line feed */
             /* go to next line */
             /* CG: should check if column should be kept */
@@ -635,7 +649,7 @@
             s->shifted = 0;
             break;
         default:
-            if (c >= 32 || c == 9) {
+            if (c >= 32) {
                 int c1, cur_len, len;
                 /* CG: assuming ISO-8859-1 characters */
                 /* CG: horrible kludge for alternate charset support */
@@ -644,7 +658,6 @@
                 /* write char (should factorize with do_char() code */
                 len = unicode_to_charset(buf1, c, s->b->charset);
                 c1 = eb_nextc(s->b, s->cur_offset, &offset);
-                /* XXX: handle tab case */
                 /* Should simplify with tty_put_char */
                 if (c1 == '\n') {
                     /* insert */
@@ -877,7 +890,7 @@
 
 /* modify the color according to the current one (may be incorrect if
    we are editing because we should write default color) */
-static void shell_color_callback(EditBuffer *b,
+static void shell_color_callback(__unused__ EditBuffer *b,
                                  void *opaque,
                                  enum LogOperation op,
                                  int offset,
@@ -919,7 +932,7 @@
 
 static int shell_get_colorized_line(EditState *e,
                                     unsigned int *buf, int buf_size,
-                                    int offset, int line_num)
+                                    int offset, __unused__ int line_num)
 {
     EditBuffer *b = e->b;
     ShellState *s = b->priv_data;
@@ -974,7 +987,7 @@
     dpy_flush(qs->screen);
 }
 
-void shell_pid_cb(void *opaque, int status)
+static void shell_pid_cb(void *opaque, int status)
 {
     ShellState *s = opaque;
     EditBuffer *b = s->b;
@@ -1146,7 +1159,7 @@
     shell_launched = 1;
 }
 
-void shell_move_left_right(EditState *e, int dir)
+static void shell_move_left_right(EditState *e, int dir)
 {
     if (e->interactive) {
         ShellState *s = e->b->priv_data;
@@ -1156,7 +1169,7 @@
     }
 }
 
-void shell_move_word_left_right(EditState *e, int dir)
+static void shell_move_word_left_right(EditState *e, int dir)
 {
     if (e->interactive) {
         ShellState *s = e->b->priv_data;
@@ -1166,7 +1179,7 @@
     }
 }
 
-void shell_move_up_down(EditState *e, int dir)
+static void shell_move_up_down(EditState *e, int dir)
 {
     if (e->interactive) {
         ShellState *s = e->b->priv_data;
@@ -1176,7 +1189,7 @@
     }
 }
 
-void shell_scroll_up_down(EditState *e, int dir)
+static void shell_scroll_up_down(EditState *e, int dir)
 {
     ShellState *s = e->b->priv_data;
 
@@ -1185,7 +1198,7 @@
     e->interactive = (e->offset == s->cur_offset);
 }
 
-void shell_move_bol(EditState *e)
+static void shell_move_bol(EditState *e)
 {
     if (e->interactive) {
         ShellState *s = e->b->priv_data;
@@ -1195,7 +1208,7 @@
     }
 }
 
-void shell_move_eol(EditState *e)
+static void shell_move_eol(EditState *e)
 {
     if (e->interactive) {
         ShellState *s = e->b->priv_data;
@@ -1205,7 +1218,7 @@
     }
 }
 
-void shell_write_char(EditState *e, int c)
+static void shell_write_char(EditState *e, int c)
 {
     char ch;
 
@@ -1238,7 +1251,7 @@
     }
 }
 
-void do_shell_toggle_input(EditState *e)
+static void do_shell_toggle_input(EditState *e)
 {
     e->interactive = !e->interactive;
     if (e->interactive) {

Index: tty.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/tty.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- tty.c       12 Dec 2006 01:03:03 -0000      1.19
+++ tty.c       31 Dec 2006 19:34:01 -0000      1.20
@@ -38,6 +38,20 @@
 #define TTYCHAR_GETBG(cc)       (((cc) >> 24) & 0xFF)
 #define TTYCHAR_DEFAULT         TTYCHAR(' ', 0, 0)
 
+#if defined(__GNUC__)
+#  define PUTC(c,f)         putc_unlocked(c, f)
+#  define FWRITE(b,s,n,f)   fwrite_unlocked(b, s, n, f)
+#  define FPRINTF           fprintf
+static inline void FPUTS(const char *s, FILE *fp) {
+    FWRITE(s, 1, strlen(s), fp);
+}
+#else
+#  define PUTC(c,f)         putc(c, f)
+#  define FWRITE(b,s,n,f)   fwrite(b, s, n, f)
+#  define FPRINTF           fprintf
+#  define FPUTS             fputs
+#endif
+
 enum InputState {
     IS_NORM,
     IS_ESC,
@@ -46,6 +60,15 @@
     IS_ESC2,
 };
 
+enum TermCode {
+    TERM_UNKNOWN = 0,
+    TERM_ANSI,
+    TERM_VT100,
+    TERM_XTERM,
+    TERM_LINUX,
+    TERM_CYGWIN,
+};
+
 typedef struct TTYState {
     TTYChar *screen;
     int screen_size;
@@ -58,37 +81,72 @@
     int utf8_state;
     int utf8_index;
     unsigned char buf[10];
+    char *term_name;
+    enum TermCode term_code;
+    int term_flags;
+#define KBS_CONTROL_H  1
 } TTYState;
 
 static void tty_resize(int sig);
-static void term_exit(void);
+static void tty_term_exit(void);
 static void tty_read_handler(void *opaque);
 
 static struct TTYState tty_state;
 static QEditScreen *tty_screen;
 
-static int term_probe(void)
+static int tty_term_probe(void)
 {
     return 1;
 }
 
 static QEDisplay tty_dpy;
 
-static int term_init(QEditScreen *s, int w, int h)
+static int tty_term_init(QEditScreen *s,
+                         __unused__ int w, __unused__ int h)
 {
     TTYState *ts;
     struct termios tty;
     struct sigaction sig;
-    char *term;
 
     memcpy(&s->dpy, &tty_dpy, sizeof(QEDisplay));
 
+    s->STDIN = stdin;
+    s->STDOUT = stdout;
+
     tty_screen = s;
     ts = &tty_state;
     s->private = ts;
     s->media = CSS_MEDIA_TTY;
 
-    tcgetattr (0, &tty);
+    /* Derive some settings from the TERM environment variable */
+    tty_state.term_code = TERM_UNKNOWN;
+    tty_state.term_flags = 0;
+    tty_state.term_name = getenv("TERM");
+    if (tty_state.term_name) {
+        /* linux and xterm -> kbs=\177
+         * ansi cygwin vt100 -> kbs=^H
+         */
+        if (strstart(tty_state.term_name, "ansi", NULL)) {
+            tty_state.term_code = TERM_ANSI;
+            tty_state.term_flags = KBS_CONTROL_H;
+        } else
+        if (strstart(tty_state.term_name, "vt100", NULL)) {
+            tty_state.term_code = TERM_VT100;
+            tty_state.term_flags = KBS_CONTROL_H;
+        } else
+        if (strstart(tty_state.term_name, "xterm", NULL)) {
+            tty_state.term_code = TERM_XTERM;
+        } else
+        if (strstart(tty_state.term_name, "linux", NULL)) {
+            tty_state.term_code = TERM_LINUX;
+        } else
+        if (strstart(tty_state.term_name, "cygwin", NULL)) {
+            tty_state.term_code = TERM_CYGWIN;
+            tty_state.term_flags = KBS_CONTROL_H;
+        }
+    }
+
+    tcgetattr(fileno(s->STDIN), &tty);
     ts->oldtty = tty;
 
     tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
@@ -100,86 +158,98 @@
     tty.c_cc[VMIN] = 1;
     tty.c_cc[VTIME] = 0;
     
-    tcsetattr(0, TCSANOW, &tty);
+    tcsetattr(fileno(s->STDIN), TCSANOW, &tty);
 
     s->charset = &charset_vt100;
 
-#ifndef CONFIG_CYGWIN
-    /* CG: Should also have a command line switch */
     /* test UTF8 support by looking at the cursor position (idea from
        Ricardas Cepas <address@hidden>). Since uClibc actually tests
        to ensure that the format string is a valid multibyte sequence
        in the current locale (ANSI/ISO C99), use a format specifier of
        %s to avoid printf() failing with EILSEQ. */
-    {
-        int y, x;
+    /* CG: Should also have a command line switch */
+    if (tty_state.term_code != TERM_CYGWIN) {
+        int y, x, n;
         
         /*               ^X  ^Z    ^M   \170101  */
         //printf("%s", "\030\032" "\r\xEF\x81\x81" "\033[6n\033D");
         /* Just print utf-8 encoding for eacute and check cursor position */
-        printf("%s", "\030\032" "\r\xC3\xA9" "\033[6n\033D");
-        scanf("\033[%u;%u", &y, &x);  /* get cursor position */
-        printf("\r   \r");            /* go back, erase 3 chars */
-        if (x == 2) {
+        FPRINTF(s->STDOUT, "%s", "\030\032" "\r\xC3\xA9" "\033[6n\033D");
+        fflush(s->STDOUT);
+        n = fscanf(s->STDIN, "\033[%u;%u", &y, &x);  /* get cursor position */
+        FPRINTF(s->STDOUT, "\r   \r");            /* go back, erase 3 chars */
+        if (n == 2 && x == 2) {
             s->charset = &charset_utf8;
         }
     }
-#endif
+#if 0
     printf("\033[?1048h\033[?1047h"     /* enable cup */
            "\033)0\033(B"        /* select character sets in block 0 and 1 */
            "\017");             /* shift out */
-    
-    atexit(term_exit);
+#else
+    FPRINTF(s->STDOUT,
+            "\033[?1049h"       /* enter_ca_mode */
+            "\033[m\033(B"      /* exit_attribute_mode */
+            "\033[4l"          /* exit_insert_mode */
+            "\033[?7h"         /* enter_am_mode */
+            "\033[39;49m"       /* orig_pair */
+            "\033[?1h\033="     /* keypad_xmit */
+           );
+#endif
+    atexit(tty_term_exit);
 
     sig.sa_handler = tty_resize;
     sigemptyset(&sig.sa_mask);
     sig.sa_flags = 0;
     sigaction(SIGWINCH, &sig, NULL);
-    fcntl(0, F_SETFL, O_NONBLOCK);
+    fcntl(fileno(s->STDIN), F_SETFL, O_NONBLOCK);
     /* If stdout is to a pty, make sure we aren't in nonblocking mode.
      * Otherwise, the printf()s in term_flush() can fail with EAGAIN,
      * causing repaint errors when running in an xterm or in a screen
      * session. */
-    fcntl(1, F_SETFL, 0);
+    fcntl(fileno(s->STDOUT), F_SETFL, 0);
 
-    set_read_handler(0, tty_read_handler, s);
+    set_read_handler(fileno(s->STDIN), tty_read_handler, s);
 
     tty_resize(0);
 
-    /* Test TERM env var:
-     * linux and xterm -> kbs=\177
-     * ansi cygwin vt100 -> kbs=^H
-     */
-    term = getenv("TERM");
-    if (term) {
-        if (strstart(term, "ansi", NULL) ||
-            strstart(term, "cygwin", NULL) ||
-            strstart(term, "vt", NULL)) {
+    if (tty_state.term_flags & KBS_CONTROL_H) {
             do_toggle_control_h(NULL, 1);
         }
-    }
+
     return 0;
 }
 
-static void term_close(QEditScreen *s)
+static void tty_term_close(QEditScreen *s)
 {
-    fcntl(0, F_SETFL, 0);
+    fcntl(fileno(s->STDIN), F_SETFL, 0);
+#if 0
     /* go to the last line */
     printf("\033[%d;%dH\033[m\033[K"
            "\033[?1047l\033[?1048l",    /* disable cup */
            s->height, 1);
-    fflush(stdout);
+#else
+    /* go to last line and clear it */
+    FPRINTF(s->STDOUT, "\033[%d;%dH\033[m\033[K", s->height, 1);
+    FPRINTF(s->STDOUT,
+            "\033[?1049l"        /* exit_ca_mode */
+            "\r"                 /* return */
+            "\033[?1l\033>"      /* keypad_local */
+            "\r"                 /* return */
+           );
+#endif
+    fflush(s->STDOUT);
 }
 
-static void term_exit(void)
+static void tty_term_exit(void)
 {
     QEditScreen *s = tty_screen;
     TTYState *ts = s->private;
 
-    tcsetattr(0, TCSANOW, &ts->oldtty);
+    tcsetattr(fileno(s->STDIN), TCSANOW, &ts->oldtty);
 }
 
-static void tty_resize(int sig)
+static void tty_resize(__unused__ int sig)
 {
     QEditScreen *s = tty_screen;
     TTYState *ts = s->private;
@@ -189,7 +259,7 @@
 
     s->width = 80;
     s->height = 24;
-    if (ioctl(0, TIOCGWINSZ, &ws) == 0) {
+    if (ioctl(fileno(s->STDIN), TIOCGWINSZ, &ws) == 0) {
         s->width = ws.ws_col;
         s->height = ws.ws_row;
     }
@@ -217,19 +287,20 @@
     s->clip_y2 = s->height;
 }
 
-static void term_invalidate(void)
+static void tty_term_invalidate(void)
 {
     tty_resize(0);
 }
 
-static void term_cursor_at(QEditScreen *s, int x1, int y1, int w, int h)
+static void tty_term_cursor_at(QEditScreen *s, int x1, int y1,
+                               __unused__ int w, __unused__ int h)
 {
     TTYState *ts = s->private;
     ts->cursor_x = x1;
     ts->cursor_y = y1;
 }
 
-static int term_is_user_input_pending(QEditScreen *s)
+static int tty_term_is_user_input_pending(QEditScreen *s)
 {
     fd_set rfds;
     struct timeval tv;
@@ -237,8 +308,8 @@
     tv.tv_sec = 0;
     tv.tv_usec = 0;
     FD_ZERO(&rfds);
-    FD_SET(0, &rfds);
-    if (select(1, &rfds, NULL, NULL, &tv) > 0)
+    FD_SET(fileno(s->STDIN), &rfds);
+    if (select(fileno(s->STDIN) + 1, &rfds, NULL, NULL, &tv) > 0)
         return 1;
     else
         return 0;
@@ -290,7 +361,7 @@
     int ch;
     QEEvent ev1, *ev = &ev1;
 
-    if (read(0, ts->buf + ts->utf8_index, 1) != 1)
+    if (read(fileno(s->STDIN), ts->buf + ts->utf8_index, 1) != 1)
         return;
 
     if (trace_buffer &&
@@ -348,7 +419,7 @@
             ts->input_state = IS_CSI2;
             break;
         case '~':
-            if (ts->input_param < sizeof(csi_lookup)/sizeof(csi_lookup[0])) {
+            if (ts->input_param < 
(int)(sizeof(csi_lookup)/sizeof(csi_lookup[0]))) {
                 ch = csi_lookup[ts->input_param];
                 goto the_end;
             }
@@ -454,7 +525,7 @@
     return cmin;
 }
 
-static void term_fill_rectangle(QEditScreen *s,
+static void tty_term_fill_rectangle(QEditScreen *s,
                                 int x1, int y1, int w, int h, QEColor color)
 {
     TTYState *ts = s->private;
@@ -489,20 +560,22 @@
 }
 
 /* XXX: could alloc font in wrapper */
-static QEFont *term_open_font(QEditScreen *s,
-                              int style, int size)
+static QEFont *tty_term_open_font(__unused__ QEditScreen *s,
+                                  __unused__ int style, __unused__ int size)
 {
     QEFont *font;
+
     font = malloc(sizeof(QEFont));
     if (!font)
         return NULL;
+
     font->ascent = 0;
     font->descent = 1;
     font->private = NULL;
     return font;
 }
 
-static void term_close_font(QEditScreen *s, QEFont *font)
+static void tty_term_close_font(__unused__ QEditScreen *s, QEFont *font)
 {
     free(font);
 }
@@ -513,7 +586,7 @@
  * chars.  
  */
 
-static int term_glyph_width(QEditScreen *s, unsigned int ucs)
+static int tty_term_glyph_width(__unused__ QEditScreen *s, unsigned int ucs)
 {
   /* fast test for majority of non-wide scripts */
   if (ucs < 0x900)
@@ -531,20 +604,21 @@
      );
 }
 
-static void term_text_metrics(QEditScreen *s, QEFont *font, 
+static void tty_term_text_metrics(QEditScreen *s, __unused__ QEFont *font, 
                               QECharMetrics *metrics,
                               const unsigned int *str, int len)
 {
     int i, x;
+
     metrics->font_ascent = font->ascent;
     metrics->font_descent = font->descent;
     x = 0;
     for (i = 0; i < len; i++)
-        x += term_glyph_width(s, str[i]);
+        x += tty_term_glyph_width(s, str[i]);
     metrics->width = x;
 }
         
-static void term_draw_text(QEditScreen *s, QEFont *font, 
+static void tty_term_draw_text(QEditScreen *s, __unused__ QEFont *font, 
                            int x, int y, const unsigned int *str, int len,
                            QEColor color)
 {
@@ -568,7 +642,7 @@
         while (len > 0) {
             cc = *str++;
             len--;
-            w = term_glyph_width(s, cc);
+            w = tty_term_glyph_width(s, cc);
             x += w;
             if (x >= s->clip_x1) {
                 /* now we are on the screen. need to put spaces for
@@ -589,7 +663,7 @@
     }
     for (; len > 0; len--) {
         cc = *str++;
-        w = term_glyph_width(s, cc);
+        w = tty_term_glyph_width(s, cc);
         /* XXX: would need to put spacs for wide chars */
         if (x + w > s->clip_x2) 
             break;
@@ -605,20 +679,22 @@
     }
 }
 
-static void term_set_clip(QEditScreen *s,
-                          int x, int y, int w, int h)
+static void tty_term_set_clip(__unused__ QEditScreen *s,
+                              __unused__ int x, __unused__ int y,
+                              __unused__ int w, __unused__ int h)
 {
 }
 
-static void term_flush(QEditScreen *s)
+static void tty_term_flush(QEditScreen *s)
 {
     TTYState *ts = s->private;
     TTYChar *ptr, *ptr1, *ptr2, cc;
-    int y, shadow, ch, bgcolor, fgcolor;
+    int y, shadow, ch, bgcolor, fgcolor, shifted, nc;
     char buf[10];
     
     bgcolor = -1;
     fgcolor = -1;
+    shifted = 0;
             
     /* CG: Should optimize output by computing it in a temporary buffer
      * and flushing it in one call to fwrite()
@@ -651,7 +727,7 @@
             if (ptr1 == ptr2)
                 continue;
 
-            printf("\033[%d;%dH", y + 1, ptr1 - ptr + 1);
+            FPRINTF(s->STDOUT, "\033[%d;%dH", y + 1, ptr1 - ptr + 1);
 
             /* CG: should scan for sequences of blanks */
             while (ptr1 < ptr2) {
@@ -661,62 +737,93 @@
                 ch = TTYCHAR_GETCH(cc);
                 if (ch != 0xffff) {
                     /* output attributes */
-                    if ((fgcolor != TTYCHAR_GETFG(cc) && ch != ' ')
-                    ||  (bgcolor != TTYCHAR_GETBG(cc))) {
+                    if ((fgcolor != (int)TTYCHAR_GETFG(cc) && ch != ' ')
+                    ||  (bgcolor != (int)TTYCHAR_GETBG(cc))) {
                         fgcolor = TTYCHAR_GETFG(cc);
                         bgcolor = TTYCHAR_GETBG(cc);
                         /* CG: should deal with bold for high intensity
                          * foreground colors
                          */
-                        printf("\033[%d;%dm", 30 + fgcolor, 40 + bgcolor);
+                        FPRINTF(s->STDOUT, "\033[%d;%dm",
+                                30 + fgcolor, 40 + bgcolor);
                     }
                     /* do not display escape codes or invalid codes */
                     if (ch < 32 || ch == 127) {
-                        putchar('.');
+                        if (shifted) {
+                            FPUTS("\033(B", s->STDOUT);
+                            shifted = 0;
+                        }
+                        PUTC('.', s->STDOUT);
                     } else
                     if (ch < 127) {
-                        putchar(ch);
+                        if (shifted) {
+                            FPUTS("\033(B", s->STDOUT);
+                            shifted = 0;
+                        }
+                        PUTC(ch, s->STDOUT);
                     } else
-                    if (cc < 128 + 32) {
+                    if (ch < 128 + 32) {
                         /* Kludge for linedrawing chars */
-                        putchar('\016');
-                        putchar(cc - 32);
-                        putchar('\017');
+                        if (!shifted) {
+                            FPUTS("\033(0", s->STDOUT);
+                            shifted = 1;
+                        }
+                        PUTC(ch - 32, s->STDOUT);
                     } else {
                         // was in qemacs-0.3.1.g2.gw/tty.c:
                         // if (cc == 0x2500)
                         //    printf("\016x\017");
                         /* s->charset is either vt100 or utf-8 */
-                        unicode_to_charset(buf, cc, s->charset);
-                        fputs(buf, stdout);
+                        if (shifted) {
+                            FPUTS("\033(B", s->STDOUT);
+                            shifted = 0;
+                        }
+                        nc = unicode_to_charset(buf, cc, s->charset);
+                        if (nc == 1) {
+                            PUTC(*(u8 *)buf, s->STDOUT);
+                        } else
+                        {
+                            FWRITE(buf, 1, nc, s->STDOUT);
+                        }
+                    }
                     }
                 }
+            if (shifted) {
+                FPUTS("\033(B", s->STDOUT);
+                shifted = 0;
             }
         }
     }
 
-    printf("\033[%d;%dH", ts->cursor_y + 1, ts->cursor_x + 1);
-    fflush(stdout);
+    FPRINTF(s->STDOUT, "\033[%d;%dH", ts->cursor_y + 1, ts->cursor_x + 1);
+    fflush(s->STDOUT);
 }
 
 
 static QEDisplay tty_dpy = {
     "vt100",
-    term_probe,
-    term_init,
-    term_close,
-    term_cursor_at,
-    term_flush,
-    term_is_user_input_pending,
-    term_fill_rectangle,
-    term_open_font,
-    term_close_font,
-    term_text_metrics,
-    term_draw_text,
-    term_set_clip,
-    NULL, /* no selection handling */
-    NULL, /* no selection handling */
-    term_invalidate,
+    tty_term_probe,
+    tty_term_init,
+    tty_term_close,
+    tty_term_cursor_at,
+    tty_term_flush,
+    tty_term_is_user_input_pending,
+    tty_term_fill_rectangle,
+    tty_term_open_font,
+    tty_term_close_font,
+    tty_term_text_metrics,
+    tty_term_draw_text,
+    tty_term_set_clip,
+    NULL, /* dpy_selection_activate */
+    NULL, /* dpy_selection_request */
+    tty_term_invalidate,
+    NULL, /* dpy_bmp_alloc */
+    NULL, /* dpy_bmp_free */
+    NULL, /* dpy_bmp_draw */
+    NULL, /* dpy_bmp_lock */
+    NULL, /* dpy_bmp_unlock */
+    NULL, /* dpy_full_screen */
+    NULL, /* next */
 };
 
 static int tty_init(void)

Index: unihex.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/unihex.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- unihex.c    9 Dec 2006 17:45:53 -0000       1.3
+++ unihex.c    31 Dec 2006 19:34:01 -0000      1.4
@@ -110,7 +110,7 @@
 }
 
 
-void unihex_move_bol(EditState *s)
+static void unihex_move_bol(EditState *s)
 {
     int pos;
 
@@ -119,7 +119,7 @@
     s->offset = eb_goto_char(s->b, pos);
 }
 
-void unihex_move_eol(EditState *s)
+static void unihex_move_eol(EditState *s)
 {
     int pos;
 
@@ -130,7 +130,7 @@
     s->offset = eb_goto_char(s->b, pos);
 }
 
-void unihex_move_left_right(EditState *s, int dir)
+static void unihex_move_left_right(EditState *s, int dir)
 {
     if (dir > 0) {
         eb_nextc(s->b, s->offset, &s->offset);
@@ -139,7 +139,7 @@
     }
 }
 
-void unihex_move_up_down(EditState *s, int dir)
+static void unihex_move_up_down(EditState *s, int dir)
 {
     int pos;
 

Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- util.c      11 Dec 2006 23:04:21 -0000      1.15
+++ util.c      31 Dec 2006 19:34:01 -0000      1.16
@@ -16,6 +16,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
 #include "qe.h"
 #include <dirent.h>
 
@@ -58,7 +59,6 @@
     return s;
 }
                      
-
 int find_file_next(FindFileState *s, char *filename, int filename_size_max)
 {
     struct dirent *dirent;
@@ -440,7 +440,7 @@
     return -1;
 }
 
-unsigned short keycodes[] = {
+static unsigned short const keycodes[] = {
     KEY_SPC, KEY_DEL, KEY_RET, KEY_ESC, KEY_TAB, KEY_SHIFT_TAB,
     KEY_CTRL(' '), KEY_DEL, KEY_CTRL('\\'),
     KEY_CTRL(']'), KEY_CTRL('^'), KEY_CTRL('_'),
@@ -456,7 +456,7 @@
     KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20,
 };
 
-const char *keystr[] = {
+static const char * const keystr[] = {
     "SPC", "DEL", "RET", "ESC", "TAB", "S-TAB",
     "C-SPC", "C-?", "C-\\", "C-]", "C-^", "C-_",
     "left", "right", "up", "down",
@@ -503,7 +503,7 @@
     for (p1 = p; *p1 && *p1 != ' '; p1++)
         continue;
 
-    for (i = 0; i < sizeof(keycodes)/sizeof(keycodes[0]); i++) {
+    for (i = 0; i < (int)(sizeof(keycodes)/sizeof(keycodes[0])); i++) {
         if (strstart(p, keystr[i], &q) && q == p1) {
             key = keycodes[i];
             *pp = p1;
@@ -552,12 +552,12 @@
     return key;
 }
 
-int strtokeys(const char *keystr, unsigned int *keys, int max_keys)
+int strtokeys(const char *kstr, unsigned int *keys, int max_keys)
 {
     int key, nb_keys;
     const char *p;
 
-    p = keystr;
+    p = kstr;
     nb_keys = 0;
 
     for (;;) {
@@ -577,28 +577,27 @@
 {
     int i;
     char buf1[32];
+    buf_t out;
+    
+    buf_init(&out, buf, buf_size);
     
     for (i = 0; i < (int)(sizeof(keycodes)/sizeof(keycodes[0])); i++) {
         if (keycodes[i] == key) {
-            pstrcpy(buf, buf_size, keystr[i]);
+            buf_puts(&out, keystr[i]);
             return;
         }
     }
     if (key >= KEY_META(0) && key <= KEY_META(0xff)) {
         keytostr(buf1, sizeof(buf1), key & 0xff);
-        snprintf(buf, buf_size, "M-%s", buf1);
-    } else if (key >= KEY_CTRL('a') && key <= KEY_CTRL('z')) {
-        snprintf(buf, buf_size, "C-%c", key + 'a' - 1);
-    } else if (key >= KEY_F1 && key <= KEY_F20) {
-        snprintf(buf, buf_size, "f%d", key - KEY_F1 + 1);
-    } else if (key > 32 && key < 127 && buf_size >= 2) {
-        buf[0] = key;
-        buf[1] = '\0';
+        buf_printf(&out, "M-%s", buf1);
+    } else
+    if (key >= KEY_CTRL('a') && key <= KEY_CTRL('z')) {
+        buf_printf(&out, "C-%c", key + 'a' - 1);
+    } else
+    if (key >= KEY_F1 && key <= KEY_F20) {
+        buf_printf(&out, "f%d", key - KEY_F1 + 1);
     } else {
-        char *q;
-        q = utf8_encode(buf1, key);
-        *q = '\0';
-        pstrcpy(buf, buf_size, buf1);
+        buf_putc_utf8(&out, key);
     }
 }
 
@@ -646,7 +645,7 @@
     { "magenta", QERGB(0xff, 0x00, 0xff) },
     { "transparent", COLOR_TRANSPARENT },
 };
-#define nb_css_colors (sizeof(css_colors) / sizeof(css_colors[0]))
+#define nb_css_colors (int)(sizeof(css_colors) / sizeof(css_colors[0]))
 
 static ColorDef *custom_colors = css_colors;
 static int nb_custom_colors;
@@ -824,6 +823,25 @@
     }
 }
 
+void css_strtolower(char *buf, __unused__ int buf_size)
+{
+    int c;
+    /* XXX: handle unicode */
+    while (*buf) {
+        c = tolower(*buf);
+        *buf++ = c;
+    }
+}
+
+void set_color(unsigned int *buf, int len, int style)
+{
+    int i;
+
+    style <<= STYLE_SHIFT;
+    for (i = 0; i < len; i++)
+        buf[i] |= style;
+}
+
 #ifdef __TINYC__
 
 /* the glibc folks use wrappers, but forgot to put a compatibility
@@ -894,52 +912,6 @@
     memset(cs, 0, sizeof(StringArray));
 }
 
-void set_color(unsigned int *buf, int len, int style)
-{
-    int i;
-
-    style <<= STYLE_SHIFT;
-    for (i = 0; i < len; i++)
-        buf[i] |= style;
-}
-
-void css_strtolower(char *buf, int buf_size)
-{
-    int c;
-    /* XXX: handle unicode */
-    while (*buf) {
-        c = tolower(*buf);
-        *buf++ = c;
-    }
-}
-
-void umemmove(unsigned int *dest, unsigned int *src, int len)
-{
-    memmove(dest, src, len * sizeof(unsigned int));
-}
-
-/* copy the n first char of a string and truncate it. */
-char *pstrncpy(char *buf, int buf_size, const char *s, int len)
-{
-    char *q;
-    int c;
-
-    if (buf_size > 0) {
-        q = buf;
-        if (len >= buf_size)
-            len = buf_size - 1;
-        while (len > 0) {
-            c = *s++;
-            if (c == '\0')
-                break;
-            *q++ = c;
-            len--;
-        }
-        *q = '\0';
-    }
-    return buf;
-}
-
 /**
  * Add a memory region to a dynamic string. In case of allocation
  * failure, the data is not added. The dynamic string is guaranteed to
@@ -1002,3 +974,85 @@
     return ret;
 }
 
+int buf_write(buf_t *bp, const void *src, int size)
+{
+    int n = buf_avail(bp);
+
+    if (n > size)
+        n = size;
+    memcpy(bp->buf + bp->len, src, n);
+    bp->pos += size;
+    bp->len += n;
+    if (bp->len < bp->size)
+        bp->buf[bp->len] = '\0';
+    return n;
+}
+
+int buf_printf(buf_t *bp, const char *fmt, ...)
+{
+    va_list ap;
+    int len;
+
+    va_start(ap, fmt);
+    len = vsnprintf(bp->buf + bp->len,
+                    (bp->pos < bp->size) ? bp->size - bp->pos : 1, fmt, ap);
+    va_end(ap);
+
+    bp->pos += len;
+    bp->len += len;
+    if (bp->len >= bp->size) {
+        bp->len = bp->size - 1;
+        if (bp->len < 0)
+            bp->len = 0;
+    }
+
+    return len;
+}
+
+int buf_putc_utf8(buf_t *bp, int c)
+{
+    if (c < 0x80) {
+        bp->pos++;
+        if (bp->pos < bp->size) {
+            bp->buf[bp->len++] = c;
+            bp->buf[bp->len] = '\0';
+            return 1;
+        } else {
+            return 0;
+        }
+    } else {
+        char buf[6];
+        int len;
+
+        len = utf8_encode(buf, c);
+
+        if (buf_avail(bp) >= len) {
+            memcpy(bp->buf + bp->len, buf, len);
+            bp->buf[bp->len] = '\0';
+            bp->pos += len;
+            bp->len += len;
+            return len;
+        }
+        bp->pos += len;
+        return 0;
+    }
+}
+
+int strsubst(char *buf, int buf_size, const char *from,
+             const char *s1, const char *s2)
+{
+    const char *p, *q;
+    buf_t out;
+
+    buf_init(&out, buf, buf_size);
+
+    p = from;
+    while ((q = strstr(p, s1)) != NULL) {
+        buf_write(&out, p, q - p);
+        buf_puts(&out, s2);
+        p = q + strlen(s1);
+    }
+    buf_puts(&out, p);
+
+    return out.pos;
+}

Index: video.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/video.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- video.c     9 Dec 2006 19:02:07 -0000       1.5
+++ video.c     31 Dec 2006 19:34:01 -0000      1.6
@@ -862,22 +862,21 @@
     return buf;
 }
 
-static void video_mode_line(EditState *s, char *buf, int buf_size)
+static int video_mode_line(EditState *s, char *buf, int buf_size)
 {
-    char *q;
+    int pos;
     const char *name;
     VideoState *is = s->mode_data;
     AVCodec *codec;
     AVCodecContext *dec;
     char buf1[32];
 
-    basic_mode_line(s, buf, buf_size, '-');
-    q = buf + strlen(buf);
+    pos = basic_mode_line(s, buf, buf_size, '-');
     if (is->paused) {
-        q += sprintf(q, "[paused]--");
+        pos += snprintf(buf + pos, buf_size - pos, "[paused]--");
     }
     if (is->ic) {
-        q += sprintf(q, "%s", 
+        pos += snprintf(buf + pos, buf_size - pos, "%s", 
                      is->ic->iformat->name);
     }
     if (is->video_st) {
@@ -886,7 +885,7 @@
         codec = dec->codec;
         if (codec)
             name = codec->name;
-        q += sprintf(q, "--%s/address@hidden", 
+        pos += snprintf(buf + pos, buf_size - pos, "--%s/address@hidden", 
                      name, get_stream_id(is->ic, is->video_st, buf1, 
sizeof(buf1)),
                      dec->width, dec->height, 
                      (float)dec->frame_rate / dec->frame_rate_base);
@@ -897,10 +896,11 @@
         codec = dec->codec;
         if (codec)
             name = codec->name;
-        q += sprintf(q, "--%s/%s[%dHz:%dch]", 
+        pos += snprintf(buf + pos, buf_size - pos, "--%s/%s[%dHz:%dch]", 
                      name, get_stream_id(is->ic, is->audio_st, buf1, 
sizeof(buf1)),
                      dec->sample_rate, dec->channels);
     }
+    return pos;
 }
 
 static void av_cycle_stream(EditState *s, int codec_type)

Index: win32.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/win32.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- win32.c     11 May 2005 15:12:14 -0000      1.3
+++ win32.c     31 Dec 2006 19:34:01 -0000      1.4
@@ -492,8 +492,16 @@
     win_text_metrics,
     win_draw_text,
     win_set_clip,
-    NULL, /* no selection handling */
-    NULL, /* no selection handling */
+    NULL, /* dpy_selection_activate */
+    NULL, /* dpy_selection_request */
+    NULL, /* dpy_invalidate */
+    NULL, /* dpy_bmp_alloc */
+    NULL, /* dpy_bmp_free */
+    NULL, /* dpy_bmp_draw */
+    NULL, /* dpy_bmp_lock */
+    NULL, /* dpy_bmp_unlock */
+    NULL, /* dpy_full_screen */
+    NULL, /* next */
 };
 
 int win32_init(void)

Index: x11.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/x11.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- x11.c       9 Dec 2006 17:45:26 -0000       1.8
+++ x11.c       31 Dec 2006 19:34:01 -0000      1.9
@@ -47,6 +47,7 @@
 static void xv_init(QEditScreen *s);
 static void x11_handle_event(void *opaque);
 
+//static struct X11State {
 static Display *display;
 static int xscreen;
 static Window window;
@@ -63,8 +64,8 @@
 static XftDraw          *renderDraw;
 #endif
 #ifdef CONFIG_XV
-static unsigned int xv_nb_adaptors, xv_port, xv_format, xv_open_count;
-static int xv_nb_formats;
+static unsigned int xv_nb_adaptors;
+static int xv_nb_formats, xv_port, xv_format, xv_open_count;
 static XvAdaptorInfo *xv_ai;
 static XvImageFormatValues *xv_fo;
 #endif
@@ -80,9 +81,12 @@
 static QEDisplay x11_dpy;
 static int visual_depth;
 
-static int force_tty = 0;
-static const char *display_str = "";
-static const char *geometry_str = "80x50";
+static int force_tty;
+static const char *display_str;
+static const char *geometry_str;
+
+static int font_ptsize;
+//} x11_state;
 
 const char *default_x11_fonts[NB_FONT_FAMILIES] = {
 #ifdef CONFIG_XFT
@@ -94,8 +98,6 @@
     "helvetica,unifont",
 };
     
-static int font_ptsize = 0;
-
 #ifdef CONFIG_DOUBLE_BUFFER
 static void update_reset(void)
 {
@@ -157,7 +159,8 @@
 }
 
 #else
-static inline void update_rect(int x1, int y1, int x2, int y2)
+static inline void update_rect(__unused__ int x1, __unused__ int y1,
+                               __unused__ int x2, __unused__ int y2)
 {
 }
 #endif
@@ -194,6 +197,9 @@
     s->private = NULL;
     s->media = CSS_MEDIA_SCREEN;
 
+    if (!display_str)
+        display_str = "";
+
     display = XOpenDisplay(display_str);
     if (display == NULL) {
         fprintf(stderr, "Could not open X11 display - exiting.\n");
@@ -220,20 +226,26 @@
     font_xsize = glyph_width(s, font, 'x');
     term_close_font(s, font);
     
+    if (w > 0 && h > 0) {
+        xsize = w;
+        ysize = h;
+    } else {
+        xsize = 80;
+        ysize = 50;
+
+        if (geometry_str) {
     p = geometry_str;
     xsize = strtol(p, (char **)&p, 0);
     if (*p == 'x')
         p++;
     ysize = strtol(p, (char **)&p, 0);
-    if (w > 0 && h > 0) {
-        xsize = w;
-        ysize = h;
-    }
 
     if (xsize <= 0 || ysize <=0) {
         fprintf(stderr, "Invalid geometry '%s'\n", geometry_str);
         exit(1);
     }
+        }
+    }
 
     xsize *= font_xsize;
     ysize *= font_ysize;
@@ -328,18 +340,14 @@
 #endif
 
     /* shm extension usable ? */
-    {
-        const char *p;
-        int is_local;
-        
         p = XDisplayName(display_str);
         strstart(p, "unix:", &p);
         strstart(p, "localhost:", &p);
-        is_local = (*p == ':');
         shm_use = 0;
-        if (is_local && XShmQueryExtension(display))
+    /* Check if display is local and XShm available */
+    if ((*p == ':') && XShmQueryExtension(display))
             shm_use = 1;
-    }
+
     /* compute bitmap format */
     switch (visual_depth) {
     case 15:
@@ -378,11 +386,11 @@
                         &xv_nb_adaptors, &xv_ai) != Success)
         return;
 
-    for (i = 0; i < xv_nb_adaptors; i++) {
+    for (i = 0; i < (int)xv_nb_adaptors; i++) {
         if ((xv_ai[i].type & XvInputMask) && 
             (xv_ai[i].type & XvImageMask)) {
             for (xv_p = xv_ai[i].base_id; 
-                 xv_p < xv_ai[i].base_id + xv_ai[i].num_ports; 
+                 xv_p < (XvPortID)(xv_ai[i].base_id + xv_ai[i].num_ports); 
                  xv_p++) {
                 if (!XvGrabPort(display, xv_p, CurrentTime)) {
                     xv_port = xv_p;
@@ -422,7 +430,7 @@
 }
 #endif
 
-static void term_close(QEditScreen *s)
+static void term_close(__unused__ QEditScreen *s)
 {
 #ifdef CONFIG_DOUBLE_BUFFER
     XFreePixmap(display, dbuffer);
@@ -468,7 +476,7 @@
     }
 }
 
-static void xor_rectangle(QEditScreen *s, 
+static void xor_rectangle(__unused__ QEditScreen *s, 
                           int x, int y, int w, int h)
 {
     int fg;
@@ -648,7 +656,7 @@
 }
 
 
-static QEFont *term_open_font(QEditScreen *s, int style, int size)
+static QEFont *term_open_font(__unused__ QEditScreen *s, int style, int size)
 {
     char family[128];
     const char *family_list, *p1;
@@ -766,7 +774,7 @@
     return NULL;
 }
 
-static void term_close_font(QEditScreen *s, QEFont *font)
+static void term_close_font(__unused__ QEditScreen *s, QEFont *font)
 {
     XFontStruct *xfont = font->private;
 
@@ -790,7 +798,7 @@
         return NULL;
 
     if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0) {
-        if (cc > xfont->max_char_or_byte2)
+        if (cc > (int)xfont->max_char_or_byte2)
             return NULL;
         cc -= xfont->min_char_or_byte2;
         if (cc < 0)
@@ -798,12 +806,12 @@
     } else {
         b1 = (cc >> 8) & 0xff;
         b2 = cc & 0xff;
-        if (b1 > xfont->max_byte1)
+        if (b1 > (int)xfont->max_byte1)
             return NULL;
         b1 -= xfont->min_byte1;
         if (b1 < 0)
             return NULL;
-        if (b2 > xfont->max_char_or_byte2)
+        if (b2 > (int)xfont->max_char_or_byte2)
             return NULL;
         b2 -= xfont->min_char_or_byte2;
         if (b2 < 0)
@@ -972,7 +980,7 @@
 }
 #endif
 
-static void term_set_clip(QEditScreen *s,
+static void term_set_clip(__unused__ QEditScreen *s,
                           int x, int y, int w, int h)
 {
     XRectangle rect;
@@ -984,7 +992,7 @@
     XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXSorted);
 }
 
-static void term_flush(QEditScreen *s)
+static void term_flush(__unused__ QEditScreen *s)
 {
 #ifdef CONFIG_DOUBLE_BUFFER
     CSSRect *r;
@@ -1020,24 +1028,24 @@
 #endif
 }
 
-static void x11_full_screen(QEditScreen *s, int full_screen)
+static void x11_full_screen(__unused__ QEditScreen *s, int full_screen)
 {
-    XWindowAttributes attr;
+    XWindowAttributes attr1;
     Window win;
 
-    XGetWindowAttributes(display, window, &attr);
+    XGetWindowAttributes(display, window, &attr1);
     if (full_screen) {
-        if ((attr.width != screen_width || attr.height != screen_height)) {
+        if ((attr1.width != screen_width || attr1.height != screen_height)) {
             /* store current window position and size */
-            XTranslateCoordinates(display, window, attr.root, 0, 0,
+            XTranslateCoordinates(display, window, attr1.root, 0, 0,
                                   &last_window_x, &last_window_y, &win);
-            last_window_width = attr.width;
-            last_window_height = attr.height;
+            last_window_width = attr1.width;
+            last_window_height = attr1.height;
             XMoveResizeWindow(display, window, 
                               0, 0, screen_width, screen_height);
         }
     } else if (!full_screen) {
-        if (attr.width == screen_width && attr.height == screen_height) {
+        if (attr1.width == screen_width && attr1.height == screen_height) {
             XMoveResizeWindow(display, window, 
                               last_window_x, last_window_y, 
                               last_window_width, last_window_height);
@@ -1045,20 +1053,21 @@
     }
 }
 
-static void term_selection_activate(QEditScreen *s)
+static void term_selection_activate(__unused__ QEditScreen *s)
 {
     /* own selection from now */
     XSetSelectionOwner(display, XA_PRIMARY, window, CurrentTime);
 }
 
-static Bool test_event(Display *dpy, XEvent *ev, char *arg)
+static Bool test_event(__unused__ Display *dpy, XEvent *ev,
+                       __unused__ char *arg)
 {
     return (ev->type == SelectionNotify);
 }
 
 /* request the selection from the GUI and put it in a new yank buffer
    if needed */
-static void term_selection_request(QEditScreen *s)
+static void term_selection_request(__unused__ QEditScreen *s)
 {
     Window w;
     Atom prop;
@@ -1164,7 +1173,7 @@
 }
 
 /* fast test to see if the user pressed a key or a mouse button */
-static int x11_is_user_input_pending(QEditScreen *s)
+static int x11_is_user_input_pending(__unused__ QEditScreen *s)
 {
     XEvent xev;
 
@@ -1527,7 +1536,7 @@
     return -1;
 }
 
-static void x11_bmp_free(QEditScreen *s, QEBitmap *b)
+static void x11_bmp_free(__unused__ QEditScreen *s, QEBitmap *b)
 {
     X11Bitmap *xb = b->priv_data;
 
@@ -1563,9 +1572,10 @@
     free(xb);
 }
 
-static void x11_bmp_draw(QEditScreen *s, QEBitmap *b, 
+static void x11_bmp_draw(__unused__ QEditScreen *s, QEBitmap *b, 
                          int dst_x, int dst_y, int dst_w, int dst_h, 
-                         int offset_x, int offset_y, int flags)
+                         __unused__ int offset_x, __unused__ int offset_y,
+                         __unused__ int flags)
 {
     X11Bitmap *xb = b->priv_data;
 
@@ -1603,7 +1613,7 @@
     }
 }
 
-static void x11_bmp_lock(QEditScreen *s, QEBitmap *b, QEPicture *pict,
+static void x11_bmp_lock(__unused__ QEditScreen *s, QEBitmap *b, QEPicture 
*pict,
                          int x1, int y1, int w1, int h1)
 {
     X11Bitmap *xb = b->priv_data;
@@ -1660,7 +1670,7 @@
     }
 }
 
-static void x11_bmp_unlock(QEditScreen *s, QEBitmap *b)
+static void x11_bmp_unlock(__unused__ QEditScreen *s, QEBitmap *b)
 {
     X11Bitmap *xb = b->priv_data;
     int ret;
@@ -1694,13 +1704,14 @@
     term_set_clip,
     term_selection_activate,
     term_selection_request,
-    NULL,
+    NULL, /* dpy_invalidate */
     x11_bmp_alloc,
     x11_bmp_free,
     x11_bmp_draw,
     x11_bmp_lock,
     x11_bmp_unlock,
     x11_full_screen,
+    NULL, /* next */
 };
 
 static CmdOptionDef cmd_options[] = {
@@ -1712,10 +1723,10 @@
       {string_ptr: &geometry_str} },
     { "font-size", "fs", "ptsize", CMD_OPT_INT | CMD_OPT_ARG, "set default 
font size", 
       {int_ptr: &font_ptsize} },
-    { NULL },
+    { NULL, NULL, NULL, 0, NULL, { NULL }},
 };
 
-int x11_init(void)
+static int x11_init(void)
 {
     qe_register_cmd_line_options(cmd_options);
     return qe_register_display(&x11_dpy);

Index: xml.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/xml.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- xml.c       8 Jul 2005 09:30:44 -0000       1.3
+++ xml.c       31 Dec 2006 19:34:01 -0000      1.4
@@ -28,7 +28,7 @@
     XML_SCRIPT = 0x10, /* special mode for inside a script, ored with c mode */
 };
 
-void xml_colorize_line(unsigned int *buf, int len, 
+static void xml_colorize_line(unsigned int *buf, __unused__ int len, 
                        int *colorize_state_ptr, int state_only)
 {
     int c, state;
@@ -174,7 +174,7 @@
     return 90; /* leave some room for more specific XML parser */
 }
 
-int xml_mode_init(EditState *s, ModeSavedData *saved_data)
+static int xml_mode_init(EditState *s, ModeSavedData *saved_data)
 {
     int ret;
     ret = text_mode_init(s, saved_data);
@@ -186,7 +186,7 @@
 
 static ModeDef xml_mode;
 
-int xml_init(void)
+static int xml_init(void)
 {
     /* c mode is almost like the text mode, so we copy and patch it */
     memcpy(&xml_mode, &text_mode, sizeof(ModeDef));




reply via email to

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