From 408364e10d30895f399d96f1433503a34627457a Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 9 Jan 2004 15:22:42 +0000 Subject: perl_checker: entries in generated pot file are sorted by files --- perl_checker.src/info.ml | 6 +++++- perl_checker.src/info.mli | 1 + perl_checker.src/parser_helper.ml | 26 ++++++++++++++------------ perl_checker.src/parser_helper.mli | 3 +-- 4 files changed, 21 insertions(+), 15 deletions(-) (limited to 'perl_checker.src') diff --git a/perl_checker.src/info.ml b/perl_checker.src/info.ml index ca14f9e..d5a1ce8 100644 --- a/perl_checker.src/info.ml +++ b/perl_checker.src/info.ml @@ -59,10 +59,14 @@ let pos2s (file, a, b) = sprintf "(%s, %d, %d)" file a b let pos2sfull pos = try - let (file, line, n1,n2) = pos2line pos in + let file, line, n1, n2 = pos2line pos in sprintf "File \"%s\", line %d, character %d-%d\n" (absolute_file_to_file file) (line + 1) n1 n2 with Not_found -> failwith ("bad position " ^ pos2s pos) +let pos2s_for_po pos = + let file, line, _, _ = pos2line pos in + absolute_file_to_file file ^ ":" ^ string_of_int (line + 1) + let is_on_same_line file (a,b) = let line_a, _ = raw_pos2raw_line file a in let line_b, _ = raw_pos2raw_line file b in diff --git a/perl_checker.src/info.mli b/perl_checker.src/info.mli index bd72bc7..d337316 100644 --- a/perl_checker.src/info.mli +++ b/perl_checker.src/info.mli @@ -11,6 +11,7 @@ val raw_pos2raw_line : string -> int -> int * int val pos2line : string * int * int -> string * int * int * int val pos2s : string * int * int -> string val pos2sfull : string * int * int -> string +val pos2s_for_po : string * int * int -> string val is_on_same_line : string -> int * int -> bool val is_on_same_line_current : int * int -> bool val pos2sfull_current : int -> int -> string diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 557cf26..b95622e 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -687,7 +687,6 @@ let followed_by_comma expr true_comma = let pot_strings = Hashtbl.create 16 -let pot_strings_and_file = Hashtbl.create 16 let po_comments = ref [] let po_comment esp = lpush po_comments esp.any @@ -736,21 +735,25 @@ msgstr \"\" | '\n' -> output_string fd "\\n\"\n\"" | c -> output_char fd c in - Hashtbl.iter (fun s po_comments -> - match Hashtbl.find_all pot_strings_and_file s with + let sorted_pot_strings = List.sort (fun (_, pos_a) (_, pos_b) -> compare pos_a pos_b) + (Hashtbl.fold (fun k (v, _) l -> (k,v) :: l) pot_strings [] ) in + List.iter (fun (s, _) -> + match Hashtbl.find_all pot_strings s with | [] -> () | l -> - List.iter (fun po_comment -> output_string fd ("#. " ^ po_comment ^ "\n")) po_comments; + List.iter (fun _ -> Hashtbl.remove pot_strings s) l ; - List.iter (fun _ -> Hashtbl.remove pot_strings_and_file s) l ; - fprintf fd "#: %s\n" (String.concat " " (List.map (fun s -> Info.absolute_file_to_file s ^ ":1") l)) ; + List.iter (fun po_comment -> output_string fd ("#. " ^ po_comment ^ "\n")) (collect snd l); + + let pos_l = List.sort compare (List.map fst l) in + fprintf fd "#: %s\n" (String.concat " " (List.map Info.pos2s_for_po pos_l)) ; output_string fd "#, c-format\n" ; output_string fd (if String.contains s '\n' then "msgid \"\"\n\"" else "msgid \"") ; String.iter print_formatted_char s ; output_string fd "\"\n" ; output_string fd "msgstr \"\"\n\n" - ) pot_strings ; + ) sorted_pot_strings ; close_out fd let call_raw force_non_builtin_func (e, para) = @@ -769,13 +772,12 @@ let call_raw force_non_builtin_func (e, para) = | "N" | "N_" -> (match para with - | [ List(String([ s, List [] ], (file, pos_a, _)) :: para) ] -> + | [ List(String([ s, List [] ], (_, pos_offset, _ as pos)) :: 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 ; + Hashtbl.add pot_strings s (pos, !po_comments) ; + po_comments := [] ) ; - let contexts = check_format_a_la_printf s pos_a in + let contexts = check_format_a_la_printf s pos_offset in if f = "N" then if List.length para < List.length contexts then warn_rule "not enough parameters" diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli index ede0d18..effa227 100644 --- a/perl_checker.src/parser_helper.mli +++ b/perl_checker.src/parser_helper.mli @@ -181,8 +181,7 @@ val to_Call_op_ : Types.fromparser Types.prio_anyexpr Types.any_spaces_pos val followed_by_comma : Types.fromparser list -> bool -> Types.fromparser list -val pot_strings : (string, string list) Hashtbl.t -val pot_strings_and_file : (string, string) Hashtbl.t +val pot_strings : (string, (string * int * int) * string list) 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 -> Types.maybe_context list -- cgit v1.2.1