summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-12-16 21:56:54 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-12-16 21:56:54 +0000
commit38d1fcc6e59327f5739ab00e048bee55fc6b2791 (patch)
tree113ed112d26ea512e4de7bddffe126bfb9781b36 /perl_checker.src
parentaef43c0a0529b1659b42bb94c4c70a3948d71834 (diff)
downloadperl_checker-38d1fcc6e59327f5739ab00e048bee55fc6b2791.tar
perl_checker-38d1fcc6e59327f5739ab00e048bee55fc6b2791.tar.gz
perl_checker-38d1fcc6e59327f5739ab00e048bee55fc6b2791.tar.bz2
perl_checker-38d1fcc6e59327f5739ab00e048bee55fc6b2791.tar.xz
perl_checker-38d1fcc6e59327f5739ab00e048bee55fc6b2791.zip
check the number of parameters given to N()
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser_helper.ml29
-rw-r--r--perl_checker.src/parser_helper.mli2
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