qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs Makefile hex.c image.c perl.c qe.c qe.h ...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs Makefile hex.c image.c perl.c qe.c qe.h ...
Date: Fri, 18 Jan 2008 17:03:36 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        08/01/18 17:03:36

Modified files:
        .              : Makefile hex.c image.c perl.c qe.c qe.h util.c 
                         video.c 
Added files:
        .              : variables.c variables.h 

Log message:
        added variables.h and variables.c for configurable state and window 
properties
        cleaned up Makefile
        renamed ModeDef::mode_line function pointer to get_mode_line
        fixed some sparse warnings
        use c99 syntax in video.c and image.c
        added EditBuffer::offset for buffer parsing
        added state variables QEmacsState::it, QEmacsState::ignore_spaces,
           QEmacsState::mmap_threshold
        support variables in config file, strings can be delimited with ' and "

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/Makefile?cvsroot=qemacs&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/qemacs/hex.c?cvsroot=qemacs&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/qemacs/image.c?cvsroot=qemacs&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/qemacs/perl.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.67&r2=1.68
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.63&r2=1.64
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.37&r2=1.38
http://cvs.savannah.gnu.org/viewcvs/qemacs/video.c?cvsroot=qemacs&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/qemacs/variables.c?cvsroot=qemacs&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/qemacs/variables.h?cvsroot=qemacs&rev=1.1

Patches:
Index: Makefile
===================================================================
RCS file: /cvsroot/qemacs/qemacs/Makefile,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- Makefile    12 Jan 2008 09:57:40 -0000      1.31
+++ Makefile    18 Jan 2008 17:03:35 -0000      1.32
@@ -19,26 +19,6 @@
 
 include config.mak
 
-# from configure
-#CONFIG_NETWORK=yes
-#CONFIG_WIN32=yes
-#CONFIG_CYGWIN=yes
-#CONFIG_TINY=yes
-#CONFIG_X11=yes
-#CONFIG_XV=yes
-#CONFIG_XRENDER=yes
-#CONFIG_XFT=yes
-#CONFIG_HTML=yes
-#CONFIG_DLL=yes
-#CONFIG_INIT_CALLS=yes
-#CONFIG_PNG_OUTPUT=yes
-#CONFIG_FFMPEG=yes
-#CONFIG_ALL_KMAPS=yes
-# Define CONFIG_ALL_MODES to include all edit modes
-#CONFIG_ALL_MODES=yes
-# Define CONFIG_UNICODE_JOIN to include unicode bidi/script handling
-#CONFIG_UNICODE_JOIN=yes
-
 ifeq ($(CC),gcc)
   CFLAGS  := -Wall -g -O2 -funsigned-char
   # do not warn about zero-length formats.
@@ -70,6 +50,12 @@
 ########################################################
 # do not modify after this
 
+TARGETLIBS:=
+TARGETS+= qe$(EXE) tqe$(EXE) kmaps ligatures
+
+OBJS=qe.o charset.o buffer.o input.o display.o util.o hex.o list.o cutils.o
+TOBJS=tqe.o charset.o buffer.o input.o display.o util.o hex.o list.o cutils.o
+
 ifdef CONFIG_PNG_OUTPUT
   HTMLTOPPM_LIBS+= -lpng
 endif
@@ -82,16 +68,10 @@
 
 LIBS+=-lm
 
-TARGETLIBS:=
-TARGETS+= qe$(EXE) tqe$(EXE) kmaps ligatures
-
 ifndef CONFIG_CYGWIN
-TARGETS+=qe-doc.html
+  TARGETS+=qe-doc.html
 endif
 
-OBJS=qe.o charset.o buffer.o input.o display.o util.o hex.o list.o cutils.o
-TOBJS=tqe.o charset.o buffer.o input.o display.o util.o hex.o list.o cutils.o
-
 ifdef CONFIG_WIN32
   OBJS+= win32.o
   TOBJS+= win32.o
@@ -117,7 +97,7 @@
 
 ifdef CONFIG_ALL_MODES
   OBJS+= unihex.o clang.o latex-mode.o xml.o bufed.o \
-         makemode.o perl.o htmlsrc.o script.o
+         makemode.o perl.o htmlsrc.o script.o variables.o
   ifndef CONFIG_WIN32
     OBJS+= shell.o dired.o
   endif
@@ -152,37 +132,25 @@
 
 ifdef CONFIG_FFMPEG
   OBJS+= video.o image.o
-  DEP_LIBS+=$(FFMPEG_LIBDIR)/libavcodec/libavcodec.a 
$(FFMPEG_LIBDIR)/libavformat/libavformat.a
+  DEP_LIBS+= $(FFMPEG_LIBDIR)/libavcodec/libavcodec.a 
$(FFMPEG_LIBDIR)/libavformat/libavformat.a
   LIBS+=  -L$(FFMPEG_LIBDIR)/libavcodec -L$(FFMPEG_LIBDIR)/libavformat 
-lavformat -lavcodec -lz -lpthread
   DEFINES+= -I$(FFMPEG_SRCDIR)/libavcodec -I$(FFMPEG_SRCDIR)/libavformat
   TARGETS+= ffplay$(EXE)
 endif
 
-all: $(TARGETLIBS) $(TARGETS)
-
-libqhtml: force
-       make -C libqhtml all
-
 ifdef CONFIG_INIT_CALLS
   # must be the last object
   OBJS+= qeend.o
   TOBJS+= qeend.o
-else
-  SRCS:= $(OBJS:.o=.c)
-  TSRCS:= $(TOBJS:.o=.c)
-  TSRCS:= $(TSRCS:tqe.c=qe.c)
-
-qe.o: allmodules.txt
-tqe.o: basemodules.txt
+endif
 
-allmodules.txt: $(SRCS) Makefile
-       echo '/* This file was generated automatically */\n'  > $@
-       grep -h ^qe_module_init $(SRCS)                      >> $@
+#
+# Dependencies
+#
+all: $(TARGETLIBS) $(TARGETS)
 
