Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to port GNU grep as a library? [closed]

Tags:

c

grep

gnu

I would like to know if it is possible to port GNU grep as a libary, leaving aside the legal complications, if any, as this is purely for non-commercial, but academic use. I have seen many ports exist of GNU grep. For example : GNU grep for win 32 here.

I wonder why nobody has ever attempted to port grep as a library ? It would be a huge benefit to applications that exploit string searching/mining as they can use the power of GNU grep internally in the their applications. I would like to attempt this feat, but since I am new to string searching/mining, would love to know the obvious challenges that may arise and why it has not been done as yet.

EDIT - The advantage of a GNU grep library is that it will do string searching much faster, using its own modified version of boyer-moore. Where as when using a regular expression wrapper library such as PCRE or Boost reg exp or Qt Reg expressions etc, the application has to read the file line-by-line and parse each line against the regexp. This is the obvious advantage that I see.

like image 755
OverTheEdge Avatar asked Sep 04 '13 05:09

OverTheEdge


1 Answers

Yes. Just link it as a library and call its main() with its intended arguments. Or better if you rename its main() to some better, f.e. to grep().

like image 64
peterh Avatar answered Oct 15 '22 03:10

peterh