Mercurial > hg > xemacs-beta
view src/gif_io.c @ 800:a5954632b187
[xemacs-hg @ 2002-03-31 08:27:14 by ben]
more fixes, first crack at finishing behavior implementation
TODO.ben-mule-21-5: Update.
configure.in: Fix for new error-checking types.
make-mswin-unicode.pl: Don't be fucked up by CRLF. Output code
to force errors when nonintercepted Windows calls issued.
behavior.el, dumped-lisp.el, menubar-items.el: Add support for saving using custom. Load into a dumped XEmacs.
Correct :title to :short-doc in accordance with behavior-defs.el.
Add a submenu under Options for turning on/off behaviors.
cl-macs.el: Properly document `loop'. Fix a minor bug in keymap iteration and
add support for bit-vector iteration.
lisp-mode.el: Rearrange and add items for macro expanding.
menubar-items.el: Document connection between these two functions.
window.el: Port stuff from GNU 21.1.
config.inc.samp, xemacs.mak: Separate out and add new variable for controlling error-checking.
s/windowsnt.h: Use new ERROR_CHECK_ALL; not related to DEBUG_XEMACS.
alloc.c, backtrace.h, buffer.c, buffer.h, bytecode.c, callproc.c, casetab.c, charset.h, chartab.c, cmdloop.c, config.h.in, console-msw.c, console-stream.c, console-tty.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dired-msw.c, dired.c, dumper.c, editfns.c, eldap.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, file-coding.h, fileio.c, frame-msw.c, frame.c, frame.h, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, insdel.c, intl-auto-encap-win32.c, intl-auto-encap-win32.h, intl-encap-win32.c, intl-win32.c, keymap.c, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-x.c, menubar.c, mule-coding.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, opaque.c, print.c, process-nt.c, process-unix.c, process.c, rangetab.c, redisplay-msw.c, redisplay-output.c, redisplay.c, regex.c, scrollbar-msw.c, select-msw.c, signal.c, specifier.c, specifier.h, symbols.c, sysdep.c, syswindows.h, text.c, text.h, toolbar-msw.c, tooltalk.c, ui-gtk.c, unicode.c, window.c: Redo error-checking macros: ERROR_CHECK_TYPECHECK ->
ERROR_CHECK_TYPES, ERROR_CHECK_CHARBPOS -> ERROR_CHECK_TEXT, add
ERROR_CHECK_DISPLAY, ERROR_CHECK_STRUCTURES. Document these in
config.h.in. Fix code to follow docs. Fix *_checking_assert()
in accordance with new names.
Attempt to fix periodic redisplay crash freeing display line
structures. Add first implementation of sledgehammer redisplay
check.
Redo print_*() to use write_fmt_string(), write_fmt_string_lisp().
Fix bug in md5 handling.
Rename character-to-unicode to char-to-unicode; same for
unicode-to-char{acter}.
Move chartab documentation to `make-char-table'.
Some header cleanup.
Clean up remaining places where nonintercepted Windows calls are
being used.
automated/mule-tests.el: Fix for new Unicode support.
author | ben |
---|---|
date | Sun, 31 Mar 2002 08:30:17 +0000 |
parents | 943eaba38521 |
children | 61855263cb07 |
line wrap: on
line source
#include <config.h> #include "lisp.h" #include "sysfile.h" #include "gifrlib.h" /****************************************************************************** * Set up the GifFileType structure for use. This must be called first in any * * client program. Then, if custom IO or Error functions are desired, call * * GifSetIOFunc/GifSetErrorFunc, then call EGifInitWrite. Else call * * EGifOpenFileName or EGifOpenFileHandle for standard IO functions. * * If setup fails, a NULL pointer is returned. * ******************************************************************************/ GifFileType *GifSetup(void) { GifIODataType *GifIO; GifFileType *GifFile; if ((GifFile = (GifFileType *) malloc(sizeof(GifFileType))) == NULL) return NULL; memset(GifFile, '\0', sizeof(GifFileType)); if ((GifIO = (GifIODataType *) malloc(sizeof(GifIODataType))) == NULL) { free((char *) GifFile); return NULL; } memset(GifIO, '\0', sizeof(GifIODataType)); GifFile->GifIO = GifIO; return GifFile; } void GifFree(GifFileType *GifFile) { GifFilePrivateType *Private; if (GifFile == NULL) return; Private = (GifFilePrivateType *) GifFile->Private; if (GifFile->SavedImages) FreeSavedImages(GifFile); if (GifFile->Image.ColorMap) FreeMapObject(GifFile->Image.ColorMap); if (GifFile->SColorMap) FreeMapObject(GifFile->SColorMap); if (Private) { free(Private); } if (GifFile->GifIO) free(GifFile->GifIO); free(GifFile); } /**************************************************************************** * Install the specified ReadFunction into the GifFile specified. * ****************************************************************************/ void GifSetReadFunc(GifFileType *GifFile, Gif_rw_func ReadFunc, VoidPtr data) { GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; GifIO->ReadFunc = ReadFunc; GifIO->ReadFunc_data = data; } /**************************************************************************** * Install the specified WriteFunction into the GifFile specified. * ****************************************************************************/ void GifSetWriteFunc(GifFileType *GifFile, Gif_rw_func WriteFunc, VoidPtr data) { GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; GifIO->WriteFunc = WriteFunc; GifIO->WriteFunc_data = data; } /**************************************************************************** * Install the specified CloseFunction into the GifFile specified. * ****************************************************************************/ void GifSetCloseFunc(GifFileType *GifFile, Gif_close_func CloseFunc, VoidPtr data) { GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; GifIO->CloseFunc = CloseFunc; GifIO->CloseFunc_data = data; } /**************************************************************************** * Install the standard IO funcs into the GifFile, including the FILE info * ****************************************************************************/ void GifStdIOInit(GifFileType *GifFile, FILE *file, int filehandle) { GifStdIODataType *IOData; if ((IOData = (GifStdIODataType*)malloc(sizeof(GifStdIODataType))) == NULL) GifInternError(GifFile, GIF_ERR_NOT_ENOUGH_MEM); IOData->File = file; IOData->FileHandle = filehandle; GifSetReadFunc(GifFile, GifStdRead, IOData); GifSetWriteFunc(GifFile, GifStdWrite, IOData); GifSetCloseFunc(GifFile, GifStdFileClose, IOData); } Bytecount GifStdRead(GifByteType *buf, Bytecount size, VoidPtr method_data) { GifStdIODataType *IOtype = (GifStdIODataType*)method_data; return (retry_fread(buf, 1, size, IOtype->File)); } Bytecount GifStdWrite(GifByteType *buf, Bytecount size, VoidPtr method_data) { GifStdIODataType *IOtype = (GifStdIODataType*)method_data; return (retry_fwrite(buf, 1, size, IOtype->File)); } int GifStdFileClose(VoidPtr method_data) { int ret; GifStdIODataType *IOtype = (GifStdIODataType*)method_data; ret = retry_fclose(IOtype->File); if (ret == 0 && IOtype->FileHandle != -1) ret = retry_close(IOtype->FileHandle); return ret; } void GifRead(GifByteType *buf, Bytecount size, GifFileType *GifFile) { GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; if ((*(GifIO->ReadFunc))(buf, size, GifIO->ReadFunc_data) != size) GifError(GifFile, "Read error!"); } void GifWrite(GifByteType *buf, Bytecount size, GifFileType *GifFile) { GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; if ((*(GifIO->WriteFunc))(buf, size, GifIO->WriteFunc_data) != size) GifError(GifFile, "Write error!"); } int GifClose(GifFileType *GifFile) { GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; return ((*(GifIO->CloseFunc))(GifIO->CloseFunc_data)); } static char *GifErrorString[14] = { "Failed to open given file", /* D_GIF_ERR_OPEN_FAILED */ "Failed to read from given file", /* D_GIF_ERR_READ_FAILED */ "Given file is NOT a GIF file", /* D_GIF_ERR_NOT_GIF_FILE */ "No Screen Descriptor detected", /* D_GIF_ERR_NO_SCRN_DSCR */ "No Image Descriptor detected", /* D_GIF_ERR_NO_IMAG_DSCR */ "No global or local color map", /* D_GIF_ERR_NO_COLOR_MAP */ "Wrong record type detected", /* D_GIF_ERR_WRONG_RECORD */ "#Pixels bigger than Width * Height", /* D_GIF_ERR_DATA_TOO_BIG */ "Fail to allocate required memory", /* D_GIF_ERR_NOT_ENOUGH_MEM */ "Failed to close given file", /* D_GIF_ERR_CLOSE_FAILED */ "Given file was not opened for read", /* D_GIF_ERR_CLOSE_FAILED */ "Image is defective, decoding aborted", /* D_GIF_ERR_IMAGE_DEFECT */ "Image EOF detected before image complete", /* D_GIF_ERR_EOF_TOO_SOON */ "Undefined error!", }; const char *GetGifError(int errore); /***************************************************************************** * Get the last GIF error in human-readable form. * *****************************************************************************/ const char *GetGifError(int errore) { char *Err; switch(errore) { case D_GIF_ERR_OPEN_FAILED: Err = GifErrorString[0]; break; case D_GIF_ERR_READ_FAILED: Err = GifErrorString[1]; break; case D_GIF_ERR_NOT_GIF_FILE: Err = GifErrorString[2]; break; case D_GIF_ERR_NO_SCRN_DSCR: Err = GifErrorString[3]; break; case D_GIF_ERR_NO_IMAG_DSCR: Err = GifErrorString[4]; break; case D_GIF_ERR_NO_COLOR_MAP: Err = GifErrorString[5]; break; case D_GIF_ERR_WRONG_RECORD: Err = GifErrorString[6]; break; case D_GIF_ERR_DATA_TOO_BIG: Err = GifErrorString[7]; break; case D_GIF_ERR_NOT_ENOUGH_MEM: Err = GifErrorString[8]; break; case D_GIF_ERR_CLOSE_FAILED: Err = GifErrorString[9]; break; case D_GIF_ERR_NOT_READABLE: Err = GifErrorString[10]; break; case D_GIF_ERR_IMAGE_DEFECT: Err = GifErrorString[11]; break; case D_GIF_ERR_EOF_TOO_SOON: Err = GifErrorString[12]; break; default: Err = GifErrorString[13]; break; } return Err; } /****************************** * These are called internally * ******************************/ void GifError(GifFileType *GifFile, const char *err_str) { GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; if (GifIO->ErrorFunc) (*(GifIO->ErrorFunc))(err_str, GifIO->ErrorFunc_data); else fprintf(stderr, "GIF FATAL ERROR: %s", err_str); exit(-10); } void GifWarning(GifFileType *GifFile, const char *err_str) { GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO; if (GifIO->WarningFunc) (*(GifIO->WarningFunc))(err_str, GifIO->WarningFunc_data); } void GifInternError(GifFileType *GifFile, int error_num) { const char *ErrStr = GetGifError(error_num); GifError(GifFile, ErrStr); } void GifInternWarning(GifFileType *GifFile, int error_num) { const char *ErrStr = GetGifError(error_num); GifWarning(GifFile, ErrStr); } void GifSetErrorFunc(GifFileType *GifFile, Gif_error_func ErrorFunc, VoidPtr data) { GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; GifIO->ErrorFunc = ErrorFunc; GifIO->ErrorFunc_data = data; } void GifSetWarningFunc(GifFileType *GifFile, Gif_error_func WarningFunc, VoidPtr data) { GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO; GifIO->WarningFunc = WarningFunc; GifIO->WarningFunc_data = data; }