qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs archive.c qe.c qe.h shell.c tty.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs archive.c qe.c qe.h shell.c tty.c
Date: Wed, 19 Mar 2014 19:42:31 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/03/19 19:42:31

Modified files:
        .              : archive.c qe.c qe.h shell.c tty.c 

Log message:
        add support for web protocols: ftp, http, https
        
        * add wget-mode to retrieve web contents via find-file
        * add shell flags for buffer mode change upon download completion
        * fix do_electric_filename to keep http:// prefix and such

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/archive.c?cvsroot=qemacs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.159&r2=1.160
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.153&r2=1.154
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.88&r2=1.89
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.58&r2=1.59

Patches:
Index: archive.c
===================================================================
RCS file: /sources/qemacs/qemacs/archive.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- archive.c   10 Mar 2014 01:51:11 -0000      1.2
+++ archive.c   19 Mar 2014 19:42:30 -0000      1.3
@@ -47,7 +47,7 @@
 
 /* Compressors */
 typedef struct CompressType {
-    const char *name;           /* name of archive format */
+    const char *name;           /* name of compressed format */
     const char *extensions;
     const char *load_cmd;       /* uncompress file to stdout */
     const char *save_cmd;       /* compress to file from stdin */
@@ -86,8 +86,15 @@
 {
     ArchiveType *atp = find_archive_type(p->filename);
 
-    if (atp)
+    if (atp) {
+        if (p->b && p->b->priv_data) {
+            /* buffer loaded, re-selecting mode causes buffer reload */
+            return 9;
+        } else {
+            /* buffer not yet loaded */
         return 70;
+        }
+    }
 
     return 0;
 }
@@ -117,7 +124,7 @@
                   atp->name, b->filename);
         snprintf(cmd, sizeof(cmd), atp->list_cmd, b->filename);
         new_shell_buffer(b, get_basename(b->filename), NULL, cmd,
-                         SF_INFINITE);
+                         SF_INFINITE | SF_BUFED_MODE);
 
         /* XXX: should check for archiver error */
         /* XXX: should delay BF_SAVELOG until buffer is fully loaded */
