// // CSV2TAB.VDM Christian Ziemski 22.02.2004 // // // Converts CSV separated data into TAB separated data // and sets VEDIT's TABs accordingly. // // The CSV separator character (";" as default) can be configured below. // // 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. // Reg_Set(104,";") // the CSV-separator BoF Search(@104, BEGIN+NOERR) // any separators found? if (EM) { return // no? then nothing to do } Num_Push(1,32) // save used registers for (#103=1; #103<33; #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 cursor column while (#103 < 33) { // loop through current line and Search_Block(@104, Cur_Pos, EoL_Pos, NOERR+ERRBREAK+ADVANCE) #105 = Cur_Col-1-#104 #@103 = Max(#@103, #105) // find max. length of n'th CSV-field #104=Cur_Col #103++ } Line(1, NOERR) } Out_Reg(103) // build the string of TABulator positions #104=0 // current cursor column for (#103=1; #103<33; #103++) { // loop through all found data fields if (#@103==0) { break } Num_Type(#@103+#104+2, NOCR) // incl. one character between fields #104 = #104+#@103+2 } 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 !) } Reg_Set(103,"Config_Tab(", INSERT) // command begin -> R.103 Reg_Set(103,")", APPEND) // command end -> R.103 Call(103) // execute the built command BoF Replace(@104, "|T", BEGIN+ALL) // replace all CSV separators with TABs Num_Pop(1,32) // restore used registers BoF