// // SEARCH-GRP.VDM Ch. Ziemski 18.11.2003 // 19.11.2003 // // Sucht in einer strukturierten Textdatei nach durch einem String // markierten Blöcken und dortdrin jeweils nach einem weiteren String. // // Gibt dann von allen Blöcken, die den 2. Suchstring enthalten, sowohl // Titel als auch Fundzeilen aus. // Reg_Push(90,99) Num_Push(90,99) Reg_Set(91,"#@$%&***") // search title, default Reg_Set(92,"/daten/transfer") // search string, default Reg_Empty(93) // found title Reg_Empty(94) // found contents for current title #91 =1 // 1 for pattern matching and 2 for regex (default for DI_1()) #92 =1 // 1 for pattern matching and 2 for regex (default for DI_1()) #99=Dialog_Input_1(91,"`Search Groups or so ...`, `Let me try a description: You can search in a file structured by special title lines/strings. Every group/paragraph in which the contents search string is found is listed with it's title line and found strings/lines. `, `??&Group title search string:`, ` using`, `.h()pattern matching or`, `.h()regular expressions`, ` `, `??Contents search s&tring: `, ` using`, `.h()pattern matching or`, `.h()regular expressions`, ` `, `[&Search]`, `[&Cancel]`", @91,SET+WORKAREA+CENTER,0,0) if ( #99 != 1 ) { Num_Pop(90,99) Reg_Pop(90,99) return } #95=Buf_Num #96=Buf_Free // prepare the search strings Reg_Set(103, @91) Call("Set_Delim") if (Reg_Size(103) == 0) { Num_Pop(90,99) Reg_Pop(90,99) Buf_Switch(#96) Buf_Quit(OK) return } Reg_Set(104, "Search(") Reg_Set(104, @103, APPEND) Reg_Set(104, ", NOERR", APPEND) if (#91==2) { Reg_Set(104, "+REGEXP)", APPEND) } else { Reg_Set(104, ")", APPEND) } Reg_Set(103, @92) Call("Set_Delim") if (Reg_Size(103) == 0) { Num_Pop(90,99) Reg_Pop(90,99) Buf_Switch(#96) Buf_Quit(OK) return } Reg_Set(105, "Search_Block(") Reg_Set(105, @103, APPEND) Reg_Set(105, ", #103", APPEND) Reg_Set(105, ", #104", APPEND) Reg_Set(105, ", NOERR", APPEND) if (#92==2) { Reg_Set(105, "+REGEXP)", APPEND) } else { Reg_Set(105, ")", APPEND) } Buf_Switch(#96) // to be sure ... Buf_Empty(OK) File_Save_As("|(VEDIT_TEMP)\ved|(PID).txt", OK+NOMSG) Update Buf_Switch(#95) // original buffer Call(104) // search title if (EM) { Num_Pop(90,99) Reg_Pop(90,99) Buf_Switch(#96) Buf_Quit(OK) return } BoL Reg_Copy(93, 1) // save complete title line Line(1, NOERR) #103 = Cur_Pos while (! AT_EoF) { Buf_Switch(#95) // original buffer Call(104) // search next title if (EM) { Reg_Empty(95) EoF } else{ BoL Reg_Copy(95, 1) // save complete title line } Line(1, NOERR) #104 = Cur_Pos Reg_Empty(94) #97=0 Goto_Pos(#103) Call(105) // search string in block #103-#104 while ( ! EM ) { BoL Reg_Copy(94,1, APPEND) // save that contents (whole line) #97=1 Line(1,NOERR+ERRBREAK) Call(105) // search string in block #103-#104 } if ( #97 != 0 ) { Buf_Switch(#96) // append found data to result buffer Update Reg_Ins(93) Ins_NewLine(1) Reg_Ins(94) Ins_NewLine(1) Buf_Switch(#95) } Goto_Pos(#104) #103 = #104 Reg_Set(93,@95) } Buf_Switch(#96) // show results BoF File_Save(NOMSG) Num_Pop(90,99) Reg_Pop(90,99) return //--------------------------------------------------------------------------- // try to find a string delimiter not included in the user's search strings :SET_DELIM: Buf_Switch(#96) // working buffer Buf_Empty(OK) Reg_Ins(103) // the original search string BoF Ins_Text(.`'´"%&*:;/~^=,.) // and all possible delimiters Ins_Text(".") for (#105=0; #105<15 ; #105++) { // loop through all the possible delimiters Goto_Pos(#105) Reg_Copy_Block(103, Cur_Pos, CP+1) // get this possible delimiter Char(1) // advance past it Search(.|@(103)., NOERR) // search for it in the rest of the string if (EM) { // if not found: good Goto_Pos(#105+1) // delete the rest of the possible ones Del_Char(15-#105-1) Del_Block(0, #105) EoF Reg_Ins(103) // and add the found delimiter at end too break // leave the loop } } if (#105 == 15) { // if no delimiter found Dialog_Input_1(99 ,"`Error`, `There are no more string delimiters possible for internal use.\nAll of them are used in your string.`, `Please change your search string a bit!`", WORKAREA+CENTER,0,0) Reg_Empty(103) return // or so ..... } Reg_Copy_Block(103, 0, File_Size) Buf_Empty(OK) Buf_Switch(#95) // original buffer return