/*1Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.2All rights reserved.34Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are6met:78- Redistributions of source code must retain the above copyright9notice, this list of conditions and the following disclaimer.1011- Redistributions in binary form must reproduce the above copyright12notice, this list of conditions and the following disclaimer in13the documentation and/or other materials provided with the14distribution.1516- Neither the name of The Numerical ALgorithms Group Ltd. nor the17names of its contributors may be used to endorse or promote products18derived from this software without specific prior written permission.1920THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER24OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,25EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233extern int contNum;34extern struct termios childbuf; /** the childs normal operating termio ***/3536/*** the terminals mapping of the function keys ***/37extern unsigned char _INTR, _QUIT, _ERASE, _KILL, _EOF, _EOL, _RES1, _RES2;38extern short INS_MODE ; /** Flag for insert mode **/39extern short ECHOIT; /** Flag for echoing **/40extern short PTY; /* A flag which lets me know whether or not I am41talking to a socket or a pty. If I am not42talking to a PTY then I have to do things like echo43back newlines, and send interuppts with an eoln44*/45/***************************************************************************46Here are the key mapping my routines need47****************************************************************************/484950#define _ESC 0X1B /** A character sent before every arrow key ***/51#define _LBRACK 0X5B /** [ **/52#define _EOLN '\n' /** eoln **/53#define _CR 0X0D /** cr **/54#define _BLANK 0X20 /** blank **/55#define _BKSPC 0X08 /** backspace **/56#define _DEL 0X7F /** delete **/57#define _BELL 0X07 /*** ring the bell **/58#define _INT 0X7F /*** interrupt **/59#define _SQUASH 0X03 /** kill my process **/60#define _CNTRL_W 0X17 /** cntrl-w, to back up a word **/61#define _CARROT 0X5E /** circumflex **/62#define _TAB 0X09 /** tab forward **/6364#ifndef WCT65#define _A 0X41 /** A **/66#define _B 0X42 /** B **/67#define _C 0X43 /** C **/68#define _D 0X44 /** D **/69#define _Z 0X5A /** Z **/70#define _H 0X48 /** H **/71#define _M 0X4D /** M **/72#define _x 0X78 /** x **/73#define _z 0X7A /*** z **/74#define _twiddle 0X7E /*** ~ **/75#define _P 0X50 /*** P **/76#define _1 0X31 /*** 1 **/77#define _2 0X32 /*** 2 **/78#define _3 0X33 /*** 3 **/79#define _4 0X34 /*** 4 **/80#define _5 0X35 /*** 5 **/81#define _6 0X36 /*** 6 **/82#define _7 0X37 /*** 7 **/83#define _8 0X38 /*** 8 **/84#define _9 0X39 /*** 9 **/85#define _0 0X30 /*** 0 **/86#define _q 0X71 /*** q **/87#endif88899091#define MAXLINE 1024 /** maximum chars. on a line ***/92#define MAXBUFF 64 /** maximum lines saved in the buffer93queue ***/9495/*** Here are the constants for my three different modes. ******/96#define CLEFRAW 097#define CLEFCANONICAL 198#define CLEFCBREAK 299100extern int mode; /** One of the above # defines *****/101102/** Here is the structure for storing bound pf-keys ***/103typedef struct Fkey104{105const char *str;106short type;107} fkey;108109extern fkey function_key[13] ; /** strings which replace function110keys when a key is hit ***/111112113extern char editorfilename[];114115/**** Here are a bunch of constant, variable and function defs for edin.c */116#define UP 0 /** Tells the replace buffer command ***/117#define DOWN 1 /** to look up or down **/118119#define inc(x) ((x+1)%MAXBUFF) /** returns the increment of the presented120pointer ***/121#define dec(x) ( ((x-1) < 0) ?(MAXBUFF - 1):(x-1))/** ibid for decrementing */122123#define flip(x) (x?(x=0):(x=1)) /*** flip the bit ***/124125/*126All the previous commands will now be stored in a double linked list.127This way when I type a command I just have to circle through this list128*/129typedef struct que_struct {130char buff[1024];131int flags[1024];132struct que_struct *prev, *next;133} QueStruct;134135typedef struct wct {136char *fname;137off_t fsize;138time_t ftime;139char *fimage;140int wordc;141char **wordv;142143struct wct *next;144} Wct;145146typedef struct wix {147Wct *pwct;148int word;149} Wix;150151152extern QueStruct *ring;153extern QueStruct *current;154extern int ring_size;155extern int prev_check;156extern int MAXRING;157158extern char buff[MAXLINE]; /** Buffers for collecting input and **/159extern int buff_flag[MAXLINE]; /** flags for whether buff chars160are printing161or non-printing **/162163extern char in_buff[1024]; /** buffer for characters read until they are164processed **/165extern int num_read;166extern int num_proc; /** num chars processed after a read **/167extern int buff_pntr; /** present length of buff **/168extern int curr_pntr; /** the current position in buff **/169170/** Here are a bunch of macros for edin.c. They are mostly just charcter171comparison stuff ***/172#define back_word(x) (((*(x) == _5) && (*(x+1) == _9) && \173(*(x+2) == _q))?(1):(0))174175#define fore_word(x) (((*(x) == _6) && (*(x+1) == _8) && \176(*(x+2) == _q))?(1):(0))177178#define alt_f1(x) (((*(x) == _3) && (*(x+1) == _7) && \179(*(x+2) == _q))?(1):(0))180181#define cntrl_end(x) (((*(x) == _4) && (*(x+1) == _8) && \182(*(x+2) == _q))?(1):(0))183184#define insert_toggle(x) (((*(x) == _3) && (*(x+1) == _9) && \185(*(x+2) == _q))?(1):(0))186187#define end_key(x) (((*(x) == _4) && (*(x+1) == _6) && \188(*(x+2) == _q))?(1):(0))189190#define control_char(x) \191(((x >= 0x01) && (x <= 0x1a))?(1):(0))192193194195/***196Some global defs needed for emulating a pty. This was taken from guru.h197***/198199200201/* Return an integer that is represented by a character string */202#define ciret(x) ((cintu.c4[0]=(x)[0]), (cintu.c4[1]=(x)[1]), \203(cintu.c4[2]=(x)[2]), (cintu.c4[3]=(x)[3]), cintu.i4)204205/* move an integer (x) to a character string (y) */206207#define icmove(x, y) ((cintu.i4=(x)), ((y)[0]=cintu.c4[0]), \208((y)[1]=cintu.c4[1]), ((y)[2]=cintu.c4[2]), \209((y)[3]=cintu.c4[3]))210211/* Return an integer that may not be on an integer boundary */212#define iiret(x) ciret(((char *)&(x)))213214/* Min of two expressions */215#define min(x, y) ((x)<(y)?(x):(y))216217/* Max of two expressions */218#define max(x, y) ((x)>(y)?(x):(y))219220221222223224