qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs clang.c dired.c qe.c qe.h util.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs clang.c dired.c qe.c qe.h util.c
Date: Wed, 26 Mar 2008 08:03:56 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        08/03/26 08:03:56

Modified files:
        .              : clang.c dired.c qe.c qe.h util.c 

Log message:
        added reduce_filename to compute a stripped filename for mode probing
          stripping VCS/backup prefixes and suffixes, fixing case.
        added Lex (.l .lex) and .C files to C mode
        fixed spurious error message at edit_set_mode_file
        restored standard behaviour for extension() : return pointer to last 
extension

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.68&r2=1.69
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.66&r2=1.67
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.39&r2=1.40

Patches:
Index: clang.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/clang.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- clang.c     12 Jan 2008 09:57:41 -0000      1.30
+++ clang.c     26 Mar 2008 08:03:55 -0000      1.31
@@ -45,7 +45,7 @@
     "_Bool|_Complex|_Imaginary|";
 
 static const char *c_mode_extensions =
-    "c|h|y|e|cc|cs|cpp|cxx|hpp|hxx|idl|jav|java|js|qe|json|pcc";
+    "c|h|y|e|cc|cs|cpp|cxx|hpp|hxx|idl|jav|java|js|qe|json|pcc|C|l|lex";
 
 #if 0
 static int get_c_identifier(char *buf, int buf_size, unsigned int *p)

Index: dired.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/dired.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- dired.c     25 Mar 2008 11:02:52 -0000      1.21
+++ dired.c     26 Mar 2008 08:03:55 -0000      1.22
@@ -240,6 +240,9 @@
     s->b->flags |= BF_DIRED;
 
     ffst = find_file_open(hs->path, "*");
