//////////////////////////////////////////////////////////
//                                                      //
// The "veditrc" file when VEDIT is named "vedit".      //
//                                                      //
//////////////////////////////////////////////////////////
//
// Part 1 - Load environment variables and configure according to
//          vedit.key and vedit.cfg files.
//
Get_Environment(6,"PHOTON")
Get_Environment(7,"TERM")
Get_Environment(8,"HOME")
Get_Environment(9,"VEDIT_PATH")
if (Reg_Size(9)==0) { Reg_Set(9,"/usr/lib/vedit3") }
Key_Load("|@(9)/vedit.key",NOERR)
Config_Load("|@(9)/vedit.cfg",NOERR)
//
/////////////////////////////////////////////////////////////////////////////
//
// Part 2 - Configure according to terminal type. (Technical)
//
// The parameter Config(H_IO_OPT) controls 8-bit character support.
// Its initial value is set by the "-o nnn" invocation option, if any.
// On a QNX console, its value will be ORed with "4" on startup.
// Its value can then be changed here according to TERM type or other
// criteria. The following values (bit-masks) are defined. 
//
//      00 - Default 7-bit terminal support
//              Use terminfo values for box-drawing character set
//              Display 8-bit chars in file as "."
//              Display Ctrl-chars in file as "."
//      04 - Enable QNX console mode
//              Display 8-bit chars in file
//              Use IBM PC window-border chars in range 128-255
//              Use IBM PC arrow chars in range 16-31
//              Display Ctrl-chars on screen
//      08 - 8-bit terminal support
//              Use terminfo values for box-drawing character set
//              Display 8-bit chars in range 128-255
//              Display Ctrl-chars as "."
//      16 - Partial 8-bit terminal support (e.g. Photon)
//              Use terminfo values for box-drawing character set
//              Display 8-bit chars in range 128-159 as "."
//              Display 8-bit chars in range 160-255
//              Display Ctrl-chars as "."
//      32 - Support IBM PC 8-bit chars (e.g. TERM=qnxt)
//              Display 8-bit chars in range 128-255
//              Use IBM PC window-border chars in range 128-255
//              Substitute IBM PC "arrow chars" with "^", "v", "<" and ">"
//              Display Ctrl-chars as "."
//
//
// Photon works best with value "16" because it supports 8-bit chars in range
// 160-255, but does not currently support 8-bit chars in range 128-159.
// 
if (Reg_Size(6)!=0) {                   //If PHOTON ...
    Config(H_IO_OPT, 16)		//Enable 8-bit chars in range 16-255
    goto TERMDONE			//Skip other TERM tests
}
//
// Some terminals (e.g. TERM=qnxt) support IBM PC 8-bit graphics chars.
// Other terminals (e.g. TERM=ansi) don't support IBM PC graphics, but do
// support 8-bit text chars (they are displayed with the ANSI character set).
//
if (Reg_Compare(7,"qnxt")==0 || Reg_Compare(7,"qnxm")==0 ) {
    Config(H_IO_OPT, Config(H_IO_OPT) | 32)       //Support IBM PC 8-bit chars
}
//
// If TERM=ansi, qansi or qansi-m, enable 8-bit text characters.
//
if (Reg_Compare(7,"ansi")==0 || Reg_Compare(7,"qansi")==0 || Reg_Compare(7,"qansi-m")==0) {
    Config(H_IO_OPT, Config(H_IO_OPT) | 08)
}

