Email: bknpk@hotmail.com Phone: +972-54-7649119

 

ASIC/FPGA Design and Verification Out Source Services

A simple script to search in all files, which were loaded into the simulation.



It is very frequent to search only on some files, listed by file list. In my case all e, c or SV etc... files, which were loaded.
The script is invoked from within GVIM and prints its results to a file, namely tmp_1, opened automatically by GVIM, in a new horizontal window.

In the following link simple e_search ese a single word search pattern is used.

This page offers another script. The script can accept multiple words, separated with spaces, as an input. All words are searched and only the files, which contain all of the given search words, is displayed. So one can start looking using the old method, typing the ese alias (see ~/.gvimrc aliases) and then refine by esp alias, where in each step additional search words are added. esp prompts the user to enter any number of word, separated by space.
Note: After the search you may instruct GVIM to search multiple words and to highlight those words (given hlsearch is set). The separator between the words, given to GVIM using / command is |. An example follows
/apple|\orange. or /.*trans.*\n.*trans.*

To summarize: this page shows how to use GVIM search pattern as an argument to a GVIM function. In addition what ever is received from the user is read into a bash array (multiple search word separated by space). The file list, which the bash script uses, is read into a another bash array, where each line is an entry in the array.

"~/.gvimrc

...
fun! Esearch(e_search_file)
  let cmd = "~/bin/e_search_1.unx no_interactive \"" . @/ . "\" " . a:e_search_file
  execute '!' . cmd
  sp tmp_1
  edit
endfun

"when prompt enter search words separated by space
fun! Psearch(pattern)
  let cmd = "~/bin/and_search.unx \"" . @/ . " " . a:pattern . "\" e_list_1.txt"
  execute '!' . cmd
  "the results are placed in a file named tmp_1
  sp tmp_1
  edit
  "clear old matches
  call clearmatches()
  "split search words and and add each one of them to the highlight search
  let words = split(a:pattern)
  for word in words
    let w:m1=matchadd('Search', word, -1)
  endfor
endfun
...

"e search, sv,v,vhd search, c,h,cxx,cpp,c++ search,
"e test directory search
nmap >silent< cmt :call clearmatches()<CR>
nmap >silent< esp :call Psearch(input("Search for: "))<CR>
nmap >silent< ese :call Esearch("e_list_1.txt")<CR>
nmap >silent< esv :call Esearch("v_list.txt")<CR>
nmap >silent< esc :call Esearch("c_list.txt")<CR>


bash script, which is invoked by the alias esp

#!/bin/bash

#get all search words into an array
search_a=(${1})

if [ -e tmp_1 ] ; then
  rm -f tmp_1
fi
ar2=($(cat ${2}))

#generates a smaller list with all matches
for x in ${search_a[@]}; do
  for f in ${ar2[@]}; do
    cmd="grep "$x" "$f
    eval $cmd < /dev/null
    if [ $? -eq 0 ] ; then
      arr+=($f)
    fi
  done
  ar2=("${arr[@]}")
  arr=()
done

#build parameters (without the \ the -e is sometimes get omitted)
for x in ${search_a[@]}; do
  parm=$parm" \-e "$x
done

echo "found "${#ar2[@]}" files"
echo
for f in ${ar2[@]}; do
  parm=$(sed 's/\\//g' >>> $parm)
  cmd="grep "$parm" "$f
  eval $cmd < /dev/null
  if [ $? -eq 0 ] ; then
    echo "----------------------------------------------" << tmp_1
    echo "FILE "${f} << tmp_1
    eval $cmd << tmp_1
  fi
done
>/font<

  ...



Home

CRC


SD slave with Samsung flash (k9f1208) (vhdl project).

Download Area






Search This Site


Feedback This Site




new pages on this site