// // CHECK-DBL.VDM Christian Ziemski 01.07.2004 // 02.07.2004 // // This macro checks a file for same number of delimiters per line. // For example a CSV formatted file has a comma as delimiter between // the fields in a line. //---------------------------------------------------------------------- // If the following registers are set appropriatly when calling the macro // there will be no dialogs requesting an input to start checking. // Otherwise the user will be asked to give an input. // // Reg_Set(103, ",") // set delimiter character // // if empty or length > 1: show dialog // // #103=4 // number of delimiters per line // // if set to 0: try to find it by myself //---------------------------------------------------------------------- // request an input from the user: // - At least the character used as delimiter // - Optionally the number of delimiters per line // while (Reg_Size(103) < 1) { #106=Dialog_Input_1(103,"`Checking delimiters / line`, `Please enter the delimiter character and the number of required delimiters per line. If the number is ´0´ or empty the macro determines the number by itself and will show a confirmation dialog. `, `?? Character used as delimiter`, `?? # of delimiters per line`, `[Start]`,`[Cancel]`", WORKAREA+CENTER,0,0) if (#106 != 1 ) { return } #103=Num_Eval_Reg(104) // convert string to number } if (#103 == 0) { // Determine the number of delimiters in line #1 Begin_Of_File repeat(ALL) { Search_Block("|@(103)", Cur_Pos, EoL_Pos, NOERR+ADVANCE) if (Error_Match) { break } #103++ } // show dialog for confirmation or change Num_Str(#103, 105, LEFT) #106=Dialog_Input_1(106,"`Input`, `This file seems to have |@(105) delimiters ´|@(103)´ per line.`, `Should the complete file beeing checked with this value?`, `[Yes]`,`[No]`", WORKAREA+CENTER,0,0) if (#106 != 1 ) { return } } // check the complete file for that count of delimiters per line #104=0 // error flag Begin_Of_File while (! At_EoF) { // check for at least #103 occurrences Search_Block("|@(103)", Cur_Pos, EoL_Pos, NOERR+ADVANCE+COUNT, #103) if (Error_Match) { // if too few delimiters #104=1 break } // check for additional occurrence Search_Block("|@(103)", Cur_Pos, EoL_Pos, NOERR) if (! Error_Match) { // if too many delimiters #104=1 break } Line(1, NOERR+ERRBREAK) } Update if (#104) { Dialog_Input_1(106,"`**** Error! ****`, `There is at least one line with a wrong number of delimiters!`", WORKAREA+CENTER,0,0) if (Match("|W|>") == 0 ) { // if on lonely whitespace End_Of_Line } } else { Dialog_Input_1(106,"`Success :-)`, `All lines are having the same number of delimiters!`", WORKAREA+CENTER,0,0) End_Of_File } Reg_Empty(103) Reg_Empty(104) Reg_Empty(105) #103=#104=#105=0