-basemodules.txt: $(TSRCS) Makefile
-       echo '/* This file was generated automatically */\n'  > $@
-       grep -h ^qe_module_init $(TSRCS)                     >> $@
-endif
+libqhtml: force
+       make -C libqhtml all
 
 qe_g$(EXE): $(OBJS) $(DEP_LIBS)
        $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
@@ -195,9 +163,9 @@
        echo `size address@hidden `wc --bytes address@hidden qe $(OPTIONS) \
                | cut -d ' ' -f 7-10,13,15-40 >> STATS
 
-tqe.o: qe.c qe.h qestyles.h qeconfig.h config.h config.mak Makefile
-       $(CC) $(DEFINES) -DCONFIG_TINY $(CFLAGS) -o $@ -c $<
-
+#
+# Tiny version of QEmacs
+#
 tqe_g$(EXE): $(TOBJS)
        $(CC) $(TLDFLAGS) -o $@ $^ $(TLIBS)
 
@@ -209,9 +177,29 @@
        echo `size address@hidden `wc --bytes address@hidden tqe $(OPTIONS) \
                | cut -d ' ' -f 7-10,13,15-40 >> STATS
 
+tqe.o: qe.c qe.h qestyles.h qeconfig.h config.h config.mak Makefile
+       $(CC) $(DEFINES) -DCONFIG_TINY $(CFLAGS) -o $@ -c $<
+
 ffplay$(EXE): qe$(EXE) Makefile
        ln -sf $< $@
 
+ifndef CONFIG_INIT_CALLS
+SRCS:= $(OBJS:.o=.c)
+TSRCS:= $(TOBJS:.o=.c)
+TSRCS:= $(TSRCS:tqe.c=qe.c)
+
+qe.o: allmodules.txt
+tqe.o: basemodules.txt
+
+allmodules.txt: $(SRCS) Makefile
+       echo '/* This file was generated automatically */\n'  > $@
+       grep -h ^qe_module_init $(SRCS)                      >> $@
+
+basemodules.txt: $(TSRCS) Makefile
+       echo '/* This file was generated automatically */\n'  > $@
+       grep -h ^qe_module_init $(TSRCS)                     >> $@
+endif
+
 cfb.o: cfb.c cfb.h fbfrender.h
 charsetjis.o: charsetjis.c charsetjis.def
 fbfrender.o: fbfrender.c fbfrender.h libfbf.h
@@ -221,78 +209,6 @@
 %.o: %.c qe.h qestyles.h config.h config.mak Makefile
        $(CC) $(DEFINES) $(CFLAGS) -o $@ -c $<
 
-clean:
-       make -C libqhtml clean
-       rm -f *~ *.o *.a *.exe *_g TAGS gmon.out core *.exe.stackdump \
-           qe qfribidi kmaptoqe ligtoqe html2png fbftoqe fbffonts.c \
-           cptoqe jistoqe allmodules.txt basemodules.txt
-
-distclean: clean
-       rm -f config.h config.mak
-
-install: $(TARGETS) qe.1
-       install -m 755 qe$(EXE) $(prefix)/bin/qemacs$(EXE)
-       ln -sf qemacs $(prefix)/bin/qe$(EXE)
-ifdef CONFIG_FFMPEG
-       ln -sf qemacs$(EXE) $(prefix)/bin/ffplay$(EXE)
-endif
-       mkdir -p $(prefix)/share/qe
-       install kmaps ligatures $(prefix)/share/qe
-       install qe.1 $(prefix)/man/man1
-ifdef CONFIG_HTML
-       install -m 755 -s html2png$(EXE) $(prefix)/bin
-endif
-
-TAGS: force
-       etags *.[ch]
-
-force:
-
-#
-# tar archive for distribution
-#
-
-FILES=Changelog COPYING README TODO qe.1 config.eg \
-      Makefile qe.tcc qemacs.spec \
-      hex.c charset.c qe.c qe.h tty.c \
-      html.c indic.c unicode_join.c input.c qeconfig.h \
-      qeend.c unihex.c arabic.c kmaptoqe.c util.c \
-      bufed.c qestyles.h x11.c buffer.c ligtoqe.c \
-      qfribidi.c clang.c latex-mode.c xml.c dired.c list.c qfribidi.h 
html2png.c \
-      charsetmore.c charsetjis.c charsetjis.def cptoqe.c jistoqe.c \
-      libfbf.c fbfrender.c cfb.c fbftoqe.c libfbf.h fbfrender.h cfb.h \
-      display.c display.h mpeg.c shell.c \
-      docbook.c unifont.lig kmaps xterm-146-dw-patch \
-      ligatures qe-doc.texi qe-doc.html \
-      tests/HELLO.txt tests/TestPage.txt tests/test-hebrew \
-      tests/test-capital-rtl tests/test-capital-rtl.ref \
-      tests/testbidi.html \
-      plugin-example/Makefile  plugin-example/my_plugin.c \
-      image.c video.c win32.c configure VERSION \
-      cutils.c cutils.h unix.c
-
-# qhtml library
-FILES+=libqhtml/Makefile libqhtml/css.c libqhtml/cssid.h \
-       libqhtml/cssparse.c libqhtml/xmlparse.c libqhtml/htmlent.h \
-       libqhtml/css.h libqhtml/csstoqe.c \
-       libqhtml/docbook.css libqhtml/html.css
-
-# fonts
-FILES+=fonts/fixed10.fbf  fonts/fixed12.fbf  fonts/fixed13.fbf  
fonts/fixed14.fbf \
-       fonts/helv10.fbf   fonts/helv12.fbf   fonts/helv14.fbf   
fonts/helv18.fbf \
-       fonts/helv24.fbf   fonts/helv8.fbf    fonts/times10.fbf  
fonts/times12.fbf \
-       fonts/times14.fbf  fonts/times18.fbf  fonts/times24.fbf  
fonts/times8.fbf \
-       fonts/unifont.fbf
-
-FILE=qemacs-$(VERSION)
-
-tar:
-       rm -rf /tmp/$(FILE)
-       mkdir -p /tmp/$(FILE)
-       cp --parents $(FILES) /tmp/$(FILE)
-       ( cd /tmp ; tar zcvf $(HOME)/$(FILE).tar.gz $(FILE) )
-       rm -rf /tmp/$(FILE)
-
 #
 # Test for bidir algorithm
 #
