| Cobra | Interactive Query Language | display pattern matches | ||
|---|---|---|---|---|
| NAMEdisplay patternsSYNTAXdp help dp * dp [Setname *] dp [Setname *] n dp [Setname *] N M dp [Setname *] n N M dp filter file.c # restrict output of dp to matches in file.c dp filter off # remove filter on dp output DESCRIPTIONThis command is intended to be used to display or summarize the results of a pe pattern expression command.
The command-name can be followed by a * to print the contents of all
currently defined pattern sets, or the name of a specific pattern set
that was created earlier (either directly through a pe
command, or seperately with the pattern set command ps.
In this case the patterns displayed are taken from the named set only.
 
With a single positive integer argument n, only the n-th match is displayed.
 The dp filter command can be used to define, or undefine, a filter on the output from dp commands, by restricting matches reported for only one specific file. By default this filter is off. EXAMPLES
	$ cobra *.c	# Cobra source directory
	: # look for fct parameters used to index arrays without bounds checking
	: pe @type @ident ( .* x:@ident .* ) { ^:x* \( :x ^[> <] \)* ^:x* [ :x ] .* }
	2 patterns matched
	230 tokens marked
	: json
	[
	  { "type"      :       " ",
	    "message"   :       "lines 728..746",
	    "file"      :       "cobra_eval.c",
	    "line"      :       728,
	  },
	  { "type"      :       " ",
	    "message"   :       "lines 1317..1335",
	    "file"      :       "cobra_prog.c",
	    "line"      :       1317,
	  }
	]
	: dp 1			# print source for the first match (18 lines)
	cobra_eval.c:728..746
	bound var 'yyrule', line 732
	   728  static void
	   729  yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
	   730  {
	   731    unsigned long int yylno = yyrline[yyrule];
	>  732    int yynrhs = yyr2[yyrule];
	   733    int yyi;
	   734    YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
	   735               yyrule - 1, yylno);
	   736    /* The symbols being reduced.  */
	   737    for (yyi = 0; yyi < yynrhs; yyi++)
	   738      {
	   739        YYFPRINTF (stderr, "   $%d = ", yyi + 1);
	   740        yy_symbol_print (stderr,
	   741                         yystos[yyssp[yyi + 1 - yynrhs]],
	   742                         &(yyvsp[(yyi + 1) - (yynrhs)])
	   743                                                );
	   744        YYFPRINTF (stderr, "\n");
	   745      }
	   746  }
	: dp			# print source for all matches
	...
	: dp 1 18 18		# print only the first match of 10 lines long
	...			# produces the same output in this case
	: terse on		# switch to terse mode
	: dp			# print a terser summary of all matches
	cobra_eval.c:728..746
	bound var 'yyrule', line 732
	   728  static void
	   729  yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
	 ...
	   745      }
	   746  }
	cobra_prog.c:1317..1335
	bound var 'yyrule', line 1321
	  1317  static void
	  1318  yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
	 ...
	  1334      }
	  1335  }
	2 of 2 patterns printed
	: terse off		# turn off terse mode again
	: B cobra_prog.c 1317	# look at the context for the 2nd match
	: q			# quit
	$
NOTESStarting with Cobra Version 4.2 (September 2022), entries from pattern sets can be suppressed from being displayed with a dp command by placing a special comment on the line where a matching pattern would start. The suppressing comment should contain the name of one or more pattern sets separated by spaces and preceded by the string @suppress which is preceded and followed by a single space. For example, this comment places on line 9 in cobra_cfg.c:#define Match(x) (strcmp(cur->txt, x) == 0) // @suppress Macrosprevents the warning from the pattern set named Macros in cobra query set rules/main/basic.cobra from being displayed. If multiple pattern sets can match the line and all should be suppressed, the set-names can be listed, separated by spaces, as in: #define Match(x) (strcmp(cur->txt, x) == 0) // @suppress Params Macros SEE ALSOpattern searches, B browse source, pe pattern expressions, json, display, list, pre, | ||||
| Return to index Manual Tutorial | (Last Updated: 13 September 2022) | |||