:TERMDONE:
//
if (Config(H_IO_OPT) & 04+32) {         //If IBM PC 8-bit char support...
    Config(S_EMPTY_C,176)               //Use graphic "desktop" character
    Config(C_EMPTY,113)                 //"Desktop" color
} else {
    Config(S_EMPTY_C,32)                //Just spaces for "desktop" character
}
//
// VEDIT can optionally delay updating the "COL:" number on the status line
// until you stop typing for a 1/2 second or longer. This reduces screen
// flicker during fast typing on terminals over a slow serial-line connection.
// If desired, change the following argument from 0 to "5" (1/2 second delay)
// or "10" (1 second delay). It can be changed inside VEDIT with
// {CONFIG, Misc, Status line update delay}.
//
Config(S_STAT_DLY,0)            //Status line update delay; 0=none
//
// For TERM=qnx, TERM=qansi or Photon, enable scroll bars and full borders.
// Also put the status line on the bottom and the menu bar on top.
// Also turn off any status line update delay, especially for Photon.
// These settings would significantly slow down screen updates on a serial
// connected CRT terminal, but are usually preferred on a fast console.
//
if (Reg_Compare(7,"qnx")==0 || Reg_Compare(7,"qansi")==0 || Reg_Size(6)!=0) {
    Config(WIN_BRD,3)                   //Enable scroll bars and full border
    Config(S_DSP_BRD,2)                 //Full borders for on-line help
    Config(S_STAT_OPT,2)                //Status line on bottom, menu bar on top
    Config(U_E_DIALOG,1)                //Enable full dialog boxes
    Config(S_STAT_DLY,0)                //Turn off status line update delay
} else {
    Config(WIN_BRD,1)                   //Use minimal borders, no scroll bars
    Config(S_DSP_BRD,1)                 //Minimal borders for on-line help
    Config(S_STAT_OPT,1)                //Status line on top, hidden menu
    Config(U_E_DIALOG,0)                //Use terse dialog boxes
}
/////////////////////////////////////////////////////////////////////////////
//
// Part 3 - Optional key assignments
//          Setup {USER} menu
//
//      The optional commands below can perform the following functions:
//
//      <Ctrl-F5> is assigned to compare two windows.
//      <Ctrl-F12> is assigned to configure VEDIT to a dBASE III ".DBF" file
//
//      To enable any function, delete the "// " from the corresponding line:
//
// Key_Add("Ctrl-F5",'[VISUAL EXIT] if((#100=Win_Next)!=Win_Num){ Compare(Win_Status(#100)+BUFFER) } else { Alert() }',OK)
// Key_Add("Ctrl-F12",'[VISUAL EXIT] BOF() Char(8) #100 = Cur_Char Char() #100 += Cur_Char * 256 Config(F_REC_HEAD, #100, LOCAL) Char() #100 = Cur_Char Char() #100 += Cur_Char * 256 Config(F_F_TYPE, #100, LOCAL) BOF() Line()',OK)
//
//      The following command adds the {USER} menu to the main menu.
//      By default, user.mnu contains a few of the macros from the
//      "key-mac.lib" library of macro. You can delete and add custom editing
//      functions to the {USER} menu as desired. See the on-line help topic
//      "USER" for more information.
//
Reg_Load(124,"user.mnu",EXTRA+NOERR)
Key_Add("Alt-U","[MENU]U",OK)           //<Alt-U> is hot-key for {USER} menu
//
/////////////////////////////////////////////////////////////////////////////
//
// Part 4 - Setup the "File-Open" event macro in T-Reg 110.  It sets 
//          configuration parameters according to the filename extension.
//
// NOTE: To enable the file-open event macro, change the "0" in the
//       following Config() command to "1".
//
Config(F_E_F_MACRO,0)           //Disable the "File-Open" event macro.
//
Reg_Set(110,`
#109=Buf_Num
Out_Reg(109) Name_Write(NOMSG+NOCR) Out_Reg(0)
Buf_Switch(36)
Buf_Empty(OK)
Reg_Ins(109)
//
// Test if this is a ".c", ".cpp" or ".h" file...
//
BOF()
if ( Search(".c|>",NOERR)==1 || Search(".cpp|>",NOERR)==1 || Search(".h|>",NOERR)==1 ) {
Buf_Switch(#109)
Config(PG_AUTO_IND,1,LOCAL)
Config(PG_IND_INC,4,LOCAL)
Config(W_LF_MARG,0,LOCAL)
Config(W_RT_MARG,0,LOCAL)
Config_Tab(4;LOCAL)
Goto ENDMACRO
}
//
// Test if this is a ".txt" word processing file...
//
BOF()
if ( Search(".txt|>",NOERR)==1 ) {
Buf_Switch(#109)
Config(PG_AUTO_IND,1,LOCAL)
Config(PG_IND_INC,4,LOCAL)
Config(W_LF_MARG,0,LOCAL)
Config(W_RT_MARG,72,LOCAL)
Config_Tab(4;LOCAL)
Goto ENDMACRO
}
//
// Test if this is an ".asm" or ".ext" file...
//
BOF()
if ( Search(".asm|>",NOERR)==1 || Search(".ext|>",NOERR)==1 ) {
Buf_Switch(#109)
Config(PG_AUTO_IND,0,LOCAL)
Config(PG_IND_INC,8,LOCAL)
Config(PG_CASE_CONV,2,LOCAL)
Config(PG_CONV_C,59,LOCAL)
Config(W_LF_MARG,0,LOCAL)
Config(W_RT_MARG,0,LOCAL)
Config_Tab(4;LOCAL)
Goto ENDMACRO
}
//
// Close buffer 36.
//
:ENDMACRO:
Buf_Switch(36)
Buf_Quit(OK)
Buf_Switch(#109)
`)
//
/////////////////////////////////////////////////////////////////////////////
//
// Last - Chain to user's "/HOME/.veditrc" file if there is one.
//
Chain_File(100,"|@(8)/.veditrc",NOERR)
Reg_Empty(100,EXTRA)                    // Else empty this macro
