home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
useful
/
util
/
edit
/
mg
/
src.lzh
/
amiga
/
ttyio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-23
|
29KB
|
1,218 lines
/*
* Name: MG 2a Amiga terminal window I/O, with all kinds o' trimmings.
* This module is 'way too big. Last Edit: 01-Dec-87
* mic@emx.cc.utexas.edu Created: 21-Apr-86 mic@emx.cc.utexas.edu
*/
#undef MANX
#undef LATTICE
#include "rexx.h"
#include "no_dir.h"
#include "compiler.h"
#include "change_font.h"
#include "v11.h"
#include "mouse.h"
#include "no_metakey.h"
#include "promptwait.h"
#include "nrow.h"
#include "ncol.h"
#include "init_cols.h"
#include "init_rows.h"
#include "do_menu.h"
#ifndef NO_METAKEY
#include "metabit.h"
#endif
#include "use_arp.h"
#ifdef USE_ARP
#include <arpfunctions.h>
#endif
/*
* Lots of includes.
*/
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/tasks.h>
#include <exec/ports.h>
#include <exec/io.h>
#include <devices/console.h>
#include <devices/inputevent.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <graphics/clip.h>
#include <graphics/view.h>
#include <graphics/rastport.h>
#include <graphics/layers.h>
#include <graphics/text.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#undef TRUE
#undef FALSE
#include "def.h" /* includes sysdef.h and ttydef.h */
#include "window.h"
#ifdef REXX
#include "key.h"
#endif
#ifdef CHANGE_FONT
#include <libraries/diskfont.h>
#endif
#ifdef LATTICE
#ifdef CHANGE_FONT
#include <proto/diskfont.h>
#endif
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/console.h>
#else
#include <functions.h>
#endif
#ifdef ANSI
#include <string.h>
#include <stdlib.h>
#endif
#ifdef USE_ARP
struct ArpBase *ArpBase;
#endif
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
#ifndef NO_DIR
extern struct Task *FindTask();
static BPTR StartLock;
char WindowTitle[MAXPATH + 20], *MyDirName;
#ifndef MANX
extern BPTR DupLock(), CurrentDir();
#endif
#endif /* NO_DIR */
#ifdef DO_MENU
extern struct Menu *InitEmacsMenu();
#endif
#ifndef LATTICE
extern int Enable_Abort; /* Do NOT allow abort! */
#endif
/*
* External MG functions and variables
*/
extern char version[]; /* Version information */
extern int ttrow; /* Current cursor row */
extern int use_metakey; /* Do meta characters? */
/*
* My own, internal functions
*/
static VOID amigaclean PROTO((void));
static void setmaxima PROTO((void));
static struct Screen *wbscreen PROTO((void));
static void ttreopen PROTO((int resize));
static int handle_kbd PROTO((int timeout));
static int dispatch PROTO((struct IntuiMessage * msg));
static int nextkey PROTO((void));
static void qkey PROTO((short k));
#ifdef MOUSE
static void qmouse PROTO((short x, short y, unsigned short qual));
#endif
#ifdef DO_MENU
static void qmenu PROTO((unsigned short code));
#endif
#ifdef MANX
/* these are in localproto.h, but this is not included for MANX3.6 */
VOID ttclose();
VOID setttysize();
VOID syscleanup();
VOID ttflush();
VOID panic();
#endif
/*
* Library bases (used by glue libraries)
*/
#ifndef LATTICE
#ifdef CHANGE_FONT
struct DiskFontBase * DiskfontBase;
#endif
#endif
/*
* Intuition window and menu variables. MG gets used a lot, because it gets
* reconfigured on the fly for the amiga-set-font and toggle-border
* operations.
*/
#define WINDOWGADGETS (WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE)
#define WINDOWFLAGS (WINDOWGADGETS | ACTIVATE)
struct NewWindow MG = {
0, 0, /* start position */
0, 0, /* width, height (set by ttopen) */
0, 1, /* detail pen, block pen */
#ifdef DO_MENU
MENUPICK | /* If menu is used */
#endif
#ifdef MOUSE
MOUSEBUTTONS | /* If mouse is used */
#endif
INTUITICKS | RAWKEY |
CLOSEWINDOW | NEWSIZE, /* IDCMP flags */
0, /* window flags (set by ttopen) */
NULL, /* pointer to first user gadget */
NULL, /* pointer to user checkmark */
NULL, /* title (filled in later) */
NULL, /* pointer to screen (none) */
NULL, /* pointer to superbitmap */
220, 40, /* minimum size (small!) */
0, 0, /* maximum size (set by ttopen) */
WBENCHSCREEN /* screen in which to open */
};
static short borderless = TRUE; /* Flag for borderless window */
static short toggle_zooms = TRUE; /* Does toggling border zoom? */
static int last_top, last_left, last_height, last_width;
struct Window *EmW = NULL; /* Our window */
struct Screen *EmS = NULL; /* Our screen (usually WB) */
short toggling = FALSE; /* Prevent menu wiping */
#ifndef V11
struct Screen WBInfo; /* Info about the WB screen */
#endif
struct TextFont *EmFont = NULL; /* Our font (usually TOPAZ_xx) */
#ifdef DO_MENU
static struct Menu *EmacsMenu = NULL; /* Our menu */
#endif
#if 0
static ULONG class; /* Intuition event */
static USHORT code, /* information */
qualifier;
static APTR address;
static SHORT x, y;
#endif /* 0 */
static LONG intuitionMsgMask;/* Signal Mask */
/* * * * * * * * * * * * * console I/O * * * * * * * * * * * * * * * * */
#define CSI 0x9b /* Command Sequence Introducer */
#define NOBUF 512 /* About 1/4 screen */
#define NIBUF 256 /* Input buffer */
static KCHAR ibuf[NIBUF]; /* keyboard input buffer */
static int ibufo, nibuf; /* head, # of bytes in ibuf */
static LONG tickcount; /* # intuiticks since last char */
static struct MsgPort *conWritePort = NULL; /* I/O ports */
static struct IOStdReq *conWriteMsg = NULL; /* I/O messages */
struct Library *ConsoleDevice; /* used by RawKeyConvert */
static unsigned char outbuf[NOBUF + 7]; /* output buffer */
static unsigned char *obuf; /* first output char */
int nobuf; /* # of bytes in above */
int nrow; /* Terminal size, rows. */
int ncol; /* Terminal size, cols. */
/* * * * * * * * * functions to open/reopen the window * * * * * * * * * */
/*
* Open up the virtual terminal MG communicates with. Set up the window,
* console, and menu strip.
*/
ttopen()
{
#ifndef LATTICE
Enable_Abort = 0; /* Disable ^C */
#endif
/* Set the window size, set the flags and title, and open it */
setmaxima();
MG.Flags = WINDOWFLAGS;
MG.Flags |= borderless ? BORDERLESS : WINDOWSIZING;
#ifndef NO_DIR
MG.Title = (UBYTE *) WindowTitle;
#else
MG.Title = (UBYTE *) version;
#endif
if ((EmW = OpenWindow(&MG)) == NULL)
amigaclean();
SetFont(EmW->RPort, EmFont);
/*
* Once the window is created, get the Intuition signal bit, set up
* the menu, and tell the virtual terminal how big it is.
*/
setttysize();
intuitionMsgMask = 1L << EmW->UserPort->mp_SigBit;
#ifdef DO_MENU
if (toggling == FALSE)
EmacsMenu = InitEmacsMenu(EmW);
if (EmacsMenu == NULL)
amigaclean();
SetMenuStrip(EmW, EmacsMenu);
#endif
/*
* Attach a console device (purely for output now) to our window
*/
if ((conWritePort = CreatePort("Emacs.con.write", 0L)) == NULL)
amigaclean();
if ((conWriteMsg = CreateStdIO(conWritePort)) == NULL)
amigaclean();
if (OpenConsole(conWriteMsg, NULL, EmW) != 0)
amigaclean();
ConsoleDevice = (struct Library *) conWriteMsg->io_Device;
nibuf = ibufo = 0;
return (0);
}
/*
* Set up the initial state of the window. Opens up libraries, decides how
* big the initial window should be, and whether it should be borderless.
*/
VOID
sysinit()
{
#ifndef NO_DIR
long len;
BPTR MyDirLock;
#endif
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L);
if (GfxBase == NULL) /* Graphics lib */
amigaclean();
IntuitionBase = (struct IntuitionBase *) /* Intuition */
OpenLibrary("intuition.library", 0L);
if (IntuitionBase == NULL)
amigaclean();
#ifdef USE_ARP
if (!(ArpBase = (struct ArpBase *) OpenLibrary("arp.library", 0L)))
panic("Compiled with USE_ARP, but arp.library not found");
#endif
#ifdef REXX
openrexx();
#endif
#ifndef NO_DIR
/*
* The following attempt to be clever assigns the external StartLock
* to the lock on the current directory, then switches our CurrentDir
* to a duplicate of that lock so we can restore the original lock on
* exit.
*/
strcpy(WindowTitle, version);
strcat(WindowTitle, ": ");
MyDi