This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 'cygcheck -f' pattern syntax.


22.09.2011 15:43, Marco atzeri ÐÐÑÐÑ:
On 9/22/2011 2:10 PM, Oleksandr Gavenko wrote:
So 'cygcheck -f' does not allow 'glob' and 'regex'.

I write simple script that allow use regex:

#!/bin/sh

regex=$(echo "$1" | sed -e 's|\\|&&|g' -e 's|=|\\=|g')

for file in /etc/setup/*.lst.gz; do
name=${file#/etc/setup/}
name=${name%.lst.gz}
gzip -d -c $file | sed -n "\=$regex={s=^=$name: /=;p;}"
done

But this script is extremely slow:

$ time ./cygsearch.sh 'bin/emacs'
emacs: /usr/bin/emacs-nox.exe
emacs: /usr/bin/emacs.ico
emacs: /usr/bin/emacsclient.exe
emacs-X11: /usr/bin/emacs-X11.exe

real 0m38.797s
user 0m44.620s
sys 0m25.574s


much faster


$ time cp /etc/setup/*.gz .

real 0m1.450s
user 0m0.061s
sys 0m1.202s

$ time gunzip *.gz

real 0m1.937s
user 0m0.170s
sys 0m1.764s

$ time grep -H "stdio.h" *.lst
cygwin.lst:usr/include/stdio.h
cygwin.lst:usr/include/sys/stdio.h

real 0m0.816s
user 0m0.046s
sys 0m0.781s

I try eliminate sed call by using internal bash capabilities but
unsuccessfully:

  for file in /etc/setup/*.lst.gz; do
    name=${file#/etc/setup/}
    name=${name%.lst.gz}
    gzip -d -c $file | while read line; do
      if [[ /"$line" =~ $regex ]]; then
        echo $name: "$line"
      fi
    done
  done

  $ time ./cygsearch 'bin/emacs'
time ./cygsearch 'bin/emacs'
emacs: usr/bin/emacs-nox.exe
emacs: usr/bin/emacs.ico

real	0m57.955s
user	0m42.105s
sys	0m34.710s


Next I try eliminate spawning any process at all with success:


#!/usr/bin/python

  import sys
  import glob
  import re
  import gzip

  r = re.compile(sys.argv[1])
  n = re.compile(r'/etc/setup/(.*)\.lst\.gz')

  for f in glob.glob(r'/etc/setup/*.lst.gz'):
      name = n.match(f).group(1)
      plain = gzip.open(f, "rb")
      for line in plain:
          line = line.rstrip('\n\r')
          if r.search(line) != None:
              print '%s: %s' % (name, line)
      plain.close()

  $ time ./cygsearch.py 'bin/emacs'
emacs-X11: usr/bin/emacs-X11.exe
emacs: usr/bin/emacs-nox.exe

real	0m3.152s
user	0m2.421s
sys	0m0.171s


-- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]