From 38d1fcc6e59327f5739ab00e048bee55fc6b2791 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 16 Dec 2003 21:56:54 +0000 Subject: check the number of parameters given to N() --- perl_checker.src/parser_helper.ml | 29 +++++++++++++++++++---------- perl_checker.src/parser_helper.mli | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index a7d48f1..117dfee 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -690,17 +690,21 @@ let po_comments = ref [] let po_comment esp = lpush po_comments esp.any let check_format_a_la_printf s pos = - let rec check_format_a_la_printf_ i = + let rec check_format_a_la_printf_ contexts i = try let i' = String.index_from s i '%' in try - (match s.[i' + 1] with - | '%' | 'd' | 's' | 'c' -> () - | c -> warn (pos + i', pos + i') (sprintf "invalid command %%%c" c)); - check_format_a_la_printf_ (i' + 2) - with Invalid_argument _ -> warn (pos + i', pos + i') "invalid command %" - with Not_found -> () - in check_format_a_la_printf_ 0 + let contexts = + match s.[i' + 1] with + | '%' -> contexts + | 'd' -> M_int :: contexts + | 's' | 'c' -> M_string :: contexts + | c -> warn (pos + i', pos + i') (sprintf "invalid command %%%c" c); contexts + in + check_format_a_la_printf_ contexts (i' + 2) + with Invalid_argument _ -> warn (pos + i', pos + i') "invalid command %" ; contexts + with Not_found -> contexts + in check_format_a_la_printf_ [] 0 let generate_pot file = let fd = open_out file in @@ -763,13 +767,18 @@ let call_raw force_non_builtin_func (e, para) = | "N" | "N_" -> (match para with - | [ List(String([ s, List [] ], (file, pos_a, _)) :: _) ] -> + | [ List(String([ s, List [] ], (file, pos_a, _)) :: para) ] -> if !Flags.generate_pot then ( Hashtbl.replace pot_strings s ((try Hashtbl.find pot_strings s with Not_found -> []) @ !po_comments) ; po_comments := [] ; Hashtbl.add pot_strings_and_file s file ; ) ; - check_format_a_la_printf s pos_a ; + let contexts = check_format_a_la_printf s pos_a in + if f = "N" then + if List.length para < List.length contexts then + warn_rule "not enough parameters" + else if List.length para > List.length contexts then + warn_rule "too many parameters" ; (*if String.contains s '\t' then warn_rule "tabulation in translated string must be written \\\\t";*) (*if count_matching_char s '\n' > 10 then warn_rule "long string";*) None diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli index 678c6f8..ec86b55 100644 --- a/perl_checker.src/parser_helper.mli +++ b/perl_checker.src/parser_helper.mli @@ -182,7 +182,7 @@ val pot_strings : (string, string list) Hashtbl.t val pot_strings_and_file : (string, string) Hashtbl.t val po_comments : string list ref val po_comment : string Types.any_spaces_pos -> unit -val check_format_a_la_printf : string -> int -> unit +val check_format_a_la_printf : string -> int -> Types.maybe_context list val generate_pot : string -> unit val call_raw : bool -> Types.fromparser * Types.fromparser list -> Types.fromparser -- cgit v1.2.1