@@ -372,9 +288,9 @@
 #
 # fonts (only needed for html2png)
 #
-FONTS=fixed10.fbf fixed12.fbf fixed13.fbf fixed14.fbf\
-      helv8.fbf helv10.fbf helv12.fbf helv14.fbf helv18.fbf helv24.fbf\
-      times8.fbf times10.fbf times12.fbf times14.fbf times18.fbf times24.fbf\
+FONTS=fixed10.fbf fixed12.fbf fixed13.fbf fixed14.fbf \
+      helv8.fbf helv10.fbf helv12.fbf helv14.fbf helv18.fbf helv24.fbf \
+      times8.fbf times10.fbf times12.fbf times14.fbf times18.fbf times24.fbf \
       unifont.fbf
 FONTS:=$(addprefix fonts/,$(FONTS))
 
@@ -387,13 +303,13 @@
 #
 # html2png tool (XML/HTML/CSS2 renderer test tool)
 #
-OBJS1=util.o cutils.o \
+OBJS1=html2png.o util.o cutils.o \
      arabic.o indic.o qfribidi.o display.o unicode_join.o \
      charset.o charsetmore.o charsetjis.o \
      libfbf.o fbfrender.o cfb.o fbffonts.o
 
-html2png$(EXE): html2png.o $(OBJS1) libqhtml/libqhtml.a
-       $(CC) $(LDFLAGS) -o $@ html2png.o $(OBJS1) \
+html2png$(EXE): $(OBJS1) libqhtml/libqhtml.a
+       $(CC) $(LDFLAGS) -o $@ $(OBJS1) \
                    -L./libqhtml -lqhtml $(HTMLTOPPM_LIBS)
 
 # autotest target
@@ -403,3 +319,73 @@
 # documentation
 qe-doc.html: qe-doc.texi Makefile
        LANGUAGE=en_US LC_ALL=en_US.UTF-8 texi2html -monolithic -number $<
+
+#
+# Maintenance targets
+#
+clean:
+       make -C libqhtml clean
+       rm -f *~ *.o *.a *.exe *_g TAGS gmon.out core *.exe.stackdump \
+           qe qfribidi kmaptoqe ligtoqe html2png fbftoqe fbffonts.c \
+           cptoqe jistoqe allmodules.txt basemodules.txt
+
+distclean: clean
+       rm -f config.h config.mak
+
+install: $(TARGETS) qe.1
+       install -m 755 qe$(EXE) $(prefix)/bin/qemacs$(EXE)
+       ln -sf qemacs $(prefix)/bin/qe$(EXE)
+ifdef CONFIG_FFMPEG
+       ln -sf qemacs$(EXE) $(prefix)/bin/ffplay$(EXE)
+endif
+       mkdir -p $(prefix)/share/qe
+       install kmaps ligatures $(prefix)/share/qe
+       install qe.1 $(prefix)/man/man1
+ifdef CONFIG_HTML
+       install -m 755 -s html2png$(EXE) $(prefix)/bin
+endif
+
+TAGS: force
+       etags *.[ch]
+
+force:
+
+#
+# tar archive for distribution
+#
+FILES:=COPYING Changelog Makefile README TODO VERSION \
+       arabic.c bufed.c buffer.c cfb.c cfb.h charset.c charsetjis.c \
+       charsetjis.def charsetmore.c clang.c config.eg config.h \
+       configure cptoqe.c cutils.c cutils.h dired.c display.c \
+       display.h docbook.c extras.c fbffonts.c fbfrender.c \
+       fbfrender.h fbftoqe.c hex.c html.c html2png.c htmlsrc.c \
+       image.c indic.c input.c jistoqe.c kmap.c kmaptoqe.c \
+       latex-mode.c libfbf.c libfbf.h ligtoqe.c list.c makemode.c \
+       mpeg.c perl.c qe-doc.html qe-doc.texi qe.1 qe.c qe.h qe.tcc \
+       qeconfig.h qeend.c qemacs.spec qestyles.h qfribidi.c \
+       qfribidi.h script.c shell.c tty.c unicode_join.c unihex.c \
+       unix.c util.c variables.c variables.h video.c win32.c x11.c \
+       xml.c xterm-146-dw-patch 
+
+FILES+=plugin-example/Makefile  plugin-example/my_plugin.c
+
+FILES+=tests/HELLO.txt tests/TestPage.txt tests/test-hebrew \
+       tests/test-capital-rtl tests/test-capital-rtl.ref \
+       tests/testbidi.html \
+
+# qhtml library
+FILES+=libqhtml/Makefile libqhtml/css.c libqhtml/css.h libqhtml/cssid.h \
+       libqhtml/cssparse.c libqhtml/csstoqe.c libqhtml/docbook.css \
+       libqhtml/html.css libqhtml/htmlent.h libqhtml/xmlparse.c
+
+# keyboard maps, code pages, fonts
+FILES+=unifont.lig ligatures kmaps $(KMAPS) $(CP) $(JIS) $(FONTS)
+
+FILE=qemacs-$(VERSION)
+
+tar: $(FILES)
+       rm -rf /tmp/$(FILE)
+       mkdir -p /tmp/$(FILE)
+       cp --parents $(FILES) /tmp/$(FILE)
+       ( cd /tmp ; tar zcvf $(HOME)/$(FILE).tar.gz $(FILE) )
+       rm -rf /tmp/$(FILE)

