Annotation of gcl520h/emulator.h, revision 1.1.1.1

1.1       root        1: #ifndef EMULATOR_DOT_H
                      2: #define EMULATOR_DOT_H
                      3: 
                      4: /*
                      5:  * EMULATOR.H       5.20A  June 8, 1995
                      6:  *
                      7:  * The Greenleaf Comm Library
                      8:  *
                      9:  * Copyright (C) 1985-1995 Greenleaf Software Inc.  All Rights Reserved.
                     10:  *
                     11:  * NOTES
                     12:  *
                     13:  *  This is the master include file for CommLib terminal emulation.
                     14:  *  The important thing needed here is the definiton of the EMULATOR
                     15:  *  structure, which carries around all of the information needed to
                     16:  *  run an emulator.
                     17:  *
                     18:  * MODIFICATIONS
                     19:  *
                     20:  * Jun 8, 1995  5.20A : Initial release
                     21:  */
                     22: 
                     23: /*
                     24:  * I need to include video.h in order to pick up the definitions
                     25:  * of the VID_WINDOW objects for my function prototypes.  Note that
                     26:  * I also need definitions of HWND and HANDLE for my canned terminal
                     27:  * objects I use under Windows and Win32 console mode.
                     28:  */
                     29: 
                     30: #include "video.h"
                     31: 
                     32: /*
                     33:  * I do some funny things with structure definitions in order to
                     34:  * make all this stuff work in a C++ like fashion.  The basic deal
                     35:  * is that is defined here a core structure called EMULATOR that contains
                     36:  * all of the base class definitions used for terminal emulation.
                     37:  * Derived classes, such as the Ansi emulation class, will define
                     38:  * a copy of EMULATOR that starts with all the same data, but addes
                     39:  * new data members onto the end.
                     40:  *
                     41:  * Here is the way you do it:
                     42:  *
                     43:  * #define EMULATOR struct _my_emulator
                     44:  * struct _my_emulator;
                     45:  *
                     46:  * #include "emulator.h"
                     47:  * #include "_emu.h"
                     48:  *
                     49:  * struct _my_emulator {
                     50:  *   EMULATOR_MEMBERS;
                     51:  *   int my_data_1;
                     52:  *   int ...
                     53:  * };
                     54:  *
                     55:  *  The macro called EMULATOR_MEMBERS contains all of the members that
                     56:  *  have to be placed at the start of the structure.
                     57:  *
                     58:  *  So this goofy arrangement means that inside my emulator code, I can
                     59:  *  do things like this:
                     60:  *
                     61:  *  foo ( EMULATOR *e )
                     62:  *  {
                     63:  *    ClearWindow( e );
                     64:  *    ...
                     65:  *
                     66:  *  Even though the structure I am using isn't exactly the same as the
                     67:  *  base version of EMULATOR, I can be secure in my knowledged that the
                     68:  *  pointer to the clear_window function is in the same place.
                     69:  *
                     70:  *  I also let you play around with the members that point to the
                     71:  *  keyboard and video data.  These have to be the same size as
                     72:  *  regular pointers, or the size of the EMULATOR structure
                     73:  *  will change, leading to disaster.
                     74:  *
                     75:  *  The only reason I let you override these is to provide full
                     76:  *  type safety in Attach...() routines.  A routine like
                     77:  *  VidPutc( VID_WINDOW *v ) can be safely assigned to emulator member
                     78:  *  vputc like this:
                     79:  *
                     80:  *  #define VIDEO_TYPE VID_WINDOW *
                     81:  *  #include "emulator.h"
                     82:  *
                     83:  *  Attach...()
                     84:  *  {
                     85:  *      emulator->vputc = VidPutc.
                     86:  *
                     87:  *  This trick means I get the compiler to perform type checking when
                     88:  *  I do this assignement.  Without it, I would have to use void pointers
                     89:  *  everywhere, and I would lose all my type safety that I worked so
                     90:  *  hard to gain.
                     91:  *
                     92:  *  Unfortunately, things are quite this easy when I pass something funky
                     93:  *  like an HWND.  In those cases, I had to resort to void pointers.
                     94:  *
                     95:  */
                     96: 
                     97: #if !defined(  EMULATOR )
                     98: #define EMULATOR struct _emulator
                     99: #endif
                    100: 
                    101: #if !defined( VIDEO_TYPE )
                    102: #define VIDEO_TYPE void GF_DLL_FAR *
                    103: #endif
                    104: 
                    105: #if !defined( KEYBOARD_TYPE )
                    106: #define KEYBOARD_TYPE void GF_DLL_FAR *
                    107: #endif
                    108: 
                    109: /*
                    110:  * The base class has built in support for keyboard macros and incoming
                    111:  * triggers.  They are both stored in linked lists of structures that
                    112:  * are defined here.  Note that derived classes are free to override
                    113:  * these, but if I did my job correctly, they shouldn't have to.
                    114:  */
                    115: 
                    116: struct _incoming_cmd_def {
                    117:     struct _incoming_cmd_def GF_DLL_FAR *next_cmd;
                    118:     int command;
                    119:     char GF_DLL_FAR *string;
                    120: };
                    121: 
                    122: struct _kbd_macro_def {
                    123:     struct _kbd_macro_def GF_DLL_FAR *next_macro;
                    124:     int key;
                    125:     char GF_DLL_FAR *s;
                    126: };
                    127: 
                    128: /*
                    129:  * The members that show up at the start of the emulator
                    130:  * structur, regardless of what follows.
                    131:  */
                    132: 
                    133: #define EMULATOR_MEMBERS                                                   \
                    134:     PORT GF_DLL_FAR *port;                                                 \
                    135:     VIDEO_TYPE video;                                                      \
                    136:     KEYBOARD_TYPE keyboard;                                                \
                    137:     char trace[ 16 ];                                                      \
                    138:     int trace_index;                                                       \
                    139:     char triggers[ 256 ];                                                  \
                    140:     struct _incoming_cmd_def GF_DLL_FAR *first_incoming_cmd_def;           \
                    141:     struct _kbd_macro_def GF_DLL_FAR *first_kbd_macro;                     \
                    142:     int test_mode;                                                         \
                    143:     int input_mask;                                                        \
                    144:     char GF_DLL_FAR *current_key;                                          \
                    145:     int ( GF_CONV *process_keyboard )( EMULATOR GF_DLL_FAR *emulator );    \
                    146:     int ( GF_CONV *process_input )( EMULATOR GF_DLL_FAR *emulator );       \
                    147:     void ( GF_CONV *destroy )( EMULATOR GF_DLL_FAR *emulator );            \
                    148:     int ( GF_CONV *read_raw_key )( EMULATOR GF_DLL_FAR *emulator );        \
                    149:     void ( GF_CONV *clear_window )( VIDEO_TYPE v );                        \
                    150:     void ( GF_CONV *clear_to_eol )( VIDEO_TYPE v );                        \
                    151:     void ( GF_CONV *goto_rc )( VIDEO_TYPE v, int row, int col );           \
                    152:     void ( GF_CONV *vputc )( VIDEO_TYPE v, int c );                        \
                    153:     void ( GF_CONV *vputs )( VIDEO_TYPE v, char GF_DLL_FAR *s );           \
                    154:     void ( GF_CONV *vset_normal )( VIDEO_TYPE v );                         \
                    155:     void ( GF_CONV *vset_reverse )( VIDEO_TYPE v );                        \
                    156:     void ( GF_CONV *vset_bold )( VIDEO_TYPE v );                           \
                    157:     void ( GF_CONV *vset_blink )( VIDEO_TYPE v );                          \
                    158:     void ( GF_CONV *vset_underline )( VIDEO_TYPE v );                      \
                    159:     void ( GF_CONV *vset_invisible )( VIDEO_TYPE v );                      \
                    160:     void ( GF_CONV *vset_foreground )( VIDEO_TYPE v, int c );              \
                    161:     void ( GF_CONV *vset_background )( VIDEO_TYPE v, int c );              \
                    162:     void ( GF_CONV *vset_wrap )( VIDEO_TYPE v, int f );                    \
                    163:     void ( GF_CONV *vbeep )( VIDEO_TYPE v );                               \
                    164:     int ( GF_CONV *row )( VIDEO_TYPE v );                                  \
                    165:     int ( GF_CONV *col )( VIDEO_TYPE v );                                  \
                    166:     int ( GF_CONV *rows )( VIDEO_TYPE v );                                 \
                    167:     int ( GF_CONV *cols )( VIDEO_TYPE v );                                 \
                    168:     int ( GF_CONV *define_kbd_macro )( EMULATOR GF_DLL_FAR *e, int key, char GF_DLL_FAR *string );   \
                    169:     int ( GF_CONV *undefine_kbd_macro )( EMULATOR GF_DLL_FAR *e, int key );                          \
                    170:     int ( GF_CONV *define_incoming_cmd )( EMULATOR GF_DLL_FAR *e, char GF_DLL_FAR *s, int cmd );     \
                    171:     int ( GF_CONV *undefine_incoming_cmd )( EMULATOR GF_DLL_FAR *e, char GF_DLL_FAR *s );            \
                    172:     void ( GF_CONV *debug_trace )( int c )
                    173: 
                    174: /*
                    175:  * The default emulator structure.
                    176:  */
                    177: 
                    178: struct _emulator {
                    179:     EMULATOR_MEMBERS;
                    180: };
                    181: 
                    182: /*
                    183:  * Here is how we call the virtual functions in
                    184:  * an easier to read manner.  Macros.
                    185:  */
                    186: 
                    187: #define ProcessKeys( e ) e->process_keyboard( e )                /* Tag: Terminal Public  */
                    188: #define ReadRawKey( e ) e->read_raw_key( e )                     /* Tag: Terminal Private */
                    189: #define ProcessInput( e ) e->process_input( e )                  /* Tag: Terminal Public  */
                    190: #define SetNormal( e ) e->vset_normal( e->video )                /* Tag: Terminal Private */
                    191: #define SetReverse( e ) e->vset_reverse( e->video )              /* Tag: Terminal Private */
                    192: #define SetBold( e ) e->vset_bold( e->video )                    /* Tag: Terminal Private */
                    193: #define SetBlink( e ) e->vset_blink( e->video )                  /* Tag: Terminal Private */
                    194: #define SetUnderline( e ) e->vset_underline( e->video )          /* Tag: Terminal Private */
                    195: #define SetInvisible( e ) e->vset_invisible( e->video )          /* Tag: Terminal Private */
                    196: #define SetBackground( e, c ) e->vset_background( e->video, c )  /* Tag: Terminal Private */
                    197: #define SetForeground( e, c ) e->vset_foreground( e->video, c )  /* Tag: Terminal Private */
                    198: #define ClearWindow( e ) e->clear_window( e->video )             /* Tag: Terminal Private */
                    199: #define ClearToEol( e ) e->clear_to_eol( e->video )              /* Tag: Terminal Private */
                    200: #define GotoRc( e, r, c ) e->goto_rc( e->video, r, c )           /* Tag: Terminal Private */
                    201: #define Row( e ) e->row( e->video )                              /* Tag: Terminal Private */
                    202: #define Col( e ) e->col( e->video )                              /* Tag: Terminal Private */
                    203: #define Rows( e ) e->rows( e->video )                            /* Tag: Terminal Private */
                    204: #define Cols( e ) e->cols( e->video )                            /* Tag: Terminal Private */
                    205: #define SetWrap( e, f ) e->vset_wrap( e->video, f )              /* Tag: Terminal Private */
                    206: #define Beep( e ) e->vbeep( e->video )                           /* Tag: Terminal Private */
                    207: #define DestroyEmulator( e ) e->destroy( e )                     /* Tag: Terminal Public  */
                    208: #define Putc( e, c ) e->vputc( e->video, c )                     /* Tag: Terminal Private */
                    209: #define Puts( e, s ) e->vputs( e->video, s )                     /* Tag: Terminal Private */
                    210: #define DefineKeyboardMacroString( e, k, s ) e->define_kbd_macro( e, k, s ) /* Tag: Terminal Public  */
                    211: #define DefineKeyboardMacroCommand( e, k ) e->define_kbd_macro( e, k, 0 )   /* Tag: Terminal Public  */
                    212: #define UndefineKeyboardMacro( e, k ) e->undefine_kbd_macro( e, k )         /* Tag: Terminal Public  */
                    213: #define DefineIncomingCommand( e, s, c ) e->define_incoming_cmd( e, s, c )  /* Tag: Terminal Public  */
                    214: #define UndefineIncomingCommand( e, s ) e->undefine_incoming_cmd( e, s )    /* Tag: Terminal Public  */
                    215: /*
                    216:  * This helps fix a documentation error.
                    217:  */
                    218: #define UndefineIncomingCmd( e, s ) e->undefine_incoming_cmd( e, s )    /* Tag: Terminal Public  */
                    219: 
                    220: #ifdef __cplusplus
                    221: extern "C" {
                    222: #endif
                    223: 
                    224: /*
                    225:  * For right now, I am including all the prototypes for each
                    226:  * and every derived class.  When we have more video types and
                    227:  * more emulators, some of these things will have to be broken
                    228:  * out into separate header files.
                    229:  */
                    230: 
                    231: /*
                    232:  * All of the supported emulators:  Just 1!  We do need to add
                    233:  * basic TTY emulation.  A patch maybe?
                    234:  */
                    235: 
                    236: EMULATOR GF_DLL_FAR * GF_CONV CreateAnsiEmulator( PORT GF_DLL_FAR *p );
                    237: 
                    238: /*
                    239:  * The two functions for Greenleaf Text based Vid Windows.  The generic attach
                    240:  * function, and the shortcut function that creates *and* attaches.
                    241:  */
                    242: 
                    243: void GF_CONV AttachVidToEmulator( EMULATOR GF_DLL_FAR *e,
                    244:                                   VID_WINDOW GF_DLL_FAR *w );
                    245: EMULATOR * GF_CONV CreateAnsiVidEmulator( PORT *p, VID_WINDOW *w );
                    246: 
                    247: /*
                    248:  * The two functions for Greenleaf WinVid Windows for Win16 and Win32.
                    249:  * The generic attach function, and the shortcut function that creates
                    250:  * *and* attaches.
                    251:  */
                    252: 
                    253: #ifdef GF_WINDOWS
                    254: EMULATOR GF_DLL_FAR * GF_CONV CreateAnsiGFTermEmulator( PORT GF_DLL_FAR *p,
                    255:                                                         HWND hWnd );
                    256: void GF_CONV AttachGFTermToEmulator( EMULATOR GF_DLL_FAR *e, HWND hWnd );
                    257: #endif
                    258: 
                    259: /*
                    260:  * The two functions for Greenleaf Win32 native console mode.
                    261:  * The generic attach function, and the shortcut function that creates
                    262:  * *and* attaches.  Plus, one simple API function to help those
                    263:  * Win32 programmers.
                    264:  */
                    265: 
                    266: #ifdef GF_WIN32
                    267: void GF_CONV AttachConsoleToEmulator( EMULATOR GF_DLL_FAR *e,
                    268:                                      HANDLE hInput,
                    269:                                      HANDLE hOutput );
                    270: EMULATOR GF_DLL_FAR * GF_CONV
                    271: CreateAnsiConsoleEmulator( PORT GF_DLL_FAR *p,
                    272:                            HANDLE hInput,
                    273:                            HANDLE hOutput );
                    274: void GF_CONV ConsumeAllConsoleInput( EMULATOR GF_DLL_FAR *e,
                    275:                                      int flag );
                    276: #endif
                    277: 
                    278: #ifdef __cplusplus
                    279: }
                    280: #endif
                    281: 
                    282: #endif /* #ifndef EMULATOR_DOT_H */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.