// EXTRACTD.VDM - Extract all lines in the current file containing the // specified search string by copying them to another file. // It can append to an existing file. // // Originally by: Greenview Data, Inc. // Last change: 04/28/99 // // Modified by Ch. Ziemski 28.05.1999 Extracted lines are deleted!!!!!!!!!! // // Usage: Select {MISC, Load/Execute macro}. Enter filename // "extract.vdm". Use default register number "100". // // At the prompt, enter the search string. At the next // prompt, enter the filename. // // Note: This macro can be used as a model for other custom macros // that extract data from one file into a new file. // Get_Input(103,"Enter search string (or to cancel): ",STATLINE+NOCR) Get_Input(104,"Enter destination filename: ",STATLINE+NOCR) if (File_Size==0) { Alert Get_Key("You must first open a non-empty file!",STATLINE) } else { Message("Processing. Please wait...",STATLINE) } // // Setup to open the destination file. // #103=Buf_Num // #103 = original buffer ID #104=Buf_Free // #104 = free buffer to use Buf_Switch(#104) // Switch to free buffer File_Open(@104) // Open the destination file if (File_Size!=00) { // If file already exists... Alert() while ((#105=Get_Key("File already exists! [A]ppend [O]verwrite [C]ancel",STATLINE)&0xFFDF)!='A' && #105!='O' && #105!='C') { Alert } // Wait for valid reply if (#105=='A') { End_Of_File } // Append to the exiting file if (#105=='O') { Del_Block(0,File_Size) } // Delete existing file if (#105=='C') { Buf_Quit(OK) // Abandon file and close buffer Buf_Switch(#103) // Back to original file Return // Return from this macro } } Buf_Switch(#103) // Switch back to original buffer Begin_Of_File // Start at beginning of file // // Process each search occurrence. // repeat(ALL) { // Repeat forever until Search() breaks out Search(@103,ERRBREAK) // Search for next occurrence Begin_Of_Line // Go to beginning of line Reg_Copy(105,1) // Copy the line to T-Reg 105 Del_Line(1) // Added by C.Z. Buf_Switch(#104) // Switch to destination file Reg_Ins(105) // Insert (append) the line Buf_Switch(#103) // Back to the original file Line(1,ERRBREAK) // Advance to next line to continue search } Buf_Switch(#104) // Switch to destination file if (File_Size < 1000000) { Begin_Of_File } // Go to beginning if small file Update() //Show the destination file while ((#105=Get_Key("Save extracted file? [Y]es [N]o-abandon [C]ancel",STATLINE)&0xFFDF)!='Y' && #105!='N' && #105!='C') { Alert } // Wait for valid reply if (#105=='Y') { Buf_Close(NOMSG+DELETE) // Save file and close buffer Buf_Switch(#103) // Back to original file Return } if (#105=='N') { Buf_Quit(OK+DELETE) // Abandon file and close buffer Buf_Switch(#103) // Back to original file Return } // // If [C]ancel, let user deal with file as desired. //