12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729 |
- #undef _LIBC
- #define _REGEX_RE_COMP
- #if defined _AIX && !defined REGEX_MALLOC
- #pragma alloca
- #endif
- #undef _GNU_SOURCE
- #define _GNU_SOURCE
- #define STDC_HEADERS
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #ifndef PARAMS
- # if defined __GNUC__ || (defined __STDC__ && __STDC__)
- # define PARAMS(args) args
- # else
- # define PARAMS(args) ()
- # endif
- #endif
- #if defined STDC_HEADERS && !defined emacs
- # include <stddef.h>
- #else
- # include <sys/types.h>
- #endif
- #define WIDE_CHAR_SUPPORT (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC)
- #if defined _LIBC || WIDE_CHAR_SUPPORT
- # include <wchar.h>
- # include <wctype.h>
- #endif
- #ifdef _LIBC
- # define regfree(preg) __regfree (preg)
- # define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
- # define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
- # define regerror(errcode, preg, errbuf, errbuf_size) \
- __regerror(errcode, preg, errbuf, errbuf_size)
- # define re_set_registers(bu, re, nu, st, en) \
- __re_set_registers (bu, re, nu, st, en)
- # define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
- __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
- # define re_match(bufp, string, size, pos, regs) \
- __re_match (bufp, string, size, pos, regs)
- # define re_search(bufp, string, size, startpos, range, regs) \
- __re_search (bufp, string, size, startpos, range, regs)
- # define re_compile_pattern(pattern, length, bufp) \
- __re_compile_pattern (pattern, length, bufp)
- # define re_set_syntax(syntax) __re_set_syntax (syntax)
- # define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
- __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
- # define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
- #define btowc __btowc
- #endif
- #if HAVE_LIBINTL_H || defined _LIBC
- # include <libintl.h>
- #else
- # define gettext(msgid) (msgid)
- #endif
- #ifndef gettext_noop
- # define gettext_noop(String) String
- #endif
- #ifdef emacs
- # include "lisp.h"
- # include "buffer.h"
- # include "syntax.h"
- #else
- # undef REL_ALLOC
- # if defined STDC_HEADERS || defined _LIBC
- # include <stdlib.h>
- # else
- char *malloc();
- char *realloc();
- # endif
- # ifdef INHIBIT_STRING_HEADER
- # if !(defined HAVE_BZERO && defined HAVE_BCOPY)
- # if !defined bzero && !defined bcopy
- # undef INHIBIT_STRING_HEADER
- # endif
- # endif
- # endif
- # ifndef INHIBIT_STRING_HEADER
- # if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC
- # include <string.h>
- # ifndef bzero
- # ifndef _LIBC
- # define bzero(s, n) (memset (s, '\0', n), (s))
- # else
- # define bzero(s, n) __bzero (s, n)
- # endif
- # endif
- # else
- # include <strings.h>
- # ifndef memcmp
- # define memcmp(s1, s2, n) bcmp (s1, s2, n)
- # endif
- # ifndef memcpy
- # define memcpy(d, s, n) (bcopy (s, d, n), (d))
- # endif
- # endif
- # endif
- # ifndef Sword
- # define Sword 1
- # endif
- # ifdef SWITCH_ENUM_BUG
- # define SWITCH_ENUM_CAST(x) ((int)(x))
- # else
- # define SWITCH_ENUM_CAST(x) (x)
- # endif
- #endif
- #include <regex.h>
- #include <ctype.h>
- #undef ISASCII
- #if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
- # define ISASCII(c) 1
- #else
- # define ISASCII(c) isascii(c)
- #endif
- #ifdef isblank
- # define ISBLANK(c) (ISASCII (c) && isblank (c))
- #else
- # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
- #endif
- #ifdef isgraph
- # define ISGRAPH(c) (ISASCII (c) && isgraph (c))
- #else
- # define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
- #endif
- #undef ISPRINT
- #define ISPRINT(c) (ISASCII (c) && isprint (c))
- #define ISDIGIT(c) (ISASCII (c) && isdigit (c))
- #define ISALNUM(c) (ISASCII (c) && isalnum (c))
- #define ISALPHA(c) (ISASCII (c) && isalpha (c))
- #define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
- #define ISLOWER(c) (ISASCII (c) && islower (c))
- #define ISPUNCT(c) (ISASCII (c) && ispunct (c))
- #define ISSPACE(c) (ISASCII (c) && isspace (c))
- #define ISUPPER(c) (ISASCII (c) && isupper (c))
- #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
- #ifdef _tolower
- # define TOLOWER(c) _tolower(c)
- #else
- # define TOLOWER(c) tolower(c)
- #endif
- #ifndef NULL
- # define NULL (void *)0
- #endif
- #undef SIGN_EXTEND_CHAR
- #if __STDC__
- # define SIGN_EXTEND_CHAR(c) ((signed char) (c))
- #else
- # define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
- #endif
- #ifndef emacs
- # define CHAR_SET_SIZE 256
- # ifdef SYNTAX_TABLE
- extern char *re_syntax_table;
- # else
- static char re_syntax_table[CHAR_SET_SIZE];
- static void init_syntax_once()
- {
- register int c;
- static int done = 0;
- if (done)
- return;
- bzero(re_syntax_table, sizeof re_syntax_table);
- for (c = 0; c < CHAR_SET_SIZE; ++c)
- if (ISALNUM(c))
- re_syntax_table[c] = Sword;
- re_syntax_table['_'] = Sword;
- done = 1;
- }
- # endif
- # define SYNTAX(c) re_syntax_table[((c) & 0xFF)]
- #endif
- #ifdef REGEX_MALLOC
- # define REGEX_ALLOCATE malloc
- # define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
- # define REGEX_FREE free
- #else
- # ifndef alloca
- # ifdef __GNUC__
- # define alloca __builtin_alloca
- # else
- # if HAVE_ALLOCA_H
- # include <alloca.h>
- # endif
- # endif
- # endif
- # define REGEX_ALLOCATE alloca
- # define REGEX_REALLOCATE(source, osize, nsize) \
- (destination = (char *) alloca (nsize), \
- memcpy (destination, source, osize))
- # define REGEX_FREE(arg) ((void)0)
- #endif
- #if defined REL_ALLOC && defined REGEX_MALLOC
- # define REGEX_ALLOCATE_STACK(size) \
- r_alloc (&failure_stack_ptr, (size))
- # define REGEX_REALLOCATE_STACK(source, osize, nsize) \
- r_re_alloc (&failure_stack_ptr, (nsize))
- # define REGEX_FREE_STACK(ptr) \
- r_alloc_free (&failure_stack_ptr)
- #else
- # ifdef REGEX_MALLOC
- # define REGEX_ALLOCATE_STACK malloc
- # define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize)
- # define REGEX_FREE_STACK free
- # else
- # define REGEX_ALLOCATE_STACK alloca
- # define REGEX_REALLOCATE_STACK(source, osize, nsize) \
- REGEX_REALLOCATE (source, osize, nsize)
- # define REGEX_FREE_STACK(arg)
- # endif
- #endif
- #define FIRST_STRING_P(ptr) \
- (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
- #define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
- #define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
- #define RETALLOC_IF(addr, n, t) \
- if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t)
- #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
- #define BYTEWIDTH 8
- #define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
- #undef MAX
- #undef MIN
- #define MAX(a, b) ((a) > (b) ? (a) : (b))
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
- typedef char boolean;
- #define false 0
- #define true 1
- static int re_match_2_internal PARAMS((struct re_pattern_buffer * bufp,
- const char *string1, int size1,
- const char *string2, int size2,
- int pos,
- struct re_registers * regs,
- int stop));
- typedef enum {
- no_op = 0,
-
- succeed,
-
- exactn,
-
- anychar,
-
- charset,
-
- charset_not,
-
- start_memory,
-
- stop_memory,
-
- duplicate,
-
- begline,
-
- endline,
-
- begbuf,
-
- endbuf,
-
- jump,
-
- jump_past_alt,
-
- on_failure_jump,
-
- on_failure_keep_string_jump,
-
- pop_failure_jump,
-
- maybe_pop_jump,
-
- dummy_failure_jump,
-
- push_dummy_failure,
-
- succeed_n,
-
- jump_n,
-
- set_number_at,
- wordchar,
- notwordchar,
- wordbeg,
- wordend,
- wordbound,
- notwordbound
- #ifdef emacs
- , before_dot,
- at_dot,
- after_dot,
-
- syntaxspec,
-
- notsyntaxspec
- #endif
- } re_opcode_t;
- #define STORE_NUMBER(destination, number) \
- do { \
- (destination)[0] = (number) & 0377; \
- (destination)[1] = (number) >> 8; \
- } while (0)
- #define STORE_NUMBER_AND_INCR(destination, number) \
- do { \
- STORE_NUMBER (destination, number); \
- (destination) += 2; \
- } while (0)
- #define EXTRACT_NUMBER(destination, source) \
- do { \
- (destination) = *(source) & 0377; \
- (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
- } while (0)
- #ifdef DEBUG
- static void extract_number _RE_ARGS((int *dest, unsigned char *source));
- static void extract_number(dest, source)
- int *dest;
- unsigned char *source;
- {
- int temp = SIGN_EXTEND_CHAR(*(source + 1));
- *dest = *source & 0377;
- *dest += temp << 8;
- }
- # ifndef EXTRACT_MACROS
- # undef EXTRACT_NUMBER
- # define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
- # endif
- #endif
- #define EXTRACT_NUMBER_AND_INCR(destination, source) \
- do { \
- EXTRACT_NUMBER (destination, source); \
- (source) += 2; \
- } while (0)
- #ifdef DEBUG
- static void extract_number_and_incr _RE_ARGS((int *destination,
- unsigned char **source));
- static void extract_number_and_incr(destination, source)
- int *destination;
- unsigned char **source;
- {
- extract_number(destination, *source);
- *source += 2;
- }
- # ifndef EXTRACT_MACROS
- # undef EXTRACT_NUMBER_AND_INCR
- # define EXTRACT_NUMBER_AND_INCR(dest, src) \
- extract_number_and_incr (&dest, &src)
- # endif
- #endif
- #ifdef DEBUG
- # include <stdio.h>
- # include <assert.h>
- static int debug;
- # define DEBUG_STATEMENT(e) e
- # define DEBUG_PRINT1(x) if (debug) printf (x)
- # define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2)
- # define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3)
- # define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4)
- # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
- if (debug) print_partial_compiled_pattern (s, e)
- # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
- if (debug) print_double_string (w, s1, sz1, s2, sz2)
- void print_fastmap(fastmap)
- char *fastmap;
- {
- unsigned was_a_range = 0;
- unsigned i = 0;
- while (i < (1 << BYTEWIDTH)) {
- if (fastmap[i++]) {
- was_a_range = 0;
- putchar(i - 1);
- while (i < (1 << BYTEWIDTH) && fastmap[i]) {
- was_a_range = 1;
- i++;
- }
- if (was_a_range) {
- printf("-");
- putchar(i - 1);
- }
- }
- }
- putchar('\n');
- }
- void print_partial_compiled_pattern(start, end)
- unsigned char *start;
- unsigned char *end;
- {
- int mcnt, mcnt2;
- unsigned char *p1;
- unsigned char *p = start;
- unsigned char *pend = end;
- if (start == NULL) {
- printf("(null)\n");
- return;
- }
-
- while (p < pend) {
- printf("%d:\t", p - start);
- switch ((re_opcode_t) * p++) {
- case no_op:
- printf("/no_op");
- break;
- case exactn:
- mcnt = *p++;
- printf("/exactn/%d", mcnt);
- do {
- putchar('/');
- putchar(*p++);
- }
- while (--mcnt);
- break;
- case start_memory:
- mcnt = *p++;
- printf("/start_memory/%d/%d", mcnt, *p++);
- break;
- case stop_memory:
- mcnt = *p++;
- printf("/stop_memory/%d/%d", mcnt, *p++);
- break;
- case duplicate:
- printf("/duplicate/%d", *p++);
- break;
- case anychar:
- printf("/anychar");
- break;
- case charset:
- case charset_not:
- {
- register int c, last = -100;
- register int in_range = 0;
- printf("/charset [%s",
- (re_opcode_t) * (p - 1) == charset_not ? "^" : "");
- assert(p + *p < pend);
- for (c = 0; c < 256; c++)
- if (c / 8 < *p && (p[1 + (c / 8)] & (1 << (c % 8)))) {
-
- if (last + 1 == c && !in_range) {
- putchar('-');
- in_range = 1;
- }
-
- else if (last + 1 != c && in_range) {
- putchar(last);
- in_range = 0;
- }
- if (!in_range)
- putchar(c);
- last = c;
- }
- if (in_range)
- putchar(last);
- putchar(']');
- p += 1 + *p;
- }
- break;
- case begline:
- printf("/begline");
- break;
- case endline:
- printf("/endline");
- break;
- case on_failure_jump:
- extract_number_and_incr(&mcnt, &p);
- printf("/on_failure_jump to %d", p + mcnt - start);
- break;
- case on_failure_keep_string_jump:
- extract_number_and_incr(&mcnt, &p);
- printf("/on_failure_keep_string_jump to %d", p + mcnt - start);
- break;
- case dummy_failure_jump:
- extract_number_and_incr(&mcnt, &p);
- printf("/dummy_failure_jump to %d", p + mcnt - start);
- break;
- case push_dummy_failure:
- printf("/push_dummy_failure");
- break;
- case maybe_pop_jump:
- extract_number_and_incr(&mcnt, &p);
- printf("/maybe_pop_jump to %d", p + mcnt - start);
- break;
- case pop_failure_jump:
- extract_number_and_incr(&mcnt, &p);
- printf("/pop_failure_jump to %d", p + mcnt - start);
- break;
- case jump_past_alt:
- extract_number_and_incr(&mcnt, &p);
- printf("/jump_past_alt to %d", p + mcnt - start);
- break;
- case jump:
- extract_number_and_incr(&mcnt, &p);
- printf("/jump to %d", p + mcnt - start);
- break;
- case succeed_n:
- extract_number_and_incr(&mcnt, &p);
- p1 = p + mcnt;
- extract_number_and_incr(&mcnt2, &p);
- printf("/succeed_n to %d, %d times", p1 - start, mcnt2);
- break;
- case jump_n:
- extract_number_and_incr(&mcnt, &p);
- p1 = p + mcnt;
- extract_number_and_incr(&mcnt2, &p);
- printf("/jump_n to %d, %d times", p1 - start, mcnt2);
- break;
- case set_number_at:
- extract_number_and_incr(&mcnt, &p);
- p1 = p + mcnt;
- extract_number_and_incr(&mcnt2, &p);
- printf("/set_number_at location %d to %d", p1 - start, mcnt2);
- break;
- case wordbound:
- printf("/wordbound");
- break;
- case notwordbound:
- printf("/notwordbound");
- break;
- case wordbeg:
- printf("/wordbeg");
- break;
- case wordend:
- printf("/wordend");
- # ifdef emacs
- case before_dot:
- printf("/before_dot");
- break;
- case at_dot:
- printf("/at_dot");
- break;
- case after_dot:
- printf("/after_dot");
- break;
- case syntaxspec:
- printf("/syntaxspec");
- mcnt = *p++;
- printf("/%d", mcnt);
- break;
- case notsyntaxspec:
- printf("/notsyntaxspec");
- mcnt = *p++;
- printf("/%d", mcnt);
- break;
- # endif
- case wordchar:
- printf("/wordchar");
- break;
- case notwordchar:
- printf("/notwordchar");
- break;
- case begbuf:
- printf("/begbuf");
- break;
- case endbuf:
- printf("/endbuf");
- break;
- default:
- printf("?%d", *(p - 1));
- }
- putchar('\n');
- }
- printf("%d:\tend of pattern.\n", p - start);
- }
- void print_compiled_pattern(bufp)
- struct re_pattern_buffer *bufp;
- {
- unsigned char *buffer = bufp->buffer;
- print_partial_compiled_pattern(buffer, buffer + bufp->used);
- printf("%ld bytes used/%ld bytes allocated.\n",
- bufp->used, bufp->allocated);
- if (bufp->fastmap_accurate && bufp->fastmap) {
- printf("fastmap: ");
- print_fastmap(bufp->fastmap);
- }
- printf("re_nsub: %d\t", bufp->re_nsub);
- printf("regs_alloc: %d\t", bufp->regs_allocated);
- printf("can_be_null: %d\t", bufp->can_be_null);
- printf("newline_anchor: %d\n", bufp->newline_anchor);
- printf("no_sub: %d\t", bufp->no_sub);
- printf("not_bol: %d\t", bufp->not_bol);
- printf("not_eol: %d\t", bufp->not_eol);
- printf("syntax: %lx\n", bufp->syntax);
-
- }
- void print_double_string(where, string1, size1, string2, size2)
- const char *where;
- const char *string1;
- const char *string2;
- int size1;
- int size2;
- {
- int this_char;
- if (where == NULL)
- printf("(null)");
- else {
- if (FIRST_STRING_P(where)) {
- for (this_char = where - string1; this_char < size1;
- this_char++)
- putchar(string1[this_char]);
- where = string2;
- }
- for (this_char = where - string2; this_char < size2; this_char++)
- putchar(string2[this_char]);
- }
- }
- void printchar(c)
- int c;
- {
- putc(c, stderr);
- }
- #else
- # undef assert
- # define assert(e)
- # define DEBUG_STATEMENT(e)
- # define DEBUG_PRINT1(x)
- # define DEBUG_PRINT2(x1, x2)
- # define DEBUG_PRINT3(x1, x2, x3)
- # define DEBUG_PRINT4(x1, x2, x3, x4)
- # define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
- # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
- #endif
- reg_syntax_t re_syntax_options;
- reg_syntax_t re_set_syntax(syntax)
- reg_syntax_t syntax;
- {
- reg_syntax_t ret = re_syntax_options;
- re_syntax_options = syntax;
- #ifdef DEBUG
- if (syntax & RE_DEBUG)
- debug = 1;
- else if (debug)
- debug = 0;
- #endif
- return ret;
- }
- #ifdef _LIBC
- weak_alias(__re_set_syntax, re_set_syntax)
- #endif
- static const char re_error_msgid[] = {
- #define REG_NOERROR_IDX 0
- gettext_noop("Success")
- "\0"
- #define REG_NOMATCH_IDX (REG_NOERROR_IDX + sizeof "Success")
- gettext_noop("No match")
- "\0"
- #define REG_BADPAT_IDX (REG_NOMATCH_IDX + sizeof "No match")
- gettext_noop("Invalid regular expression")
- "\0"
- #define REG_ECOLLATE_IDX (REG_BADPAT_IDX + sizeof "Invalid regular expression")
- gettext_noop("Invalid collation character")
- "\0"
- #define REG_ECTYPE_IDX (REG_ECOLLATE_IDX + sizeof "Invalid collation character")
- gettext_noop("Invalid character class name")
- "\0"
- #define REG_EESCAPE_IDX (REG_ECTYPE_IDX + sizeof "Invalid character class name")
- gettext_noop("Trailing backslash")
- "\0"
- #define REG_ESUBREG_IDX (REG_EESCAPE_IDX + sizeof "Trailing backslash")
- gettext_noop("Invalid back reference")
- "\0"
- #define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference")
- gettext_noop("Unmatched [ or [^")
- "\0"
- #define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^")
- gettext_noop("Unmatched ( or \\(")
- "\0"
- #define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")
- gettext_noop("Unmatched \\{")
- "\0"
- #define REG_BADBR_IDX (REG_EBRACE_IDX + sizeof "Unmatched \\{")
- gettext_noop("Invalid content of \\{\\}")
- "\0"
- #define REG_ERANGE_IDX (REG_BADBR_IDX + sizeof "Invalid content of \\{\\}")
- gettext_noop("Invalid range end")
- "\0"
- #define REG_ESPACE_IDX (REG_ERANGE_IDX + sizeof "Invalid range end")
- gettext_noop("Memory exhausted")
- "\0"
- #define REG_BADRPT_IDX (REG_ESPACE_IDX + sizeof "Memory exhausted")
- gettext_noop("Invalid preceding regular expression")
- "\0"
- #define REG_EEND_IDX (REG_BADRPT_IDX + sizeof "Invalid preceding regular expression")
- gettext_noop("Premature end of regular expression")
- "\0"
- #define REG_ESIZE_IDX (REG_EEND_IDX + sizeof "Premature end of regular expression")
- gettext_noop("Regular expression too big")
- "\0"
- #define REG_ERPAREN_IDX (REG_ESIZE_IDX + sizeof "Regular expression too big")
- gettext_noop("Unmatched ) or \\)")
- };
- static const size_t re_error_msgid_idx[] = {
- REG_NOERROR_IDX,
- REG_NOMATCH_IDX,
- REG_BADPAT_IDX,
- REG_ECOLLATE_IDX,
- REG_ECTYPE_IDX,
- REG_EESCAPE_IDX,
- REG_ESUBREG_IDX,
- REG_EBRACK_IDX,
- REG_EPAREN_IDX,
- REG_EBRACE_IDX,
- REG_BADBR_IDX,
- REG_ERANGE_IDX,
- REG_ESPACE_IDX,
- REG_BADRPT_IDX,
- REG_EEND_IDX,
- REG_ESIZE_IDX,
- REG_ERPAREN_IDX
- };
- #define MATCH_MAY_ALLOCATE
- #ifdef __GNUC__
- # undef C_ALLOCA
- #endif
- #if (defined C_ALLOCA || defined REGEX_MALLOC) && defined emacs
- # undef MATCH_MAY_ALLOCATE
- #endif
- #ifndef INIT_FAILURE_ALLOC
- # define INIT_FAILURE_ALLOC 5
- #endif
- #ifdef INT_IS_16BIT
- # if defined MATCH_MAY_ALLOCATE
- long int re_max_failures = 4000;
- # else
- long int re_max_failures = 2000;
- # endif
- union fail_stack_elt {
- unsigned char *pointer;
- long int integer;
- };
- typedef union fail_stack_elt fail_stack_elt_t;
- typedef struct {
- fail_stack_elt_t *stack;
- unsigned long int size;
- unsigned long int avail;
- } fail_stack_type;
- #else
- # if defined MATCH_MAY_ALLOCATE
- int re_max_failures = 20000;
- # else
- int re_max_failures = 2000;
- # endif
- union fail_stack_elt {
- unsigned char *pointer;
- int integer;
- };
- typedef union fail_stack_elt fail_stack_elt_t;
- typedef struct {
- fail_stack_elt_t *stack;
- unsigned size;
- unsigned avail;
- } fail_stack_type;
- #endif
- #define FAIL_STACK_EMPTY() (fail_stack.avail == 0)
- #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
- #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
- #ifdef MATCH_MAY_ALLOCATE
- # define INIT_FAIL_STACK() \
- do { \
- fail_stack.stack = (fail_stack_elt_t *) \
- REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \
- \
- if (fail_stack.stack == NULL) \
- return -2; \
- \
- fail_stack.size = INIT_FAILURE_ALLOC; \
- fail_stack.avail = 0; \
- } while (0)
- # define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack)
- #else
- # define INIT_FAIL_STACK() \
- do { \
- fail_stack.avail = 0; \
- } while (0)
- # define RESET_FAIL_STACK()
- #endif
- #define DOUBLE_FAIL_STACK(fail_stack) \
- ((fail_stack).size > (unsigned) (re_max_failures * MAX_FAILURE_ITEMS) \
- ? 0 \
- : ((fail_stack).stack = (fail_stack_elt_t *) \
- REGEX_REALLOCATE_STACK ((fail_stack).stack, \
- (fail_stack).size * sizeof (fail_stack_elt_t), \
- ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \
- \
- (fail_stack).stack == NULL \
- ? 0 \
- : ((fail_stack).size <<= 1, \
- 1)))
- #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \
- ((FAIL_STACK_FULL () \
- && !DOUBLE_FAIL_STACK (FAIL_STACK)) \
- ? 0 \
- : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER, \
- 1))
- #define PUSH_FAILURE_POINTER(item) \
- fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item)
- #define PUSH_FAILURE_INT(item) \
- fail_stack.stack[fail_stack.avail++].integer = (item)
- #define PUSH_FAILURE_ELT(item) \
- fail_stack.stack[fail_stack.avail++] = (item)
- #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
- #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
- #define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
- #ifdef DEBUG
- # define DEBUG_PUSH PUSH_FAILURE_INT
- # define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT ()
- #else
- # define DEBUG_PUSH(item)
- # define DEBUG_POP(item_addr)
- #endif
- #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \
- do { \
- char *destination; \
-
- \
-
- \
- active_reg_t this_reg; \
- \
- DEBUG_STATEMENT (failure_id++); \
- DEBUG_STATEMENT (nfailure_points_pushed++); \
- DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \
- DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\
- DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
- \
- DEBUG_PRINT2 (" slots needed: %ld\n", NUM_FAILURE_ITEMS); \
- DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \
- \
- \
- while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \
- { \
- if (!DOUBLE_FAIL_STACK (fail_stack)) \
- return failure_code; \
- \
- DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \
- (fail_stack).size); \
- DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\
- } \
- \
- \
- DEBUG_PRINT1 ("\n"); \
- \
- if (1) \
- for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \
- this_reg++) \
- { \
- DEBUG_PRINT2 (" Pushing reg: %lu\n", this_reg); \
- DEBUG_STATEMENT (num_regs_pushed++); \
- \
- DEBUG_PRINT2 (" start: %p\n", regstart[this_reg]); \
- PUSH_FAILURE_POINTER (regstart[this_reg]); \
- \
- DEBUG_PRINT2 (" end: %p\n", regend[this_reg]); \
- PUSH_FAILURE_POINTER (regend[this_reg]); \
- \
- DEBUG_PRINT2 (" info: %p\n ", \
- reg_info[this_reg].word.pointer); \
- DEBUG_PRINT2 (" match_null=%d", \
- REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
- DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
- DEBUG_PRINT2 (" matched_something=%d", \
- MATCHED_SOMETHING (reg_info[this_reg])); \
- DEBUG_PRINT2 (" ever_matched=%d", \
- EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
- DEBUG_PRINT1 ("\n"); \
- PUSH_FAILURE_ELT (reg_info[this_reg].word); \
- } \
- \
- DEBUG_PRINT2 (" Pushing low active reg: %ld\n", lowest_active_reg);\
- PUSH_FAILURE_INT (lowest_active_reg); \
- \
- DEBUG_PRINT2 (" Pushing high active reg: %ld\n", highest_active_reg);\
- PUSH_FAILURE_INT (highest_active_reg); \
- \
- DEBUG_PRINT2 (" Pushing pattern %p:\n", pattern_place); \
- DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
- PUSH_FAILURE_POINTER (pattern_place); \
- \
- DEBUG_PRINT2 (" Pushing string %p: `", string_place); \
- DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
- size2); \
- DEBUG_PRINT1 ("'\n"); \
- PUSH_FAILURE_POINTER (string_place); \
- \
- DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \
- DEBUG_PUSH (failure_id); \
- } while (0)
- #define NUM_REG_ITEMS 3
- #ifdef DEBUG
- # define NUM_NONREG_ITEMS 5
- #else
- # define NUM_NONREG_ITEMS 4
- #endif
- #define MAX_FAILURE_ITEMS (5 * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
- #define NUM_FAILURE_ITEMS \
- (((0 \
- ? 0 : highest_active_reg - lowest_active_reg + 1) \
- * NUM_REG_ITEMS) \
- + NUM_NONREG_ITEMS)
- #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
- #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
- { \
- DEBUG_STATEMENT (unsigned failure_id;) \
- active_reg_t this_reg; \
- const unsigned char *string_temp; \
- \
- assert (!FAIL_STACK_EMPTY ()); \
- \
- \
- DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
- DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \
- DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \
- \
- assert (fail_stack.avail >= NUM_NONREG_ITEMS); \
- \
- DEBUG_POP (&failure_id); \
- DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \
- \
-
- \
- string_temp = POP_FAILURE_POINTER (); \
- if (string_temp != NULL) \
- str = (const char *) string_temp; \
- \
- DEBUG_PRINT2 (" Popping string %p: `", str); \
- DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
- DEBUG_PRINT1 ("'\n"); \
- \
- pat = (unsigned char *) POP_FAILURE_POINTER (); \
- DEBUG_PRINT2 (" Popping pattern %p:\n", pat); \
- DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
- \
- \
- high_reg = (active_reg_t) POP_FAILURE_INT (); \
- DEBUG_PRINT2 (" Popping high active reg: %ld\n", high_reg); \
- \
- low_reg = (active_reg_t) POP_FAILURE_INT (); \
- DEBUG_PRINT2 (" Popping low active reg: %ld\n", low_reg); \
- \
- if (1) \
- for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \
- { \
- DEBUG_PRINT2 (" Popping reg: %ld\n", this_reg); \
- \
- reg_info[this_reg].word = POP_FAILURE_ELT (); \
- DEBUG_PRINT2 (" info: %p\n", \
- reg_info[this_reg].word.pointer); \
- \
- regend[this_reg] = (const char *) POP_FAILURE_POINTER (); \
- DEBUG_PRINT2 (" end: %p\n", regend[this_reg]); \
- \
- regstart[this_reg] = (const char *) POP_FAILURE_POINTER (); \
- DEBUG_PRINT2 (" start: %p\n", regstart[this_reg]); \
- } \
- else \
- { \
- for (this_reg = highest_active_reg; this_reg > high_reg; this_reg--) \
- { \
- reg_info[this_reg].word.integer = 0; \
- regend[this_reg] = 0; \
- regstart[this_reg] = 0; \
- } \
- highest_active_reg = high_reg; \
- } \
- \
- set_regs_matched_done = 0; \
- DEBUG_STATEMENT (nfailure_points_popped++); \
- }
- typedef union {
- fail_stack_elt_t word;
- struct {
-
- #define MATCH_NULL_UNSET_VALUE 3
- unsigned match_null_string_p:2;
- unsigned is_active:1;
- unsigned matched_something:1;
- unsigned ever_matched_something:1;
- } bits;
- } register_info_type;
- #define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p)
- #define IS_ACTIVE(R) ((R).bits.is_active)
- #define MATCHED_SOMETHING(R) ((R).bits.matched_something)
- #define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something)
- #define SET_REGS_MATCHED() \
- do \
- { \
- if (!set_regs_matched_done) \
- { \
- active_reg_t r; \
- set_regs_matched_done = 1; \
- for (r = lowest_active_reg; r <= highest_active_reg; r++) \
- { \
- MATCHED_SOMETHING (reg_info[r]) \
- = EVER_MATCHED_SOMETHING (reg_info[r]) \
- = 1; \
- } \
- } \
- } \
- while (0)
- static char reg_unset_dummy;
- #define REG_UNSET_VALUE (®_unset_dummy)
- #define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
- static reg_errcode_t regex_compile
- _RE_ARGS(
- (const char *pattern, size_t size, reg_syntax_t syntax,
- struct re_pattern_buffer * bufp));
- static void store_op1
- _RE_ARGS((re_opcode_t op, unsigned char *loc, int arg));
- static void store_op2
- _RE_ARGS((re_opcode_t op, unsigned char *loc, int arg1, int arg2));
- static void insert_op1
- _RE_ARGS(
- (re_opcode_t op, unsigned char *loc, int arg,
- unsigned char *end));
- static void insert_op2
- _RE_ARGS(
- (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
- unsigned char *end));
- static boolean at_begline_loc_p
- _RE_ARGS((const char *pattern, const char *p, reg_syntax_t syntax));
- static boolean at_endline_loc_p
- _RE_ARGS((const char *p, const char *pend, reg_syntax_t syntax));
- static reg_errcode_t compile_range
- _RE_ARGS(
- (const char **p_ptr, const char *pend, char *translate,
- reg_syntax_t syntax, unsigned char *b));
- #ifndef PATFETCH
- # define PATFETCH(c) \
- do {if (p == pend) return REG_EEND; \
- c = (unsigned char) *p++; \
- if (translate) c = (unsigned char) translate[c]; \
- } while (0)
- #endif
- #define PATFETCH_RAW(c) \
- do {if (p == pend) return REG_EEND; \
- c = (unsigned char) *p++; \
- } while (0)
- #define PATUNFETCH p--
- #ifndef TRANSLATE
- # define TRANSLATE(d) \
- (translate ? (char) translate[(unsigned char) (d)] : (d))
- #endif
- #define INIT_BUF_SIZE 32
- #define GET_BUFFER_SPACE(n) \
- while ((unsigned long) (b - bufp->buffer + (n)) > bufp->allocated) \
- EXTEND_BUFFER ()
- #define BUF_PUSH(c) \
- do { \
- GET_BUFFER_SPACE (1); \
- *b++ = (unsigned char) (c); \
- } while (0)
- #define BUF_PUSH_2(c1, c2) \
- do { \
- GET_BUFFER_SPACE (2); \
- *b++ = (unsigned char) (c1); \
- *b++ = (unsigned char) (c2); \
- } while (0)
- #define BUF_PUSH_3(c1, c2, c3) \
- do { \
- GET_BUFFER_SPACE (3); \
- *b++ = (unsigned char) (c1); \
- *b++ = (unsigned char) (c2); \
- *b++ = (unsigned char) (c3); \
- } while (0)
- #define STORE_JUMP(op, loc, to) \
- store_op1 (op, loc, (int) ((to) - (loc) - 3))
- #define STORE_JUMP2(op, loc, to, arg) \
- store_op2 (op, loc, (int) ((to) - (loc) - 3), arg)
- #define INSERT_JUMP(op, loc, to) \
- insert_op1 (op, loc, (int) ((to) - (loc) - 3), b)
- #define INSERT_JUMP2(op, loc, to, arg) \
- insert_op2 (op, loc, (int) ((to) - (loc) - 3), arg, b)
- #if defined _MSC_VER && !defined WIN32
- # define MAX_BUF_SIZE 65500L
- # define REALLOC(p,s) realloc ((p), (size_t) (s))
- #else
- # define MAX_BUF_SIZE (1L << 16)
- # define REALLOC(p,s) realloc ((p), (s))
- #endif
- #define EXTEND_BUFFER() \
- do { \
- unsigned char *old_buffer = bufp->buffer; \
- if (bufp->allocated == MAX_BUF_SIZE) \
- return REG_ESIZE; \
- bufp->allocated <<= 1; \
- if (bufp->allocated > MAX_BUF_SIZE) \
- bufp->allocated = MAX_BUF_SIZE; \
- bufp->buffer = (unsigned char *) REALLOC (bufp->buffer, bufp->allocated);\
- if (bufp->buffer == NULL) \
- return REG_ESPACE; \
- \
- if (old_buffer != bufp->buffer) \
- { \
- b = (b - old_buffer) + bufp->buffer; \
- begalt = (begalt - old_buffer) + bufp->buffer; \
- if (fixup_alt_jump) \
- fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\
- if (laststart) \
- laststart = (laststart - old_buffer) + bufp->buffer; \
- if (pending_exact) \
- pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
- } \
- } while (0)
- #define MAX_REGNUM 255
- typedef unsigned regnum_t;
- typedef long pattern_offset_t;
- typedef struct {
- pattern_offset_t begalt_offset;
- pattern_offset_t fixup_alt_jump;
- pattern_offset_t inner_group_offset;
- pattern_offset_t laststart_offset;
- regnum_t regnum;
- } compile_stack_elt_t;
- typedef struct {
- compile_stack_elt_t *stack;
- unsigned size;
- unsigned avail;
- } compile_stack_type;
- #define INIT_COMPILE_STACK_SIZE 32
- #define COMPILE_STACK_EMPTY (compile_stack.avail == 0)
- #define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size)
- #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
- #define SET_LIST_BIT(c) \
- (b[((unsigned char) (c)) / BYTEWIDTH] \
- |= 1 << (((unsigned char) c) % BYTEWIDTH))
- #define GET_UNSIGNED_NUMBER(num) \
- { if (p != pend) \
- { \
- PATFETCH (c); \
- while ('0' <= c && c <= '9') \
- { \
- if (num < 0) \
- num = 0; \
- num = num * 10 + c - '0'; \
- if (p == pend) \
- break; \
- PATFETCH (c); \
- } \
- } \
- }
- #if defined _LIBC || WIDE_CHAR_SUPPORT
- # ifdef CHARCLASS_NAME_MAX
- # define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX
- # else
- # define CHAR_CLASS_MAX_LENGTH 256
- # endif
- # ifdef _LIBC
- # define IS_CHAR_CLASS(string) __wctype (string)
- # else
- # define IS_CHAR_CLASS(string) wctype (string)
- # endif
- #else
- # define CHAR_CLASS_MAX_LENGTH 6
- # define IS_CHAR_CLASS(string) \
- (STREQ (string, "alpha") || STREQ (string, "upper") \
- || STREQ (string, "lower") || STREQ (string, "digit") \
- || STREQ (string, "alnum") || STREQ (string, "xdigit") \
- || STREQ (string, "space") || STREQ (string, "print") \
- || STREQ (string, "punct") || STREQ (string, "graph") \
- || STREQ (string, "cntrl") || STREQ (string, "blank"))
- #endif
- #ifndef MATCH_MAY_ALLOCATE
- static fail_stack_type fail_stack;
- static int regs_allocated_size;
- static const char **regstart, **regend;
- static const char **old_regstart, **old_regend;
- static const char **best_regstart, **best_regend;
- static register_info_type *reg_info;
- static const char **reg_dummy;
- static register_info_type *reg_info_dummy;
- static regex_grow_registers(num_regs)
- int num_regs;
- {
- if (num_regs > regs_allocated_size) {
- RETALLOC_IF(regstart, num_regs, const char *);
- RETALLOC_IF(regend, num_regs, const char *);
- RETALLOC_IF(old_regstart, num_regs, const char *);
- RETALLOC_IF(old_regend, num_regs, const char *);
- RETALLOC_IF(best_regstart, num_regs, const char *);
- RETALLOC_IF(best_regend, num_regs, const char *);
- RETALLOC_IF(reg_info, num_regs, register_info_type);
- RETALLOC_IF(reg_dummy, num_regs, const char *);
- RETALLOC_IF(reg_info_dummy, num_regs, register_info_type);
- regs_allocated_size = num_regs;
- }
- }
- #endif
- static boolean group_in_compile_stack _RE_ARGS((compile_stack_type
- compile_stack,
- regnum_t regnum));
- #define FREE_STACK_RETURN(value) \
- return (free (compile_stack.stack), value)
- static reg_errcode_t regex_compile(pattern, size, syntax, bufp)
- const char *pattern;
- size_t size;
- reg_syntax_t syntax;
- struct re_pattern_buffer *bufp;
- {
-
- register unsigned char c, c1;
-
- const char *p1;
-
- register unsigned char *b;
-
- compile_stack_type compile_stack;
-
- const char *p = pattern;
- const char *pend = pattern + size;
-
- RE_TRANSLATE_TYPE translate = bufp->translate;
-
- unsigned char *pending_exact = 0;
-
- unsigned char *laststart = 0;
-
- unsigned char *begalt;
-
- const char *beg_interval;
-
- unsigned char *fixup_alt_jump = 0;
-
- regnum_t regnum = 0;
- #ifdef DEBUG
- DEBUG_PRINT1("\nCompiling pattern: ");
- if (debug) {
- unsigned debug_count;
- for (debug_count = 0; debug_count < size; debug_count++)
- putchar(pattern[debug_count]);
- putchar('\n');
- }
- #endif
-
- compile_stack.stack =
- TALLOC(INIT_COMPILE_STACK_SIZE, compile_stack_elt_t);
- if (compile_stack.stack == NULL)
- return REG_ESPACE;
- compile_stack.size = INIT_COMPILE_STACK_SIZE;
- compile_stack.avail = 0;
-
- bufp->syntax = syntax;
- bufp->fastmap_accurate = 0;
- bufp->not_bol = bufp->not_eol = 0;
-
- bufp->used = 0;
-
- bufp->re_nsub = 0;
- #if !defined emacs && !defined SYNTAX_TABLE
-
- init_syntax_once();
- #endif
- if (bufp->allocated == 0) {
- if (bufp->buffer) {
- RETALLOC(bufp->buffer, INIT_BUF_SIZE, unsigned char);
- } else {
- bufp->buffer = TALLOC(INIT_BUF_SIZE, unsigned char);
- }
- if (!bufp->buffer)
- FREE_STACK_RETURN(REG_ESPACE);
- bufp->allocated = INIT_BUF_SIZE;
- }
- begalt = b = bufp->buffer;
-
- while (p != pend) {
- PATFETCH(c);
- switch (c) {
- case '^':
- {
- if (
- p == pattern + 1
-
- || syntax & RE_CONTEXT_INDEP_ANCHORS
-
- || at_begline_loc_p(pattern, p, syntax))
- BUF_PUSH(begline);
- else
- goto normal_char;
- }
- break;
- case '$':
- {
- if (
- p == pend
-
- || syntax & RE_CONTEXT_INDEP_ANCHORS
-
- || at_endline_loc_p(p, pend, syntax))
- BUF_PUSH(endline);
- else
- goto normal_char;
- }
- break;
- case '+':
- case '?':
- if ((syntax & RE_BK_PLUS_QM)
- || (syntax & RE_LIMITED_OPS))
- goto normal_char;
- handle_plus:
- case '*':
-
- if (!laststart) {
- if (syntax & RE_CONTEXT_INVALID_OPS)
- FREE_STACK_RETURN(REG_BADRPT);
- else if (!(syntax & RE_CONTEXT_INDEP_OPS))
- goto normal_char;
- }
- {
-
- boolean keep_string_p = false;
-
- char zero_times_ok = 0, many_times_ok = 0;
-
- for (;;) {
- zero_times_ok |= c != '+';
- many_times_ok |= c != '?';
- if (p == pend)
- break;
- PATFETCH(c);
- if (c == '*'
- || (!(syntax & RE_BK_PLUS_QM)
- && (c == '+' || c == '?')));
- else if (syntax & RE_BK_PLUS_QM && c == '\\') {
- if (p == pend)
- FREE_STACK_RETURN(REG_EESCAPE);
- PATFETCH(c1);
- if (!(c1 == '+' || c1 == '?')) {
- PATUNFETCH;
- PATUNFETCH;
- break;
- }
- c = c1;
- } else {
- PATUNFETCH;
- break;
- }
-
- }
-
- if (!laststart)
- break;
-
- if (many_times_ok) {
- assert(p - 1 > pattern);
-
- GET_BUFFER_SPACE(3);
-
- if (TRANSLATE(*(p - 2)) == TRANSLATE('.')
- && zero_times_ok
- && p < pend && TRANSLATE(*p) == TRANSLATE('\n')
- && !(syntax & RE_DOT_NEWLINE)) {
- STORE_JUMP(jump, b, laststart);
- keep_string_p = true;
- } else
-
- STORE_JUMP(maybe_pop_jump, b, laststart - 3);
-
- b += 3;
- }
-
- GET_BUFFER_SPACE(3);
- INSERT_JUMP(keep_string_p ? on_failure_keep_string_jump
- : on_failure_jump, laststart, b + 3);
- pending_exact = 0;
- b += 3;
- if (!zero_times_ok) {
-
- GET_BUFFER_SPACE(3);
- INSERT_JUMP(dummy_failure_jump, laststart,
- laststart + 6);
- b += 3;
- }
- }
- break;
- case '.':
- laststart = b;
- BUF_PUSH(anychar);
- break;
- case '[':
- {
- boolean had_char_class = false;
- if (p == pend)
- FREE_STACK_RETURN(REG_EBRACK);
-
- GET_BUFFER_SPACE(34);
- laststart = b;
-
- BUF_PUSH(*p == '^' ? charset_not : charset);
- if (*p == '^')
- p++;
-
- p1 = p;
-
- BUF_PUSH((1 << BYTEWIDTH) / BYTEWIDTH);
-
- bzero(b, (1 << BYTEWIDTH) / BYTEWIDTH);
-
- if ((re_opcode_t) b[-2] == charset_not
- && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) SET_LIST_BIT('\n');
-
- for (;;) {
- if (p == pend)
- FREE_STACK_RETURN(REG_EBRACK);
- PATFETCH(c);
-
- if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') {
- if (p == pend)
- FREE_STACK_RETURN(REG_EESCAPE);
- PATFETCH(c1);
- SET_LIST_BIT(c1);
- continue;
- }
-
- if (c == ']' && p != p1 + 1)
- break;
-
- if (had_char_class && c == '-' && *p != ']')
- FREE_STACK_RETURN(REG_ERANGE);
-
- if (c == '-' && !(p - 2 >= pattern && p[-2] == '[')
- && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
- && *p != ']') {
- reg_errcode_t ret
- = compile_range(&p, pend, translate, syntax, b);
- if (ret != REG_NOERROR)
- FREE_STACK_RETURN(ret);
- }
- else if (p[0] == '-' && p[1] != ']') {
- reg_errcode_t ret;
-
- PATFETCH(c1);
- ret = compile_range(&p, pend, translate, syntax, b);
- if (ret != REG_NOERROR)
- FREE_STACK_RETURN(ret);
- }
-
- else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':') {
- char str[CHAR_CLASS_MAX_LENGTH + 1];
- PATFETCH(c);
- c1 = 0;
-
- if (p == pend)
- FREE_STACK_RETURN(REG_EBRACK);
- for (;;) {
- PATFETCH(c);
- if ((c == ':' && *p == ']') || p == pend)
- break;
- if (c1 < CHAR_CLASS_MAX_LENGTH)
- str[c1++] = c;
- else
-
- str[0] = '\0';
- }
- str[c1] = '\0';
-
- if (c == ':' && *p == ']') {
- #if defined _LIBC || WIDE_CHAR_SUPPORT
- boolean is_lower = STREQ(str, "lower");
- boolean is_upper = STREQ(str, "upper");
- wctype_t wt;
- int ch;
- wt = IS_CHAR_CLASS(str);
- if (wt == 0)
- FREE_STACK_RETURN(REG_ECTYPE);
-
- PATFETCH(c);
- if (p == pend)
- FREE_STACK_RETURN(REG_EBRACK);
- for (ch = 0; ch < 1 << BYTEWIDTH; ++ch) {
- # ifdef _LIBC
- if (__iswctype(__btowc(ch), wt))
- SET_LIST_BIT(ch);
- # else
- if (iswctype(btowc(ch), wt))
- SET_LIST_BIT(ch);
- # endif
- if (translate && (is_upper || is_lower)
- && (ISUPPER(ch) || ISLOWER(ch)))
- SET_LIST_BIT(ch);
- }
- had_char_class = true;
- #else
- int ch;
- boolean is_alnum = STREQ(str, "alnum");
- boolean is_alpha = STREQ(str, "alpha");
- boolean is_blank = STREQ(str, "blank");
- boolean is_cntrl = STREQ(str, "cntrl");
- boolean is_digit = STREQ(str, "digit");
- boolean is_graph = STREQ(str, "graph");
- boolean is_lower = STREQ(str, "lower");
- boolean is_print = STREQ(str, "print");
- boolean is_punct = STREQ(str, "punct");
- boolean is_space = STREQ(str, "space");
- boolean is_upper = STREQ(str, "upper");
- boolean is_xdigit = STREQ(str, "xdigit");
- if (!IS_CHAR_CLASS(str))
- FREE_STACK_RETURN(REG_ECTYPE);
-
- PATFETCH(c);
- if (p == pend)
- FREE_STACK_RETURN(REG_EBRACK);
- for (ch = 0; ch < 1 << BYTEWIDTH; ch++) {
-
- if ((is_alnum && ISALNUM(ch))
- || (is_alpha && ISALPHA(ch))
- || (is_blank && ISBLANK(ch))
- || (is_cntrl && ISCNTRL(ch)))
- SET_LIST_BIT(ch);
- if ((is_digit && ISDIGIT(ch))
- || (is_graph && ISGRAPH(ch))
- || (is_lower && ISLOWER(ch))
- || (is_print && ISPRINT(ch)))
- SET_LIST_BIT(ch);
- if ((is_punct && ISPUNCT(ch))
- || (is_space && ISSPACE(ch))
- || (is_upper && ISUPPER(ch))
- || (is_xdigit && ISXDIGIT(ch)))
- SET_LIST_BIT(ch);
- if (translate && (is_upper || is_lower)
- && (ISUPPER(ch) || ISLOWER(ch)))
- SET_LIST_BIT(ch);
- }
- had_char_class = true;
- #endif
- } else {
- c1++;
- while (c1--)
- PATUNFETCH;
- SET_LIST_BIT('[');
- SET_LIST_BIT(':');
- had_char_class = false;
- }
- } else {
- had_char_class = false;
- SET_LIST_BIT(c);
- }
- }
-
- while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
- b[-1]--;
- b += b[-1];
- }
- break;
- case '(':
- if (syntax & RE_NO_BK_PARENS)
- goto handle_open;
- else
- goto normal_char;
- case ')':
- if (syntax & RE_NO_BK_PARENS)
- goto handle_close;
- else
- goto normal_char;
- case '\n':
- if (syntax & RE_NEWLINE_ALT)
- goto handle_alt;
- else
- goto normal_char;
- case '|':
- if (syntax & RE_NO_BK_VBAR)
- goto handle_alt;
- else
- goto normal_char;
- case '{':
- if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES)
- goto handle_interval;
- else
- goto normal_char;
- case '\\':
- if (p == pend)
- FREE_STACK_RETURN(REG_EESCAPE);
-
- PATFETCH_RAW(c);
- switch (c) {
- case '(':
- if (syntax & RE_NO_BK_PARENS)
- goto normal_backslash;
- handle_open:
- bufp->re_nsub++;
- regnum++;
- if (COMPILE_STACK_FULL) {
- RETALLOC(compile_stack.stack, compile_stack.size << 1,
- compile_stack_elt_t);
- if (compile_stack.stack == NULL)
- return REG_ESPACE;
- compile_stack.size <<= 1;
- }
-
- COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
- COMPILE_STACK_TOP.fixup_alt_jump
- =
- fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
- COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer;
- COMPILE_STACK_TOP.regnum = regnum;
-
- if (regnum <= MAX_REGNUM) {
- COMPILE_STACK_TOP.inner_group_offset =
- b - bufp->buffer + 2;
- BUF_PUSH_3(start_memory, regnum, 0);
- }
- compile_stack.avail++;
- fixup_alt_jump = 0;
- laststart = 0;
- begalt = b;
-
- pending_exact = 0;
- break;
- case ')':
- if (syntax & RE_NO_BK_PARENS)
- goto normal_backslash;
- if (COMPILE_STACK_EMPTY) {
- if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
- goto normal_backslash;
- else
- FREE_STACK_RETURN(REG_ERPAREN);
- }
- handle_close:
- if (fixup_alt_jump) {
- BUF_PUSH(push_dummy_failure);
-
- STORE_JUMP(jump_past_alt, fixup_alt_jump, b - 1);
- }
-
- if (COMPILE_STACK_EMPTY) {
- if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
- goto normal_char;
- else
- FREE_STACK_RETURN(REG_ERPAREN);
- }
-
- assert(compile_stack.avail != 0);
- {
-
- regnum_t this_group_regnum;
- compile_stack.avail--;
- begalt =
- bufp->buffer + COMPILE_STACK_TOP.begalt_offset;
- fixup_alt_jump =
- COMPILE_STACK_TOP.fixup_alt_jump ? bufp->buffer +
- COMPILE_STACK_TOP.fixup_alt_jump - 1 : 0;
- laststart =
- bufp->buffer + COMPILE_STACK_TOP.laststart_offset;
- this_group_regnum = COMPILE_STACK_TOP.regnum;
-
- pending_exact = 0;
-
- if (this_group_regnum <= MAX_REGNUM) {
- unsigned char *inner_group_loc
- =
- bufp->buffer +
- COMPILE_STACK_TOP.inner_group_offset;
- *inner_group_loc = regnum - this_group_regnum;
- BUF_PUSH_3(stop_memory, this_group_regnum,
- regnum - this_group_regnum);
- }
- }
- break;
- case '|':
- if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR)
- goto normal_backslash;
- handle_alt:
- if (syntax & RE_LIMITED_OPS)
- goto normal_char;
-
- GET_BUFFER_SPACE(3);
- INSERT_JUMP(on_failure_jump, begalt, b + 6);
- pending_exact = 0;
- b += 3;
-
- if (fixup_alt_jump)
- STORE_JUMP(jump_past_alt, fixup_alt_jump, b);
-
- fixup_alt_jump = b;
- GET_BUFFER_SPACE(3);
- b += 3;
- laststart = 0;
- begalt = b;
- break;
- case '{':
-
- if (!(syntax & RE_INTERVALS)
-
- || ((syntax & RE_INTERVALS)
- && (syntax & RE_NO_BK_BRACES)) || (p - 2 == pattern
- && p == pend))
- goto normal_backslash;
- handle_interval:
- {
-
-
- int lower_bound = -1, upper_bound = -1;
- beg_interval = p - 1;
- if (p == pend) {
- if (!(syntax & RE_INTERVALS)
- && (syntax & RE_NO_BK_BRACES)) goto
- unfetch_interval;
- else
- FREE_STACK_RETURN(REG_EBRACE);
- }
- GET_UNSIGNED_NUMBER(lower_bound);
- if (c == ',') {
- GET_UNSIGNED_NUMBER(upper_bound);
- if ((!(syntax & RE_NO_BK_BRACES) && c != '\\')
- || ((syntax & RE_NO_BK_BRACES) && c != '}'))
- FREE_STACK_RETURN(REG_BADBR);
- if (upper_bound < 0)
- upper_bound = RE_DUP_MAX;
- } else
-
- upper_bound = lower_bound;
- if (lower_bound < 0 || upper_bound > RE_DUP_MAX
- || lower_bound > upper_bound) {
- if (!(syntax & RE_INTERVALS)
- && (syntax & RE_NO_BK_BRACES)) goto
- unfetch_interval;
- else
- FREE_STACK_RETURN(REG_BADBR);
- }
- if (!(syntax & RE_NO_BK_BRACES)) {
- if (c != '\\')
- FREE_STACK_RETURN(REG_EBRACE);
- PATFETCH(c);
- }
- if (c != '}') {
- if (!(syntax & RE_INTERVALS)
- && (syntax & RE_NO_BK_BRACES)) goto
- unfetch_interval;
- else
- FREE_STACK_RETURN(REG_BADBR);
- }
-
-
- if (!laststart) {
- if (syntax & RE_CONTEXT_INVALID_OPS)
- FREE_STACK_RETURN(REG_BADRPT);
- else if (syntax & RE_CONTEXT_INDEP_OPS)
- laststart = b;
- else
- goto unfetch_interval;
- }
-
- if (upper_bound == 0) {
- GET_BUFFER_SPACE(3);
- INSERT_JUMP(jump, laststart, b + 3);
- b += 3;
- }
-
- else {
- unsigned nbytes = 10 + (upper_bound > 1) * 10;
- GET_BUFFER_SPACE(nbytes);
-
- INSERT_JUMP2(succeed_n, laststart,
- b + 5 + (upper_bound > 1) * 5,
- lower_bound);
- b += 5;
-
- insert_op2(set_number_at, laststart, 5,
- lower_bound, b);
- b += 5;
- if (upper_bound > 1) {
- STORE_JUMP2(jump_n, b, laststart + 5,
- upper_bound - 1);
- b += 5;
-
- insert_op2(set_number_at, laststart,
- b - laststart, upper_bound - 1, b);
- b += 5;
- }
- }
- pending_exact = 0;
- beg_interval = NULL;
- }
- break;
- unfetch_interval:
-
- assert(beg_interval);
- p = beg_interval;
- beg_interval = NULL;
-
- PATFETCH(c);
- if (!(syntax & RE_NO_BK_BRACES)) {
- if (p > pattern && p[-1] == '\\')
- goto normal_backslash;
- }
- goto normal_char;
- #ifdef emacs
-
- case '=':
- BUF_PUSH(at_dot);
- break;
- case 's':
- laststart = b;
- PATFETCH(c);
- BUF_PUSH_2(syntaxspec, syntax_spec_code[c]);
- break;
- case 'S':
- laststart = b;
- PATFETCH(c);
- BUF_PUSH_2(notsyntaxspec, syntax_spec_code[c]);
- break;
- #endif
- case 'w':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- laststart = b;
- BUF_PUSH(wordchar);
- break;
- case 'W':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- laststart = b;
- BUF_PUSH(notwordchar);
- break;
- case '<':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- BUF_PUSH(wordbeg);
- break;
- case '>':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- BUF_PUSH(wordend);
- break;
- case 'b':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- BUF_PUSH(wordbound);
- break;
- case 'B':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- BUF_PUSH(notwordbound);
- break;
- case '`':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- BUF_PUSH(begbuf);
- break;
- case '\'':
- if (syntax & RE_NO_GNU_OPS)
- goto normal_char;
- BUF_PUSH(endbuf);
- break;
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (syntax & RE_NO_BK_REFS)
- goto normal_char;
- c1 = c - '0';
- if (c1 > regnum)
- FREE_STACK_RETURN(REG_ESUBREG);
-
- if (group_in_compile_stack(compile_stack, (regnum_t) c1))
- goto normal_char;
- laststart = b;
- BUF_PUSH_2(duplicate, c1);
- break;
- case '+':
- case '?':
- if (syntax & RE_BK_PLUS_QM)
- goto handle_plus;
- else
- goto normal_backslash;
- default:
- normal_backslash:
-
- c = TRANSLATE(c);
- goto normal_char;
- }
- break;
- default:
-
- normal_char:
-
- if (!pending_exact
-
- || pending_exact + *pending_exact + 1 != b
-
- || *pending_exact == (1 << BYTEWIDTH) - 1
-
- || *p == '*' || *p == '^' || ((syntax & RE_BK_PLUS_QM)
- ? *p == '\\' && (p[1] == '+'
- || p[1] ==
- '?') : (*p
- ==
- '+'
- ||
- *p
- ==
- '?'))
- || ((syntax & RE_INTERVALS)
- && ((syntax & RE_NO_BK_BRACES)
- ? *p == '{' : (p[0] == '\\' && p[1] == '{')))) {
-
- laststart = b;
- BUF_PUSH_2(exactn, 0);
- pending_exact = b - 1;
- }
- BUF_PUSH(c);
- (*pending_exact)++;
- break;
- }
- }
-
- if (fixup_alt_jump)
- STORE_JUMP(jump_past_alt, fixup_alt_jump, b);
- if (!COMPILE_STACK_EMPTY)
- FREE_STACK_RETURN(REG_EPAREN);
-
- if (syntax & RE_NO_POSIX_BACKTRACKING)
- BUF_PUSH(succeed);
- free(compile_stack.stack);
-
- bufp->used = b - bufp->buffer;
- #ifdef DEBUG
- if (debug) {
- DEBUG_PRINT1("\nCompiled pattern: \n");
- print_compiled_pattern(bufp);
- }
- #endif
- #ifndef MATCH_MAY_ALLOCATE
-
- {
- int num_regs = bufp->re_nsub + 1;
-
- if (fail_stack.size < (2 * re_max_failures * MAX_FAILURE_ITEMS)) {
- fail_stack.size = (2 * re_max_failures * MAX_FAILURE_ITEMS);
- # ifdef emacs
- if (!fail_stack.stack)
- fail_stack.stack
- = (fail_stack_elt_t *) xmalloc(fail_stack.size
- *
- sizeof
- (fail_stack_elt_t));
- else
- fail_stack.stack =
- (fail_stack_elt_t *) xrealloc(fail_stack.stack,
- (fail_stack.size *
- sizeof
- (fail_stack_elt_t)));
- # else
- if (!fail_stack.stack)
- fail_stack.stack
- = (fail_stack_elt_t *) malloc(fail_stack.size
- *
- sizeof
- (fail_stack_elt_t));
- else
- fail_stack.stack =
- (fail_stack_elt_t *) realloc(fail_stack.stack,
- (fail_stack.size *
- sizeof
- (fail_stack_elt_t)));
- # endif
- }
- regex_grow_registers(num_regs);
- }
- #endif
- return REG_NOERROR;
- }
- static void store_op1(op, loc, arg)
- re_opcode_t op;
- unsigned char *loc;
- int arg;
- {
- *loc = (unsigned char) op;
- STORE_NUMBER(loc + 1, arg);
- }
- static void store_op2(op, loc, arg1, arg2)
- re_opcode_t op;
- unsigned char *loc;
- int arg1, arg2;
- {
- *loc = (unsigned char) op;
- STORE_NUMBER(loc + 1, arg1);
- STORE_NUMBER(loc + 3, arg2);
- }
- static void insert_op1(op, loc, arg, end)
- re_opcode_t op;
- unsigned char *loc;
- int arg;
- unsigned char *end;
- {
- register unsigned char *pfrom = end;
- register unsigned char *pto = end + 3;
- while (pfrom != loc)
- *--pto = *--pfrom;
- store_op1(op, loc, arg);
- }
- static void insert_op2(op, loc, arg1, arg2, end)
- re_opcode_t op;
- unsigned char *loc;
- int arg1, arg2;
- unsigned char *end;
- {
- register unsigned char *pfrom = end;
- register unsigned char *pto = end + 5;
- while (pfrom != loc)
- *--pto = *--pfrom;
- store_op2(op, loc, arg1, arg2);
- }
- static boolean at_begline_loc_p(pattern, p, syntax)
- const char *pattern, *p;
- reg_syntax_t syntax;
- {
- const char *prev = p - 2;
- boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
- return
-
- (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
-
- || (*prev == '|'
- && (syntax & RE_NO_BK_VBAR || prev_prev_backslash));
- }
- static boolean at_endline_loc_p(p, pend, syntax)
- const char *p, *pend;
- reg_syntax_t syntax;
- {
- const char *next = p;
- boolean next_backslash = *next == '\\';
- const char *next_next = p + 1 < pend ? p + 1 : 0;
- return
-
- (syntax & RE_NO_BK_PARENS ? *next == ')'
- : next_backslash && next_next && *next_next == ')')
-
- || (syntax & RE_NO_BK_VBAR ? *next == '|'
- : next_backslash && next_next && *next_next == '|');
- }
- static boolean group_in_compile_stack(compile_stack, regnum)
- compile_stack_type compile_stack;
- regnum_t regnum;
- {
- int this_element;
- for (this_element = compile_stack.avail - 1;
- this_element >= 0; this_element--)
- if (compile_stack.stack[this_element].regnum == regnum)
- return true;
- return false;
- }
- static reg_errcode_t compile_range(p_ptr, pend, translate, syntax, b)
- const char **p_ptr, *pend;
- RE_TRANSLATE_TYPE translate;
- reg_syntax_t syntax;
- unsigned char *b;
- {
- unsigned this_char;
- const char *p = *p_ptr;
- reg_errcode_t ret;
- char range_start[2];
- char range_end[2];
- char ch[2];
- if (p == pend)
- return REG_ERANGE;
-
- range_start[0] = p[-2];
- range_start[1] = '\0';
- range_end[0] = p[0];
- range_end[1] = '\0';
-
- (*p_ptr)++;
-
- ret = syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
-
- ch[1] = '\0';
- for (this_char = 0; this_char <= (unsigned char) -1; ++this_char) {
- ch[0] = this_char;
- if (strcoll(range_start, ch) <= 0 && strcoll(ch, range_end) <= 0) {
- SET_LIST_BIT(TRANSLATE(this_char));
- ret = REG_NOERROR;
- }
- }
- return ret;
- }
- int re_compile_fastmap(bufp)
- struct re_pattern_buffer *bufp;
- {
- int j, k;
- #ifdef MATCH_MAY_ALLOCATE
- fail_stack_type fail_stack;
- #endif
- #ifndef REGEX_MALLOC
- char *destination;
- #endif
- register char *fastmap = bufp->fastmap;
- unsigned char *pattern = bufp->buffer;
- unsigned char *p = pattern;
- register unsigned char *pend = pattern + bufp->used;
- #ifdef REL_ALLOC
-
- fail_stack_elt_t *failure_stack_ptr;
- #endif
-
- boolean path_can_be_null = true;
-
- boolean succeed_n_p = false;
- assert(fastmap != NULL && p != NULL);
- INIT_FAIL_STACK();
- bzero(fastmap, 1 << BYTEWIDTH);
- bufp->fastmap_accurate = 1;
- bufp->can_be_null = 0;
- while (1) {
- if (p == pend || *p == succeed) {
-
- if (!FAIL_STACK_EMPTY()) {
- bufp->can_be_null |= path_can_be_null;
-
- path_can_be_null = true;
- p = fail_stack.stack[--fail_stack.avail].pointer;
- continue;
- } else
- break;
- }
-
- assert(p < pend);
- switch (SWITCH_ENUM_CAST((re_opcode_t) * p++)) {
-
- case duplicate:
- bufp->can_be_null = 1;
- goto done;
-
- case exactn:
- fastmap[p[1]] = 1;
- break;
- case charset:
- for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
- if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
- fastmap[j] = 1;
- break;
- case charset_not:
-
- for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
- fastmap[j] = 1;
- for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
- if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
- fastmap[j] = 1;
- break;
- case wordchar:
- for (j = 0; j < (1 << BYTEWIDTH); j++)
- if (SYNTAX(j) == Sword)
- fastmap[j] = 1;
- break;
- case notwordchar:
- for (j = 0; j < (1 << BYTEWIDTH); j++)
- if (SYNTAX(j) != Sword)
- fastmap[j] = 1;
- break;
- case anychar:
- {
- int fastmap_newline = fastmap['\n'];
-
- for (j = 0; j < (1 << BYTEWIDTH); j++)
- fastmap[j] = 1;
-
- if (!(bufp->syntax & RE_DOT_NEWLINE))
- fastmap['\n'] = fastmap_newline;
-
- else if (bufp->can_be_null)
- goto done;
-
- break;
- }
- #ifdef emacs
- case syntaxspec:
- k = *p++;
- for (j = 0; j < (1 << BYTEWIDTH); j++)
- if (SYNTAX(j) == (enum syntaxcode) k)
- fastmap[j] = 1;
- break;
- case notsyntaxspec:
- k = *p++;
- for (j = 0; j < (1 << BYTEWIDTH); j++)
- if (SYNTAX(j) != (enum syntaxcode) k)
- fastmap[j] = 1;
- break;
-
- case before_dot:
- case at_dot:
- case after_dot:
- continue;
- #endif
- case no_op:
- case begline:
- case endline:
- case begbuf:
- case endbuf:
- case wordbound:
- case notwordbound:
- case wordbeg:
- case wordend:
- case push_dummy_failure:
- continue;
- case jump_n:
- case pop_failure_jump:
- case maybe_pop_jump:
- case jump:
- case jump_past_alt:
- case dummy_failure_jump:
- EXTRACT_NUMBER_AND_INCR(j, p);
- p += j;
- if (j > 0)
- continue;
-
- if ((re_opcode_t) * p != on_failure_jump
- && (re_opcode_t) * p != succeed_n)
- continue;
- p++;
- EXTRACT_NUMBER_AND_INCR(j, p);
- p += j;
-
- if (!FAIL_STACK_EMPTY()
- && fail_stack.stack[fail_stack.avail - 1].pointer == p)
- fail_stack.avail--;
- continue;
- case on_failure_jump:
- case on_failure_keep_string_jump:
- handle_on_failure_jump:
- EXTRACT_NUMBER_AND_INCR(j, p);
-
- if (p + j < pend) {
- if (!PUSH_PATTERN_OP(p + j, fail_stack)) {
- RESET_FAIL_STACK();
- return -2;
- }
- } else
- bufp->can_be_null = 1;
- if (succeed_n_p) {
- EXTRACT_NUMBER_AND_INCR(k, p);
- succeed_n_p = false;
- }
- continue;
- case succeed_n:
-
- p += 2;
-
- EXTRACT_NUMBER_AND_INCR(k, p);
- if (k == 0) {
- p -= 4;
- succeed_n_p = true;
- goto handle_on_failure_jump;
- }
- continue;
- case set_number_at:
- p += 4;
- continue;
- case start_memory:
- case stop_memory:
- p += 2;
- continue;
- default:
- abort();
- }
-
- path_can_be_null = false;
- p = pend;
- }
-
- bufp->can_be_null |= path_can_be_null;
- done:
- RESET_FAIL_STACK();
- return 0;
- }
- #ifdef _LIBC
- weak_alias(__re_compile_fastmap, re_compile_fastmap)
- #endif
- void re_set_registers(bufp, regs, num_regs, starts, ends)
- struct re_pattern_buffer *bufp;
- struct re_registers *regs;
- unsigned num_regs;
- regoff_t *starts, *ends;
- {
- if (num_regs) {
- bufp->regs_allocated = REGS_REALLOCATE;
- regs->num_regs = num_regs;
- regs->start = starts;
- regs->end = ends;
- } else {
- bufp->regs_allocated = REGS_UNALLOCATED;
- regs->num_regs = 0;
- regs->start = regs->end = (regoff_t *) 0;
- }
- }
- #ifdef _LIBC
- weak_alias(__re_set_registers, re_set_registers)
- #endif
- int re_search(bufp, string, size, startpos, range, regs)
- struct re_pattern_buffer *bufp;
- const char *string;
- int size, startpos, range;
- struct re_registers *regs;
- {
- return re_search_2(bufp, NULL, 0, string, size, startpos, range,
- regs, size);
- }
- #ifdef _LIBC
- weak_alias(__re_search, re_search)
- #endif
- int
- re_search_2(bufp, string1, size1, string2, size2, startpos, range, regs,
- stop)
- struct re_pattern_buffer *bufp;
- const char *string1, *string2;
- int size1, size2;
- int startpos;
- int range;
- struct re_registers *regs;
- int stop;
- {
- int val;
- register char *fastmap = bufp->fastmap;
- register RE_TRANSLATE_TYPE translate = bufp->translate;
- int total_size = size1 + size2;
- int endpos = startpos + range;
-
- if (startpos < 0 || startpos > total_size)
- return -1;
-
- if (endpos < 0)
- range = 0 - startpos;
- else if (endpos > total_size)
- range = total_size - startpos;
-
- if (bufp->used > 0 && range > 0
- && ((re_opcode_t) bufp->buffer[0] == begbuf
-
- || ((re_opcode_t) bufp->buffer[0] == begline
- && !bufp->newline_anchor))) {
- if (startpos > 0)
- return -1;
- else
- range = 1;
- }
- #ifdef emacs
-
- if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot
- && range > 0) {
- range = PT - startpos;
- if (range <= 0)
- return -1;
- }
- #endif
-
- if (fastmap && !bufp->fastmap_accurate)
- if (re_compile_fastmap(bufp) == -2)
- return -2;
-
- for (;;) {
-
- if (fastmap && startpos < total_size && !bufp->can_be_null) {
- if (range > 0) {
- register const char *d;
- register int lim = 0;
- int irange = range;
- if (startpos < size1 && startpos + range >= size1)
- lim = range - (size1 - startpos);
- d =
- (startpos >=
- size1 ? string2 - size1 : string1) + startpos;
-
- if (translate)
- while (range > lim && !fastmap[(unsigned char)
- translate[
- (unsigned
- char) *d++]])
- range--;
- else
- while (range > lim && !fastmap[(unsigned char) *d++])
- range--;
- startpos += irange - range;
- } else {
- register char c = (size1 == 0 || startpos >= size1
- ? string2[startpos - size1]
- : string1[startpos]);
- if (!fastmap[(unsigned char) TRANSLATE(c)])
- goto advance;
- }
- }
-
- if (range >= 0 && startpos == total_size && fastmap
- && !bufp->can_be_null) return -1;
- val = re_match_2_internal(bufp, string1, size1, string2, size2,
- startpos, regs, stop);
- #ifndef REGEX_MALLOC
- # ifdef C_ALLOCA
- alloca(0);
- # endif
- #endif
- if (val >= 0)
- return startpos;
- if (val == -2)
- return -2;
- advance:
- if (!range)
- break;
- else if (range > 0) {
- range--;
- startpos++;
- } else {
- range++;
- startpos--;
- }
- }
- return -1;
- }
- #ifdef _LIBC
- weak_alias(__re_search_2, re_search_2)
- #endif
- #define POINTER_TO_OFFSET(ptr) \
- (FIRST_STRING_P (ptr) \
- ? ((regoff_t) ((ptr) - string1)) \
- : ((regoff_t) ((ptr) - string2 + size1)))
- #define MATCHING_IN_FIRST_STRING (dend == end_match_1)
- #define PREFETCH() \
- while (d == dend) \
- { \
- \
- if (dend == end_match_2) \
- goto fail; \
- \
- d = string2; \
- dend = end_match_2; \
- }
- #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2)
- #define AT_STRINGS_END(d) ((d) == end2)
- #define WORDCHAR_P(d) \
- (SYNTAX ((d) == end1 ? *string2 \
- : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \
- == Sword)
- #if 0
- #define AT_WORD_BOUNDARY(d) \
- (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \
- || WORDCHAR_P (d - 1) != WORDCHAR_P (d))
- #endif
- #ifdef MATCH_MAY_ALLOCATE
- # define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL
- # define FREE_VARIABLES() \
- do { \
- REGEX_FREE_STACK (fail_stack.stack); \
- FREE_VAR (regstart); \
- FREE_VAR (regend); \
- FREE_VAR (old_regstart); \
- FREE_VAR (old_regend); \
- FREE_VAR (best_regstart); \
- FREE_VAR (best_regend); \
- FREE_VAR (reg_info); \
- FREE_VAR (reg_dummy); \
- FREE_VAR (reg_info_dummy); \
- } while (0)
- #else
- # define FREE_VARIABLES() ((void)0)
- #endif
- #define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
- #define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
- #ifndef emacs
- int re_match(bufp, string, size, pos, regs)
- struct re_pattern_buffer *bufp;
- const char *string;
- int size, pos;
- struct re_registers *regs;
- {
- int result = re_match_2_internal(bufp, NULL, 0, string, size,
- pos, regs, size);
- # ifndef REGEX_MALLOC
- # ifdef C_ALLOCA
- alloca(0);
- # endif
- # endif
- return result;
- }
- # ifdef _LIBC
- weak_alias(__re_match, re_match)
- # endif
- #endif
- static boolean group_match_null_string_p _RE_ARGS((unsigned char **p,
- unsigned char *end,
- register_info_type *
- reg_info));
- static boolean alt_match_null_string_p
- _RE_ARGS(
- (unsigned char *p, unsigned char *end,
- register_info_type * reg_info));
- static boolean common_op_match_null_string_p
- _RE_ARGS(
- (unsigned char **p, unsigned char *end,
- register_info_type * reg_info));
- static int bcmp_translate
- _RE_ARGS((const char *s1, const char *s2, int len, char *translate));
- int re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop)
- struct re_pattern_buffer *bufp;
- const char *string1, *string2;
- int size1, size2;
- int pos;
- struct re_registers *regs;
- int stop;
- {
- int result = re_match_2_internal(bufp, string1, size1, string2, size2,
- pos, regs, stop);
- #ifndef REGEX_MALLOC
- # ifdef C_ALLOCA
- alloca(0);
- # endif
- #endif
- return result;
- }
- #ifdef _LIBC
- weak_alias(__re_match_2, re_match_2)
- #endif
- static int
- re_match_2_internal(bufp, string1, size1, string2, size2, pos, regs, stop)
- struct re_pattern_buffer *bufp;
- const char *string1, *string2;
- int size1, size2;
- int pos;
- struct re_registers *regs;
- int stop;
- {
-
- int mcnt;
- unsigned char *p1;
-
- const char *end1, *end2;
-
- const char *end_match_1, *end_match_2;
-
- const char *d, *dend;
-
- unsigned char *p = bufp->buffer;
- register unsigned char *pend = p + bufp->used;
-
- unsigned char *just_past_start_mem = 0;
-
- RE_TRANSLATE_TYPE translate = bufp->translate;
-
- #ifdef MATCH_MAY_ALLOCATE
- fail_stack_type fail_stack;
- #endif
- #ifdef DEBUG
- static unsigned failure_id;
- unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
- #endif
- #ifdef REL_ALLOC
-
- fail_stack_elt_t *failure_stack_ptr;
- #endif
-
- size_t num_regs = bufp->re_nsub + 1;
-
- active_reg_t lowest_active_reg = NO_LOWEST_ACTIVE_REG;
- active_reg_t highest_active_reg = NO_HIGHEST_ACTIVE_REG;
-
- #ifdef MATCH_MAY_ALLOCATE
- const char **regstart, **regend;
- #endif
-
- #ifdef MATCH_MAY_ALLOCATE
- const char **old_regstart, **old_regend;
- #endif
-
- #ifdef MATCH_MAY_ALLOCATE
- register_info_type *reg_info;
- #endif
-
- unsigned best_regs_set = false;
- #ifdef MATCH_MAY_ALLOCATE
- const char **best_regstart, **best_regend;
- #endif
-
- const char *match_end = NULL;
-
- int set_regs_matched_done = 0;
-
- #ifdef MATCH_MAY_ALLOCATE
- const char **reg_dummy;
- register_info_type *reg_info_dummy;
- #endif
- #ifdef DEBUG
-
- unsigned num_regs_pushed = 0;
- #endif
- DEBUG_PRINT1("\n\nEntering re_match_2.\n");
- INIT_FAIL_STACK();
- #ifdef MATCH_MAY_ALLOCATE
-
- if (bufp->re_nsub) {
- regstart = REGEX_TALLOC(num_regs, const char *);
- regend = REGEX_TALLOC(num_regs, const char *);
- old_regstart = REGEX_TALLOC(num_regs, const char *);
- old_regend = REGEX_TALLOC(num_regs, const char *);
- best_regstart = REGEX_TALLOC(num_regs, const char *);
- best_regend = REGEX_TALLOC(num_regs, const char *);
- reg_info = REGEX_TALLOC(num_regs, register_info_type);
- reg_dummy = REGEX_TALLOC(num_regs, const char *);
- reg_info_dummy = REGEX_TALLOC(num_regs, register_info_type);
- if (!(regstart && regend && old_regstart && old_regend && reg_info
- && best_regstart && best_regend && reg_dummy
- && reg_info_dummy)) {
- FREE_VARIABLES();
- return -2;
- }
- } else {
-
- regstart = regend = old_regstart = old_regend = best_regstart
- = best_regend = reg_dummy = NULL;
- reg_info = reg_info_dummy = (register_info_type *) NULL;
- }
- #endif
-
- if (pos < 0 || pos > size1 + size2) {
- FREE_VARIABLES();
- return -1;
- }
-
- for (mcnt = 1; (unsigned) mcnt < num_regs; mcnt++) {
- regstart[mcnt] = regend[mcnt]
- = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE;
- REG_MATCH_NULL_STRING_P(reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE;
- IS_ACTIVE(reg_info[mcnt]) = 0;
- MATCHED_SOMETHING(reg_info[mcnt]) = 0;
- EVER_MATCHED_SOMETHING(reg_info[mcnt]) = 0;
- }
-
- if (size2 == 0 && string1 != NULL) {
- string2 = string1;
- size2 = size1;
- string1 = 0;
- size1 = 0;
- }
- end1 = string1 + size1;
- end2 = string2 + size2;
-
- if (stop <= size1) {
- end_match_1 = string1 + stop;
- end_match_2 = string2;
- } else {
- end_match_1 = end1;
- end_match_2 = string2 + stop - size1;
- }
-
- if (size1 > 0 && pos <= size1) {
- d = string1 + pos;
- dend = end_match_1;
- } else {
- d = string2 + pos - size1;
- dend = end_match_2;
- }
- DEBUG_PRINT1("The compiled pattern is:\n");
- DEBUG_PRINT_COMPILED_PATTERN(bufp, p, pend);
- DEBUG_PRINT1("The string to match is: `");
- DEBUG_PRINT_DOUBLE_STRING(d, string1, size1, string2, size2);
- DEBUG_PRINT1("'\n");
-
- for (;;) {
- #ifdef _LIBC
- DEBUG_PRINT2("\n%p: ", p);
- #else
- DEBUG_PRINT2("\n0x%x: ", p);
- #endif
- if (p == pend) {
- DEBUG_PRINT1("end of pattern ... ");
-
- if (d != end_match_2) {
-
- boolean same_str_p = (FIRST_STRING_P(match_end)
- == MATCHING_IN_FIRST_STRING);
-
- boolean best_match_p;
-
- if (same_str_p)
- best_match_p = d > match_end;
- else
- best_match_p = !MATCHING_IN_FIRST_STRING;
- DEBUG_PRINT1("backtracking.\n");
- if (!FAIL_STACK_EMPTY()) {
-
- if (!best_regs_set || best_match_p) {
- best_regs_set = true;
- match_end = d;
- DEBUG_PRINT1("\nSAVING match as best so far.\n");
- for (mcnt = 1; (unsigned) mcnt < num_regs; mcnt++) {
- best_regstart[mcnt] = regstart[mcnt];
- best_regend[mcnt] = regend[mcnt];
- }
- }
- goto fail;
- }
-
- else if (best_regs_set && !best_match_p) {
- restore_best_regs:
-
- DEBUG_PRINT1("Restoring best registers.\n");
- d = match_end;
- dend = ((d >= string1 && d <= end1)
- ? end_match_1 : end_match_2);
- for (mcnt = 1; (unsigned) mcnt < num_regs; mcnt++) {
- regstart[mcnt] = best_regstart[mcnt];
- regend[mcnt] = best_regend[mcnt];
- }
- }
- }
-
- succeed_label:
- DEBUG_PRINT1("Accepting match.\n");
-
- if (regs && !bufp->no_sub) {
-
- if (bufp->regs_allocated == REGS_UNALLOCATED) {
- regs->num_regs = MAX(RE_NREGS, num_regs + 1);
- regs->start = TALLOC(regs->num_regs, regoff_t);
- regs->end = TALLOC(regs->num_regs, regoff_t);
- if (regs->start == NULL || regs->end == NULL) {
- FREE_VARIABLES();
- return -2;
- }
- bufp->regs_allocated = REGS_REALLOCATE;
- } else if (bufp->regs_allocated == REGS_REALLOCATE) {
- if (regs->num_regs < num_regs + 1) {
- regs->num_regs = num_regs + 1;
- RETALLOC(regs->start, regs->num_regs, regoff_t);
- RETALLOC(regs->end, regs->num_regs, regoff_t);
- if (regs->start == NULL || regs->end == NULL) {
- FREE_VARIABLES();
- return -2;
- }
- }
- } else {
-
- assert(bufp->regs_allocated == REGS_FIXED);
- }
-
- if (regs->num_regs > 0) {
- regs->start[0] = pos;
- regs->end[0] = (MATCHING_IN_FIRST_STRING
- ? ((regoff_t) (d - string1))
- : ((regoff_t) (d - string2 + size1)));
- }
-
- for (mcnt = 1;
- (unsigned) mcnt < MIN(num_regs, regs->num_regs);
- mcnt++) {
- if (REG_UNSET(regstart[mcnt])
- || REG_UNSET(regend[mcnt])) regs->start[mcnt] =
- regs->end[mcnt] = -1;
- else {
- regs->start[mcnt]
- = (regoff_t) POINTER_TO_OFFSET(regstart[mcnt]);
- regs->end[mcnt]
- = (regoff_t) POINTER_TO_OFFSET(regend[mcnt]);
- }
- }
-
- for (mcnt = num_regs; (unsigned) mcnt < regs->num_regs;
- mcnt++)
- regs->start[mcnt] = regs->end[mcnt] = -1;
- }
-
- DEBUG_PRINT4
- ("%u failure points pushed, %u popped (%u remain).\n",
- nfailure_points_pushed, nfailure_points_popped,
- nfailure_points_pushed - nfailure_points_popped);
- DEBUG_PRINT2("%u registers pushed.\n", num_regs_pushed);
- mcnt = d - pos - (MATCHING_IN_FIRST_STRING
- ? string1 : string2 - size1);
- DEBUG_PRINT2("Returning %d from re_match_2.\n", mcnt);
- FREE_VARIABLES();
- return mcnt;
- }
-
- switch (SWITCH_ENUM_CAST((re_opcode_t) * p++)) {
-
- case no_op:
- DEBUG_PRINT1("EXECUTING no_op.\n");
- break;
- case succeed:
- DEBUG_PRINT1("EXECUTING succeed.\n");
- goto succeed_label;
-
- case exactn:
- mcnt = *p++;
- DEBUG_PRINT2("EXECUTING exactn %d.\n", mcnt);
-
- if (translate) {
- do {
- PREFETCH();
- if ((unsigned char) translate[(unsigned char) *d++]
- != (unsigned char) *p++)
- goto fail;
- }
- while (--mcnt);
- } else {
- do {
- PREFETCH();
- if (*d++ != (char) *p++)
- goto fail;
- }
- while (--mcnt);
- }
- SET_REGS_MATCHED();
- break;
-
- case anychar:
- DEBUG_PRINT1("EXECUTING anychar.\n");
- PREFETCH();
- if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE(*d) == '\n')
- || (bufp->syntax & RE_DOT_NOT_NULL
- && TRANSLATE(*d) == '\000')) goto fail;
- SET_REGS_MATCHED();
- DEBUG_PRINT2(" Matched `%d'.\n", *d);
- d++;
- break;
- case charset:
- case charset_not:
- {
- register unsigned char c;
- boolean not = (re_opcode_t) * (p - 1) == charset_not;
- DEBUG_PRINT2("EXECUTING charset%s.\n", not ? "_not" : "");
- PREFETCH();
- c = TRANSLATE(*d);
-
- if (c < (unsigned) (*p * BYTEWIDTH)
- && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
- not = !not;
- p += 1 + *p;
- if (!not)
- goto fail;
- SET_REGS_MATCHED();
- d++;
- break;
- }
-
- case start_memory:
- DEBUG_PRINT3("EXECUTING start_memory %d (%d):\n", *p, p[1]);
-
- p1 = p;
- if (REG_MATCH_NULL_STRING_P(reg_info[*p]) ==
- MATCH_NULL_UNSET_VALUE)
- REG_MATCH_NULL_STRING_P(reg_info[*p]) =
- group_match_null_string_p(&p1, pend, reg_info);
-
- old_regstart[*p] = REG_MATCH_NULL_STRING_P(reg_info[*p])
- ? REG_UNSET(regstart[*p]) ? d : regstart[*p]
- : regstart[*p];
- DEBUG_PRINT2(" old_regstart: %d\n",
- POINTER_TO_OFFSET(old_regstart[*p]));
- regstart[*p] = d;
- DEBUG_PRINT2(" regstart: %d\n",
- POINTER_TO_OFFSET(regstart[*p]));
- IS_ACTIVE(reg_info[*p]) = 1;
- MATCHED_SOMETHING(reg_info[*p]) = 0;
-
- set_regs_matched_done = 0;
-
- highest_active_reg = *p;
-
- if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
- lowest_active_reg = *p;
-
- p += 2;
- just_past_start_mem = p;
- break;
-
- case stop_memory:
- DEBUG_PRINT3("EXECUTING stop_memory %d (%d):\n", *p, p[1]);
-
- old_regend[*p] = REG_MATCH_NULL_STRING_P(reg_info[*p])
- ? REG_UNSET(regend[*p]) ? d : regend[*p]
- : regend[*p];
- DEBUG_PRINT2(" old_regend: %d\n",
- POINTER_TO_OFFSET(old_regend[*p]));
- regend[*p] = d;
- DEBUG_PRINT2(" regend: %d\n",
- POINTER_TO_OFFSET(regend[*p]));
-
- IS_ACTIVE(reg_info[*p]) = 0;
-
- set_regs_matched_done = 0;
-
- if (lowest_active_reg == highest_active_reg) {
- lowest_active_reg = NO_LOWEST_ACTIVE_REG;
- highest_active_reg = NO_HIGHEST_ACTIVE_REG;
- } else {
- unsigned char r = *p - 1;
- while (r > 0 && !IS_ACTIVE(reg_info[r]))
- r--;
-
- if (r == 0) {
- lowest_active_reg = NO_LOWEST_ACTIVE_REG;
- highest_active_reg = NO_HIGHEST_ACTIVE_REG;
- } else
- highest_active_reg = r;
- }
-
- if ((!MATCHED_SOMETHING(reg_info[*p])
- || just_past_start_mem == p - 1)
- && (p + 2) < pend) {
- boolean is_a_jump_n = false;
- p1 = p + 2;
- mcnt = 0;
- switch ((re_opcode_t) * p1++) {
- case jump_n:
- is_a_jump_n = true;
- case pop_failure_jump:
- case maybe_pop_jump:
- case jump:
- case dummy_failure_jump:
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- if (is_a_jump_n)
- p1 += 2;
- break;
- default:
- ;
- }
- p1 += mcnt;
-
- if (mcnt < 0 && (re_opcode_t) * p1 == on_failure_jump
- && (re_opcode_t) p1[3] == start_memory && p1[4] == *p) {
-
- if (EVER_MATCHED_SOMETHING(reg_info[*p])) {
- unsigned r;
- EVER_MATCHED_SOMETHING(reg_info[*p]) = 0;
-
- for (r = *p;
- r < (unsigned) *p + (unsigned) *(p + 1); r++) {
- regstart[r] = old_regstart[r];
-
- if (old_regend[r] >= regstart[r])
- regend[r] = old_regend[r];
- }
- }
- p1++;
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- PUSH_FAILURE_POINT(p1 + mcnt, d, -2);
- goto fail;
- }
- }
-
- p += 2;
- break;
-
- case duplicate:
- {
- register const char *d2, *dend2;
- int regno = *p++;
- DEBUG_PRINT2("EXECUTING duplicate %d.\n", regno);
-
- if (REG_UNSET(regstart[regno]) || REG_UNSET(regend[regno]))
- goto fail;
-
- d2 = regstart[regno];
-
- dend2 = ((FIRST_STRING_P(regstart[regno])
- == FIRST_STRING_P(regend[regno]))
- ? regend[regno] : end_match_1);
- for (;;) {
-
- while (d2 == dend2) {
- if (dend2 == end_match_2)
- break;
- if (dend2 == regend[regno])
- break;
-
- d2 = string2;
- dend2 = regend[regno];
- }
-
- if (d2 == dend2)
- break;
-
- PREFETCH();
-
- mcnt = dend - d;
-
- if (mcnt > dend2 - d2)
- mcnt = dend2 - d2;
-
- if (translate ? bcmp_translate(d, d2, mcnt, translate)
- : memcmp(d, d2, mcnt))
- goto fail;
- d += mcnt, d2 += mcnt;
-
- SET_REGS_MATCHED();
- }
- }
- break;
-
- case begline:
- DEBUG_PRINT1("EXECUTING begline.\n");
- if (AT_STRINGS_BEG(d)) {
- if (!bufp->not_bol)
- break;
- } else if (d[-1] == '\n' && bufp->newline_anchor) {
- break;
- }
-
- goto fail;
-
- case endline:
- DEBUG_PRINT1("EXECUTING endline.\n");
- if (AT_STRINGS_END(d)) {
- if (!bufp->not_eol)
- break;
- }
-
- else if ((d == end1 ? *string2 : *d) == '\n'
- && bufp->newline_anchor) {
- break;
- }
- goto fail;
-
- case begbuf:
- DEBUG_PRINT1("EXECUTING begbuf.\n");
- if (AT_STRINGS_BEG(d))
- break;
- goto fail;
-
- case endbuf:
- DEBUG_PRINT1("EXECUTING endbuf.\n");
- if (AT_STRINGS_END(d))
- break;
- goto fail;
-
- case on_failure_keep_string_jump:
- DEBUG_PRINT1("EXECUTING on_failure_keep_string_jump");
- EXTRACT_NUMBER_AND_INCR(mcnt, p);
- #ifdef _LIBC
- DEBUG_PRINT3(" %d (to %p):\n", mcnt, p + mcnt);
- #else
- DEBUG_PRINT3(" %d (to 0x%x):\n", mcnt, p + mcnt);
- #endif
- PUSH_FAILURE_POINT(p + mcnt, NULL, -2);
- break;
-
- case on_failure_jump:
- on_failure:
- DEBUG_PRINT1("EXECUTING on_failure_jump");
- EXTRACT_NUMBER_AND_INCR(mcnt, p);
- #ifdef _LIBC
- DEBUG_PRINT3(" %d (to %p)", mcnt, p + mcnt);
- #else
- DEBUG_PRINT3(" %d (to 0x%x)", mcnt, p + mcnt);
- #endif
-
-
- p1 = p;
-
- while (p1 < pend && (re_opcode_t) * p1 == no_op)
- p1++;
- if (p1 < pend && (re_opcode_t) * p1 == start_memory) {
-
- highest_active_reg = *(p1 + 1) + *(p1 + 2);
- if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
- lowest_active_reg = *(p1 + 1);
- }
- DEBUG_PRINT1(":\n");
- PUSH_FAILURE_POINT(p + mcnt, d, -2);
- break;
-
- case maybe_pop_jump:
- EXTRACT_NUMBER_AND_INCR(mcnt, p);
- DEBUG_PRINT2("EXECUTING maybe_pop_jump %d.\n", mcnt);
- {
- register unsigned char *p2 = p;
-
-
- while (1) {
- if (p2 + 2 < pend
- && ((re_opcode_t) * p2 == stop_memory
- || (re_opcode_t) * p2 == start_memory))
- p2 += 3;
- else if (p2 + 6 < pend
- && (re_opcode_t) * p2 == dummy_failure_jump)
- p2 += 6;
- else
- break;
- }
- p1 = p + mcnt;
-
-
- if (p2 == pend) {
-
- p[-3] = (unsigned char) pop_failure_jump;
- DEBUG_PRINT1
- (" End of pattern: change to `pop_failure_jump'.\n");
- }
- else if ((re_opcode_t) * p2 == exactn
- || (bufp->newline_anchor
- && (re_opcode_t) * p2 == endline)) {
- register unsigned char c =
- *p2 == (unsigned char) endline ? '\n' : p2[2];
- if ((re_opcode_t) p1[3] == exactn && p1[5] != c) {
- p[-3] = (unsigned char) pop_failure_jump;
- DEBUG_PRINT3(" %c != %c => pop_failure_jump.\n",
- c, p1[5]);
- }
- else if ((re_opcode_t) p1[3] == charset
- || (re_opcode_t) p1[3] == charset_not) {
- int not = (re_opcode_t) p1[3] == charset_not;
- if (c < (unsigned char) (p1[4] * BYTEWIDTH)
- && p1[5 +
- c / BYTEWIDTH] & (1 << (c %
- BYTEWIDTH))) not
- = !not;
-
- if (!not) {
- p[-3] = (unsigned char) pop_failure_jump;
- DEBUG_PRINT1
- (" No match => pop_failure_jump.\n");
- }
- }
- } else if ((re_opcode_t) * p2 == charset) {
-
- if ((re_opcode_t) p1[3] == exactn
- && !((int) p2[1] * BYTEWIDTH > (int) p1[5]
- && (p2[2 + p1[5] / BYTEWIDTH]
- & (1 << (p1[5] % BYTEWIDTH))))) {
- p[-3] = (unsigned char) pop_failure_jump;
- DEBUG_PRINT1(" No match => pop_failure_jump.\n");
- }
- else if ((re_opcode_t) p1[3] == charset_not) {
- int idx;
-
- for (idx = 0; idx < (int) p2[1]; idx++)
- if (!(p2[2 + idx] == 0 || (idx < (int) p1[4]
- &&
- ((p2
- [2 +
- idx] & ~p1[5 +
- idx])
- == 0))))
- break;
- if (idx == p2[1]) {
- p[-3] = (unsigned char) pop_failure_jump;
- DEBUG_PRINT1
- (" No match => pop_failure_jump.\n");
- }
- } else if ((re_opcode_t) p1[3] == charset) {
- int idx;
-
- for (idx = 0;
- idx < (int) p2[1] && idx < (int) p1[4]; idx++)
- if ((p2[2 + idx] & p1[5 + idx]) != 0)
- break;
- if (idx == p2[1] || idx == p1[4]) {
- p[-3] = (unsigned char) pop_failure_jump;
- DEBUG_PRINT1
- (" No match => pop_failure_jump.\n");
- }
- }
- }
- }
- p -= 2;
- if ((re_opcode_t) p[-1] != pop_failure_jump) {
- p[-1] = (unsigned char) jump;
- DEBUG_PRINT1(" Match => jump.\n");
- goto unconditional_jump;
- }
-
-
- case pop_failure_jump:
- {
-
- active_reg_t dummy_low_reg, dummy_high_reg;
- unsigned char *pdummy;
- const char *sdummy;
- DEBUG_PRINT1("EXECUTING pop_failure_jump.\n");
- POP_FAILURE_POINT(sdummy, pdummy,
- dummy_low_reg, dummy_high_reg,
- reg_dummy, reg_dummy, reg_info_dummy);
- }
-
- unconditional_jump:
- #ifdef _LIBC
- DEBUG_PRINT2("\n%p: ", p);
- #else
- DEBUG_PRINT2("\n0x%x: ", p);
- #endif
-
-
- case jump:
- EXTRACT_NUMBER_AND_INCR(mcnt, p);
- DEBUG_PRINT2("EXECUTING jump %d ", mcnt);
- p += mcnt;
- #ifdef _LIBC
- DEBUG_PRINT2("(to %p).\n", p);
- #else
- DEBUG_PRINT2("(to 0x%x).\n", p);
- #endif
- break;
-
- case jump_past_alt:
- DEBUG_PRINT1("EXECUTING jump_past_alt.\n");
- goto unconditional_jump;
-
- case dummy_failure_jump:
- DEBUG_PRINT1("EXECUTING dummy_failure_jump.\n");
-
- PUSH_FAILURE_POINT(NULL, NULL, -2);
- goto unconditional_jump;
-
- case push_dummy_failure:
- DEBUG_PRINT1("EXECUTING push_dummy_failure.\n");
-
- PUSH_FAILURE_POINT(NULL, NULL, -2);
- break;
-
- case succeed_n:
- EXTRACT_NUMBER(mcnt, p + 2);
- DEBUG_PRINT2("EXECUTING succeed_n %d.\n", mcnt);
- assert(mcnt >= 0);
-
- if (mcnt > 0) {
- mcnt--;
- p += 2;
- STORE_NUMBER_AND_INCR(p, mcnt);
- #ifdef _LIBC
- DEBUG_PRINT3(" Setting %p to %d.\n", p - 2, mcnt);
- #else
- DEBUG_PRINT3(" Setting 0x%x to %d.\n", p - 2, mcnt);
- #endif
- } else if (mcnt == 0) {
- #ifdef _LIBC
- DEBUG_PRINT2(" Setting two bytes from %p to no_op.\n",
- p + 2);
- #else
- DEBUG_PRINT2(" Setting two bytes from 0x%x to no_op.\n",
- p + 2);
- #endif
- p[2] = (unsigned char) no_op;
- p[3] = (unsigned char) no_op;
- goto on_failure;
- }
- break;
- case jump_n:
- EXTRACT_NUMBER(mcnt, p + 2);
- DEBUG_PRINT2("EXECUTING jump_n %d.\n", mcnt);
-
- if (mcnt) {
- mcnt--;
- STORE_NUMBER(p + 2, mcnt);
- #ifdef _LIBC
- DEBUG_PRINT3(" Setting %p to %d.\n", p + 2, mcnt);
- #else
- DEBUG_PRINT3(" Setting 0x%x to %d.\n", p + 2, mcnt);
- #endif
- goto unconditional_jump;
- }
-
- else
- p += 4;
- break;
- case set_number_at:
- {
- DEBUG_PRINT1("EXECUTING set_number_at.\n");
- EXTRACT_NUMBER_AND_INCR(mcnt, p);
- p1 = p + mcnt;
- EXTRACT_NUMBER_AND_INCR(mcnt, p);
- #ifdef _LIBC
- DEBUG_PRINT3(" Setting %p to %d.\n", p1, mcnt);
- #else
- DEBUG_PRINT3(" Setting 0x%x to %d.\n", p1, mcnt);
- #endif
- STORE_NUMBER(p1, mcnt);
- break;
- }
- #if 0
-
- case wordbound:
- DEBUG_PRINT1("EXECUTING wordbound.\n");
- if (AT_WORD_BOUNDARY(d))
- break;
- goto fail;
- case notwordbound:
- DEBUG_PRINT1("EXECUTING notwordbound.\n");
- if (AT_WORD_BOUNDARY(d))
- goto fail;
- break;
- #else
- case wordbound:
- {
- boolean prevchar, thischar;
- DEBUG_PRINT1("EXECUTING wordbound.\n");
- if (AT_STRINGS_BEG(d) || AT_STRINGS_END(d))
- break;
- prevchar = WORDCHAR_P(d - 1);
- thischar = WORDCHAR_P(d);
- if (prevchar != thischar)
- break;
- goto fail;
- }
- case notwordbound:
- {
- boolean prevchar, thischar;
- DEBUG_PRINT1("EXECUTING notwordbound.\n");
- if (AT_STRINGS_BEG(d) || AT_STRINGS_END(d))
- goto fail;
- prevchar = WORDCHAR_P(d - 1);
- thischar = WORDCHAR_P(d);
- if (prevchar != thischar)
- goto fail;
- break;
- }
- #endif
- case wordbeg:
- DEBUG_PRINT1("EXECUTING wordbeg.\n");
- if (WORDCHAR_P(d) && (AT_STRINGS_BEG(d) || !WORDCHAR_P(d - 1)))
- break;
- goto fail;
- case wordend:
- DEBUG_PRINT1("EXECUTING wordend.\n");
- if (!AT_STRINGS_BEG(d) && WORDCHAR_P(d - 1)
- && (!WORDCHAR_P(d) || AT_STRINGS_END(d)))
- break;
- goto fail;
- #ifdef emacs
- case before_dot:
- DEBUG_PRINT1("EXECUTING before_dot.\n");
- if (PTR_CHAR_POS((unsigned char *) d) >= point)
- goto fail;
- break;
- case at_dot:
- DEBUG_PRINT1("EXECUTING at_dot.\n");
- if (PTR_CHAR_POS((unsigned char *) d) != point)
- goto fail;
- break;
- case after_dot:
- DEBUG_PRINT1("EXECUTING after_dot.\n");
- if (PTR_CHAR_POS((unsigned char *) d) <= point)
- goto fail;
- break;
- case syntaxspec:
- DEBUG_PRINT2("EXECUTING syntaxspec %d.\n", mcnt);
- mcnt = *p++;
- goto matchsyntax;
- case wordchar:
- DEBUG_PRINT1("EXECUTING Emacs wordchar.\n");
- mcnt = (int) Sword;
- matchsyntax:
- PREFETCH();
-
- d++;
- if (SYNTAX(d[-1]) != (enum syntaxcode) mcnt)
- goto fail;
- SET_REGS_MATCHED();
- break;
- case notsyntaxspec:
- DEBUG_PRINT2("EXECUTING notsyntaxspec %d.\n", mcnt);
- mcnt = *p++;
- goto matchnotsyntax;
- case notwordchar:
- DEBUG_PRINT1("EXECUTING Emacs notwordchar.\n");
- mcnt = (int) Sword;
- matchnotsyntax:
- PREFETCH();
-
- d++;
- if (SYNTAX(d[-1]) == (enum syntaxcode) mcnt)
- goto fail;
- SET_REGS_MATCHED();
- break;
- #else
- case wordchar:
- DEBUG_PRINT1("EXECUTING non-Emacs wordchar.\n");
- PREFETCH();
- if (!WORDCHAR_P(d))
- goto fail;
- SET_REGS_MATCHED();
- d++;
- break;
- case notwordchar:
- DEBUG_PRINT1("EXECUTING non-Emacs notwordchar.\n");
- PREFETCH();
- if (WORDCHAR_P(d))
- goto fail;
- SET_REGS_MATCHED();
- d++;
- break;
- #endif
- default:
- abort();
- }
- continue;
-
- fail:
- if (!FAIL_STACK_EMPTY()) {
- DEBUG_PRINT1("\nFAIL:\n");
- POP_FAILURE_POINT(d, p,
- lowest_active_reg, highest_active_reg,
- regstart, regend, reg_info);
-
- if (!p)
- goto fail;
-
- assert(p <= pend);
- if (p < pend) {
- boolean is_a_jump_n = false;
-
- switch ((re_opcode_t) * p) {
- case jump_n:
- is_a_jump_n = true;
- case maybe_pop_jump:
- case pop_failure_jump:
- case jump:
- p1 = p + 1;
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- p1 += mcnt;
- if ((is_a_jump_n && (re_opcode_t) * p1 == succeed_n)
- || (!is_a_jump_n
- && (re_opcode_t) * p1 == on_failure_jump))
- goto fail;
- break;
- default:
- ;
- }
- }
- if (d >= string1 && d <= end1)
- dend = end_match_1;
- } else
- break;
- }
- if (best_regs_set)
- goto restore_best_regs;
- FREE_VARIABLES();
- return -1;
- }
- static boolean group_match_null_string_p(p, end, reg_info)
- unsigned char **p, *end;
- register_info_type *reg_info;
- {
- int mcnt;
-
- unsigned char *p1 = *p + 2;
- while (p1 < end) {
-
- switch ((re_opcode_t) * p1) {
-
- case on_failure_jump:
- p1++;
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
-
- if (mcnt >= 0) {
-
-
- while ((re_opcode_t) p1[mcnt - 3] == jump_past_alt) {
-
- if (!alt_match_null_string_p(p1, p1 + mcnt - 3,
- reg_info)) return false;
-
- p1 += mcnt;
-
- if ((re_opcode_t) * p1 != on_failure_jump)
- break;
-
- p1++;
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- if ((re_opcode_t) p1[mcnt - 3] != jump_past_alt) {
-
- p1 -= 3;
- break;
- }
- }
-
- EXTRACT_NUMBER(mcnt, p1 - 2);
- if (!alt_match_null_string_p(p1, p1 + mcnt, reg_info))
- return false;
- p1 += mcnt;
- }
- break;
- case stop_memory:
- assert(p1[1] == **p);
- *p = p1 + 2;
- return true;
- default:
- if (!common_op_match_null_string_p(&p1, end, reg_info))
- return false;
- }
- }
- return false;
- }
- static boolean alt_match_null_string_p(p, end, reg_info)
- unsigned char *p, *end;
- register_info_type *reg_info;
- {
- int mcnt;
- unsigned char *p1 = p;
- while (p1 < end) {
-
- switch ((re_opcode_t) * p1) {
-
- case on_failure_jump:
- p1++;
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- p1 += mcnt;
- break;
- default:
- if (!common_op_match_null_string_p(&p1, end, reg_info))
- return false;
- }
- }
- return true;
- }
- static boolean common_op_match_null_string_p(p, end, reg_info)
- unsigned char **p, *end;
- register_info_type *reg_info;
- {
- int mcnt;
- boolean ret;
- int reg_no;
- unsigned char *p1 = *p;
- switch ((re_opcode_t) * p1++) {
- case no_op:
- case begline:
- case endline:
- case begbuf:
- case endbuf:
- case wordbeg:
- case wordend:
- case wordbound:
- case notwordbound:
- #ifdef emacs
- case before_dot:
- case at_dot:
- case after_dot:
- #endif
- break;
- case start_memory:
- reg_no = *p1;
- assert(reg_no > 0 && reg_no <= MAX_REGNUM);
- ret = group_match_null_string_p(&p1, end, reg_info);
-
- if (REG_MATCH_NULL_STRING_P(reg_info[reg_no]) ==
- MATCH_NULL_UNSET_VALUE)
- REG_MATCH_NULL_STRING_P(reg_info[reg_no]) = ret;
- if (!ret)
- return false;
- break;
-
- case jump:
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- if (mcnt >= 0)
- p1 += mcnt;
- else
- return false;
- break;
- case succeed_n:
-
- p1 += 2;
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- if (mcnt == 0) {
- p1 -= 4;
- EXTRACT_NUMBER_AND_INCR(mcnt, p1);
- p1 += mcnt;
- } else
- return false;
- break;
- case duplicate:
- if (!REG_MATCH_NULL_STRING_P(reg_info[*p1]))
- return false;
- break;
- case set_number_at:
- p1 += 4;
- default:
-
- return false;
- }
- *p = p1;
- return true;
- }
- static int bcmp_translate(s1, s2, len, translate)
- const char *s1, *s2;
- register int len;
- RE_TRANSLATE_TYPE translate;
- {
- register const unsigned char *p1 = (const unsigned char *) s1;
- register const unsigned char *p2 = (const unsigned char *) s2;
- while (len) {
- if (translate[*p1++] != translate[*p2++])
- return 1;
- len--;
- }
- return 0;
- }
- const char *re_compile_pattern(pattern, length, bufp)
- const char *pattern;
- size_t length;
- struct re_pattern_buffer *bufp;
- {
- reg_errcode_t ret;
-
- bufp->regs_allocated = REGS_UNALLOCATED;
-
- bufp->no_sub = 0;
-
- bufp->newline_anchor = 1;
- ret = regex_compile(pattern, length, re_syntax_options, bufp);
- if (!ret)
- return NULL;
- return gettext(re_error_msgid + re_error_msgid_idx[(int) ret]);
- }
- #ifdef _LIBC
- weak_alias(__re_compile_pattern, re_compile_pattern)
- #endif
- #if defined _REGEX_RE_COMP || defined _LIBC
- static struct re_pattern_buffer re_comp_buf;
- char *
- #ifdef _LIBC
- weak_function
- #endif
- re_comp(s)
- const char *s;
- {
- reg_errcode_t ret;
- if (!s) {
- if (!re_comp_buf.buffer)
- return gettext("No previous regular expression");
- return 0;
- }
- if (!re_comp_buf.buffer) {
- re_comp_buf.buffer = (unsigned char *) malloc(200);
- if (re_comp_buf.buffer == NULL)
- return (char *) gettext(re_error_msgid
- +
- re_error_msgid_idx[(int) REG_ESPACE]);
- re_comp_buf.allocated = 200;
- re_comp_buf.fastmap = (char *) malloc(1 << BYTEWIDTH);
- if (re_comp_buf.fastmap == NULL)
- return (char *) gettext(re_error_msgid
- +
- re_error_msgid_idx[(int) REG_ESPACE]);
- }
-
-
- re_comp_buf.newline_anchor = 1;
- ret = regex_compile(s, strlen(s), re_syntax_options, &re_comp_buf);
- if (!ret)
- return NULL;
-
- return (char *) gettext(re_error_msgid +
- re_error_msgid_idx[(int) ret]);
- }
- int
- #ifdef _LIBC
- weak_function
- #endif
- re_exec(s)
- const char *s;
- {
- const int len = strlen(s);
- return
- 0 <= re_search(&re_comp_buf, s, len, 0, len,
- (struct re_registers *) 0);
- }
- #endif
- #ifndef emacs
- int regcomp(preg, pattern, cflags)
- regex_t *preg;
- const char *pattern;
- int cflags;
- {
- reg_errcode_t ret;
- reg_syntax_t syntax
- = (cflags & REG_EXTENDED) ?
- RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
-
- preg->buffer = 0;
- preg->allocated = 0;
- preg->used = 0;
-
- preg->fastmap = (char *) malloc(1 << BYTEWIDTH);
- if (cflags & REG_ICASE) {
- unsigned i;
- preg->translate
- = (RE_TRANSLATE_TYPE) malloc(CHAR_SET_SIZE
- * sizeof(*(RE_TRANSLATE_TYPE) 0));
- if (preg->translate == NULL)
- return (int) REG_ESPACE;
-
- for (i = 0; i < CHAR_SET_SIZE; i++)
- preg->translate[i] = ISUPPER(i) ? TOLOWER(i) : i;
- } else
- preg->translate = NULL;
-
- if (cflags & REG_NEWLINE) {
- syntax &= ~RE_DOT_NEWLINE;
- syntax |= RE_HAT_LISTS_NOT_NEWLINE;
-
- preg->newline_anchor = 1;
- } else
- preg->newline_anchor = 0;
- preg->no_sub = !!(cflags & REG_NOSUB);
-
- ret = regex_compile(pattern, strlen(pattern), syntax, preg);
-
- if (ret == REG_ERPAREN)
- ret = REG_EPAREN;
- if (ret == REG_NOERROR && preg->fastmap) {
-
- if (re_compile_fastmap(preg) == -2) {
-
- free(preg->fastmap);
- preg->fastmap = NULL;
- }
- }
- return (int) ret;
- }
- #ifdef _LIBC
- weak_alias(__regcomp, regcomp)
- #endif
- int regexec(preg, string, nmatch, pmatch, eflags)
- const regex_t *preg;
- const char *string;
- size_t nmatch;
- regmatch_t pmatch[];
- int eflags;
- {
- int ret;
- struct re_registers regs;
- regex_t private_preg;
- int len = strlen(string);
- boolean want_reg_info = !preg->no_sub && nmatch > 0;
- private_preg = *preg;
- private_preg.not_bol = !!(eflags & REG_NOTBOL);
- private_preg.not_eol = !!(eflags & REG_NOTEOL);
-
- private_preg.regs_allocated = REGS_FIXED;
- if (want_reg_info) {
- regs.num_regs = nmatch;
- regs.start = TALLOC(nmatch * 2, regoff_t);
- if (regs.start == NULL)
- return (int) REG_NOMATCH;
- regs.end = regs.start + nmatch;
- }
-
- ret = re_search(&private_preg, string, len,
- 0, len,
- want_reg_info ? ®s : (struct re_registers *) 0);
-
- if (want_reg_info) {
- if (ret >= 0) {
- unsigned r;
- for (r = 0; r < nmatch; r++) {
- pmatch[r].rm_so = regs.start[r];
- pmatch[r].rm_eo = regs.end[r];
- }
- }
-
- free(regs.start);
- }
-
- return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
- }
- #ifdef _LIBC
- weak_alias(__regexec, regexec)
- #endif
- size_t regerror(errcode, preg, errbuf, errbuf_size)
- int errcode;
- const regex_t *preg;
- char *errbuf;
- size_t errbuf_size;
- {
- const char *msg;
- size_t msg_size;
- if (errcode < 0 || errcode >= (int) (sizeof(re_error_msgid_idx)
- / sizeof(re_error_msgid_idx[0])))
-
- abort();
- msg = gettext(re_error_msgid + re_error_msgid_idx[errcode]);
- msg_size = strlen(msg) + 1;
- if (errbuf_size != 0) {
- if (msg_size > errbuf_size) {
- #if defined HAVE_MEMPCPY || defined _LIBC
- *((char *) __mempcpy(errbuf, msg, errbuf_size - 1)) = '\0';
- #else
- memcpy(errbuf, msg, errbuf_size - 1);
- errbuf[errbuf_size - 1] = 0;
- #endif
- } else
- memcpy(errbuf, msg, msg_size);
- }
- return msg_size;
- }
- #ifdef _LIBC
- weak_alias(__regerror, regerror)
- #endif
- void regfree(preg)
- regex_t *preg;
- {
- if (preg->buffer != NULL)
- free(preg->buffer);
- preg->buffer = NULL;
- preg->allocated = 0;
- preg->used = 0;
- if (preg->fastmap != NULL)
- free(preg->fastmap);
- preg->fastmap = NULL;
- preg->fastmap_accurate = 0;
- if (preg->translate != NULL)
- free(preg->translate);
- preg->translate = NULL;
- }
- #ifdef _LIBC
- weak_alias(__regfree, regfree)
- #endif
- #endif
|