Skip to content

Commit 7b01abf

Browse files
committed
csgrep.1: add example explaining what checker/evt/msg are
... and move the description of available modes into the man page only Suggested-by: Petr Špaček
1 parent c8ca241 commit 7b01abf

File tree

3 files changed

+54
-23
lines changed

3 files changed

+54
-23
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,16 @@ endif()
109109

110110
# macro to generate a man page from the corresponding binary
111111
macro(create_manpage BINARY)
112+
set(H2M_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${BINARY}.h2m")
113+
if(EXISTS "${H2M_INCLUDE}")
114+
set(H2M_ARGS --include ${H2M_INCLUDE})
115+
else()
116+
set(H2M_ARGS "")
117+
endif()
112118
add_custom_command(TARGET ${BINARY} POST_BUILD
113-
COMMAND ${HELP2MAN} --no-info --section 1
119+
COMMAND ${HELP2MAN} --no-info --section 1 ${H2M_ARGS}
114120
${CMAKE_CURRENT_BINARY_DIR}/${BINARY}
115-
> ${BINARY}.1
121+
> ${BINARY}.1 || rm -f ${BINARY}.1
116122
COMMENT "Generating ${BINARY} man page"
117123
VERBATIM)
118124
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BINARY}.1

csgrep.cc

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -487,25 +487,6 @@ bool chainFilters(
487487
template <class TDesc, class TStream>
488488
void printUsage(TStream &str, const TDesc &desc) {
489489
desc.print(str);
490-
str << "\n\n\
491-
DESCRIPTION OF AVAILABLE MODES\n\
492-
------------------------------\n\
493-
\n\
494-
dig_key_events - for each defect, print only the checker and key event\n\
495-
\n\
496-
evtstat - print overall checker/key_event statistics for the matched defects\n\
497-
\n\
498-
files - print only names of error files that contain the matched defects\n\
499-
\n\
500-
filestat - print statistics of matched defects per individual source files\n\
501-
\n\
502-
grep - print matched defects using the same format as expected on the input\n\
503-
\n\
504-
grouped - print matched defects, grouped by error files they originate from\n\
505-
\n\
506-
json - print matched defects in a JSON format\n\
507-
\n\
508-
stat - print overall statistics of the matched defects in given error files\n\n";
509490
}
510491

511492
template <class TDecorator>
@@ -547,9 +528,9 @@ int main(int argc, char *argv[])
547528

548529
try {
549530
desc.add_options()
550-
("checker", po::value<string>(), "defect matches if its checker matches the given regex")
531+
("checker", po::value<string>(), "defect matches if its checker matches the given regex (each defect has assigned exactly one checker)")
551532
("path", po::value<string>(), "defect matches if the path of its key event matches the given regex")
552-
("event", po::value<string>(), "defect matches if its key event matches the given regex")
533+
("event", po::value<string>(), "defect matches if its key event matches the given regex (each defect has exactly one key event, which determines its location in the code)")
553534
("error", po::value<string>(), "defect matches if the message of its key event matches the given regex")
554535
("msg", po::value<string>(), "defect matches if any of its messages matches the given regex")
555536
("annot", po::value<string>(), "defect matches if its annotation matches the given regex")

csgrep.h2m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[NAME]
2+
csgrep - filter the list of defects by the specified regex-based predicates
3+
4+
[EXAMPLE - CHECKERS, EVENTS, MESSAGES]
5+
.nf
6+
Error: FORWARD_NULL (CWE-476):
7+
libhsm.c:1168: assign_zero: Assigning: key_handles = NULL.
8+
libhsm.c:1210: var_deref_op: Dereferencing null pointer key_handles.
9+
.fi
10+
11+
In the above example, FORWARD_NULL is the
12+
.B checker
13+
, assign_zero and var_deref_op are
14+
.B events
15+
, where var_deref_op is the key event and
16+
"Dereferencing null pointer key_handles." is the
17+
.B message
18+
associated with the key event.
19+
20+
[DESCRIPTION OF AVAILABLE MODES]
21+
22+
.B dig_key_events
23+
- for each defect, print only the checker and key event
24+
25+
.B evtstat
26+
- print overall checker/key_event statistics for the matched defects
27+
28+
.B files
29+
- print only names of error files that contain the matched defects
30+
31+
.B filestat
32+
- print statistics of matched defects per individual source files
33+
34+
.B grep
35+
- print matched defects using the same format as expected on the input
36+
37+
.B grouped
38+
- print matched defects, grouped by error files they originate from
39+
40+
.B json
41+
- print matched defects in a JSON format
42+
43+
.B stat
44+
- print overall statistics of the matched defects in given error files

0 commit comments

Comments
 (0)