aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorJim Blandy1991-05-31 00:27:05 +0000
committerJim Blandy1991-05-31 00:27:05 +0000
commitb92a743788e84acad9c22f0d9b4917a94c32ff8d (patch)
treeb1e1b4fb47195d52176bb06d5f87d5625ce2a5ee /lib-src
parentdc6f92b83455e13fba9ee1c88122fcc9453e79cd (diff)
downloademacs-b92a743788e84acad9c22f0d9b4917a94c32ff8d.tar.gz
emacs-b92a743788e84acad9c22f0d9b4917a94c32ff8d.zip
entered into RCS
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacstool.c318
1 files changed, 239 insertions, 79 deletions
diff --git a/lib-src/emacstool.c b/lib-src/emacstool.c
index 5e310e0faa4..1312dd912fc 100644
--- a/lib-src/emacstool.c
+++ b/lib-src/emacstool.c
@@ -1,37 +1,62 @@
1/* 1/*
2 * 2 *
3 * Copyright (C) 1986 Free Software Foundation, Inc. 3 * Copyright (C) 1986, 1988, 1990, 1991 Free Software Foundation, Inc.
4 * 4 *
5 * This file is part of GNU Emacs. 5 * This file is part of GNU Emacs.
6 6 *
7GNU Emacs is free software; you can redistribute it and/or modify 7 * GNU Emacs is distributed in the hope that it will be useful,
8it under the terms of the GNU General Public License as published by 8 * but without any warranty. No author or distributor
9the Free Software Foundation; either version 1, or (at your option) 9 * accepts responsibility to anyone for the consequences of using it
10any later version. 10 * or for whether it serves any particular purpose or works at all,
11 11 * unless he says so in writing.
12GNU Emacs is distributed in the hope that it will be useful, 12 *
13but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * Everyone is granted permission to copy, modify and redistribute
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Emacs, but only under the conditions described in the
15GNU General Public License for more details. 15 * document "GNU Emacs copying permission notice". An exact copy
16 16 * of the document is supposed to have been given to you along with
17You should have received a copy of the GNU General Public License 17 * GNU Emacs so that you can know how you may redistribute it all.
18along with GNU Emacs; see the file COPYING. If not, write to 18 * It should be in a file named COPYING. Among other things, the
19the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 19 * copyright notice and this notice must be preserved on all copies.
20 * 20 *
21 * 21 *
22 * For Emacs in SunView/Sun-Windows: (supported by Sun Unix v3.2) 22 * For Emacs in SunView/Sun-Windows: (supported by Sun Unix v3.2 or greater)
23 * Insert a notifier filter-function to convert all useful input 23 * Insert a notifier filter-function to convert all useful input
24 * to "key" sequences that emacs can understand. See: Emacstool(1). 24 * to "key" sequences that emacs can understand. See: Emacstool(1).
25 * 25 *
26 * Author: Jeff Peck, Sun Microsystems, Inc. <peck@sun.com> 26 * Author: Jeff Peck, Sun Microsystems, Inc. <peck@eng.sun.com>
27 * 27 *
28 * Original Idea: Ian Batten 28 * Original Idea: Ian Batten
29 * Updated 15-Mar-88, Jeff Peck: set IN_EMACSTOOL, TERM, TERMCAP 29 * Updated 15-Mar-88, Jeff Peck: set IN_EMACSTOOL, TERM, TERMCAP
30 * 30 * Updated 10-Sep-88, Jeff Peck: add XVIEW and JLE support
31 * Updated 8-Oct-90, Jeff Peck: add Meta-bit for Xview
32 * Updated 6-Mar-91, Jeff Peck: Hack to detect -Wt invocation
33 * [note, TTYSW limitation means you must Click-To-Type in Openwin]
34 * [fixed in OW3 or use local/tty.o]
35 * for better results, this should move to using TERMSW.
36 * Updated 10-Mar-91, Jeff Peck, et al: support for TERMSW (TTERM)
37 * allows point-to-type even in OW2
38 *
39 * [note: xvetool should be started with the "-nw" flag for emacs!]
31 */ 40 */
32 41
42#ifdef XVIEW
43#include <xview/xview.h>
44#include <xview/panel.h>
45#include <xview/attr.h>
46#include <xview/tty.h>
47#include <xview/ttysw.h> /* private defines */
48#include <xview/termsw.h> /* -DTTERM */
49#include <xview/font.h> /* for testing */
50#else
33#include <suntool/sunview.h> 51#include <suntool/sunview.h>
34#include <suntool/tty.h> 52#include <suntool/tty.h>
53#include <suntool/ttysw.h>
54#endif XVIEW
55
56#ifdef JLE
57# include <locale.h>
58#endif JLE
59
35#include <stdio.h> 60#include <stdio.h>
36#include <sys/file.h> 61#include <sys/file.h>
37 62
@@ -51,13 +76,35 @@ static int m_prefix_length = 2; /* mouse_prefix length */
51static char *key_prefix = "\030*"; /* C-x * */ 76static char *key_prefix = "\030*"; /* C-x * */
52static int k_prefix_length = 2; /* key_prefix length */ 77static int k_prefix_length = 2; /* key_prefix length */
53 78
79#ifdef JLE
80static char *emacs_name = "nemacs"; /* default run command */
81static char *title = "NEmacstool - "; /* initial title */
82#else
54static char *emacs_name = "emacs"; /* default run command */ 83static char *emacs_name = "emacs"; /* default run command */
55static char buffer[BUFFER_SIZE]; /* send to ttysw_input */
56static char *title = "Emacstool - "; /* initial title */ 84static char *title = "Emacstool - "; /* initial title */
85#endif JLE
86
87static char buffer[BUFFER_SIZE]; /* send to ttysw_input */
88static char *bold_name = 0; /* for -bold option */
57 89
58Frame frame; /* Base frame for system */ 90Frame frame; /* Base frame for system */
59Tty ttysw; /* Where emacs is */ 91
92#ifndef TTERM
93#define SWTYPE TTY
94Tty tty_win; /* Where emacs is reading */
95#else
96#define SWTYPE TERMSW
97Termsw tty_win; /* Termsw does follow-mouse */
98#endif TTERM
99
100#ifdef XVIEW
101Xv_Window tty_view; /* Where the events are in Xview*/
102#else
103Tty tty_view; /* SunView place filler */
104#endif XVIEW
105
60int font_width, font_height; /* For translating pixels to chars */ 106int font_width, font_height; /* For translating pixels to chars */
107int left_margin = 0; /* default window -- frame offset */
61 108
62int console_fd = 0; /* for debugging: setenv DEBUGEMACSTOOL */ 109int console_fd = 0; /* for debugging: setenv DEBUGEMACSTOOL */
63FILE *console; /* for debugging: setenv DEBUGEMACSTOOL */ 110FILE *console; /* for debugging: setenv DEBUGEMACSTOOL */
@@ -69,7 +116,6 @@ static short default_image[258] =
69#include <images/terminal.icon> 116#include <images/terminal.icon>
70}; 117};
71mpr_static(icon_image, 64, 64, 1, default_image); 118mpr_static(icon_image, 64, 64, 1, default_image);
72
73 119
74/* 120/*
75 * Assign a value to a set of keys 121 * Assign a value to a set of keys
@@ -148,7 +194,11 @@ time_delta (now_sec, now_usec, prev_sec, prev_usec)
148 */ 194 */
149static Notify_value 195static Notify_value
150input_event_filter_function (window, event, arg, type) 196input_event_filter_function (window, event, arg, type)
197#ifdef XVIEW
198 Xv_Window window;
199#else
151 Window window; 200 Window window;
201#endif XVIEW
152 Event *event; 202 Event *event;
153 Notify_arg arg; 203 Notify_arg arg;
154 Notify_event_type type; 204 Notify_event_type type;
@@ -159,7 +209,7 @@ input_event_filter_function (window, event, arg, type)
159 209
160 /* UP L1 is the STOP key */ 210 /* UP L1 is the STOP key */
161 if (event_id(event) == WIN_STOP) { 211 if (event_id(event) == WIN_STOP) {
162 ttysw_input(ttysw, "\007\007\007\007\007\007\007", 7); 212 ttysw_input(tty_win, "\007\007\007\007\007\007\007", 7);
163 return NOTIFY_IGNORED; 213 return NOTIFY_IGNORED;
164 } 214 }
165 215
@@ -175,15 +225,15 @@ input_event_filter_function (window, event, arg, type)
175 return notify_next_event_func (window, event, arg, type); 225 return notify_next_event_func (window, event, arg, type);
176*/ 226*/
177 time_stamp = event_time (event); 227 time_stamp = event_time (event);
178 ttysw_input (ttysw, mouse_prefix, m_prefix_length); 228 ttysw_input (tty_win, mouse_prefix, m_prefix_length);
179 sprintf (buffer, "(%d %d %d %d)\015", 229 sprintf (buffer, "(%d %d %d %d)\015",
180 button_value (event), 230 button_value (event),
181 event_x (event) / font_width, 231 (event_x (event) - left_margin) / font_width,
182 event_y (event) / font_height, 232 event_y (event) / font_height,
183 time_delta (time_stamp.tv_sec, time_stamp.tv_usec, 233 time_delta (time_stamp.tv_sec, time_stamp.tv_usec,
184 prev_event_sec, prev_event_usec) 234 prev_event_sec, prev_event_usec)
185 ); 235 );
186 ttysw_input (ttysw, buffer, strlen(buffer)); 236 ttysw_input (tty_win, buffer, strlen(buffer));
187 prev_event_sec = time_stamp.tv_sec; 237 prev_event_sec = time_stamp.tv_sec;
188 prev_event_usec = time_stamp.tv_usec; 238 prev_event_usec = time_stamp.tv_usec;
189 return NOTIFY_IGNORED; 239 return NOTIFY_IGNORED;
@@ -221,9 +271,9 @@ input_event_filter_function (window, event, arg, type)
221 return NOTIFY_IGNORED; 271 return NOTIFY_IGNORED;
222 } 272 }
223#endif 273#endif
224 ttysw_input (ttysw, key_prefix, k_prefix_length); 274 ttysw_input (tty_win, key_prefix, k_prefix_length);
225 sprintf (buffer, "%c%c", d, c); 275 sprintf (buffer, "%c%c", d, c);
226 ttysw_input(ttysw, buffer, strlen(buffer)); 276 ttysw_input(tty_win, buffer, strlen(buffer));
227 277
228 return NOTIFY_IGNORED; 278 return NOTIFY_IGNORED;
229 } 279 }
@@ -237,6 +287,13 @@ input_event_filter_function (window, event, arg, type)
237 event_set_id(event, (event_id(event) - 32)); 287 event_set_id(event, (event_id(event) - 32));
238/* crufty, but it works for now. is there an UPCASE(event)? */ 288/* crufty, but it works for now. is there an UPCASE(event)? */
239#endif 289#endif
290#ifndef NO_META_BIT
291/* under Openwindows/X, the meta bit is not set in the key event,
292 * emacs expects this so we add it in here:
293 */
294 if (event_is_ascii(event) && event_meta_is_down(event))
295 event_set_id(event, 128 | event_id(event));
296#endif
240 return notify_next_event_func (window, event, arg, type); 297 return notify_next_event_func (window, event, arg, type);
241} 298}
242 299
@@ -246,17 +303,16 @@ main (argc, argv)
246{ 303{
247 int error_code; /* Error codes */ 304 int error_code; /* Error codes */
248 305
306#ifdef JLE
307 setlocale(LC_ALL, "");
308#endif JLE
309
249 if(getenv("DEBUGEMACSTOOL")) 310 if(getenv("DEBUGEMACSTOOL"))
250 console = fdopen (console_fd = open("/dev/console",O_WRONLY), "w"); 311 console = fdopen (console_fd = open("/dev/console",O_WRONLY), "w");
251 312
252 /* do this first, so arglist can override it */
253 frame_icon = icon_create (ICON_LABEL, "Emacstool",
254 ICON_IMAGE, &icon_image,
255 0);
256
257 putenv("IN_EMACSTOOL=t"); /* notify subprocess that it is in emacstool */ 313 putenv("IN_EMACSTOOL=t"); /* notify subprocess that it is in emacstool */
258 314
259 if (putenv("TERM=sun") != 0) /* TTYSW will be a TERM=sun window */ 315 if (putenv("TERM=sun") != 0) /* TTY_WIN will be a TERM=sun window */
260 {fprintf (stderr, "%s: Could not set TERM=sun, using `%s'\n", 316 {fprintf (stderr, "%s: Could not set TERM=sun, using `%s'\n",
261 argv[0], (char *)getenv("TERM")) ;}; 317 argv[0], (char *)getenv("TERM")) ;};
262 /* 318 /*
@@ -276,65 +332,169 @@ main (argc, argv)
276 } ; 332 } ;
277 333
278 /* find command to run as subprocess in window */ 334 /* find command to run as subprocess in window */
279 if (!(argv[0] = (char *)getenv("EMACSTOOL"))) /* Set emacs command name */ 335 if (!(argv[0] = (char *)getenv("EMACSTOOL"))) /* Set emacs command name */
280 argv[0] = emacs_name; 336 argv[0] = emacs_name;
337 /* Emacstool recognizes two special args: -rc <file> and -bold <bold-name> */
281 for (argc = 1; argv[argc]; argc++) /* Use last one on line */ 338 for (argc = 1; argv[argc]; argc++) /* Use last one on line */
282 if(!(strcmp ("-rc", argv[argc]))) /* Override if -rc given */ 339 {
283 { 340 if(!(strcmp ("-rc", argv[argc]))) /* Override if -rc given */
284 int i = argc; 341 {int i = argc;
285 argv[argc--]=0; /* kill the -rc argument */ 342 argv[argc--]=0; /* kill the -rc argument */
286 if (argv[i+1]) { /* move to agrv[0] and squeeze the rest */ 343 if (argv[i+1]) { /* move to argv[0] and squeeze the rest */
287 argv[0]=argv[i+1]; 344 argv[0]=argv[i+1];
288 for (; argv[i+2]; (argv[i]=argv[i+2],argv[++i]=0)); 345 for (; argv[i+2]; (argv[i]=argv[i+2],argv[++i]=0));
289 } 346 }
290 } 347 }
348
349 if (!(strcmp ("-bold", argv[argc])))
350 {int i = argc;
351 argv[argc--]=0; /* kill the -bold argument */
352 if (argv[i+1]) { /* move to bold_name and squeeze the rest */
353 bold_name = argv[i+1];
354 for (; argv[i+2]; (argv[i]=argv[i+2],argv[++i]=0));
355 }
356 }
357 };
291 358
292 strcpy (buffer, title); 359 strcpy (buffer, title);
293 strncat (buffer, argv[0], /* append run command name */ 360 strncat (buffer, argv[0], /* append run command name */
294 (BUFFER_SIZE - (strlen (buffer)) - (strlen (argv[0]))) - 1); 361 (BUFFER_SIZE - (strlen (buffer)) - (strlen (argv[0]))) - 1);
295 362
296 /* Build a frame to run in */ 363 error_code = interpose_on_window(argc,argv);
297 frame = window_create ((Window)NULL, FRAME, 364 if (error_code != 0) { /* Barf */
298 FRAME_LABEL, buffer, 365 fprintf (stderr, "notify_interpose_event_func returns %d.\n", error_code);
299 FRAME_ICON, frame_icon, 366 exit (1);
300 FRAME_ARGC_PTR_ARGV, &argc, argv, 367 }
301 0); 368
369#ifdef XVIEW
370 xv_main_loop (frame); /* And away we go */
371#else
372 window_main_loop (frame);
373#endif XVIEW
374}
302 375
303 /* Create a tty with emacs in it */ 376#ifdef XVIEW
304 ttysw = window_create (frame, TTY, 377int interpose_on_window(argc,argv)
378 int argc;
379 char **argv;
380{
381#ifndef TTERM
382 int i, font_width_adjust = 1; /* hackery, and hueristics */
383 /* if -Wt is not supplied, then font comes out as lucida-14 (width=8)
384 * rather than the screen.r.12 (width=7) typically used
385 * this hack attempts to workaround it.
386 * could use a env var EMACSTOOL_DEFAULT_FONT_WIDTH instead */
387 for (i = 1; argv[i]; i++) {
388 if (!(strcmp ("-Wt", argv[i])))
389 {font_width_adjust = 0;
390 if (console_fd) fprintf(console, "-Wt = %d\n", font_width_adjust);
391 break;}
392 }
393#endif TTERM
394 /* initialize Xview, and strip window args */
395 xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0);
396
397 /* do this first, so arglist can override it */
398 frame_icon = icon_create (ICON_LABEL, "Emacstool",
399 ICON_IMAGE, &icon_image,
400 0);
401
402 /* Build a frame to run in */
403 frame = xv_create ((Xv_Window)NULL, FRAME,
404 FRAME_LABEL, buffer,
405 FRAME_ICON, frame_icon,
406 0);
407
408 /* Create a tty with emacs in it */
409 tty_win = xv_create (frame, SWTYPE, WIN_IS_CLIENT_PANE,
305 TTY_QUIT_ON_CHILD_DEATH, TRUE, 410 TTY_QUIT_ON_CHILD_DEATH, TRUE,
306 TTY_BOLDSTYLE, 8, 411 TTY_BOLDSTYLE, TTYSW_BOLD_INVERT,
307 TTY_ARGV, argv, 412 TTY_ARGV, argv,
308 0); 413 0);
309 414
310 window_set(ttysw, 415 if (bold_name) {
311 WIN_CONSUME_PICK_EVENTS, 416 (void)xv_set(tty_win, TTY_BOLDSTYLE_NAME, bold_name, 0);
312 WIN_STOP, 417 }
313 WIN_MOUSE_BUTTONS, WIN_UP_EVENTS, 418
314 /* LOC_WINENTER, LOC_WINEXIT, LOC_MOVE, */
315 0,
316
317 WIN_CONSUME_KBD_EVENTS,
318 WIN_STOP,
319 WIN_ASCII_EVENTS,
320 WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
321 /* WIN_UP_ASCII_EVENTS, */
322 0,
323
324 0);
325
326 font_height = (int)window_get (ttysw, WIN_ROW_HEIGHT);
327 font_width = (int)window_get (ttysw, WIN_COLUMN_WIDTH);
328
329 /* Interpose my event function */
330 error_code = (int) notify_interpose_event_func
331 (ttysw, input_event_filter_function, NOTIFY_SAFE);
332
333 if (error_code != 0) /* Barf */
334 { 419 {
335 fprintf (stderr, "notify_interpose_event_func got %d.\n", error_code); 420 Xv_font font; /* declare temp font variable */
336 exit (1); 421 font = (Xv_font)xv_get (tty_win, XV_FONT);
422 font_height = (int)xv_get (font, FONT_DEFAULT_CHAR_HEIGHT);
423 font_width = (int)xv_get (font, FONT_DEFAULT_CHAR_WIDTH);
424 }
425 if (console_fd) fprintf(console, "Width = %d\n", font_width);
426
427#ifndef TTERM
428 font_width -= font_width_adjust; /* A guess! font bug in ttysw*/
429#else
430 /* make the termsw act as a tty */
431 xv_set(tty_win, TERMSW_MODE, TTYSW_MODE_TYPE, 0);
432 /* termsw has variable offset depending on scrollbar size/location */
433 left_margin = (int)xv_get (tty_win, TEXTSW_LEFT_MARGIN);
434#endif TTERM
435
436 tty_view = (Xv_Window) xv_get (tty_win, OPENWIN_NTH_VIEW, 0);
437 xv_set(tty_view,
438 WIN_CONSUME_EVENTS,
439 WIN_MOUSE_BUTTONS, WIN_UP_EVENTS,
440 ACTION_ADJUST, ACTION_MENU,
441 WIN_ASCII_EVENTS,
442 WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
443 0,
444 0);
445 /* Interpose my event function */
446 return (int) notify_interpose_event_func
447 (tty_view, input_event_filter_function, NOTIFY_SAFE);
448}
449#else
450int interpose_on_window (argc, argv)
451 int argc;
452 char **argv;
453{
454 /* do this first, so arglist can override it */
455 frame_icon = icon_create (ICON_LABEL, "Emacstool",
456 ICON_IMAGE, &icon_image,
457 0);
458
459 /* Build a frame to run in */
460 frame = window_create ((Window)NULL, FRAME,
461 FRAME_LABEL, buffer,
462 FRAME_ICON, frame_icon,
463 FRAME_ARGC_PTR_ARGV, &argc, argv,
464 0);
465
466 /* Create a tty with emacs in it */
467 tty_win = window_create (frame, TTY,
468 TTY_QUIT_ON_CHILD_DEATH, TRUE,
469 TTY_BOLDSTYLE, TTYSW_BOLD_INVERT,
470 TTY_ARGV, argv,
471 0);
472
473 if (bold_name) {
474 (void)window_set(tty_win, TTY_BOLDSTYLE_NAME, bold_name, 0);
337 } 475 }
338 476
339 window_main_loop (frame); /* And away we go */ 477 /* ttysw uses pf_default, one must set WIN_FONT explicitly */
478 window_set (tty_win, WIN_FONT, pf_default(), 0);
479 font_height = (int)window_get (tty_win, WIN_ROW_HEIGHT);
480 font_width = (int)window_get (tty_win, WIN_COLUMN_WIDTH);
481
482 tty_view = tty_win;
483 window_set(tty_view,
484 WIN_CONSUME_PICK_EVENTS,
485 WIN_STOP,
486 WIN_MOUSE_BUTTONS, WIN_UP_EVENTS,
487 /* LOC_WINENTER, LOC_WINEXIT, LOC_MOVE, */
488 0,
489 WIN_CONSUME_KBD_EVENTS,
490 WIN_STOP,
491 WIN_ASCII_EVENTS,
492 WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
493 /* WIN_UP_ASCII_EVENTS, */
494 0,
495 0);
496 /* Interpose my event function */
497 return (int) notify_interpose_event_func
498 (tty_view, input_event_filter_function, NOTIFY_SAFE);
340} 499}
500#endif XVIEW