Cobra Interactive Query Language commandline options

NAME

Cobra commandline options

DESCRIPTION

	$ cobra -?		# Assuming version 2.4 or later
	cobra: unrecognized option '-?'
	usage: cobra [-option]* [file]*
 	-Ada                -- recognize Ada keywords (implies -nocpp)
	-allheaderfiles     -- process all header files (also system headers)
	-C++                -- recognize C++ keywords
	-c "commands"       -- execute commands and stop (cf -e, -f)
	-c "m /regex; p"    -- find tokens matching a regular expr
	-comments           -- include comments as tokens (unless -cpp is also used) <- new
	-configure dir      -- set and remember the name for the cobra rules directory
	-cpp                -- enable C preprocessing
	-d and -v -d        -- debug cobra inline program executions
	-eof                -- treat end-of-file as added tokens named EOF
	-eol                -- treat newlines as added tokens named EOL
	-e name             -- (or -expr or -regex) print lines with tokens matching name
	-e "token_expr"     -- print lines matching a token_expr (cf -view)
	                       use meta-symbols: ( | ) . * + ?
	                       use ^name for not-matching name
	                       var-binding:   name:@ident
	                       var-reference: :name
	                       see also -pattern (or -pat)
	-f file             -- execute commands from file and stop (cf -view)
	-F list             -- use the files in file 'list' as inputs (one per line)
	-Idir, -Dstr, -Ustr -- preprocessing directives
	-Java               -- recognize Java keywords
	-json               -- output result of a -pe query in json format
	-json+              -- output more detailed result of a -pe query in json format
	-lib                -- list available predefined cobra -f checks
	-m or -macros       -- parse text of macros (implies -nocpp)
	-n or -nocpp        -- do not do any C preprocessing (default)
	-noqualifiers       -- do not tag qualifiers
	-noheaderfiles      -- do not process header files
	-notypedefs         -- do not process typedefs
	-notypes            -- do not tag type names
	-Nn                 -- use n threads
	-pat or -pattern    -- see -pe
	-pe "tokens"        -- like -e but simplified: (|)+? are regular symbols
	                       * and ] are meta-symbols unless preceded by a space
	                       [ is a meta-symbol unless followed by a space
	-preserve           -- preserve temporary files
	-Python             -- recognize Python keywords
	-quiet              -- do not print script commands executed or nr of matches
	-recursive 'pattern' -- use 'find pattern' to find files to process (cf. -F)
	-regex "expr"       -- see -e
	-runtimes           -- report runtimes of commands executed, if >1s
	-scrub              -- produce output in scrub-format
        -stream N           -- set stdin stream buffer-limit to N bytes (default 8192)
        -stream_margin N    -- set stdin window margin to N tokens (default 1000)
        -terse              -- disable output from d, l, and p commands, implies -quiet
        -text               -- no token types, just text-strings and symbols
	-tok                -- only tokenize the input
	-version            -- print version number and exit
	-v                  -- more verbose
	-view -f file       -- show dot-graph of DFA(s) of inline program(s)
	-view -e "token_expr" -- show dot-graph of NDFA for token_expr
	-V                  -- print version number and exit
	-var name=value     -- set name in def-script to value (cf. -f)

arguments starting with -- are passed as-is to standalone backends,
if such a backend was defined, otherwise they are ignored (e.g. --debug)
When preprocessing is not enabled (the default mode) beware that if source code isn't reasonably behaved the scanner can become confused about pairs of parentheses, brackets, or braces that it will try to match. In the following example, for instance, it would appear (with preprocessing disabled) that there are more closing braces than opening braces:
	badstyle()
	{	printf(
	#ifdef X
		"disk");
	#else
		*argv);
	#endif
	}
Cobra will warn if this happens for any source file it scans.
The problem can be avoided either by allowing the preprocessor to run, or by formatting the code itself differently. For instance:
	badstyle()
	{	printf(
	#ifdef X
		"disk"
	#else
		*argv
	#endif
		);
	}
In cases where not all headerfiles from #include directives are available, it can sometimes still be better to leave preprocessing enabled, and to ignore the preprocessors error messages that result, to improve the consistency of the data structure.

One convenient way of debuggin pattern expression matching is to first display the NDFA, using

	$ cobra -view -pe "pattern" file.c
and then run the pattern matching in verbose mode (on a small sample file) as
	$ cobra -v -pe "pattern" file.c

Return to index
Manual
Tutorial
(Last Updated: 19 March 2021)