# HG changeset patch # User Adam Chlipala # Date 1555877395 14400 # Node ID 3fc43e261f672ea5e8a67b555daf37a10b56dccf # Parent c3d4217e1da736bac8eb9c62247ac1c2f1b4f25f Spacing and indentation fixes in tools, from Chen Yiwu diff -r c3d4217e1da7 -r 3fc43e261f67 tools/bsd_license.ml --- a/tools/bsd_license.ml Sun Jan 20 15:44:31 2019 -0500 +++ b/tools/bsd_license.ml Sun Apr 21 16:09:55 2019 -0400 @@ -1,4 +1,4 @@ -let read_line () = +let read_line () = try Some (read_line ()) with End_of_file -> None @@ -31,44 +31,44 @@ print_endline " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE"; print_endline " * POSSIBILITY OF SUCH DAMAGE." end - + let rec initial () = match read_line () with | None -> () | Some line -> - let trimmed = String.trim line in - if String.length trimmed >= 12 && String.sub trimmed 0 12 = "(* Copyright" then begin - print_endline line; - copyright_block () - end else - print_endline line; - initial () + let trimmed = String.trim line in + if String.length trimmed >= 12 && String.sub trimmed 0 12 = "(* Copyright" then begin + print_endline line; + copyright_block () + end else + print_endline line; + initial () and copyright_block () = match read_line () with | None -> () | Some line -> - let trimmed = String.trim line in - if String.length trimmed >= 2 && String.sub trimmed 0 2 = "*)" then begin - print_endline line; - initial () - end else if String.length trimmed >= 31 && String.sub trimmed 0 31 = "* This work is licensed under a" then begin - print_endline line; - print_bsd_licence (); - drop_to_end_comment () - end else - print_endline line; - copyright_block () + let trimmed = String.trim line in + if String.length trimmed >= 2 && String.sub trimmed 0 2 = "*)" then begin + print_endline line; + initial () + end else if String.length trimmed >= 31 && String.sub trimmed 0 31 = "* This work is licensed under a" then begin + print_endline line; + print_bsd_licence (); + drop_to_end_comment () + end else + print_endline line; + copyright_block () and drop_to_end_comment () = match read_line () with | None -> () | Some line -> - let trimmed = String.trim line in - if String.length trimmed >= 2 && String.sub trimmed 0 2 = "*)" then begin - print_endline line; - initial () - end else - drop_to_end_comment () + let trimmed = String.trim line in + if String.length trimmed >= 2 && String.sub trimmed 0 2 = "*)" then begin + print_endline line; + initial () + end else + drop_to_end_comment () let () = initial () diff -r c3d4217e1da7 -r 3fc43e261f67 tools/make_template.ml --- a/tools/make_template.ml Sun Jan 20 15:44:31 2019 -0500 +++ b/tools/make_template.ml Sun Apr 21 16:09:55 2019 -0400 @@ -1,4 +1,4 @@ -let read_line () = +let read_line () = try Some (read_line ()) with End_of_file -> None @@ -8,50 +8,50 @@ | None -> () | Some "(* begin thide *)" -> thide last_was_empty | Some "" -> - if not (last_was_empty) then - print_newline (); - initial true + if not (last_was_empty) then + print_newline (); + initial true | Some line -> - let idx = try Some (String.index line '(') with Not_found -> None in - match idx with - | Some idx -> - if String.length line > idx+1 && line.[idx+1] = '*' - && not (String.length line > idx+4 && String.sub line (idx+2) 3 = " EX") then - if line.[String.length line - 2] = '*' && line.[String.length line - 1] = ')' then - initial last_was_empty - else - comment 1 last_was_empty - else begin - print_endline line; - initial false - end - | None -> - print_endline line; - initial false + let idx = try Some (String.index line '(') with Not_found -> None in + match idx with + | Some idx -> + if String.length line > idx+1 && line.[idx+1] = '*' + && not (String.length line > idx+4 && String.sub line (idx+2) 3 = " EX") then + if line.[String.length line - 2] = '*' && line.[String.length line - 1] = ')' then + initial last_was_empty + else + comment 1 last_was_empty + else begin + print_endline line; + initial false + end + | None -> + print_endline line; + initial false and comment count last_was_empty = match read_line () with | None -> () | Some line -> - if String.length line >= 2 && line.[0] = '(' && line.[1] = '*' then - if String.length line >= 2 && line.[String.length line - 2] = '*' - && line.[String.length line - 1] = ')' then - comment count last_was_empty - else - comment (count+1) last_was_empty - else if String.length line >= 2 && line.[String.length line - 2] = '*' - && line.[String.length line - 1] = ')' then - if try - let idx = String.index line '(' in - idx < String.length line - 1 && line.[idx + 1] = '*' - with Not_found -> false then - comment count last_was_empty - else if count = 1 then - initial last_was_empty - else - comment (count-1) last_was_empty + if String.length line >= 2 && line.[0] = '(' && line.[1] = '*' then + if String.length line >= 2 && line.[String.length line - 2] = '*' + && line.[String.length line - 1] = ')' then + comment count last_was_empty else - comment count last_was_empty + comment (count+1) last_was_empty + else if String.length line >= 2 && line.[String.length line - 2] = '*' + && line.[String.length line - 1] = ')' then + if try + let idx = String.index line '(' in + idx < String.length line - 1 && line.[idx + 1] = '*' + with Not_found -> false then + comment count last_was_empty + else if count = 1 then + initial last_was_empty + else + comment (count-1) last_was_empty + else + comment count last_was_empty and thide last_was_empty = match read_line () with diff -r c3d4217e1da7 -r 3fc43e261f67 tools/prepare_spellcheck.ml --- a/tools/prepare_spellcheck.ml Sun Jan 20 15:44:31 2019 -0500 +++ b/tools/prepare_spellcheck.ml Sun Apr 21 16:09:55 2019 -0400 @@ -1,4 +1,4 @@ -let read_line () = +let read_line () = try Some (read_line ()) with End_of_file -> None @@ -17,8 +17,8 @@ try let pos = Str.search_forward (Str.regexp "\\[\\|%\\|#") s n in let ender = match s.[pos] with - | '[' -> ']' - | _ -> s.[pos] in + | '[' -> ']' + | _ -> s.[pos] in let pos' = String.index_from s (pos+1) ender in san (pos'+1) (acc ^ String.sub s n (pos-n)) with Not_found -> acc ^ Str.string_after s n @@ -28,52 +28,52 @@ match read_line () with | None -> () | Some line -> - match strstr "(**" line with - | None -> initial () - | Some pos -> - match strstr "*)" line with - | None -> - begin match strstr "[[" line with - | None -> - print_endline (sanitize (Str.string_after line (pos+3))); - comment () - | Some _ -> runTo "]]" - end - | Some pos' -> - let rest = Str.string_after line (pos+3) in - if not (prefix " printing" rest || prefix " begin" rest || prefix " end" rest) then - print_endline (sanitize (String.sub line (pos+3) (pos' - (pos+3)))); - initial () + match strstr "(**" line with + | None -> initial () + | Some pos -> + match strstr "*)" line with + | None -> + begin match strstr "[[" line with + | None -> + print_endline (sanitize (Str.string_after line (pos+3))); + comment () + | Some _ -> runTo "]]" + end + | Some pos' -> + let rest = Str.string_after line (pos+3) in + if not (prefix " printing" rest || prefix " begin" rest || prefix " end" rest) then + print_endline (sanitize (String.sub line (pos+3) (pos' - (pos+3)))); + initial () and comment () = match read_line () with | None -> () | Some line -> - match strstr "*)" line with - | None -> - begin match strstr "[[" line with - | None -> - begin match strstr "<<" line with - | None -> - print_endline (sanitize line); - comment () - | Some _ -> runTo ">>" - end - | Some _ -> runTo "]]" - end - | Some pos -> - print_endline (sanitize (Str.string_before line pos)); - initial () + match strstr "*)" line with + | None -> + begin match strstr "[[" line with + | None -> + begin match strstr "<<" line with + | None -> + print_endline (sanitize line); + comment () + | Some _ -> runTo ">>" + end + | Some _ -> runTo "]]" + end + | Some pos -> + print_endline (sanitize (Str.string_before line pos)); + initial () and runTo ender = match read_line () with | None -> () | Some line -> - match strstr ender line with - | None -> runTo ender - | _ -> - match strstr "*)" line with - | None -> comment () - | _ -> initial () + match strstr ender line with + | None -> runTo ender + | _ -> + match strstr "*)" line with + | None -> comment () + | _ -> initial () let () = initial ()