Mercurial > hg > xemacs-beta
view src/glyphs-shared.c @ 5634:2014ff433daf
Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion
src/ChangeLog addition:
2012-01-01 Aidan Kehoe <kehoea@parhasard.net>
Add #'test-completion, API from GNU.
Accept hash table COLLECTIONs in it and in the other
completion-oriented functions, #'try-completion,
#'all-completions, and those Lisp functions implemented in terms
of them.
* lisp.h: Update the prototype of map_obarray(), making FN
compatible with the FUNCTION argument of elisp_maphash();
* abbrev.c (abbrev_match_mapper):
* abbrev.c (record_symbol):
* doc.c (verify_doc_mapper):
* symbols.c (mapatoms_1):
* symbols.c (apropos_mapper):
Update these mapper functions to reflect the new argument to
map_obarray().
* symbols.c (map_obarray):
Call FN with two arguments, the string name of the symbol, and the
symbol itself, for API (mapper) compatibility with
elisp_maphash().
* minibuf.c (map_completion): New. Map a maphash_function_t across
a non function COLLECTION, as appropriate for #'try-completion and
friends.
* minibuf.c (map_completion_list): New. Map a maphash_function_t
across a pseudo-alist, as appropriate for the completion
functions.
* minibuf.c (ignore_completion_p): PRED needs to be called with
two args if and only if the collection is a hash table. Implement
this.
* minibuf.c (try_completion_mapper): New. The loop body of
#'try-completion, refactored out.
* minibuf.c (Ftry_completion): Use try_completion_mapper(),
map_completion().
* minibuf.c (all_completions_mapper): New. The loop body of
#'all-completions, refactored out.
* minibuf.c (Fall_completions): Use all_completions_mapper(),
map_completion().
* minibuf.c (test_completion_mapper): New. The loop body of
#'test-completion.
* minibuf.c (Ftest_completion): New, API from GNU.
* minibuf.c (syms_of_minibuf): Make Ftest_completion available.
tests/ChangeLog addition:
2012-01-01 Aidan Kehoe <kehoea@parhasard.net>
* automated/completion-tests.el: New.
Test #'try-completion, #'all-completion and #'test-completion with
list, vector and hash-table COLLECTION arguments.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 01 Jan 2012 15:18:52 +0000 |
parents | 308d34e9f07d |
children |
line wrap: on
line source
/* Routines shared between window-system backends for glyph objects. Copyright (C) 1993, 1994 Free Software Foundation, Inc. Copyright (C) 1995 Board of Trustees, University of Illinois Copyright (C) 1995 Tinker Systems Copyright (C) 1995, 1996, 2001 Ben Wing Copyright (C) 1995 Sun Microsystems Copyright (C) 1998, 1999, 2000 Andy Piper This file is part of XEmacs. XEmacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. XEmacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ /* Synched up with: Not in FSF. */ /* taken from glyphs-*.c HINT HINT HINT Bill Perry: Please put code here and avoid massive duplication in *-gtk.c!!! */ #include <config.h> #include "lisp.h" #include "buffer.h" #include "elhash.h" #include "faces.h" #include "frame.h" #include "glyphs.h" #include "imgproc.h" #include "insdel.h" #include "lstream.h" #include "opaque.h" #include "sysdep.h" #include "window.h" #include "sysfile.h" Lisp_Object Q_resource_type, Q_resource_id; void shared_resource_validate (Lisp_Object instantiator) { if ((NILP (find_keyword_in_vector (instantiator, Q_file)) && NILP (find_keyword_in_vector (instantiator, Q_resource_id))) || NILP (find_keyword_in_vector (instantiator, Q_resource_type))) sferror ("Must supply :file, :resource-id and :resource-type", instantiator); } Lisp_Object shared_resource_normalize (Lisp_Object inst, Lisp_Object console_type, Lisp_Object UNUSED (dest_mask), Lisp_Object tag) { /* This function can call lisp */ Lisp_Object file = Qnil; struct gcpro gcpro1, gcpro2; Lisp_Object alist = Qnil; GCPRO2 (file, alist); file = potential_pixmap_file_instantiator (inst, Q_file, Q_data, console_type); if (NILP (file)) /* normalization impossible for the console type */ RETURN_UNGCPRO (Qnil); if (CONSP (file)) /* failure locating filename */ signal_double_image_error ("Opening pixmap file", "no such file or directory", Fcar (file)); if (EQ (file, Qt)) /* no conversion necessary */ RETURN_UNGCPRO (inst); alist = tagged_vector_to_alist (inst); { alist = remassq_no_quit (Q_file, alist); alist = Fcons (Fcons (Q_file, file), alist); } { Lisp_Object result = alist_to_tagged_vector (tag, alist); free_alist (alist); RETURN_UNGCPRO (result); } } /* Originally from xmu.c, but is now shared across X11, GTK, and MSW. */ /* * Based on an optimized version provided by Jim Becker, August 5, 1988. */ #ifndef BitmapSuccess #define BitmapSuccess 0 #define BitmapOpenFailed 1 #define BitmapFileInvalid 2 #define BitmapNoMemory 3 #endif #define MAX_SIZE 255 /* shared data for the image read/parse logic */ static short hexTable[256]; /* conversion value */ static int hex_initialized; /* easier to fill in at run time */ /* * Table index for the hex values. Initialized once, first time. * Used for translation value or delimiter significance lookup. */ static void initHexTable (void) { /* * We build the table at run time for several reasons: * * 1. portable to non-ASCII machines. * 2. still reentrant since we set the init flag after setting table. * 3. easier to extend. * 4. less prone to bugs. */ hexTable['0'] = 0; hexTable['1'] = 1; hexTable['2'] = 2; hexTable['3'] = 3; hexTable['4'] = 4; hexTable['5'] = 5; hexTable['6'] = 6; hexTable['7'] = 7; hexTable['8'] = 8; hexTable['9'] = 9; hexTable['A'] = 10; hexTable['B'] = 11; hexTable['C'] = 12; hexTable['D'] = 13; hexTable['E'] = 14; hexTable['F'] = 15; hexTable['a'] = 10; hexTable['b'] = 11; hexTable['c'] = 12; hexTable['d'] = 13; hexTable['e'] = 14; hexTable['f'] = 15; /* delimiters of significance are flagged w/ negative value */ hexTable[' '] = -1; hexTable[','] = -1; hexTable['}'] = -1; hexTable['\n'] = -1; hexTable['\t'] = -1; hex_initialized = 1; } /* * read next hex value in the input stream, return -1 if EOF */ static int NextInt (FILE *fstream) { int ch; int value = 0; int gotone = 0; int done = 0; /* loop, accumulate hex value until find delimiter */ /* skip any initial delimiters found in read stream */ while (!done) { ch = getc(fstream); if (ch == EOF) { value = -1; done++; } else { /* trim high bits, check type and accumulate */ ch &= 0xff; if (isascii(ch) && isxdigit(ch)) { value = (value << 4) + hexTable[ch]; gotone++; } else if ((hexTable[ch]) < 0 && gotone) done++; } } return value; } /* * The data returned by the following routine is always in left-most byte * first and left-most bit first. If it doesn't return BitmapSuccess then * its arguments won't have been touched. This routine should look as much * like the Xlib routine XReadBitmapfile as possible. */ static int read_bitmap_data (FILE *fstream, int *width, int *height, Binbyte **datap, int *x_hot, int *y_hot) { Binbyte *data = NULL; /* working variable */ Ascbyte line[MAX_SIZE]; /* input line from file */ int size; /* number of bytes of data */ Ascbyte name_and_type[MAX_SIZE]; /* an input line */ Ascbyte *type; /* for parsing */ int value; /* from an input line */ int version10p; /* boolean, old format */ int padding; /* to handle alignment */ int bytes_per_line; /* per scanline of data */ int ww = 0; /* width */ int hh = 0; /* height */ int hx = -1; /* x hotspot */ int hy = -1; /* y hotspot */ #ifndef Xmalloc #define Xmalloc(size) malloc(size) #endif /* first time initialization */ if (!hex_initialized) initHexTable(); /* error cleanup and return macro */ #define RETURN(code) { if (data) free (data); return code; } while (fgets(line, MAX_SIZE, fstream)) { if (strlen(line) == MAX_SIZE-1) { RETURN (BitmapFileInvalid); } if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) { if (!(type = strrchr(name_and_type, '_'))) type = name_and_type; else type++; if (!strcmp("width", type)) ww = value; if (!strcmp("height", type)) hh = value; if (!strcmp("hot", type)) { if (type-- == name_and_type || type-- == name_and_type) continue; if (!strcmp("x_hot", type)) hx = value; if (!strcmp("y_hot", type)) hy = value; } continue; } if (sscanf(line, "static short %s = {", name_and_type) == 1) version10p = 1; else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1) version10p = 0; else if (sscanf(line, "static char %s = {", name_and_type) == 1) version10p = 0; else continue; if (!(type = strrchr(name_and_type, '_'))) type = name_and_type; else type++; if (strcmp("bits[]", type)) continue; if (!ww || !hh) RETURN (BitmapFileInvalid); if ((ww % 16) && ((ww % 16) < 9) && version10p) padding = 1; else padding = 0; bytes_per_line = (ww+7)/8 + padding; size = bytes_per_line * hh; data = (Binbyte *) Xmalloc ((unsigned int) size); if (!data) RETURN (BitmapNoMemory); if (version10p) { Binbyte *ptr; int bytes; for (bytes=0, ptr=data; bytes<size; (bytes += 2)) { if ((value = NextInt(fstream)) < 0) RETURN (BitmapFileInvalid); *(ptr++) = value; if (!padding || ((bytes+2) % bytes_per_line)) *(ptr++) = value >> 8; } } else { Binbyte *ptr; int bytes; for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) { if ((value = NextInt(fstream)) < 0) RETURN (BitmapFileInvalid); *ptr=value; } } break; } /* end while */ if (data == NULL) { RETURN (BitmapFileInvalid); } *datap = data; data = NULL; *width = ww; *height = hh; if (x_hot) *x_hot = hx; if (y_hot) *y_hot = hy; RETURN (BitmapSuccess); } int read_bitmap_data_from_file (Lisp_Object filename, /* Remaining args are RETURNED */ int *width, int *height, Binbyte **datap, int *x_hot, int *y_hot) { FILE *fstream; int status; Extbyte *fileext; LISP_PATHNAME_CONVERT_OUT (filename, fileext); if ((fstream = fopen (fileext, "r")) == NULL) return BitmapOpenFailed; status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot); retry_fclose (fstream); return status; } void syms_of_glyphs_shared (void) { DEFKEYWORD (Q_resource_id); DEFKEYWORD (Q_resource_type); }