// VEDITSAV.VDM - Write VEDIT's current status out to files. // Implements {FILE, Edit session restore}. // // Originally by: Thomas C. Burt, Greenview Data, Inc. // Last change: 22-February-2005 // Last change: 14-April-2006 Christian Ziemski: don't save hard coded VEDIT paths into .PRJ // added NOERR to Chdir // // Requires: VEDIT 6.15 or later (due to syntax of Replace()). // // From VEDIT: Select {File, Enable edit restore} then {File, Exit}. // Or give the command mode commands "Exit". // // Note: The command "QALL" does not save the edit session. // // Description: Creates files "veditsav.env" and "veditsav.dat" in the // user's config directory, typically "C:\VEDIT". However, // if {CONFIG, File handling, Save session in current directory} // is enabled, the files are saved in the current directory. // // VEDITSAV.ENV holds the commands to restore the edit-session. // VEDITSAV.DAT holds the user cut & paste text registers 0-9, // system text registers 107-116, 119 and 123-126 (the // tools and user menus and current keyboard and // window layouts), unnamed edit buffers and buffer- // dependent configuration values. // ////////////////////////////////////////////////////////////////////////////// // // Text Register Usage // // 0 Scratch: hold buffer dependent configuration parameters // 1 Scratch: hold name of current edit file // 2 (End of command characters: ) // 121 VEDIT HOME directory or current (startup) directory // // Numeric Register Usage (0 - 29 are saved and restored) // // 0 Local scratch variable // 1 " " " // 2 " " " // 3 Status of active window when macro starts // 4 ID of active window when macro starts // 5 ID of T-Reg current macro is executing in // 6 ID of buffer for creating restoration cmds - "VEDITSAV.ENV" // 7 ID of active edit buffer at start of this macro // 8 Current zoom status for editing windows // 10 ID of current buffer/register (working index) // 11 Flag when saving buffer dependent configuration variables // 30 Current edit position // 50 Current length of edit-session-saving file - "VEDITSAV.DAT" // 51 Length of text register being saved // 110 Active buffer ID at startup (temporary at start; put into #7) // 111 ID of work buffer (temporary at start; put into #6) // //**************************************************************************** // if ( Macro_Num == 122 ) { // (Don't want message when RUNSHELL'ng) Message("Saving edit session...",STATLINE) } Save_Env() // Inform VEDIT its edit-session is to be saved #110 = Buf_Num // ID of active edit buffer at inception #111 = Buf_Free(EXTRA) // ID of edit-session restoration work buffer // // Delete any non-Command-mode reserved windows since the macro that // creates/deletes them will not be restored when we come back up. // if (Win_Reserved_Bottom && Win_Reserved_Bottom_ID != '$'+128) { Win_Delete(Win_Reserved_Bottom_ID) } if (Win_Reserved_Top && Win_Reserved_Top_ID != '$'+128) { Win_Delete(Win_Reserved_Top_ID) } if (Win_Total==0) { Screen_Init() } // Need at least one window // WR($,4,BOTTOM) // Enable these lines as debugging aid // Update // WS($) // ? ////////////////////////////////////////////////////////////////// // // // Save to .ENV File // // // ////////////////////////////////////////////////////////////////// // // Create the .ENV file in a temporary work buffer. // if (#111<0) { // If all temporary buffers are in use #111 = XBUF1 // Use Extra_Buffer_1 Buf_Switch(#111) // Switch to it Buf_Quit(OK) // And empty/close it } Buf_Switch(#111,EXTRA) // Create work buffer as normal edit buffer // // Setup T-Reg[121] with the name of the directory into which to store // VEDITSAV.ENV and VEDITSAV.DAT. // if (OS_Type < 4) { // If Win/DOS (not UNIX/QNX) ... if (Config(F_SAVE_SESS)) { // If saving into current (startup) directory Out_Ins() Name_Dir(EXTRA+NOMSG+NOCR) // Insert startup directory name Out_Ins(CLEAR) // (Not same as current directory CUR_DIR) } else { // Else insert VEDIT Home Directory name Ins_Text(USER_CFG) } Char(-1) // Strip any final "\" (e.g., the root dir) if (Cur_Char != '\') { Char(1) } Reg_Copy(121,0) // Copy directory name without "\" to R[121] Reg_Set(121,"\",APPEND) // Append final "\" to R[121] } else { // Else its UNIX/QNX... if (Config(F_SAVE_SESS)) { // If saving into current (startup) directory Out_Ins() Name_Dir(EXTRA+NOMSG+NOCR) // Insert startup directory name Out_Ins(CLEAR) // (Not same as current directory CUR_DIR) Reg_Copy(121,0) // Copy directory name without "/" to R[121] } else { // Else insert VEDIT Home Directory name Reg_Set(121,USER_CFG) // Copy user's config directory into R[121] } Reg_Set(121,"/",APPEND) // Append final "/" to R[121] } File_Open_Write("|@(121)veditsav.env",SUPPRESS+FORCE+OVERWRITE) Begin_Of_File() // Erase any former macro commands Del_Char(ALL) // Better safe than sorry // // First, save some numeric variables. // Format is: #r = value // Out_Ins() // Capture console output in work buff Num_Display(0,9) // List all non-zero numregs from #0 - #9 // (98,99 must not be saved because of // complications for "locked-in" macros, // such as WildFile). Num_Display(107,116) // List all non-zero numregs from #107 - #116 // Must not include 118 used in STARTUP.VDM Num_Display(119,119) // Include #119 used in HTML.KEY Out_Ins(CLEAR) // Restore console output // // Now define some variables for our own use. // #3 = Win_Status(Win_Num) // #3 = status of active window at startup #4 = Win_Num #5 = Macro_Num // #5 = currently executing T-Reg #6 = #111 // #6 = Edit-session restoration work buffer #7 = #110 // #7 = ID of active edit buffer at statup #8 = Is_Zoomed // #8 = Current zoom status for editing windows #11 = 0 // #11 will be set when saving buffer dependent values if (#7 > Num_Edit_Bufs) { #7 = 1 } // Buffer-save loop doesn't (yet) // work with reserved buffers // // Save entire set of configuration parameters. // Buf_Switch(#6) // Switch to work buffer Out_Ins() // Divert console output into work buffer Config_Display(EXTRA+SHORT+SUPPRESS+GLOBAL) // Save complete "Config(...)" commands // Skip full description // Don't save hardware dependent parms // Save global buffer-dependent values Out_Ins(CLEAR) // Restore console output // IT("Config( E_INS_MODE,") // Add current insert/overstrike mode NI(Config(E_INS_MODE),LEFT|NOCR) IT(")") IN() ////////////////////////////////////////////////////////////////// // // // Save to .DAT File // // // ////////////////////////////////////////////////////////////////// // // Create .DAT file, starting with T-Reg[0]. // File_Delete("|@(121)veditsav.dat",OK+NOERR) // Ensure upcoming Reg_Save() doesn't // generate a prompt but does create a // new file, regardless of any existing // file or the size of T-Reg[0] Reg_Save(0,"|@(121)veditsav.dat",NOCONFIRM) // Create the file, OK if empty #10 = 0 // Text Register[0] #50 = 0 // Current length of VEDITSAV.DAT #51 = Reg_Size(#10) Call("RLP") // Reg_Load_Part(0,veditsav.dat,0,#51) // // Append remaining "cut & paste" T-Regs[1-9]. // for (#10 = 1; #10 < 10; #10++) { // Save cut & paste registers if ((#51=Reg_Size(#10)) > 0) { Reg_Save(#10,"|@(121)veditsav.dat",APPEND) // Append current text register contents to .DAT file Call("RLP") // Generate reload instruction in .ENV file: // Reg_Load_Part(r,"fname",ofs,len) // 'r' = #10 // 'ofs' = #50 // 'len' = #51 // then update ofs += len } } ////////////////////////////////////////////////////////////////////////// // // // Note: T-Regs[97-106] are never to be saved due to possible later // // complications when a "locked-in" macro is improperly // // terminated such as for a syntax error, internal error, the // // user closing Vedit while WildFile is running, etc. // // // ////////////////////////////////////////////////////////////////////////// // // Save necessary system registers but don't save // this macro, keyboard or window structures (yet) or // T-Regs[117,118,120-122]. // Note: STARTUP.VDM runs in 122 // for (#10 = 107; #10 < 126; #10++) { if ((#10<>#5) && #10<>117 && #10<>118 && ((#10 < 120) || (#10 > 122))) { if ((#51=Reg_Size(#10)) > 0) { Reg_Save(#10,"|@(121)veditsav.dat",APPEND) Call("RLP") } } } ////////////////////////////////////////////////////////////////// // // // Finish saving to .PRJ file // // Save edited files (after confirmed prompt). // // Save unnamed edit buffer into .DAT file. // // // ////////////////////////////////////////////////////////////////// // // Free up Text Registers[0-3]. // Set up T-Reg[2] with end-of-command chars: closing parenthesis, newline. // Reg_Push(0,3) // Free up text registers 0 - 3 Reg_Set(2,") // (Balance next paren... ") // Reg[2] = end of command chars // // Save # screen lines if DOS; only restore if DOS. // if (OS_Type == 2) { // If DOS ... IT("if(OS_Type==2 && Screen_Lines!=") NI(Screen_Lines,LEFT+NOCR) IT(") {Screen_Size(") // Screen_Size(Screen_Lines) NI(Screen_Lines,LEFT+NOCR) IT(")}") IN() } // // Save edit buffers. // Num_Push(20,29) // Free up 10 numeric registers Buf_Switch(#10=#7) // Get starting buffer # do { #30 = Cur_Pos Reg_Empty(1) for (#1=0; #1<10; #1++) { // for Text Markers[m], m = #1 = 0,9 #2 = 20 + #1 // Compute index #@2 = marker(#1) // Save markers in #20[m] } RCB(0,0,0,EXTRA) // T-Reg[0] = buffer dependent config values #31 = Block_Begin #32 = Block_End #33 = Column_Begin #34 = Column_End #35 = Block_Mode #36 = #37 = 0 // Assume not editing disk sectors if (OS_Type == 2) { // If DOS... #36 = Is_Disk_Open // check for disk editing if (#36) { #37 = Disk_Open_Mode } // and get the disk-open mode } if (Is_Open_Write && #36==0) { Out_Reg(1) Name_Write(EXTRA+NOMSG+NOCR) Out_Reg(CLEAR) #37 = Browse_Mode } else { #51 = Reg_Size(#10+BUFFER) } Buf_Switch(#6) IT("Buf_Switch(") // Buf_Switch(r)) NI(#10,LEFT|NOCR) Reg_Ins(2) // Closing paren, newline // // DOS version only - If disk open // if (#36) { IT("Disk_Open('") // Disk_Open('d',mode)) IC('A'+#36-1) IT("',") NI(#37,LEFT|NOCR) Reg_Ins(2) // Closing paren, newline // // else if output "fn" // } else { if (Reg_Size(1)>0) { IT(/File_Open(*"/) // File_Open("fn")) Reg_Ins(1) IT(/"*,MRU/) if (#37&0xC2) { IT("|BROWSE") } // If user wanted browse-only Reg_Ins(2) // Closing paren, newline if (#37&01) { IT("Browse_Mode(SET)") // If {EDIT, Browse} IN() } // // else save into .DAT file. // } else { #10 += BUFFER if ((#51=Reg_Size(#10)) > 0) { Reg_Save(#10,"|@(121)veditsav.dat",APPEND) Call("RLP") // Reg_Load_Part(r,"file",ofs,len) } #10 -= BUFFER }} Reg_Save(0,"|@(121)veditsav.dat",APPEND) // Save buffer dependent parameters Num_Push(10,10) #10 = 0 #51 = Reg_Size(0) #11 = 1 Call("RLP") // Reg_Load_Part(0,"fn",ofs,len,LOCAL) #11 = 0 Num_Pop(10,10) for (#1=0; #1<10; #1++) { // for i=0,9 #2 = 20 + #1 // #20[i] = Saved filemarkers if (#@2 >= 0) { // If filemarker[i] is defined IT("Set_Marker(") // Set_Marker[i,markpos]) NI(#1,LEFT|NOCR) IT(",") NI(#@2,LEFT|NOCR) Reg_Ins(2) // Closing paren, newline } } IT("Block_Begin(") // Block_Begin(#31)) NI(#31,LEFT|NOCR) Reg_Ins(2) // Closing paren, newline IT("Block_End(") // Block_End(#32)) NI(#32,LEFT|NOCR) Reg_Ins(2) IT("Column_Begin(") // Column_Begin(#33)) NI(#33,LEFT|NOCR) Reg_Ins(2) IT("Column_End(") // Column_End(#34)) NI(#34,LEFT|NOCR) Reg_Ins(2) IT("Block_Mode(") // Block_Mode(x)) NI(#35,LEFT|NOCR) Reg_Ins(2) IT("Goto_Pos(") // Goto_Pos(edit pos)) NI(#30,LEFT|NOCR) Reg_Ins(2) Buf_Switch(#10) // Goto buffer just processed Buf_Switch(#10=Buf_Next()) // Goto next edited buffer } while (#10<>#7) // Until circled all the way around // // Save current search/replace strings and search options. // BS(#6) if (SRD > 0) { Out_Ins() IT("SR_Set(") //) SRD(EXTRA) if (SRD > 1) { IT(",SET") } Reg_Ins(2) Out_Ins(CLEAR) #10 = Search_Options IT("Search_Options(") //) NI(#10,LEFT+NOCR) Reg_Ins(2) } // // Save current working directory. // BS(#6) // Switch to work buffer IT("Chdir('") // Beginning of Chdir(cwd)) Out_Ins() // Capture console output in work buff Name_Dir(NOMSG|NOCR) // Capture current working dir name Out_Ins(CLEAR) // Restore console output IT("', NOERR") // CZ: NOERR added for USB stick usage Reg_Ins(2) // // Save window structures into .DAT file. // Only restore if same type (Win32, Win16, DOS) and version #. // #10 = 126 // ID of window structures #51 = Reg_Size(#10) Reg_Save(#10,"|@(121)veditsav.dat",APPEND) IT("if(OS_Type==") NI(OS_Type,LEFT+NOCR) IT(" && Is_Win32==") NI(Is_Win32,LEFT+NOCR) IT(" && Win_Struct_Size==") NI(Win_Struct_Size,LEFT+NOCR) IT(" && Version_Num==") NI(Version_Num,LEFT+NOCR) IT(") {") IN() Call("RLP") // Reg_Load_Part(126,...) IT("} else { Screen_Init(ATTACH) }") IN() // // If (main) buffer 1 currently closed, need to close it during restore. // if (Buf_Status(1)==-1) { IT("Buf_Switch(1) Buf_Close(NOMSG)") //Close buffer 1 IN() } // // Ensure start-up in original active buffer. // IT("Buf_Switch(") //) NI(#7,LEFT|NOCR) Reg_Ins(2) if (#3>0) { // Switch to original window and IT("Win_Switch(") //) attach it if it viewed an edit NI(#4,LEFT+NOCR) // buffer. (Handles case of multiple IT(",ATTACH") // windows into one edit buffer) Reg_Ins(2) } // // Cause any Project to be re-opened. // if (OS_Type == 1) { // If Windows... Reg_Set(3,Proj_Current) if (Reg_Size(3)>0) { IT("Reg_Push(122,122)") // Must save STARTUP.VDM in 122 IN() IT(/Proj_Open("/) // Proj_Open("fn") Reg_Ins(3) IT(/",LOCAL/) Reg_Ins(2) IT("Reg_Pop(122,122)") // Restore STARTUP.VDM in 122 IN() } } // // Cause screen to be redrawn. // IT("Screen_Reset()") IN() // // Rezoom window, if needed. // if (#8<>0) { IT("Update()") // Screen doesn't update otherwise IN() IT("Win_Zoom()") // Zoom the window IN() } // // Cleanup for restoration macro. // IT("Return(1,DELETE)") // Discard Edit-session restoring macro IN() //CZ insert ----------------------------------------- // Replace any hardcoded // - Vedit home directory (e.g. C:\VEDIT\) with variable HOME //Replace("$(HOME)\","|(HOME)\", BEGIN+ALL+NOERR) Replace("$(HOME)\\","|(HOME)\\", REGEXP+BEGIN+ALL+NOERR) //CZ end -- ----------------------------------------- File_Close(NOMSG+SUPPRESS) // Close VEDITSAV.ENV Buf_Quit(OK) // Release extra buffer // // Cleanup for this macro. // Num_Pop(20,29) Reg_Pop(0,3) Save_Env(CLEAR) // Inform VEDIT to finish saving edit-session Buf_Switch(#7) // Switch back to original active buffer Return() // //**************************************************************************** // // RLP - Generate command 'Reg_Load_Part(r,"veditsav.dat",ofs,len,NOERR[+LOCAL])' // in work buffer, where 'r' = #10, 'ofs' = #50, 'len' = #51; // then update ofs+=len. // (#11 sets "LOCAL" when saving buffer dependent configuration values.) // :RLP: IT("Reg_Load_Part(") //) NI(#10,LEFT|NOCR) IT(`,"`) Reg_Ins(121) IT(`veditsav.dat",`) NI(#50,LEFT|NOCR) IT(",") NI(#51,LEFT|NOCR) iT(",NOERR") if (#11) { IT("+LOCAL") } //( IT(")") IN() #50 += #51 Return()