Changes to qemacs/latex-mode.c

Charlie Gordon <[email protected]>
Newsgroups gmane.editors.qemacs.devel
Message-ID <[email protected]>
Index: qemacs/latex-mode.c
diff -u qemacs/latex-mode.c:1.7 qemacs/latex-mode.c:1.8
--- qemacs/latex-mode.c:1.7	Sun May  8 16:37:42 2005
+++ qemacs/latex-mode.c	Mon May  9 05:58:47 2005
@@ -270,37 +270,21 @@
 
 static void do_latex(EditState *e, const char *cmd)
 {
+    char bname[MAX_FILENAME_SIZE];
     char buf[1024];
-    int i;
-    char *p, *f;
-    char *bname;
-
-    /* strip extension from filename, find the last dot after the last
-     * slash (ie, the last dot in the filename)
-     */
-    /* CG: should use extension(), also should ignore leading dots */
-    f = strrchr(e->b->filename, '/');
-    if (f)
-        f++;
-    else
-        f = e->b->filename;
-    p = strrchr(f, '.');
-    if (p) {
-        int len = p - e->b->filename;
-        bname = (char *)malloc(len + 1);
-        pstrncpy(bname, len + 1, e->b->filename, len);
-    } else {
-        bname = strdup(e->b->filename);
-    }
+    int i, len;
+
+    /* strip extension from filename */
+    pstrcpy(bname, sizeof(bname), e->b->filename);
+    len = extension(bname) - bname;
+    bname[len] = '\0';
 
     if (!cmd || cmd[0] == '\0')
-        strcpy(buf, "LaTeX");
-    else
-        strcpy(buf, cmd);
+        cmd = "LaTeX";
 
     /* check what command to run */
     for (i = 0; latex_funcs[i].name; i++) {
-        if (strcasecmp(buf, latex_funcs[i].name) == 0) {
+        if (strcasecmp(cmd, latex_funcs[i].name) == 0) {
             /* pass the EditState through to latex_cmd_run() */
             latex_funcs[i].es = e;
             /* construct the command line to run */
@@ -315,12 +299,10 @@
             } else {
                 latex_cmd_run((void *)&latex_funcs[i], buf);
             }
-            break;
+            return;
         }
     }
-    if (latex_funcs[i].name == 0)
-        put_status(e, "%s: No match", buf);
-    free(bname);
+    put_status(e, "%s: No match", buf);
 }
 
 /* specific LaTeX commands */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.