--- layout: fc_discuss_archives title: Message 3 from Frama-C-discuss on June 2010 ---
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Frama-c-discuss] Unknows Pragma



Hello,

> I got the command to work. But obviously I have several other pragmas that
> should be ignored. Seems like I will need the perlscript anyway.

It is a little longer in OCaml than in Perl, but it was faster for me
to write this way
(and it doesn't add dependencies since you already have OCaml now).

___

let description = "\\(#pragma LINK_INFO.*\\)"
  ^ "\\|" ^ "\\(#pragma foo\\)"

let regexp = Str.regexp description

let () =
  try
    while true; do
      let line = input_line stdin in
      if Str.string_match regexp line 0
      then print_newline ()
      else print_endline line
    done;
  with End_of_file -> ()
___

Name the file gr.ml.

Compile with:
ocamlc -o gr str.cma gr.ml

or even better, if you have ocamlopt, use instead:
ocamlopt -o gr str.cmxa gr.ml

The command gr reads from its standard input and emits a filtered file
on its standard output.

___

#pragma bar
#pragma foo
#pragma zut
#pragma LINK_INFO blah, blah

int main()
{
	return 0; /* hopefully all goes well. */
}
___

gr < test.c
___

#pragma bar

#pragma zut


int main()
{
	return 0; /* hopefully all goes well. */
}
___

Use frama-c with the option:
-cpp-command "gcc -C -E -I. - <  %1 | gr > %2"

The syntax for regular expressions is at:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Str.html

Note that unlike grep, you must use regexps that match the entire line
that you wish to me removed. Use .* at the beginning and end of your
regexps if appropriate.

Pascal