/*      global.h                               26.04.95       */
/*
/  --------------------------------------------------------------
/  Copyright (C) 1993: Michael Braun
/                      Kaetinger Muehlenweg 103 A
/                      D-28816 Stuhr
/  --------------------------------------------------------------
/
/    global header file for mbedit.c (publics / externals)
/
*/


/************************/
/* often used macros    */
/************************/


/************************/
/* some defines         */
/************************/

#define VERSION_DATE    "26.04.95"     /* <= modify here !! */
#define VERSION_TEXT_3  "7.47"         /* <= modify here !! */

#define VERSION_TEXT_1  "mbedit "

#if (DEMO_VERSION == 0)
#define VERSION_TEXT_2  "V"     /* Version */
#endif

#if (DEMO_VERSION == 1)
#define VERSION_TEXT_2  "S"     /* Shareware */
#endif

#if (DEMO_VERSION == 2)
#define VERSION_TEXT_2  "D"     /* Demo */
#endif



#define LINE_OFFSET    1  /* mbedit counts rows, lines internally from 0, */
                          /* display starts from 1 */

#define CURSOR_STABIL  1  /* page up/down doesn't move the cursor position */
                          /* on the screen (except at begin and end of file) */

                          /* relation between cursor position in the memory */
                          /* and on the screen */
#define REL_COLUMN    (fc->column - fc->left_col)


/************************/
/* often used defines   */
/************************/


/************************/
/*  structures          */
/************************/

struct FILE_CONTROL {
       /* bei init nicht anfassen ... */
          char filename [BUF_256];  /* name of datafile in work */
          char FA_HU * buff_0; /* pointer to start of edit-buffer */
          long buffer_size;    /* actual length of buffer */
          int  malloc_flag;    /* 1 = buffer is available */
          int  left_col;       /* left visible column on screen (default: 0) */

#if WINDOW_COMMAND
          int  wind_arow [3];  /* row index in both windows */
          long wind_index[3];  /* index of file in both windows */
#endif
          int  syntax_flag;    /* 0=OFF, 1=comments, 2=keywords, 3=both */

       /* bei init definiert setzen */
          char FA_HU * buffer; /* pointer to actual byte in edit-buffer */
          long tag_index [4];  /* -1 = undefined */
          int  buff_no;        /* 0/1 (= act_buff_no [act_window]) */
          long find [2];       /* first and (last+1) char of find string */
 
       /* bei init loeschen ... */
          long byte_anz;       /* total no of bytes */
          long byte_index;     /* index of actual byte */
          long top_left;       /* index of upper left corner on screen */
          long lin_left;       /* index of left byte on actual line */
 
          long line_anz;       /* total no of lines in buffer */
          long line_index;     /* no of actual line */

          int  view_only;      /* 1 = file must no be modified */
          int  change_flag;    /* 1 = file has been modified */
          int  arow;           /* actual row    (0 ... 22) of cursor */
                               /* relative to begin of window */
          int  column;         /* actual column (0 ... 79) of cursor */
       };

#if (WITH_LAST_AGAIN)
struct MINI_CONTROL {
          char filename [BUF_256];  /* name of datafile in work */
          long byte_index;     /* index of actual byte */
          int  view_only;      /* 1 = file must no be modified */
       };
#endif

#define lrow   arow+MIN_ROW    /* relative to begin of screen */


/************************/
/*  public variables    */
/************************/

#undef pubext
#ifdef _GLOBAL_
#define pubext
#else
#define pubext extern
#endif


pubext char copyright_text []
#ifdef _GLOBAL_
        = {"Copyright (C) 1992 - 1995  /  Michael Braun"}
#endif
;

/* structure for file control */
#define MAX_FC_NUM 10     /* max. anzahl von edit-files */
pubext int act_window;       /* 0 : normal mode       */
                             /* 1 : window mode oben  */
                             /* 2 : window mode unten */
pubext int act_buff_no [3];  /* index: act_window */
pubext int same_buffer;      /* 1 = window 1 + 2 contain same buffer */

pubext int w_top [3]         /* window top */
#ifdef _GLOBAL_
   = { 0, 0, 0 } 
#endif
;

