ASIC/FPGA Design and Verification Out Source Services

Run a perl script from vim on a block, to create a list of all c, c++ loaded files.

  1. As it is usual the case, which is presented in this site, some data (text) need to be extracted from a simulation log file.
    In this case all c, c++ and header files are the data to be extracted and create a list of all files, which were loaded, based on it.

  2. The algorithm is simple. Look for \.[ch] lines.
    Upon finding such a line, split on spaces to an array.
    Do more filtering like: start and end characters, remove " etc....

  3. Note: Some of the filtering is done by using perl's index and substr functions. It is easier and quicker to find the first occurrence of a single character in a string and trim the string accordingly.

  4. To execute the script form within vim, type, after putting tags at the start and stop, to mark the block of text, that vim passes to the perl script:
    :'a,'b !perl ~/bin/vim_extract_c_cc_h.pl

    If you need to work on all the file, then there is no need to put any marks. Simply use the file operator:
    :% !perl ~/bin/vim_extract_c_cc_h.pl


    You might also need to pipe the result to remove file repetition:
    cat file | sort | uniq

  5. The code is shown below:

    #!/bin/perl

    #works on FC log
    #extracts loaded files with the following suffixes .c .cc .h
    #ignore all others
    #invocation from within vim
    #:'a,'b !perl ~/bin/vim_extract_c_cc_h.pl

    while (<STDIN>) {
      if($_ =~ /\.[ch]/) {
        chomp($_);
        #.c .cc .h
        #does it contain spaces
        @a=split(/ /, $_);
        $a_n=@a;
        if($a_n == 1) { &prt($_); }
        else {
          foreach $j ( @a ) {
            if($j =~ /\.[ch]/) {
              &prt($j);
            }
          }#foreach
        }
      }
    }

    sub prt {
      #remove "
      my $buf=$_[0];
      if($buf =~ /.*"(.*\.[ch].*)/) {
        $buf=$1;
      }
      #filter .c:111
      my $ix=index($buf, ':');
      if($ix >= 0) {
        $buf=substr($buf, 0, $ix);
      }
      
      #must start with a character or /
      if($buf =~ /^[A-Za-z\/].*\.[ch]$/) {
        print("$buf\n");
      }
      elsif($buf =~ /\.cc/) {
        print("$buf\n");
      }
    }


 


Also available on this project:


Home

Some tips for controlling the xterm title








Search This Site


Feedback This Site




new pages on this site