// // TAB2FIX-2.VDM Christian Ziemski 22.02.2004 // 20.08.2004 // // // *** Experimental release regarding more than 32 TABs! (up to 100) *** // // Converts TAB separated data into fixed length data // (Based on CSV2TAB.VDM) // // Note: // Up to VEDIT 6.11 there is a limitation of 32 TABs up to column 254. // That is enhanced to ~100 TABs up to around column 65000 // in the upcoming version of VEDIT. // // 6.12: // Up to column 65535, but still restricted number of different sized TABs // (To be precise: The memory storing the TAB positions seems to be max. 141 bytes.) // (There are more *Equal sized* TABs possible, but not yet implemented here.) // BoF Search("|T", BEGIN+NOERR) // any TAB separators found? if (EM) { return // no? then nothing to do } // simple check for number of TABs, (assuming equal lines!) BoF #103=0 while (Search_Block("|T", Cur_Pos, EoL_Pos, ADVANCE+NOERR)>0) { #103++ } if (#103>100) { Num_Str(#103, 103) #104=Dialog_Input_1(104, "`TAB2FIX.VDM`, `Sorry, this macro only supports max. 100 TABs.`, `The current file seems to have |@(103) TABs in a line.`, `[&Ok]`",APP+CENTER,0,0) return } if (#103>32) { Num_Str(#103, 103) #104=Dialog_Input_1(104, "`TAB2FIX.VDM`, `The current file seems to have more than 32 (|@(103)) TABs in a line.`, `Let's try to do it anyway...`, `[&Ok]`,`[&Cancel]`",APP+CENTER,0,0) if (#104 != 1) { return } } Num_Push(1,100) // save used registers for (#103=1; #103<101; #103++) { // set them all to zero #@103=0 } BoF while (! At_EoF) { // loop through all data lines #103=1 // counter for TABs #104=1 // current character position in line while (#103 < 101) { // loop through current line and Search_Block("|T", Cur_Pos, EoL_Pos, NOERR+ERRBREAK) #105 = Cur_Pos-BoL_Pos-#104+1 // length of current field #@103 = Max(#@103, #105) // find max. length of n'th field Char(1) #104=Cur_Pos-BoL_Pos+1 // current character position in line #103++ } Line(1, NOERR) } Out_Reg(103) // build the string of new TABulator positions #104=1 // current cursor column for (#103=1; #103<101; #103++) { // loop through all found data fields if (#@103==0) { break } #105=#@103+#104+1 // incl. one character between fields (needed!) Num_Type(#105, NOCR) #104 = #105 } Out_Reg(CLEAR) if (#103==2) { // if only one Tab => extra handling Out_Reg(103) // this position 2 times Num_Type(#1, NOCR) Num_Type(#1, NOCR) // (otherwise it would be Out_Reg(CLEAR) // interpreted as distance !) } if (Reg_Size(103) > 140) { // 140 Bytes seem to be an internal limit #104=Dialog_Input_1(104, "`TAB2FIX.VDM`, `Problem: There have been really too many TABs :-(`, `[Continue &anyway]`,`[&Cancel]`",APP+CENTER,0,0) if (#104 != 1) { Num_Pop(1,100) // restore used registers return } } Reg_Set(103,"Config_Tab(", INSERT) // command begin -> R.103 Reg_Set(103,")", APPEND) // command end -> R.103 Call(103) // execute the built command Detab_Block(0, File_Size) // TABs to spaces Num_Pop(1,100) // restore used registers BoF