qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs qe.h qe.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs qe.h qe.c
Date: Fri, 21 Dec 2007 10:30:24 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        07/12/21 10:30:24

Modified files:
        .              : qe.h qe.c 

Log message:
        use generic prompt system for write-file and simplify do_save_buffer
        use INT_MAX instead of MAXINT
        use INT_MIN for NO_ARG

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.46&r2=1.47

Patches:
Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- qe.h        20 Dec 2007 20:37:16 -0000      1.42
+++ qe.h        21 Dec 2007 10:30:24 -0000      1.43
@@ -31,6 +31,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <errno.h>
+#include <limits.h>
 #include <inttypes.h>
 
 #ifdef HAVE_QE_CONFIG_H
@@ -101,13 +102,18 @@
 typedef struct EditBuffer EditBuffer;
 typedef struct QEmacsState QEmacsState;
 
-#define MAXINT 0x7fffffff
-#define NO_ARG MAXINT
+#ifndef INT_MAX
+#define INT_MAX  0x7fffffff
+#endif
+#ifndef INT_MIN
+#define INT_MIN  (-0x7fffffff-1)
+#endif
+#define NO_ARG  INT_MIN
 /* Size for a filename buffer */
 #define MAX_FILENAME_SIZE 1024
 /* Size for a buffer name buffer */
 #define MAX_BUFFERNAME_SIZE 256
-/* Maximum length for a command name buffer */
+/* Size for a command name buffer */
 #define MAX_CMDNAME_SIZE  32
 
 /* low level I/O events */
@@ -914,7 +920,7 @@
     unsigned char *colorize_states; 
     int colorize_nb_lines;
     int colorize_nb_valid_lines;
-    /* maximum valid offset, MAXINT if not modified. Needed to invalide
+    /* maximum valid offset, INT_MAX if not modified. Needed to invalide
        'colorize_states' */
     int colorize_max_valid_offset; 
 
@@ -1406,7 +1412,8 @@
 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_buffer(EditState *s, int save_as);
+void do_save_buffer(EditState *s);
+void do_write_file(EditState *s, const char *filename);
 void do_write_region(EditState *s, const char *filename);
 void do_isearch(EditState *s, int dir);
 void do_refresh_complete(EditState *s);

Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- qe.c        20 Dec 2007 21:37:34 -0000      1.46
+++ qe.c        21 Dec 2007 10:30:24 -0000      1.47
@@ -2891,12 +2891,12 @@
     int colorize_state;
     
     /* invalidate cache if needed */
-    if (s->colorize_max_valid_offset != MAXINT) {
+    if (s->colorize_max_valid_offset != INT_MAX) {
         eb_get_pos(s->b, &line, &col, s->colorize_max_valid_offset);
         line++;
         if (line < s->colorize_nb_valid_lines)
             s->colorize_nb_valid_lines = line;
-        s->colorize_max_valid_offset = MAXINT;
+        s->colorize_max_valid_offset = INT_MAX;
     }
 
     /* realloc line buffer if needed */
@@ -2960,7 +2960,7 @@
     qe_free(&s->colorize_states);
     s->colorize_nb_lines = 0;
     s->colorize_nb_valid_lines = 0;
-    s->colorize_max_valid_offset = MAXINT;
+    s->colorize_max_valid_offset = INT_MAX;
     s->get_colorized_line_func = NULL;
     s->colorize_func = NULL;
     
@@ -5117,6 +5117,7 @@
 void do_insert_file(EditState *s, const char *filename)
 {
     FILE *f;
+
     f = fopen(filename, "r");
     if (!f) {
         put_status(s, "Could not insert file '%s'", filename);
@@ -5139,62 +5140,38 @@
     set_filename(s->b, path);
 }
 
-static void save_edit_cb(void *opaque, char *filename);
-static void save_final(EditState *s);
-
-void do_save_buffer(EditState *s, int save_as)
+static void put_save_message(EditState *s, const char *filename, int nb)
 {
-    char default_path[MAX_FILENAME_SIZE];
-
-    if (!save_as && !s->b->modified) {
-        /* CG: This behaviour bugs me! */
-        put_status(s, "(No changes need to be saved)");
-        return;
-    }
-
-    if (save_as || s->b->filename[0] == '\0') {
-        get_default_path(s, default_path, sizeof(default_path));
-        minibuffer_edit(default_path, 
-                        "Write file: ", get_history("file"), file_completion, 
-                        save_edit_cb, s);
+    if (nb >= 0) {
+       put_status(s, "Wrote %d bytes to %s", nb, filename);
     } else {
-        save_final(s);
+        put_status(s, "Could not write %s", filename);
     }
 }
 
-static void save_edit_cb(void *opaque, char *filename)
+void do_save_buffer(EditState *s)
 {
-    EditState *s = opaque;
-
-    if (!filename)
+    if (!s->b->modified) {
+        /* CG: This behaviour bugs me! */
+        put_status(s, "(No changes need to be saved)");
         return;
-    set_filename(s->b, filename);
-    qe_free(&filename);
-    save_final(s);
+    }
+    put_save_message(s, s->b->filename, eb_save_buffer(s->b));
 }
 
-static void save_final(EditState *s)
+void do_write_file(EditState *s, const char *filename)
 {
-    int res;
-
-    res = eb_save_buffer(s->b);
-    if (res >= 0) {
-       put_status(s, "Wrote %d bytes to %s", res, s->b->filename);
-    } else {
-        put_status(s, "Could not write %s", s->b->filename);
-    }
+    do_set_visited_file_name(s, filename, "n");
+    do_save_buffer(s);
 }
 
 void do_write_region(EditState *s, const char *filename)
 {
     char absname[MAX_FILENAME_SIZE];
-    int res;
 
     canonize_absolute_path(absname, sizeof(absname), filename);
-    res = eb_write_buffer(s->b, s->b->mark, s->offset, filename);
-    if (res >= 0) {
-       put_status(s, "Wrote %d bytes to %s", res, filename);
-    }
+    put_save_message(s, filename,
+                     eb_write_buffer(s->b, s->b->mark, s->offset, filename));
 }
 
 typedef struct QuitState {




reply via email to

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