repv property_cache_ref (repv id, repv prop) { unsigned int h, i; if (cache_vec == rep_NULL) return rep_NULL; h = CACHE_HASH (id, prop) * CACHE_ASSOC; DB (("prop ref: 0x%x,%s (%d) -> ", id, rep_STR (rep_SYM (prop)->name), h)); for (i = h; i < h + CACHE_ASSOC; i++) { if (cache_ids[i] == id && cache_props[i] == prop) { cache_hits++; DB (("hit\n")); cache_ages[i] = ++cache_clock; return cache_values[i]; } } DB (("miss\n")); cache_misses++; return rep_NULL; }
static bool pango_load (Lisp_Font *f) { PangoLanguage *language; PangoFontDescription *fontdesc; PangoFont *font; PangoFontMetrics *metrics; if (pango_context) { language = pango_context_get_language (pango_context); } else { char *langname, *p; #ifdef HAVE_PANGO_XFT pango_context = pango_xft_get_context (dpy, screen_num); #endif langname = g_strdup (setlocale (LC_CTYPE, NULL)); p = strchr (langname, '.'); if (p) *p = 0; p = strchr (langname, '@'); if (p) *p = 0; language = pango_language_from_string (langname); pango_context_set_language (pango_context, language); g_free (langname); } fontdesc = pango_font_description_from_string (rep_STR (f->name)); if (!pango_font_description_get_family (fontdesc)) pango_font_description_set_family (fontdesc, "Sans"); if (pango_font_description_get_size (fontdesc) <= 0) pango_font_description_set_size (fontdesc, 12 * PANGO_SCALE); pango_context_set_font_description (pango_context, fontdesc); font = pango_context_load_font (pango_context, fontdesc); if (!font) { pango_font_description_free(fontdesc); return FALSE; } metrics = pango_font_get_metrics (font, language); f->ascent = metrics->ascent / PANGO_SCALE; f->descent = metrics->descent / PANGO_SCALE; pango_font_metrics_unref (metrics); f->font = fontdesc; /* We save the font description, not the font itself! That's because it seems we can't recover it perfectly later, and the layout routines want a description */ return TRUE; }
void gh_get_substr(repv src, char *dst, long start, size_t len) { if (!rep_STRING (src) || rep_STRING_LEN (src) <= start) return; len = MIN (len, rep_STRING_LEN (src) - start); memcpy (dst, rep_STR (src) + start, len); }
static char * completion_generator (char *word, int state) { if (state == 0) { repv fun = completion_fun; if (fun == Qnil) /* backwards compatibility, ugh */ fun = Fsymbol_value (Qrl_completion_generator, Qt); if (Ffunctionp (fun) != Qnil) { completions = (rep_call_with_barrier (Ffuncall, rep_list_2 (fun, rep_string_dup (word)), rep_TRUE, 0, 0, 0)); } else { repv re = Fquote_regexp (rep_string_dup (word)); repv boundp = Fsymbol_value (Qboundp, Qt); completions = Fapropos (rep_concat2("^", rep_STR(re)), boundp, Qnil); } if (completions == rep_NULL) completions = Qnil; } if (completions != Qnil && rep_CONSP(completions) && (rep_SYMBOLP(rep_CAR(completions)) || rep_STRINGP(rep_CAR(completions)))) { repv string = rep_CAR(completions); if (rep_SYMBOLP(string)) string = rep_SYM(string)->name; completions = rep_CDR(completions); return strdup (rep_STR(string)); } else return 0; }
repv sys_make_color(Lisp_Color *c) { if (gdk_color_parse (rep_STR (c->name), &c->color)) { if (gdk_colormap_alloc_color (color_map, &c->color, 0, 1)) return rep_VAL (c); else return Fsignal(Qerror, rep_list_2(rep_VAL(&no_alloc_color), c->name)); } else return Fsignal(Qerror, rep_list_2(rep_VAL(&no_parse_color), c->name)); }
void property_cache_set (repv id, repv prop, repv value, int invals) { unsigned int h, i, oldest, oldest_age; if (cache_vec == rep_NULL) { cache_vec = Fmake_vector (rep_MAKE_INT (CACHE_SIZE * 3), Qnil); rep_mark_static (&cache_vec); cache_ids = rep_VECT (cache_vec)->array; cache_props = cache_ids + CACHE_SIZE; cache_values = cache_props + CACHE_SIZE; } h = CACHE_HASH (id, prop) * CACHE_ASSOC; oldest_age = UINT_MAX; oldest = -1; for (i = h; i < h + CACHE_ASSOC; i++) { if (cache_ids[i] == id && cache_props[i] == prop) { cache_values[i] = value; cache_updates[i] += invals; return; } if (cache_ages[i] <= oldest_age) { oldest_age = cache_ages[i]; oldest = i; } } assert (oldest != -1); if (cache_ids[oldest] != 0) DB (("prop eject: 0x%x (%d)\n", cache_ids[oldest], oldest)); cache_ids[oldest] = id; cache_props[oldest] = prop; cache_values[oldest] = value; cache_ages[oldest] = ++cache_clock; cache_updates[oldest] = invals; DB (("set: 0x%x,%s (%d)\n", id, rep_STR (rep_SYM (prop)->name), oldest)); }
static bool fontstruct_load (Lisp_Font *f) { XFontStruct *font_struct; font_struct = XLoadQueryFont (dpy, rep_STR (f->name)); if (font_struct == 0) return FALSE; f->font = font_struct; f->ascent = font_struct->ascent; f->descent = font_struct->descent; return TRUE; }
static bool xft_load (Lisp_Font *f) { XftFont *xft_font; xft_font = XftFontOpenName (dpy, screen_num, rep_STR (f->name)); if (xft_font == 0) return FALSE; f->font = xft_font; f->ascent = xft_font->ascent; f->descent = xft_font->descent; return TRUE; }
static bool fontset_load (Lisp_Font *f) { XFontSet font_set; int ascent, descent; char **missing_charset_list, *def_string; int num_missing_charset_list; font_set = x_create_fontset (rep_STR (f->name), &missing_charset_list, &num_missing_charset_list, &def_string); if (font_set != 0) { XFontStruct **fstrs; char **font_names; int i, j, num_fonts; f->font = font_set; num_fonts = XFontsOfFontSet (font_set, &fstrs, &font_names); ascent = descent = 0; for (i = 0; i < num_fonts; i++) { if (fstrs[i]->ascent > ascent) f->ascent = fstrs[i]->ascent; if (fstrs[i]->descent > descent) f->descent = fstrs[i]->descent; } if (num_missing_charset_list > 0) { fprintf (stderr, "Missing charsets in FontSet creation\n"); for (j = 0; j < num_missing_charset_list; j++) fprintf (stderr, "\t%s\n", missing_charset_list[j]); XFreeStringList (missing_charset_list); } return TRUE; } return FALSE; }
char *gh_scm2newstr(repv str, size_t *lenp) { char *buf; size_t len; if (!rep_STRINGP (str)) return NULL; len = rep_STRING_LEN (str); buf = malloc (len + 1); memcpy (buf, rep_STR (str), len); buf[len] = 0; if (lenp != NULL) *lenp = len; return buf; }
static void make_argv (repv list, int *argc, char ***argv) { int c = rep_INT (Flength (list)), i; char **v; v = (char **)rep_alloc ((c+1) * sizeof(char**)); for (i = 0; i < c; i++, list = rep_CDR (list)) { if (!rep_STRINGP (rep_CAR (list))) { rep_free ((char *)v); return; } v[i] = strdup (rep_STR (rep_CAR (list))); } v[c] = NULL; *argv = v; *argc = c; }
/* Scan the command line for options. */ static void get_options(void) { repv opt; if (rep_get_option("--sync", 0)) opt_sync = 1; if (rep_get_option("--geometry", &opt)) geom_str = strdup (rep_STR(opt)); if (rep_get_option("--fg", &opt)) default_fg_color = strdup (rep_STR(opt)); if (rep_get_option("--bg", &opt)) default_bg_color = strdup (rep_STR(opt)); if (rep_get_option("--bl", &opt)) default_block_color = strdup (rep_STR(opt)); if (rep_get_option("--hl", &opt)) default_hl_color = strdup (rep_STR(opt)); if (rep_get_option("--ml", &opt)) default_ml_color = strdup (rep_STR(opt)); if (rep_get_option("--font", &opt)) def_font_str = opt; }
static char * rep_ffi_marshal (unsigned int type_id, repv value, char *ptr) { rep_ffi_type *type = ffi_types[type_id]; switch (type->subtype) { DEFSTRING (err, "unknown ffi type id"); DEFSTRING (err2, "ffi struct expected a vector or list"); case rep_FFI_PRIMITIVE: switch (type->type->type) { case FFI_TYPE_VOID: return ptr; case FFI_TYPE_INT: *(int *)ptr = (int) rep_get_long_int (value); return ptr + sizeof (int); case FFI_TYPE_FLOAT: *(float *)ptr = (float) rep_get_float (value); return ptr + sizeof (float); case FFI_TYPE_DOUBLE: *(double *)ptr = (double) rep_get_float (value); return ptr + sizeof (double); #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE case FFI_TYPE_LONGDOUBLE: *(long double *)ptr = (long double) rep_get_float (value); return ptr + sizeof (long double); #endif case FFI_TYPE_UINT8: *(uint8_t *)ptr = (uint8_t) rep_get_long_int (value); return ptr + sizeof (uint8_t); case FFI_TYPE_SINT8: *(int8_t *)ptr = (int8_t) rep_get_long_int (value); return ptr + sizeof (int8_t); case FFI_TYPE_UINT16: *(uint16_t *)ptr = (uint16_t) rep_get_long_int (value); return ptr + sizeof (uint16_t); case FFI_TYPE_SINT16: *(int16_t *)ptr = (int16_t) rep_get_long_int (value); return ptr + sizeof (int16_t); case FFI_TYPE_UINT32: *(uint32_t *)ptr = (uint32_t) rep_get_long_int (value); return ptr + sizeof (uint32_t); case FFI_TYPE_SINT32: *(int32_t *)ptr = (int32_t) rep_get_long_int (value); return ptr + sizeof (int32_t); case FFI_TYPE_UINT64: *(uint64_t *)ptr = (uint64_t) rep_get_longlong_int (value); return ptr + sizeof (uint64_t); case FFI_TYPE_SINT64: *(int64_t *)ptr = (int64_t) rep_get_longlong_int (value); return ptr + sizeof (int64_t); case FFI_TYPE_POINTER: *(void **)ptr = (rep_STRINGP(value)) ? rep_STR (value) : rep_get_pointer (value); return ptr + sizeof (void *); case FFI_TYPE_STRUCT: /* FIXME: */ default: Fsignal (Qerror, rep_list_2 (rep_VAL (&err), rep_MAKE_INT (type_id))); return NULL; } /* not reached */ case rep_FFI_STRUCT: { rep_ffi_struct *s = (rep_ffi_struct *) type; rep_GC_root gc_value; int i; rep_PUSHGC (gc_value, value); for (i = 0; i < s->n_elements; i++) { repv elt; if (rep_VECTORP (value)) elt = rep_VECTI (value, i); else if (rep_CONSP (value)) { elt = rep_CAR (value); value = rep_CDR (value); } else { rep_POPGC; Fsignal (Qerror, rep_list_2 (rep_VAL (&err2), value)); return NULL; } ptr = rep_ffi_marshal (s->element_ids[i], elt, ptr); if (ptr == NULL) { rep_POPGC; return NULL; } } rep_POPGC; return ptr; } case rep_FFI_ALIAS: { rep_ffi_alias *s = (rep_ffi_alias *) type; if (s->conv_in != rep_NULL) { value = rep_call_lisp1 (s->conv_in, value); if (value == rep_NULL) return NULL; } return rep_ffi_marshal (s->base, value, ptr); } default: Fsignal (Qerror, rep_list_2 (rep_VAL (&err), rep_MAKE_INT (type_id))); return NULL; } }
if(rl_point > -1) { rl_redisplay(); select(1, &readset, NULL, NULL, &timeout); } rl_point = tmp; } return 0; } #endif DEFUN("readline", Freadline, Sreadline, (repv prompt_, repv completer), rep_Subr2) { char *prompt = rep_STRINGP(prompt_) ? ((char *) rep_STR(prompt_)) : "> "; #ifdef HAVE_LIBREADLINE char *input; repv ret = Qnil, saved; rep_GC_root gc_saved; saved = completion_fun; completion_fun = completer; rep_PUSHGC (gc_saved, saved); input = readline (prompt); rep_POPGC; completion_fun = saved; if (input) { int len = strlen (input);