pubext int w_bot [3]         /* window bottom */
#ifdef _GLOBAL_
   = { INIT_ROWS-1, INIT_ROWS-1, INIT_ROWS-1 } 
#endif
;

pubext struct FILE_CONTROL file_control [MAX_FC_NUM];
pubext struct FILE_CONTROL *fc;        /* actual file control */

#if (WITH_LAST_AGAIN)
pubext int mini_file_num;
pubext struct MINI_CONTROL mini_control [MAX_FC_NUM];
#endif


/* operation mode */
pubext int  mode_flag;            /* 0 : command  */
                                  /* 1 : insert   */
                                  /* 2 : exchange */

#define MODE_TEXT_0 "mode: \"command\" - <F1>: Help Info"
#define MODE_TEXT_1 "mode: \"insert\" - leave with <esc>"
#define MODE_TEXT_2 "mode: \"exchange\" - leave with <esc>"
#define MODE_TEXT_3 "Hex View: cursor keys, <esc>, Edit"
#define MODE_TEXT_4 "Hex Edit: cursor keys, <esc>, <tab>, value"

pubext char *mode_text []
#ifdef _GLOBAL_
                                /* mode_flag */
               = { MODE_TEXT_0      /* 0 */
                  ,MODE_TEXT_1      /* 1 */
                  ,MODE_TEXT_2      /* 2 */
#if (WITH_HEX_VIEW)
                  ,MODE_TEXT_3      /* 3 */
                  ,MODE_TEXT_4      /* 4 */
#endif
                 }
#endif
;

#if (ACT_SERVER == SERVER_VT_100)
pubext int text_area;          /* == 0: text area */
                               /* >= 1: status line or history window */
#endif


/* buffer for ^A, ^X, ^Z, ^U */
struct SAVE_U {int  anz;
             int  index;
             int  command;
             char buffer [BUF_256];
             };
pubext struct SAVE_U save_u;


/* buffer for exchange/backspace */
struct SAVE_X {int  index;
               char buffer [BUF_256];
               };
pubext struct SAVE_X save_x;

/* buffer for buffer/delete */
struct SAVE_D {int  toggle;
               long index0;
               long index1;
               };
pubext struct SAVE_D save_d;

/* settings */
struct SETTINGS {int  autonl;
                 int  bak_file;
                 int  c_case;
                 int  display;
                 char e_delimit [BUF_256];
                 int  go;
                 int  highbit;
                 int  indent;
                 int  file_num;
                 int  k_token;
                 int  margin [3];
                 int  notab;
                 int  radix;
                 int  showfind;
                 int  tabs;
                 int  viewrow;
                 int  warning;
                 int  wildcards;
                 int  tilde_home;
                };


#define TOKEN_DELIMITERS "!\"#%&\'()*+,-./:;<=>?@[\\]^`{|}~"

/* Wenn die String-Konstante direkt in die Struktur  */
/* eingetragen wird, meldet der Microsoft-c-Compiler */
/* im "nicht - _GLOBAL_ - Fall" hier:                */
/* warning: unescaped newline in nonactive code      */
/* ursache : das \"                                  */

pubext struct SETTINGS set
#ifdef _GLOBAL_
              = {                         /* X  implemented */
                                     0,   /* X  Autonl      */
                                     1,   /* X  Bak_file    */
                                     0,   /* X  Case        */
                                     1,   /* X  Display     */
                      TOKEN_DELIMITERS,   /* X  E_delimit   */
                                     0,   /* -  Go          */
                                     0,   /* X  Highbit     */
                                     1,   /* X  Indent      */
                                     2,   /* X  File_num    */
                                     0,   /* X  K_token     */
                              4, 0, 76,   /* X  Margin      */
                                     1,   /* X  Notab       */
                                   'D',   /* X  Radix       */
                                     0,   /* X  Showfind    */
                                     8,   /* X  Tabs        */
                     (5 - LINE_OFFSET),   /* X  Viewrow     */
                                     2,   /* X  Warning     */
                                     0,   /* X  Wildcards   */
                                     0,   /* X  Tilde Home  */
                }
#endif
;

pubext int line_2_flag;           /* 0 : line_2 unchanged, suppress display */
                                  /* 1 : line_2 modified, display mode_text */
                                  /* 2 : line_2 contains other text,        */
                                  /*     (e.g. an error message)            */
                                  /*     keep until next key is pressed     */

