Index: src/files.c =================================================================== --- src/files.c (revision 5537) +++ src/files.c (working copy) @@ -33,6 +33,37 @@ #include #include +/* Does the given filename end in ".gz"? */ +int isgz(char *fname) +{ + char *strend; + int len; + + if (fname == NULL) + return -1; + + len = strlen(fname); + if (len < 3) + return -1; + + strend = malloc(4 * sizeof(char)); + sprintf(strend, "%c%c%c", fname[len - 3], fname[len - 2], fname[len - 1]); + + if (strcmp(strend, ".gz") == 0) { + free(strend); + + /* The filename ends in ".gz", but do we have gzip? */ + if (system("gzip --version > /dev/null 2>&1") != 0) + return -2; + + /* Use gzip to handle the file. */ + return 0; + } + + free(strend); + return -1; +} + /* Add an entry to the openfile openfilestruct. This should only be * called from open_buffer(). */ void make_new_buffer(void) @@ -956,8 +987,14 @@ beep(); return -1; } else { - /* The file is A-OK. Open it. */ - *f = fdopen(fd, "rb"); + /* The file is A-OK. Open it, via gzip or directly. */ + if (isgz(full_filename) == 0) { + char *open_cmd = (char *) nmalloc(sizeof(char) * (20 + strlen(full_filename))); + sprintf(open_cmd, "gzip -cdfq \'%s\'", full_filename); + *f = popen(open_cmd, "r"); + free(open_cmd); + } else + *f = fdopen(fd, "rb"); if (*f == NULL) { statusbar(_("Error reading %s: %s"), filename, strerror(errno)); @@ -2015,7 +2052,16 @@ goto cleanup_and_exit; } - f = fdopen(fd, (append == APPEND) ? "ab" : "wb"); + if (isgz(realname) == 0) { + char *write_cmd = (char *) nmalloc(sizeof(char) * (20 + strlen(realname))); + if (append == APPEND) + sprintf(write_cmd, "gzip -c >> \'%s\'", realname); + else + sprintf(write_cmd, "gzip -c > \'%s\'", realname); + f = popen(write_cmd, "w"); + free(write_cmd); + } else + f = fdopen(fd, (append == APPEND) ? "ab" : "wb"); if (f == NULL) { statusbar(_("Error writing %s: %s"), realname,