qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs cptoqe.c cutils.c cutils.h jistoqe.c lat...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs cptoqe.c cutils.c cutils.h jistoqe.c lat...
Date: Tue, 22 Apr 2008 08:11:57 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        08/04/22 08:11:56

Modified files:
        .              : cptoqe.c cutils.c cutils.h jistoqe.c 
                         latex-mode.c qe.h util.c 

Log message:
        moved get_basename, get_extension, and get_dirname to cutils.h/c
        added wrappers for get_basename_nc and get_basename_offset
        added wrappers for get_extension_nc and get_extension_offset
        added strip_extension
        use these where appropriate
        remove duplicate definitions in stand-alone utilities

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/cptoqe.c?cvsroot=qemacs&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.h?cvsroot=qemacs&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/qemacs/jistoqe.c?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.87&r2=1.88
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.49&r2=1.50

Patches:
Index: cptoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cptoqe.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- cptoqe.c    20 Apr 2008 14:18:18 -0000      1.12
+++ cptoqe.c    22 Apr 2008 08:11:55 -0000      1.13
@@ -33,32 +33,6 @@
                      module_init + sizeof(module_init) - module_init_p, \
                      "%s", s))
 
-static char *get_basename(const char *pathname)
-{
-    const char *base = pathname;
-
-    while (*pathname) {
-        if (*pathname++ == '/')
-            base = pathname;
-    }
-    return (char *)base;
-}
-
-static char *get_extension(const char *pathname)
-{
-    const char *p, *ext;
-
-    for (ext = p = pathname + strlen(pathname); p > pathname; p--) {
-        if (p[-1] == '/')
-            break;
-        if (*p == '.') {
-            ext = p;
-            break;
-        }
-    }
-    return (char *)ext;
-}
-
 static inline char *skipspaces(char *p) {
     while (isspace((unsigned char)*p))
         p++;
@@ -136,7 +110,7 @@
             continue;
         if (!memcmp(p, "include ", 8)) {
             pstrcpy(includename, sizeof(includename), filename);
-            base = get_basename(includename) - includename;
+            base = get_basename_offset(includename);
             pstrcpy(includename + base, sizeof(includename) - base,
                     skipspaces(p + 8));
             f = fopen(includename, "r");
@@ -353,7 +327,7 @@
         }
 
         pstrcpy(name, sizeof(name), get_basename(filename));
-        *get_extension(name) = '\0';
+        strip_extension(name);
         for (p = name; *p; p++) {
             if (*p == '_')
                 *p = '-';

Index: cutils.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- cutils.c    8 Jan 2008 16:37:54 -0000       1.14
+++ cutils.c    22 Apr 2008 08:11:55 -0000      1.15
@@ -21,6 +21,7 @@
 
 #include <string.h>
 
+#include "config.h"     /* for CONFIG_WIN32 */
 #include "cutils.h"
 
 /* these functions are duplicated from ffmpeg/libavformat/cutils.c
@@ -110,3 +111,70 @@
     }
     return buf;
 }
+
+/* Get the filename portion of a path */
+const char *get_basename(const char *filename)
+{
+    const char *p;
+    const char *base;
+
+    base = filename;
+    if (base) {
+        for (p = base; *p; p++) {
+#ifdef CONFIG_WIN32
+            /* Simplistic DOS/Windows filename support */
+            if (*p == '/' || *p == '\\' || (*p == ':' && p == filename + 1))
+                base = p + 1;
+#else
+            if (*p == '/')
+                base = p + 1;
+#endif
+        }
+    }
+    return base;
+}
+
+/* Return the last extension in a path, ignoring leading dots */
+const char *get_extension(const char *filename)
+{
+    const char *p, *ext;
+
+    p = get_basename(filename);
+    ext = NULL;
+    if (p) {
+        while (*p == '.')
+            p++;
+        for (; *p; p++) {
+            if (*p == '.')
+                ext = p;
+        }
+        if (!ext)
+            ext = p;
+    }
+    return ext;
+}
+
+/* Extract the directory portion of a path:
+ * This leaves out the trailing slash if any.  The complete path is
+ * obtained by catenating dirname + '/' + basename.
+ * if the original path doesn't contain anything dirname is just "."
+ */
+char *get_dirname(char *dest, int size, const char *file)
+{
+    char *p;
+
+    if (dest) {
+        p = dest;
+        if (file) {
+            pstrcpy(dest, size, file);
+            p = get_basename_nc(dest);
+            if (p > dest + 1 && p[-1] != ':' && p[-2] != ':')
+                p--;
+
+            if (p == dest)
+                *p++ = '.';
+        }
+        *p = '\0';
+    }
+    return dest;
+}

Index: cutils.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- cutils.h    8 Jan 2008 16:37:54 -0000       1.12
+++ cutils.h    22 Apr 2008 08:11:56 -0000      1.13
@@ -34,6 +34,24 @@
 void pstrcpy(char *buf, int buf_size, const char *str);
 char *pstrcat(char *buf, int buf_size, const char *s);
 char *pstrncpy(char *buf, int buf_size, const char *s, int len);
+const char *get_basename(const char *filename);
+static inline char *get_basename_nc(char *filename) {
+    return (char *)get_basename(filename);
+}
+static inline int get_basename_offset(const char *filename) {
+    return get_basename(filename) - filename;
+}
+const char *get_extension(const char *filename);
+static inline char *get_extension_nc(char *filename) {
+    return (char *)get_extension(filename);
+}
+static inline int get_extension_offset(const char *filename) {
+    return get_extension(filename) - filename;
+}
+static inline void strip_extension(char *filename) {
+    filename[get_extension(filename) - filename] = '\0';
+}
+char *get_dirname(char *dest, int size, const char *file);
 
 /* Double linked lists. Same API as the linux kernel */
 

Index: jistoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/jistoqe.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- jistoqe.c   20 Apr 2008 14:18:18 -0000      1.3
+++ jistoqe.c   22 Apr 2008 08:11:56 -0000      1.4
@@ -25,32 +25,6 @@
 
 #include "cutils.h"
 
-static char *get_basename(const char *pathname)
-{
-    const char *base = pathname;
-
-    while (*pathname) {
-        if (*pathname++ == '/')
-            base = pathname;
-    }
-    return (char *)base;
-}
-
-static char *get_extension(const char *pathname)
-{
-    const char *p, *ext;
-
-    for (ext = p = pathname + strlen(pathname); p > pathname; p--) {
-        if (p[-1] == '/')
-            break;
-        if (*p == '.') {
-            ext = p;
-            break;
-        }
-    }
-    return (char *)ext;
-}
-
 static char *getline(char *buf, int buf_size, FILE *f, int strip_comments)
 {
     for (;;) {
@@ -190,7 +164,7 @@
         filename = argv[i];
 
         pstrcpy(name, sizeof(name), get_basename(filename));
-        *get_extension(name) = '\0';
+        strip_extension(name);
 
         f = fopen(filename, "r");
         if (!f) {

Index: latex-mode.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- latex-mode.c        9 Apr 2008 16:15:45 -0000       1.28
+++ latex-mode.c        22 Apr 2008 08:11:56 -0000      1.29
@@ -282,13 +282,11 @@
 {
     char bname[MAX_FILENAME_SIZE];
     char buf[1024];
-    int len;
     struct latex_function *func;
 
     /* strip extension from filename */
     pstrcpy(bname, sizeof(bname), e->b->filename);
-    len = get_extension(bname) - bname;
-    bname[len] = '\0';
+    strip_extension(bname);
 
     if (!cmd || cmd[0] == '\0')
         cmd = "LaTeX";

Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -b -r1.87 -r1.88
--- qe.h        20 Apr 2008 12:01:34 -0000      1.87
+++ qe.h        22 Apr 2008 08:11:56 -0000      1.88
@@ -187,9 +187,6 @@
 int is_directory(const char *path);
 void canonicalize_path(char *buf, int buf_size, const char *path);
 void canonicalize_absolute_path(char *buf, int buf_size, const char *path1);
-const char *get_basename(const char *filename);
-const char *get_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);

Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- util.c      20 Apr 2008 11:51:58 -0000      1.49
+++ util.c      22 Apr 2008 08:11:56 -0000      1.50
@@ -276,73 +276,6 @@
     canonicalize_path(buf, buf_size, path1);
 }
 
-/* Get the filename portion of a path */
-const char *get_basename(const char *filename)
-{
-    const char *p;
-    const char *base;
-
-    base = filename;
-    if (base) {
-        for (p = base; *p; p++) {
-#ifdef CONFIG_WIN32
-            /* Simplistic DOS filename support */
-            if (*p == '/' || *p == '\\' || *p == ':')
-                base = p + 1;
-#else
-            if (*p == '/')
-                base = p + 1;
-#endif
-        }
-    }
-    return base;
-}
-
-/* Return the last extension in a path, ignoring leading dots */
-const char *get_extension(const char *filename)
-{
-    const char *p, *ext;
-
-    p = get_basename(filename);
-    ext = NULL;
-    if (p) {
-        while (*p == '.')
-            p++;
-        for (; *p; p++) {
-            if (*p == '.')
-                ext = p;
-        }
-        if (!ext)
-            ext = p;
-    }
-    return ext;
-}
-
-/* Extract the directory portion of a path:
- * This leaves out the trailing slash if any.  The complete path is
- * obtained by catenating dirname + '/' + basename.
- * if the original path doesn't contain anything dirname is just "."
- */
-char *get_dirname(char *dest, int size, const char *file)
-{
-    char *p;
-
-    if (dest) {
-        p = dest;
-        if (file) {
-            pstrcpy(dest, size, file);
-            p = dest + (get_basename(dest) - dest);
-            if (p > dest + 1 && p[-1] != ':' && p[-2] != ':')
-                p--;
-
-            if (p == dest)
-                *p++ = '.';
-        }
-        *p = '\0';
-    }
-    return dest;
-}
-
 char *reduce_filename(char *dest, int size, const char *filename)
 {
     const char *base = get_basename(filename);
@@ -357,11 +290,11 @@
     
     pstrcat(dest, size, base);
 
-    dbase = dest + (get_basename(dest) - dest);
+    dbase = get_basename_nc(dest);
 
     /* Strip numeric extensions (vcs version numbers) */
     for (;;) {
-        ext = dbase + (get_extension(dbase) - dbase);
+        ext = get_extension_nc(dbase);
         if (*ext != '.' || !qe_isdigit(ext[1]))
             break;
         *ext = '\0';




reply via email to

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