// // FLAT2CSV.VDM Christian Ziemski 07.07.2004 // // Converts a flat text like: // // Ted Green 100 Main Street Ann Arbor MI // Thomas Burt 200 Division Street Ann Arbor MI // // to something like: // // "Ted","Green","100 Main Street","Ann Arbor","MI" // "Thomas","Burt","200 Division Street","Ann Arbor","MI" // // Using a template defining the number of whitespace-delimited "words" // per entry in a line. // If there are more "words" in a line than defined, the reminder is // combined into one entry. // //--------------------------------------------------------------------- // Reg_Set(103, "1 1 3 2 1") // the template describing the source //Reg_Set(103, "*") // every word will become a single entry Reg_Set(104, ",") // the delimiter for the target #106=0 if ((Reg_Size(103)==0) || (Reg_Compare(103, "*") == 0)) { #106=1 } #104=Buf_Num #105=Buf_Switch(Buf_Free) Reg_Ins(103) BoF Buf_Switch(#104) BoF while (! At_EoF) { Ins_Text(`"`) if (#106==0) { Buf_Switch(#105) #103=Num_Eval(ADVANCE) Buf_Switch(#104) } else { #103=1 } Search_Block("|W", Cur_Pos, EoL_Pos, NOERR+COUNT, #103) if (EM) { EoL Ins_Text(`"`) } else { Ins_Text(`"`) Reg_Ins(104) Del_Char(Chars_Matched) } if (At_EoL) { Buf_Switch(#105) BoF Buf_Switch(#104) Line(1, NOERR) } } Buf_Switch(#105) Buf_Quit(OK) Buf_Switch(#104)