+    /* Should scan directory/filespec before computing lines to adjust
+     * filename gutter width
+     */
     while (!find_file_next(ffst, filename, sizeof(filename))) {
         if (lstat(filename, &st) < 0)
             continue;

Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -b -r1.68 -r1.69
--- qe.c        18 Jan 2008 17:03:35 -0000      1.68
+++ qe.c        26 Mar 2008 08:03:56 -0000      1.69
@@ -1594,9 +1594,15 @@
         return 0;
 
     if (!f1) {
+        struct stat st;
+
+        if (stat(b->filename, &st) < 0 || !S_ISREG(st.st_mode))
+            return -1;
+
         f = fopen(b->filename, "r");
-        if (!f)
+        if (!f) {
             goto fail;
+        }
     } else {
         f = f1;
     }
@@ -1607,6 +1613,7 @@
     b->save_log = saved;
     if (!f1)
         fclose(f);
+
     if (ret < 0) {
     fail:
         if (!f1) {
@@ -1733,6 +1740,7 @@
 void do_next_mode(EditState *s)
 {
     QEmacsState *qs = s->qe_state;
+    char fname[MAX_FILENAME_SIZE];
     u8 buf[1024];
     ModeProbeData probe_data;
     int size;
@@ -1741,8 +1749,10 @@
     size = eb_read(s->b, 0, buf, sizeof(buf));
     probe_data.buf = buf;
     probe_data.buf_size = size;
-    probe_data.filename = s->b->filename;
+    probe_data.real_filename = s->b->filename;
     probe_data.total_size = s->b->total_size;
+    probe_data.filename = reduce_filename(fname, sizeof(fname),
+                                          basename(s->b->filename));
     /* CG: should pass EditState? QEmacsState ? */
 
     m = m0 = s->mode;
@@ -5195,6 +5205,7 @@
                            int len, long total_size)
 {
     QEmacsState *qs = s->qe_state;
+    char fname[MAX_FILENAME_SIZE];
     EditBuffer *b;
     ModeDef *m, *selected_mode;
     ModeProbeData probe_data;
@@ -5209,9 +5220,11 @@
     probe_data.buf_size = len;
     p = memchr(buf, '\n', len);
     probe_data.line_len = p ? p - buf : len;
-    probe_data.filename = b->filename;
+    probe_data.real_filename = b->filename;
     probe_data.mode = mode;
     probe_data.total_size = total_size;
+    probe_data.filename = reduce_filename(fname, sizeof(fname),
+                                          basename(b->filename));
     /* CG: should pass EditState? QEmacsState ? */
 
     m = qs->first_mode;

Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -b -r1.66 -r1.67
--- qe.h        25 Mar 2008 10:13:37 -0000      1.66
+++ qe.h        26 Mar 2008 08:03:56 -0000      1.67
@@ -180,6 +180,7 @@
 const char *basename(const char *filename);
 const char *extension(const char *filename);
 char *get_dirname(char *dest, int size, const char *file);
+char *reduce_filename(char *dest, int size, const char *filename);
 int match_extension(const char *filename, const char *extlist);
 int remove_slash(char *buf);
 int append_slash(char *buf, int buf_size);
@@ -733,6 +734,7 @@
     int tab_size;
 
     EditBuffer *next; /* next editbuffer in qe_state buffer list */
+
     char name[MAX_BUFFERNAME_SIZE];     /* buffer name */
     char filename[MAX_FILENAME_SIZE];   /* file name */
 
@@ -1007,7 +1009,8 @@
 typedef struct DisplayState DisplayState;
 
 typedef struct ModeProbeData {
-    const char *filename;
+    const char *real_filename;
+    const char *filename;  /* reduced filename for mode matching purposes */
     const u8 *buf;
     int buf_size;
     int line_len;

Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- util.c      25 Mar 2008 11:05:45 -0000      1.39
+++ util.c      26 Mar 2008 08:03:56 -0000      1.40
@@ -277,7 +277,7 @@
     if (base) {
         for (p = base; *p; p++) {
 #ifdef WIN32
-            /* Simplitic DOS filename support */
+            /* Simplistic DOS filename support */
             if (*p == '/' || *p == '\\' || *p == ':')
                 base = p + 1;
 #else
@@ -300,11 +300,9 @@
         while (*p == '.')
             p++;
         for (; *p; p++) {
-            if (*p == '.') {
-                if (!ext || !qe_isdigit(p[1]))
+            if (*p == '.')
                     ext = p;
             }
-        }
         if (!ext)
             ext = p;
     }
@@ -336,22 +334,57 @@
     return dest;
 }
 
+char *reduce_filename(char *dest, int size, const char *filename)
+{
+    const char *base = basename(filename);
+    char *dbase, *ext, *p;
+
+    /* Copy path unchanged */
+    pstrncpy(dest, size, filename, base - filename);
+
+    /* Strip cvs temp file prefix */
+    if (base[0] == '.' && base[1] == '#' && base[2] != '\0')
+        base += 2;
+    
+    pstrcat(dest, size, base);
+
+    dbase = dest + (basename(dest) - dest);
+
+    /* Strip numeric extensions (vcs version numbers) */
+    for (;;) {
+        ext = dbase + (extension(dbase) - dbase);
+        if (*ext != '.' || !qe_isdigit(ext[1]))
+            break;
+        *ext = '\0';
+    }
+    
+    if (*ext == '.') {
+        /* Convert all upper case filenames with extension to lower
+         * case */
+        for (p = dbase; *p; p++) {
+            if (qe_islower(*p))
+                break;
+        }
+        if (!*p) {
+            qe_strtolower(dbase, dest + size - dbase, dbase);
+        }
+    }
+
+    /* Strip backup file suffix */
+    p = dbase + strlen(dbase);
+    if (p > dbase + 1 && p[-1] == '~')
+        *--p = '\0';
+
+    return dest;
+}
+
 int match_extension(const char *filename, const char *extlist)
 {
     const char *r;
 
     r = extension(filename);
     if (*r == '.') {
-        char buf[32];
-        char *p;
-
-        /* Match extensions in lowercase, strip extra extensions.
-         * thus ignoring cvs version tags (as in .#cutils.c.1.13)
-         */
-        qe_strtolower(buf, sizeof(buf), r + 1);
-        if ((p = strchr(buf, '.')) != NULL)
-            *p = '\0';
-        return strfind(extlist, buf);
+        return strfind(extlist, r + 1);
     } else {
         return 0;
     }




reply via email to

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