aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2013-08-11 21:43:36 +0200
committerLars Magne Ingebrigtsen2013-08-11 21:43:36 +0200
commit313546eb796f4588c1c9af60f08f2bd122ef0bdb (patch)
tree011785b2e4c70e7f0ec25e28ff752e4279f2a97d /src
parentf90e3ebd13de8169ada56274f3abaa1ea8dc6d05 (diff)
downloademacs-313546eb796f4588c1c9af60f08f2bd122ef0bdb.tar.gz
emacs-313546eb796f4588c1c9af60f08f2bd122ef0bdb.zip
Add zlib support via the `decompress-gzipped-region' function
This adds a new file, src/decompress.c, as well as tests for the presence of -lz.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/Makefile.in6
-rw-r--r--src/decompress.c139
-rw-r--r--src/emacs.c4
-rw-r--r--src/lisp.h5
5 files changed, 160 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index fce45d37447..340e8407b33 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12013-08-11 Lars Magne Ingebrigtsen <larsi@gnus.org>
2
3 * lisp.h: Include decompress.c support.
4
5 * emacs.c (main): Include decompress.c support.
6
7 * Makefile.in: Include -lz if present.
8
12013-08-11 Jan Djärv <jan.h.d@swipnet.se> 92013-08-11 Jan Djärv <jan.h.d@swipnet.se>
2 10
3 * nsmenu.m (ns_update_menubar): Call fillWithWidgetValue:frame: 11 * nsmenu.m (ns_update_menubar): Call fillWithWidgetValue:frame:
diff --git a/src/Makefile.in b/src/Makefile.in
index 65927ba236c..f0ed770ac8f 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -243,6 +243,8 @@ IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@
243LIBXML2_LIBS = @LIBXML2_LIBS@ 243LIBXML2_LIBS = @LIBXML2_LIBS@
244LIBXML2_CFLAGS = @LIBXML2_CFLAGS@ 244LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
245 245
246LIBZ = @LIBZ@
247
246XRANDR_LIBS = @XRANDR_LIBS@ 248XRANDR_LIBS = @XRANDR_LIBS@
247XRANDR_CFLAGS = @XRANDR_CFLAGS@ 249XRANDR_CFLAGS = @XRANDR_CFLAGS@
248 250
@@ -374,7 +376,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
374 process.o gnutls.o callproc.o \ 376 process.o gnutls.o callproc.o \
375 region-cache.o sound.o atimer.o \ 377 region-cache.o sound.o atimer.o \
376 doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \ 378 doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \
377 profiler.o \ 379 profiler.o decompress.o \
378 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ 380 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
379 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ) 381 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ)
380obj = $(base_obj) $(NS_OBJC_OBJ) 382obj = $(base_obj) $(NS_OBJC_OBJ)
@@ -429,7 +431,7 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
429 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ 431 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
430 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ 432 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
431 $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(LIB_PTHREAD_SIGMASK) \ 433 $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(LIB_PTHREAD_SIGMASK) \
432 $(GFILENOTIFY_LIBS) $(LIB_MATH) 434 $(GFILENOTIFY_LIBS) $(LIB_MATH) $(LIBZ)
433 435
434all: emacs$(EXEEXT) $(OTHER_FILES) 436all: emacs$(EXEEXT) $(OTHER_FILES)
435.PHONY: all 437.PHONY: all
diff --git a/src/decompress.c b/src/decompress.c
new file mode 100644
index 00000000000..18f7884a4c2
--- /dev/null
+++ b/src/decompress.c
@@ -0,0 +1,139 @@
1/* Interface to zlib.
2 Copyright (C) 2013 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <config.h>
20
21#ifdef HAVE_ZLIB
22
23#include <zlib.h>
24
25#include "lisp.h"
26#include "character.h"
27#include "buffer.h"
28
29
30#define BUFFER_SIZE 16384
31
32struct decompress_unwind_data {
33 ptrdiff_t old_point, start;
34 z_stream *stream;
35};
36
37static void
38unwind_decompress (void *ddata) {
39 struct decompress_unwind_data *data = ddata;
40 inflateEnd (data->stream);
41 /* Delete any uncompressed data already inserted and restore
42 point. */
43 if (data->start) {
44 del_range (data->start, PT);
45 SET_PT (data->old_point);
46 }
47}
48
49DEFUN ("decompress-gzipped-region", Fdecompress_gzipped_region,
50 Sdecompress_gzipped_region,
51 2, 2, 0,
52 doc: /* Decompress a gzip-compressed region.
53The text in the region will be replaced by the decompressed data.
54On failure, nil is returned and the data is left in place.
55This function can only be called in unibyte buffers.*/)
56 (Lisp_Object start, Lisp_Object end)
57{
58 ptrdiff_t istart, iend, point = PT;
59 z_stream stream;
60 int decompressed;
61 char out[16384];
62 struct decompress_unwind_data unwind_data;
63 ptrdiff_t count = SPECPDL_INDEX ();
64
65 validate_region (&start, &end);
66 move_gap_both (iend, iend);
67
68 if (! NILP (BVAR (current_buffer, enable_multibyte_characters)))
69 error ("This function can only be called in unibyte buffers");
70
71 /* This is a unibyte buffer, so character positions and bytes are
72 the same. */
73 istart = XINT (start);
74 iend = XINT (end);
75
76 stream.zalloc = Z_NULL;
77 stream.zfree = Z_NULL;
78 stream.opaque = Z_NULL;
79 stream.avail_in = 0;
80 stream.next_in = Z_NULL;
81
82 /* This magic number apparently means "this is gzip". */
83 if (inflateInit2 (&stream, 16 + MAX_WBITS) != Z_OK)
84 return Qnil;
85
86 /* We're inserting the decompressed data at the end of the
87 compressed data. */
88 SET_PT (iend);
89
90 stream.avail_in = iend - istart;
91 stream.next_in = (char *) BYTE_POS_ADDR (istart);
92
93 unwind_data.start = iend;
94 unwind_data.stream = &stream;
95 unwind_data.old_point = point;
96 record_unwind_protect_ptr (unwind_decompress, &unwind_data);
97
98 immediate_quit = 1;
99
100 /* Run inflate() on input until the output buffer isn't full. */
101 do {
102 stream.avail_out = BUFFER_SIZE;
103 stream.next_out = out;
104 switch (inflate (&stream, Z_NO_FLUSH)) {
105 case Z_STREAM_ERROR:
106 case Z_NEED_DICT:
107 case Z_DATA_ERROR:
108 case Z_MEM_ERROR:
109 unbind_to (count, Qnil);
110 return Qnil;
111 }
112
113 decompressed = BUFFER_SIZE - stream.avail_out;
114 insert_1_both (out, decompressed, decompressed, 0, 0, 0);
115 QUIT;
116 } while (stream.avail_out == 0);
117
118 immediate_quit = 0;
119
120 unwind_data.start = 0;
121 unbind_to (count, Qnil);
122
123 /* Delete the compressed data. */
124 del_range (istart, iend);
125
126 return Qt;
127}
128
129
130/***********************************************************************
131 Initialization
132 ***********************************************************************/
133void
134syms_of_decompress (void)
135{
136 defsubr (&Sdecompress_gzipped_region);
137}
138
139#endif /* HAVE_ZLIB */
diff --git a/src/emacs.c b/src/emacs.c
index 23aef6a2b65..3c80d3ed753 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1406,6 +1406,10 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1406 syms_of_xml (); 1406 syms_of_xml ();
1407#endif 1407#endif
1408 1408
1409#ifdef HAVE_ZLIB
1410 syms_of_decompress ();
1411#endif
1412
1409 syms_of_menu (); 1413 syms_of_menu ();
1410 1414
1411#ifdef HAVE_NTGUI 1415#ifdef HAVE_NTGUI
diff --git a/src/lisp.h b/src/lisp.h
index 8ca6d05a821..107150461eb 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4213,6 +4213,11 @@ extern void syms_of_xml (void);
4213extern void xml_cleanup_parser (void); 4213extern void xml_cleanup_parser (void);
4214#endif 4214#endif
4215 4215
4216#ifdef HAVE_ZLIB
4217/* Defined in decompress.c. */
4218extern void syms_of_decompress (void);
4219#endif
4220
4216#ifdef HAVE_DBUS 4221#ifdef HAVE_DBUS
4217/* Defined in dbusbind.c. */ 4222/* Defined in dbusbind.c. */
4218void syms_of_dbusbind (void); 4223void syms_of_dbusbind (void);