pcre_exec.c 147 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940
  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* PCRE is a library of functions to support regular expressions whose syntax
  5. and semantics are as close as possible to those of the Perl 5 language.
  6. Written by Philip Hazel
  7. Copyright (c) 1997-2008 University of Cambridge
  8. -----------------------------------------------------------------------------
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. * Neither the name of the University of Cambridge nor the names of its
  17. contributors may be used to endorse or promote products derived from
  18. this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. POSSIBILITY OF SUCH DAMAGE.
  30. -----------------------------------------------------------------------------
  31. */
  32. /* This module contains pcre_exec(), the externally visible function that does
  33. pattern matching using an NFA algorithm, trying to mimic Perl as closely as
  34. possible. There are also some static supporting functions. */
  35. #ifdef HAVE_CONFIG_H
  36. #include "config.h"
  37. #endif
  38. #define NLBLOCK md /* Block containing newline information */
  39. #define PSSTART start_subject /* Field containing processed string start */
  40. #define PSEND end_subject /* Field containing processed string end */
  41. #include "pcre_internal.h"
  42. /* Undefine some potentially clashing cpp symbols */
  43. #undef min
  44. #undef max
  45. /* Flag bits for the match() function */
  46. #define match_condassert 0x01 /* Called to check a condition assertion */
  47. #define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */
  48. /* Non-error returns from the match() function. Error returns are externally
  49. defined PCRE_ERROR_xxx codes, which are all negative. */
  50. #define MATCH_MATCH 1
  51. #define MATCH_NOMATCH 0
  52. /* Special internal returns from the match() function. Make them sufficiently
  53. negative to avoid the external error codes. */
  54. #define MATCH_COMMIT (-999)
  55. #define MATCH_PRUNE (-998)
  56. #define MATCH_SKIP (-997)
  57. #define MATCH_THEN (-996)
  58. /* Maximum number of ints of offset to save on the stack for recursive calls.
  59. If the offset vector is bigger, malloc is used. This should be a multiple of 3,
  60. because the offset vector is always a multiple of 3 long. */
  61. #define REC_STACK_SAVE_MAX 30
  62. /* Min and max values for the common repeats; for the maxima, 0 => infinity */
  63. static const char rep_min[] = { 0, 0, 1, 1, 0, 0 };
  64. static const char rep_max[] = { 0, 0, 0, 0, 1, 1 };
  65. #ifdef DEBUG
  66. /*************************************************
  67. * Debugging function to print chars *
  68. *************************************************/
  69. /* Print a sequence of chars in printable format, stopping at the end of the
  70. subject if the requested.
  71. Arguments:
  72. p points to characters
  73. length number to print
  74. is_subject TRUE if printing from within md->start_subject
  75. md pointer to matching data block, if is_subject is TRUE
  76. Returns: nothing
  77. */
  78. static void
  79. pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
  80. {
  81. unsigned int c;
  82. if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
  83. while (length-- > 0)
  84. if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
  85. }
  86. #endif
  87. /*************************************************
  88. * Match a back-reference *
  89. *************************************************/
  90. /* If a back reference hasn't been set, the length that is passed is greater
  91. than the number of characters left in the string, so the match fails.
  92. Arguments:
  93. offset index into the offset vector
  94. eptr points into the subject
  95. length length to be matched
  96. md points to match data block
  97. ims the ims flags
  98. Returns: TRUE if matched
  99. */
  100. static BOOL
  101. match_ref(int offset, register USPTR eptr, int length, match_data *md,
  102. unsigned long int ims)
  103. {
  104. USPTR p = md->start_subject + md->offset_vector[offset];
  105. #ifdef DEBUG
  106. if (eptr >= md->end_subject)
  107. printf("matching subject <null>");
  108. else
  109. {
  110. printf("matching subject ");
  111. pchars(eptr, length, TRUE, md);
  112. }
  113. printf(" against backref ");
  114. pchars(p, length, FALSE, md);
  115. printf("\n");
  116. #endif
  117. /* Always fail if not enough characters left */
  118. if (length > md->end_subject - eptr) return FALSE;
  119. /* Separate the caselesss case for speed */
  120. if ((ims & PCRE_CASELESS) != 0)
  121. {
  122. while (length-- > 0)
  123. if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;
  124. }
  125. else
  126. { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
  127. return TRUE;
  128. }
  129. /***************************************************************************
  130. ****************************************************************************
  131. RECURSION IN THE match() FUNCTION
  132. The match() function is highly recursive, though not every recursive call
  133. increases the recursive depth. Nevertheless, some regular expressions can cause
  134. it to recurse to a great depth. I was writing for Unix, so I just let it call
  135. itself recursively. This uses the stack for saving everything that has to be
  136. saved for a recursive call. On Unix, the stack can be large, and this works
  137. fine.
  138. It turns out that on some non-Unix-like systems there are problems with
  139. programs that use a lot of stack. (This despite the fact that every last chip
  140. has oodles of memory these days, and techniques for extending the stack have
  141. been known for decades.) So....
  142. There is a fudge, triggered by defining NO_RECURSE, which avoids recursive
  143. calls by keeping local variables that need to be preserved in blocks of memory
  144. obtained from malloc() instead instead of on the stack. Macros are used to
  145. achieve this so that the actual code doesn't look very different to what it
  146. always used to.
  147. The original heap-recursive code used longjmp(). However, it seems that this
  148. can be very slow on some operating systems. Following a suggestion from Stan
  149. Switzer, the use of longjmp() has been abolished, at the cost of having to
  150. provide a unique number for each call to RMATCH. There is no way of generating
  151. a sequence of numbers at compile time in C. I have given them names, to make
  152. them stand out more clearly.
  153. Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
  154. FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
  155. tests. Furthermore, not using longjmp() means that local dynamic variables
  156. don't have indeterminate values; this has meant that the frame size can be
  157. reduced because the result can be "passed back" by straight setting of the
  158. variable instead of being passed in the frame.
  159. ****************************************************************************
  160. ***************************************************************************/
  161. /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
  162. below must be updated in sync. */
  163. enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10,
  164. RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
  165. RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
  166. RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
  167. RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
  168. RM51, RM52, RM53, RM54 };
  169. /* These versions of the macros use the stack, as normal. There are debugging
  170. versions and production versions. Note that the "rw" argument of RMATCH isn't
  171. actuall used in this definition. */
  172. #ifndef NO_RECURSE
  173. #define REGISTER register
  174. #ifdef DEBUG
  175. #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
  176. { \
  177. printf("match() called in line %d\n", __LINE__); \
  178. rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
  179. printf("to line %d\n", __LINE__); \
  180. }
  181. #define RRETURN(ra) \
  182. { \
  183. printf("match() returned %d from line %d ", ra, __LINE__); \
  184. return ra; \
  185. }
  186. #else
  187. #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
  188. rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
  189. #define RRETURN(ra) return ra
  190. #endif
  191. #else
  192. /* These versions of the macros manage a private stack on the heap. Note that
  193. the "rd" argument of RMATCH isn't actually used in this definition. It's the md
  194. argument of match(), which never changes. */
  195. #define REGISTER
  196. #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
  197. {\
  198. heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
  199. frame->Xwhere = rw; \
  200. newframe->Xeptr = ra;\
  201. newframe->Xecode = rb;\
  202. newframe->Xmstart = mstart;\
  203. newframe->Xoffset_top = rc;\
  204. newframe->Xims = re;\
  205. newframe->Xeptrb = rf;\
  206. newframe->Xflags = rg;\
  207. newframe->Xrdepth = frame->Xrdepth + 1;\
  208. newframe->Xprevframe = frame;\
  209. frame = newframe;\
  210. DPRINTF(("restarting from line %d\n", __LINE__));\
  211. goto HEAP_RECURSE;\
  212. L_##rw:\
  213. DPRINTF(("jumped back to line %d\n", __LINE__));\
  214. }
  215. #define RRETURN(ra)\
  216. {\
  217. heapframe *newframe = frame;\
  218. frame = newframe->Xprevframe;\
  219. (pcre_stack_free)(newframe);\
  220. if (frame != NULL)\
  221. {\
  222. rrc = ra;\
  223. goto HEAP_RETURN;\
  224. }\
  225. return ra;\
  226. }
  227. /* Structure for remembering the local variables in a private frame */
  228. typedef struct heapframe {
  229. struct heapframe *Xprevframe;
  230. /* Function arguments that may change */
  231. const uschar *Xeptr;
  232. const uschar *Xecode;
  233. const uschar *Xmstart;
  234. int Xoffset_top;
  235. long int Xims;
  236. eptrblock *Xeptrb;
  237. int Xflags;
  238. unsigned int Xrdepth;
  239. /* Function local variables */
  240. const uschar *Xcallpat;
  241. const uschar *Xcharptr;
  242. const uschar *Xdata;
  243. const uschar *Xnext;
  244. const uschar *Xpp;
  245. const uschar *Xprev;
  246. const uschar *Xsaved_eptr;
  247. recursion_info Xnew_recursive;
  248. BOOL Xcur_is_word;
  249. BOOL Xcondition;
  250. BOOL Xprev_is_word;
  251. unsigned long int Xoriginal_ims;
  252. #ifdef SUPPORT_UCP
  253. int Xprop_type;
  254. int Xprop_value;
  255. int Xprop_fail_result;
  256. int Xprop_category;
  257. int Xprop_chartype;
  258. int Xprop_script;
  259. int Xoclength;
  260. uschar Xocchars[8];
  261. #endif
  262. int Xctype;
  263. unsigned int Xfc;
  264. int Xfi;
  265. int Xlength;
  266. int Xmax;
  267. int Xmin;
  268. int Xnumber;
  269. int Xoffset;
  270. int Xop;
  271. int Xsave_capture_last;
  272. int Xsave_offset1, Xsave_offset2, Xsave_offset3;
  273. int Xstacksave[REC_STACK_SAVE_MAX];
  274. eptrblock Xnewptrb;
  275. /* Where to jump back to */
  276. int Xwhere;
  277. } heapframe;
  278. #endif
  279. /***************************************************************************
  280. ***************************************************************************/
  281. /*************************************************
  282. * Match from current position *
  283. *************************************************/
  284. /* This function is called recursively in many circumstances. Whenever it
  285. returns a negative (error) response, the outer incarnation must also return the
  286. same response.
  287. Performance note: It might be tempting to extract commonly used fields from the
  288. md structure (e.g. utf8, end_subject) into individual variables to improve
  289. performance. Tests using gcc on a SPARC disproved this; in the first case, it
  290. made performance worse.
  291. Arguments:
  292. eptr pointer to current character in subject
  293. ecode pointer to current position in compiled code
  294. mstart pointer to the current match start position (can be modified
  295. by encountering \K)
  296. offset_top current top pointer
  297. md pointer to "static" info for the match
  298. ims current /i, /m, and /s options
  299. eptrb pointer to chain of blocks containing eptr at start of
  300. brackets - for testing for empty matches
  301. flags can contain
  302. match_condassert - this is an assertion condition
  303. match_cbegroup - this is the start of an unlimited repeat
  304. group that can match an empty string
  305. rdepth the recursion depth
  306. Returns: MATCH_MATCH if matched ) these values are >= 0
  307. MATCH_NOMATCH if failed to match )
  308. a negative PCRE_ERROR_xxx value if aborted by an error condition
  309. (e.g. stopped by repeated call or recursion limit)
  310. */
  311. static int
  312. match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,
  313. int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
  314. int flags, unsigned int rdepth)
  315. {
  316. /* These variables do not need to be preserved over recursion in this function,
  317. so they can be ordinary variables in all cases. Mark some of them with
  318. "register" because they are used a lot in loops. */
  319. register int rrc; /* Returns from recursive calls */
  320. register int i; /* Used for loops not involving calls to RMATCH() */
  321. register unsigned int c; /* Character values not kept over RMATCH() calls */
  322. register BOOL utf8; /* Local copy of UTF-8 flag for speed */
  323. BOOL minimize, possessive; /* Quantifier options */
  324. /* When recursion is not being used, all "local" variables that have to be
  325. preserved over calls to RMATCH() are part of a "frame" which is obtained from
  326. heap storage. Set up the top-level frame here; others are obtained from the
  327. heap whenever RMATCH() does a "recursion". See the macro definitions above. */
  328. #ifdef NO_RECURSE
  329. heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));
  330. frame->Xprevframe = NULL; /* Marks the top level */
  331. /* Copy in the original argument variables */
  332. frame->Xeptr = eptr;
  333. frame->Xecode = ecode;
  334. frame->Xmstart = mstart;
  335. frame->Xoffset_top = offset_top;
  336. frame->Xims = ims;
  337. frame->Xeptrb = eptrb;
  338. frame->Xflags = flags;
  339. frame->Xrdepth = rdepth;
  340. /* This is where control jumps back to to effect "recursion" */
  341. HEAP_RECURSE:
  342. /* Macros make the argument variables come from the current frame */
  343. #define eptr frame->Xeptr
  344. #define ecode frame->Xecode
  345. #define mstart frame->Xmstart
  346. #define offset_top frame->Xoffset_top
  347. #define ims frame->Xims
  348. #define eptrb frame->Xeptrb
  349. #define flags frame->Xflags
  350. #define rdepth frame->Xrdepth
  351. /* Ditto for the local variables */
  352. #ifdef SUPPORT_UTF8
  353. #define charptr frame->Xcharptr
  354. #endif
  355. #define callpat frame->Xcallpat
  356. #define data frame->Xdata
  357. #define next frame->Xnext
  358. #define pp frame->Xpp
  359. #define prev frame->Xprev
  360. #define saved_eptr frame->Xsaved_eptr
  361. #define new_recursive frame->Xnew_recursive
  362. #define cur_is_word frame->Xcur_is_word
  363. #define condition frame->Xcondition
  364. #define prev_is_word frame->Xprev_is_word
  365. #define original_ims frame->Xoriginal_ims
  366. #ifdef SUPPORT_UCP
  367. #define prop_type frame->Xprop_type
  368. #define prop_value frame->Xprop_value
  369. #define prop_fail_result frame->Xprop_fail_result
  370. #define prop_category frame->Xprop_category
  371. #define prop_chartype frame->Xprop_chartype
  372. #define prop_script frame->Xprop_script
  373. #define oclength frame->Xoclength
  374. #define occhars frame->Xocchars
  375. #endif
  376. #define ctype frame->Xctype
  377. #define fc frame->Xfc
  378. #define fi frame->Xfi
  379. #define length frame->Xlength
  380. #define max frame->Xmax
  381. #define min frame->Xmin
  382. #define number frame->Xnumber
  383. #define offset frame->Xoffset
  384. #define op frame->Xop
  385. #define save_capture_last frame->Xsave_capture_last
  386. #define save_offset1 frame->Xsave_offset1
  387. #define save_offset2 frame->Xsave_offset2
  388. #define save_offset3 frame->Xsave_offset3
  389. #define stacksave frame->Xstacksave
  390. #define newptrb frame->Xnewptrb
  391. /* When recursion is being used, local variables are allocated on the stack and
  392. get preserved during recursion in the normal way. In this environment, fi and
  393. i, and fc and c, can be the same variables. */
  394. #else /* NO_RECURSE not defined */
  395. #define fi i
  396. #define fc c
  397. #ifdef SUPPORT_UTF8 /* Many of these variables are used only */
  398. const uschar *charptr; /* in small blocks of the code. My normal */
  399. #endif /* style of coding would have declared */
  400. const uschar *callpat; /* them within each of those blocks. */
  401. const uschar *data; /* However, in order to accommodate the */
  402. const uschar *next; /* version of this code that uses an */
  403. USPTR pp; /* external "stack" implemented on the */
  404. const uschar *prev; /* heap, it is easier to declare them all */
  405. USPTR saved_eptr; /* here, so the declarations can be cut */
  406. /* out in a block. The only declarations */
  407. recursion_info new_recursive; /* within blocks below are for variables */
  408. /* that do not have to be preserved over */
  409. BOOL cur_is_word; /* a recursive call to RMATCH(). */
  410. BOOL condition;
  411. BOOL prev_is_word;
  412. unsigned long int original_ims;
  413. #ifdef SUPPORT_UCP
  414. int prop_type;
  415. int prop_value;
  416. int prop_fail_result;
  417. int prop_category;
  418. int prop_chartype;
  419. int prop_script;
  420. int oclength;
  421. uschar occhars[8];
  422. #endif
  423. int ctype;
  424. int length;
  425. int max;
  426. int min;
  427. int number;
  428. int offset;
  429. int op;
  430. int save_capture_last;
  431. int save_offset1, save_offset2, save_offset3;
  432. int stacksave[REC_STACK_SAVE_MAX];
  433. eptrblock newptrb;
  434. #endif /* NO_RECURSE */
  435. /* These statements are here to stop the compiler complaining about unitialized
  436. variables. */
  437. #ifdef SUPPORT_UCP
  438. prop_value = 0;
  439. prop_fail_result = 0;
  440. #endif
  441. /* This label is used for tail recursion, which is used in a few cases even
  442. when NO_RECURSE is not defined, in order to reduce the amount of stack that is
  443. used. Thanks to Ian Taylor for noticing this possibility and sending the
  444. original patch. */
  445. TAIL_RECURSE:
  446. /* OK, now we can get on with the real code of the function. Recursive calls
  447. are specified by the macro RMATCH and RRETURN is used to return. When
  448. NO_RECURSE is *not* defined, these just turn into a recursive call to match()
  449. and a "return", respectively (possibly with some debugging if DEBUG is
  450. defined). However, RMATCH isn't like a function call because it's quite a
  451. complicated macro. It has to be used in one particular way. This shouldn't,
  452. however, impact performance when true recursion is being used. */
  453. #ifdef SUPPORT_UTF8
  454. utf8 = md->utf8; /* Local copy of the flag */
  455. #else
  456. utf8 = FALSE;
  457. #endif
  458. /* First check that we haven't called match() too many times, or that we
  459. haven't exceeded the recursive call limit. */
  460. if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);
  461. if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
  462. original_ims = ims; /* Save for resetting on ')' */
  463. /* At the start of a group with an unlimited repeat that may match an empty
  464. string, the match_cbegroup flag is set. When this is the case, add the current
  465. subject pointer to the chain of such remembered pointers, to be checked when we
  466. hit the closing ket, in order to break infinite loops that match no characters.
  467. When match() is called in other circumstances, don't add to the chain. The
  468. match_cbegroup flag must NOT be used with tail recursion, because the memory
  469. block that is used is on the stack, so a new one may be required for each
  470. match(). */
  471. if ((flags & match_cbegroup) != 0)
  472. {
  473. newptrb.epb_saved_eptr = eptr;
  474. newptrb.epb_prev = eptrb;
  475. eptrb = &newptrb;
  476. }
  477. /* Now start processing the opcodes. */
  478. for (;;)
  479. {
  480. minimize = possessive = FALSE;
  481. op = *ecode;
  482. /* For partial matching, remember if we ever hit the end of the subject after
  483. matching at least one subject character. */
  484. if (md->partial &&
  485. eptr >= md->end_subject &&
  486. eptr > mstart)
  487. md->hitend = TRUE;
  488. switch(op)
  489. {
  490. case OP_FAIL:
  491. RRETURN(MATCH_NOMATCH);
  492. case OP_PRUNE:
  493. RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  494. ims, eptrb, flags, RM51);
  495. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  496. RRETURN(MATCH_PRUNE);
  497. case OP_COMMIT:
  498. RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  499. ims, eptrb, flags, RM52);
  500. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  501. RRETURN(MATCH_COMMIT);
  502. case OP_SKIP:
  503. RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  504. ims, eptrb, flags, RM53);
  505. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  506. md->start_match_ptr = eptr; /* Pass back current position */
  507. RRETURN(MATCH_SKIP);
  508. case OP_THEN:
  509. RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  510. ims, eptrb, flags, RM54);
  511. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  512. RRETURN(MATCH_THEN);
  513. /* Handle a capturing bracket. If there is space in the offset vector, save
  514. the current subject position in the working slot at the top of the vector.
  515. We mustn't change the current values of the data slot, because they may be
  516. set from a previous iteration of this group, and be referred to by a
  517. reference inside the group.
  518. If the bracket fails to match, we need to restore this value and also the
  519. values of the final offsets, in case they were set by a previous iteration
  520. of the same bracket.
  521. If there isn't enough space in the offset vector, treat this as if it were
  522. a non-capturing bracket. Don't worry about setting the flag for the error
  523. case here; that is handled in the code for KET. */
  524. case OP_CBRA:
  525. case OP_SCBRA:
  526. number = GET2(ecode, 1+LINK_SIZE);
  527. offset = number << 1;
  528. #ifdef DEBUG
  529. printf("start bracket %d\n", number);
  530. printf("subject=");
  531. pchars(eptr, 16, TRUE, md);
  532. printf("\n");
  533. #endif
  534. if (offset < md->offset_max)
  535. {
  536. save_offset1 = md->offset_vector[offset];
  537. save_offset2 = md->offset_vector[offset+1];
  538. save_offset3 = md->offset_vector[md->offset_end - number];
  539. save_capture_last = md->capture_last;
  540. DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
  541. md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
  542. flags = (op == OP_SCBRA)? match_cbegroup : 0;
  543. do
  544. {
  545. RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  546. ims, eptrb, flags, RM1);
  547. if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  548. md->capture_last = save_capture_last;
  549. ecode += GET(ecode, 1);
  550. }
  551. while (*ecode == OP_ALT);
  552. DPRINTF(("bracket %d failed\n", number));
  553. md->offset_vector[offset] = save_offset1;
  554. md->offset_vector[offset+1] = save_offset2;
  555. md->offset_vector[md->offset_end - number] = save_offset3;
  556. RRETURN(MATCH_NOMATCH);
  557. }
  558. /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
  559. as a non-capturing bracket. */
  560. /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  561. /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  562. DPRINTF(("insufficient capture room: treat as non-capturing\n"));
  563. /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  564. /* VVVVVVVVVVVVVVVVVVVVVVVVV */
  565. /* Non-capturing bracket. Loop for all the alternatives. When we get to the
  566. final alternative within the brackets, we would return the result of a
  567. recursive call to match() whatever happened. We can reduce stack usage by
  568. turning this into a tail recursion, except in the case when match_cbegroup
  569. is set.*/
  570. case OP_BRA:
  571. case OP_SBRA:
  572. DPRINTF(("start non-capturing bracket\n"));
  573. flags = (op >= OP_SBRA)? match_cbegroup : 0;
  574. for (;;)
  575. {
  576. if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */
  577. {
  578. if (flags == 0) /* Not a possibly empty group */
  579. {
  580. ecode += _pcre_OP_lengths[*ecode];
  581. DPRINTF(("bracket 0 tail recursion\n"));
  582. goto TAIL_RECURSE;
  583. }
  584. /* Possibly empty group; can't use tail recursion. */
  585. RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
  586. eptrb, flags, RM48);
  587. RRETURN(rrc);
  588. }
  589. /* For non-final alternatives, continue the loop for a NOMATCH result;
  590. otherwise return. */
  591. RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
  592. eptrb, flags, RM2);
  593. if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  594. ecode += GET(ecode, 1);
  595. }
  596. /* Control never reaches here. */
  597. /* Conditional group: compilation checked that there are no more than
  598. two branches. If the condition is false, skipping the first branch takes us
  599. past the end if there is only one branch, but that's OK because that is
  600. exactly what going to the ket would do. As there is only one branch to be
  601. obeyed, we can use tail recursion to avoid using another stack frame. */
  602. case OP_COND:
  603. case OP_SCOND:
  604. if (ecode[LINK_SIZE+1] == OP_RREF) /* Recursion test */
  605. {
  606. offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/
  607. condition = md->recursive != NULL &&
  608. (offset == RREF_ANY || offset == md->recursive->group_num);
  609. ecode += condition? 3 : GET(ecode, 1);
  610. }
  611. else if (ecode[LINK_SIZE+1] == OP_CREF) /* Group used test */
  612. {
  613. offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */
  614. condition = offset < offset_top && md->offset_vector[offset] >= 0;
  615. ecode += condition? 3 : GET(ecode, 1);
  616. }
  617. else if (ecode[LINK_SIZE+1] == OP_DEF) /* DEFINE - always false */
  618. {
  619. condition = FALSE;
  620. ecode += GET(ecode, 1);
  621. }
  622. /* The condition is an assertion. Call match() to evaluate it - setting
  623. the final argument match_condassert causes it to stop at the end of an
  624. assertion. */
  625. else
  626. {
  627. RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
  628. match_condassert, RM3);
  629. if (rrc == MATCH_MATCH)
  630. {
  631. condition = TRUE;
  632. ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
  633. while (*ecode == OP_ALT) ecode += GET(ecode, 1);
  634. }
  635. else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
  636. {
  637. RRETURN(rrc); /* Need braces because of following else */
  638. }
  639. else
  640. {
  641. condition = FALSE;
  642. ecode += GET(ecode, 1);
  643. }
  644. }
  645. /* We are now at the branch that is to be obeyed. As there is only one,
  646. we can use tail recursion to avoid using another stack frame, except when
  647. match_cbegroup is required for an unlimited repeat of a possibly empty
  648. group. If the second alternative doesn't exist, we can just plough on. */
  649. if (condition || *ecode == OP_ALT)
  650. {
  651. ecode += 1 + LINK_SIZE;
  652. if (op == OP_SCOND) /* Possibly empty group */
  653. {
  654. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
  655. RRETURN(rrc);
  656. }
  657. else /* Group must match something */
  658. {
  659. flags = 0;
  660. goto TAIL_RECURSE;
  661. }
  662. }
  663. else /* Condition false & no 2nd alternative */
  664. {
  665. ecode += 1 + LINK_SIZE;
  666. }
  667. break;
  668. /* End of the pattern, either real or forced. If we are in a top-level
  669. recursion, we should restore the offsets appropriately and continue from
  670. after the call. */
  671. case OP_ACCEPT:
  672. case OP_END:
  673. if (md->recursive != NULL && md->recursive->group_num == 0)
  674. {
  675. recursion_info *rec = md->recursive;
  676. DPRINTF(("End of pattern in a (?0) recursion\n"));
  677. md->recursive = rec->prevrec;
  678. memmove(md->offset_vector, rec->offset_save,
  679. rec->saved_max * sizeof(int));
  680. mstart = rec->save_start;
  681. ims = original_ims;
  682. ecode = rec->after_call;
  683. break;
  684. }
  685. /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
  686. string - backtracking will then try other alternatives, if any. */
  687. if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
  688. md->end_match_ptr = eptr; /* Record where we ended */
  689. md->end_offset_top = offset_top; /* and how many extracts were taken */
  690. md->start_match_ptr = mstart; /* and the start (\K can modify) */
  691. RRETURN(MATCH_MATCH);
  692. /* Change option settings */
  693. case OP_OPT:
  694. ims = ecode[1];
  695. ecode += 2;
  696. DPRINTF(("ims set to %02lx\n", ims));
  697. break;
  698. /* Assertion brackets. Check the alternative branches in turn - the
  699. matching won't pass the KET for an assertion. If any one branch matches,
  700. the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
  701. start of each branch to move the current point backwards, so the code at
  702. this level is identical to the lookahead case. */
  703. case OP_ASSERT:
  704. case OP_ASSERTBACK:
  705. do
  706. {
  707. RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
  708. RM4);
  709. if (rrc == MATCH_MATCH) break;
  710. if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  711. ecode += GET(ecode, 1);
  712. }
  713. while (*ecode == OP_ALT);
  714. if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);
  715. /* If checking an assertion for a condition, return MATCH_MATCH. */
  716. if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
  717. /* Continue from after the assertion, updating the offsets high water
  718. mark, since extracts may have been taken during the assertion. */
  719. do ecode += GET(ecode,1); while (*ecode == OP_ALT);
  720. ecode += 1 + LINK_SIZE;
  721. offset_top = md->end_offset_top;
  722. continue;
  723. /* Negative assertion: all branches must fail to match */
  724. case OP_ASSERT_NOT:
  725. case OP_ASSERTBACK_NOT:
  726. do
  727. {
  728. RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
  729. RM5);
  730. if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
  731. if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  732. ecode += GET(ecode,1);
  733. }
  734. while (*ecode == OP_ALT);
  735. if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
  736. ecode += 1 + LINK_SIZE;
  737. continue;
  738. /* Move the subject pointer back. This occurs only at the start of
  739. each branch of a lookbehind assertion. If we are too close to the start to
  740. move back, this match function fails. When working with UTF-8 we move
  741. back a number of characters, not bytes. */
  742. case OP_REVERSE:
  743. #ifdef SUPPORT_UTF8
  744. if (utf8)
  745. {
  746. i = GET(ecode, 1);
  747. while (i-- > 0)
  748. {
  749. eptr--;
  750. if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
  751. BACKCHAR(eptr);
  752. }
  753. }
  754. else
  755. #endif
  756. /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
  757. {
  758. eptr -= GET(ecode, 1);
  759. if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
  760. }
  761. /* Skip to next op code */
  762. ecode += 1 + LINK_SIZE;
  763. break;
  764. /* The callout item calls an external function, if one is provided, passing
  765. details of the match so far. This is mainly for debugging, though the
  766. function is able to force a failure. */
  767. case OP_CALLOUT:
  768. if (pcre_callout != NULL)
  769. {
  770. pcre_callout_block cb;
  771. cb.version = 1; /* Version 1 of the callout block */
  772. cb.callout_number = ecode[1];
  773. cb.offset_vector = md->offset_vector;
  774. cb.subject = (PCRE_SPTR)md->start_subject;
  775. cb.subject_length = md->end_subject - md->start_subject;
  776. cb.start_match = mstart - md->start_subject;
  777. cb.current_position = eptr - md->start_subject;
  778. cb.pattern_position = GET(ecode, 2);
  779. cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
  780. cb.capture_top = offset_top/2;
  781. cb.capture_last = md->capture_last;
  782. cb.callout_data = md->callout_data;
  783. if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
  784. if (rrc < 0) RRETURN(rrc);
  785. }
  786. ecode += 2 + 2*LINK_SIZE;
  787. break;
  788. /* Recursion either matches the current regex, or some subexpression. The
  789. offset data is the offset to the starting bracket from the start of the
  790. whole pattern. (This is so that it works from duplicated subpatterns.)
  791. If there are any capturing brackets started but not finished, we have to
  792. save their starting points and reinstate them after the recursion. However,
  793. we don't know how many such there are (offset_top records the completed
  794. total) so we just have to save all the potential data. There may be up to
  795. 65535 such values, which is too large to put on the stack, but using malloc
  796. for small numbers seems expensive. As a compromise, the stack is used when
  797. there are no more than REC_STACK_SAVE_MAX values to store; otherwise malloc
  798. is used. A problem is what to do if the malloc fails ... there is no way of
  799. returning to the top level with an error. Save the top REC_STACK_SAVE_MAX
  800. values on the stack, and accept that the rest may be wrong.
  801. There are also other values that have to be saved. We use a chained
  802. sequence of blocks that actually live on the stack. Thanks to Robin Houston
  803. for the original version of this logic. */
  804. case OP_RECURSE:
  805. {
  806. callpat = md->start_code + GET(ecode, 1);
  807. new_recursive.group_num = (callpat == md->start_code)? 0 :
  808. GET2(callpat, 1 + LINK_SIZE);
  809. /* Add to "recursing stack" */
  810. new_recursive.prevrec = md->recursive;
  811. md->recursive = &new_recursive;
  812. /* Find where to continue from afterwards */
  813. ecode += 1 + LINK_SIZE;
  814. new_recursive.after_call = ecode;
  815. /* Now save the offset data. */
  816. new_recursive.saved_max = md->offset_end;
  817. if (new_recursive.saved_max <= REC_STACK_SAVE_MAX)
  818. new_recursive.offset_save = stacksave;
  819. else
  820. {
  821. new_recursive.offset_save =
  822. (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));
  823. if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
  824. }
  825. memcpy(new_recursive.offset_save, md->offset_vector,
  826. new_recursive.saved_max * sizeof(int));
  827. new_recursive.save_start = mstart;
  828. mstart = eptr;
  829. /* OK, now we can do the recursion. For each top-level alternative we
  830. restore the offset and recursion data. */
  831. DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
  832. flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
  833. do
  834. {
  835. RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
  836. md, ims, eptrb, flags, RM6);
  837. if (rrc == MATCH_MATCH)
  838. {
  839. DPRINTF(("Recursion matched\n"));
  840. md->recursive = new_recursive.prevrec;
  841. if (new_recursive.offset_save != stacksave)
  842. (pcre_free)(new_recursive.offset_save);
  843. RRETURN(MATCH_MATCH);
  844. }
  845. else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
  846. {
  847. DPRINTF(("Recursion gave error %d\n", rrc));
  848. RRETURN(rrc);
  849. }
  850. md->recursive = &new_recursive;
  851. memcpy(md->offset_vector, new_recursive.offset_save,
  852. new_recursive.saved_max * sizeof(int));
  853. callpat += GET(callpat, 1);
  854. }
  855. while (*callpat == OP_ALT);
  856. DPRINTF(("Recursion didn't match\n"));
  857. md->recursive = new_recursive.prevrec;
  858. if (new_recursive.offset_save != stacksave)
  859. (pcre_free)(new_recursive.offset_save);
  860. RRETURN(MATCH_NOMATCH);
  861. }
  862. /* Control never reaches here */
  863. /* "Once" brackets are like assertion brackets except that after a match,
  864. the point in the subject string is not moved back. Thus there can never be
  865. a move back into the brackets. Friedl calls these "atomic" subpatterns.
  866. Check the alternative branches in turn - the matching won't pass the KET
  867. for this kind of subpattern. If any one branch matches, we carry on as at
  868. the end of a normal bracket, leaving the subject pointer. */
  869. case OP_ONCE:
  870. prev = ecode;
  871. saved_eptr = eptr;
  872. do
  873. {
  874. RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
  875. if (rrc == MATCH_MATCH) break;
  876. if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
  877. ecode += GET(ecode,1);
  878. }
  879. while (*ecode == OP_ALT);
  880. /* If hit the end of the group (which could be repeated), fail */
  881. if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
  882. /* Continue as from after the assertion, updating the offsets high water
  883. mark, since extracts may have been taken. */
  884. do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
  885. offset_top = md->end_offset_top;
  886. eptr = md->end_match_ptr;
  887. /* For a non-repeating ket, just continue at this level. This also
  888. happens for a repeating ket if no characters were matched in the group.
  889. This is the forcible breaking of infinite loops as implemented in Perl
  890. 5.005. If there is an options reset, it will get obeyed in the normal
  891. course of events. */
  892. if (*ecode == OP_KET || eptr == saved_eptr)
  893. {
  894. ecode += 1+LINK_SIZE;
  895. break;
  896. }
  897. /* The repeating kets try the rest of the pattern or restart from the
  898. preceding bracket, in the appropriate order. The second "call" of match()
  899. uses tail recursion, to avoid using another stack frame. We need to reset
  900. any options that changed within the bracket before re-running it, so
  901. check the next opcode. */
  902. if (ecode[1+LINK_SIZE] == OP_OPT)
  903. {
  904. ims = (ims & ~PCRE_IMS) | ecode[4];
  905. DPRINTF(("ims set to %02lx at group repeat\n", ims));
  906. }
  907. if (*ecode == OP_KETRMIN)
  908. {
  909. RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
  910. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  911. ecode = prev;
  912. flags = 0;
  913. goto TAIL_RECURSE;
  914. }
  915. else /* OP_KETRMAX */
  916. {
  917. RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
  918. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  919. ecode += 1 + LINK_SIZE;
  920. flags = 0;
  921. goto TAIL_RECURSE;
  922. }
  923. /* Control never gets here */
  924. /* An alternation is the end of a branch; scan along to find the end of the
  925. bracketed group and go to there. */
  926. case OP_ALT:
  927. do ecode += GET(ecode,1); while (*ecode == OP_ALT);
  928. break;
  929. /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating
  930. that it may occur zero times. It may repeat infinitely, or not at all -
  931. i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper
  932. repeat limits are compiled as a number of copies, with the optional ones
  933. preceded by BRAZERO or BRAMINZERO. */
  934. case OP_BRAZERO:
  935. {
  936. next = ecode+1;
  937. RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
  938. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  939. do next += GET(next,1); while (*next == OP_ALT);
  940. ecode = next + 1 + LINK_SIZE;
  941. }
  942. break;
  943. case OP_BRAMINZERO:
  944. {
  945. next = ecode+1;
  946. do next += GET(next, 1); while (*next == OP_ALT);
  947. RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
  948. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  949. ecode++;
  950. }
  951. break;
  952. /* End of a group, repeated or non-repeating. */
  953. case OP_KET:
  954. case OP_KETRMIN:
  955. case OP_KETRMAX:
  956. prev = ecode - GET(ecode, 1);
  957. /* If this was a group that remembered the subject start, in order to break
  958. infinite repeats of empty string matches, retrieve the subject start from
  959. the chain. Otherwise, set it NULL. */
  960. if (*prev >= OP_SBRA)
  961. {
  962. saved_eptr = eptrb->epb_saved_eptr; /* Value at start of group */
  963. eptrb = eptrb->epb_prev; /* Backup to previous group */
  964. }
  965. else saved_eptr = NULL;
  966. /* If we are at the end of an assertion group, stop matching and return
  967. MATCH_MATCH, but record the current high water mark for use by positive
  968. assertions. Do this also for the "once" (atomic) groups. */
  969. if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
  970. *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
  971. *prev == OP_ONCE)
  972. {
  973. md->end_match_ptr = eptr; /* For ONCE */
  974. md->end_offset_top = offset_top;
  975. RRETURN(MATCH_MATCH);
  976. }
  977. /* For capturing groups we have to check the group number back at the start
  978. and if necessary complete handling an extraction by setting the offsets and
  979. bumping the high water mark. Note that whole-pattern recursion is coded as
  980. a recurse into group 0, so it won't be picked up here. Instead, we catch it
  981. when the OP_END is reached. Other recursion is handled here. */
  982. if (*prev == OP_CBRA || *prev == OP_SCBRA)
  983. {
  984. number = GET2(prev, 1+LINK_SIZE);
  985. offset = number << 1;
  986. #ifdef DEBUG
  987. printf("end bracket %d", number);
  988. printf("\n");
  989. #endif
  990. md->capture_last = number;
  991. if (offset >= md->offset_max) md->offset_overflow = TRUE; else
  992. {
  993. md->offset_vector[offset] =
  994. md->offset_vector[md->offset_end - number];
  995. md->offset_vector[offset+1] = eptr - md->start_subject;
  996. if (offset_top <= offset) offset_top = offset + 2;
  997. }
  998. /* Handle a recursively called group. Restore the offsets
  999. appropriately and continue from after the call. */
  1000. if (md->recursive != NULL && md->recursive->group_num == number)
  1001. {
  1002. recursion_info *rec = md->recursive;
  1003. DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
  1004. md->recursive = rec->prevrec;
  1005. mstart = rec->save_start;
  1006. memcpy(md->offset_vector, rec->offset_save,
  1007. rec->saved_max * sizeof(int));
  1008. ecode = rec->after_call;
  1009. ims = original_ims;
  1010. break;
  1011. }
  1012. }
  1013. /* For both capturing and non-capturing groups, reset the value of the ims
  1014. flags, in case they got changed during the group. */
  1015. ims = original_ims;
  1016. DPRINTF(("ims reset to %02lx\n", ims));
  1017. /* For a non-repeating ket, just continue at this level. This also
  1018. happens for a repeating ket if no characters were matched in the group.
  1019. This is the forcible breaking of infinite loops as implemented in Perl
  1020. 5.005. If there is an options reset, it will get obeyed in the normal
  1021. course of events. */
  1022. if (*ecode == OP_KET || eptr == saved_eptr)
  1023. {
  1024. ecode += 1 + LINK_SIZE;
  1025. break;
  1026. }
  1027. /* The repeating kets try the rest of the pattern or restart from the
  1028. preceding bracket, in the appropriate order. In the second case, we can use
  1029. tail recursion to avoid using another stack frame, unless we have an
  1030. unlimited repeat of a group that can match an empty string. */
  1031. flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
  1032. if (*ecode == OP_KETRMIN)
  1033. {
  1034. RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
  1035. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1036. if (flags != 0) /* Could match an empty string */
  1037. {
  1038. RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
  1039. RRETURN(rrc);
  1040. }
  1041. ecode = prev;
  1042. goto TAIL_RECURSE;
  1043. }
  1044. else /* OP_KETRMAX */
  1045. {
  1046. RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
  1047. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1048. ecode += 1 + LINK_SIZE;
  1049. flags = 0;
  1050. goto TAIL_RECURSE;
  1051. }
  1052. /* Control never gets here */
  1053. /* Start of subject unless notbol, or after internal newline if multiline */
  1054. case OP_CIRC:
  1055. if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
  1056. if ((ims & PCRE_MULTILINE) != 0)
  1057. {
  1058. if (eptr != md->start_subject &&
  1059. (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
  1060. RRETURN(MATCH_NOMATCH);
  1061. ecode++;
  1062. break;
  1063. }
  1064. /* ... else fall through */
  1065. /* Start of subject assertion */
  1066. case OP_SOD:
  1067. if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);
  1068. ecode++;
  1069. break;
  1070. /* Start of match assertion */
  1071. case OP_SOM:
  1072. if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);
  1073. ecode++;
  1074. break;
  1075. /* Reset the start of match point */
  1076. case OP_SET_SOM:
  1077. mstart = eptr;
  1078. ecode++;
  1079. break;
  1080. /* Assert before internal newline if multiline, or before a terminating
  1081. newline unless endonly is set, else end of subject unless noteol is set. */
  1082. case OP_DOLL:
  1083. if ((ims & PCRE_MULTILINE) != 0)
  1084. {
  1085. if (eptr < md->end_subject)
  1086. { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
  1087. else
  1088. { if (md->noteol) RRETURN(MATCH_NOMATCH); }
  1089. ecode++;
  1090. break;
  1091. }
  1092. else
  1093. {
  1094. if (md->noteol) RRETURN(MATCH_NOMATCH);
  1095. if (!md->endonly)
  1096. {
  1097. if (eptr != md->end_subject &&
  1098. (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
  1099. RRETURN(MATCH_NOMATCH);
  1100. ecode++;
  1101. break;
  1102. }
  1103. }
  1104. /* ... else fall through for endonly */
  1105. /* End of subject assertion (\z) */
  1106. case OP_EOD:
  1107. if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);
  1108. ecode++;
  1109. break;
  1110. /* End of subject or ending \n assertion (\Z) */
  1111. case OP_EODN:
  1112. if (eptr != md->end_subject &&
  1113. (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
  1114. RRETURN(MATCH_NOMATCH);
  1115. ecode++;
  1116. break;
  1117. /* Word boundary assertions */
  1118. case OP_NOT_WORD_BOUNDARY:
  1119. case OP_WORD_BOUNDARY:
  1120. {
  1121. /* Find out if the previous and current characters are "word" characters.
  1122. It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
  1123. be "non-word" characters. */
  1124. #ifdef SUPPORT_UTF8
  1125. if (utf8)
  1126. {
  1127. if (eptr == md->start_subject) prev_is_word = FALSE; else
  1128. {
  1129. const uschar *lastptr = eptr - 1;
  1130. while((*lastptr & 0xc0) == 0x80) lastptr--;
  1131. GETCHAR(c, lastptr);
  1132. prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
  1133. }
  1134. if (eptr >= md->end_subject) cur_is_word = FALSE; else
  1135. {
  1136. GETCHAR(c, eptr);
  1137. cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
  1138. }
  1139. }
  1140. else
  1141. #endif
  1142. /* More streamlined when not in UTF-8 mode */
  1143. {
  1144. prev_is_word = (eptr != md->start_subject) &&
  1145. ((md->ctypes[eptr[-1]] & ctype_word) != 0);
  1146. cur_is_word = (eptr < md->end_subject) &&
  1147. ((md->ctypes[*eptr] & ctype_word) != 0);
  1148. }
  1149. /* Now see if the situation is what we want */
  1150. if ((*ecode++ == OP_WORD_BOUNDARY)?
  1151. cur_is_word == prev_is_word : cur_is_word != prev_is_word)
  1152. RRETURN(MATCH_NOMATCH);
  1153. }
  1154. break;
  1155. /* Match a single character type; inline for speed */
  1156. case OP_ANY:
  1157. if ((ims & PCRE_DOTALL) == 0)
  1158. {
  1159. if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
  1160. }
  1161. if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1162. if (utf8)
  1163. while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  1164. ecode++;
  1165. break;
  1166. /* Match a single byte, even in UTF-8 mode. This opcode really does match
  1167. any byte, even newline, independent of the setting of PCRE_DOTALL. */
  1168. case OP_ANYBYTE:
  1169. if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1170. ecode++;
  1171. break;
  1172. case OP_NOT_DIGIT:
  1173. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1174. GETCHARINCTEST(c, eptr);
  1175. if (
  1176. #ifdef SUPPORT_UTF8
  1177. c < 256 &&
  1178. #endif
  1179. (md->ctypes[c] & ctype_digit) != 0
  1180. )
  1181. RRETURN(MATCH_NOMATCH);
  1182. ecode++;
  1183. break;
  1184. case OP_DIGIT:
  1185. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1186. GETCHARINCTEST(c, eptr);
  1187. if (
  1188. #ifdef SUPPORT_UTF8
  1189. c >= 256 ||
  1190. #endif
  1191. (md->ctypes[c] & ctype_digit) == 0
  1192. )
  1193. RRETURN(MATCH_NOMATCH);
  1194. ecode++;
  1195. break;
  1196. case OP_NOT_WHITESPACE:
  1197. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1198. GETCHARINCTEST(c, eptr);
  1199. if (
  1200. #ifdef SUPPORT_UTF8
  1201. c < 256 &&
  1202. #endif
  1203. (md->ctypes[c] & ctype_space) != 0
  1204. )
  1205. RRETURN(MATCH_NOMATCH);
  1206. ecode++;
  1207. break;
  1208. case OP_WHITESPACE:
  1209. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1210. GETCHARINCTEST(c, eptr);
  1211. if (
  1212. #ifdef SUPPORT_UTF8
  1213. c >= 256 ||
  1214. #endif
  1215. (md->ctypes[c] & ctype_space) == 0
  1216. )
  1217. RRETURN(MATCH_NOMATCH);
  1218. ecode++;
  1219. break;
  1220. case OP_NOT_WORDCHAR:
  1221. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1222. GETCHARINCTEST(c, eptr);
  1223. if (
  1224. #ifdef SUPPORT_UTF8
  1225. c < 256 &&
  1226. #endif
  1227. (md->ctypes[c] & ctype_word) != 0
  1228. )
  1229. RRETURN(MATCH_NOMATCH);
  1230. ecode++;
  1231. break;
  1232. case OP_WORDCHAR:
  1233. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1234. GETCHARINCTEST(c, eptr);
  1235. if (
  1236. #ifdef SUPPORT_UTF8
  1237. c >= 256 ||
  1238. #endif
  1239. (md->ctypes[c] & ctype_word) == 0
  1240. )
  1241. RRETURN(MATCH_NOMATCH);
  1242. ecode++;
  1243. break;
  1244. case OP_ANYNL:
  1245. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1246. GETCHARINCTEST(c, eptr);
  1247. switch(c)
  1248. {
  1249. default: RRETURN(MATCH_NOMATCH);
  1250. case 0x000d:
  1251. if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  1252. break;
  1253. case 0x000a:
  1254. break;
  1255. case 0x000b:
  1256. case 0x000c:
  1257. case 0x0085:
  1258. case 0x2028:
  1259. case 0x2029:
  1260. if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  1261. break;
  1262. }
  1263. ecode++;
  1264. break;
  1265. case OP_NOT_HSPACE:
  1266. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1267. GETCHARINCTEST(c, eptr);
  1268. switch(c)
  1269. {
  1270. default: break;
  1271. case 0x09: /* HT */
  1272. case 0x20: /* SPACE */
  1273. case 0xa0: /* NBSP */
  1274. case 0x1680: /* OGHAM SPACE MARK */
  1275. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  1276. case 0x2000: /* EN QUAD */
  1277. case 0x2001: /* EM QUAD */
  1278. case 0x2002: /* EN SPACE */
  1279. case 0x2003: /* EM SPACE */
  1280. case 0x2004: /* THREE-PER-EM SPACE */
  1281. case 0x2005: /* FOUR-PER-EM SPACE */
  1282. case 0x2006: /* SIX-PER-EM SPACE */
  1283. case 0x2007: /* FIGURE SPACE */
  1284. case 0x2008: /* PUNCTUATION SPACE */
  1285. case 0x2009: /* THIN SPACE */
  1286. case 0x200A: /* HAIR SPACE */
  1287. case 0x202f: /* NARROW NO-BREAK SPACE */
  1288. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  1289. case 0x3000: /* IDEOGRAPHIC SPACE */
  1290. RRETURN(MATCH_NOMATCH);
  1291. }
  1292. ecode++;
  1293. break;
  1294. case OP_HSPACE:
  1295. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1296. GETCHARINCTEST(c, eptr);
  1297. switch(c)
  1298. {
  1299. default: RRETURN(MATCH_NOMATCH);
  1300. case 0x09: /* HT */
  1301. case 0x20: /* SPACE */
  1302. case 0xa0: /* NBSP */
  1303. case 0x1680: /* OGHAM SPACE MARK */
  1304. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  1305. case 0x2000: /* EN QUAD */
  1306. case 0x2001: /* EM QUAD */
  1307. case 0x2002: /* EN SPACE */
  1308. case 0x2003: /* EM SPACE */
  1309. case 0x2004: /* THREE-PER-EM SPACE */
  1310. case 0x2005: /* FOUR-PER-EM SPACE */
  1311. case 0x2006: /* SIX-PER-EM SPACE */
  1312. case 0x2007: /* FIGURE SPACE */
  1313. case 0x2008: /* PUNCTUATION SPACE */
  1314. case 0x2009: /* THIN SPACE */
  1315. case 0x200A: /* HAIR SPACE */
  1316. case 0x202f: /* NARROW NO-BREAK SPACE */
  1317. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  1318. case 0x3000: /* IDEOGRAPHIC SPACE */
  1319. break;
  1320. }
  1321. ecode++;
  1322. break;
  1323. case OP_NOT_VSPACE:
  1324. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1325. GETCHARINCTEST(c, eptr);
  1326. switch(c)
  1327. {
  1328. default: break;
  1329. case 0x0a: /* LF */
  1330. case 0x0b: /* VT */
  1331. case 0x0c: /* FF */
  1332. case 0x0d: /* CR */
  1333. case 0x85: /* NEL */
  1334. case 0x2028: /* LINE SEPARATOR */
  1335. case 0x2029: /* PARAGRAPH SEPARATOR */
  1336. RRETURN(MATCH_NOMATCH);
  1337. }
  1338. ecode++;
  1339. break;
  1340. case OP_VSPACE:
  1341. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1342. GETCHARINCTEST(c, eptr);
  1343. switch(c)
  1344. {
  1345. default: RRETURN(MATCH_NOMATCH);
  1346. case 0x0a: /* LF */
  1347. case 0x0b: /* VT */
  1348. case 0x0c: /* FF */
  1349. case 0x0d: /* CR */
  1350. case 0x85: /* NEL */
  1351. case 0x2028: /* LINE SEPARATOR */
  1352. case 0x2029: /* PARAGRAPH SEPARATOR */
  1353. break;
  1354. }
  1355. ecode++;
  1356. break;
  1357. #ifdef SUPPORT_UCP
  1358. /* Check the next character by Unicode property. We will get here only
  1359. if the support is in the binary; otherwise a compile-time error occurs. */
  1360. case OP_PROP:
  1361. case OP_NOTPROP:
  1362. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1363. GETCHARINCTEST(c, eptr);
  1364. {
  1365. int chartype, script;
  1366. int category = _pcre_ucp_findprop(c, &chartype, &script);
  1367. switch(ecode[1])
  1368. {
  1369. case PT_ANY:
  1370. if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
  1371. break;
  1372. case PT_LAMP:
  1373. if ((chartype == ucp_Lu ||
  1374. chartype == ucp_Ll ||
  1375. chartype == ucp_Lt) == (op == OP_NOTPROP))
  1376. RRETURN(MATCH_NOMATCH);
  1377. break;
  1378. case PT_GC:
  1379. if ((ecode[2] != category) == (op == OP_PROP))
  1380. RRETURN(MATCH_NOMATCH);
  1381. break;
  1382. case PT_PC:
  1383. if ((ecode[2] != chartype) == (op == OP_PROP))
  1384. RRETURN(MATCH_NOMATCH);
  1385. break;
  1386. case PT_SC:
  1387. if ((ecode[2] != script) == (op == OP_PROP))
  1388. RRETURN(MATCH_NOMATCH);
  1389. break;
  1390. default:
  1391. RRETURN(PCRE_ERROR_INTERNAL);
  1392. }
  1393. ecode += 3;
  1394. }
  1395. break;
  1396. /* Match an extended Unicode sequence. We will get here only if the support
  1397. is in the binary; otherwise a compile-time error occurs. */
  1398. case OP_EXTUNI:
  1399. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1400. GETCHARINCTEST(c, eptr);
  1401. {
  1402. int chartype, script;
  1403. int category = _pcre_ucp_findprop(c, &chartype, &script);
  1404. if (category == ucp_M) RRETURN(MATCH_NOMATCH);
  1405. while (eptr < md->end_subject)
  1406. {
  1407. int len = 1;
  1408. if (!utf8) c = *eptr; else
  1409. {
  1410. GETCHARLEN(c, eptr, len);
  1411. }
  1412. category = _pcre_ucp_findprop(c, &chartype, &script);
  1413. if (category != ucp_M) break;
  1414. eptr += len;
  1415. }
  1416. }
  1417. ecode++;
  1418. break;
  1419. #endif
  1420. /* Match a back reference, possibly repeatedly. Look past the end of the
  1421. item to see if there is repeat information following. The code is similar
  1422. to that for character classes, but repeated for efficiency. Then obey
  1423. similar code to character type repeats - written out again for speed.
  1424. However, if the referenced string is the empty string, always treat
  1425. it as matched, any number of times (otherwise there could be infinite
  1426. loops). */
  1427. case OP_REF:
  1428. {
  1429. offset = GET2(ecode, 1) << 1; /* Doubled ref number */
  1430. ecode += 3; /* Advance past item */
  1431. /* If the reference is unset, set the length to be longer than the amount
  1432. of subject left; this ensures that every attempt at a match fails. We
  1433. can't just fail here, because of the possibility of quantifiers with zero
  1434. minima. */
  1435. length = (offset >= offset_top || md->offset_vector[offset] < 0)?
  1436. md->end_subject - eptr + 1 :
  1437. md->offset_vector[offset+1] - md->offset_vector[offset];
  1438. /* Set up for repetition, or handle the non-repeated case */
  1439. switch (*ecode)
  1440. {
  1441. case OP_CRSTAR:
  1442. case OP_CRMINSTAR:
  1443. case OP_CRPLUS:
  1444. case OP_CRMINPLUS:
  1445. case OP_CRQUERY:
  1446. case OP_CRMINQUERY:
  1447. c = *ecode++ - OP_CRSTAR;
  1448. minimize = (c & 1) != 0;
  1449. min = rep_min[c]; /* Pick up values from tables; */
  1450. max = rep_max[c]; /* zero for max => infinity */
  1451. if (max == 0) max = INT_MAX;
  1452. break;
  1453. case OP_CRRANGE:
  1454. case OP_CRMINRANGE:
  1455. minimize = (*ecode == OP_CRMINRANGE);
  1456. min = GET2(ecode, 1);
  1457. max = GET2(ecode, 3);
  1458. if (max == 0) max = INT_MAX;
  1459. ecode += 5;
  1460. break;
  1461. default: /* No repeat follows */
  1462. if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);
  1463. eptr += length;
  1464. continue; /* With the main loop */
  1465. }
  1466. /* If the length of the reference is zero, just continue with the
  1467. main loop. */
  1468. if (length == 0) continue;
  1469. /* First, ensure the minimum number of matches are present. We get back
  1470. the length of the reference string explicitly rather than passing the
  1471. address of eptr, so that eptr can be a register variable. */
  1472. for (i = 1; i <= min; i++)
  1473. {
  1474. if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);
  1475. eptr += length;
  1476. }
  1477. /* If min = max, continue at the same level without recursion.
  1478. They are not both allowed to be zero. */
  1479. if (min == max) continue;
  1480. /* If minimizing, keep trying and advancing the pointer */
  1481. if (minimize)
  1482. {
  1483. for (fi = min;; fi++)
  1484. {
  1485. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
  1486. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1487. if (fi >= max || !match_ref(offset, eptr, length, md, ims))
  1488. RRETURN(MATCH_NOMATCH);
  1489. eptr += length;
  1490. }
  1491. /* Control never gets here */
  1492. }
  1493. /* If maximizing, find the longest string and work backwards */
  1494. else
  1495. {
  1496. pp = eptr;
  1497. for (i = min; i < max; i++)
  1498. {
  1499. if (!match_ref(offset, eptr, length, md, ims)) break;
  1500. eptr += length;
  1501. }
  1502. while (eptr >= pp)
  1503. {
  1504. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
  1505. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1506. eptr -= length;
  1507. }
  1508. RRETURN(MATCH_NOMATCH);
  1509. }
  1510. }
  1511. /* Control never gets here */
  1512. /* Match a bit-mapped character class, possibly repeatedly. This op code is
  1513. used when all the characters in the class have values in the range 0-255,
  1514. and either the matching is caseful, or the characters are in the range
  1515. 0-127 when UTF-8 processing is enabled. The only difference between
  1516. OP_CLASS and OP_NCLASS occurs when a data character outside the range is
  1517. encountered.
  1518. First, look past the end of the item to see if there is repeat information
  1519. following. Then obey similar code to character type repeats - written out
  1520. again for speed. */
  1521. case OP_NCLASS:
  1522. case OP_CLASS:
  1523. {
  1524. data = ecode + 1; /* Save for matching */
  1525. ecode += 33; /* Advance past the item */
  1526. switch (*ecode)
  1527. {
  1528. case OP_CRSTAR:
  1529. case OP_CRMINSTAR:
  1530. case OP_CRPLUS:
  1531. case OP_CRMINPLUS:
  1532. case OP_CRQUERY:
  1533. case OP_CRMINQUERY:
  1534. c = *ecode++ - OP_CRSTAR;
  1535. minimize = (c & 1) != 0;
  1536. min = rep_min[c]; /* Pick up values from tables; */
  1537. max = rep_max[c]; /* zero for max => infinity */
  1538. if (max == 0) max = INT_MAX;
  1539. break;
  1540. case OP_CRRANGE:
  1541. case OP_CRMINRANGE:
  1542. minimize = (*ecode == OP_CRMINRANGE);
  1543. min = GET2(ecode, 1);
  1544. max = GET2(ecode, 3);
  1545. if (max == 0) max = INT_MAX;
  1546. ecode += 5;
  1547. break;
  1548. default: /* No repeat follows */
  1549. min = max = 1;
  1550. break;
  1551. }
  1552. /* First, ensure the minimum number of matches are present. */
  1553. #ifdef SUPPORT_UTF8
  1554. /* UTF-8 mode */
  1555. if (utf8)
  1556. {
  1557. for (i = 1; i <= min; i++)
  1558. {
  1559. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1560. GETCHARINC(c, eptr);
  1561. if (c > 255)
  1562. {
  1563. if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
  1564. }
  1565. else
  1566. {
  1567. if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1568. }
  1569. }
  1570. }
  1571. else
  1572. #endif
  1573. /* Not UTF-8 mode */
  1574. {
  1575. for (i = 1; i <= min; i++)
  1576. {
  1577. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1578. c = *eptr++;
  1579. if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1580. }
  1581. }
  1582. /* If max == min we can continue with the main loop without the
  1583. need to recurse. */
  1584. if (min == max) continue;
  1585. /* If minimizing, keep testing the rest of the expression and advancing
  1586. the pointer while it matches the class. */
  1587. if (minimize)
  1588. {
  1589. #ifdef SUPPORT_UTF8
  1590. /* UTF-8 mode */
  1591. if (utf8)
  1592. {
  1593. for (fi = min;; fi++)
  1594. {
  1595. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
  1596. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1597. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1598. GETCHARINC(c, eptr);
  1599. if (c > 255)
  1600. {
  1601. if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
  1602. }
  1603. else
  1604. {
  1605. if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1606. }
  1607. }
  1608. }
  1609. else
  1610. #endif
  1611. /* Not UTF-8 mode */
  1612. {
  1613. for (fi = min;; fi++)
  1614. {
  1615. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
  1616. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1617. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1618. c = *eptr++;
  1619. if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1620. }
  1621. }
  1622. /* Control never gets here */
  1623. }
  1624. /* If maximizing, find the longest possible run, then work backwards. */
  1625. else
  1626. {
  1627. pp = eptr;
  1628. #ifdef SUPPORT_UTF8
  1629. /* UTF-8 mode */
  1630. if (utf8)
  1631. {
  1632. for (i = min; i < max; i++)
  1633. {
  1634. int len = 1;
  1635. if (eptr >= md->end_subject) break;
  1636. GETCHARLEN(c, eptr, len);
  1637. if (c > 255)
  1638. {
  1639. if (op == OP_CLASS) break;
  1640. }
  1641. else
  1642. {
  1643. if ((data[c/8] & (1 << (c&7))) == 0) break;
  1644. }
  1645. eptr += len;
  1646. }
  1647. for (;;)
  1648. {
  1649. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
  1650. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1651. if (eptr-- == pp) break; /* Stop if tried at original pos */
  1652. BACKCHAR(eptr);
  1653. }
  1654. }
  1655. else
  1656. #endif
  1657. /* Not UTF-8 mode */
  1658. {
  1659. for (i = min; i < max; i++)
  1660. {
  1661. if (eptr >= md->end_subject) break;
  1662. c = *eptr;
  1663. if ((data[c/8] & (1 << (c&7))) == 0) break;
  1664. eptr++;
  1665. }
  1666. while (eptr >= pp)
  1667. {
  1668. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
  1669. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1670. eptr--;
  1671. }
  1672. }
  1673. RRETURN(MATCH_NOMATCH);
  1674. }
  1675. }
  1676. /* Control never gets here */
  1677. /* Match an extended character class. This opcode is encountered only
  1678. in UTF-8 mode, because that's the only time it is compiled. */
  1679. #ifdef SUPPORT_UTF8
  1680. case OP_XCLASS:
  1681. {
  1682. data = ecode + 1 + LINK_SIZE; /* Save for matching */
  1683. ecode += GET(ecode, 1); /* Advance past the item */
  1684. switch (*ecode)
  1685. {
  1686. case OP_CRSTAR:
  1687. case OP_CRMINSTAR:
  1688. case OP_CRPLUS:
  1689. case OP_CRMINPLUS:
  1690. case OP_CRQUERY:
  1691. case OP_CRMINQUERY:
  1692. c = *ecode++ - OP_CRSTAR;
  1693. minimize = (c & 1) != 0;
  1694. min = rep_min[c]; /* Pick up values from tables; */
  1695. max = rep_max[c]; /* zero for max => infinity */
  1696. if (max == 0) max = INT_MAX;
  1697. break;
  1698. case OP_CRRANGE:
  1699. case OP_CRMINRANGE:
  1700. minimize = (*ecode == OP_CRMINRANGE);
  1701. min = GET2(ecode, 1);
  1702. max = GET2(ecode, 3);
  1703. if (max == 0) max = INT_MAX;
  1704. ecode += 5;
  1705. break;
  1706. default: /* No repeat follows */
  1707. min = max = 1;
  1708. break;
  1709. }
  1710. /* First, ensure the minimum number of matches are present. */
  1711. for (i = 1; i <= min; i++)
  1712. {
  1713. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1714. GETCHARINC(c, eptr);
  1715. if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
  1716. }
  1717. /* If max == min we can continue with the main loop without the
  1718. need to recurse. */
  1719. if (min == max) continue;
  1720. /* If minimizing, keep testing the rest of the expression and advancing
  1721. the pointer while it matches the class. */
  1722. if (minimize)
  1723. {
  1724. for (fi = min;; fi++)
  1725. {
  1726. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
  1727. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1728. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1729. GETCHARINC(c, eptr);
  1730. if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
  1731. }
  1732. /* Control never gets here */
  1733. }
  1734. /* If maximizing, find the longest possible run, then work backwards. */
  1735. else
  1736. {
  1737. pp = eptr;
  1738. for (i = min; i < max; i++)
  1739. {
  1740. int len = 1;
  1741. if (eptr >= md->end_subject) break;
  1742. GETCHARLEN(c, eptr, len);
  1743. if (!_pcre_xclass(c, data)) break;
  1744. eptr += len;
  1745. }
  1746. for(;;)
  1747. {
  1748. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
  1749. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1750. if (eptr-- == pp) break; /* Stop if tried at original pos */
  1751. if (utf8) BACKCHAR(eptr);
  1752. }
  1753. RRETURN(MATCH_NOMATCH);
  1754. }
  1755. /* Control never gets here */
  1756. }
  1757. #endif /* End of XCLASS */
  1758. /* Match a single character, casefully */
  1759. case OP_CHAR:
  1760. #ifdef SUPPORT_UTF8
  1761. if (utf8)
  1762. {
  1763. length = 1;
  1764. ecode++;
  1765. GETCHARLEN(fc, ecode, length);
  1766. if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  1767. while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
  1768. }
  1769. else
  1770. #endif
  1771. /* Non-UTF-8 mode */
  1772. {
  1773. if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);
  1774. if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
  1775. ecode += 2;
  1776. }
  1777. break;
  1778. /* Match a single character, caselessly */
  1779. case OP_CHARNC:
  1780. #ifdef SUPPORT_UTF8
  1781. if (utf8)
  1782. {
  1783. length = 1;
  1784. ecode++;
  1785. GETCHARLEN(fc, ecode, length);
  1786. if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  1787. /* If the pattern character's value is < 128, we have only one byte, and
  1788. can use the fast lookup table. */
  1789. if (fc < 128)
  1790. {
  1791. if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  1792. }
  1793. /* Otherwise we must pick up the subject character */
  1794. else
  1795. {
  1796. unsigned int dc;
  1797. GETCHARINC(dc, eptr);
  1798. ecode += length;
  1799. /* If we have Unicode property support, we can use it to test the other
  1800. case of the character, if there is one. */
  1801. if (fc != dc)
  1802. {
  1803. #ifdef SUPPORT_UCP
  1804. if (dc != _pcre_ucp_othercase(fc))
  1805. #endif
  1806. RRETURN(MATCH_NOMATCH);
  1807. }
  1808. }
  1809. }
  1810. else
  1811. #endif /* SUPPORT_UTF8 */
  1812. /* Non-UTF-8 mode */
  1813. {
  1814. if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);
  1815. if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  1816. ecode += 2;
  1817. }
  1818. break;
  1819. /* Match a single character repeatedly. */
  1820. case OP_EXACT:
  1821. min = max = GET2(ecode, 1);
  1822. ecode += 3;
  1823. goto REPEATCHAR;
  1824. case OP_POSUPTO:
  1825. possessive = TRUE;
  1826. /* Fall through */
  1827. case OP_UPTO:
  1828. case OP_MINUPTO:
  1829. min = 0;
  1830. max = GET2(ecode, 1);
  1831. minimize = *ecode == OP_MINUPTO;
  1832. ecode += 3;
  1833. goto REPEATCHAR;
  1834. case OP_POSSTAR:
  1835. possessive = TRUE;
  1836. min = 0;
  1837. max = INT_MAX;
  1838. ecode++;
  1839. goto REPEATCHAR;
  1840. case OP_POSPLUS:
  1841. possessive = TRUE;
  1842. min = 1;
  1843. max = INT_MAX;
  1844. ecode++;
  1845. goto REPEATCHAR;
  1846. case OP_POSQUERY:
  1847. possessive = TRUE;
  1848. min = 0;
  1849. max = 1;
  1850. ecode++;
  1851. goto REPEATCHAR;
  1852. case OP_STAR:
  1853. case OP_MINSTAR:
  1854. case OP_PLUS:
  1855. case OP_MINPLUS:
  1856. case OP_QUERY:
  1857. case OP_MINQUERY:
  1858. c = *ecode++ - OP_STAR;
  1859. minimize = (c & 1) != 0;
  1860. min = rep_min[c]; /* Pick up values from tables; */
  1861. max = rep_max[c]; /* zero for max => infinity */
  1862. if (max == 0) max = INT_MAX;
  1863. /* Common code for all repeated single-character matches. We can give
  1864. up quickly if there are fewer than the minimum number of characters left in
  1865. the subject. */
  1866. REPEATCHAR:
  1867. #ifdef SUPPORT_UTF8
  1868. if (utf8)
  1869. {
  1870. length = 1;
  1871. charptr = ecode;
  1872. GETCHARLEN(fc, ecode, length);
  1873. if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  1874. ecode += length;
  1875. /* Handle multibyte character matching specially here. There is
  1876. support for caseless matching if UCP support is present. */
  1877. if (length > 1)
  1878. {
  1879. #ifdef SUPPORT_UCP
  1880. unsigned int othercase;
  1881. if ((ims & PCRE_CASELESS) != 0 &&
  1882. (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)
  1883. oclength = _pcre_ord2utf8(othercase, occhars);
  1884. else oclength = 0;
  1885. #endif /* SUPPORT_UCP */
  1886. for (i = 1; i <= min; i++)
  1887. {
  1888. if (memcmp(eptr, charptr, length) == 0) eptr += length;
  1889. #ifdef SUPPORT_UCP
  1890. /* Need braces because of following else */
  1891. else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
  1892. else
  1893. {
  1894. if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
  1895. eptr += oclength;
  1896. }
  1897. #else /* without SUPPORT_UCP */
  1898. else { RRETURN(MATCH_NOMATCH); }
  1899. #endif /* SUPPORT_UCP */
  1900. }
  1901. if (min == max) continue;
  1902. if (minimize)
  1903. {
  1904. for (fi = min;; fi++)
  1905. {
  1906. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
  1907. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1908. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1909. if (memcmp(eptr, charptr, length) == 0) eptr += length;
  1910. #ifdef SUPPORT_UCP
  1911. /* Need braces because of following else */
  1912. else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
  1913. else
  1914. {
  1915. if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
  1916. eptr += oclength;
  1917. }
  1918. #else /* without SUPPORT_UCP */
  1919. else { RRETURN (MATCH_NOMATCH); }
  1920. #endif /* SUPPORT_UCP */
  1921. }
  1922. /* Control never gets here */
  1923. }
  1924. else /* Maximize */
  1925. {
  1926. pp = eptr;
  1927. for (i = min; i < max; i++)
  1928. {
  1929. if (eptr > md->end_subject - length) break;
  1930. if (memcmp(eptr, charptr, length) == 0) eptr += length;
  1931. #ifdef SUPPORT_UCP
  1932. else if (oclength == 0) break;
  1933. else
  1934. {
  1935. if (memcmp(eptr, occhars, oclength) != 0) break;
  1936. eptr += oclength;
  1937. }
  1938. #else /* without SUPPORT_UCP */
  1939. else break;
  1940. #endif /* SUPPORT_UCP */
  1941. }
  1942. if (possessive) continue;
  1943. for(;;)
  1944. {
  1945. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
  1946. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1947. if (eptr == pp) RRETURN(MATCH_NOMATCH);
  1948. #ifdef SUPPORT_UCP
  1949. eptr--;
  1950. BACKCHAR(eptr);
  1951. #else /* without SUPPORT_UCP */
  1952. eptr -= length;
  1953. #endif /* SUPPORT_UCP */
  1954. }
  1955. }
  1956. /* Control never gets here */
  1957. }
  1958. /* If the length of a UTF-8 character is 1, we fall through here, and
  1959. obey the code as for non-UTF-8 characters below, though in this case the
  1960. value of fc will always be < 128. */
  1961. }
  1962. else
  1963. #endif /* SUPPORT_UTF8 */
  1964. /* When not in UTF-8 mode, load a single-byte character. */
  1965. {
  1966. if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  1967. fc = *ecode++;
  1968. }
  1969. /* The value of fc at this point is always less than 256, though we may or
  1970. may not be in UTF-8 mode. The code is duplicated for the caseless and
  1971. caseful cases, for speed, since matching characters is likely to be quite
  1972. common. First, ensure the minimum number of matches are present. If min =
  1973. max, continue at the same level without recursing. Otherwise, if
  1974. minimizing, keep trying the rest of the expression and advancing one
  1975. matching character if failing, up to the maximum. Alternatively, if
  1976. maximizing, find the maximum number of characters and work backwards. */
  1977. DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
  1978. max, eptr));
  1979. if ((ims & PCRE_CASELESS) != 0)
  1980. {
  1981. fc = md->lcc[fc];
  1982. for (i = 1; i <= min; i++)
  1983. if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  1984. if (min == max) continue;
  1985. if (minimize)
  1986. {
  1987. for (fi = min;; fi++)
  1988. {
  1989. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
  1990. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1991. if (fi >= max || eptr >= md->end_subject ||
  1992. fc != md->lcc[*eptr++])
  1993. RRETURN(MATCH_NOMATCH);
  1994. }
  1995. /* Control never gets here */
  1996. }
  1997. else /* Maximize */
  1998. {
  1999. pp = eptr;
  2000. for (i = min; i < max; i++)
  2001. {
  2002. if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
  2003. eptr++;
  2004. }
  2005. if (possessive) continue;
  2006. while (eptr >= pp)
  2007. {
  2008. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
  2009. eptr--;
  2010. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2011. }
  2012. RRETURN(MATCH_NOMATCH);
  2013. }
  2014. /* Control never gets here */
  2015. }
  2016. /* Caseful comparisons (includes all multi-byte characters) */
  2017. else
  2018. {
  2019. for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
  2020. if (min == max) continue;
  2021. if (minimize)
  2022. {
  2023. for (fi = min;; fi++)
  2024. {
  2025. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
  2026. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2027. if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
  2028. RRETURN(MATCH_NOMATCH);
  2029. }
  2030. /* Control never gets here */
  2031. }
  2032. else /* Maximize */
  2033. {
  2034. pp = eptr;
  2035. for (i = min; i < max; i++)
  2036. {
  2037. if (eptr >= md->end_subject || fc != *eptr) break;
  2038. eptr++;
  2039. }
  2040. if (possessive) continue;
  2041. while (eptr >= pp)
  2042. {
  2043. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
  2044. eptr--;
  2045. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2046. }
  2047. RRETURN(MATCH_NOMATCH);
  2048. }
  2049. }
  2050. /* Control never gets here */
  2051. /* Match a negated single one-byte character. The character we are
  2052. checking can be multibyte. */
  2053. case OP_NOT:
  2054. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2055. ecode++;
  2056. GETCHARINCTEST(c, eptr);
  2057. if ((ims & PCRE_CASELESS) != 0)
  2058. {
  2059. #ifdef SUPPORT_UTF8
  2060. if (c < 256)
  2061. #endif
  2062. c = md->lcc[c];
  2063. if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);
  2064. }
  2065. else
  2066. {
  2067. if (*ecode++ == c) RRETURN(MATCH_NOMATCH);
  2068. }
  2069. break;
  2070. /* Match a negated single one-byte character repeatedly. This is almost a
  2071. repeat of the code for a repeated single character, but I haven't found a
  2072. nice way of commoning these up that doesn't require a test of the
  2073. positive/negative option for each character match. Maybe that wouldn't add
  2074. very much to the time taken, but character matching *is* what this is all
  2075. about... */
  2076. case OP_NOTEXACT:
  2077. min = max = GET2(ecode, 1);
  2078. ecode += 3;
  2079. goto REPEATNOTCHAR;
  2080. case OP_NOTUPTO:
  2081. case OP_NOTMINUPTO:
  2082. min = 0;
  2083. max = GET2(ecode, 1);
  2084. minimize = *ecode == OP_NOTMINUPTO;
  2085. ecode += 3;
  2086. goto REPEATNOTCHAR;
  2087. case OP_NOTPOSSTAR:
  2088. possessive = TRUE;
  2089. min = 0;
  2090. max = INT_MAX;
  2091. ecode++;
  2092. goto REPEATNOTCHAR;
  2093. case OP_NOTPOSPLUS:
  2094. possessive = TRUE;
  2095. min = 1;
  2096. max = INT_MAX;
  2097. ecode++;
  2098. goto REPEATNOTCHAR;
  2099. case OP_NOTPOSQUERY:
  2100. possessive = TRUE;
  2101. min = 0;
  2102. max = 1;
  2103. ecode++;
  2104. goto REPEATNOTCHAR;
  2105. case OP_NOTPOSUPTO:
  2106. possessive = TRUE;
  2107. min = 0;
  2108. max = GET2(ecode, 1);
  2109. ecode += 3;
  2110. goto REPEATNOTCHAR;
  2111. case OP_NOTSTAR:
  2112. case OP_NOTMINSTAR:
  2113. case OP_NOTPLUS:
  2114. case OP_NOTMINPLUS:
  2115. case OP_NOTQUERY:
  2116. case OP_NOTMINQUERY:
  2117. c = *ecode++ - OP_NOTSTAR;
  2118. minimize = (c & 1) != 0;
  2119. min = rep_min[c]; /* Pick up values from tables; */
  2120. max = rep_max[c]; /* zero for max => infinity */
  2121. if (max == 0) max = INT_MAX;
  2122. /* Common code for all repeated single-byte matches. We can give up quickly
  2123. if there are fewer than the minimum number of bytes left in the
  2124. subject. */
  2125. REPEATNOTCHAR:
  2126. if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2127. fc = *ecode++;
  2128. /* The code is duplicated for the caseless and caseful cases, for speed,
  2129. since matching characters is likely to be quite common. First, ensure the
  2130. minimum number of matches are present. If min = max, continue at the same
  2131. level without recursing. Otherwise, if minimizing, keep trying the rest of
  2132. the expression and advancing one matching character if failing, up to the
  2133. maximum. Alternatively, if maximizing, find the maximum number of
  2134. characters and work backwards. */
  2135. DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max,
  2136. max, eptr));
  2137. if ((ims & PCRE_CASELESS) != 0)
  2138. {
  2139. fc = md->lcc[fc];
  2140. #ifdef SUPPORT_UTF8
  2141. /* UTF-8 mode */
  2142. if (utf8)
  2143. {
  2144. register unsigned int d;
  2145. for (i = 1; i <= min; i++)
  2146. {
  2147. GETCHARINC(d, eptr);
  2148. if (d < 256) d = md->lcc[d];
  2149. if (fc == d) RRETURN(MATCH_NOMATCH);
  2150. }
  2151. }
  2152. else
  2153. #endif
  2154. /* Not UTF-8 mode */
  2155. {
  2156. for (i = 1; i <= min; i++)
  2157. if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  2158. }
  2159. if (min == max) continue;
  2160. if (minimize)
  2161. {
  2162. #ifdef SUPPORT_UTF8
  2163. /* UTF-8 mode */
  2164. if (utf8)
  2165. {
  2166. register unsigned int d;
  2167. for (fi = min;; fi++)
  2168. {
  2169. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
  2170. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2171. GETCHARINC(d, eptr);
  2172. if (d < 256) d = md->lcc[d];
  2173. if (fi >= max || eptr >= md->end_subject || fc == d)
  2174. RRETURN(MATCH_NOMATCH);
  2175. }
  2176. }
  2177. else
  2178. #endif
  2179. /* Not UTF-8 mode */
  2180. {
  2181. for (fi = min;; fi++)
  2182. {
  2183. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
  2184. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2185. if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
  2186. RRETURN(MATCH_NOMATCH);
  2187. }
  2188. }
  2189. /* Control never gets here */
  2190. }
  2191. /* Maximize case */
  2192. else
  2193. {
  2194. pp = eptr;
  2195. #ifdef SUPPORT_UTF8
  2196. /* UTF-8 mode */
  2197. if (utf8)
  2198. {
  2199. register unsigned int d;
  2200. for (i = min; i < max; i++)
  2201. {
  2202. int len = 1;
  2203. if (eptr >= md->end_subject) break;
  2204. GETCHARLEN(d, eptr, len);
  2205. if (d < 256) d = md->lcc[d];
  2206. if (fc == d) break;
  2207. eptr += len;
  2208. }
  2209. if (possessive) continue;
  2210. for(;;)
  2211. {
  2212. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
  2213. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2214. if (eptr-- == pp) break; /* Stop if tried at original pos */
  2215. BACKCHAR(eptr);
  2216. }
  2217. }
  2218. else
  2219. #endif
  2220. /* Not UTF-8 mode */
  2221. {
  2222. for (i = min; i < max; i++)
  2223. {
  2224. if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
  2225. eptr++;
  2226. }
  2227. if (possessive) continue;
  2228. while (eptr >= pp)
  2229. {
  2230. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
  2231. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2232. eptr--;
  2233. }
  2234. }
  2235. RRETURN(MATCH_NOMATCH);
  2236. }
  2237. /* Control never gets here */
  2238. }
  2239. /* Caseful comparisons */
  2240. else
  2241. {
  2242. #ifdef SUPPORT_UTF8
  2243. /* UTF-8 mode */
  2244. if (utf8)
  2245. {
  2246. register unsigned int d;
  2247. for (i = 1; i <= min; i++)
  2248. {
  2249. GETCHARINC(d, eptr);
  2250. if (fc == d) RRETURN(MATCH_NOMATCH);
  2251. }
  2252. }
  2253. else
  2254. #endif
  2255. /* Not UTF-8 mode */
  2256. {
  2257. for (i = 1; i <= min; i++)
  2258. if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
  2259. }
  2260. if (min == max) continue;
  2261. if (minimize)
  2262. {
  2263. #ifdef SUPPORT_UTF8
  2264. /* UTF-8 mode */
  2265. if (utf8)
  2266. {
  2267. register unsigned int d;
  2268. for (fi = min;; fi++)
  2269. {
  2270. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
  2271. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2272. GETCHARINC(d, eptr);
  2273. if (fi >= max || eptr >= md->end_subject || fc == d)
  2274. RRETURN(MATCH_NOMATCH);
  2275. }
  2276. }
  2277. else
  2278. #endif
  2279. /* Not UTF-8 mode */
  2280. {
  2281. for (fi = min;; fi++)
  2282. {
  2283. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
  2284. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2285. if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
  2286. RRETURN(MATCH_NOMATCH);
  2287. }
  2288. }
  2289. /* Control never gets here */
  2290. }
  2291. /* Maximize case */
  2292. else
  2293. {
  2294. pp = eptr;
  2295. #ifdef SUPPORT_UTF8
  2296. /* UTF-8 mode */
  2297. if (utf8)
  2298. {
  2299. register unsigned int d;
  2300. for (i = min; i < max; i++)
  2301. {
  2302. int len = 1;
  2303. if (eptr >= md->end_subject) break;
  2304. GETCHARLEN(d, eptr, len);
  2305. if (fc == d) break;
  2306. eptr += len;
  2307. }
  2308. if (possessive) continue;
  2309. for(;;)
  2310. {
  2311. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
  2312. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2313. if (eptr-- == pp) break; /* Stop if tried at original pos */
  2314. BACKCHAR(eptr);
  2315. }
  2316. }
  2317. else
  2318. #endif
  2319. /* Not UTF-8 mode */
  2320. {
  2321. for (i = min; i < max; i++)
  2322. {
  2323. if (eptr >= md->end_subject || fc == *eptr) break;
  2324. eptr++;
  2325. }
  2326. if (possessive) continue;
  2327. while (eptr >= pp)
  2328. {
  2329. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
  2330. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2331. eptr--;
  2332. }
  2333. }
  2334. RRETURN(MATCH_NOMATCH);
  2335. }
  2336. }
  2337. /* Control never gets here */
  2338. /* Match a single character type repeatedly; several different opcodes
  2339. share code. This is very similar to the code for single characters, but we
  2340. repeat it in the interests of efficiency. */
  2341. case OP_TYPEEXACT:
  2342. min = max = GET2(ecode, 1);
  2343. minimize = TRUE;
  2344. ecode += 3;
  2345. goto REPEATTYPE;
  2346. case OP_TYPEUPTO:
  2347. case OP_TYPEMINUPTO:
  2348. min = 0;
  2349. max = GET2(ecode, 1);
  2350. minimize = *ecode == OP_TYPEMINUPTO;
  2351. ecode += 3;
  2352. goto REPEATTYPE;
  2353. case OP_TYPEPOSSTAR:
  2354. possessive = TRUE;
  2355. min = 0;
  2356. max = INT_MAX;
  2357. ecode++;
  2358. goto REPEATTYPE;
  2359. case OP_TYPEPOSPLUS:
  2360. possessive = TRUE;
  2361. min = 1;
  2362. max = INT_MAX;
  2363. ecode++;
  2364. goto REPEATTYPE;
  2365. case OP_TYPEPOSQUERY:
  2366. possessive = TRUE;
  2367. min = 0;
  2368. max = 1;
  2369. ecode++;
  2370. goto REPEATTYPE;
  2371. case OP_TYPEPOSUPTO:
  2372. possessive = TRUE;
  2373. min = 0;
  2374. max = GET2(ecode, 1);
  2375. ecode += 3;
  2376. goto REPEATTYPE;
  2377. case OP_TYPESTAR:
  2378. case OP_TYPEMINSTAR:
  2379. case OP_TYPEPLUS:
  2380. case OP_TYPEMINPLUS:
  2381. case OP_TYPEQUERY:
  2382. case OP_TYPEMINQUERY:
  2383. c = *ecode++ - OP_TYPESTAR;
  2384. minimize = (c & 1) != 0;
  2385. min = rep_min[c]; /* Pick up values from tables; */
  2386. max = rep_max[c]; /* zero for max => infinity */
  2387. if (max == 0) max = INT_MAX;
  2388. /* Common code for all repeated single character type matches. Note that
  2389. in UTF-8 mode, '.' matches a character of any length, but for the other
  2390. character types, the valid characters are all one-byte long. */
  2391. REPEATTYPE:
  2392. ctype = *ecode++; /* Code for the character type */
  2393. #ifdef SUPPORT_UCP
  2394. if (ctype == OP_PROP || ctype == OP_NOTPROP)
  2395. {
  2396. prop_fail_result = ctype == OP_NOTPROP;
  2397. prop_type = *ecode++;
  2398. prop_value = *ecode++;
  2399. }
  2400. else prop_type = -1;
  2401. #endif
  2402. /* First, ensure the minimum number of matches are present. Use inline
  2403. code for maximizing the speed, and do the type test once at the start
  2404. (i.e. keep it out of the loop). Also we can test that there are at least
  2405. the minimum number of bytes before we start. This isn't as effective in
  2406. UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that
  2407. is tidier. Also separate the UCP code, which can be the same for both UTF-8
  2408. and single-bytes. */
  2409. if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2410. if (min > 0)
  2411. {
  2412. #ifdef SUPPORT_UCP
  2413. if (prop_type >= 0)
  2414. {
  2415. switch(prop_type)
  2416. {
  2417. case PT_ANY:
  2418. if (prop_fail_result) RRETURN(MATCH_NOMATCH);
  2419. for (i = 1; i <= min; i++)
  2420. {
  2421. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2422. GETCHARINCTEST(c, eptr);
  2423. }
  2424. break;
  2425. case PT_LAMP:
  2426. for (i = 1; i <= min; i++)
  2427. {
  2428. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2429. GETCHARINCTEST(c, eptr);
  2430. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2431. if ((prop_chartype == ucp_Lu ||
  2432. prop_chartype == ucp_Ll ||
  2433. prop_chartype == ucp_Lt) == prop_fail_result)
  2434. RRETURN(MATCH_NOMATCH);
  2435. }
  2436. break;
  2437. case PT_GC:
  2438. for (i = 1; i <= min; i++)
  2439. {
  2440. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2441. GETCHARINCTEST(c, eptr);
  2442. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2443. if ((prop_category == prop_value) == prop_fail_result)
  2444. RRETURN(MATCH_NOMATCH);
  2445. }
  2446. break;
  2447. case PT_PC:
  2448. for (i = 1; i <= min; i++)
  2449. {
  2450. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2451. GETCHARINCTEST(c, eptr);
  2452. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2453. if ((prop_chartype == prop_value) == prop_fail_result)
  2454. RRETURN(MATCH_NOMATCH);
  2455. }
  2456. break;
  2457. case PT_SC:
  2458. for (i = 1; i <= min; i++)
  2459. {
  2460. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2461. GETCHARINCTEST(c, eptr);
  2462. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2463. if ((prop_script == prop_value) == prop_fail_result)
  2464. RRETURN(MATCH_NOMATCH);
  2465. }
  2466. break;
  2467. default:
  2468. RRETURN(PCRE_ERROR_INTERNAL);
  2469. }
  2470. }
  2471. /* Match extended Unicode sequences. We will get here only if the
  2472. support is in the binary; otherwise a compile-time error occurs. */
  2473. else if (ctype == OP_EXTUNI)
  2474. {
  2475. for (i = 1; i <= min; i++)
  2476. {
  2477. GETCHARINCTEST(c, eptr);
  2478. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2479. if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
  2480. while (eptr < md->end_subject)
  2481. {
  2482. int len = 1;
  2483. if (!utf8) c = *eptr; else
  2484. {
  2485. GETCHARLEN(c, eptr, len);
  2486. }
  2487. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2488. if (prop_category != ucp_M) break;
  2489. eptr += len;
  2490. }
  2491. }
  2492. }
  2493. else
  2494. #endif /* SUPPORT_UCP */
  2495. /* Handle all other cases when the coding is UTF-8 */
  2496. #ifdef SUPPORT_UTF8
  2497. if (utf8) switch(ctype)
  2498. {
  2499. case OP_ANY:
  2500. for (i = 1; i <= min; i++)
  2501. {
  2502. if (eptr >= md->end_subject ||
  2503. ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
  2504. RRETURN(MATCH_NOMATCH);
  2505. eptr++;
  2506. while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  2507. }
  2508. break;
  2509. case OP_ANYBYTE:
  2510. eptr += min;
  2511. break;
  2512. case OP_ANYNL:
  2513. for (i = 1; i <= min; i++)
  2514. {
  2515. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2516. GETCHARINC(c, eptr);
  2517. switch(c)
  2518. {
  2519. default: RRETURN(MATCH_NOMATCH);
  2520. case 0x000d:
  2521. if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  2522. break;
  2523. case 0x000a:
  2524. break;
  2525. case 0x000b:
  2526. case 0x000c:
  2527. case 0x0085:
  2528. case 0x2028:
  2529. case 0x2029:
  2530. if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  2531. break;
  2532. }
  2533. }
  2534. break;
  2535. case OP_NOT_HSPACE:
  2536. for (i = 1; i <= min; i++)
  2537. {
  2538. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2539. GETCHARINC(c, eptr);
  2540. switch(c)
  2541. {
  2542. default: break;
  2543. case 0x09: /* HT */
  2544. case 0x20: /* SPACE */
  2545. case 0xa0: /* NBSP */
  2546. case 0x1680: /* OGHAM SPACE MARK */
  2547. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  2548. case 0x2000: /* EN QUAD */
  2549. case 0x2001: /* EM QUAD */
  2550. case 0x2002: /* EN SPACE */
  2551. case 0x2003: /* EM SPACE */
  2552. case 0x2004: /* THREE-PER-EM SPACE */
  2553. case 0x2005: /* FOUR-PER-EM SPACE */
  2554. case 0x2006: /* SIX-PER-EM SPACE */
  2555. case 0x2007: /* FIGURE SPACE */
  2556. case 0x2008: /* PUNCTUATION SPACE */
  2557. case 0x2009: /* THIN SPACE */
  2558. case 0x200A: /* HAIR SPACE */
  2559. case 0x202f: /* NARROW NO-BREAK SPACE */
  2560. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  2561. case 0x3000: /* IDEOGRAPHIC SPACE */
  2562. RRETURN(MATCH_NOMATCH);
  2563. }
  2564. }
  2565. break;
  2566. case OP_HSPACE:
  2567. for (i = 1; i <= min; i++)
  2568. {
  2569. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2570. GETCHARINC(c, eptr);
  2571. switch(c)
  2572. {
  2573. default: RRETURN(MATCH_NOMATCH);
  2574. case 0x09: /* HT */
  2575. case 0x20: /* SPACE */
  2576. case 0xa0: /* NBSP */
  2577. case 0x1680: /* OGHAM SPACE MARK */
  2578. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  2579. case 0x2000: /* EN QUAD */
  2580. case 0x2001: /* EM QUAD */
  2581. case 0x2002: /* EN SPACE */
  2582. case 0x2003: /* EM SPACE */
  2583. case 0x2004: /* THREE-PER-EM SPACE */
  2584. case 0x2005: /* FOUR-PER-EM SPACE */
  2585. case 0x2006: /* SIX-PER-EM SPACE */
  2586. case 0x2007: /* FIGURE SPACE */
  2587. case 0x2008: /* PUNCTUATION SPACE */
  2588. case 0x2009: /* THIN SPACE */
  2589. case 0x200A: /* HAIR SPACE */
  2590. case 0x202f: /* NARROW NO-BREAK SPACE */
  2591. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  2592. case 0x3000: /* IDEOGRAPHIC SPACE */
  2593. break;
  2594. }
  2595. }
  2596. break;
  2597. case OP_NOT_VSPACE:
  2598. for (i = 1; i <= min; i++)
  2599. {
  2600. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2601. GETCHARINC(c, eptr);
  2602. switch(c)
  2603. {
  2604. default: break;
  2605. case 0x0a: /* LF */
  2606. case 0x0b: /* VT */
  2607. case 0x0c: /* FF */
  2608. case 0x0d: /* CR */
  2609. case 0x85: /* NEL */
  2610. case 0x2028: /* LINE SEPARATOR */
  2611. case 0x2029: /* PARAGRAPH SEPARATOR */
  2612. RRETURN(MATCH_NOMATCH);
  2613. }
  2614. }
  2615. break;
  2616. case OP_VSPACE:
  2617. for (i = 1; i <= min; i++)
  2618. {
  2619. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2620. GETCHARINC(c, eptr);
  2621. switch(c)
  2622. {
  2623. default: RRETURN(MATCH_NOMATCH);
  2624. case 0x0a: /* LF */
  2625. case 0x0b: /* VT */
  2626. case 0x0c: /* FF */
  2627. case 0x0d: /* CR */
  2628. case 0x85: /* NEL */
  2629. case 0x2028: /* LINE SEPARATOR */
  2630. case 0x2029: /* PARAGRAPH SEPARATOR */
  2631. break;
  2632. }
  2633. }
  2634. break;
  2635. case OP_NOT_DIGIT:
  2636. for (i = 1; i <= min; i++)
  2637. {
  2638. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2639. GETCHARINC(c, eptr);
  2640. if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
  2641. RRETURN(MATCH_NOMATCH);
  2642. }
  2643. break;
  2644. case OP_DIGIT:
  2645. for (i = 1; i <= min; i++)
  2646. {
  2647. if (eptr >= md->end_subject ||
  2648. *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
  2649. RRETURN(MATCH_NOMATCH);
  2650. /* No need to skip more bytes - we know it's a 1-byte character */
  2651. }
  2652. break;
  2653. case OP_NOT_WHITESPACE:
  2654. for (i = 1; i <= min; i++)
  2655. {
  2656. if (eptr >= md->end_subject ||
  2657. (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
  2658. RRETURN(MATCH_NOMATCH);
  2659. while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
  2660. }
  2661. break;
  2662. case OP_WHITESPACE:
  2663. for (i = 1; i <= min; i++)
  2664. {
  2665. if (eptr >= md->end_subject ||
  2666. *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
  2667. RRETURN(MATCH_NOMATCH);
  2668. /* No need to skip more bytes - we know it's a 1-byte character */
  2669. }
  2670. break;
  2671. case OP_NOT_WORDCHAR:
  2672. for (i = 1; i <= min; i++)
  2673. {
  2674. if (eptr >= md->end_subject ||
  2675. (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
  2676. RRETURN(MATCH_NOMATCH);
  2677. while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
  2678. }
  2679. break;
  2680. case OP_WORDCHAR:
  2681. for (i = 1; i <= min; i++)
  2682. {
  2683. if (eptr >= md->end_subject ||
  2684. *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
  2685. RRETURN(MATCH_NOMATCH);
  2686. /* No need to skip more bytes - we know it's a 1-byte character */
  2687. }
  2688. break;
  2689. default:
  2690. RRETURN(PCRE_ERROR_INTERNAL);
  2691. } /* End switch(ctype) */
  2692. else
  2693. #endif /* SUPPORT_UTF8 */
  2694. /* Code for the non-UTF-8 case for minimum matching of operators other
  2695. than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
  2696. number of bytes present, as this was tested above. */
  2697. switch(ctype)
  2698. {
  2699. case OP_ANY:
  2700. if ((ims & PCRE_DOTALL) == 0)
  2701. {
  2702. for (i = 1; i <= min; i++)
  2703. {
  2704. if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
  2705. eptr++;
  2706. }
  2707. }
  2708. else eptr += min;
  2709. break;
  2710. case OP_ANYBYTE:
  2711. eptr += min;
  2712. break;
  2713. /* Because of the CRLF case, we can't assume the minimum number of
  2714. bytes are present in this case. */
  2715. case OP_ANYNL:
  2716. for (i = 1; i <= min; i++)
  2717. {
  2718. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2719. switch(*eptr++)
  2720. {
  2721. default: RRETURN(MATCH_NOMATCH);
  2722. case 0x000d:
  2723. if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  2724. break;
  2725. case 0x000a:
  2726. break;
  2727. case 0x000b:
  2728. case 0x000c:
  2729. case 0x0085:
  2730. if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  2731. break;
  2732. }
  2733. }
  2734. break;
  2735. case OP_NOT_HSPACE:
  2736. for (i = 1; i <= min; i++)
  2737. {
  2738. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2739. switch(*eptr++)
  2740. {
  2741. default: break;
  2742. case 0x09: /* HT */
  2743. case 0x20: /* SPACE */
  2744. case 0xa0: /* NBSP */
  2745. RRETURN(MATCH_NOMATCH);
  2746. }
  2747. }
  2748. break;
  2749. case OP_HSPACE:
  2750. for (i = 1; i <= min; i++)
  2751. {
  2752. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2753. switch(*eptr++)
  2754. {
  2755. default: RRETURN(MATCH_NOMATCH);
  2756. case 0x09: /* HT */
  2757. case 0x20: /* SPACE */
  2758. case 0xa0: /* NBSP */
  2759. break;
  2760. }
  2761. }
  2762. break;
  2763. case OP_NOT_VSPACE:
  2764. for (i = 1; i <= min; i++)
  2765. {
  2766. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2767. switch(*eptr++)
  2768. {
  2769. default: break;
  2770. case 0x0a: /* LF */
  2771. case 0x0b: /* VT */
  2772. case 0x0c: /* FF */
  2773. case 0x0d: /* CR */
  2774. case 0x85: /* NEL */
  2775. RRETURN(MATCH_NOMATCH);
  2776. }
  2777. }
  2778. break;
  2779. case OP_VSPACE:
  2780. for (i = 1; i <= min; i++)
  2781. {
  2782. if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2783. switch(*eptr++)
  2784. {
  2785. default: RRETURN(MATCH_NOMATCH);
  2786. case 0x0a: /* LF */
  2787. case 0x0b: /* VT */
  2788. case 0x0c: /* FF */
  2789. case 0x0d: /* CR */
  2790. case 0x85: /* NEL */
  2791. break;
  2792. }
  2793. }
  2794. break;
  2795. case OP_NOT_DIGIT:
  2796. for (i = 1; i <= min; i++)
  2797. if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
  2798. break;
  2799. case OP_DIGIT:
  2800. for (i = 1; i <= min; i++)
  2801. if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
  2802. break;
  2803. case OP_NOT_WHITESPACE:
  2804. for (i = 1; i <= min; i++)
  2805. if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
  2806. break;
  2807. case OP_WHITESPACE:
  2808. for (i = 1; i <= min; i++)
  2809. if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
  2810. break;
  2811. case OP_NOT_WORDCHAR:
  2812. for (i = 1; i <= min; i++)
  2813. if ((md->ctypes[*eptr++] & ctype_word) != 0)
  2814. RRETURN(MATCH_NOMATCH);
  2815. break;
  2816. case OP_WORDCHAR:
  2817. for (i = 1; i <= min; i++)
  2818. if ((md->ctypes[*eptr++] & ctype_word) == 0)
  2819. RRETURN(MATCH_NOMATCH);
  2820. break;
  2821. default:
  2822. RRETURN(PCRE_ERROR_INTERNAL);
  2823. }
  2824. }
  2825. /* If min = max, continue at the same level without recursing */
  2826. if (min == max) continue;
  2827. /* If minimizing, we have to test the rest of the pattern before each
  2828. subsequent match. Again, separate the UTF-8 case for speed, and also
  2829. separate the UCP cases. */
  2830. if (minimize)
  2831. {
  2832. #ifdef SUPPORT_UCP
  2833. if (prop_type >= 0)
  2834. {
  2835. switch(prop_type)
  2836. {
  2837. case PT_ANY:
  2838. for (fi = min;; fi++)
  2839. {
  2840. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
  2841. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2842. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2843. GETCHARINC(c, eptr);
  2844. if (prop_fail_result) RRETURN(MATCH_NOMATCH);
  2845. }
  2846. /* Control never gets here */
  2847. case PT_LAMP:
  2848. for (fi = min;; fi++)
  2849. {
  2850. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
  2851. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2852. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2853. GETCHARINC(c, eptr);
  2854. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2855. if ((prop_chartype == ucp_Lu ||
  2856. prop_chartype == ucp_Ll ||
  2857. prop_chartype == ucp_Lt) == prop_fail_result)
  2858. RRETURN(MATCH_NOMATCH);
  2859. }
  2860. /* Control never gets here */
  2861. case PT_GC:
  2862. for (fi = min;; fi++)
  2863. {
  2864. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
  2865. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2866. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2867. GETCHARINC(c, eptr);
  2868. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2869. if ((prop_category == prop_value) == prop_fail_result)
  2870. RRETURN(MATCH_NOMATCH);
  2871. }
  2872. /* Control never gets here */
  2873. case PT_PC:
  2874. for (fi = min;; fi++)
  2875. {
  2876. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
  2877. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2878. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2879. GETCHARINC(c, eptr);
  2880. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2881. if ((prop_chartype == prop_value) == prop_fail_result)
  2882. RRETURN(MATCH_NOMATCH);
  2883. }
  2884. /* Control never gets here */
  2885. case PT_SC:
  2886. for (fi = min;; fi++)
  2887. {
  2888. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
  2889. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2890. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2891. GETCHARINC(c, eptr);
  2892. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2893. if ((prop_script == prop_value) == prop_fail_result)
  2894. RRETURN(MATCH_NOMATCH);
  2895. }
  2896. /* Control never gets here */
  2897. default:
  2898. RRETURN(PCRE_ERROR_INTERNAL);
  2899. }
  2900. }
  2901. /* Match extended Unicode sequences. We will get here only if the
  2902. support is in the binary; otherwise a compile-time error occurs. */
  2903. else if (ctype == OP_EXTUNI)
  2904. {
  2905. for (fi = min;; fi++)
  2906. {
  2907. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
  2908. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2909. if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2910. GETCHARINCTEST(c, eptr);
  2911. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2912. if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
  2913. while (eptr < md->end_subject)
  2914. {
  2915. int len = 1;
  2916. if (!utf8) c = *eptr; else
  2917. {
  2918. GETCHARLEN(c, eptr, len);
  2919. }
  2920. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2921. if (prop_category != ucp_M) break;
  2922. eptr += len;
  2923. }
  2924. }
  2925. }
  2926. else
  2927. #endif /* SUPPORT_UCP */
  2928. #ifdef SUPPORT_UTF8
  2929. /* UTF-8 mode */
  2930. if (utf8)
  2931. {
  2932. for (fi = min;; fi++)
  2933. {
  2934. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
  2935. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2936. if (fi >= max || eptr >= md->end_subject ||
  2937. (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&
  2938. IS_NEWLINE(eptr)))
  2939. RRETURN(MATCH_NOMATCH);
  2940. GETCHARINC(c, eptr);
  2941. switch(ctype)
  2942. {
  2943. case OP_ANY: /* This is the DOTALL case */
  2944. break;
  2945. case OP_ANYBYTE:
  2946. break;
  2947. case OP_ANYNL:
  2948. switch(c)
  2949. {
  2950. default: RRETURN(MATCH_NOMATCH);
  2951. case 0x000d:
  2952. if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  2953. break;
  2954. case 0x000a:
  2955. break;
  2956. case 0x000b:
  2957. case 0x000c:
  2958. case 0x0085:
  2959. case 0x2028:
  2960. case 0x2029:
  2961. if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  2962. break;
  2963. }
  2964. break;
  2965. case OP_NOT_HSPACE:
  2966. switch(c)
  2967. {
  2968. default: break;
  2969. case 0x09: /* HT */
  2970. case 0x20: /* SPACE */
  2971. case 0xa0: /* NBSP */
  2972. case 0x1680: /* OGHAM SPACE MARK */
  2973. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  2974. case 0x2000: /* EN QUAD */
  2975. case 0x2001: /* EM QUAD */
  2976. case 0x2002: /* EN SPACE */
  2977. case 0x2003: /* EM SPACE */
  2978. case 0x2004: /* THREE-PER-EM SPACE */
  2979. case 0x2005: /* FOUR-PER-EM SPACE */
  2980. case 0x2006: /* SIX-PER-EM SPACE */
  2981. case 0x2007: /* FIGURE SPACE */
  2982. case 0x2008: /* PUNCTUATION SPACE */
  2983. case 0x2009: /* THIN SPACE */
  2984. case 0x200A: /* HAIR SPACE */
  2985. case 0x202f: /* NARROW NO-BREAK SPACE */
  2986. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  2987. case 0x3000: /* IDEOGRAPHIC SPACE */
  2988. RRETURN(MATCH_NOMATCH);
  2989. }
  2990. break;
  2991. case OP_HSPACE:
  2992. switch(c)
  2993. {
  2994. default: RRETURN(MATCH_NOMATCH);
  2995. case 0x09: /* HT */
  2996. case 0x20: /* SPACE */
  2997. case 0xa0: /* NBSP */
  2998. case 0x1680: /* OGHAM SPACE MARK */
  2999. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  3000. case 0x2000: /* EN QUAD */
  3001. case 0x2001: /* EM QUAD */
  3002. case 0x2002: /* EN SPACE */
  3003. case 0x2003: /* EM SPACE */
  3004. case 0x2004: /* THREE-PER-EM SPACE */
  3005. case 0x2005: /* FOUR-PER-EM SPACE */
  3006. case 0x2006: /* SIX-PER-EM SPACE */
  3007. case 0x2007: /* FIGURE SPACE */
  3008. case 0x2008: /* PUNCTUATION SPACE */
  3009. case 0x2009: /* THIN SPACE */
  3010. case 0x200A: /* HAIR SPACE */
  3011. case 0x202f: /* NARROW NO-BREAK SPACE */
  3012. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  3013. case 0x3000: /* IDEOGRAPHIC SPACE */
  3014. break;
  3015. }
  3016. break;
  3017. case OP_NOT_VSPACE:
  3018. switch(c)
  3019. {
  3020. default: break;
  3021. case 0x0a: /* LF */
  3022. case 0x0b: /* VT */
  3023. case 0x0c: /* FF */
  3024. case 0x0d: /* CR */
  3025. case 0x85: /* NEL */
  3026. case 0x2028: /* LINE SEPARATOR */
  3027. case 0x2029: /* PARAGRAPH SEPARATOR */
  3028. RRETURN(MATCH_NOMATCH);
  3029. }
  3030. break;
  3031. case OP_VSPACE:
  3032. switch(c)
  3033. {
  3034. default: RRETURN(MATCH_NOMATCH);
  3035. case 0x0a: /* LF */
  3036. case 0x0b: /* VT */
  3037. case 0x0c: /* FF */
  3038. case 0x0d: /* CR */
  3039. case 0x85: /* NEL */
  3040. case 0x2028: /* LINE SEPARATOR */
  3041. case 0x2029: /* PARAGRAPH SEPARATOR */
  3042. break;
  3043. }
  3044. break;
  3045. case OP_NOT_DIGIT:
  3046. if (c < 256 && (md->ctypes[c] & ctype_digit) != 0)
  3047. RRETURN(MATCH_NOMATCH);
  3048. break;
  3049. case OP_DIGIT:
  3050. if (c >= 256 || (md->ctypes[c] & ctype_digit) == 0)
  3051. RRETURN(MATCH_NOMATCH);
  3052. break;
  3053. case OP_NOT_WHITESPACE:
  3054. if (c < 256 && (md->ctypes[c] & ctype_space) != 0)
  3055. RRETURN(MATCH_NOMATCH);
  3056. break;
  3057. case OP_WHITESPACE:
  3058. if (c >= 256 || (md->ctypes[c] & ctype_space) == 0)
  3059. RRETURN(MATCH_NOMATCH);
  3060. break;
  3061. case OP_NOT_WORDCHAR:
  3062. if (c < 256 && (md->ctypes[c] & ctype_word) != 0)
  3063. RRETURN(MATCH_NOMATCH);
  3064. break;
  3065. case OP_WORDCHAR:
  3066. if (c >= 256 || (md->ctypes[c] & ctype_word) == 0)
  3067. RRETURN(MATCH_NOMATCH);
  3068. break;
  3069. default:
  3070. RRETURN(PCRE_ERROR_INTERNAL);
  3071. }
  3072. }
  3073. }
  3074. else
  3075. #endif
  3076. /* Not UTF-8 mode */
  3077. {
  3078. for (fi = min;; fi++)
  3079. {
  3080. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
  3081. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3082. if (fi >= max || eptr >= md->end_subject ||
  3083. ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
  3084. RRETURN(MATCH_NOMATCH);
  3085. c = *eptr++;
  3086. switch(ctype)
  3087. {
  3088. case OP_ANY: /* This is the DOTALL case */
  3089. break;
  3090. case OP_ANYBYTE:
  3091. break;
  3092. case OP_ANYNL:
  3093. switch(c)
  3094. {
  3095. default: RRETURN(MATCH_NOMATCH);
  3096. case 0x000d:
  3097. if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  3098. break;
  3099. case 0x000a:
  3100. break;
  3101. case 0x000b:
  3102. case 0x000c:
  3103. case 0x0085:
  3104. if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
  3105. break;
  3106. }
  3107. break;
  3108. case OP_NOT_HSPACE:
  3109. switch(c)
  3110. {
  3111. default: break;
  3112. case 0x09: /* HT */
  3113. case 0x20: /* SPACE */
  3114. case 0xa0: /* NBSP */
  3115. RRETURN(MATCH_NOMATCH);
  3116. }
  3117. break;
  3118. case OP_HSPACE:
  3119. switch(c)
  3120. {
  3121. default: RRETURN(MATCH_NOMATCH);
  3122. case 0x09: /* HT */
  3123. case 0x20: /* SPACE */
  3124. case 0xa0: /* NBSP */
  3125. break;
  3126. }
  3127. break;
  3128. case OP_NOT_VSPACE:
  3129. switch(c)
  3130. {
  3131. default: break;
  3132. case 0x0a: /* LF */
  3133. case 0x0b: /* VT */
  3134. case 0x0c: /* FF */
  3135. case 0x0d: /* CR */
  3136. case 0x85: /* NEL */
  3137. RRETURN(MATCH_NOMATCH);
  3138. }
  3139. break;
  3140. case OP_VSPACE:
  3141. switch(c)
  3142. {
  3143. default: RRETURN(MATCH_NOMATCH);
  3144. case 0x0a: /* LF */
  3145. case 0x0b: /* VT */
  3146. case 0x0c: /* FF */
  3147. case 0x0d: /* CR */
  3148. case 0x85: /* NEL */
  3149. break;
  3150. }
  3151. break;
  3152. case OP_NOT_DIGIT:
  3153. if ((md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
  3154. break;
  3155. case OP_DIGIT:
  3156. if ((md->ctypes[c] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
  3157. break;
  3158. case OP_NOT_WHITESPACE:
  3159. if ((md->ctypes[c] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
  3160. break;
  3161. case OP_WHITESPACE:
  3162. if ((md->ctypes[c] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
  3163. break;
  3164. case OP_NOT_WORDCHAR:
  3165. if ((md->ctypes[c] & ctype_word) != 0) RRETURN(MATCH_NOMATCH);
  3166. break;
  3167. case OP_WORDCHAR:
  3168. if ((md->ctypes[c] & ctype_word) == 0) RRETURN(MATCH_NOMATCH);
  3169. break;
  3170. default:
  3171. RRETURN(PCRE_ERROR_INTERNAL);
  3172. }
  3173. }
  3174. }
  3175. /* Control never gets here */
  3176. }
  3177. /* If maximizing, it is worth using inline code for speed, doing the type
  3178. test once at the start (i.e. keep it out of the loop). Again, keep the
  3179. UTF-8 and UCP stuff separate. */
  3180. else
  3181. {
  3182. pp = eptr; /* Remember where we started */
  3183. #ifdef SUPPORT_UCP
  3184. if (prop_type >= 0)
  3185. {
  3186. switch(prop_type)
  3187. {
  3188. case PT_ANY:
  3189. for (i = min; i < max; i++)
  3190. {
  3191. int len = 1;
  3192. if (eptr >= md->end_subject) break;
  3193. GETCHARLEN(c, eptr, len);
  3194. if (prop_fail_result) break;
  3195. eptr+= len;
  3196. }
  3197. break;
  3198. case PT_LAMP:
  3199. for (i = min; i < max; i++)
  3200. {
  3201. int len = 1;
  3202. if (eptr >= md->end_subject) break;
  3203. GETCHARLEN(c, eptr, len);
  3204. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3205. if ((prop_chartype == ucp_Lu ||
  3206. prop_chartype == ucp_Ll ||
  3207. prop_chartype == ucp_Lt) == prop_fail_result)
  3208. break;
  3209. eptr+= len;
  3210. }
  3211. break;
  3212. case PT_GC:
  3213. for (i = min; i < max; i++)
  3214. {
  3215. int len = 1;
  3216. if (eptr >= md->end_subject) break;
  3217. GETCHARLEN(c, eptr, len);
  3218. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3219. if ((prop_category == prop_value) == prop_fail_result)
  3220. break;
  3221. eptr+= len;
  3222. }
  3223. break;
  3224. case PT_PC:
  3225. for (i = min; i < max; i++)
  3226. {
  3227. int len = 1;
  3228. if (eptr >= md->end_subject) break;
  3229. GETCHARLEN(c, eptr, len);
  3230. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3231. if ((prop_chartype == prop_value) == prop_fail_result)
  3232. break;
  3233. eptr+= len;
  3234. }
  3235. break;
  3236. case PT_SC:
  3237. for (i = min; i < max; i++)
  3238. {
  3239. int len = 1;
  3240. if (eptr >= md->end_subject) break;
  3241. GETCHARLEN(c, eptr, len);
  3242. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3243. if ((prop_script == prop_value) == prop_fail_result)
  3244. break;
  3245. eptr+= len;
  3246. }
  3247. break;
  3248. }
  3249. /* eptr is now past the end of the maximum run */
  3250. if (possessive) continue;
  3251. for(;;)
  3252. {
  3253. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
  3254. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3255. if (eptr-- == pp) break; /* Stop if tried at original pos */
  3256. if (utf8) BACKCHAR(eptr);
  3257. }
  3258. }
  3259. /* Match extended Unicode sequences. We will get here only if the
  3260. support is in the binary; otherwise a compile-time error occurs. */
  3261. else if (ctype == OP_EXTUNI)
  3262. {
  3263. for (i = min; i < max; i++)
  3264. {
  3265. if (eptr >= md->end_subject) break;
  3266. GETCHARINCTEST(c, eptr);
  3267. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3268. if (prop_category == ucp_M) break;
  3269. while (eptr < md->end_subject)
  3270. {
  3271. int len = 1;
  3272. if (!utf8) c = *eptr; else
  3273. {
  3274. GETCHARLEN(c, eptr, len);
  3275. }
  3276. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3277. if (prop_category != ucp_M) break;
  3278. eptr += len;
  3279. }
  3280. }
  3281. /* eptr is now past the end of the maximum run */
  3282. if (possessive) continue;
  3283. for(;;)
  3284. {
  3285. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
  3286. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3287. if (eptr-- == pp) break; /* Stop if tried at original pos */
  3288. for (;;) /* Move back over one extended */
  3289. {
  3290. int len = 1;
  3291. if (!utf8) c = *eptr; else
  3292. {
  3293. BACKCHAR(eptr);
  3294. GETCHARLEN(c, eptr, len);
  3295. }
  3296. prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3297. if (prop_category != ucp_M) break;
  3298. eptr--;
  3299. }
  3300. }
  3301. }
  3302. else
  3303. #endif /* SUPPORT_UCP */
  3304. #ifdef SUPPORT_UTF8
  3305. /* UTF-8 mode */
  3306. if (utf8)
  3307. {
  3308. switch(ctype)
  3309. {
  3310. case OP_ANY:
  3311. if (max < INT_MAX)
  3312. {
  3313. if ((ims & PCRE_DOTALL) == 0)
  3314. {
  3315. for (i = min; i < max; i++)
  3316. {
  3317. if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3318. eptr++;
  3319. while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3320. }
  3321. }
  3322. else
  3323. {
  3324. for (i = min; i < max; i++)
  3325. {
  3326. if (eptr >= md->end_subject) break;
  3327. eptr++;
  3328. while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3329. }
  3330. }
  3331. }
  3332. /* Handle unlimited UTF-8 repeat */
  3333. else
  3334. {
  3335. if ((ims & PCRE_DOTALL) == 0)
  3336. {
  3337. for (i = min; i < max; i++)
  3338. {
  3339. if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3340. eptr++;
  3341. while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3342. }
  3343. }
  3344. else
  3345. {
  3346. eptr = md->end_subject;
  3347. }
  3348. }
  3349. break;
  3350. /* The byte case is the same as non-UTF8 */
  3351. case OP_ANYBYTE:
  3352. c = max - min;
  3353. if (c > (unsigned int)(md->end_subject - eptr))
  3354. c = md->end_subject - eptr;
  3355. eptr += c;
  3356. break;
  3357. case OP_ANYNL:
  3358. for (i = min; i < max; i++)
  3359. {
  3360. int len = 1;
  3361. if (eptr >= md->end_subject) break;
  3362. GETCHARLEN(c, eptr, len);
  3363. if (c == 0x000d)
  3364. {
  3365. if (++eptr >= md->end_subject) break;
  3366. if (*eptr == 0x000a) eptr++;
  3367. }
  3368. else
  3369. {
  3370. if (c != 0x000a &&
  3371. (md->bsr_anycrlf ||
  3372. (c != 0x000b && c != 0x000c &&
  3373. c != 0x0085 && c != 0x2028 && c != 0x2029)))
  3374. break;
  3375. eptr += len;
  3376. }
  3377. }
  3378. break;
  3379. case OP_NOT_HSPACE:
  3380. case OP_HSPACE:
  3381. for (i = min; i < max; i++)
  3382. {
  3383. BOOL gotspace;
  3384. int len = 1;
  3385. if (eptr >= md->end_subject) break;
  3386. GETCHARLEN(c, eptr, len);
  3387. switch(c)
  3388. {
  3389. default: gotspace = FALSE; break;
  3390. case 0x09: /* HT */
  3391. case 0x20: /* SPACE */
  3392. case 0xa0: /* NBSP */
  3393. case 0x1680: /* OGHAM SPACE MARK */
  3394. case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
  3395. case 0x2000: /* EN QUAD */
  3396. case 0x2001: /* EM QUAD */
  3397. case 0x2002: /* EN SPACE */
  3398. case 0x2003: /* EM SPACE */
  3399. case 0x2004: /* THREE-PER-EM SPACE */
  3400. case 0x2005: /* FOUR-PER-EM SPACE */
  3401. case 0x2006: /* SIX-PER-EM SPACE */
  3402. case 0x2007: /* FIGURE SPACE */
  3403. case 0x2008: /* PUNCTUATION SPACE */
  3404. case 0x2009: /* THIN SPACE */
  3405. case 0x200A: /* HAIR SPACE */
  3406. case 0x202f: /* NARROW NO-BREAK SPACE */
  3407. case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
  3408. case 0x3000: /* IDEOGRAPHIC SPACE */
  3409. gotspace = TRUE;
  3410. break;
  3411. }
  3412. if (gotspace == (ctype == OP_NOT_HSPACE)) break;
  3413. eptr += len;
  3414. }
  3415. break;
  3416. case OP_NOT_VSPACE:
  3417. case OP_VSPACE:
  3418. for (i = min; i < max; i++)
  3419. {
  3420. BOOL gotspace;
  3421. int len = 1;
  3422. if (eptr >= md->end_subject) break;
  3423. GETCHARLEN(c, eptr, len);
  3424. switch(c)
  3425. {
  3426. default: gotspace = FALSE; break;
  3427. case 0x0a: /* LF */
  3428. case 0x0b: /* VT */
  3429. case 0x0c: /* FF */
  3430. case 0x0d: /* CR */
  3431. case 0x85: /* NEL */
  3432. case 0x2028: /* LINE SEPARATOR */
  3433. case 0x2029: /* PARAGRAPH SEPARATOR */
  3434. gotspace = TRUE;
  3435. break;
  3436. }
  3437. if (gotspace == (ctype == OP_NOT_VSPACE)) break;
  3438. eptr += len;
  3439. }
  3440. break;
  3441. case OP_NOT_DIGIT:
  3442. for (i = min; i < max; i++)
  3443. {
  3444. int len = 1;
  3445. if (eptr >= md->end_subject) break;
  3446. GETCHARLEN(c, eptr, len);
  3447. if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;
  3448. eptr+= len;
  3449. }
  3450. break;
  3451. case OP_DIGIT:
  3452. for (i = min; i < max; i++)
  3453. {
  3454. int len = 1;
  3455. if (eptr >= md->end_subject) break;
  3456. GETCHARLEN(c, eptr, len);
  3457. if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;
  3458. eptr+= len;
  3459. }
  3460. break;
  3461. case OP_NOT_WHITESPACE:
  3462. for (i = min; i < max; i++)
  3463. {
  3464. int len = 1;
  3465. if (eptr >= md->end_subject) break;
  3466. GETCHARLEN(c, eptr, len);
  3467. if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;
  3468. eptr+= len;
  3469. }
  3470. break;
  3471. case OP_WHITESPACE:
  3472. for (i = min; i < max; i++)
  3473. {
  3474. int len = 1;
  3475. if (eptr >= md->end_subject) break;
  3476. GETCHARLEN(c, eptr, len);
  3477. if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;
  3478. eptr+= len;
  3479. }
  3480. break;
  3481. case OP_NOT_WORDCHAR:
  3482. for (i = min; i < max; i++)
  3483. {
  3484. int len = 1;
  3485. if (eptr >= md->end_subject) break;
  3486. GETCHARLEN(c, eptr, len);
  3487. if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;
  3488. eptr+= len;
  3489. }
  3490. break;
  3491. case OP_WORDCHAR:
  3492. for (i = min; i < max; i++)
  3493. {
  3494. int len = 1;
  3495. if (eptr >= md->end_subject) break;
  3496. GETCHARLEN(c, eptr, len);
  3497. if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;
  3498. eptr+= len;
  3499. }
  3500. break;
  3501. default:
  3502. RRETURN(PCRE_ERROR_INTERNAL);
  3503. }
  3504. /* eptr is now past the end of the maximum run */
  3505. if (possessive) continue;
  3506. for(;;)
  3507. {
  3508. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
  3509. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3510. if (eptr-- == pp) break; /* Stop if tried at original pos */
  3511. BACKCHAR(eptr);
  3512. }
  3513. }
  3514. else
  3515. #endif /* SUPPORT_UTF8 */
  3516. /* Not UTF-8 mode */
  3517. {
  3518. switch(ctype)
  3519. {
  3520. case OP_ANY:
  3521. if ((ims & PCRE_DOTALL) == 0)
  3522. {
  3523. for (i = min; i < max; i++)
  3524. {
  3525. if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3526. eptr++;
  3527. }
  3528. break;
  3529. }
  3530. /* For DOTALL case, fall through and treat as \C */
  3531. case OP_ANYBYTE:
  3532. c = max - min;
  3533. if (c > (unsigned int)(md->end_subject - eptr))
  3534. c = md->end_subject - eptr;
  3535. eptr += c;
  3536. break;
  3537. case OP_ANYNL:
  3538. for (i = min; i < max; i++)
  3539. {
  3540. if (eptr >= md->end_subject) break;
  3541. c = *eptr;
  3542. if (c == 0x000d)
  3543. {
  3544. if (++eptr >= md->end_subject) break;
  3545. if (*eptr == 0x000a) eptr++;
  3546. }
  3547. else
  3548. {
  3549. if (c != 0x000a &&
  3550. (md->bsr_anycrlf ||
  3551. (c != 0x000b && c != 0x000c && c != 0x0085)))
  3552. break;
  3553. eptr++;
  3554. }
  3555. }
  3556. break;
  3557. case OP_NOT_HSPACE:
  3558. for (i = min; i < max; i++)
  3559. {
  3560. if (eptr >= md->end_subject) break;
  3561. c = *eptr;
  3562. if (c == 0x09 || c == 0x20 || c == 0xa0) break;
  3563. eptr++;
  3564. }
  3565. break;
  3566. case OP_HSPACE:
  3567. for (i = min; i < max; i++)
  3568. {
  3569. if (eptr >= md->end_subject) break;
  3570. c = *eptr;
  3571. if (c != 0x09 && c != 0x20 && c != 0xa0) break;
  3572. eptr++;
  3573. }
  3574. break;
  3575. case OP_NOT_VSPACE:
  3576. for (i = min; i < max; i++)
  3577. {
  3578. if (eptr >= md->end_subject) break;
  3579. c = *eptr;
  3580. if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
  3581. break;
  3582. eptr++;
  3583. }
  3584. break;
  3585. case OP_VSPACE:
  3586. for (i = min; i < max; i++)
  3587. {
  3588. if (eptr >= md->end_subject) break;
  3589. c = *eptr;
  3590. if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
  3591. break;
  3592. eptr++;
  3593. }
  3594. break;
  3595. case OP_NOT_DIGIT:
  3596. for (i = min; i < max; i++)
  3597. {
  3598. if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) != 0)
  3599. break;
  3600. eptr++;
  3601. }
  3602. break;
  3603. case OP_DIGIT:
  3604. for (i = min; i < max; i++)
  3605. {
  3606. if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) == 0)
  3607. break;
  3608. eptr++;
  3609. }
  3610. break;
  3611. case OP_NOT_WHITESPACE:
  3612. for (i = min; i < max; i++)
  3613. {
  3614. if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) != 0)
  3615. break;
  3616. eptr++;
  3617. }
  3618. break;
  3619. case OP_WHITESPACE:
  3620. for (i = min; i < max; i++)
  3621. {
  3622. if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) == 0)
  3623. break;
  3624. eptr++;
  3625. }
  3626. break;
  3627. case OP_NOT_WORDCHAR:
  3628. for (i = min; i < max; i++)
  3629. {
  3630. if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) != 0)
  3631. break;
  3632. eptr++;
  3633. }
  3634. break;
  3635. case OP_WORDCHAR:
  3636. for (i = min; i < max; i++)
  3637. {
  3638. if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) == 0)
  3639. break;
  3640. eptr++;
  3641. }
  3642. break;
  3643. default:
  3644. RRETURN(PCRE_ERROR_INTERNAL);
  3645. }
  3646. /* eptr is now past the end of the maximum run */
  3647. if (possessive) continue;
  3648. while (eptr >= pp)
  3649. {
  3650. RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
  3651. eptr--;
  3652. if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3653. }
  3654. }
  3655. /* Get here if we can't make it match with any permitted repetitions */
  3656. RRETURN(MATCH_NOMATCH);
  3657. }
  3658. /* Control never gets here */
  3659. /* There's been some horrible disaster. Arrival here can only mean there is
  3660. something seriously wrong in the code above or the OP_xxx definitions. */
  3661. default:
  3662. DPRINTF(("Unknown opcode %d\n", *ecode));
  3663. RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
  3664. }
  3665. /* Do not stick any code in here without much thought; it is assumed
  3666. that "continue" in the code above comes out to here to repeat the main
  3667. loop. */
  3668. } /* End of main loop */
  3669. /* Control never reaches here */
  3670. /* When compiling to use the heap rather than the stack for recursive calls to
  3671. match(), the RRETURN() macro jumps here. The number that is saved in
  3672. frame->Xwhere indicates which label we actually want to return to. */
  3673. #ifdef NO_RECURSE
  3674. #define LBL(val) case val: goto L_RM##val;
  3675. HEAP_RETURN:
  3676. switch (frame->Xwhere)
  3677. {
  3678. LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
  3679. LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
  3680. LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
  3681. LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
  3682. LBL(53) LBL(54)
  3683. #ifdef SUPPORT_UTF8
  3684. LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
  3685. LBL(32) LBL(34) LBL(42) LBL(46)
  3686. #ifdef SUPPORT_UCP
  3687. LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
  3688. #endif /* SUPPORT_UCP */
  3689. #endif /* SUPPORT_UTF8 */
  3690. default:
  3691. DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
  3692. return PCRE_ERROR_INTERNAL;
  3693. }
  3694. #undef LBL
  3695. #endif /* NO_RECURSE */
  3696. }
  3697. /***************************************************************************
  3698. ****************************************************************************
  3699. RECURSION IN THE match() FUNCTION
  3700. Undefine all the macros that were defined above to handle this. */
  3701. #ifdef NO_RECURSE
  3702. #undef eptr
  3703. #undef ecode
  3704. #undef mstart
  3705. #undef offset_top
  3706. #undef ims
  3707. #undef eptrb
  3708. #undef flags
  3709. #undef callpat
  3710. #undef charptr
  3711. #undef data
  3712. #undef next
  3713. #undef pp
  3714. #undef prev
  3715. #undef saved_eptr
  3716. #undef new_recursive
  3717. #undef cur_is_word
  3718. #undef condition
  3719. #undef prev_is_word
  3720. #undef original_ims
  3721. #undef ctype
  3722. #undef length
  3723. #undef max
  3724. #undef min
  3725. #undef number
  3726. #undef offset
  3727. #undef op
  3728. #undef save_capture_last
  3729. #undef save_offset1
  3730. #undef save_offset2
  3731. #undef save_offset3
  3732. #undef stacksave
  3733. #undef newptrb
  3734. #endif
  3735. /* These two are defined as macros in both cases */
  3736. #undef fc
  3737. #undef fi
  3738. /***************************************************************************
  3739. ***************************************************************************/
  3740. /*************************************************
  3741. * Execute a Regular Expression *
  3742. *************************************************/
  3743. /* This function applies a compiled re to a subject string and picks out
  3744. portions of the string if it matches. Two elements in the vector are set for
  3745. each substring: the offsets to the start and end of the substring.
  3746. Arguments:
  3747. argument_re points to the compiled expression
  3748. extra_data points to extra data or is NULL
  3749. subject points to the subject string
  3750. length length of subject string (may contain binary zeros)
  3751. start_offset where to start in the subject string
  3752. options option bits
  3753. offsets points to a vector of ints to be filled in with offsets
  3754. offsetcount the number of elements in the vector
  3755. Returns: > 0 => success; value is the number of elements filled in
  3756. = 0 => success, but offsets is not big enough
  3757. -1 => failed to match
  3758. < -1 => some kind of unexpected problem
  3759. */
  3760. PCRE_EXP_DEFN int
  3761. pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
  3762. PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
  3763. int offsetcount)
  3764. {
  3765. int rc, resetcount, ocount;
  3766. int first_byte = -1;
  3767. int req_byte = -1;
  3768. int req_byte2 = -1;
  3769. int newline;
  3770. unsigned long int ims;
  3771. BOOL using_temporary_offsets = FALSE;
  3772. BOOL anchored;
  3773. BOOL startline;
  3774. BOOL firstline;
  3775. BOOL first_byte_caseless = FALSE;
  3776. BOOL req_byte_caseless = FALSE;
  3777. BOOL utf8;
  3778. match_data match_block;
  3779. match_data *md = &match_block;
  3780. const uschar *tables;
  3781. const uschar *start_bits = NULL;
  3782. USPTR start_match = (USPTR)subject + start_offset;
  3783. USPTR end_subject;
  3784. USPTR req_byte_ptr = start_match - 1;
  3785. pcre_study_data internal_study;
  3786. const pcre_study_data *study;
  3787. real_pcre internal_re;
  3788. const real_pcre *external_re = (const real_pcre *)argument_re;
  3789. const real_pcre *re = external_re;
  3790. /* Plausibility checks */
  3791. if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
  3792. if (re == NULL || subject == NULL ||
  3793. (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
  3794. if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
  3795. /* Fish out the optional data from the extra_data structure, first setting
  3796. the default values. */
  3797. study = NULL;
  3798. md->match_limit = MATCH_LIMIT;
  3799. md->match_limit_recursion = MATCH_LIMIT_RECURSION;
  3800. md->callout_data = NULL;
  3801. /* The table pointer is always in native byte order. */
  3802. tables = external_re->tables;
  3803. if (extra_data != NULL)
  3804. {
  3805. register unsigned int flags = extra_data->flags;
  3806. if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
  3807. study = (const pcre_study_data *)extra_data->study_data;
  3808. if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)
  3809. md->match_limit = extra_data->match_limit;
  3810. if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)
  3811. md->match_limit_recursion = extra_data->match_limit_recursion;
  3812. if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
  3813. md->callout_data = extra_data->callout_data;
  3814. if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;
  3815. }
  3816. /* If the exec call supplied NULL for tables, use the inbuilt ones. This
  3817. is a feature that makes it possible to save compiled regex and re-use them
  3818. in other programs later. */
  3819. if (tables == NULL) tables = _pcre_default_tables;
  3820. /* Check that the first field in the block is the magic number. If it is not,
  3821. test for a regex that was compiled on a host of opposite endianness. If this is
  3822. the case, flipped values are put in internal_re and internal_study if there was
  3823. study data too. */
  3824. if (re->magic_number != MAGIC_NUMBER)
  3825. {
  3826. re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
  3827. if (re == NULL) return PCRE_ERROR_BADMAGIC;
  3828. if (study != NULL) study = &internal_study;
  3829. }
  3830. /* Set up other data */
  3831. anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
  3832. startline = (re->flags & PCRE_STARTLINE) != 0;
  3833. firstline = (re->options & PCRE_FIRSTLINE) != 0;
  3834. /* The code starts after the real_pcre block and the capture name table. */
  3835. md->start_code = (const uschar *)external_re + re->name_table_offset +
  3836. re->name_count * re->name_entry_size;
  3837. md->start_subject = (USPTR)subject;
  3838. md->start_offset = start_offset;
  3839. md->end_subject = md->start_subject + length;
  3840. end_subject = md->end_subject;
  3841. md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
  3842. utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
  3843. md->notbol = (options & PCRE_NOTBOL) != 0;
  3844. md->noteol = (options & PCRE_NOTEOL) != 0;
  3845. md->notempty = (options & PCRE_NOTEMPTY) != 0;
  3846. md->partial = (options & PCRE_PARTIAL) != 0;
  3847. md->hitend = FALSE;
  3848. md->recursive = NULL; /* No recursion at top level */
  3849. md->lcc = tables + lcc_offset;
  3850. md->ctypes = tables + ctypes_offset;
  3851. /* Handle different \R options. */
  3852. switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
  3853. {
  3854. case 0:
  3855. if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
  3856. md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
  3857. else
  3858. #ifdef BSR_ANYCRLF
  3859. md->bsr_anycrlf = TRUE;
  3860. #else
  3861. md->bsr_anycrlf = FALSE;
  3862. #endif
  3863. break;
  3864. case PCRE_BSR_ANYCRLF:
  3865. md->bsr_anycrlf = TRUE;
  3866. break;
  3867. case PCRE_BSR_UNICODE:
  3868. md->bsr_anycrlf = FALSE;
  3869. break;
  3870. default: return PCRE_ERROR_BADNEWLINE;
  3871. }
  3872. /* Handle different types of newline. The three bits give eight cases. If
  3873. nothing is set at run time, whatever was used at compile time applies. */
  3874. switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
  3875. (pcre_uint32)options) & PCRE_NEWLINE_BITS)
  3876. {
  3877. case 0: newline = NEWLINE; break; /* Compile-time default */
  3878. case PCRE_NEWLINE_CR: newline = '\r'; break;
  3879. case PCRE_NEWLINE_LF: newline = '\n'; break;
  3880. case PCRE_NEWLINE_CR+
  3881. PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
  3882. case PCRE_NEWLINE_ANY: newline = -1; break;
  3883. case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
  3884. default: return PCRE_ERROR_BADNEWLINE;
  3885. }
  3886. if (newline == -2)
  3887. {
  3888. md->nltype = NLTYPE_ANYCRLF;
  3889. }
  3890. else if (newline < 0)
  3891. {
  3892. md->nltype = NLTYPE_ANY;
  3893. }
  3894. else
  3895. {
  3896. md->nltype = NLTYPE_FIXED;
  3897. if (newline > 255)
  3898. {
  3899. md->nllen = 2;
  3900. md->nl[0] = (newline >> 8) & 255;
  3901. md->nl[1] = newline & 255;
  3902. }
  3903. else
  3904. {
  3905. md->nllen = 1;
  3906. md->nl[0] = newline;
  3907. }
  3908. }
  3909. /* Partial matching is supported only for a restricted set of regexes at the
  3910. moment. */
  3911. if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
  3912. return PCRE_ERROR_BADPARTIAL;
  3913. /* Check a UTF-8 string if required. Unfortunately there's no way of passing
  3914. back the character offset. */
  3915. #ifdef SUPPORT_UTF8
  3916. if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
  3917. {
  3918. if (_pcre_valid_utf8((uschar *)subject, length) >= 0)
  3919. return PCRE_ERROR_BADUTF8;
  3920. if (start_offset > 0 && start_offset < length)
  3921. {
  3922. int tb = ((uschar *)subject)[start_offset];
  3923. if (tb > 127)
  3924. {
  3925. tb &= 0xc0;
  3926. if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET;
  3927. }
  3928. }
  3929. }
  3930. #endif
  3931. /* The ims options can vary during the matching as a result of the presence
  3932. of (?ims) items in the pattern. They are kept in a local variable so that
  3933. restoring at the exit of a group is easy. */
  3934. ims = re->options & (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL);
  3935. /* If the expression has got more back references than the offsets supplied can
  3936. hold, we get a temporary chunk of working store to use during the matching.
  3937. Otherwise, we can use the vector supplied, rounding down its size to a multiple
  3938. of 3. */
  3939. ocount = offsetcount - (offsetcount % 3);
  3940. if (re->top_backref > 0 && re->top_backref >= ocount/3)
  3941. {
  3942. ocount = re->top_backref * 3 + 3;
  3943. md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
  3944. if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
  3945. using_temporary_offsets = TRUE;
  3946. DPRINTF(("Got memory to hold back references\n"));
  3947. }
  3948. else md->offset_vector = offsets;
  3949. md->offset_end = ocount;
  3950. md->offset_max = (2*ocount)/3;
  3951. md->offset_overflow = FALSE;
  3952. md->capture_last = -1;
  3953. /* Compute the minimum number of offsets that we need to reset each time. Doing
  3954. this makes a huge difference to execution time when there aren't many brackets
  3955. in the pattern. */
  3956. resetcount = 2 + re->top_bracket * 2;
  3957. if (resetcount > offsetcount) resetcount = ocount;
  3958. /* Reset the working variable associated with each extraction. These should
  3959. never be used unless previously set, but they get saved and restored, and so we
  3960. initialize them to avoid reading uninitialized locations. */
  3961. if (md->offset_vector != NULL)
  3962. {
  3963. register int *iptr = md->offset_vector + ocount;
  3964. register int *iend = iptr - resetcount/2 + 1;
  3965. while (--iptr >= iend) *iptr = -1;
  3966. }
  3967. /* Set up the first character to match, if available. The first_byte value is
  3968. never set for an anchored regular expression, but the anchoring may be forced
  3969. at run time, so we have to test for anchoring. The first char may be unset for
  3970. an unanchored pattern, of course. If there's no first char and the pattern was
  3971. studied, there may be a bitmap of possible first characters. */
  3972. if (!anchored)
  3973. {
  3974. if ((re->flags & PCRE_FIRSTSET) != 0)
  3975. {
  3976. first_byte = re->first_byte & 255;
  3977. if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
  3978. first_byte = md->lcc[first_byte];
  3979. }
  3980. else
  3981. if (!startline && study != NULL &&
  3982. (study->options & PCRE_STUDY_MAPPED) != 0)
  3983. start_bits = study->start_bits;
  3984. }
  3985. /* For anchored or unanchored matches, there may be a "last known required
  3986. character" set. */
  3987. if ((re->flags & PCRE_REQCHSET) != 0)
  3988. {
  3989. req_byte = re->req_byte & 255;
  3990. req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
  3991. req_byte2 = (tables + fcc_offset)[req_byte]; /* case flipped */
  3992. }
  3993. /* ==========================================================================*/
  3994. /* Loop for handling unanchored repeated matching attempts; for anchored regexs
  3995. the loop runs just once. */
  3996. for(;;)
  3997. {
  3998. USPTR save_end_subject = end_subject;
  3999. USPTR new_start_match;
  4000. /* Reset the maximum number of extractions we might see. */
  4001. if (md->offset_vector != NULL)
  4002. {
  4003. register int *iptr = md->offset_vector;
  4004. register int *iend = iptr + resetcount;
  4005. while (iptr < iend) *iptr++ = -1;
  4006. }
  4007. /* Advance to a unique first char if possible. If firstline is TRUE, the
  4008. start of the match is constrained to the first line of a multiline string.
  4009. That is, the match must be before or at the first newline. Implement this by
  4010. temporarily adjusting end_subject so that we stop scanning at a newline. If
  4011. the match fails at the newline, later code breaks this loop. */
  4012. if (firstline)
  4013. {
  4014. USPTR t = start_match;
  4015. while (t < md->end_subject && !IS_NEWLINE(t)) t++;
  4016. end_subject = t;
  4017. }
  4018. /* Now test for a unique first byte */
  4019. if (first_byte >= 0)
  4020. {
  4021. if (first_byte_caseless)
  4022. while (start_match < end_subject &&
  4023. md->lcc[*start_match] != first_byte)
  4024. { NEXTCHAR(start_match); }
  4025. else
  4026. while (start_match < end_subject && *start_match != first_byte)
  4027. { NEXTCHAR(start_match); }
  4028. }
  4029. /* Or to just after a linebreak for a multiline match if possible */
  4030. else if (startline)
  4031. {
  4032. if (start_match > md->start_subject + start_offset)
  4033. {
  4034. while (start_match <= end_subject && !WAS_NEWLINE(start_match))
  4035. { NEXTCHAR(start_match); }
  4036. /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
  4037. and we are now at a LF, advance the match position by one more character.
  4038. */
  4039. if (start_match[-1] == '\r' &&
  4040. (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
  4041. start_match < end_subject &&
  4042. *start_match == '\n')
  4043. start_match++;
  4044. }
  4045. }
  4046. /* Or to a non-unique first char after study */
  4047. else if (start_bits != NULL)
  4048. {
  4049. while (start_match < end_subject)
  4050. {
  4051. register unsigned int c = *start_match;
  4052. if ((start_bits[c/8] & (1 << (c&7))) == 0)
  4053. { NEXTCHAR(start_match); }
  4054. else break;
  4055. }
  4056. }
  4057. /* Restore fudged end_subject */
  4058. end_subject = save_end_subject;
  4059. #ifdef DEBUG /* Sigh. Some compilers never learn. */
  4060. printf(">>>> Match against: ");
  4061. pchars(start_match, end_subject - start_match, TRUE, md);
  4062. printf("\n");
  4063. #endif
  4064. /* If req_byte is set, we know that that character must appear in the subject
  4065. for the match to succeed. If the first character is set, req_byte must be
  4066. later in the subject; otherwise the test starts at the match point. This
  4067. optimization can save a huge amount of backtracking in patterns with nested
  4068. unlimited repeats that aren't going to match. Writing separate code for
  4069. cased/caseless versions makes it go faster, as does using an autoincrement
  4070. and backing off on a match.
  4071. HOWEVER: when the subject string is very, very long, searching to its end can
  4072. take a long time, and give bad performance on quite ordinary patterns. This
  4073. showed up when somebody was matching something like /^\d+C/ on a 32-megabyte
  4074. string... so we don't do this when the string is sufficiently long.
  4075. ALSO: this processing is disabled when partial matching is requested.
  4076. */
  4077. if (req_byte >= 0 &&
  4078. end_subject - start_match < REQ_BYTE_MAX &&
  4079. !md->partial)
  4080. {
  4081. register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
  4082. /* We don't need to repeat the search if we haven't yet reached the
  4083. place we found it at last time. */
  4084. if (p > req_byte_ptr)
  4085. {
  4086. if (req_byte_caseless)
  4087. {
  4088. while (p < end_subject)
  4089. {
  4090. register int pp = *p++;
  4091. if (pp == req_byte || pp == req_byte2) { p--; break; }
  4092. }
  4093. }
  4094. else
  4095. {
  4096. while (p < end_subject)
  4097. {
  4098. if (*p++ == req_byte) { p--; break; }
  4099. }
  4100. }
  4101. /* If we can't find the required character, break the matching loop,
  4102. forcing a match failure. */
  4103. if (p >= end_subject)
  4104. {
  4105. rc = MATCH_NOMATCH;
  4106. break;
  4107. }
  4108. /* If we have found the required character, save the point where we
  4109. found it, so that we don't search again next time round the loop if
  4110. the start hasn't passed this character yet. */
  4111. req_byte_ptr = p;
  4112. }
  4113. }
  4114. /* OK, we can now run the match. */
  4115. md->start_match_ptr = start_match;
  4116. md->match_call_count = 0;
  4117. rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
  4118. switch(rc)
  4119. {
  4120. /* NOMATCH and PRUNE advance by one character. THEN at this level acts
  4121. exactly like PRUNE. */
  4122. case MATCH_NOMATCH:
  4123. case MATCH_PRUNE:
  4124. case MATCH_THEN:
  4125. new_start_match = start_match + 1;
  4126. #ifdef SUPPORT_UTF8
  4127. if (utf8)
  4128. while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
  4129. new_start_match++;
  4130. #endif
  4131. break;
  4132. /* SKIP passes back the next starting point explicitly. */
  4133. case MATCH_SKIP:
  4134. new_start_match = md->start_match_ptr;
  4135. break;
  4136. /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
  4137. case MATCH_COMMIT:
  4138. rc = MATCH_NOMATCH;
  4139. goto ENDLOOP;
  4140. /* Any other return is some kind of error. */
  4141. default:
  4142. goto ENDLOOP;
  4143. }
  4144. /* Control reaches here for the various types of "no match at this point"
  4145. result. Reset the code to MATCH_NOMATCH for subsequent checking. */
  4146. rc = MATCH_NOMATCH;
  4147. /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
  4148. newline in the subject (though it may continue over the newline). Therefore,
  4149. if we have just failed to match, starting at a newline, do not continue. */
  4150. if (firstline && IS_NEWLINE(start_match)) break;
  4151. /* Advance to new matching position */
  4152. start_match = new_start_match;
  4153. /* Break the loop if the pattern is anchored or if we have passed the end of
  4154. the subject. */
  4155. if (anchored || start_match > end_subject) break;
  4156. /* If we have just passed a CR and we are now at a LF, and the pattern does
  4157. not contain any explicit matches for \r or \n, and the newline option is CRLF
  4158. or ANY or ANYCRLF, advance the match position by one more character. */
  4159. if (start_match[-1] == '\r' &&
  4160. start_match < end_subject &&
  4161. *start_match == '\n' &&
  4162. (re->flags & PCRE_HASCRORLF) == 0 &&
  4163. (md->nltype == NLTYPE_ANY ||
  4164. md->nltype == NLTYPE_ANYCRLF ||
  4165. md->nllen == 2))
  4166. start_match++;
  4167. } /* End of for(;;) "bumpalong" loop */
  4168. /* ==========================================================================*/
  4169. /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
  4170. conditions is true:
  4171. (1) The pattern is anchored or the match was failed by (*COMMIT);
  4172. (2) We are past the end of the subject;
  4173. (3) PCRE_FIRSTLINE is set and we have failed to match at a newline, because
  4174. this option requests that a match occur at or before the first newline in
  4175. the subject.
  4176. When we have a match and the offset vector is big enough to deal with any
  4177. backreferences, captured substring offsets will already be set up. In the case
  4178. where we had to get some local store to hold offsets for backreference
  4179. processing, copy those that we can. In this case there need not be overflow if
  4180. certain parts of the pattern were not used, even though there are more
  4181. capturing parentheses than vector slots. */
  4182. ENDLOOP:
  4183. if (rc == MATCH_MATCH)
  4184. {
  4185. if (using_temporary_offsets)
  4186. {
  4187. if (offsetcount >= 4)
  4188. {
  4189. memcpy(offsets + 2, md->offset_vector + 2,
  4190. (offsetcount - 2) * sizeof(int));
  4191. DPRINTF(("Copied offsets from temporary memory\n"));
  4192. }
  4193. if (md->end_offset_top > offsetcount) md->offset_overflow = TRUE;
  4194. DPRINTF(("Freeing temporary memory\n"));
  4195. (pcre_free)(md->offset_vector);
  4196. }
  4197. /* Set the return code to the number of captured strings, or 0 if there are
  4198. too many to fit into the vector. */
  4199. rc = md->offset_overflow? 0 : md->end_offset_top/2;
  4200. /* If there is space, set up the whole thing as substring 0. The value of
  4201. md->start_match_ptr might be modified if \K was encountered on the success
  4202. matching path. */
  4203. if (offsetcount < 2) rc = 0; else
  4204. {
  4205. offsets[0] = md->start_match_ptr - md->start_subject;
  4206. offsets[1] = md->end_match_ptr - md->start_subject;
  4207. }
  4208. DPRINTF((">>>> returning %d\n", rc));
  4209. return rc;
  4210. }
  4211. /* Control gets here if there has been an error, or if the overall match
  4212. attempt has failed at all permitted starting positions. */
  4213. if (using_temporary_offsets)
  4214. {
  4215. DPRINTF(("Freeing temporary memory\n"));
  4216. (pcre_free)(md->offset_vector);
  4217. }
  4218. if (rc != MATCH_NOMATCH)
  4219. {
  4220. DPRINTF((">>>> error: returning %d\n", rc));
  4221. return rc;
  4222. }
  4223. else if (md->partial && md->hitend)
  4224. {
  4225. DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
  4226. return PCRE_ERROR_PARTIAL;
  4227. }
  4228. else
  4229. {
  4230. DPRINTF((">>>> returning PCRE_ERROR_NOMATCH\n"));
  4231. return PCRE_ERROR_NOMATCH;
  4232. }
  4233. }
  4234. /* End of pcre_exec.c */