#if (ACT_OP_SYSTEM != MS_DOS)
pubext int esc_waittime
#ifdef _GLOBAL_
            = { 
                ESC_WAITTIME
              }
#endif
;
#endif

/* -FF-  */

/* variable screen dimensions */

struct SCREEN { int rows;
                int columns;
              };

pubext struct SCREEN screen
#ifdef _GLOBAL_
            = { INIT_ROWS,
                INIT_COLUMNS
              }
#endif
;

#define ROWS           screen.rows
#define COLUMNS        screen.columns

#define STATUS_LINES   2
#define TOP_ROW        (w_top[act_window])
#define BOT_ROW        (w_bot[act_window])
#define MIN_ROW        (TOP_ROW)
#define MAX_ROW        (BOT_ROW - STATUS_LINES)

/* -FF-  */

/* fuer switches.c, disp_hnd.c */

pubext char str_calc [BUF_256];         /* for "Calc"               */
pubext char str_syst [BUF_256];         /* for "!system" + "qh ..." */
pubext char str_find [BUF_256];         /* for "Find", "Replace" */
pubext char str_repl [BUF_256];         /* for "Find", "Replace" */
pubext char str_numb [BUF_256];         /* for "Set Leftcol,..." */
pubext char str_q_i1 [BUF_256];         /* for "Quit" "Init"     */
pubext char str_q_i2 [BUF_256];         /* for "Quit" "Init"     */
pubext char str_q_wr [BUF_256];         /* for "Quit" "Write"    */
pubext char str_getf [BUF_256];         /* for "Get"             */
pubext char str_putf [BUF_256];         /* for "Put"             */
pubext char str_macr [BUF_256];         /* for "Macro Create/Execute" */
pubext char str_getm [BUF_256];         /* for "Macro Get"            */

/* -FF-  */

/* Modification History */
/* 24.11.92 - main_loop () */
/* 25.11.92 - perform_key_... () */
/* 26.11.92 - get_total_lines () */
/* 27.11.92 - insert, exchange */
/* 29.11.92 - valid_char () */
/* 30.11.92 - perform_view () */
/* 01.12.92 - perform_find () */
/* 04.12.92 - err_read_file () */
/* 07.12.92 - LINE_OFFSET */
/* 19.12.92 - FILE_CONTROL.filename [BUF_256]   (wg. "..\..\lib\<filename.ext>") */
/* 19.12.92 - FA_HU (far / huge) */
/* 20.12.92 - pubext other_fc (vorher static in mbedit.c) */
/* 21.12.92 - int mode_flag (vorher char) */
/* 03.01.93 - MACRO_NESTING_TO_DEEP */
/* 17.06.93 - Version 3.3: fore- and background-color from macro-file */
/* 18.06.93 - set.warning */
/* 08.09.93 - fc.find[2] */
/* 12.09.93 - DEMO_VERSION */
/* 03.10.93 - FILE_CONTROL.same_file, .other_row, .other_index */
/* 11.12.93 - VERSION_TEXT_1, _2, _3 */
/* 19.02.94 - Status Line 2 jetzt ueber volle laenge (disp_hnd.c, mon_outp.c) */
/*            versions-kennung jetzt mit 2 nachkommastellen */
/* 11.03.94 - siehe commands.c */
/* 06.05.94 - microsft.c: ltoa: sonderfall value = 0, bei radix 2 */
/* 09.05.94 - switches.c: 'P'aragraph: LOCK_WHEN_VIEW_ONLY */
/* 09.05.94 - macro.c, kb_input.c: esc_waittime */
/* 10.05.94 - div. modifications for hp-ux, */
/*            macro.c: reverse search for macro file */
/* 21.06.94 - macro.c: new entry in key_tab []: 0x7f */
/* 29.06.94 - set.tilde_home */
/* 31.08.94 - mbedit.c: take over new_lines + new_cols only, if != 0 */
/* 02.10.94 - fc.syntax_flag = f (WITH_SYNTAX_HIGHLIGHTING)*/
/* 06.10.94 - fc.syntax_flag always defined */
