view src/sunfns.c @ 47576:b31c8ab7336a

Sync with version 2.0.20. Lengthy ChangeLog follows: 2002-09-22 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> Version 2.0.20 released. 2002-09-20 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> * net/tramp.el (tramp-completion-function-alist): Escape open paren in docstring. (tramp-user-regexp, tramp-host-regexp): Allow empty strings. (tramp-handle-insert-file-contents): Call tramp-message-for-buffer instead of tramp-message. (tramp-open-connection-rsh): Handle empty string as user name. (tramp-open-connection-su): Handle empty string as host name. Handle nil user name. (tramp-handle-file-local-copy, tramp-handle-write-region) (tramp-completion-handle-file-name-all-completions) (tramp-open-connection-telnet, tramp-open-connection-rsh) (tramp-open-connection-su, tramp-post-connection) (tramp-maybe-open-connection, tramp-method-out-of-band-p) (tramp-get-connection-function, tramp-get-remote-sh) (tramp-get-rsh-program, tramp-get-rsh-args) (tramp-get-rcp-program, tramp-get-rcp-args) (tramp-get-rcp-keep-date-arg, tramp-get-su-program) (tramp-get-su-args, tramp-get-telnet-program) (tramp-get-telnet-args): Use `tramp-find-method', perhaps require additional args USER, HOST. (tramp-action-password, tramp-open-connection-telnet) (tramp-open-connection-su, tramp-open-connection-multi) (tramp-method-out-of-band-p): `tramp-method-out-of-band-p' now takes USER and HOST arguments, to be able to use `tramp-find-method'. Update callers. (tramp-find-method): New function. 2002-09-20 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-insert-directory): Handle "--dired" in SWITCHES (by removing it). 2002-09-18 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-file-name-handler): Add `file-remote-p' property. 2002-09-17 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (top-level): Maybe autoload uudecode-decode-region. 2002-09-16 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-bug): Add tramp-methods. 2002-09-16 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-methods): Update docstring: tramp-encoding-command, tramp-decoding-command, tramp-encoding-function and tramp-decoding-function are not parameters anymore. (tramp-uuencode-region): Autoload it. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> Version 2.0.19 released. * net/tramp-uu.el: New file, implements uuencode in Lisp. * net/tramp.el (tramp-coding-commands): Use `tramp-uuencode-region' as local encoder for the uuencode based entries. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-write-region): Wrong parens. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> Version 2.0.18 released. * net/tramp.el (tramp-perl-decode): Perl changes to accomodate older versions of Perl. Now tested with 5.004. Suggestion from Michael Albinus. 2002-09-12 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-find-inline-encoding): Call tramp-call-local-coding-command with nil for INPUT and OUTPUT. (tramp-call-local-coding-command): OUTPUT equals nil means to discard the output. INPUT equals nil means /dev/null. 2002-09-12 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-encoding-shell): Default to environment variable COMSPEC on Windows. (tramp-handle-write-region): More debugging output. (tramp-find-inline-encoding): Ditto. 2002-09-11 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-handle-file-name-all-completions): Define `result1'. (tramp-parse-hosts-group): Discard IPv6 entries. 2002-09-11 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> * net/tramp.el (tramp-post-connection): Only send Perl mime-encode/decode implementations when using inline method. (tramp-handle-file-local-copy) (tramp-handle-write-region, tramp-post-connection) (tramp-coding-commands, tramp-find-inline-encoding): For the inline encodings, distinguish between local and remote commands, instead of between commands and functions. (The local commands can be functions, too.) If the local host is a Windows machine, we can't expect the same commands to work there as on the remote host. (tramp-call-local-coding-command): New function for calling local encoding and decoding commands. (tramp-set-remote-encoding, tramp-get-remote-encoding) (tramp-set-remote-decoding, tramp-get-remote-decoding) (tramp-set-local-encoding, tramp-get-local-encoding) (tramp-set-local-decoding, tramp-get-local-decoding): New functions. (tramp-get-encoding-command, tramp-set-encoding-command) (tramp-get-decoding-command, tramp-set-decoding-command) (tramp-get-encoding-function, tramp-set-encoding-function) (tramp-get-decoding-function, tramp-set-decoding-function): Old functions, removed. 2002-09-10 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-open-connection-setup-interactive-shell): Change command to invoke /bin/sh slightly to make it compatible with the `rc' shell. Suggested by Daniel Pittman. 2002-09-10 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-handle-write-region): Added missing `)'. Hope it's the right place. 2002-09-09 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-open-connection-setup-interactive-shell): Do "exec env PS1='$ ' /bin/sh" instead of just "exec /bin/sh" in order to get a sane shell prompt. If people have ${CWD}, say, in their shell prompt, then the default login shell might display something harmless, but the /bin/sh will display a dollar sign which confused the subsequent prompt recognition. (tramp-multi-action-password): More debugging output. (tramp-encoding-shell): Renamed from tramp-sh-program. More documentation. Default to cmd.exe on Windows NT. (tramp-encoding-command-switch): New variable. Use instead of hard-wired "-c" which is only good for /bin/sh. (tramp-encoding-reads-stdin): New variable. If t, commands are called like "/bin/sh -c COMMAND <INPUT", if nil, they are called like "/bin/sh -c COMMAND INPUT", ie the input file is the last argument. (tramp-multi-sh-program): Always default to tramp-encoding-shell. (tramp-handle-file-local-copy, tramp-handle-write-region): Respect tramp-encoding-shell and friends. (tramp-find-inline-encoding): Use new-style calls for checking if the local commands work. 2002-09-07 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-methods): Remove `tramp-completion-function' entries. They are handled now by `tramp-completion-function-alist'. (tramp-completion-function): Defvar removed. I've never used it. Hmm. (tramp-get-completion-function) (tramp-get-completion-rsh, tramp-get-completion-ssh) (tramp-get-completion-telnet, tramp-get-completion-su): Functions removed as well. Not necessary any longer due to extended customization means. (tramp-completion-function-alist): New defcustom. Holds all FUNCTION FILE pairs used for user and host name completion relevant for METHOD. (tramp-completion-function-alist-rsh) (tramp-completion-function-alist-ssh) (tramp-completion-function-alist-telnet) (tramp-completion-function-alist-su): Defconst for initializing `tramp-completion-function-alist'. Unfortunately, mainly UNIX-like values are known for me until now. Needs to be completed for at least VMS++ like operating systems. (tramp-set-completion-function) (tramp-get-completion-function): New functions for configuration of `tramp-completion-function-alist'. The old definition of `tramp-get-completion-function' has been discarded. (tramp-completion-handle-file-name-all-completions): Change function call for user/host completion according to definition in `tramp-completion-function-alist'. (tramp-parse-passwd): Added exception handling for "root", because `tramp-get-completion-su' (the previous place for this stuff) doesn't exist any longer. 2002-09-07 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-enter-password): Use `tramp-password-end-of-line' to terminate the line. (tramp-bug): Include new variable `tramp-password-end-of-line'. (tramp-password-end-of-line): New variable. People who use plink under Windows might have to issue "\r\n" after the password, but they need to send just "\n" after the other commands. So this variable was introduced to complement `tramp-rsh-end-of-line'. (tramp-wait-for-output, tramp-post-connection): Allow "\r" at end of line of the output delimiter. 2002-09-06 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-file-local-copy, tramp-find-shell) (tramp-open-connection-setup-interactive-shell): Add some comments about Douglas Grey Stephen's suggestions to make Tramp work better with plink under Windows. I'm not sure what to think of them, but now I have a guinea pig to try it out on. Said guinea pig is having other problems, though... Also remove some commented-out code. 2002-09-06 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods): Algorithm slightly tuned. (tramp-get-completion-user-host): Accept user names as they are if typed until "@". (tramp-completion-mode): Replace `last-input-char' by modern `last-input-event'. Check for `event-modifiers'. 2002-09-06 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (file-expand-wildcards): Corrected check to see if advising is necessary. 2002-09-05 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-postfix-single-method-format) (tramp-postfix-multi-method-format) (tramp-postfix-multi-hop-format) (tramp-postfix-user-format): New format strings. (tramp-postfix-single-method-regexp) (tramp-postfix-multi-method-regexp) (tramp-postfix-multi-hop-regexp) (tramp-postfix-user-regexp) (tramp-make-multi-tramp-file-format) (tramp-make-tramp-file-name): Apply them. (tramp-completion-handle-file-name-all-completions): Fix for invoking ange-ftp in case of "/ftp:xxx" file names. 2002-09-04 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-prefix-format) (tramp-postfix-host-format): New format strings. (tramp-prefix-regexp, tramp-method-regexp) (tramp-postfix-single-method-regexp) (tramp-postfix-multi-method-regexp) (tramp-postfix-multi-hop-regexp) (tramp-user-regexp, tramp-postfix-user-regexp) (tramp-host-regexp, tramp-postfix-host-regexp) (tramp-path-regexp): New atomar regular expressions. If corresponding format strings exist, derived from them. (tramp-file-name-structure) (tramp-multi-file-name-structure) (tramp-multi-file-name-hop-structure) (tramp-make-multi-tramp-file-format) (tramp-completion-mode) (tramp-completion-dissect-file-name) (tramp-parse-rhosts-group) (tramp-parse-shosts-group) (tramp-parse-hosts-group) (tramp-parse-passwd-group): Apply these expressions. (tramp-file-name-structure-unified) (tramp-file-name-structure-separate) (tramp-make-tramp-file-format-unified) (tramp-make-tramp-file-format-separate) (tramp-make-tramp-file-format) (tramp-make-tramp-file-user-nil-format-unified) (tramp-make-tramp-file-user-nil-format-separate) (tramp-make-tramp-file-user-nil-format) (tramp-multi-file-name-structure-unified) (tramp-multi-file-name-structure-separate) (tramp-multi-file-name-hop-structure-unified) (tramp-multi-file-name-hop-structure-separate) (tramp-make-multi-tramp-file-format-unified) (tramp-make-multi-tramp-file-format-separate): Removed. (tramp-make-tramp-file-name): Allow partial tramp file names. Generate tramp file format on-the-fly depending on parameters. Apply atomar format strings resp expressions. (tramp-get-completion-methods) (tramp-get-completion-user-host): Apply `tramp-make-tramp-file-name'. (tramp-parse-hosts-group): Take all host names and IP addresses into account. (tramp-bug): Remove `tramp-make-tramp-file-format'. 2002-09-01 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-methods): Add `tramp-completion-function' for "su" and "sudo". (tramp-get-completion-telnet): Implement it. (tramp-parse-hosts) (tramp-parse-hosts-group) (tramp-get-completion-su) (tramp-parse-passwd) (tramp-parse-passwd-group): New functions. 2002-08-31 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): Check for `last-input-char'. (tramp-completion-file-name-handler-alist): Add handler for `file-exists-p. (tramp-completion-handle-file-exists-p): New function. (tramp-completion-handle-file-name-completion): Simplified. (tramp-completion-dissect-file-name): Regexp's reorganised. (tramp-completion-handle-file-name-all-completions): Call completion-function only if `user' or `host' is given. (tramp-get-completion-user-host): New function. (tramp-get-completion-rsh) (tramp-get-completion-ssh): Apply it. 2002-08-29 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-handler-alist): Add handler for `expand-file-name'. (tramp-completion-handle-expand-file-name): New function. 2002-08-26 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): New function. (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-all-completions): Apply it. (tramp-methods): Remove double definition of `ssh1-old' and `ssh2-old'. (tramp-point-at-eol): New defalias. (tramp-parse-rhosts-group) (tramp-parse-shosts-group):: Apply it. 2002-08-25 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods) (tramp-get-completion-rsh) (tramp-get-completion-ssh): Add "[" for Xemacs. (tramp-completion-file-name-regexp-separate): Expression adapted. (tramp-completion-file-name-handler-alist): Add handler for `file-name-directory' and `file-name-nondirectory'. (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-nondirectory) (tramp-completion-run-real-handler): New functions. (tramp-completion-file-name-handler) (tramp-completion-handle-file-name-all-completions): Apply `tramp-completion-run-real-handler'. (tramp-parse-rhosts) (tramp-parse-shosts): Use `with-temp-buffer'. `result? renamed to `res' (otherwise side effects in XEmacs). 2002-08-24 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-regexp) (tramp-completion-file-name-handler-alist) (tramp-flatten-list) (tramp-completion-dissect-file-name) (tramp-get-completion-rsh) (tramp-parse-rhosts) (tramp-parse-rhosts-group) (tramp-get-completion-ssh): Doc string tuned. (tramp-methods): Doc string and custom type extended for `tramp-completion-function'. (tramp-completion-function): Variable added. Is it really used? Other variables like `tramp-completion-function' aren't used. (tramp-completion-file-name-handler-alist): Add handler for `file-name-completion'. (tramp-completion-handle-file-name-completion): New function. 2002-08-18 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-parse-rhosts) (tramp-parse-rhosts-group) (tramp-parse-shosts) (tramp-parse-shosts-group): New functions. 2002-08-17 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-dissect-file-name) (tramp-completion-dissect-file-name1): New functions. 2002-08-16 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-function) (tramp-get-completion-rsh) (tramp-get-completion-ssh) (tramp-get-completion-telnet): New functions. (tramp-methods): Add `tramp-completion-function' for all methods. 2002-08-15 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods): New function. (tramp-find-default-method): Allow host to be nil (like user). 2002-08-14 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-regexp-unified) (tramp-completion-file-name-regexp-separate) (tramp-completion-file-name-regexp) (tramp-completion-file-name-handler-alist): New defcustoms. (tramp-completion-file-name-handler): New function. Add `tramp-completion-file-name-handler' to `file-name-handler-alist'. (tramp-run-real-handler): Add `tramp-completion-file-name-handler' to `inhibit-file-name-handlers'. (tramp-completion-handle-file-name-all-completions) (tramp-completion-handle-file-name-completion): New functions. 2002-08-12 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-invoke-ange-ftp): `tramp-disable-ange-ftp' must be called again after activating `ange-ftp'. (tramp-ange-ftp-file-name-p): Check for Xemacs. 2002-08-08 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-do-copy-or-rename-file): Don't pass KEEP-DATE to tramp-invoke-ange-ftp 'rename. (tramp-handle-write-region): Don't pass LOCKNAME and CONFIRM to tramp-invoke-ange-ftp 'write-region. (tramp-handle-set-file-modes): Change order of FILENAME and MODE passing to tramp-invoke-ange-ftp 'set-file-modes. (tramp-flatten-list): New function. Maybe this functionality does exist already elsewhere in the libraries. (tramp-invoke-ange-ftp): Apply `tramp-flatten-list' to parameter list in order to avoid nested lists, f.e. when invoked from `tramp-handle-dired-call-process'. 2002-09-05 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-chunksize): New kluge variable. (tramp-send-region): If tramp-chunksize is non-nil, send region in parts and sleep 0.1 seconds between chunks. 2002-09-03 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-insert-directory): Use `insert-buffer-substring' instead of `insert-buffer', which is not supposed to be used from Lisp. Remember old point in a variable instead of using `mark'. Suggestion from Stefan Monnier. (tramp-unified-filenames): New variable. Use it in default value of other filename variables. (file-expand-wildcards): Don't advise unless "[" and "]" are used in the filename format. 2002-09-01 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-methods): Remove duplicate definition of ssh1-old and ssh2-old.
author Kai Großjohann <kgrossjo@eu.uu.net>
date Sun, 22 Sep 2002 13:23:36 +0000
parents 40db0673e6f0
children 23a1cea22d13
line wrap: on
line source

/* Functions for Sun Windows menus and selection buffer.
   Copyright (C) 1987, 1999, 2001 Free Software Foundation, Inc.

This file is probably totally obsolete.  In any case, the FSF is
unwilling to support it.  We agreed to include it in our distribution
only on the understanding that we would spend no time at all on it.

If you have complaints about this file, send them to peck@sun.com.
If no one at Sun wants to maintain this, then consider it not
maintained at all.  It would be a bad thing for the GNU project if
this file took our effort away from higher-priority things.


This file is part of GNU Emacs.

GNU Emacs 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 2, or (at your option)
any later version.

GNU Emacs 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 GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

/* Author: Jeff Peck, Sun Microsystems, Inc. <peck@sun.com>
Original ideas by David Kastan and Eric Negaard, SRI International
Major help from: Steve Greenbaum, Reasoning Systems, Inc.
 		    <froud@kestrel.arpa>
who first discovered the Menu_Base_Kludge.
 */

/*
 *	Emacs Lisp-Callable functions for sunwindows
 */
#include <config.h>

#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <sunwindow/window_hs.h>
#include <suntool/selection.h>
#include <suntool/menu.h>
#include <suntool/walkmenu.h>
#include <suntool/frame.h>
#include <suntool/window.h>

#include <fcntl.h>
#undef NULL /* We don't need sunview's idea of NULL */
#include "lisp.h"
#include "window.h"
#include "buffer.h"
#include "termhooks.h"

/* conversion to/from character & frame coordinates */
/* From Gosling Emacs SunWindow driver by Chris Torek */

/* Chars to frame coords.  Note that we speak in zero origin. */
#define CtoSX(cx) ((cx) * Sun_Font_Xsize)
#define CtoSY(cy) ((cy) * Sun_Font_Ysize)

/* Frame coords to chars */
#define StoCX(sx) ((sx) / Sun_Font_Xsize)
#define StoCY(sy) ((sy) / Sun_Font_Ysize)

#define CHECK_GFX(x) if((win_fd<0)&&(Fsun_window_init(),(win_fd<0)))return(x)
int win_fd = -1;
struct pixfont *Sun_Font;	/* The font */
int Sun_Font_Xsize;		/* Width of font  */
int Sun_Font_Ysize;		/* Height of font */

#define Menu_Base_Kludge	/* until menu_show_using_fd gets fixed */
#ifdef  Menu_Base_Kludge
static Frame Menu_Base_Frame;
static int Menu_Base_fd;
static Lisp_Object sm_kludge_string;
#endif
struct cursor CurrentCursor;	/* The current cursor */

static short CursorData[16];	/* Build cursor here */
static mpr_static(CursorMpr, 16, 16, 1, CursorData);
static struct cursor NewCursor = {0, 0, PIX_SRC ^ PIX_DST, &CursorMpr};

#define RIGHT_ARROW_CURSOR	/* if you want the right arrow */
#ifdef RIGHT_ARROW_CURSOR
/* The default right-arrow cursor, with XOR drawing. */
static short ArrowCursorData[16] = {
  0x0001,0x0003,0x0007,0x000F,0x001F,0x003F,0x007F,0x000F,
  0x001B,0x0019,0x0030,0x0030,0x0060,0x0060,0x00C0,0x00C0};
static mpr_static(ArrowCursorMpr, 16, 16, 1, ArrowCursorData);
struct cursor DefaultCursor = {15, 0, PIX_SRC ^ PIX_DST, &ArrowCursorMpr};

#else
/* The default left-arrow cursor, with XOR drawing. */
static short ArrowCursorData[16] = {
	0x8000,0xC000,0xE000,0xF000,0xF800,0xFC00,0xFE00,0xF000,
	0xD800,0x9800,0x0C00,0x0C00,0x0600,0x0600,0x0300,0x0300};
static mpr_static(ArrowCursorMpr, 16, 16, 1, ArrowCursorData);
struct cursor DefaultCursor = {0, 0, PIX_SRC ^ PIX_DST, &ArrowCursorMpr};
#endif

/*
 *	Initialize window
 */
DEFUN ("sun-window-init", Fsun_window_init, Ssun_window_init, 0, 1, 0,
       doc: /* One time setup for using Sun Windows with mouse.
Unless optional argument FORCE is non-nil, is a noop after its first call.
Returns a number representing the file descriptor of the open Sun Window,
or -1 if can not open it.  */)
     (force)
     Lisp_Object force;
{
  char *cp;
  static int already_initialized = 0;

  if ((! already_initialized) || (!NILP(force))) {
    cp = getenv("WINDOW_GFX");
    if (cp != 0) win_fd = emacs_open (cp, O_RDWR, 0);
    if (win_fd > 0)
      {
	Sun_Font = pf_default();
	Sun_Font_Xsize = Sun_Font->pf_defaultsize.x;
	Sun_Font_Ysize = Sun_Font->pf_defaultsize.y;
	Fsun_change_cursor_icon (Qnil);	/* set up the default cursor */
	already_initialized = 1;
#ifdef  Menu_Base_Kludge

	/* Make a frame to use for putting the menu on, and get its fd. */
	Menu_Base_Frame = window_create(0, FRAME,
					WIN_X, 0, WIN_Y, 0,
					WIN_ROWS, 1, WIN_COLUMNS, 1,
					WIN_SHOW, FALSE,
					FRAME_NO_CONFIRM, 1,
					0);
	Menu_Base_fd = (int) window_get(Menu_Base_Frame, WIN_FD);
#endif
      }
  }
  return(make_number(win_fd));
}

/*
 *	Mouse sit-for (allows a shorter interval than the regular sit-for
 *	and can be interrupted by the mouse)
 */
DEFUN ("sit-for-millisecs", Fsit_for_millisecs, Ssit_for_millisecs, 1, 1, 0,
       doc: /* Like sit-for, but ARG is milliseconds.
Perform redisplay, then wait for ARG milliseconds or until
input is available.  Returns t if wait completed with no input.
Redisplay does not happen if input is available before it starts.  */)
     (n)
     Lisp_Object n;
{
  struct timeval Timeout;
  int waitmask = 1;
  
  CHECK_NUMBER (n);
  Timeout.tv_sec = XINT(n) / 1000;
  Timeout.tv_usec = (XINT(n) - (Timeout.tv_sec * 1000)) * 1000;

  if (detect_input_pending()) return(Qnil);
  redisplay_preserve_echo_area (16);
  /*
   *	Check for queued keyboard input/mouse hits again
   *	(A bit screen update can take some time!)
   */
  if (detect_input_pending()) return(Qnil);
  select(1,&waitmask,0,0,&Timeout);
  if (detect_input_pending()) return(Qnil);
  return(Qt);
}

/*
 *   Sun sleep-for (allows a shorter interval than the regular sleep-for)
 */
DEFUN ("sleep-for-millisecs", 
       Fsleep_for_millisecs,
       Ssleep_for_millisecs, 1, 1, 0,
       doc: /* Pause, without updating display, for ARG milliseconds.  */)
     (n)
     Lisp_Object n;
{
  unsigned useconds;

  CHECK_NUMBER (n);
  useconds = XINT(n) * 1000;
  usleep(useconds);
  return(Qt);
}

DEFUN ("update-display", Fupdate_display, Supdate_display, 0, 0, 0,
       doc: /* Perform redisplay.  */)
     ()
{
  redisplay_preserve_echo_area (17);
  return(Qt);
}


/*
 *	Change the Sun mouse icon
 */
DEFUN ("sun-change-cursor-icon",
       Fsun_change_cursor_icon,
       Ssun_change_cursor_icon, 1, 1, 0,
       doc: /* Change the Sun mouse cursor icon.
ICON is a lisp vector whose 1st element
is the X offset of the cursor hot-point, whose 2nd element is the Y offset
of the cursor hot-point and whose 3rd element is the cursor pixel data
expressed as a string.  If ICON is nil then the original arrow cursor is used.  */)
     (Icon)
     Lisp_Object Icon;
{
  register unsigned char *cp;
  register short *p;
  register int i;
  Lisp_Object X_Hot, Y_Hot, Data;
  
  CHECK_GFX (Qnil);
  /*
   *	If the icon is null, we just restore the DefaultCursor
   */
  if (NILP(Icon)) 
    CurrentCursor = DefaultCursor;
  else {
    /*
     *	extract the data from the vector
     */
    CHECK_VECTOR (Icon);
    if (XVECTOR(Icon)->size < 3) return(Qnil);
    X_Hot = XVECTOR(Icon)->contents[0];
    Y_Hot = XVECTOR(Icon)->contents[1];
    Data = XVECTOR(Icon)->contents[2];
    
    CHECK_NUMBER (X_Hot);
    CHECK_NUMBER (Y_Hot);
    CHECK_STRING (Data);
    if (SCHARS (Data) != 32) return(Qnil);
    /*
     *	Setup the new cursor
     */
    NewCursor.cur_xhot = X_Hot;
    NewCursor.cur_yhot = Y_Hot;
    cp = SDATA (Data);
    p = CursorData;
    i = 16;
    while(--i >= 0)
      *p++ = (cp[0] << 8) | cp[1], cp += 2;
    CurrentCursor = NewCursor;
  }
  win_setcursor(win_fd, &CurrentCursor);
  return(Qt);
}

/*
 *	Interface for sunwindows selection
 */
static Lisp_Object Current_Selection;

static
sel_write (sel, file)
     struct selection *sel;
     FILE *file;
{
  fwrite (SDATA (Current_Selection), sizeof (char), 
	  sel->sel_items, file);
}

static
sel_clear (sel, windowfd)
     struct selection *sel;
     int windowfd;
{
}

static
sel_read (sel, file)
     struct selection *sel;
     FILE *file;
{
  register int i, n;
  register char *cp;
  
  Current_Selection = make_string ("", 0);
  if (sel->sel_items <= 0)
    return (0);
  cp = (char *) malloc(sel->sel_items);
  if (cp == (char *)0) {
    error("malloc failed in sel_read");
    return(-1);
  }
  n = fread(cp, sizeof(char), sel->sel_items, file);
  if (n > sel->sel_items) {
    error("fread botch in sel_read");
    return(-1);
  } else if (n < 0) {
    error("Error reading selection.");
    return(-1);
  }
  /*
   * The shelltool select saves newlines as carriage returns,
   * but emacs wants newlines.
   */
  for (i = 0; i < n; i++) 
    if (cp[i] == '\r') cp[i] = '\n';

  Current_Selection = make_string (cp, n);
  free (cp);
  return (0);
}

/*
 *	Set the window system "selection" to be the arg STRING
 */
DEFUN ("sun-set-selection", Fsun_set_selection, Ssun_set_selection, 1, 1,
       "sSet selection to: ",
       doc: /* Set the current sunwindow selection to STRING.  */)
     (str)
     Lisp_Object str;
{
  struct selection selection;

  CHECK_STRING (str);
  Current_Selection = str;

  CHECK_GFX (Qnil);
  selection.sel_type = SELTYPE_CHAR;
  selection.sel_items = SCHARS (str);
  selection.sel_itembytes = 1;
  selection.sel_pubflags = 1;
  selection_set(&selection, sel_write, sel_clear, win_fd);
  return (Qt);
}
/*
 *	Stuff the current window system selection into the current buffer
 */
DEFUN ("sun-get-selection", Fsun_get_selection, Ssun_get_selection, 0, 0, 0,
       doc: /* Return the current sunwindows selection as a string.  */)
     ()
{
  CHECK_GFX (Current_Selection);
  selection_get (sel_read, win_fd);
  return (Current_Selection);
}

Menu sun_menu_create();

Menu_item
sun_item_create (Pair)
     Lisp_Object Pair;
{
  /* In here, we depend on Lisp supplying zero terminated strings in the data*/
  /* so we can just pass the pointers, and not recopy anything */

  Menu_item menu_item;
  Menu submenu;
  Lisp_Object String;
  Lisp_Object Value;

  if (!CONSP(Pair)) wrong_type_argument(Qlistp, Pair);
  String = Fcar(Pair);
  CHECK_STRING(String);
  Value = Fcdr(Pair);
  if (SYMBOLP (Value))
    Value = SYMBOL_VALUE (Value);
  if (VECTORP (Value)) {
    submenu = sun_menu_create (Value);
    menu_item = menu_create_item
      (MENU_RELEASE, MENU_PULLRIGHT_ITEM, SDATA (String), submenu, 0);
  } else {
    menu_item = menu_create_item
      (MENU_RELEASE, MENU_STRING_ITEM, SDATA (String), Value, 0);
  }
  return menu_item;
}

Menu 
sun_menu_create (Vector)
     Lisp_Object Vector;
{
  Menu menu;
  int i;
  CHECK_VECTOR(Vector);
  menu=menu_create(0); 
  for(i = 0; i < XVECTOR(Vector)->size; i++) {
    menu_set (menu, MENU_APPEND_ITEM, 
	      sun_item_create(XVECTOR(Vector)->contents[i]), 0);
  }
  return menu;
}

/*
 *  If the first item of the menu has nil as its value, then make the
 *  item look like a label by inverting it and making it unselectable.
 *  Returns 1 if the label was made, 0 otherwise.
 */
int
make_menu_label (menu)
     Menu menu;
{
  int made_label_p = 0;

  if (( menu_get(menu, MENU_NITEMS) > 0 ) && /* At least one item */
      ((Lisp_Object) menu_get(menu_get(menu, MENU_NTH_ITEM, 1),
			      MENU_VALUE) == Qnil )) {
      menu_set(menu_get(menu, MENU_NTH_ITEM, 1),
	       MENU_INVERT, TRUE,
	       MENU_FEEDBACK, FALSE,
	       0);
      made_label_p = 1;
    }
  return made_label_p;
}

/*
 *	Do a pop-up menu and return the selected value
 */
DEFUN ("sun-menu-internal",
       Fsun_menu_internal,
       Ssun_menu_internal, 5, 5, 0,
       doc: /* Set up a SunView pop-up menu and return the user's choice.
Arguments WINDOW, X, Y, BUTTON, and MENU.
*** User code should generally use sun-menu-evaluate ***

Arguments WINDOW, X, Y, BUTTON, and MENU.
Put MENU up in WINDOW at position X, Y.
The BUTTON argument specifies the button to be released that selects an item:
   1 = LEFT BUTTON
   2 = MIDDLE BUTTON
   4 = RIGHT BUTTON
The MENU argument is a vector containing (STRING . VALUE) pairs.
The VALUE of the selected item is returned.
If the VALUE of the first pair is nil, then the first STRING will be used
as a menu label.  */)
     (window, X_Position, Y_Position, Button, MEnu)
     Lisp_Object window, X_Position, Y_Position, Button, MEnu;
{
  Menu menu;
  int button, xpos, ypos;
  Event event0;
  Event *event = &event0;
  Lisp_Object Value, Pair;
  
  CHECK_NUMBER(X_Position);
  CHECK_NUMBER(Y_Position);
  CHECK_LIVE_WINDOW(window);
  CHECK_NUMBER(Button);
  CHECK_VECTOR(MEnu);

  CHECK_GFX (Qnil);

  xpos = CtoSX (WINDOW_LEFT_MARGIN (XWINDOW (window)) + XINT(X_Position));
  ypos = CtoSY (XWINDOW(window)->top  + XINT(Y_Position));
#ifdef  Menu_Base_Kludge
  {static Lisp_Object symbol[2];
   symbol[0] = Fintern (sm_kludge_string, Qnil);
   Pair = Ffuncall (1, symbol);
   xpos += XINT (XCDR (Pair));
   ypos += XINT (XCAR (Pair));
 }
#endif

  button = XINT(Button);
  if(button == 4) button = 3;
  event_set_id   (event, BUT(button));
  event_set_down (event);
  event_set_x    (event, xpos);
  event_set_y    (event, ypos);

  menu = sun_menu_create(MEnu);
  make_menu_label(menu);

#ifdef  Menu_Base_Kludge
  Value = (Lisp_Object) menu_show(menu, Menu_Base_Frame, event, 0);
#else
/* This confuses the notifier or something: */
  Value = (Lisp_Object) menu_show_using_fd(menu, win_fd, event, 0);
/*
 * Right button gets lost, and event sequencing or delivery gets mixed up
 * So, until that gets fixed, we use this <Menu_Base_Frame> kludge:
 */
#endif
  menu_destroy (menu);

  return ((int)Value ? Value : Qnil);
}


/*
 *	Define everything
 */
syms_of_sunfns()
{
#ifdef  Menu_Base_Kludge
  /* i'm just too lazy to re-write this into C code */
  /* so we will call this elisp function from C */
  sm_kludge_string = make_pure_string ("sm::menu-kludge", 15, 15, 0);
#endif /* Menu_Base_Kludge */

  defsubr(&Ssun_window_init);
  defsubr(&Ssit_for_millisecs);
  defsubr(&Ssleep_for_millisecs);
  defsubr(&Supdate_display);
  defsubr(&Ssun_change_cursor_icon);
  defsubr(&Ssun_set_selection);
  defsubr(&Ssun_get_selection);
  defsubr(&Ssun_menu_internal);
}