// REM-LINE.VDM - Remove (deletes) all lines containing a string listed in a // file of "remove strings". (Works well for comparing two // lists of items, e.g. e-mail addresses.) // // Originally by: Ted Green, Greenview Data, Inc. // Last change: 05/01/2003 // Modified by Ian Binnie 21/04/2004 for long lines // // Requires: VEDIT 5.00 or later. // // Note: Each "remove string" must be at least three characters long. // // Reg_Set(11,"email.txt") //Default source filename Reg_Set(12,"remove.txt") //Default remove-list filename Reg_Set(13,"ediff.txt") //Default destination filename Reg_Set(14,"match.txt") //List of matching lines that were removed #18 = Buf_Num //#18 = original buffer # Win_Clear() Message(` ******************************************* * REM-LINE.VDM - 05/01/2003 * * Delete lines with string in remove list * ******************************************* `) if (Is_Open_Write && Filesize ) { Goto NEWREMOVE } //Skip if source file already open // :NEWSOURCE: Get_Input(11,"\nEnter source filename: ",@11,NOCR) Get_Filename(11,@11) if (File_Exist(@11)==0) { Alert() Message("File not found. Try again.\n") Goto NEWSOURCE } File_Open("|@(11)") // :NEWREMOVE: #11 = Buf_Num //#11 = source buffer # Get_Input(12,"\nEnter remove-list filename: ",@12,NOCR) Get_Filename(12,@12) if (File_Exist(@12)==0) { Alert() Message("File not found. Try again.\n") Goto NEWREMOVE } File_Open("|@(12)") #12 = Buf_Num //#12 = remove-list buffer # // :NEWDESTINATION: Get_Input(13,"\nEnter destination filename: ",@13,NOCR) Get_Filename(13,@13) // // If file exists, prompt to overwrite, append or get new name. // if (File_Exist(@13)) { Alert() Message(" File already exists! [O] Overwrite it [N] Get new filename [C] Cancel macro Enter desired option: ") repeat (ALL) { #10=Get_Key("")&0xFFDF if (#10=='O' || #10=='N' || #10=='C') { Break } Alert() } Type_Char( Previous_Key(0) ) if (#10=='N') { Goto NEWDESTINATION } if (#10=='O') { File_Delete(@13,OK) } if (#10=='C') { Return } } Buf_Switch(#11) //Switch to source buffer File_Save_As(@13,OK) //Save as destination filename // :NEWDELETED: Get_Input(14,`\nEnter filename for "removed" (matching) lines : `,@14,NOCR) Get_Filename(14,@14) // // If file exists, prompt to overwrite, append or get new name. // if (File_Exist(@14)) { Alert() Message(" File already exists! [A] Append to it [O] Overwrite it [N] Get new filename [C] Cancel macro Enter desired option: ") repeat (ALL) { #10=Get_Key("")&0xFFDF if (#10=='A' || #10=='O' || #10=='N' || #10=='C') { Break } Alert() } Type_Char( Previous_Key(0) ) if (#10=='O') { File_Delete(@14,OK) } if (#10=='N') { Goto NEWDESTINATION } if (#10=='C') { Return } } // #14 = Buf_Free() //#14 = buffer for "removed" lines Buf_Switch(#14) //Switch to buffer File_Open("|@(14)") //Open/create the "removed" line file // // // Main processing loop. // Message("\nRemoving lines...\n") Buf_Switch(#12) //Switch to remove-list BOF //Start at beginning of it repeat(ALL) { //Repeat forever until Line() breaks out if ((#19=Cur_Line)%100==0) { Win_Hor(1) Win_EOL() Message(`Number of "remove" entries processed: `) Num_Type(#19,NOCR) } Reg_Copy_Block(16,CP,EOL_Pos) //IB 21/04/2004 Copy next remove-string to T-Reg 16 #16 = EOL_Pos - CP //IB 21/04/2004 length of remove-string if (#16 >= 100) // IB 21/04/2004 { Reg_Copy_Block(15,CP,CP+100) //Copy 1st 100 characters of remove-string to T-Reg 15 } else { Reg_Copy_Block(15,CP,EOL_Pos) // Copy short remove-string to T-Reg 15 } if (Reg_Size(15) >= 3) { //Remove string must be at least three characters Repeat(ALL) { //Search for all occurrences Buf_Switch(#11) //Switch to the source file Search("|<|@(15)",BEGIN+ERRBREAK) //IB 21/04/2004 Search for line matching 1st 100 chars if(Compare(16) == 0) //IB 21/04/2004 Check if matching is exact (except CASE) { If(Match("|L",ERRBREAK) == 0) //IB 21/04/2004 ensure at EOL { RCB(0,CP-#16,CP+Chars_Matched,DELETE) //IB 21/04/2004 Move line to T-Reg 0 Buf_Switch(#14) //Switch to "removed" lines buffer Reg_Ins(0) //Add the "removed" line } } } Buf_Switch(#12) //Switch back to remove-list buffer } Line(1,ERRBREAK) //Advance to next item; break-out at EOF } // // Show destination file and Save/abandon it. // Buf_Switch(#11) //Switch to source/destination file if (File_Size < 1000000) { Begin_Of_File } // Go to beginning if small file Update() //Show the destination file while ((#10=Get_Key("\nSave destination file? [Y]es [N]o-abandon [C]ancel")&0xFFDF)!='Y' && #10!='N' && #10!='C') { Alert } //Wait for valid reply if (#10=='Y') { Buf_Close(NOMSG) //Save file and close buffer Buf_Switch(#18) //Back to original file Return } if (#10=='N') { Buf_Quit(OK) //Abandon file and close buffer Buf_Switch(#18) //Back to original file Return }