Mercurial > hg > xemacs-beta
annotate src/gif_io.c @ 4539:061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
lib-src/ChangeLog addition:
2008-12-27 Aidan Kehoe <kehoea@parhasard.net>
* make-docfile.c (main): Allow more than one -d argument, followed
by a directory to change to.
(put_filename): Don't strip directory information; with previous
change, allows retrieval of Lisp function and variable origin
files from #'built-in-symbol-file relative to lisp-directory.
(scan_lisp_file): Don't add an extraneous newline after the file
name, put_filename has added the newline already.
lisp/ChangeLog addition:
2008-12-27 Aidan Kehoe <kehoea@parhasard.net>
* loadup.el (load-history):
Add the contents of current-load-list to load-history before
clearing it. Move the variable declarations earlier in the file to
a format understood by make-docfile.c.
* custom.el (custom-declare-variable): Add the variable's symbol
to the current file's load history entry correctly, don't use a
cons. Eliminate a comment that we don't need to worry about, we
don't need to check the `initialized' C variable in Lisp.
* bytecomp.el (byte-compile-output-file-form):
Merge Andreas Schwab's pre-GPLv3 GNU change of 19970831 here;
treat #'custom-declare-variable correctly, generating the
docstrings in a format understood by make-docfile.c.
* loadhist.el (symbol-file): Correct behaviour for checking
autoloaded macros and functions when supplied with a TYPE
argument. Accept fully-qualified paths from
#'built-in-symbol-file; if a path is not fully-qualified, return
it relative to lisp-directory if the filename corresponds to a
Lisp file, and relative to (concat source-directory "/src/")
otherwise.
* make-docfile.el (preloaded-file-list):
Rationalise some let bindings a little. Use the "-d" argument to
make-docfile.c to supply Lisp paths relative to lisp-directory,
not absolutely. Add in loadup.el explicitly to the list of files
to be processed by make-docfile.c--it doesn't make sense to add it
to preloaded-file-list, since that is used for purposes of
byte-compilation too.
src/ChangeLog addition:
2008-12-27 Aidan Kehoe <kehoea@parhasard.net>
* doc.c (Fbuilt_in_symbol_file):
Return a subr's filename immediately if we've found it. Check for
compiled function and compiled macro docstrings in DOC too, and
return them if they exist.
The branch of the if statement focused on functions may have
executed, but we may still want to check variable bindings; an
else clause isn't appropriate.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 27 Dec 2008 14:05:50 +0000 |
parents | 726060ee587c |
children |
rev | line source |
---|---|
442 | 1 #include <config.h> |
647 | 2 #include "lisp.h" |
442 | 3 |
647 | 4 #include "sysfile.h" |
5 | |
428 | 6 #include "gifrlib.h" |
7 | |
8 /****************************************************************************** | |
9 * Set up the GifFileType structure for use. This must be called first in any * | |
10 * client program. Then, if custom IO or Error functions are desired, call * | |
11 * GifSetIOFunc/GifSetErrorFunc, then call EGifInitWrite. Else call * | |
12 * EGifOpenFileName or EGifOpenFileHandle for standard IO functions. * | |
13 * If setup fails, a NULL pointer is returned. * | |
14 ******************************************************************************/ | |
15 GifFileType *GifSetup(void) | |
16 { | |
17 GifIODataType *GifIO; | |
18 GifFileType *GifFile; | |
19 | |
20 if ((GifFile = (GifFileType *) malloc(sizeof(GifFileType))) == NULL) | |
21 return NULL; | |
22 memset(GifFile, '\0', sizeof(GifFileType)); | |
23 if ((GifIO = (GifIODataType *) malloc(sizeof(GifIODataType))) == NULL) { | |
24 free((char *) GifFile); | |
25 return NULL; | |
26 } | |
27 memset(GifIO, '\0', sizeof(GifIODataType)); | |
28 GifFile->GifIO = GifIO; | |
29 return GifFile; | |
30 } | |
31 | |
32 void GifFree(GifFileType *GifFile) | |
33 { | |
34 GifFilePrivateType *Private; | |
35 | |
36 if (GifFile == NULL) return; | |
37 | |
38 Private = (GifFilePrivateType *) GifFile->Private; | |
39 | |
40 if (GifFile->SavedImages) | |
41 FreeSavedImages(GifFile); | |
42 if (GifFile->Image.ColorMap) | |
43 FreeMapObject(GifFile->Image.ColorMap); | |
44 if (GifFile->SColorMap) | |
45 FreeMapObject(GifFile->SColorMap); | |
46 if (Private) | |
47 { | |
48 free(Private); | |
49 } | |
50 if (GifFile->GifIO) | |
51 free(GifFile->GifIO); | |
52 free(GifFile); | |
53 } | |
54 | |
55 /**************************************************************************** | |
56 * Install the specified ReadFunction into the GifFile specified. * | |
57 ****************************************************************************/ | |
58 void GifSetReadFunc(GifFileType *GifFile, Gif_rw_func ReadFunc, VoidPtr data) | |
59 { | |
60 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; | |
61 GifIO->ReadFunc = ReadFunc; | |
62 GifIO->ReadFunc_data = data; | |
63 } | |
64 | |
65 /**************************************************************************** | |
66 * Install the specified WriteFunction into the GifFile specified. * | |
67 ****************************************************************************/ | |
68 void GifSetWriteFunc(GifFileType *GifFile, Gif_rw_func WriteFunc, VoidPtr data) | |
69 { | |
70 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; | |
71 GifIO->WriteFunc = WriteFunc; | |
72 GifIO->WriteFunc_data = data; | |
73 } | |
74 | |
75 /**************************************************************************** | |
76 * Install the specified CloseFunction into the GifFile specified. * | |
77 ****************************************************************************/ | |
78 void GifSetCloseFunc(GifFileType *GifFile, Gif_close_func CloseFunc, VoidPtr data) | |
79 { | |
80 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; | |
81 GifIO->CloseFunc = CloseFunc; | |
82 GifIO->CloseFunc_data = data; | |
83 } | |
84 | |
85 /**************************************************************************** | |
86 * Install the standard IO funcs into the GifFile, including the FILE info * | |
87 ****************************************************************************/ | |
88 void GifStdIOInit(GifFileType *GifFile, FILE *file, int filehandle) | |
89 { | |
90 GifStdIODataType *IOData; | |
91 | |
92 if ((IOData = (GifStdIODataType*)malloc(sizeof(GifStdIODataType))) == NULL) | |
93 GifInternError(GifFile, GIF_ERR_NOT_ENOUGH_MEM); | |
94 IOData->File = file; | |
95 IOData->FileHandle = filehandle; | |
96 GifSetReadFunc(GifFile, GifStdRead, IOData); | |
97 GifSetWriteFunc(GifFile, GifStdWrite, IOData); | |
98 GifSetCloseFunc(GifFile, GifStdFileClose, IOData); | |
99 } | |
100 | |
665 | 101 Bytecount GifStdRead(GifByteType *buf, Bytecount size, VoidPtr method_data) |
428 | 102 { |
103 GifStdIODataType *IOtype = (GifStdIODataType*)method_data; | |
771 | 104 return (retry_fread(buf, 1, size, IOtype->File)); |
428 | 105 } |
106 | |
665 | 107 Bytecount GifStdWrite(GifByteType *buf, Bytecount size, VoidPtr method_data) |
428 | 108 { |
109 GifStdIODataType *IOtype = (GifStdIODataType*)method_data; | |
771 | 110 return (retry_fwrite(buf, 1, size, IOtype->File)); |
428 | 111 } |
112 | |
113 int GifStdFileClose(VoidPtr method_data) | |
114 { | |
115 int ret; | |
116 GifStdIODataType *IOtype = (GifStdIODataType*)method_data; | |
771 | 117 ret = retry_fclose(IOtype->File); |
428 | 118 if (ret == 0 && IOtype->FileHandle != -1) |
771 | 119 ret = retry_close(IOtype->FileHandle); |
428 | 120 return ret; |
121 } | |
122 | |
665 | 123 void GifRead(GifByteType *buf, Bytecount size, GifFileType *GifFile) |
428 | 124 { |
125 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; | |
126 if ((*(GifIO->ReadFunc))(buf, size, GifIO->ReadFunc_data) != size) | |
127 GifError(GifFile, "Read error!"); | |
128 } | |
129 | |
665 | 130 void GifWrite(GifByteType *buf, Bytecount size, GifFileType *GifFile) |
428 | 131 { |
132 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; | |
133 if ((*(GifIO->WriteFunc))(buf, size, GifIO->WriteFunc_data) != size) | |
134 GifError(GifFile, "Write error!"); | |
135 } | |
136 | |
137 int GifClose(GifFileType *GifFile) | |
138 { | |
139 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; | |
140 return ((*(GifIO->CloseFunc))(GifIO->CloseFunc_data)); | |
141 } | |
142 | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
143 static const char *GifErrorString[14] = { |
428 | 144 "Failed to open given file", /* D_GIF_ERR_OPEN_FAILED */ |
145 "Failed to read from given file", /* D_GIF_ERR_READ_FAILED */ | |
146 "Given file is NOT a GIF file", /* D_GIF_ERR_NOT_GIF_FILE */ | |
147 "No Screen Descriptor detected", /* D_GIF_ERR_NO_SCRN_DSCR */ | |
148 "No Image Descriptor detected", /* D_GIF_ERR_NO_IMAG_DSCR */ | |
149 "No global or local color map", /* D_GIF_ERR_NO_COLOR_MAP */ | |
150 "Wrong record type detected", /* D_GIF_ERR_WRONG_RECORD */ | |
151 "#Pixels bigger than Width * Height", /* D_GIF_ERR_DATA_TOO_BIG */ | |
152 "Fail to allocate required memory", /* D_GIF_ERR_NOT_ENOUGH_MEM */ | |
153 "Failed to close given file", /* D_GIF_ERR_CLOSE_FAILED */ | |
154 "Given file was not opened for read", /* D_GIF_ERR_CLOSE_FAILED */ | |
155 "Image is defective, decoding aborted", /* D_GIF_ERR_IMAGE_DEFECT */ | |
156 "Image EOF detected before image complete", /* D_GIF_ERR_EOF_TOO_SOON */ | |
157 "Undefined error!", | |
158 }; | |
159 | |
771 | 160 const char *GetGifError(int errore); |
428 | 161 |
162 /***************************************************************************** | |
163 * Get the last GIF error in human-readable form. * | |
164 *****************************************************************************/ | |
771 | 165 const char *GetGifError(int errore) |
428 | 166 { |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
167 const char *Err; |
428 | 168 |
771 | 169 switch(errore) { |
428 | 170 case D_GIF_ERR_OPEN_FAILED: |
171 Err = GifErrorString[0]; | |
172 break; | |
173 case D_GIF_ERR_READ_FAILED: | |
174 Err = GifErrorString[1]; | |
175 break; | |
176 case D_GIF_ERR_NOT_GIF_FILE: | |
177 Err = GifErrorString[2]; | |
178 break; | |
179 case D_GIF_ERR_NO_SCRN_DSCR: | |
180 Err = GifErrorString[3]; | |
181 break; | |
182 case D_GIF_ERR_NO_IMAG_DSCR: | |
183 Err = GifErrorString[4]; | |
184 break; | |
185 case D_GIF_ERR_NO_COLOR_MAP: | |
186 Err = GifErrorString[5]; | |
187 break; | |
188 case D_GIF_ERR_WRONG_RECORD: | |
189 Err = GifErrorString[6]; | |
190 break; | |
191 case D_GIF_ERR_DATA_TOO_BIG: | |
192 Err = GifErrorString[7]; | |
193 break; | |
194 case D_GIF_ERR_NOT_ENOUGH_MEM: | |
195 Err = GifErrorString[8]; | |
196 break; | |
197 case D_GIF_ERR_CLOSE_FAILED: | |
198 Err = GifErrorString[9]; | |
199 break; | |
200 case D_GIF_ERR_NOT_READABLE: | |
201 Err = GifErrorString[10]; | |
202 break; | |
203 case D_GIF_ERR_IMAGE_DEFECT: | |
204 Err = GifErrorString[11]; | |
205 break; | |
206 case D_GIF_ERR_EOF_TOO_SOON: | |
207 Err = GifErrorString[12]; | |
208 break; | |
209 default: | |
210 Err = GifErrorString[13]; | |
211 break; | |
212 } | |
213 return Err; | |
214 } | |
215 | |
216 /****************************** | |
217 * These are called internally * | |
218 ******************************/ | |
2268 | 219 DOESNT_RETURN GifError(GifFileType *GifFile, const char *err_str) |
428 | 220 { |
221 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; | |
222 if (GifIO->ErrorFunc) | |
223 (*(GifIO->ErrorFunc))(err_str, GifIO->ErrorFunc_data); | |
224 else | |
225 fprintf(stderr, "GIF FATAL ERROR: %s", err_str); | |
226 exit(-10); | |
227 } | |
228 | |
229 void GifWarning(GifFileType *GifFile, const char *err_str) | |
230 { | |
231 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; | |
232 if (GifIO->WarningFunc) | |
233 (*(GifIO->WarningFunc))(err_str, GifIO->WarningFunc_data); | |
234 } | |
235 | |
2268 | 236 DOESNT_RETURN GifInternError(GifFileType *GifFile, int error_num) |
428 | 237 { |
238 const char *ErrStr = GetGifError(error_num); | |
239 GifError(GifFile, ErrStr); | |
240 } | |
241 | |
242 void GifInternWarning(GifFileType *GifFile, int error_num) | |
243 { | |
244 const char *ErrStr = GetGifError(error_num); | |
245 GifWarning(GifFile, ErrStr); | |
246 } | |
247 | |
248 void GifSetErrorFunc(GifFileType *GifFile, Gif_error_func ErrorFunc, VoidPtr data) | |
249 { | |
250 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; | |
251 GifIO->ErrorFunc = ErrorFunc; | |
252 GifIO->ErrorFunc_data = data; | |
253 } | |
254 | |
255 void GifSetWarningFunc(GifFileType *GifFile, Gif_error_func WarningFunc, VoidPtr data) | |
256 { | |
257 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; | |
258 GifIO->WarningFunc = WarningFunc; | |
259 GifIO->WarningFunc_data = data; | |
260 } |