@@ -154,7 +161,7 @@
 {
     int i;
 
-    /* archive mode is almost like the text mode, so we copy and patch it */
+    /* copy and patch text_mode */
     memcpy(&archive_mode, &text_mode, sizeof(ModeDef));
     archive_mode.name = "archive";
     archive_mode.mode_probe = archive_mode_probe;
@@ -193,8 +200,15 @@
 {
     CompressType *ctp = find_compress_type(p->filename);
 
-    if (ctp)
+    if (ctp) {
+        if (p->b && p->b->priv_data) {
+            /* buffer loaded, re-selecting mode causes buffer reload */
+            return 9;
+        } else {
+            /* buffer not yet loaded */
         return 60;
+        }
+    }
 
     return 0;
 }
@@ -213,7 +227,7 @@
 
 static int compress_buffer_load(EditBuffer *b, FILE *f)
 {
-    /* Launch subprocess to list compress contents */
+    /* Launch subprocess to expand compressed contents */
     char cmd[1024];
     CompressType *ctp;
 
@@ -222,7 +236,7 @@
         eb_clear(b);
         snprintf(cmd, sizeof(cmd), ctp->load_cmd, b->filename);
         new_shell_buffer(b, get_basename(b->filename), NULL, cmd,
-                         SF_INFINITE);
+                         SF_INFINITE | SF_AUTO_CODING | SF_AUTO_MODE);
         /* XXX: should check for archiver error */
         /* XXX: should delay BF_SAVELOG until buffer is fully loaded */
         b->flags |= BF_READONLY;
@@ -258,7 +272,7 @@
 {
     int i;
 
-    /* compress mode is almost like the text mode, so we copy and patch it */
+    /* copy and patch text_mode */
     memcpy(&compress_mode, &text_mode, sizeof(ModeDef));
     compress_mode.name = "compress";
     compress_mode.mode_probe = compress_mode_probe;
@@ -277,11 +291,82 @@
     return 0;
 }
 
+/*---------------- Wget ----------------*/
+
+static ModeDef wget_mode;
+
+static int wget_mode_probe(ModeDef *mode, ModeProbeData *p)
+{
+    if (strstart(p->real_filename, "http:", NULL)
+    ||  strstart(p->real_filename, "https:", NULL)
+    ||  strstart(p->real_filename, "ftp:", NULL)) {
+        if (p->b && p->b->priv_data) {
+            /* buffer loaded, re-selecting mode causes buffer reload */
+            return 9;
+        } else {
+            /* buffer not yet loaded */
+            return 90;
+        }
+    }
+
+    return 0;
+}
+
+static int wget_buffer_load(EditBuffer *b, FILE *f)
+{
+    /* Launch wget subprocess to retrieve contents */
+    char cmd[1024];
+
+    eb_clear(b);
+    snprintf(cmd, sizeof(cmd), "wget -q -O - %s", b->filename);
+    new_shell_buffer(b, get_basename(b->filename), NULL, cmd,
+                     SF_INFINITE | SF_AUTO_CODING | SF_AUTO_MODE);
+    /* XXX: should check for wget error */
+    /* XXX: should delay BF_SAVELOG until buffer is fully loaded */
+    b->flags |= BF_READONLY;
+
+    return 0;
+}
+
+static int wget_buffer_save(EditBuffer *b, int start, int end,
+                               const char *filename)
+{
+    /* XXX: should put contents back to web server */
+    return -1;
+}
+
+static void wget_buffer_close(EditBuffer *b)
+{
+    /* XXX: kill process? */
+}
+
+static EditBufferDataType wget_data_type = {
+    "wget",
+    wget_buffer_load,
+    wget_buffer_save,
+    wget_buffer_close,
+    NULL, /* next */
+};
+
+static int wget_init(void)
+{
+    /* copy and patch text_mode */
+    memcpy(&wget_mode, &text_mode, sizeof(ModeDef));
+    wget_mode.name = "wget";
+    wget_mode.mode_probe = wget_mode_probe;
+    wget_mode.data_type = &wget_data_type;
+
+    eb_register_data_type(&wget_data_type);
+    qe_register_mode(&wget_mode);
+
+    return 0;
+}
+
 /*---------------- Initialization ----------------*/
 
 static int archive_compress_init(void)
 {
-    return archive_init() || compress_init();
+    return archive_init() || compress_init() || wget_init();
 }
 
 qe_module_init(archive_compress_init);

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.159
retrieving revision 1.160
diff -u -b -r1.159 -r1.160
--- qe.c        18 Mar 2014 08:20:06 -0000      1.159
+++ qe.c        19 Mar 2014 19:42:30 -0000      1.160
@@ -1686,7 +1686,7 @@
     if (b->filename[0] == '\0')
         return 0;
 
-    if (!f1) {
+    if (!f1 && b->data_type == &raw_data_type) {
         struct stat st;
 
         if (stat(b->filename, &st) < 0 || !S_ISREG(st.st_mode))
@@ -5089,14 +5089,33 @@
     complete_end(&cs);
 }
 
+static int eb_match_string_reverse(EditBuffer *b, int offset, const char *str,
+                                   int *offsetp)
+{
+    int len = strlen(str);
+
+    while (len > 0) {
+        if (offset <= 0 || eb_prevc(b, offset, &offset) != str[--len])
+            return 0;
+    }
+    *offsetp = offset;
+    return 1;
+}
+
 void do_electric_filename(EditState *s, int key)
 {
-    int c, offset;
+    int c, offset, stop;
 
     if (completion_function == file_completion) {
+        stop = s->offset;
         c = eb_prevc(s->b, s->offset, &offset);
-        if (c == '/')
-            eb_delete(s->b, 0, s->offset);
+        if (c == '/') {
+            if (eb_match_string_reverse(s->b, offset, "http:", &stop)
+            ||  eb_match_string_reverse(s->b, offset, "https:", &stop)
+            ||  eb_match_string_reverse(s->b, offset, "ftp:", &stop))
+                ;
+            eb_delete(s->b, 0, stop);
+        }
     }
     do_char(s, key, 1);
 }
@@ -5793,12 +5812,12 @@
 
     /* First we try to read the first block to determine the data type */
     if (stat(filename, &st) < 0) {
-        /* XXX: default charset should be selectable.  Use utf8 for now */
+        /* XXX: default charset should be selectable.  Should have auto
+         * charset transparent support for both utf8 and latin1.
+         * Use utf8 for now */
         eb_set_charset(b, &charset_utf8, b->eol_type);
         /* XXX: dired_mode_probe will check for wildcards in real_filename */
-        put_status(s, "(New file)");
-        /* Try to determine the desired mode based on the filename.
-         * This avoids having to set c-mode for each new .c or .h file. */
+        /* Try to determine the desired mode based on the filename. */
         b->st_mode = st_mode = S_IFREG;
         buf[0] = '\0';
         buf_size = 0;
@@ -5811,6 +5830,8 @@
          */
         b->default_mode = selected_mode;
         switch_to_buffer(s, b);
+        if (b->data_type == &raw_data_type)
+            put_status(s, "(New file)");
         do_load_qerc(s, s->b->filename);
         return;
     } else {
@@ -5818,7 +5839,6 @@
         buf_size = 0;
         f = NULL;
 
-        /* CG: should check for ISDIR and do dired */
         if (S_ISREG(st_mode)) {
             f = fopen(filename, "r");
             if (!f)

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -b -r1.153 -r1.154
--- qe.h        18 Mar 2014 08:20:05 -0000      1.153
+++ qe.h        19 Mar 2014 19:42:31 -0000      1.154
@@ -1695,6 +1695,7 @@
 void edit_invalidate(EditState *s);
 void display_mode_line(EditState *s);
 void edit_set_mode(EditState *s, ModeDef *m);
+void do_set_next_mode(EditState *s, int dir);
 
 /* loading files */
 void do_exit_qemacs(EditState *s, int argval);
@@ -1971,6 +1972,9 @@
 #define SF_INTERACTIVE   0x01
 #define SF_COLOR         0x02
 #define SF_INFINITE      0x04
+#define SF_AUTO_CODING   0x08
+#define SF_AUTO_MODE     0x10
+#define SF_BUFED_MODE    0x20
 EditBuffer *new_shell_buffer(EditBuffer *b0, const char *bufname,
                              const char *caption, const char *cmd,
                              int shell_flags);

Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- shell.c     15 Mar 2014 22:52:51 -0000      1.88
+++ shell.c     19 Mar 2014 19:42:31 -0000      1.89
@@ -1367,6 +1367,10 @@
     for (e = qs->first_window; e != NULL; e = e->next_window) {
         if (e->b == b)
             e->interactive = 0;
+        if (s->shell_flags & SF_AUTO_CODING)
+            do_set_auto_coding(e, 0);
+        if (s->shell_flags & SF_AUTO_MODE)
+            do_set_next_mode(e, 0);
     }
     if (!(s->shell_flags & SF_INTERACTIVE)) {
         shell_close(b);
@@ -1935,9 +1939,11 @@
 {
     if (p->b && p->b->priv_data) {
         ShellState *s = p->b->priv_data;
-        if (s->signature == &shell_signature)
+        if (s->signature == &shell_signature) {
+            if (s->shell_flags & SF_INTERACTIVE)
             return 100;
     }
+    }
     return 0;
 }
 

Index: tty.c
===================================================================
RCS file: /sources/qemacs/qemacs/tty.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- tty.c       1 Feb 2014 12:49:06 -0000       1.58
+++ tty.c       19 Mar 2014 19:42:31 -0000      1.59
@@ -251,7 +251,7 @@
            s->height, 1);
 #else
     /* go to last line and clear it */
-    TTY_FPRINTF(s->STDOUT, "\033[%d;%dH\033[m\033[K", s->height, 1);
+    TTY_FPRINTF(s->STDOUT, "\033[%d;%dH" "\033[m\033[K", s->height, 1);
     TTY_FPRINTF(s->STDOUT,
                 "\033[?1049l"        /* exit_ca_mode */
                 "\r"                 /* return */
@@ -1291,7 +1291,8 @@
 
     TTY_FPUTS("\033[0m", s->STDOUT);
     if (ts->cursor_y + 1 >= 0 && ts->cursor_x + 1 >= 0) {
-        TTY_FPRINTF(s->STDOUT, "\033[%d;%dH", ts->cursor_y + 1, ts->cursor_x + 
1);
+        TTY_FPRINTF(s->STDOUT, "\033[%d;%dH",
+                    ts->cursor_y + 1, ts->cursor_x + 1);
     }
     fflush(s->STDOUT);
 }



reply via email to

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