//////////////////////////////////////////////////////////
//                                                      //
// The "veditrc" file when VEDIT is named "ved".        //
//                                                      //
//////////////////////////////////////////////////////////
//
// Part 1 - Load environment variables and configure according to
//          the global 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,"/qnx4/vedit") }
//
Config_Load("|@(9)/vedit.cfg",NOERR)
Key_Load("|@(9)/vedit.key",NOERR)
//
// The user's config directory by default is $HOME/vedit, but can be changed
// if necessary by enabling and modifying the following three lines. This
// is the default directory for {CONFIG, Save config}.
//
// Reg_Set(5,@8)                //@5 = "$HOME"
// Reg_Set(5,"/vedit",APPEND)   //@5 = "$HOME/vedit"
// Config_String(USER_CFG,@5)   //Change user's config dir if needed
//
// Make sure the user's config directory exists; create it if necessary,
//
if (File_Exist(USER_CFG)==0) { Sys("mkdir $HOME/vedit",OK) }
//
/////////////////////////////////////////////////////////////////////////////
//
// Part 2 - Configure according to terminal type. (Technical)
//
// The parameter Config(H_IO_OPT) controls how characters are displayed.
// 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
//              Display Ctrl-chars in range 0-31 as "."
//              Display 8-bit chars in range 128-255 as "."
//              Display box-drawing character set as "-", "|", "+", etc.
//     +01 - Display Ctrl-chars in range 0-31 on screen.
//              (Does not work with Photon or serial terminals.)
//     +02 - Unused
//      04 - Enable QNX console mode
//              Display 8-bit chars
//              Use IBM PC window-border chars in range 128-255
//              Use IBM PC arrow chars in range 16-31
//              Display Ctrl-chars on screen
//              (Should normally not be combined with other values.)
//     +08 - Display 8-bit chars in range 160-255
//     +16 - Display 8-bit chars in range 128-159
//              (Does not work with Photon.)
//     +32 - Use terminal's box-drawing character mode
//              Normally, use terminfo values for box-drawing character set
//              If +128, use IBM PC box-drawing character set
//              (Should normally be used.)
//     +64 - Override box-drawing "arrow chars" with "^", "v", "<" and ">"
//              (Suggested for Photon.)
//     +128 - Use IBM PC box-drawing character set in range 16-31 & 128-255
//              Should use +64 unless chars unless chars 16-31 are supported
//              (Also uses shaded buttons in dialog boxes.)
//
// The desired options can be selected by adding (or ORing) the corresponding
// values together. However, "04" should not be combined with other values.
////////
//
// If running on the QNX console, skip TERM value checking.
//
if (Config(H_IO_OPT)==4) { goto TERMDONE }
//
// Photon works best with value "8+32+64+128". It supports 8-bit chars in
// range 160-255, but does not support range 128-159. It uses the IBM-PC
// graphics character set as the box-drawing character set; since this set
// has no arrows, the simple arrow chars should be used via "+64".
//
if (Reg_Size(6)!=0) {                   //If PHOTON ...
    Config(H_IO_OPT, 8+32+64+128)       //Setup for PHOTON
    goto TERMDONE                       //Skip other TERM tests
}
//
// Most terminals have a box-drawing mode for drawing boxes and lines.
// The terminfo database sets these characters each terminal.
//
Config(H_IO_OPT, Config(H_IO_OPT) | 32) //Enable box-drawing character set
                                        //using terminfo values
//
// Select the TERM types (e.g. qnxt, qnxm) that have support for IBM PC 8-bit
// graphics characters. The IBM PC graphics character set will then be used
// to draw menu borders, window borders and dialog boxes. Otherwise the
// characters defined in the terminfo database are used.
//
if (Reg_Compare(7,"qnxt")==0 || Reg_Compare(7,"qnxm")==0 ) {
    Config(H_IO_OPT, Config(H_IO_OPT) | 64+128) //Support IBM PC 8-bit chars
}
//
// Select the remaining TERM types (e.g. ansi, qansi and qansi-m) that can
// display 8-bit text characters in the range 160-255, but don't support the
// IBM PC graphics character set. (They support the ANSI character set).
// Otherwise 8-bit text characters are displayed as ".".
//
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 this is the QNX main console or IBM PC graphics support was selected
// above, use an IBM PC graphic "desktop" character for the screen areas
// where there is no editing window. Select the color for this character.
//
// Else, use simple spaces for the "desktop" character. The default color is
// black, unless a different color was selected in "vedit.cfg" loaded above.
//
if (Config(H_IO_OPT) & 04) {            //If QNX console...
    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} and {TUTOR} menus.
//
//      The optional commands below can perform the following functions:
//
//      <Ctrl-F5> is assigned to compare two windows.
//      <Alt-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("Alt-F12",'[MENU]MMB',OK)
//
// Shift-F12 runs a macro which opens mynotes.txt for editing personal notes.
//
Key_Add("Shft-F12",'[MENU]MMY',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 macros. 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
//
//      The following command sets up the {TOOL} menu as the {Tutor} menu.
//      Alternatively, you could load your own custom {TOOL} menu, similar
//      to the {USER} menu. If you don't want a {Tutor} menu, disable the
//      following three commands by preceding each one with "//".
//
Reg_Load(123,"tutor.mnu",EXTRA+NOERR)
Config_String(TOOL_MENU,"Tutor")
Key_Add("Alt-T","[MENU]T",OK)           //<Alt-T> is hot-key for {TOOL} menu
//
/////////////////////////////////////////////////////////////////////////////
//
// Part 4 - Setup filename specific configuration
//
//      The "File-Open" event macro in T-Reg 110 is used to set configuration
//      parameters according to the filename extension.
//      It must be enabled with {CONFIG, File handling, Enable file
//      open/close macro} or with Config(F_E_F_MACRO,1).
//
//      If desired, you can un-comment the following command to enable the
//      file-open event macro, overriding any setting in the vedit.cfg file.
//
// Config(F_E_F_MACRO,1)        //Enable the "File-Open" event macro
//                              //This enables filename specific configuration
//
Reg_Set(110,`//File-Open event macro
#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 - Load optional user's config/keyboard files in $HOME/vedit directory.
//
Config_Load("|(USER_CFG)/ved.cfg",NOERR)
Key_Load("|(USER_CFG)/ved.key",NOERR)
Reg_Empty(100,EXTRA)                    // Very last, empty this macro
