Mercurial > hg > xemacs-beta
view src/gif_io.c @ 844:047d37eb70d7
[xemacs-hg @ 2002-05-16 13:30:23 by ben]
ui fixes for things that were bothering me
bytecode.c, editfns.c, lisp.h, lread.c: Fix save-restriction to use markers rather than pseudo-markers
(integers representing the amount of text on either side of the
region). That way, all inserts are handled correctly, not just
those inside old restriction.
Add buffer argument to save_restriction_save().
process.c: Clean up very dirty and kludgy code that outputs into a buffer --
use proper unwind protects, etc.
font-lock.c: Do save-restriction/widen around the function -- otherwise, incorrect
results will ensue when a buffer has been narrowed before a call to
e.g. `buffer-syntactic-context' -- something that happens quite often.
fileio.c: Look for a handler for make-temp-name.
window.c, winslots.h: Try to solve this annoying problem: have two frames displaying the
buffer, in different places; in one, temporarily switch away to
another buffer and then back -- and you've lost your position;
it's reset to the other one in the other frame. My current
solution involves window-level caches of buffers and points (also
a cache for window-start); when set-window-buffer is called, it
looks to see if the buffer was previously visited in the window,
and if so, uses the most recent point at that time. (It's a
marker, so it handles changes.)
#### Note: It could be argued that doing it on the frame level
would be better -- e.g. if you visit a buffer temporarily through
a grep, and then go back to that buffer, you presumably want the
grep's position rather than some previous position provided
everything was in the same frame, even though the grep was in
another window in the frame. However, doing it on the frame level
fails when you have two windows on the same frame. Perhaps we
keep both a window and a frame cache, and use the frame cache if
there are no other windows on the frame showing the buffer, else
the window's cache? This is probably something to be configurable
using a specifier. Suggestions please please please?
window.c: Clean up a bit code that deals with the annoyance of window-point
vs. point.
dialog.el: Function to ask a
multiple-choice question, automatically choosing a dialog box or
minibuffer representation as necessary. Generalized version of
yes-or-no-p, y-or-n-p.
files.el: Use get-user-response to ask "yes/no/diff" question when recovering.
"diff" means that a diff is displayed between the current file and the
autosave. (Converts/deconverts escape-quoted as necessary. No more
complaints from you, Mr. Turnbull!) One known problem: when a dialog
is used, it's modal, so you can't scroll the diff. Will fix soon.
lisp-mode.el: If we're filling a string, don't treat semicolon as a comment,
which would give very unfriendly results.
Uses `buffer-syntactic-context'.
simple.el: all changes back to the beginning. (Useful if you've saved the file
in the middle of the changes.)
simple.el: Add option kill-word-into-kill-ring, which controls whether words
deleted with kill-word, backward-kill-word, etc. are "cut" into the
kill ring, or "cleared" into nothingness. (My preference is the
latter, by far. I'd almost go so far as suggesting we make it the
default, as you can always select a word and then cut it if you want
it cut.)
menubar-items.el: Add option corresponding to kill-word-into-kill-ring.
author | ben |
---|---|
date | Thu, 16 May 2002 13:30:58 +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; }