(************************************************************************) (* * The Rocq Prover / The Rocq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
(* rocq wc - counts the lines of spec, proof and comments in Rocq sources
* Copyright (C) 2003 Jean-Christophe Filliâtre *)
(*s {\bf rocq wc.} Counts the lines of spec, proof and comments in a Rocq source.
It assumes the files to be lexically well-formed. *)
(*i*){ open Printf open Lexing (*i*)
(*s Command-line options. *)
let spec_only = reffalse let proof_only = reffalse let percentage = reffalse let skip_header = reftrue
(*s Counters. [clines] counts the number of code lines of the current file,and[dlines]thenumberofcommentlines.[tclines]and[tdlines]
are the corresponding totals. *)
let slines = ref0 let plines = ref0 let dlines = ref0
let tslines = ref0 let tplines = ref0 let tdlines = ref0
(*s The following booleans indicate whether we have seen spec, proof or commentsofaronthecurrentline;whenanewlineisreached,[newline]
is called and updates the counters accordingly. *)
let seen_spec = reffalse let seen_proof = reffalse let seen_comment = reffalse
let newline () = if !seen_spec then incr slines; if !seen_proof then incr plines; if !seen_comment then incr dlines;
seen_spec := false; seen_proof := false; seen_comment := false
let print_line sl pl dl fo = ifnot !proof_only then printf " %8d" sl; ifnot !spec_only then printf " %8d" pl; ifnot (!proof_only || !spec_only) then printf " %8d" dl;
(match fo with Some f -> printf " %s" f | _ -> ()); if !percentage thenbegin let s = sl + pl + dl in let p = if s > 0then100 * dl / s else0in
printf " (%d%%)" p end;
print_newline ()
let print_file fo = print_line !slines !plines !dlines fo
let print_totals () = print_line !tslines !tplines !tdlines (Some "total")
(*i*)}(*i*)
(*s Shortcuts for regular expressions. The [rcs] regular expression isusedtoskiptheCVSinfospossiblycontainedinsomecomments,
in order not to consider it as documentation. *)
(*s The following entry [read_header] is used to skip the possible header at thebeginningoffiles(unlessoption\texttt{-e}isspecified). Itstopswheneveritencountersanemptylineoranycharacteroutside acomment.Inthislastcase,itcorrectlyresetsthelexerposition
on that character (decreasing [lex_curr_pos] by 1). *)
let process_channel ch = let lb = Lexing.from_channel ch in
reset_counters (); if !skip_header then read_header lb;
spec lb
let process_file f = try let ch = open_in f in
process_channel ch;
close_in ch;
print_file (Some f);
update_totals () with
| Sys_error s ->
flush stdout; eprintf "rocq wc: %s: %s\n" f s; flush stderr
(*s Parsing of the command line. *)
let usage () =
prerr_endline "usage: rocq wc [options] [files]";
prerr_endline "Options are:";
prerr_endline " -p print percentage of comments";
prerr_endline " -s print only the spec size";
prerr_endline " -r print only the proof size";
prerr_endline " -e (everything) do not skip headers";
exit 1
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.