Пример #1
0
static ad_device_data *
sound_nas_create(Lisp_Object nas_options)
{
	sound_nas_data_t *snd;
	char *server[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
	int i, server_cnt = 0;
	AuServer *aud = NULL;
	Lisp_Object opt_server = Qnil;

	/* parse options */
	opt_server = Fplist_get(nas_options, intern(":server"), Qnil);
	if (!NILP(opt_server) && !STRINGP(opt_server) && !DEVICEP(opt_server)) {
		wrong_type_argument(Qstringp, opt_server);
		return NULL;
	}

	if (NILP(opt_server))
		nas_setup_defaults(server, &server_cnt);
	else if (STRINGP(opt_server))
		server[server_cnt++] = (char*)XSTRING_DATA(opt_server);
#ifdef HAVE_X_WINDOWS
	else if (DEVICEP(opt_server) && DEVICE_X_P(XDEVICE(opt_server)))
		server[server_cnt++] =
			(char*)XSTRING_DATA(
				DEVICE_CONNECTION(XDEVICE(opt_server)));
#endif

	NAS_DEBUG("trying %d connections\n", server_cnt);
	for (i = 0; i<server_cnt; i++)
		if ((aud = nas_try_connection(server[i])))
			break;

	if (!aud) {
		NAS_DEBUG_C("cannot contact any NAS server\n");
		warn_when_safe(Qnas, Qwarning,
			       GETTEXT("No NAS servers in sight.\n"));
		return NULL; /* Could not contact NAS server */
	}


	/* -- initialise -- */
	snd = xnew_and_zero(sound_nas_data_t);
	snd->aud = aud;

	/* round up SOUND_MAX_AUDIO_FRAME_SIZE to multiple of NAS_FRAG_SIZE
	 * divide by 3 first because of 2:1 split */
	snd->proposed_buffer_size =
		(SOUND_MAX_AUDIO_FRAME_SIZE/3 + NAS_FRAG_SIZE-1)
		& ~(NAS_FRAG_SIZE-1);
	NAS_DEBUG_C("proposed buffer size: %u\n", snd->proposed_buffer_size);

	NAS_DEBUG_C("created: 0x%x\n", (unsigned int)snd);

	return snd;
}
Пример #2
0
Extbyte *add_accel_and_to_external(Lisp_Object string)
{
	int i;
	int found_accel = 0;
	Extbyte *retval;
	Bufbyte *name = XSTRING_DATA(string);

	for (i = 0; name[i]; ++i)
		if (name[i] == '%' && name[i + 1] == '_') {
			found_accel = 1;
			break;
		}

	if (found_accel)
		LISP_STRING_TO_EXTERNAL_MALLOC(string, retval, Qlwlib_encoding);
	else {
		size_t namelen = XSTRING_LENGTH(string);
		Bufbyte *chars = (Bufbyte *) alloca(namelen + 3);
		chars[0] = '%';
		chars[1] = '_';
		memcpy(chars + 2, name, namelen + 1);
		C_STRING_TO_EXTERNAL_MALLOC(chars, retval, Qlwlib_encoding);
	}

	return retval;
}
Пример #3
0
static int
gtk_initialize_color_instance (struct Lisp_Color_Instance *c, Lisp_Object name,
			       Lisp_Object device, Error_behavior errb)
{
  GdkColor color;
  int result;

  result = gtk_parse_nearest_color (XDEVICE (device), &color,
				    XSTRING_DATA   (name),
				    XSTRING_LENGTH (name),
				    errb);

  if (!result)
    return 0;

  /* Don't allocate the data until we're sure that we will succeed,
     or the finalize method may get f****d. */
  c->data = xnew (struct gtk_color_instance_data);
  if (result == 3)
    COLOR_INSTANCE_GTK_DEALLOC (c) = 0;
  else
    COLOR_INSTANCE_GTK_DEALLOC (c) = 1;
  COLOR_INSTANCE_GTK_COLOR (c) = gdk_color_copy (&color);
  return 1;
}
Пример #4
0
static void
weird_doc (Lisp_Object sym, const Ascbyte *weirdness, const Ascbyte *type,
	   int pos)
{
  if (!strcmp (weirdness, "duplicate")) return;
  message ("Note: Strange doc (%s) for %s %s @ %d",
           GETTEXT (weirdness), GETTEXT (type),
	   XSTRING_DATA (XSYMBOL (sym)->name), pos);
}
Пример #5
0
static ad_device_data *
sound_ao_create(Lisp_Object ao_options)
{
	int driver;
	ao_device *device;
	ao_option *options;
	ao_sample_format *fmt;
	/* result */
	sound_ao_data_t *aod;
	/* option keywords */
	Lisp_Object opt_driver;
	char *optext_driver = NULL;

	/* parse options */
	opt_driver = Fplist_get(ao_options, intern(":driver"), Qnil);
	if (!NILP(opt_driver) && !STRINGP(opt_driver)) {
		wrong_type_argument(Qstringp, opt_driver);
		return NULL;
	} else if (STRINGP(opt_driver))
		optext_driver = (char*)XSTRING_DATA(opt_driver);

	/* -- initialise -- */
	ao_initialize();
	fmt = xmalloc(sizeof(ao_sample_format));

	/* -- Setup for driver -- */
	if (optext_driver != NULL)
		driver = ao_driver_id(optext_driver);
	else
		driver = ao_default_driver_id();

	/* just some generics */
	fmt->channels = 2;
	fmt->rate = 44100;
	fmt->bits = 16;
	fmt->byte_format = AO_FMT_LITTLE;

	options = NULL;

	/* -- Open driver -- */
	device = ao_open_live(driver, fmt, options);
	if (device == NULL) {
		message(GETTEXT("audio-ao: Unsupported driver."));
		xfree(fmt);
		aod = NULL;
	} else {
		aod = xnew_and_zero(sound_ao_data_t);

		aod->ad = device;
		aod->options = NULL;
		aod->fmt = fmt;
		aod->driver_id = driver;
	}

	return aod;
}
Пример #6
0
static void
nas_setup_defaults(char **server, int *cnt)
{
	int i;
	Lisp_Object tmp;

	/* considering some defaults */
	NAS_DEBUG("trying to find some defaults\n");

#ifdef HAVE_X_WINDOWS
	/* check for the device connection of the currently active frame */
	tmp = Fselected_device(Qnil);
	if (DEVICEP(tmp) && DEVICE_X_P(XDEVICE(tmp)))
		server[(*cnt)++] =
			(char*)XSTRING_DATA(
				DEVICE_CONNECTION(XDEVICE(tmp)));

	/* tbd: check for conn of the initial frame */
#endif

	/* try to look for $AUDIOSERVER */
	if ((server[(*cnt)] = getenv("AUDIOSERVER"))) {
		/* only add the stuff, if not already in the try queue */
		for (i=0; i < (*cnt); i++)
			if (strcmp(server[i], server[(*cnt)]) == 0)
				break;
		if (i == (*cnt))
			(*cnt)++;
	}
	/* try to look for $DISPLAY */
	if ((server[(*cnt)] = getenv("DISPLAY"))){
		/* only add the stuff, if not already in the try queue */
		for (i=0; i < (*cnt); i++)
			if (strcmp(server[i], server[(*cnt)]) == 0)
				break;
		if (i == (*cnt))
			(*cnt)++;
	}

	/* oh, let's try localhost:0.0, if not already there of course */
	for (i=0; i < (*cnt); i++)
		if (strcmp(server[i], "localhost:0.0") == 0)
			break;
	if (i == (*cnt))
		server[(*cnt)++] = "localhost:0.0";

	/* finally we try NULL, too */
	server[(*cnt)++] = NULL;

	return;
}
Пример #7
0
static int
gtk_font_spec_matches_charset (struct device *d, Lisp_Object charset,
			       const Bufbyte *nonreloc, Lisp_Object reloc,
			       Bytecount offset, Bytecount length)
{
  if (UNBOUNDP (charset))
    return 1;
  /* Hack! Short font names don't have the registry in them,
     so we just assume the user knows what they're doing in the
     case of ASCII.  For other charsets, you gotta give the
     long form; sorry buster.
     */
  if (EQ (charset, Vcharset_ascii))
    {
      const Bufbyte *the_nonreloc = nonreloc;
      int i;
      Bytecount the_length = length;

      if (!the_nonreloc)
	the_nonreloc = XSTRING_DATA (reloc);
      fixup_internal_substring (nonreloc, reloc, offset, &the_length);
      the_nonreloc += offset;
      if (!memchr (the_nonreloc, '*', the_length))
	{
	  for (i = 0;; i++)
	    {
	      const Bufbyte *new_nonreloc = (const Bufbyte *)
		memchr (the_nonreloc, '-', the_length);
	      if (!new_nonreloc)
		break;
	      new_nonreloc++;
	      the_length -= new_nonreloc - the_nonreloc;
	      the_nonreloc = new_nonreloc;
	    }

	  /* If it has less than 5 dashes, it's a short font.
	     Of course, long fonts always have 14 dashes or so, but short
	     fonts never have more than 1 or 2 dashes, so this is some
	     sort of reasonable heuristic. */
	  if (i < 5)
	    return 1;
	}
    }

  return (fast_string_match (XCHARSET_REGISTRY (charset),
			     nonreloc, reloc, offset, length, 1,
			     ERROR_ME, 0) >= 0);
}
Пример #8
0
static void
print_console (Lisp_Object obj, Lisp_Object printcharfun,
	       int UNUSED (escapeflag))
{
  struct console *con = XCONSOLE (obj);

  if (print_readably)
    printing_unreadable_lisp_object (obj, XSTRING_DATA (con->name));

  write_fmt_string (printcharfun, "#<%s-console",
		    !CONSOLE_LIVE_P (con) ? "dead" : CONSOLE_TYPE_NAME (con));
  if (CONSOLE_LIVE_P (con) && !NILP (CONSOLE_CONNECTION (con)))
    write_fmt_string_lisp (printcharfun, " on %S", 1,
			   CONSOLE_CONNECTION (con));
  write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj));
}
Пример #9
0
static void
print_ldap(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
	char buf[32];

	Lisp_LDAP *ldap = XLDAP(obj);

	if (print_readably)
		error("printing unreadable object #<ldap %s>",
		      XSTRING_DATA(ldap->host));

	write_c_string("#<ldap ", printcharfun);
	print_internal(ldap->host, printcharfun, 1);
	if (!ldap->ld)
		write_c_string("(dead) ", printcharfun);
	write_fmt_string(printcharfun, " 0x%lx>", (long)ldap);
}
Пример #10
0
static void
print_device (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
{
  struct device *d = XDEVICE (obj);
  char buf[256];

  if (print_readably)
    error ("printing unreadable object #<device %s 0x%x>",
	   XSTRING_DATA (d->name), d->header.uid);

  sprintf (buf, "#<%s-device", !DEVICE_LIVE_P (d) ? "dead" :
	   DEVICE_TYPE_NAME (d));
  write_c_string (buf, printcharfun);
  if (DEVICE_LIVE_P (d) && !NILP (DEVICE_CONNECTION (d)))
    {
      write_c_string (" on ", printcharfun);
      print_internal (DEVICE_CONNECTION (d), printcharfun, 1);
    }
  sprintf (buf, " 0x%x>", d->header.uid);
  write_c_string (buf, printcharfun);
}
Пример #11
0
static Lisp_Object
casify_object (enum case_action flag, Lisp_Object string_or_char,
	       Lisp_Object buffer)
{
  struct buffer *buf = decode_buffer (buffer, 0);

 retry:

  if (CHAR_OR_CHAR_INTP (string_or_char))
    {
      Ichar c;
      CHECK_CHAR_COERCE_INT (string_or_char);
      c = XCHAR (string_or_char);
      if (flag == CASE_DOWN)
	{
	  c = DOWNCASE (buf, c);
	}
      else if (flag == CASE_UP)
	{
	  c = UPCASE (buf, c);
	}
      else
	{
	  c = CANONCASE (buf, c);
	}

      return make_char (c);
    }

  if (STRINGP (string_or_char))
    {
      Lisp_Object syntax_table = buf->mirror_syntax_table;
      Ibyte *storage =
	alloca_ibytes (XSTRING_LENGTH (string_or_char) * MAX_ICHAR_LEN);
      Ibyte *newp = storage;
      Ibyte *oldp = XSTRING_DATA (string_or_char);
      Ibyte *endp = oldp + XSTRING_LENGTH (string_or_char);
      int wordp = 0, wordp_prev;

      while (oldp < endp)
	{
	  Ichar c = itext_ichar (oldp);
	  switch (flag)
	    {
	    case CASE_UP:
	      c = UPCASE (buf, c);
	      break;
	    case CASE_DOWN:
	      c = DOWNCASE (buf, c);
	      break;
	    case CASE_CANONICALIZE:
	      c = CANONCASE (buf, c);
	      break;
	    case CASE_CAPITALIZE:
	    case CASE_CAPITALIZE_UP:
	      wordp_prev = wordp;
	      wordp = WORD_SYNTAX_P (syntax_table, c);
	      if (!wordp) break;
	      if (wordp_prev)
		{
		  if (flag == CASE_CAPITALIZE)
		    c = DOWNCASE (buf, c);
		}
	      else
		c = UPCASE (buf, c);
	      break;
	    }

	  newp += set_itext_ichar (newp, c);
	  INC_IBYTEPTR (oldp);
	}

      return make_string (storage, newp - storage);
    }

  string_or_char = wrong_type_argument (Qchar_or_string_p, string_or_char);
  goto retry;
}
Пример #12
0
  EXTERNAL_PROPERTY_LIST_LOOP(list, keyword, value, search_plist)
    {
      /* Host */
      if (EQ (keyword, Qhost))
        {
          CHECK_STRING (value);
          ldap_host = alloca (XSTRING_LENGTH (value) + 1);
          strcpy (ldap_host, (char *)XSTRING_DATA (value));
        }
      /* Filter */
      else if (EQ (keyword, Qfilter))
        {
          CHECK_STRING (value);
          ldap_filter = alloca (XSTRING_LENGTH (value) + 1);
          strcpy (ldap_filter, (char *)XSTRING_DATA (value));
        }
      /* Attributes */
      else if (EQ (keyword, Qattributes))
        {
          if (! NILP (value))
            {
              Lisp_Object attr_left = value;
              struct gcpro ngcpro1;

              NGCPRO1 (attr_left);
              CHECK_CONS (value);

              ldap_attributes = alloca ((XINT (Flength (value)) + 1)*sizeof (char *));

              for (i=0; !NILP (attr_left); i++) {
                CHECK_STRING (XCAR (attr_left));
                ldap_attributes[i] = alloca (XSTRING_LENGTH (XCAR (attr_left)) + 1);
                strcpy(ldap_attributes[i],
                       (char *)(XSTRING_DATA( XCAR (attr_left))));
                attr_left = XCDR (attr_left);
              }
              ldap_attributes[i] = NULL;
              NUNGCPRO;
            }
        }
      /* Attributes Only */
      else if (EQ (keyword, Qattrsonly))
        {
          CHECK_SYMBOL (value);
          ldap_attrsonly = NILP (value) ? 0 : 1;
        }
      /* Base */
      else if (EQ (keyword, Qbase))
        {
          if (!NILP (value))
            {
              CHECK_STRING (value);
              ldap_base = alloca (XSTRING_LENGTH (value) + 1);
              strcpy (ldap_base, (char *)XSTRING_DATA (value));
            }
        }
      /* Scope */
      else if (EQ (keyword, Qscope))
        {
          CHECK_SYMBOL (value);

          if (EQ (value, Qbase))
            ldap_scope = LDAP_SCOPE_BASE;
          else if (EQ (value, Qonelevel))
            ldap_scope = LDAP_SCOPE_ONELEVEL;
          else if (EQ (value, Qsubtree))
            ldap_scope = LDAP_SCOPE_SUBTREE;
          else
            signal_simple_error ("Invalid scope", value);
        }
      /* Authentication method */
      else if (EQ (keyword, Qauth))
        {
          CHECK_SYMBOL (value);

          if (EQ (value, Qsimple))
            ldap_auth = LDAP_AUTH_SIMPLE;
#ifdef LDAP_AUTH_KRBV41
          else if (EQ (value, Qkrbv41))
            ldap_auth = LDAP_AUTH_KRBV41;
#endif
#ifdef LDAP_AUTH_KRBV42
          else if (EQ (value, Qkrbv42))
            ldap_auth = LDAP_AUTH_KRBV42;
#endif
          else
            signal_simple_error ("Invalid authentication method", value);
        }
      /* Bind DN */
      else if (EQ (keyword, Qbinddn))
        {
          if (!NILP (value))
            {
              CHECK_STRING (value);
              ldap_binddn = alloca (XSTRING_LENGTH (value) + 1);
              strcpy (ldap_binddn, (char *)XSTRING_DATA (value));
            }
        }
      /* Password */
      else if (EQ (keyword, Qpasswd))
        {
          if (!NILP (value))
            {
              CHECK_STRING (value);
              ldap_passwd = alloca (XSTRING_LENGTH (value) + 1);
              strcpy (ldap_passwd, (char *)XSTRING_DATA (value));
            }
        }
      /* Deref */
      else if (EQ (keyword, Qderef))
        {
          CHECK_SYMBOL (value);
          if (EQ (value, Qnever))
            ldap_deref = LDAP_DEREF_NEVER;
          else if (EQ (value, Qsearch))
            ldap_deref = LDAP_DEREF_SEARCHING;
          else if (EQ (value, Qfind))
            ldap_deref = LDAP_DEREF_FINDING;
          else if (EQ (value, Qalways))
            ldap_deref = LDAP_DEREF_ALWAYS;
          else
            signal_simple_error ("Invalid deref value", value);
        }
      /* Timelimit */
      else if (EQ (keyword, Qtimelimit))
        {
          if (!NILP (value))
            {
              CHECK_INT (value);
              ldap_timelimit = XINT (value);
            }
        }
      /* Sizelimit */
      else if (EQ (keyword, Qsizelimit))
        {
          if (!NILP (value))
            {
              CHECK_INT (value);
              ldap_sizelimit = XINT (value);
            }
        }
    }
Пример #13
0
static Lisp_Object
casify_object(enum case_action flag, Lisp_Object string_or_char,
	      Lisp_Object buffer)
{
	struct buffer *buf = decode_buffer(buffer, 0);

      retry:

	if (CHAR_OR_CHAR_INTP(string_or_char)) {
		Emchar c;
		CHECK_CHAR_COERCE_INT(string_or_char);
		c = XCHAR(string_or_char);
		c = (flag == CASE_DOWN) ? DOWNCASE(buf, c) : UPCASE(buf, c);
		return make_char(c);
	}

	if (STRINGP(string_or_char)) {
		Lisp_Char_Table *syntax_table =
		    XCHAR_TABLE(buf->mirror_syntax_table);
		Bufbyte *storage =
		    alloca_array(Bufbyte,
				 XSTRING_LENGTH(string_or_char) *
				 MAX_EMCHAR_LEN);
		Bufbyte *newp = storage;
		Bufbyte *oldp = XSTRING_DATA(string_or_char);
		int wordp = 0, wordp_prev;

		while (*oldp) {
			Emchar c = charptr_emchar(oldp);
			switch (flag) {
			case CASE_UP:
				c = UPCASE(buf, c);
				break;
			case CASE_DOWN:
				c = DOWNCASE(buf, c);
				break;
			case CASE_CAPITALIZE:
			case CASE_CAPITALIZE_UP:
				wordp_prev = wordp;
				wordp = WORD_SYNTAX_P(syntax_table, c);
				if (!wordp)
					break;
				if (wordp_prev) {
					if (flag == CASE_CAPITALIZE)
						c = DOWNCASE(buf, c);
				} else
					c = UPCASE(buf, c);
				break;

				/* can't happen */
			default:
				/* abort()? */
				break;
			}

			newp += set_charptr_emchar(newp, c);
			INC_CHARPTR(oldp);
		}

		return make_string(storage, newp - storage);
	}

	string_or_char = wrong_type_argument(Qchar_or_string_p, string_or_char);
	goto retry;
}
Пример #14
0
static Lisp_Object
get_object_file_name (Lisp_Object filepos)
{
  REGISTER int fd;
  REGISTER Ibyte *name_nonreloc = 0;
  EMACS_INT position;
  Lisp_Object file, tem;
  Lisp_Object name_reloc = Qnil;
  int standard_doc_file = 0;

  if (FIXNUMP (filepos))
    {
      file = Vinternal_doc_file_name;
      standard_doc_file = 1;
      position = XFIXNUM (filepos);
    }
  else if (CONSP (filepos) && FIXNUMP (XCDR (filepos)))
    {
      file = XCAR (filepos);
      position = XFIXNUM (XCDR (filepos));
      if (position < 0)
	position = - position;
    }
  else
    return Qnil;

  if (!STRINGP (file))
    return Qnil;

  /* Put the file name in NAME as a C string.
     If it is relative, combine it with Vdoc_directory.  */

  tem = Ffile_name_absolute_p (file);
  if (NILP (tem))
    {
      Bytecount minsize;
      /* XEmacs: Move this check here.  OK if called during loadup to
	 load byte code instructions. */
      if (!STRINGP (Vdoc_directory))
	return Qnil;

      minsize = XSTRING_LENGTH (Vdoc_directory);
      /* sizeof ("../lib-src/") == 12 */
      if (minsize < 12)
	minsize = 12;
      name_nonreloc = alloca_ibytes (minsize + XSTRING_LENGTH (file) + 8);
      string_join (name_nonreloc, Vdoc_directory, file);
    }
  else
    name_reloc = file;

  fd = qxe_open (name_nonreloc ? name_nonreloc :
		 XSTRING_DATA (name_reloc), O_RDONLY | OPEN_BINARY, 0);
  if (fd < 0)
    {
      if (purify_flag)
	{
	    /* sizeof ("../lib-src/") == 12 */
	  name_nonreloc = alloca_ibytes (12 + XSTRING_LENGTH (file) + 8);
	  /* Preparing to dump; DOC file is probably not installed.
	     So check in ../lib-src. */
	  qxestrcpy_ascii (name_nonreloc, "../lib-src/");
	  qxestrcat (name_nonreloc, XSTRING_DATA (file));

	  fd = qxe_open (name_nonreloc, O_RDONLY | OPEN_BINARY, 0);
	}

      if (fd < 0)
	report_file_error ("Cannot open doc string file",
			   name_nonreloc ? build_istring (name_nonreloc) :
			   name_reloc);
    }

  tem = extract_object_file_name (fd, position, name_nonreloc, name_reloc,
			      standard_doc_file);
  retry_close (fd);

  if (!STRINGP (tem))
    signal_error_1 (Qinvalid_byte_code, tem);

  return tem;
}
Пример #15
0
static void
gtk_output_toolbar_button (struct frame *f, Lisp_Object button)
{
  int shadow_thickness = 2;
  int x_adj, y_adj, width_adj, height_adj;
  GdkWindow *x_win = FRAME_GTK_TEXT_WIDGET (f)->window;
  GdkGC *background_gc = get_toolbar_gc (f);
  Lisp_Object instance, frame, window, glyph;
  struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
  struct Lisp_Image_Instance *p;
  struct window *w;
  int vertical = tb->vertical;
  int border_width = tb->border_width;

  if (vertical)
    {
      x_adj = border_width;
      width_adj = - 2 * border_width;
      y_adj = 0;
      height_adj = 0;
    }
  else
    {
      x_adj = 0;
      width_adj = 0;
      y_adj = border_width;
      height_adj = - 2 * border_width;
    }

  XSETFRAME (frame, f);
  window = FRAME_LAST_NONMINIBUF_WINDOW (f);
  w = XWINDOW (window);

  glyph = get_toolbar_button_glyph (w, tb);

  if (tb->enabled)
    {
      if (tb->down)
	{
	  shadow_thickness = -2;
	}
      else
	{
	  shadow_thickness = 2;
	}
    }
  else
    {
      shadow_thickness = 0;
    }

  background_gc = get_toolbar_gc (f);

  /* Clear the entire area. */
  gdk_draw_rectangle (x_win, background_gc, TRUE,
		      tb->x + x_adj,
		      tb->y + y_adj,
		      tb->width + width_adj,
		      tb->height + height_adj);

  /* Draw the outline. */
  if (shadow_thickness)
    gtk_output_shadows (f, tb->x + x_adj, tb->y + y_adj,
			tb->width + width_adj, tb->height + height_adj,
			shadow_thickness);

  /* Do the border. */
  gdk_draw_rectangle (x_win, background_gc, TRUE, tb->x, tb->y,
		      (vertical ? border_width : tb->width),
		      (vertical ? tb->height : border_width));

  gdk_draw_rectangle (x_win, background_gc, TRUE,
		      (vertical ? tb->x + tb->width - border_width : tb->x),
		      (vertical ? tb->y : tb->y + tb->height - border_width),
		      (vertical ? border_width : tb->width),
		      (vertical ? tb->height : border_width));

  background_gc = get_toolbar_gc (f);

  /* #### It is currently possible for users to trash us by directly
     changing the toolbar glyphs.  Avoid crashing in that case. */
  if (GLYPHP (glyph))
    instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1);
  else
    instance = Qnil;

  if (IMAGE_INSTANCEP (instance))
    {
      int width = tb->width + width_adj - shadow_thickness * 2;
      int height = tb->height + height_adj - shadow_thickness * 2;
      int x_offset = x_adj + shadow_thickness;
      int y_offset = y_adj + shadow_thickness;

      p = XIMAGE_INSTANCE (instance);

      if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p))
	{
	  if (width > (int) IMAGE_INSTANCE_PIXMAP_WIDTH (p))
	    {
	      x_offset += ((int) (width - IMAGE_INSTANCE_PIXMAP_WIDTH (p))
			   / 2);
	      width = IMAGE_INSTANCE_PIXMAP_WIDTH (p);
	    }
	  if (height > (int) IMAGE_INSTANCE_PIXMAP_HEIGHT (p))
	    {
	      y_offset += ((int) (height - IMAGE_INSTANCE_PIXMAP_HEIGHT (p))
			   / 2);
	      height = IMAGE_INSTANCE_PIXMAP_HEIGHT (p);
	    }

	  gtk_output_gdk_pixmap (f, XIMAGE_INSTANCE (instance), tb->x + x_offset,
				 tb->y + y_offset, 0, 0, 0, 0, width, height,
				 0, 0, 0, background_gc);
	}
      else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_TEXT)
	{
	  /* #### We need to make the face used configurable. */
	  struct face_cachel *cachel =
	    WINDOW_FACE_CACHEL (w, DEFAULT_INDEX);
	  struct display_line dl;
	  Lisp_Object string = IMAGE_INSTANCE_TEXT_STRING (p);
	  unsigned char charsets[NUM_LEADING_BYTES];
	  Emchar_dynarr *buf;
	  struct font_metric_info fm;

	  /* This could be true if we were called via the Expose event
             handler.  Mark the button as dirty and return
             immediately. */
	  if (f->window_face_cache_reset)
	    {
	      tb->dirty = 1;
	      MARK_TOOLBAR_CHANGED;
	      return;
	    }
	  buf = Dynarr_new (Emchar);
	  convert_bufbyte_string_into_emchar_dynarr
	    (XSTRING_DATA (string), XSTRING_LENGTH (string), buf);
	  find_charsets_in_emchar_string (charsets, Dynarr_atp (buf, 0),
					  Dynarr_length (buf));
	  ensure_face_cachel_complete (cachel, window, charsets);
	  face_cachel_charset_font_metric_info (cachel, charsets, &fm);

	  dl.ascent = fm.ascent;
	  dl.descent = fm.descent;
	  dl.ypos = tb->y + y_offset + fm.ascent;

	  if (fm.ascent + fm.descent <= height)
	    {
	      dl.ypos += (height - fm.ascent - fm.descent) / 2;
	      dl.clip = 0;
	    }
	  else
	    {
	      dl.clip = fm.ascent + fm.descent - height;
	    }

	  gtk_output_string (w, &dl, buf, tb->x + x_offset, 0, 0, width,
			     DEFAULT_INDEX, 0, 0, 0, 0);
	  Dynarr_free (buf);
	}

      /* We silently ignore the image if it isn't a pixmap or text. */
    }

  tb->dirty = 0;
}
Пример #16
0
static void
mswindows_format_file (WIN32_FIND_DATA *file, char *buf, int display_size,
		       int add_newline)
{
  char			*cptr;
  int			len;
  Lisp_Object		luser;
  double		file_size;

  len = strlen(file->cFileName);
  file_size =
    file->nFileSizeHigh * (double)UINT_MAX + file->nFileSizeLow;
  cptr = buf;
#if INDENT_LISTING
  *cptr++ = ' ';
  *cptr++ = ' ';
#endif
  if (display_size)
    {
      sprintf(cptr, "%6d ", (int)((file_size + 1023.) / 1024.));
      cptr += 7;
    }
  if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
      *cptr++ = 'd';
    } else {
      *cptr++ = '-';
    }
  cptr[0] = cptr[3] = cptr[6] = 'r';
  if (file->dwFileAttributes & FILE_ATTRIBUTE_READONLY)
    {
      cptr[1] = cptr[4] = cptr[7] = '-';
    } else {
      cptr[1] = cptr[4] = cptr[7] = 'w';
    }
  if ((file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
      (len > 4 &&
       (_stricmp(&file->cFileName[len - 4], ".exe") == 0
	|| _stricmp(&file->cFileName[len - 4], ".com") == 0
	|| _stricmp(&file->cFileName[len - 4], ".bat") == 0
#if 0
	|| _stricmp(&file->cFileName[len - 4], ".pif") == 0
#endif
	)))
    {
      cptr[2] = cptr[5] = cptr[8] = 'x';
    } else {
      cptr[2] = cptr[5] = cptr[8] = '-';
    }
  cptr += 9;
  if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
      strcpy(cptr, "   2 ");
    } else {
      strcpy(cptr, "   1 ");
    }
  cptr += 5;
  luser = Fuser_login_name(Qnil);
  if (!STRINGP(luser))
    {
      sprintf(cptr, "%-9d", 0);
    } else {
      char		*str;

      str = XSTRING_DATA(luser);
      sprintf(cptr, "%-8s ", str);
    }
  while (*cptr)
    {
      ++cptr;
    }
  sprintf(cptr, "%-8d ", getgid());
  cptr += 9;
  if (file_size > 99999999.0)
    {
      file_size = (file_size + 1023.0) / 1024.;
      if (file_size > 999999.0)
	{
	  sprintf(cptr, "%6.0fMB ", (file_size + 1023.0) / 1024.);
	} else {
	  sprintf(cptr, "%6.0fKB ", file_size);
	}
    } else {
      sprintf(cptr, "%8.0f ", file_size);
    }
  while (*cptr)
    {
      ++cptr;
    }
  {
    time_t		t, now;
    char		*ctimebuf;
    extern char		*sys_ctime(const time_t *t);	/* in nt.c */

    if (
#if 0
	/*
	 * This doesn't work.
	 * This code should be correct ...
	 */
	FileTimeToLocalFileTime(&file->ftLastWriteTime, &localtime) &&
	((t = convert_time(localtime)) != 0) &&
#else
	/*
	 * But this code "works" ...
	 */
	((t = convert_time(file->ftLastWriteTime)) != 0) &&
#endif
	((ctimebuf = sys_ctime(&t)) != NULL))
      {
	memcpy(cptr, &ctimebuf[4], 7);
	now = time(NULL);
	if (now - t > (365. / 2.0) * 86400.)
	  {
	    /* more than 6 months */
	    cptr[7] = ' ';
	    memcpy(&cptr[8], &ctimebuf[20], 4);
	  } else {
	    /* less than 6 months */
	    memcpy(&cptr[7], &ctimebuf[11], 5);
	  }
	cptr += 12;
	*cptr++ = ' ';
      }
  }
  if (add_newline)
    {
      sprintf(cptr, "%s\n", file->cFileName);
    }
  else
    {
      strcpy(cptr, file->cFileName);
    }
}