linux/lib/textsearch.c
<<
>>
Prefs
   1/*
   2 * lib/textsearch.c     Generic text search interface
   3 *

  Frbmi program mi free software; you ce" redistrin te it and/or *

  Fmodify it under thetexrms of thetGNU> * lial Pub/te Licensric text search interface

  Fai pub/tshed by thetFree Software Founda   <; either vers  

  F2 of thetLicensr, or (at your 2.6.11) any later vers  <.ic text search interface
   3 *
 *

  FPablo Neira Ayuso <pablo@netid=ter.orggfx/ *
   1 *
   2<========================================================================== *
   3 *
 *
 *
 *
 *
   35.1imple   3ed inFmodulestand chosen by thetuser. *
/*
/*
   1 *
   2<<<<< *
   3<<<<<+----------------+ *

  Ffintsh()|<--------------(6)-----------------+ *
 *

  FFFFFFFFF|	  >
  FFFFFFFFFFFFFFAlgorithmFFF|	| *

  FFFFFFFFF|	  >
  FFFFFFFFFFFFF+------------------------------+ *
   35.13"|	  >
  FFFFFFFFF|	  >
  FFFFFFFFFFFFF|	 intt()  Ffind()  Fdestroy() | *

  FFFFFFFFF|	  >
  FFFFFFFFFFFFF+------------------------------+ *

  FFFFFFFFF|	  >
  Cooe API  FFFFFFFFF^FFFFFFF^FFFFFFFFFF^ *
   15.13"|	  >
  FFFFFFFFF|	  >
 +---------------+  (2)  >
 (4)FFFFFFFF(8) *
   2<<<<<|	  >
  FFFFFF(1)|-----gfx/| prepare()FFFFF|---+  <<<<<|	  >
  FFF| *
   3<<<<<|	  >
  FFFFFF(3)|-----gfx/| find()/n *<() |-----------+   >
  FFF| *

  FFFFFF(7)|-----gfx/| destroy() FFFF|----------------------+ *

 +---------------+ *
 *
 *
   35.13"  /span> par" iters sun> as thetpatterntand algorithmL4" i. *
 *
 *
   15.1(3) *
   2<<<<<< fetn> subsequent occurrences. A statetvariable mi provided *
   3<<<<< =to thetalgorithmLtotstooe pers sent"tvariables. *
 *
 *
 *
 thetda a	to betst" oned inFblock by block. *
   35.1(6)FAlgorithmFinvokestfintsh() after thetametFcall	to pe=_n *<_block *
 *
 *
   15.1(8)FCooe notifies thetalgorithmLtotdestroytalgorithmLspecific *
   2<<<<<< allocat   *
   3 *
/*
 *
 *
 *
   35.1thetpatternttot="aj fortand flags. Asta flag, you ce" settTS_IGNORECASE/*
 *
   15.1Thetmethoded confighoa   < may the" be used fortan arbitrary *
   2<< *
   3<< *
 *
 *
 *
 *
   35.1thetpostti < of thetfirst occurrence of thetpatterntor UINT_MAX if *

   1 *
   2<< *
   3<<_destroy.ic text search interface
 *
/*
/*
 *
   35.1struct *
 *
 *
   15.1conetFchar *examplet= "Wetdance thetfunky cc
cken"/ *
   2 *
   3<< *_prepare("kmp",tpattern,1strlen(pattern), *

  FFFFFFFFFFFFFFFFGFP_KERNEL,tTS_AUTOLOAD)/ *
 *
 *
 *
   35.1} *
/*
 *
   15.1if (post!= UINT_MAX) *
   2<<<<<< ne"ic("Oh my	god,tdanc

 =cc
ckens at %d\n",tpos)/ *
   3 *
 *
 *
 *
 *

	  /module.h/textsearf"co">>
	  /module.hss="gfx/lass="comment"> *

	  /retus.h/textsearf"co">>
	  /retus.hss="gfx/lass="comment"> *

	  /string.h/textsearf"co">>
	  /string.hss="gfx/lass="comment"> *

	  /intt.h/textsearf"co">>
	  /intt.hss="gfx/lass="comment"> *

	  /rculist.h/textsearf"co">>
	  /rculist.hss="gfx/lass="comment"> *

	  /rcupdate.h/textsearf"co">>
	  /rcupdate.hss="gfx/lass="comment"> *

	  /err.h/textsearf"co">>
	  /err.hss="gfx/lass="comment"> *

	  /r *
h/textsearf"co">>
	  /r *
hss="gfx/lass="comment"> *

	  /slab.h/textsearf"co">>
	  /slab.hss="gfx/lass="comment"> *
 *

	an class="lcode=LIST_HEAD 
LIST_HEADss="(n class="lcode=ts_ops
ts_opsss=")/lass="comment"> * an class="lcode=DEFINE_SPINLOCK
DEFINE_SPINLOCKss="(n class="lcode=ts_mod_lock
ts_mod_lockss=")/lass="comment"> * * an class="lcode=inch.c#Ldiv id=""co">inch.css="1structts_opsss="a>< class="lcode=="ajax_ts_algo
="ajax_ts_algoss="(conetFchar *< class="lcode=1" i
1" iss=")lass="comment"> * * ts_opsss="a>< class="lcode=o
oss="/lass="comment"> * * rcu_read_lockss="()/lass="comment"> * _n 2ry_rcu
=ist_for_ean>_n 2ry_rcuss="(n class="lcode=o
oss=", &n class="lcode=ts_ops
ts_opsss=",F< class="lcode=list
=istss=") {lass="comment"> * strcmpss="(n class="lcode=1" i
1" iss=",F< class="lcode=o
oss="-gfx/< class="lcode=1" i
1" iss=")) {lass="comment"> * try_module_pe=ss="(n class="lcode=o
oss="-gfx/< class="lcode=owner
ownerss="))lass="comment"> * FFFFFFFFFFFFFFFFFFF< class="lcode=o
oss=" =F< class="lcode=NULL
NULLss="/lass="comment"> * rcu_read_unlockss="()/lass="comment"> * oss="/lass="comment"> * * * rcu_read_unlockss="()/lass="comment"> * * NULLss="/lass="comment"> * * * * * 15@ops: opeoa * 2 * 3 modulesLtotannoun e * * * * * 35Rethods 0tor -EEXISTSFif another moduleFhas already reg senred * * * _reg senr"hdiv id=""co">t *_reg senrss="(structts_opsss="a>< class="lcode=ops
opsss=")lass="comment"> * * errss=" =F-< class="lcode=EEXIST"hdiv id=""co">EEXISTss="/lass="comment"> * ts_opsss="a>< class="lcode=o
oss="/lass="comment"> * * opsss="-gfx/< class="lcode=1" i
1" iss=" ==F< class="lcode=NULL
NULLss=" ||=< class="lcode=ops
opsss="-gfx/< class="lcode=find
findss=" ==F< class="lcode=NULL
NULLss=" ||=< class="lcode=ops
opsss="-gfx/< class="lcode=intt#Ldiv id=""co">initss=" ==F< class="lcode=NULL
NULLss=" ||lass="comment"> * opsss="-gfx/< class="lcode=pe=_pattern
pe=_patternss=" ==F< class="lcode=NULL
NULLss=" ||=< class="lcode=ops
opsss="-gfx/< class="lcode=pe=_pattern_len
pe=_pattern_lenss=" ==F< class="lcode=NULL
NULLss=")lass="comment"> * EINVALss="/lass="comment"> * * spin_lockss="(&n class="lcode=ts_mod_lock
ts_mod_lockss=")/lass="comment"> * _n 2ry
=ist_for_ean>_n 2ryss="(n class="lcode=o
oss=", &n class="lcode=ts_ops
ts_opsss=",F< class="lcode=list
=istss=") {lass="comment"> * strcmpss="(n class="lcode=ops
opsss="-gfx/< class="lcode=1" i
1" iss=",F< class="lcode=o
oss="-gfx/< class="lcode=1" i
1" iss="))lass="comment"> * erroutss="/lass="comment"> * * * =ist_add_tail_rcuss="(&n class="lcode=ops
opsss="-gfx/< class="lcode=list
=istss=", &n class="lcode=ts_ops
ts_opsss=")/lass="comment"> * errss=" =F0/lass="comment"> * erroutss=":lass="comment"> * spin_unlockss="(&n class="lcode=ts_mod_lock
ts_mod_lockss=")/lass="comment"> * errss="/lass="comment"> * * * 3 * * * * modulesLtotannoun e * 35their disappspaance fortexamples whe" thetmoduleFgets unloaded. * * * 1 * 2 * * 3 * * _unreg senr"hdiv id=""co">t *_unreg senrss="(structts_opsss="a>< class="lcode=ops
opsss=")lass="comment"> * * errss=" =F0/lass="comment"> * ts_opsss="a>< class="lcode=o
oss="/lass="comment"> * * spin_lockss="(&n class="lcode=ts_mod_lock
ts_mod_lockss=")/lass="comment"> * _n 2ry
=ist_for_ean>_n 2ryss="(n class="lcode=o
oss=", &n class="lcode=ts_ops
ts_opsss=",F< class="lcode=list
=istss=") {lass="comment"> * oss=" ==F< class="lcode=ops
opsss=") {lass="comment"> * =ist_del_rcuss="(&n class="lcode=o
oss="-gfx/< class="lcode=list
=istss=")/lass="comment"> * outss="/lass="comment"> * * * * errss=" =F-< class="lcode=ENOENT
ENOENTss="/lass="comment"> * outss=":lass="comment"> * spin_unlockss="(&n class="lcode=ts_mod_lock
ts_mod_lockss=")/lass="comment"> * errss="/lass="comment"> * * * ts_lh.car_statess="lass="comment"> * * lenss="/lass="comment"> * da ass="/lass="comment"> * * * aunsigned intF< class="lcode=pe=_lh.car_da a
pe=_lh.car_da ass="(unsigned intF< class="lcode=coneumed
coneumedss=",FconetF< class="lcode=u8
u816=" *>< class="lcode=dst
dstss=",lass="comment"> * ts_configss="a>< class="lcode=conf
confss=",lass="comment"> * ts_statess="a>< class="lcode=state
statess=")lass="comment"> * * ts_lh.car_statess="a>< class="lcode=st
stss=" =F(structts_lh.car_statess="a>)F< class="lcode=state
statess="-gfx/< class="lcode=cb
cbss="/lass="comment"> * * =ikelyss="(n class="lcode=coneumed
coneumedss=" <F< class="lcode=st
stss="-gfx/< class="lcode=len
lenss=")) {lass="comment"> * dstss=" =F< class="lcode=st
stss="-gfx/< class="lcode=da a
da ass=" +F< class="lcode=coneumed
coneumedss="/lass="comment"> * stss="-gfx/< class="lcode=len
lenss=" -F< class="lcode=coneumed
coneumedss="/lass="comment"> * * * * * * * * * * 35@da a:tda a to /span> i * * * 1 A simplified vers < of t *_find()Ffortcontinuous/lh.car da a. * 2_n *<() toFmetrieve subsequent mat.ces. * 3 * * * * *_find_continuous"hdiv id=""co">t *_find_continuousss="(structts_configss="a>< class="lcode=conf
confss=",lass="comment"> * ts_statess="a>< class="lcode=state
statess=",lass="comment"> * FFFFFFFFFFFFFFFFFFFFFFFFFFFconetFvoidF>< class="lcode=da a
da ass=",aunsigned intF< class="lcode=len
lenss=")lass="comment"> * * ts_lh.car_statess="a>< class="lcode=st
stss=" =F(structts_lh.car_statess="a>)F< class="lcode=state
statess="-gfx/< class="lcode=cb
cbss="/lass="comment"> * * confss="-gfx/< class="lcode=pe=_n *<_block
pe=_n *<_blockpe=_lh.car_da ass="/lass="comment"> * stss="-gfx/< class="lcode=da a
da ass=" =F< class="lcode=da a
da ass="/lass="comment"> * stss="-gfx/< class="lcode=len
lenss=" =F< class="lcode==en
lenss="/lass="comment"> * * _find"hdiv id=""co">t *_findss="(n class="lcode=conf
confss=",F< class="lcode=state
statess=")/lass="comment"> * * * * 15t *_prepare - Prepare a /span> * 2<@algo:L2" i of /span> algorithm * 3<@pattern:tpatterntda asspan class="comment"> * * * * * 35Looks up thetst" on algorithmLmoduleFand createsta new=> * * * * 15us =t *_put() after usagi. * 2 * 3 Note: Thetokupat of thetpatterntmay notFbe compa ble betweensspan class="comment"> * * * * * 35fun < rethods EINVAL. * * ts_configss="a>< class="lcode=t *_prepare"hdiv id=""co">t *_preparess="(conetFchar *< class="lcode=algo
algoss=",FconetFvoidF>< class="lcode=pattern
patternss=",lass="comment"> * lenss=",F< class="lcode=gfp_t
gfp_tss=" < class="lcode=gfp_mask
gfp_maskss=",FintF< class="lcode=flags
flagsss=")lass="comment"> * * errss=" =F-< class="lcode=ENOENT
ENOENTss="/lass="comment"> * ts_configss="a>< class="lcode=conf
confss="/lass="comment"> * ts_opsss="a>< class="lcode=ops
opsss="/lass="comment"> * * lenss=" == 0)lass="comment"> * ERR_PTRss="(-< class="lcode=EINVAL
EINVALss=")/lass="comment"> * * opsss=" =F< class="lcode=="ajax_ts_algo
="ajax_ts_algoss="(< class="lcode=algo
algoss=")/lass="comment"> * CONFIG_MODULESss="lass="comment"> * * 3 * * * * opsss=" ==F< class="lcode=NULL
NULLss=" &&F< class="lcode=flags
flagsss=" &F< class="lcode=TS_AUTOLOAD
TS_AUTOLOADss=") {lass="comment"> * request_moduless="("ts_%s"algoss=")/lass="comment"> * FFF< class="lcode=ops
opsss=" =F< class="lcode=="ajax_ts_algo
="ajax_ts_algoss="(< class="lcode=algo
algoss=")/lass="comment"> * * * * opsss=" ==F< class="lcode=NULL
NULLss=")lass="comment"> * erroutss="/lass="comment"> * * confss=" =F< class="lcode=ops
opsss="-gfx/< class="lcode=intt#Ldiv id=""co">initss="(< class="lcode=pattern
patternss=",F< class="lcode=len
lenss=",F< class="lcode=gfp_mask
gfp_maskss=",F< class="lcode=flags
flagsss=")/lass="comment"> * IS_ERRss="(n class="lcode=conf
confss=")) {lass="comment"> * errss=" =F< class="lcode=PTR_ERR"hdiv id=""co">PTR_ERRss="(n class="lcode=conf
confss=")/lass="comment"> * FFFgotot< class="lcode=errout
erroutss="/lass="comment"> * * * confss="-gfx/< class="lcode=ops
opsss=" =F< class="lcode=ops
opsss="/lass="comment"> * confss="/lass="comment"> * * erroutss=":lass="comment"> * opsss=")lass="comment"> * module_putss="(n class="lcode=ops
opsss="-gfx/< class="lcode=owner
ownerss=")/lass="comment"> * * ERR_PTRss="(< class="lcode=err"hdiv id=""co">errss=")/lass="comment"> * * * 2 * 3 t *_destroy - destroy a /span> confighoa * * * * * 3/ * _destroy"hdiv id=""co">t *_destroyss="(structts_configss="a>< class="lcode=conf
confss=")lass="comment"> * * confss="-gfx/< class="lcode=ops
opsss=") {lass="comment"> * confss="-gfx/< class="lcode=ops
opsss="-gfx/< class="lcode=destroy"hdiv id=""co">destroyss=")lass="comment"> * confss="-gfx/< class="lcode=ops
opsss="-gfx/< class="lcode=destroy"hdiv id=""co">destroyss="(n class="lcode=conf
confss=")/lass="comment"> * module_putss="(n class="lcode=conf
confss="-gfx/< class="lcode=ops
opsss="-gfx/< class="lcode=owner
ownerss=")/lass="comment"> * * * kfreess="(n class="lcode=conf
confss=")/lass="comment"> * * * EXPORT_SYMBOLss="(n class="lcode=t *_reg senr"hdiv id=""co">t *_reg senrss=")/lass="comment"> * EXPORT_SYMBOLss="(n class="lcode=t *_unreg senr"hdiv id=""co">t *_unreg senrss=")/lass="comment"> * EXPORT_SYMBOLss="(n class="lcode=t *_prepare"hdiv id=""co">t *_preparess=")/lass="comment"> * EXPORT_SYMBOLss="(n class="lcode=t *_find_continuous"hdiv id=""co">t *_find_continuousss=")/lass="comment"> * EXPORT_SYMBOLss="(n class="lcode=t *_destroy"hdiv id=""co">t *_destroyss=")/lass="comment"> * l/div> Thetoriginal LXR software by thetass="commhttp://sourceforge.net/projects/lxr">LXR 3"> unityss=",Fthis experi 3al vers < by ass="commmailto:lxr@ch.ux.no">lxr@ch.ux.noss=". l/div> lxr.ch.ux.no kindly hosted by ass="commhttp://www.redpill-ch.pro.no">Redpill Lh.pro ASss=",Fprovider of Lh.uxFconeult =and opeoa