Index: hex.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/hex.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- hex.c       11 Jan 2008 11:29:28 -0000      1.21
+++ hex.c       18 Jan 2008 17:03:35 -0000      1.22
@@ -334,7 +334,7 @@
     .scroll_up_down = text_scroll_up_down,
     .write_char = text_write_char,
     .mouse_goto = text_mouse_goto,
-    .mode_line = hex_mode_line,
+    .get_mode_line = hex_mode_line,
 };
 
 static ModeDef hex_mode = {
@@ -353,7 +353,7 @@
     .scroll_up_down = text_scroll_up_down,
     .write_char = hex_write_char,
     .mouse_goto = text_mouse_goto,
-    .mode_line = hex_mode_line,
+    .get_mode_line = hex_mode_line,
 };
 
 static int hex_init(void)

Index: image.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/image.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- image.c     11 Jan 2008 11:29:29 -0000      1.18
+++ image.c     18 Jan 2008 17:03:35 -0000      1.19
@@ -828,16 +828,16 @@
 
 ModeDef image_mode = {
     "image",
-    instance_size: sizeof(ImageState),
-    mode_probe: image_mode_probe,
-    mode_init: image_mode_init,
-    mode_close: image_mode_close,
-    display: image_display,
-    move_up_down: image_move_up_down,
-    move_left_right: image_move_left_right,
-    scroll_up_down: image_scroll_up_down,
-    data_type: &image_data_type,
-    mode_line: image_mode_line,
+    .instance_size = sizeof(ImageState),
+    .mode_probe = image_mode_probe,
+    .mode_init = image_mode_init,
+    .mode_close = image_mode_close,
+    .display = image_display,
+    .move_up_down = image_move_up_down,
+    .move_left_right = image_move_left_right,
+    .scroll_up_down = image_scroll_up_down,
+    .data_type = &image_data_type,
+    .get_mode_line = image_mode_line,
 };
 
 static EditBufferDataType image_data_type = {

Index: perl.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/perl.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- perl.c      12 Jan 2008 09:57:41 -0000      1.7
+++ perl.c      18 Jan 2008 17:03:35 -0000      1.8
@@ -62,11 +62,11 @@
     if (str[j] == '0') {
         j++;
         if (str[j] == 'x' || str[j] == 'X') {
-            do j++; while (qe_isxdigit(str[j]));
+            do { j++; } while (qe_isxdigit(str[j]));
             return j;
         }
         if (str[j] >= '0' && str[j] <= '7') {
-            do j++; while (str[j] >= '0' && str[j] <= '7');
+            do { j++; } while (str[j] >= '0' && str[j] <= '7');
             return j;
         }
     }
@@ -74,7 +74,7 @@
         j++;
 
     if (str[j] == '.')
-        do j++; while (qe_isdigit(str[j]));
+        do { j++; } while (qe_isdigit(str[j]));
 
     if (str[j] == 'E' || str[j] == 'e') {
         j++;

Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- qe.c        12 Jan 2008 09:57:41 -0000      1.67
+++ qe.c        18 Jan 2008 17:03:35 -0000      1.68
@@ -29,6 +29,8 @@
 
 #include "qfribidi.h"
 
+#include "variables.h"
+
 #ifdef CONFIG_DLL
 #include <dlfcn.h>
 #endif
@@ -92,8 +94,8 @@
         m->mode_save_data = generic_mode_save_data;
     if (!m->data_type)
         m->data_type = &raw_data_type;
-    if (!m->mode_line)
-        m->mode_line = text_mode_line;
+    if (!m->get_mode_line)
+        m->get_mode_line = text_mode_line;
 
     /* add a new command to switch to that mode */
     if (!(m->mode_flags & MODEF_NOCMD)) {
@@ -726,7 +728,7 @@
 
 void do_delete_char(EditState *s, int argval)
 {
-    int end, i, offset1;
+    int endpos, i, offset1;
 
     if (s->b->flags & BF_READONLY)
         return;
@@ -737,14 +739,14 @@
     } else
     if (argval) {
         /* save kill if universal argument given */
-        end = s->offset;
-        for (i = argval; i > 0 && end < s->b->total_size; i--) {
-            eb_nextc(s->b, end, &end);
+        endpos = s->offset;
+        for (i = argval; i > 0 && endpos < s->b->total_size; i--) {
+            eb_nextc(s->b, endpos, &endpos);
         }
-        for (i = argval; i < 0 && end > 0; i++) {
-            eb_prevc(s->b, end, &end);
+        for (i = argval; i < 0 && endpos > 0; i++) {
+            eb_prevc(s->b, endpos, &endpos);
         }
-        do_kill(s, s->offset, end, argval);
+        do_kill(s, s->offset, endpos, argval);
     }
 }
 
@@ -2046,7 +2048,7 @@
     int y = s->ytop + s->height;
 
     if (s->flags & WF_MODELINE) {
-        s->mode->mode_line(s, buf, sizeof(buf));
+        s->mode->get_mode_line(s, buf, sizeof(buf));
         if (!strequal(buf, s->modeline_shadow)) {
             print_at_byte(s->screen,
                           s->xleft,
@@ -6951,6 +6953,47 @@
     }
 }
 
+static int qe_cfg_parse_string(EditState *s, const char **pp,
+                               char *dest, int size)
+{
+    const char *p = *pp;
+    int c, delim = *p++;
+    int res = 0;
+    int pos = 0;
+
+    for (;;) {
+        c = *p;
+        if (c == '\0') {
+            put_status(s, "Unterminated string");
+            res = -1;
+            break;
+        }
+        p++;
+        if (c == delim)
+            break;
+        if (c == '\\') {
+            c = *p++;
+            switch (c) {
+            case 'n':
+                c = '\n';
+                break;
+            case 'r':
+                c = '\r';
+                break;
+            case 't':
+                c = '\t';
+                break;
+            }
+        }
+        if (pos < size - 1)
+            dest[pos++] = c;
+    }
+    if (pos < size)
+        dest[pos] = '\0';
+    *pp = p;
+    return res;
+}
+
 int parse_config_file(EditState *s, const char *filename)
 {
     QEmacsState *qs = s->qe_state;
@@ -7028,10 +7071,33 @@
                 goto fail;
             continue;
         }
+#ifndef CONFIG_TINY
+        {
+            /* search for variable */
+            struct VarDef *vp;
+
+            vp = qe_find_variable(cmd);
+            if (vp) {
+                if (!expect_token(&p, '='))
+                    goto fail;
+                skip_spaces(&p);
+                if (*p == '\"' || *p == '\'') {
+                    if (qe_cfg_parse_string(s, &p, str, countof(str)))
+                        goto fail;
+                    qe_set_variable(s, cmd, str, 0);
+                } else {
+                    qe_set_variable(s, cmd, NULL, strtol(p, (char**)&p, 0));
+                }
+                skip_spaces(&p);
+                if (*p != ';' && *p != '\n')
+                    put_status(s, "Syntax error '%s'", cmd);
+                continue;
+            }
+        }
+#endif
         /* search for command */
         d = qe_find_cmd(cmd);
         if (!d) {
-            /* CG: should handle variables */
             err = -1;
             put_status(s, "Unknown command '%s'", cmd);
             continue;
@@ -7055,7 +7121,7 @@
             unsigned char arg_type;
             int ret;
 
-            ret = parse_arg(&r, &arg_type, prompt, sizeof(prompt),
+            ret = parse_arg(&r, &arg_type, prompt, countof(prompt),
                             NULL, 0, NULL, 0);
             if (ret < 0)
                 goto badcmd;
@@ -7102,49 +7168,26 @@
 
             switch (args_type[i]) {
             case CMD_ARG_INT:
-                args[i].n = strtol(p, (char**)&q, 0);
-                if (q == p) {
+                r = p;
+                args[i].n = strtol(p, (char**)&p, 0);
+                if (p == r) {
                     put_status(s, "Number expected for arg %d", i);
                     goto fail;
                 }
-                p = q;
                 break;
             case CMD_ARG_STRING:
-                if (*p != '\"') {
+                if (*p != '\"' && *p != '\'') {
                     /* XXX: should convert number to string */
                     put_status(s, "String expected for arg %d", i);
                     goto fail;
                 }
-                p++;
-                /* Sloppy parser: all strings will fit in buffer
-                 * because it is the same size as line buffer.
-                 * All config commands must fit on a single line.
-                 */
-                q = strp;
-                while (*p != '\"' && *p != '\0') {
-                    c = *p++;
-                    if (c == '\\') {
-                        c = *p++;
-                        switch (c) {
-                        case 'n':
-                            c = '\n';
-                            break;
-                        case 'r':
-                            c = '\r';
-                            break;
-                        }
-                    }
-                    *q++ = c;
-                }
-                *q = '\0';
-                c = '"';
-                if (*p != c) {
-                    put_status(s, "Unterminated string");
+                if (qe_cfg_parse_string(s, &p, strp,
+                                        str + countof(str) - strp) < 0)
+                {
                     goto fail;
                 }
-                p++;
                 args[i].p = strp;
-                strp = q + 1;
+                strp += strlen(strp) + 1;
                 break;
             }
         }

Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -b -r1.63 -r1.64
--- qe.h        12 Jan 2008 09:57:41 -0000      1.63
+++ qe.h        18 Jan 2008 17:03:35 -0000      1.64
@@ -24,6 +24,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <stddef.h>
 #include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
@@ -727,6 +728,9 @@
      */
     struct ModeSavedData *saved_data;
 
+    /* default mode stuff when buffer is detached from window */
+    int offset;         /* used in eval.c */
+
     EditBuffer *next; /* next editbuffer in qe_state buffer list */
     char name[MAX_BUFFERNAME_SIZE];     /* buffer name */
     char filename[MAX_FILENAME_SIZE];   /* file name */
@@ -1054,7 +1058,7 @@
     int mode_flags;
 #define MODEF_NOCMD 0x0001 /* do not register xxx-mode command automatically */
     EditBufferDataType *data_type; /* native buffer data type (NULL = raw) */
-    int (*mode_line)(EditState *s, char *buf, int buf_size); /* return mode 
line */
+    int (*get_mode_line)(EditState *s, char *buf, int buf_size); /* return 
mode line */
 
     /* mode specific key bindings */
     //struct KeyDef *first_key;
@@ -1120,7 +1124,7 @@
     struct HistoryEntry *first_history;
     //struct QECharset *first_charset;
     //struct QETimer *first_timer;
-    //struct VarDef *first_variable;
+    struct VarDef *first_variable;
     struct InputMethod *input_methods;
     EditState *first_window;
     EditState *active_window; /* window in which we edit */
@@ -1168,13 +1172,13 @@
     char system_fonts[NB_FONT_FAMILIES][256];
 
     ///* global variables */
-    //int it;             /* last result from expression evaluator */
+    int it;             /* last result from expression evaluator */
     ////int force_tty;    /* prevent graphics display (X11...) */
     //int no_config;      /* prevent config file eval */
     //int force_refresh;  /* force a complete screen refresh */
-    //int ignore_spaces;  /* ignore spaces when comparing windows */
+    int ignore_spaces;  /* ignore spaces when comparing windows */
     int hilite_region;  /* hilite the current region when selecting */
-    //int mmap_threshold; /* minimum file size for mmap */
+    int mmap_threshold; /* minimum file size for mmap */
 };
 
 extern QEmacsState qe_state;
@@ -1207,14 +1211,14 @@
 
 typedef enum CmdSig {
     CMD_void = 0,
-    CMD_ES,     /* ES, no other arguments */
-    CMD_ESi,    /* ES + integer */
-    CMD_ESs,    /* ES + string */
-    CMD_ESii,   /* ES + integer + integer */
-    CMD_ESsi,   /* ES + string + integer */
-    CMD_ESss,   /* ES + string + string */
-    CMD_ESssi,  /* ES + string + string + integer */
-    CMD_ESsss,  /* ES + string + string + string */
+    CMD_ES,     /* (ES*) -> void */
+    CMD_ESi,    /* (ES*, int) -> void */
+    CMD_ESs,    /* (ES*, string) -> void */
+    CMD_ESii,   /* (ES*, int, int) -> void */
+    CMD_ESsi,   /* (ES*, string, int) -> void */
+    CMD_ESss,   /* (ES*, string, string) -> void */
+    CMD_ESssi,  /* (ES*, string, string, int) -> void */
+    CMD_ESsss,  /* (ES*, string, string, string) -> void */
 } CmdSig;
 
 #define MAX_CMD_ARGS 5
@@ -1244,7 +1248,7 @@
     const char *name;
     CmdProto action;
     CmdSig sig : 8;
-    int val : 24;
+    signed int val : 24;
 } CmdDef;
 
 /* new command macros */

Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- util.c      11 Jan 2008 11:29:29 -0000      1.37
+++ util.c      18 Jan 2008 17:03:35 -0000      1.38
@@ -1155,10 +1155,12 @@
 {
 #ifdef CONFIG_WIN32
     struct _timeb tb;
+
     _ftime(&tb);
     return tb.time * 1000 + tb.millitm;
 #else
     struct timeval tv;
+
     gettimeofday(&tv, NULL);
     return tv.tv_sec * 1000 + (tv.tv_usec / 1000);
 #endif
@@ -1168,10 +1170,12 @@
 {
 #ifdef CONFIG_WIN32
     struct _timeb tb;
+
     _ftime(&tb);
     return tb.time * 1000000 + tb.millitm * 1000;
 #else
     struct timeval tv;
+
     gettimeofday(&tv, NULL);
     return tv.tv_sec * 1000000 + tv.tv_usec;
 #endif

Index: video.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/video.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- video.c     11 Jan 2008 11:29:29 -0000      1.12
+++ video.c     18 Jan 2008 17:03:36 -0000      1.13
@@ -951,13 +951,13 @@
 
 ModeDef video_mode = {
     "av",
-    instance_size: sizeof(VideoState),
-    mode_probe: video_mode_probe,
-    mode_init: video_mode_init,
-    mode_close: video_mode_close,
-    display: video_display,
-    data_type: &video_data_type,
-    mode_line: video_mode_line,
+    .instance_size = sizeof(VideoState),
+    .mode_probe = video_mode_probe,
+    .mode_init = video_mode_init,
+    .mode_close = video_mode_close,
+    .display = video_display,
+    .data_type = &video_data_type,
+    .get_mode_line = video_mode_line,
 };
 
 static EditBufferDataType video_data_type = {

Index: variables.c
===================================================================
RCS file: variables.c
diff -N variables.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ variables.c 18 Jan 2008 17:03:36 -0000      1.1
@@ -0,0 +1,325 @@
+/*
+ * QEmacs, tiny but powerful multimode editor
+ *
+ * Copyright (c) 2000-2008 Charlie Gordon.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "qe.h"
+#include "variables.h"
+
+static VarDef var_table[] = {
+
+    S_VAR( "screen-width", width, VAR_NUMBER, VAR_RO )
+    S_VAR( "screen-height", height, VAR_NUMBER, VAR_RO )
+    S_VAR( "is-full-screen", is_full_screen, VAR_NUMBER, VAR_RO )
+    S_VAR( "flag-split-window-change-focus", flag_split_window_change_focus, 
VAR_NUMBER, VAR_RW )
+    S_VAR( "backspace-is-control-h", backspace_is_control_h, VAR_NUMBER, 
VAR_RW )
+    S_VAR( "ungot-key", ungot_key, VAR_NUMBER, VAR_RW )
+    S_VAR( "QEPATH", res_path, VAR_CHARS, VAR_RO )
+    //S_VAR( "it", it, VAR_NUMBER, VAR_RW )
+    S_VAR( "ignore-spaces", ignore_spaces, VAR_NUMBER, VAR_RW )
+    S_VAR( "hilite-region", hilite_region, VAR_NUMBER, VAR_RW )
+    S_VAR( "mmap-threshold", mmap_threshold, VAR_NUMBER, VAR_RW )
+
+    //B_VAR( "screen-charset", charset, VAR_NUMBER, VAR_RW )
+
+    B_VAR( "mark", mark, VAR_NUMBER, VAR_RW )
+    B_VAR( "bufsize", total_size, VAR_NUMBER, VAR_RO )
+    B_VAR( "bufname", name, VAR_CHARS, VAR_RO )
+    B_VAR( "filename", filename, VAR_CHARS, VAR_RO )
+
+    W_VAR( "point", offset, VAR_NUMBER, VAR_RW )
+    W_VAR( "tab-size", tab_size, VAR_NUMBER, VAR_RW )
+    W_VAR( "indent-size", indent_size, VAR_NUMBER, VAR_RW )
+    W_VAR( "indent-tabs-mode", indent_tabs_mode, VAR_NUMBER, VAR_RW )
+    W_VAR( "default-style", default_style, VAR_NUMBER, VAR_RW )
+    W_VAR( "region-style", region_style, VAR_NUMBER, VAR_RW )
+    W_VAR( "curline-style", curline_style, VAR_NUMBER, VAR_RW )
+    W_VAR( "window-width", width, VAR_NUMBER, VAR_RW )
+    W_VAR( "window_height", height, VAR_NUMBER, VAR_RW )
+    W_VAR( "window-left", xleft, VAR_NUMBER, VAR_RW )
+    W_VAR( "window-top", ytop, VAR_NUMBER, VAR_RW )
+    W_VAR( "window-prompt", prompt, VAR_STRING, VAR_RW )
+
+    M_VAR( "mode-name", name, VAR_CHARS, VAR_RO )
+
+    /* more buffer fields: modified, readonly, binary, charset */
+    /* more window fields: mode_line, disp_width, color, input_method...
+     */
+
+    //G_VAR( "text-mode-line", text_mode.mode_line, VAR_STRING, VAR_RW )
+    //G_VAR( "ascii-mode-line", ascii_mode.mode_line, VAR_STRING, VAR_RW )
+    //G_VAR( "hex-mode-line", hex_mode.mode_line, VAR_STRING, VAR_RW )
+    //G_VAR( "unicode-mode-line", unihex_mode.mode_line, VAR_STRING, VAR_RW )
+
+    //Dispatch these to the appropriate modules
+    //G_VAR( "c-mode-extensions", c_mode_extensions, VAR_STRING, VAR_RW )
+    //G_VAR( "c-mode-keywords", c_mode_keywords, VAR_STRING, VAR_RW )
+    //G_VAR( "c-mode-types", c_mode_types, VAR_STRING, VAR_RW )
+    //G_VAR( "html-mode-extensions", html_mode_extensions, VAR_STRING, VAR_RW )
+    //G_VAR( "perl-mode-extensions", perl_mode_extensions, VAR_STRING, VAR_RW )
+};
+
+void qe_register_variables(VarDef *vars, int count)
+{
+    QEmacsState *qs = &qe_state;
+    VarDef *vp;
+
+    for (vp = vars; vp < vars + count - 1; vp++) {
+        vp->next = vp + 1;
+    }
+    vp->next = qs->first_variable;
+    qs->first_variable = vars;
+}
+
+VarDef *qe_find_variable(const char *name)
+{
+    QEmacsState *qs = &qe_state;
+    VarDef *vp;
+
+    for (vp = qs->first_variable; vp; vp = vp->next) {
+        if (strequal(vp->name, name))
+              return vp;
+    }
+    /* Should have a list of local variables for buffer/window/mode
+     * instances
+     */
+    return NULL;
+}
+
+void qe_complete_variable(CompleteState *cp)
+{
+    QEmacsState *qs = cp->s->qe_state;
+    const VarDef *vp;
+
+    for (vp = qs->first_variable; vp; vp = vp->next) {
+        complete_test(cp, vp->name);
+    }
+}
+
+QVarType qe_get_variable(EditState *s, const char *name,
+                         char *buf, int size, int *pnum)
+{
+    const VarDef *vp;
+    int num = 0;
+    const char *str = NULL;
+    const void *ptr;
+
+    vp = qe_find_variable(name);
+    if (!vp) {
+        /* Should enumerate user variables ? */
+
+        /* Try environment */
+        str = getenv(name);
+        if (str) {
+            pstrcpy(buf, size, str);
+            return VAR_STRING;
+        } else {
+            if (size > 0)
+                *buf = '\0';
+            return VAR_UNKNOWN;
+        }
+    }
+    switch (vp->domain) {
+    case VAR_SELF:
+        ptr = &vp->value;
+        break;
+    case VAR_GLOBAL:
+        ptr = vp->value.ptr;
+        break;
+    case VAR_STATE:
+        ptr = (const u8*)s->qe_state + vp->value.offset;
+        break;
+    case VAR_BUFFER:
+        ptr = (const u8*)s->b + vp->value.offset;
+        break;
+    case VAR_WINDOW:
+        ptr = (const u8*)s + vp->value.offset;
+        break;
+    case VAR_MODE:
+        ptr = (const u8*)s->mode + vp->value.offset;
+        break;
+    default:
+        if (size > 0)
+            *buf = '\0';
+        return VAR_UNKNOWN;
+    }
+
+    switch (vp->type) {
+    case VAR_STRING:
+        str = *(const char**)ptr;
+        pstrcpy(buf, size, str);
+        break;
+    case VAR_CHARS:
+        str = (const char*)ptr;
+        pstrcpy(buf, size, str);
+        break;
+    case VAR_NUMBER:
+        num = *(const int*)ptr;
+        if (pnum)
+            *pnum = num;
+        else
+            snprintf(buf, size, "%d", num);
+        break;
+    default:
+        if (size > 0)
+            *buf = '\0';
+        return VAR_UNKNOWN;
+    }
+    return vp->type;
+}
+
+/* Ugly kludge to check for allocated data: pointers above end are
+ * assumed to be allocated with qe_malloc
+ */
+extern u8 end[];
+
+QVarType qe_set_variable(EditState *s, const char *name,
+                         const char *value, int num)
+{
+    char buf[32];
+    void *ptr;
+    char **pstr;
+    VarDef *vp;
+
+    vp = qe_find_variable(name);
+    if (!vp) {
+        /* Create user variable (global/buffer/window/mode?) */
+        vp = qe_mallocz(VarDef);
+        vp->name = qe_strdup(name);
+        vp->domain = VAR_SELF;
+        vp->rw = VAR_RW;
+        if (value) {
+            vp->value.str = qe_strdup(value);
+            vp->type = VAR_STRING;
+        } else {
+            vp->value.num = num;
+            vp->type = VAR_NUMBER;
+        }
+        qe_register_variables(vp, 1);
+        return vp->type;
+    } else
+    if (vp->rw == VAR_RO) {
+        put_status(s, "Variable %s is read-only", name);
+        return VAR_UNKNOWN;
+    } else {
+        switch (vp->domain) {
+        case VAR_SELF:
+            ptr = &vp->value;
+            break;
+        case VAR_GLOBAL:
+            ptr = vp->value.ptr;
+            break;
+        case VAR_STATE:
+            ptr = (u8*)s->qe_state + vp->value.offset;
+            break;
+        case VAR_BUFFER:
+            ptr = (u8*)s->b + vp->value.offset;
+            break;
+        case VAR_WINDOW:
+            ptr = (u8*)s + vp->value.offset;
+            break;
+        case VAR_MODE:
+            ptr = (u8*)s->mode + vp->value.offset;
+            break;
+        default:
+            return VAR_UNKNOWN;
+        }
+
+        switch (vp->type) {
+        case VAR_STRING:
+            if (!value) {
+                sprintf(buf, "%d", num);
+                value = buf;
+            }
+            pstr = (char **)ptr;
+            if ((u8 *)*pstr > end)
+                qe_free(*pstr);
+            *pstr = qe_strdup(value);
+            break;
+        case VAR_CHARS:
+            if (!value) {
+                sprintf(buf, "%d", num);
+                value = buf;
+            }
+            pstrcpy(ptr, vp->size, value);
+            break;
+        case VAR_NUMBER:
+            if (!value)
+                *(int*)ptr = num;
+            else
+                *(int*)ptr = strtol(value, NULL, 0);
+            break;
+        default:
+            return VAR_UNKNOWN;
+        }
+        return vp->type;
+    }
+}
+
+void do_show_variable(EditState *s, const char *name)
+{
+    char buf[MAX_FILENAME_SIZE];
+
+    if (qe_get_variable(s, name, buf, sizeof(buf), NULL) == VAR_UNKNOWN)
+        put_status(s, "No variable %s", name);
+    else
+        put_status(s, "%s -> %s", name, buf);
+}
+
+void do_set_variable(EditState *s, const char *name, const char *value)
+{
+    qe_set_variable(s, name, value, 0);
+}
+
+/* should register this as help function */
+void qe_list_variables(EditState *s, EditBuffer *b)
+{
+    QEmacsState *qs = s->qe_state;
+    char buf[MAX_FILENAME_SIZE];
+    const VarDef *vp;
+
+    eb_printf(b, "\n  variables:\n\n");
+    for (vp = qs->first_variable; vp; vp = vp->next) {
+        qe_get_variable(s, vp->name, buf, sizeof(buf), NULL);
+        eb_printf(b, "    D%d T%d %s  %-14s  '%s'\n",
+                  vp->domain, vp->type, vp->rw ? "rw" : "ro",
+                  vp->name, buf);
+    }
+}
+
+/*---------------- commands ----------------*/
+
+static CmdDef var_commands[] = {
+    CMD_( KEY_NONE, KEY_NONE,
+          "show-variable", do_show_variable, ESs,
+          "s{Show variable: }[var]|var|")
+    CMD_( KEY_F8, KEY_NONE,
+          "set-variable", do_set_variable, ESss,
+          "s{Set variable: }[var]|var|s{to value: }|value|")
+    CMD_DEF_END,
+};
+
+static int vars_init(void)
+{
+    qe_register_variables(var_table, countof(var_table));
+    qe_register_cmd_table(var_commands, NULL);
+    register_completion("var", qe_complete_variable);
+    return 0;
+}
+
+qe_module_init(vars_init);

Index: variables.h
===================================================================
RCS file: variables.h
diff -N variables.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ variables.h 18 Jan 2008 17:03:36 -0000      1.1
@@ -0,0 +1,65 @@
+
+typedef enum QVarType {
+    VAR_UNKNOWN = 0,
+    VAR_NUMBER,
+    VAR_STRING,
+    VAR_CHARS,
+} QVarType;
+
+enum QVarAccess {
+    VAR_RO,
+    VAR_RW,
+};
+
+enum QVarDomain {
+    VAR_GLOBAL,
+    VAR_STATE,
+    VAR_BUFFER,
+    VAR_WINDOW,
+    VAR_MODE,
+    VAR_SELF,
+};
+
+typedef struct VarDef {
+    const char *name;
+    enum QVarDomain domain : 4;
+    enum QVarType type : 4;
+    enum QVarAccess rw : 2;
+    unsigned int size : 16;
+    union {
+        void *ptr;
+        int offset;
+        char **pstr;
+        int *pint;
+        char *str;
+        int num;
+    } value;
+    struct VarDef *next;
+} VarDef;
+
+#define U_VAR(name, type) \
+    { (name), VAR_SELF, type, VAR_RW, 0, { .num = 0 }, NULL },
+#define G_VAR(name,ptr,type,rw) \
+    { (name), VAR_GLOBAL, type, rw, 0, { (void*)&(ptr) }, NULL },
+#define S_VAR(name,fld,type,rw) \
+    { (name), VAR_STATE, type, rw, sizeof(((QEmacsState*)0)->fld), { .offset = 
offsetof(QEmacsState, fld) }, NULL },
+#define B_VAR(name,fld,type,rw) \
+    { (name), VAR_BUFFER, type, rw, sizeof(((EditBuffer*)0)->fld), { .offset = 
offsetof(EditBuffer, fld) }, NULL },
+#define W_VAR(name,fld,type,rw) \
+    { (name), VAR_WINDOW, type, rw, sizeof(((EditState*)0)->fld), { .offset = 
offsetof(EditState, fld) }, NULL },
+#define M_VAR(name,fld,type,rw) \
+    { (name), VAR_MODE, type, rw, sizeof(((ModeDef*)0)->fld), { .offset = 
offsetof(ModeDef, fld) }, NULL },
+
+void qe_register_variables(VarDef *vars, int count);
+VarDef *qe_find_variable(const char *name);
+void qe_complete_variable(CompleteState *cp);
+
+QVarType qe_get_variable(EditState *s, const char *name,
+                        char *buf, int size, int *pnum);
+QVarType qe_set_variable(EditState *s, const char *name,
+                        const char *value, int num);
+
+void qe_list_variables(EditState *s, EditBuffer *b);
+
+void do_set_variable(EditState *s, const char *name, const char *value);
+void do_show_variable(EditState *s, const char *name);




reply via email to

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