libtirpc-0008-Add-rpcgen-program-from-nfs-utils-sources.patch 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504
  1. From 8a1ee148ea860c20fa4e076839e5681412a11f7e Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. Date: Sat, 10 Nov 2012 16:21:01 +0100
  4. Subject: [PATCH] Add rpcgen program from nfs-utils sources
  5. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  6. ---
  7. Makefile.am | 2 +-
  8. configure.ac | 12 +-
  9. rpcgen/Makefile.am | 22 ++
  10. rpcgen/rpc_clntout.c | 217 ++++++++++
  11. rpcgen/rpc_cout.c | 706 +++++++++++++++++++++++++++++++++
  12. rpcgen/rpc_hout.c | 490 +++++++++++++++++++++++
  13. rpcgen/rpc_main.c | 1067 ++++++++++++++++++++++++++++++++++++++++++++++++++
  14. rpcgen/rpc_output.h | 16 +
  15. rpcgen/rpc_parse.c | 609 ++++++++++++++++++++++++++++
  16. rpcgen/rpc_parse.h | 166 ++++++++
  17. rpcgen/rpc_sample.c | 247 ++++++++++++
  18. rpcgen/rpc_scan.c | 474 ++++++++++++++++++++++
  19. rpcgen/rpc_scan.h | 103 +++++
  20. rpcgen/rpc_svcout.c | 882 +++++++++++++++++++++++++++++++++++++++++
  21. rpcgen/rpc_tblout.c | 165 ++++++++
  22. rpcgen/rpc_util.c | 479 ++++++++++++++++++++++
  23. rpcgen/rpc_util.h | 166 ++++++++
  24. rpcgen/rpcgen.1 | 521 ++++++++++++++++++++++++
  25. 18 files changed, 6342 insertions(+), 2 deletions(-)
  26. create mode 100644 rpcgen/Makefile.am
  27. create mode 100644 rpcgen/rpc_clntout.c
  28. create mode 100644 rpcgen/rpc_cout.c
  29. create mode 100644 rpcgen/rpc_hout.c
  30. create mode 100644 rpcgen/rpc_main.c
  31. create mode 100644 rpcgen/rpc_output.h
  32. create mode 100644 rpcgen/rpc_parse.c
  33. create mode 100644 rpcgen/rpc_parse.h
  34. create mode 100644 rpcgen/rpc_sample.c
  35. create mode 100644 rpcgen/rpc_scan.c
  36. create mode 100644 rpcgen/rpc_scan.h
  37. create mode 100644 rpcgen/rpc_svcout.c
  38. create mode 100644 rpcgen/rpc_tblout.c
  39. create mode 100644 rpcgen/rpc_util.c
  40. create mode 100644 rpcgen/rpc_util.h
  41. create mode 100644 rpcgen/rpcgen.1
  42. diff --git a/Makefile.am b/Makefile.am
  43. index 1a7596b..afb4e38 100644
  44. --- a/Makefile.am
  45. +++ b/Makefile.am
  46. @@ -1,4 +1,4 @@
  47. -SUBDIRS = src man doc
  48. +SUBDIRS = src man doc rpcgen
  49. ACLOCAL_AMFLAGS = -I m4
  50. nobase_include_HEADERS = tirpc/netconfig.h \
  51. diff --git a/configure.ac b/configure.ac
  52. index 487ec83..7f35b48 100644
  53. --- a/configure.ac
  54. +++ b/configure.ac
  55. @@ -29,6 +29,16 @@ AC_CHECK_HEADER(netinet/ip6.h,
  56. AC_CHECK_LIB([pthread], [pthread_create])
  57. +AM_CONDITIONAL(CROSS_COMPILING, test $cross_compiling = yes)
  58. -AC_CONFIG_FILES([Makefile src/Makefile man/Makefile doc/Makefile])
  59. +AC_MSG_CHECKING([for a C compiler for build tools])
  60. +if test $cross_compiling = yes; then
  61. + AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
  62. +else
  63. + CC_FOR_BUILD=$CC
  64. +fi
  65. +AC_MSG_RESULT([$CC_FOR_BUILD])
  66. +AC_SUBST(CC_FOR_BUILD)
  67. +
  68. +AC_CONFIG_FILES([Makefile src/Makefile man/Makefile doc/Makefile rpcgen/Makefile])
  69. AC_OUTPUT(libtirpc.pc)
  70. diff --git a/rpcgen/Makefile.am b/rpcgen/Makefile.am
  71. new file mode 100644
  72. index 0000000..2277b6f
  73. --- /dev/null
  74. +++ b/rpcgen/Makefile.am
  75. @@ -0,0 +1,22 @@
  76. +COMPILE = $(CC_FOR_BUILD) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
  77. + $(CPPFLAGS_FOR_BUILD) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD)
  78. +LINK = $(CC_FOR_BUILD) $(AM_CFLAGS) $(CFLAGS_FOR_BUILD) $(AM_LDFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
  79. +
  80. +bin_PROGRAMS = rpcgen
  81. +
  82. +rpcgen_SOURCES = \
  83. + rpc_clntout.c \
  84. + rpc_cout.c \
  85. + rpc_hout.c \
  86. + rpc_main.c \
  87. + rpc_parse.c \
  88. + rpc_sample.c \
  89. + rpc_scan.c \
  90. + rpc_svcout.c \
  91. + rpc_tblout.c \
  92. + rpc_util.c \
  93. + rpc_parse.h \
  94. + rpc_scan.h \
  95. + rpc_util.h
  96. +
  97. +dist_man1_MANS = rpcgen.1
  98. diff --git a/rpcgen/rpc_clntout.c b/rpcgen/rpc_clntout.c
  99. new file mode 100644
  100. index 0000000..e2f4382
  101. --- /dev/null
  102. +++ b/rpcgen/rpc_clntout.c
  103. @@ -0,0 +1,217 @@
  104. +/*
  105. + * Copyright (c) 2009, Sun Microsystems, Inc.
  106. + * All rights reserved.
  107. + *
  108. + * Redistribution and use in source and binary forms, with or without
  109. + * modification, are permitted provided that the following conditions are met:
  110. + * - Redistributions of source code must retain the above copyright notice,
  111. + * this list of conditions and the following disclaimer.
  112. + * - Redistributions in binary form must reproduce the above copyright notice,
  113. + * this list of conditions and the following disclaimer in the documentation
  114. + * and/or other materials provided with the distribution.
  115. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  116. + * contributors may be used to endorse or promote products derived
  117. + * from this software without specific prior written permission.
  118. + *
  119. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  120. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  121. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  122. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  123. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  124. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  125. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  126. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  127. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  128. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  129. + * POSSIBILITY OF SUCH DAMAGE.
  130. + */
  131. +
  132. +#if 0
  133. +static char sccsid[] = "@(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI";
  134. +#endif
  135. +
  136. +/*
  137. + * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
  138. + * Copyright (C) 1987, Sun Microsytsems, Inc.
  139. + */
  140. +#include <stdio.h>
  141. +#include <string.h>
  142. +#include <rpc/types.h>
  143. +#include "rpc_parse.h"
  144. +#include "rpc_util.h"
  145. +#include "rpc_output.h"
  146. +
  147. +/* extern pdeclaration(); */
  148. +/* void printarglist(); */
  149. +
  150. +#define DEFAULT_TIMEOUT 25 /* in seconds */
  151. +static char RESULT[] = "clnt_res";
  152. +
  153. +static void write_program(definition *def);
  154. +static void printbody(proc_list *proc);
  155. +
  156. +
  157. +void
  158. +write_stubs(void)
  159. +{
  160. + list *l;
  161. + definition *def;
  162. +
  163. + f_print(fout,
  164. + "\n/* Default timeout can be changed using clnt_control() */\n");
  165. + f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
  166. + DEFAULT_TIMEOUT);
  167. + for (l = defined; l != NULL; l = l->next) {
  168. + def = (definition *) l->val;
  169. + if (def->def_kind == DEF_PROGRAM) {
  170. + write_program(def);
  171. + }
  172. + }
  173. +}
  174. +
  175. +static void
  176. +write_program(definition *def)
  177. +{
  178. + version_list *vp;
  179. + proc_list *proc;
  180. +
  181. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  182. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  183. + f_print(fout, "\n");
  184. + ptype(proc->res_prefix, proc->res_type, 1);
  185. + f_print(fout, "*\n");
  186. + pvname(proc->proc_name, vp->vers_num);
  187. + printarglist(proc, "clnt", "CLIENT *");
  188. + f_print(fout, "{\n");
  189. + printbody(proc);
  190. + f_print(fout, "}\n");
  191. + }
  192. + }
  193. +}
  194. +
  195. +/*
  196. + * Writes out declarations of procedure's argument list.
  197. + * In either ANSI C style, in one of old rpcgen style (pass by reference),
  198. + * or new rpcgen style (multiple arguments, pass by value);
  199. + */
  200. +
  201. +/* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
  202. +
  203. +void
  204. +printarglist(proc_list *proc, char *addargname, char *addargtype)
  205. +{
  206. +
  207. + decl_list *l;
  208. +
  209. + if (!newstyle) { /* old style: always pass arg by reference */
  210. + if (Cflag) { /* C++ style heading */
  211. + f_print(fout, "(");
  212. + ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
  213. + f_print(fout, "*argp, %s%s)\n", addargtype, addargname);
  214. + } else {
  215. + f_print(fout, "(argp, %s)\n", addargname);
  216. + f_print(fout, "\t");
  217. + ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
  218. + f_print(fout, "*argp;\n");
  219. + }
  220. + } else if (streq(proc->args.decls->decl.type, "void")) {
  221. + /* newstyle, 0 argument */
  222. + if (Cflag)
  223. + f_print(fout, "(%s%s)\n", addargtype, addargname);
  224. + else
  225. + f_print(fout, "(%s)\n", addargname);
  226. + } else {
  227. + /* new style, 1 or multiple arguments */
  228. + if (!Cflag) {
  229. + f_print(fout, "(");
  230. + for (l = proc->args.decls; l != NULL; l = l->next)
  231. + f_print(fout, "%s, ", l->decl.name);
  232. + f_print(fout, "%s)\n", addargname);
  233. + for (l = proc->args.decls; l != NULL; l = l->next) {
  234. + pdeclaration(proc->args.argname, &l->decl, 1, ";\n");
  235. + }
  236. + } else { /* C++ style header */
  237. + f_print(fout, "(");
  238. + for (l = proc->args.decls; l != NULL; l = l->next) {
  239. + pdeclaration(proc->args.argname, &l->decl, 0, ", ");
  240. + }
  241. + f_print(fout, " %s%s)\n", addargtype, addargname);
  242. + }
  243. + }
  244. +
  245. + if (!Cflag)
  246. + f_print(fout, "\t%s%s;\n", addargtype, addargname);
  247. +}
  248. +
  249. +
  250. +
  251. +static char *
  252. +ampr(char *type)
  253. +{
  254. + if (isvectordef(type, REL_ALIAS)) {
  255. + return ("");
  256. + } else {
  257. + return ("&");
  258. + }
  259. +}
  260. +
  261. +static void
  262. +printbody(proc_list *proc)
  263. +{
  264. + decl_list *l;
  265. + bool_t args2 = (proc->arg_num > 1);
  266. +
  267. + /* For new style with multiple arguments, need a structure in which
  268. + * to stuff the arguments. */
  269. + if (newstyle && args2) {
  270. + f_print(fout, "\t%s", proc->args.argname);
  271. + f_print(fout, " arg;\n");
  272. + }
  273. + f_print(fout, "\tstatic ");
  274. + if (streq(proc->res_type, "void")) {
  275. + f_print(fout, "char ");
  276. + } else {
  277. + ptype(proc->res_prefix, proc->res_type, 0);
  278. + }
  279. + f_print(fout, "%s;\n", RESULT);
  280. + f_print(fout, "\n");
  281. + f_print(fout, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
  282. + ampr(proc->res_type), RESULT, RESULT);
  283. + if (newstyle && !args2 && (streq(proc->args.decls->decl.type, "void"))) {
  284. + /* newstyle, 0 arguments */
  285. + f_print(fout,
  286. + "\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_void, (caddr_t) NULL, "
  287. + "(xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
  288. + proc->proc_name,
  289. + stringfix(proc->res_type), ampr(proc->res_type), RESULT);
  290. +
  291. + } else if (newstyle && args2) {
  292. + /* newstyle, multiple arguments: stuff arguments into structure */
  293. + for (l = proc->args.decls; l != NULL; l = l->next) {
  294. + f_print(fout, "\targ.%s = %s;\n",
  295. + l->decl.name, l->decl.name);
  296. + }
  297. + f_print(fout,
  298. + "\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_%s, (caddr_t) &arg, "
  299. + "(xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
  300. + proc->proc_name, proc->args.argname,
  301. + stringfix(proc->res_type), ampr(proc->res_type), RESULT);
  302. + } else { /* single argument, new or old style */
  303. + f_print(fout,
  304. + "\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_%s, "
  305. + "(caddr_t) %s%s, (xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
  306. + proc->proc_name,
  307. + stringfix(proc->args.decls->decl.type),
  308. + (newstyle ? "&" : ""),
  309. + (newstyle ? proc->args.decls->decl.name : "argp"),
  310. + stringfix(proc->res_type), ampr(proc->res_type), RESULT);
  311. + }
  312. + f_print(fout, "\t\treturn (NULL);\n");
  313. + f_print(fout, "\t}\n");
  314. + if (streq(proc->res_type, "void")) {
  315. + f_print(fout, "\treturn ((void *)%s%s);\n",
  316. + ampr(proc->res_type), RESULT);
  317. + } else {
  318. + f_print(fout, "\treturn (%s%s);\n", ampr(proc->res_type), RESULT);
  319. + }
  320. +}
  321. diff --git a/rpcgen/rpc_cout.c b/rpcgen/rpc_cout.c
  322. new file mode 100644
  323. index 0000000..a61214f
  324. --- /dev/null
  325. +++ b/rpcgen/rpc_cout.c
  326. @@ -0,0 +1,706 @@
  327. +/*
  328. + * Copyright (c) 2009, Sun Microsystems, Inc.
  329. + * All rights reserved.
  330. + *
  331. + * Redistribution and use in source and binary forms, with or without
  332. + * modification, are permitted provided that the following conditions are met:
  333. + * - Redistributions of source code must retain the above copyright notice,
  334. + * this list of conditions and the following disclaimer.
  335. + * - Redistributions in binary form must reproduce the above copyright notice,
  336. + * this list of conditions and the following disclaimer in the documentation
  337. + * and/or other materials provided with the distribution.
  338. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  339. + * contributors may be used to endorse or promote products derived
  340. + * from this software without specific prior written permission.
  341. + *
  342. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  343. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  344. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  345. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  346. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  347. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  348. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  349. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  350. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  351. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  352. + * POSSIBILITY OF SUCH DAMAGE.
  353. + */
  354. +
  355. +#if 0
  356. +static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI";
  357. +#endif
  358. +
  359. +/*
  360. + * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
  361. + */
  362. +#include <stdio.h>
  363. +#include <string.h>
  364. +#include <stdlib.h>
  365. +#include <malloc.h>
  366. +#include <ctype.h>
  367. +#include "rpc_parse.h"
  368. +#include "rpc_util.h"
  369. +
  370. +static int findtype(definition *def, char *type);
  371. +static int undefined(char *type);
  372. +static void print_generic_header(char *procname, int pointerp);
  373. +static void print_header(definition *def);
  374. +static void print_prog_header(proc_list *plist);
  375. +static void print_trailer(void);
  376. +static void print_ifopen(int indent, char *name);
  377. +static void print_ifarg(char *arg);
  378. +static void print_ifsizeof(char *prefix, char *type);
  379. +static void print_ifclose(int indent);
  380. +static void print_ifstat(int indent, char *prefix, char *type, relation rel,
  381. + char *amax, char *objname, char *name);
  382. +static void emit_enum(definition *def);
  383. +static void emit_program(definition *def);
  384. +static void emit_union(definition *def);
  385. +static void emit_struct(definition *def);
  386. +static void emit_typedef(definition *def);
  387. +static void print_stat(int indent, declaration *dec);
  388. +static void emit_inline(declaration *decl, int flag);
  389. +static void emit_single_in_line(declaration *decl, int flag, relation rel);
  390. +static char * upcase(char *str);
  391. +
  392. +/*
  393. + * Emit the C-routine for the given definition
  394. + */
  395. +void
  396. +emit(definition *def)
  397. +{
  398. + if (def->def_kind == DEF_CONST) {
  399. + return;
  400. + }
  401. + if (def->def_kind == DEF_PROGRAM) {
  402. + emit_program(def);
  403. + return;
  404. + }
  405. + if (def->def_kind == DEF_TYPEDEF) {
  406. + /* now we need to handle declarations like
  407. + * struct typedef foo foo;
  408. + * since we dont want this to be expanded into 2 calls
  409. + * to xdr_foo */
  410. +
  411. + if (strcmp(def->def.ty.old_type, def->def_name) == 0)
  412. + return;
  413. + };
  414. +
  415. + print_header(def);
  416. + switch (def->def_kind) {
  417. + case DEF_UNION:
  418. + emit_union(def);
  419. + break;
  420. + case DEF_ENUM:
  421. + emit_enum(def);
  422. + break;
  423. + case DEF_STRUCT:
  424. + emit_struct(def);
  425. + break;
  426. + case DEF_TYPEDEF:
  427. + emit_typedef(def);
  428. + break;
  429. + default:
  430. + break;
  431. + }
  432. + print_trailer();
  433. +}
  434. +
  435. +static int
  436. +findtype(definition *def, char *type)
  437. +{
  438. +
  439. + if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
  440. + return (0);
  441. + } else {
  442. + return (streq(def->def_name, type));
  443. + }
  444. +}
  445. +
  446. +static int
  447. +undefined(char *type)
  448. +{
  449. + definition *def;
  450. +
  451. + def = (definition *) FINDVAL(defined, type, findtype);
  452. +
  453. + return (def == NULL);
  454. +}
  455. +
  456. +
  457. +static void
  458. +print_generic_header(char *procname, int pointerp)
  459. +{
  460. + f_print(fout, "\n");
  461. + f_print(fout, "bool_t\n");
  462. + if (Cflag) {
  463. + f_print(fout, "xdr_%s(", procname);
  464. + f_print(fout, "XDR *xdrs, ");
  465. + f_print(fout, "%s ", procname);
  466. + if (pointerp)
  467. + f_print(fout, "*");
  468. + f_print(fout, "objp)\n{\n\n");
  469. + } else {
  470. + f_print(fout, "xdr_%s(xdrs, objp)\n", procname);
  471. + f_print(fout, "\tXDR *xdrs;\n");
  472. + f_print(fout, "\t%s ", procname);
  473. + if (pointerp)
  474. + f_print(fout, "*");
  475. + f_print(fout, "objp;\n{\n\n");
  476. + }
  477. +}
  478. +
  479. +static void
  480. +print_header(definition *def)
  481. +{
  482. + print_generic_header(def->def_name,
  483. + def->def_kind != DEF_TYPEDEF ||
  484. + !isvectordef(def->def.ty.old_type, def->def.ty.rel));
  485. +
  486. + /* Now add Inline support */
  487. +
  488. +
  489. + if (Inline == 0)
  490. + return;
  491. +}
  492. +
  493. +static void
  494. +print_prog_header(proc_list *plist)
  495. +{
  496. + print_generic_header(plist->args.argname, 1);
  497. +}
  498. +
  499. +static void
  500. +print_trailer(void)
  501. +{
  502. + f_print(fout, "\treturn (TRUE);\n");
  503. + f_print(fout, "}\n");
  504. +}
  505. +
  506. +
  507. +static void
  508. +print_ifopen(int indent, char *name)
  509. +{
  510. + tabify(fout, indent);
  511. + f_print(fout, " if (!xdr_%s(xdrs", name);
  512. +}
  513. +
  514. +static void
  515. +print_ifarg(char *arg)
  516. +{
  517. + f_print(fout, ", %s", arg);
  518. +}
  519. +
  520. +static void
  521. +print_ifsizeof(char *prefix, char *type)
  522. +{
  523. + if (streq(type, "bool")) {
  524. + f_print(fout, ", sizeof(bool_t), (xdrproc_t)xdr_bool");
  525. + } else {
  526. + f_print(fout, ", sizeof(");
  527. + if (undefined(type) && prefix) {
  528. + f_print(fout, "%s ", prefix);
  529. + }
  530. + f_print(fout, "%s), (xdrproc_t)xdr_%s", type, type);
  531. + }
  532. +}
  533. +
  534. +static void
  535. +print_ifclose(int indent)
  536. +{
  537. + f_print(fout, ")) {\n");
  538. + tabify(fout, indent);
  539. + f_print(fout, "\t return (FALSE);\n");
  540. + tabify(fout, indent);
  541. + f_print(fout, " }\n");
  542. +}
  543. +
  544. +static void
  545. +print_ifstat(int indent, char *prefix, char *type, relation rel,
  546. + char *amax, char *objname, char *name)
  547. +{
  548. + char *alt = NULL;
  549. +
  550. + switch (rel) {
  551. + case REL_POINTER:
  552. + print_ifopen(indent, "pointer");
  553. + print_ifarg("(char **)");
  554. + f_print(fout, "%s", objname);
  555. + print_ifsizeof(prefix, type);
  556. + break;
  557. + case REL_VECTOR:
  558. + if (streq(type, "string")) {
  559. + alt = "string";
  560. + } else if (streq(type, "opaque")) {
  561. + alt = "opaque";
  562. + }
  563. + if (alt) {
  564. + print_ifopen(indent, alt);
  565. + print_ifarg(objname);
  566. + } else {
  567. + print_ifopen(indent, "vector");
  568. + print_ifarg("(char *)");
  569. + f_print(fout, "%s", objname);
  570. + }
  571. + print_ifarg(amax);
  572. + if (!alt) {
  573. + print_ifsizeof(prefix, type);
  574. + }
  575. + break;
  576. + case REL_ARRAY:
  577. + if (streq(type, "string")) {
  578. + alt = "string";
  579. + } else if (streq(type, "opaque")) {
  580. + alt = "bytes";
  581. + }
  582. + if (streq(type, "string")) {
  583. + print_ifopen(indent, alt);
  584. + print_ifarg(objname);
  585. + } else {
  586. + if (alt) {
  587. + print_ifopen(indent, alt);
  588. + } else {
  589. + print_ifopen(indent, "array");
  590. + }
  591. + /* The (void*) avoids a gcc-4.1 warning */
  592. + print_ifarg("(char **)(void*)");
  593. + if (*objname == '&') {
  594. + f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",
  595. + objname, name, objname, name);
  596. + } else {
  597. + f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len",
  598. + objname, name, objname, name);
  599. + }
  600. + }
  601. + print_ifarg(amax);
  602. + if (!alt) {
  603. + print_ifsizeof(prefix, type);
  604. + }
  605. + break;
  606. + case REL_ALIAS:
  607. + print_ifopen(indent, type);
  608. + print_ifarg(objname);
  609. + break;
  610. + }
  611. + print_ifclose(indent);
  612. +}
  613. +
  614. +static void
  615. +emit_enum(definition *def)
  616. +{
  617. + print_ifopen(1, "enum");
  618. + print_ifarg("(enum_t *)objp");
  619. + print_ifclose(1);
  620. +}
  621. +
  622. +static void
  623. +emit_program(definition *def)
  624. +{
  625. + decl_list *dl;
  626. + version_list *vlist;
  627. + proc_list *plist;
  628. +
  629. + for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next)
  630. + for (plist = vlist->procs; plist != NULL; plist = plist->next) {
  631. + if (!newstyle || plist->arg_num < 2)
  632. + continue;/* old style, or single argument */
  633. + print_prog_header(plist);
  634. + for (dl = plist->args.decls; dl != NULL; dl = dl->next)
  635. + print_stat(1, &dl->decl);
  636. + print_trailer();
  637. + }
  638. +}
  639. +
  640. +
  641. +static void
  642. +emit_union(definition *def)
  643. +{
  644. + declaration *dflt;
  645. + case_list *cl;
  646. + declaration *cs;
  647. + char *object;
  648. + char *vecformat = "objp->%s_u.%s";
  649. + char *format = "&objp->%s_u.%s";
  650. +
  651. + print_stat(1,&def->def.un.enum_decl);
  652. + f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
  653. + for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
  654. +
  655. + f_print(fout, "\tcase %s:\n", cl->case_name);
  656. + if(cl->contflag == 1) /* a continued case statement */
  657. + continue;
  658. + cs = &cl->case_decl;
  659. + if (!streq(cs->type, "void")) {
  660. + object = alloc(strlen(def->def_name) + strlen(format) +
  661. + strlen(cs->name) + 1);
  662. + if (isvectordef (cs->type, cs->rel)) {
  663. + s_print(object, vecformat, def->def_name,
  664. + cs->name);
  665. + } else {
  666. + s_print(object, format, def->def_name,
  667. + cs->name);
  668. + }
  669. + print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
  670. + object, cs->name);
  671. + free(object);
  672. + }
  673. + f_print(fout, "\t\tbreak;\n");
  674. + }
  675. + dflt = def->def.un.default_decl;
  676. + if (dflt != NULL) {
  677. + if (!streq(dflt->type, "void")) {
  678. + f_print(fout, "\tdefault:\n");
  679. + object = alloc(strlen(def->def_name) + strlen(format) +
  680. + strlen(dflt->name) + 1);
  681. + if (isvectordef (dflt->type, dflt->rel)) {
  682. + s_print(object, vecformat, def->def_name,
  683. + dflt->name);
  684. + } else {
  685. + s_print(object, format, def->def_name,
  686. + dflt->name);
  687. + }
  688. +
  689. + print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
  690. + dflt->array_max, object, dflt->name);
  691. + free(object);
  692. + f_print(fout, "\t\tbreak;\n");
  693. + } else {
  694. + /* Avoid gcc warnings about `value not handled in switch' */
  695. + f_print(fout, "\tdefault:\n");
  696. + f_print(fout, "\t\tbreak;\n");
  697. + }
  698. + } else {
  699. + f_print(fout, "\tdefault:\n");
  700. + f_print(fout, "\t\treturn (FALSE);\n");
  701. + }
  702. +
  703. + f_print(fout, "\t}\n");
  704. +}
  705. +
  706. +static void
  707. +emit_struct(definition *def)
  708. +{
  709. + decl_list *dl;
  710. + int i, j, size, flag;
  711. + decl_list *cur = NULL, *psav;
  712. + bas_type *ptr;
  713. + char *sizestr, *plus;
  714. + char ptemp[256];
  715. + int can_inline;
  716. + const char *buf_declaration;
  717. +
  718. +
  719. + if (Inline == 0) {
  720. + for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
  721. + print_stat(1, &dl->decl);
  722. + } else {
  723. + size = 0;
  724. + can_inline = 0;
  725. + for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
  726. + if ((dl->decl.prefix == NULL) && ((ptr = find_type(dl->decl.type)) != NULL) && ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) {
  727. +
  728. + if (dl->decl.rel == REL_ALIAS)
  729. + size += ptr->length;
  730. + else {
  731. + can_inline = 1;
  732. + break; /* can be inlined */
  733. + };
  734. + } else {
  735. + if (size >= Inline) {
  736. + can_inline = 1;
  737. + break; /* can be inlined */
  738. + }
  739. + size = 0;
  740. + }
  741. + if (size > Inline)
  742. + can_inline = 1;
  743. +
  744. + if (can_inline == 0) { /* can not inline, drop back to old mode */
  745. + for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
  746. + print_stat(1, &dl->decl);
  747. + return;
  748. + };
  749. +
  750. +
  751. +
  752. +
  753. + flag = PUT;
  754. + for (j = 0; j < 2; j++) {
  755. +
  756. + if (flag == PUT)
  757. + f_print(fout, "\n\t if (xdrs->x_op == XDR_ENCODE) {\n");
  758. + else
  759. + f_print(fout, "\n \t return (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n");
  760. +
  761. +
  762. + i = 0;
  763. + size = 0;
  764. + sizestr = NULL;
  765. + buf_declaration = "int32_t *";
  766. + for (dl = def->def.st.decls; dl != NULL; dl = dl->next) { /* xxx */
  767. +
  768. + /* now walk down the list and check for basic types */
  769. + if ((dl->decl.prefix == NULL) && ((ptr = find_type(dl->decl.type)) != NULL) && ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) {
  770. + if (i == 0)
  771. + cur = dl;
  772. + i++;
  773. +
  774. + if (dl->decl.rel == REL_ALIAS)
  775. + size += ptr->length;
  776. + else {
  777. + /* this is required to handle arrays */
  778. +
  779. + if (sizestr == NULL)
  780. + plus = " ";
  781. + else
  782. + plus = "+";
  783. +
  784. + if (ptr->length != 1)
  785. + s_print(ptemp, " %s %s * %d", plus, dl->decl.array_max, ptr->length);
  786. + else
  787. + s_print(ptemp, " %s %s ", plus, dl->decl.array_max);
  788. +
  789. + /*now concatenate to sizestr !!!! */
  790. + if (sizestr == NULL)
  791. + sizestr = strdup(ptemp);
  792. + else {
  793. + sizestr = realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1);
  794. + if (sizestr == NULL) {
  795. +
  796. + f_print(stderr, "Fatal error : no memory \n");
  797. + crash();
  798. + };
  799. + sizestr = strcat(sizestr, ptemp); /*build up length of array */
  800. +
  801. + }
  802. + }
  803. +
  804. + } else {
  805. + if (i > 0)
  806. + {
  807. + if (sizestr == NULL && size < Inline) {
  808. + /* don't expand into inline code if size < inline */
  809. + while (cur != dl) {
  810. + print_stat(1, &cur->decl);
  811. + cur = cur->next;
  812. + }
  813. + } else {
  814. +
  815. +
  816. +
  817. + /* were already looking at a xdr_inlineable structure */
  818. + if (sizestr == NULL)
  819. + f_print(fout, "\t %sbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
  820. + buf_declaration, size);
  821. + else if (size == 0)
  822. + f_print(fout,
  823. + "\t %sbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
  824. + buf_declaration, sizestr);
  825. + else
  826. + f_print(fout,
  827. + "\t %sbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
  828. + buf_declaration, size, sizestr);
  829. + buf_declaration = "";
  830. +
  831. + f_print(fout, "\n\t if (buf == NULL) {\n");
  832. +
  833. + psav = cur;
  834. + while (cur != dl) {
  835. + print_stat(2, &cur->decl);
  836. + cur = cur->next;
  837. + }
  838. +
  839. + f_print(fout, "\n\t }\n\t else {\n");
  840. +
  841. + cur = psav;
  842. + while (cur != dl) {
  843. + emit_inline(&cur->decl, flag);
  844. + cur = cur->next;
  845. + }
  846. +
  847. + f_print(fout, "\t }\n");
  848. + }
  849. + }
  850. + size = 0;
  851. + i = 0;
  852. + sizestr = NULL;
  853. + print_stat(1, &dl->decl);
  854. + }
  855. +
  856. + }
  857. + if (i > 0)
  858. + {
  859. + if (sizestr == NULL && size < Inline) {
  860. + /* don't expand into inline code if size < inline */
  861. + while (cur != dl) {
  862. + print_stat(1, &cur->decl);
  863. + cur = cur->next;
  864. + }
  865. + } else {
  866. +
  867. + /* were already looking at a xdr_inlineable structure */
  868. + if (sizestr == NULL)
  869. + f_print(fout, "\t\t%sbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
  870. + buf_declaration, size);
  871. + else if (size == 0)
  872. + f_print(fout,
  873. + "\t\t%sbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
  874. + buf_declaration, sizestr);
  875. + else
  876. + f_print(fout,
  877. + "\t\t%sbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
  878. + buf_declaration, size, sizestr);
  879. + buf_declaration = "";
  880. +
  881. + f_print(fout, "\n\t\tif (buf == NULL) {\n");
  882. +
  883. + psav = cur;
  884. + while (cur != NULL) {
  885. + print_stat(2, &cur->decl);
  886. + cur = cur->next;
  887. + }
  888. + f_print(fout, "\n\t }\n\t else {\n");
  889. +
  890. + cur = psav;
  891. + while (cur != dl) {
  892. + emit_inline(&cur->decl, flag);
  893. + cur = cur->next;
  894. + }
  895. +
  896. + f_print(fout, "\t }\n");
  897. +
  898. + }
  899. + }
  900. + flag = GET;
  901. + }
  902. + f_print(fout, "\t return(TRUE);\n\t}\n\n");
  903. +
  904. + /* now take care of XDR_FREE case */
  905. +
  906. + for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
  907. + print_stat(1, &dl->decl);
  908. + }
  909. +}
  910. +
  911. +
  912. +
  913. +
  914. +static void
  915. +emit_typedef(definition *def)
  916. +{
  917. + char *prefix = def->def.ty.old_prefix;
  918. + char *type = def->def.ty.old_type;
  919. + char *amax = def->def.ty.array_max;
  920. + relation rel = def->def.ty.rel;
  921. +
  922. +
  923. + print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
  924. +}
  925. +
  926. +static void
  927. +print_stat(int indent, declaration *dec)
  928. +{
  929. + char *prefix = dec->prefix;
  930. + char *type = dec->type;
  931. + char *amax = dec->array_max;
  932. + relation rel = dec->rel;
  933. + char name[256];
  934. +
  935. + if (isvectordef(type, rel)) {
  936. + s_print(name, "objp->%s", dec->name);
  937. + } else {
  938. + s_print(name, "&objp->%s", dec->name);
  939. + }
  940. + print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
  941. +}
  942. +
  943. +
  944. +static void
  945. +emit_inline(declaration *decl, int flag)
  946. +{
  947. +
  948. + /*check whether an array or not */
  949. +
  950. + switch (decl->rel) {
  951. + case REL_ALIAS:
  952. + emit_single_in_line(decl, flag, REL_ALIAS);
  953. + break;
  954. + case REL_VECTOR:
  955. + f_print(fout, "\t\t{ register %s *genp; \n", decl->type);
  956. + f_print(fout, "\t\t int i;\n");
  957. + f_print(fout, "\t\t for ( i = 0,genp=objp->%s;\n \t\t\ti < %s; i++){\n\t\t",
  958. + decl->name, decl->array_max);
  959. + emit_single_in_line(decl, flag, REL_VECTOR);
  960. + f_print(fout, "\t\t }\n\t\t };\n");
  961. + break;
  962. + default:
  963. + break;
  964. + }
  965. +}
  966. +
  967. +static void
  968. +emit_single_in_line(declaration *decl, int flag, relation rel)
  969. +{
  970. + char *upp_case;
  971. + int freed=0;
  972. +
  973. + if(flag == PUT)
  974. + f_print(fout,"\t\t (void) IXDR_PUT_");
  975. + else
  976. + if(rel== REL_ALIAS)
  977. + f_print(fout,"\t\t objp->%s = IXDR_GET_",decl->name);
  978. + else
  979. + f_print(fout,"\t\t *genp++ = IXDR_GET_");
  980. +
  981. + upp_case=upcase(decl->type);
  982. +
  983. + /* hack - XX */
  984. + if(strcmp(upp_case,"INT") == 0)
  985. + {
  986. + free(upp_case);
  987. + freed=1;
  988. + upp_case="INT32";
  989. + }
  990. +
  991. + if(strcmp(upp_case,"U_INT") == 0)
  992. + {
  993. + free(upp_case);
  994. + freed=1;
  995. + upp_case="U_INT32";
  996. + }
  997. +
  998. +
  999. + if(flag == PUT)
  1000. + if(rel== REL_ALIAS)
  1001. + f_print(fout,"%s(buf,objp->%s);\n",upp_case,decl->name);
  1002. + else
  1003. + f_print(fout,"%s(buf,*genp++);\n",upp_case);
  1004. +
  1005. + else
  1006. + f_print(fout,"%s(buf);\n",upp_case);
  1007. + if(!freed)
  1008. + free(upp_case);
  1009. +
  1010. +}
  1011. +
  1012. +
  1013. +static char *
  1014. +upcase(char *str)
  1015. +{
  1016. + char *ptr, *hptr;
  1017. +
  1018. +
  1019. + ptr = (char *) malloc(strlen(str)+1);
  1020. + if (ptr == (char *) NULL) {
  1021. + f_print(stderr, "malloc failed \n");
  1022. + exit(1);
  1023. + };
  1024. +
  1025. + hptr = ptr;
  1026. + while (*str != '\0')
  1027. + *ptr++ = toupper(*str++);
  1028. +
  1029. + *ptr = '\0';
  1030. + return (hptr);
  1031. +
  1032. +}
  1033. diff --git a/rpcgen/rpc_hout.c b/rpcgen/rpc_hout.c
  1034. new file mode 100644
  1035. index 0000000..ea1cb24
  1036. --- /dev/null
  1037. +++ b/rpcgen/rpc_hout.c
  1038. @@ -0,0 +1,490 @@
  1039. +/*
  1040. + * Copyright (c) 2009, Sun Microsystems, Inc.
  1041. + * All rights reserved.
  1042. + *
  1043. + * Redistribution and use in source and binary forms, with or without
  1044. + * modification, are permitted provided that the following conditions are met:
  1045. + * - Redistributions of source code must retain the above copyright notice,
  1046. + * this list of conditions and the following disclaimer.
  1047. + * - Redistributions in binary form must reproduce the above copyright notice,
  1048. + * this list of conditions and the following disclaimer in the documentation
  1049. + * and/or other materials provided with the distribution.
  1050. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  1051. + * contributors may be used to endorse or promote products derived
  1052. + * from this software without specific prior written permission.
  1053. + *
  1054. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  1055. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1056. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1057. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  1058. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  1059. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  1060. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  1061. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  1062. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  1063. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  1064. + * POSSIBILITY OF SUCH DAMAGE.
  1065. + */
  1066. +
  1067. +#if 0
  1068. +static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI";
  1069. +#endif
  1070. +
  1071. +/*
  1072. + * rpc_hout.c, Header file outputter for the RPC protocol compiler
  1073. + */
  1074. +#include <stdio.h>
  1075. +#include <ctype.h>
  1076. +#include "rpc_parse.h"
  1077. +#include "rpc_util.h"
  1078. +#include "rpc_output.h"
  1079. +
  1080. +
  1081. +static int undefined2(char *type, char *stop);
  1082. +static void pxdrfuncdecl(char *name, int pointerp);
  1083. +static void pconstdef(definition *def);
  1084. +static void pargdef(definition *def);
  1085. +static void pstructdef(definition *def);
  1086. +static void puniondef(definition *def);
  1087. +static void pdefine(char *name, char *num);
  1088. +static void puldefine(char *name, char *num);
  1089. +static int define_printed(proc_list *stop, version_list *start);
  1090. +static void pprogramdef(definition *def);
  1091. +static void pprocdef(proc_list *proc, version_list *vp,
  1092. + char *addargtype, int server_p, int mode);
  1093. +static void parglist(proc_list *proc, char *addargtype);
  1094. +static void penumdef(definition *def);
  1095. +static void ptypedef(definition *def);
  1096. +
  1097. +/*
  1098. + * Print the C-version of an xdr definition
  1099. + */
  1100. +void
  1101. +print_datadef(definition *def)
  1102. +{
  1103. +
  1104. + if (def->def_kind == DEF_PROGRAM ) /* handle data only */
  1105. + return;
  1106. +
  1107. + if (def->def_kind != DEF_CONST) {
  1108. + f_print(fout, "\n");
  1109. + }
  1110. + switch (def->def_kind) {
  1111. + case DEF_STRUCT:
  1112. + pstructdef(def);
  1113. + break;
  1114. + case DEF_UNION:
  1115. + puniondef(def);
  1116. + break;
  1117. + case DEF_ENUM:
  1118. + penumdef(def);
  1119. + break;
  1120. + case DEF_TYPEDEF:
  1121. + ptypedef(def);
  1122. + break;
  1123. + case DEF_PROGRAM:
  1124. + pprogramdef(def);
  1125. + break;
  1126. + case DEF_CONST:
  1127. + pconstdef(def);
  1128. + break;
  1129. + }
  1130. + if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) {
  1131. + pxdrfuncdecl( def->def_name,
  1132. + def->def_kind != DEF_TYPEDEF ||
  1133. + !isvectordef(def->def.ty.old_type, def->def.ty.rel));
  1134. +
  1135. + }
  1136. +}
  1137. +
  1138. +
  1139. +void
  1140. +print_funcdef(definition *def)
  1141. +{
  1142. + switch (def->def_kind) {
  1143. + case DEF_PROGRAM:
  1144. + f_print(fout, "\n");
  1145. + pprogramdef(def);
  1146. + break;
  1147. + default:
  1148. + break;
  1149. + }
  1150. +}
  1151. +
  1152. +static void
  1153. +pxdrfuncdecl(char *name, int pointerp)
  1154. +{
  1155. + f_print(fout,
  1156. + "#ifdef __cplusplus \n"
  1157. + "extern \"C\" bool_t xdr_%s(XDR *, %s%s);\n"
  1158. + "#elif __STDC__ \n"
  1159. + "extern bool_t xdr_%s(XDR *, %s%s);\n"
  1160. + "#else /* Old Style C */ \n"
  1161. + "bool_t xdr_%s();\n"
  1162. + "#endif /* Old Style C */ \n\n",
  1163. + name, name, pointerp ? "*" : "",
  1164. + name, name, pointerp ? "*" : "",
  1165. + name);
  1166. +}
  1167. +
  1168. +
  1169. +static void
  1170. +pconstdef(definition *def)
  1171. +{
  1172. + pdefine(def->def_name, def->def.co);
  1173. +}
  1174. +
  1175. +/* print out the definitions for the arguments of functions in the
  1176. + header file
  1177. +*/
  1178. +static void
  1179. +pargdef(definition *def)
  1180. +{
  1181. + decl_list *l;
  1182. + version_list *vers;
  1183. + char *name;
  1184. + proc_list *plist;
  1185. +
  1186. +
  1187. + for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
  1188. + for(plist = vers->procs; plist != NULL;
  1189. + plist = plist->next) {
  1190. +
  1191. + if (!newstyle || plist->arg_num < 2) {
  1192. + continue; /* old style or single args */
  1193. + }
  1194. + name = plist->args.argname;
  1195. + f_print(fout, "struct %s {\n", name);
  1196. + for (l = plist->args.decls;
  1197. + l != NULL; l = l->next) {
  1198. + pdeclaration(name, &l->decl, 1, ";\n" );
  1199. + }
  1200. + f_print(fout, "};\n");
  1201. + f_print(fout, "typedef struct %s %s;\n", name, name);
  1202. + pxdrfuncdecl(name, 0);
  1203. + f_print( fout, "\n" );
  1204. + }
  1205. + }
  1206. +
  1207. +}
  1208. +
  1209. +
  1210. +static void
  1211. +pstructdef(definition *def)
  1212. +{
  1213. + decl_list *l;
  1214. + char *name = def->def_name;
  1215. +
  1216. + f_print(fout, "struct %s {\n", name);
  1217. + for (l = def->def.st.decls; l != NULL; l = l->next) {
  1218. + pdeclaration(name, &l->decl, 1, ";\n");
  1219. + }
  1220. + f_print(fout, "};\n");
  1221. + f_print(fout, "typedef struct %s %s;\n", name, name);
  1222. +}
  1223. +
  1224. +static void
  1225. +puniondef(definition *def)
  1226. +{
  1227. + case_list *l;
  1228. + char *name = def->def_name;
  1229. + declaration *decl;
  1230. +
  1231. + f_print(fout, "struct %s {\n", name);
  1232. + decl = &def->def.un.enum_decl;
  1233. + if (streq(decl->type, "bool")) {
  1234. + f_print(fout, "\tbool_t %s;\n", decl->name);
  1235. + } else {
  1236. + f_print(fout, "\t%s %s;\n", decl->type, decl->name);
  1237. + }
  1238. + f_print(fout, "\tunion {\n");
  1239. + for (l = def->def.un.cases; l != NULL; l = l->next) {
  1240. + if (l->contflag == 0)
  1241. + pdeclaration(name, &l->case_decl, 2, ";\n");
  1242. + }
  1243. + decl = def->def.un.default_decl;
  1244. + if (decl && !streq(decl->type, "void")) {
  1245. + pdeclaration(name, decl, 2, ";\n");
  1246. + }
  1247. + f_print(fout, "\t} %s_u;\n", name);
  1248. + f_print(fout, "};\n");
  1249. + f_print(fout, "typedef struct %s %s;\n", name, name);
  1250. +}
  1251. +
  1252. +static void
  1253. +pdefine(char *name, char *num)
  1254. +{
  1255. + f_print(fout, "#define %s %s\n", name, num);
  1256. +}
  1257. +
  1258. +static void
  1259. +puldefine(char *name, char *num)
  1260. +{
  1261. + f_print(fout, "#define %s ((u_int32_t)%s)\n", name, num);
  1262. +}
  1263. +
  1264. +static int
  1265. +define_printed(proc_list *stop, version_list *start)
  1266. +{
  1267. + version_list *vers;
  1268. + proc_list *proc;
  1269. +
  1270. + for (vers = start; vers != NULL; vers = vers->next) {
  1271. + for (proc = vers->procs; proc != NULL; proc = proc->next) {
  1272. + if (proc == stop) {
  1273. + return (0);
  1274. + } else if (streq(proc->proc_name, stop->proc_name)) {
  1275. + return (1);
  1276. + }
  1277. + }
  1278. + }
  1279. + abort();
  1280. + /* NOTREACHED */
  1281. +}
  1282. +
  1283. +static void
  1284. +pprogramdef(definition *def)
  1285. +{
  1286. + version_list *vers;
  1287. + proc_list *proc;
  1288. + int i;
  1289. + char *ext;
  1290. +
  1291. + pargdef(def);
  1292. +
  1293. + puldefine(def->def_name, def->def.pr.prog_num);
  1294. + for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
  1295. + if (tblflag) {
  1296. + f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n",
  1297. + locase(def->def_name), vers->vers_num);
  1298. + f_print(fout, "extern %s_%s_nproc;\n",
  1299. + locase(def->def_name), vers->vers_num);
  1300. + }
  1301. + puldefine(vers->vers_name, vers->vers_num);
  1302. +
  1303. + /*
  1304. + * Print out 3 definitions, one for ANSI-C, another for C++,
  1305. + * a third for old style C
  1306. + */
  1307. +
  1308. + for (i = 0; i < 3; i++) {
  1309. + if (i == 0) {
  1310. + f_print(fout, "\n#ifdef __cplusplus\n");
  1311. + ext = "extern \"C\" ";
  1312. + } else if (i == 1) {
  1313. + f_print(fout, "\n#elif __STDC__\n");
  1314. + ext = "extern ";
  1315. + } else {
  1316. + f_print(fout, "\n#else /* Old Style C */ \n");
  1317. + ext = "extern ";
  1318. + }
  1319. +
  1320. +
  1321. + for (proc = vers->procs; proc != NULL; proc = proc->next) {
  1322. + if (!define_printed(proc, def->def.pr.versions)) {
  1323. + puldefine(proc->proc_name, proc->proc_num);
  1324. + }
  1325. + f_print(fout, "%s", ext);
  1326. + pprocdef(proc, vers, "CLIENT *", 0, i);
  1327. + f_print(fout, "%s", ext);
  1328. + pprocdef(proc, vers, "struct svc_req *", 1, i);
  1329. +
  1330. + }
  1331. +
  1332. + }
  1333. + f_print(fout, "#endif /* Old Style C */ \n");
  1334. + }
  1335. +}
  1336. +
  1337. +static void
  1338. +pprocdef(proc_list *proc, version_list *vp, char *addargtype,
  1339. + int server_p, int mode)
  1340. +{
  1341. + ptype(proc->res_prefix, proc->res_type, 1);
  1342. + f_print(fout, "* ");
  1343. + if (server_p)
  1344. + pvname_svc(proc->proc_name, vp->vers_num);
  1345. + else
  1346. + pvname(proc->proc_name, vp->vers_num);
  1347. +
  1348. + /*
  1349. + * mode 0 == cplusplus, mode 1 = ANSI-C, mode 2 = old style C
  1350. + */
  1351. + if (mode == 0 || mode == 1)
  1352. + parglist(proc, addargtype);
  1353. + else
  1354. + f_print(fout, "();\n");
  1355. +}
  1356. +
  1357. +
  1358. +
  1359. +/* print out argument list of procedure */
  1360. +static void
  1361. +parglist(proc_list *proc, char *addargtype)
  1362. +{
  1363. + decl_list *dl;
  1364. +
  1365. + f_print(fout, "(");
  1366. +
  1367. + if (proc->arg_num < 2 && newstyle &&
  1368. + streq(proc->args.decls->decl.type, "void")) {
  1369. + /* 0 argument in new style: do nothing */
  1370. + } else {
  1371. + for (dl = proc->args.decls; dl != NULL; dl = dl->next) {
  1372. + ptype(dl->decl.prefix, dl->decl.type, 1);
  1373. + if (!newstyle)
  1374. + f_print(fout, "*"); /* old style passes by reference */
  1375. +
  1376. + f_print(fout, ", ");
  1377. + }
  1378. + }
  1379. +
  1380. + f_print(fout, "%s);\n", addargtype);
  1381. +}
  1382. +
  1383. +static void
  1384. +penumdef(definition *def)
  1385. +{
  1386. + char *name = def->def_name;
  1387. + enumval_list *l;
  1388. + char *last = NULL;
  1389. + int count = 0;
  1390. +
  1391. + f_print(fout, "enum %s {\n", name);
  1392. + for (l = def->def.en.vals; l != NULL; l = l->next) {
  1393. + f_print(fout, "\t%s", l->name);
  1394. + if (l->assignment) {
  1395. + f_print(fout, " = %s", l->assignment);
  1396. + last = l->assignment;
  1397. + count = 1;
  1398. + } else {
  1399. + if (last == NULL) {
  1400. + f_print(fout, " = %d", count++);
  1401. + } else {
  1402. + f_print(fout, " = %s + %d", last, count++);
  1403. + }
  1404. + }
  1405. + f_print(fout, ",\n");
  1406. + }
  1407. + f_print(fout, "};\n");
  1408. + f_print(fout, "typedef enum %s %s;\n", name, name);
  1409. +}
  1410. +
  1411. +static void
  1412. +ptypedef(definition *def)
  1413. +{
  1414. + char *name = def->def_name;
  1415. + char *old = def->def.ty.old_type;
  1416. + char prefix[8]; /* enough to contain "struct ", including NUL */
  1417. + relation rel = def->def.ty.rel;
  1418. +
  1419. +
  1420. + if (!streq(name, old)) {
  1421. + if (streq(old, "string")) {
  1422. + old = "char";
  1423. + rel = REL_POINTER;
  1424. + } else if (streq(old, "opaque")) {
  1425. + old = "char";
  1426. + } else if (streq(old, "bool")) {
  1427. + old = "bool_t";
  1428. + }
  1429. + if (undefined2(old, name) && def->def.ty.old_prefix) {
  1430. + s_print(prefix, "%s ", def->def.ty.old_prefix);
  1431. + } else {
  1432. + prefix[0] = 0;
  1433. + }
  1434. + f_print(fout, "typedef ");
  1435. + switch (rel) {
  1436. + case REL_ARRAY:
  1437. + f_print(fout, "struct {\n");
  1438. + f_print(fout, "\tu_int %s_len;\n", name);
  1439. + f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
  1440. + f_print(fout, "} %s", name);
  1441. + break;
  1442. + case REL_POINTER:
  1443. + f_print(fout, "%s%s *%s", prefix, old, name);
  1444. + break;
  1445. + case REL_VECTOR:
  1446. + f_print(fout, "%s%s %s[%s]", prefix, old, name,
  1447. + def->def.ty.array_max);
  1448. + break;
  1449. + case REL_ALIAS:
  1450. + f_print(fout, "%s%s %s", prefix, old, name);
  1451. + break;
  1452. + }
  1453. + f_print(fout, ";\n");
  1454. + }
  1455. +}
  1456. +
  1457. +void
  1458. +pdeclaration(char *name, declaration *dec, int tab, char *separator)
  1459. +{
  1460. + char buf[8]; /* enough to hold "struct ", include NUL */
  1461. + char *prefix;
  1462. + char *type;
  1463. +
  1464. + if (streq(dec->type, "void")) {
  1465. + return;
  1466. + }
  1467. + tabify(fout, tab);
  1468. + if (streq(dec->type, name) && !dec->prefix) {
  1469. + f_print(fout, "struct ");
  1470. + }
  1471. + if (streq(dec->type, "string")) {
  1472. + f_print(fout, "char *%s", dec->name);
  1473. + } else {
  1474. + prefix = "";
  1475. + if (streq(dec->type, "bool")) {
  1476. + type = "bool_t";
  1477. + } else if (streq(dec->type, "opaque")) {
  1478. + type = "char";
  1479. + } else {
  1480. + if (dec->prefix) {
  1481. + s_print(buf, "%s ", dec->prefix);
  1482. + prefix = buf;
  1483. + }
  1484. + type = dec->type;
  1485. + }
  1486. + switch (dec->rel) {
  1487. + case REL_ALIAS:
  1488. + f_print(fout, "%s%s %s", prefix, type, dec->name);
  1489. + break;
  1490. + case REL_VECTOR:
  1491. + f_print(fout, "%s%s %s[%s]", prefix, type, dec->name,
  1492. + dec->array_max);
  1493. + break;
  1494. + case REL_POINTER:
  1495. + f_print(fout, "%s%s *%s", prefix, type, dec->name);
  1496. + break;
  1497. + case REL_ARRAY:
  1498. + f_print(fout, "struct {\n");
  1499. + tabify(fout, tab);
  1500. + f_print(fout, "\tu_int %s_len;\n", dec->name);
  1501. + tabify(fout, tab);
  1502. + f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
  1503. + tabify(fout, tab);
  1504. + f_print(fout, "} %s", dec->name);
  1505. + break;
  1506. + }
  1507. + }
  1508. + f_print(fout, separator );
  1509. +}
  1510. +
  1511. +static int
  1512. +undefined2(char *type, char *stop)
  1513. +{
  1514. + list *l;
  1515. + definition *def;
  1516. +
  1517. + for (l = defined; l != NULL; l = l->next) {
  1518. + def = (definition *) l->val;
  1519. + if (def->def_kind != DEF_PROGRAM) {
  1520. + if (streq(def->def_name, stop)) {
  1521. + return (1);
  1522. + } else if (streq(def->def_name, type)) {
  1523. + return (0);
  1524. + }
  1525. + }
  1526. + }
  1527. + return (1);
  1528. +}
  1529. diff --git a/rpcgen/rpc_main.c b/rpcgen/rpc_main.c
  1530. new file mode 100644
  1531. index 0000000..28aa60c
  1532. --- /dev/null
  1533. +++ b/rpcgen/rpc_main.c
  1534. @@ -0,0 +1,1067 @@
  1535. +/*
  1536. + * Copyright (c) 2009, Sun Microsystems, Inc.
  1537. + * All rights reserved.
  1538. + *
  1539. + * Redistribution and use in source and binary forms, with or without
  1540. + * modification, are permitted provided that the following conditions are met:
  1541. + * - Redistributions of source code must retain the above copyright notice,
  1542. + * this list of conditions and the following disclaimer.
  1543. + * - Redistributions in binary form must reproduce the above copyright notice,
  1544. + * this list of conditions and the following disclaimer in the documentation
  1545. + * and/or other materials provided with the distribution.
  1546. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  1547. + * contributors may be used to endorse or promote products derived
  1548. + * from this software without specific prior written permission.
  1549. + *
  1550. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  1551. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1552. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1553. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  1554. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  1555. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  1556. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  1557. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  1558. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  1559. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  1560. + * POSSIBILITY OF SUCH DAMAGE.
  1561. + */
  1562. +
  1563. +#if 0
  1564. +static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
  1565. +#endif
  1566. +
  1567. +/*
  1568. + * rpc_main.c, Top level of the RPC protocol compiler.
  1569. + */
  1570. +
  1571. +#include <sys/types.h>
  1572. +#include <sys/param.h>
  1573. +#include <sys/file.h>
  1574. +#include <sys/stat.h>
  1575. +#include <stdio.h>
  1576. +#include <string.h>
  1577. +#include <stdlib.h>
  1578. +#include <unistd.h>
  1579. +#include <ctype.h>
  1580. +#include <errno.h>
  1581. +#include "rpc_parse.h"
  1582. +#include "rpc_util.h"
  1583. +#include "rpc_scan.h"
  1584. +
  1585. +struct commandline {
  1586. + int cflag; /* xdr C routines */
  1587. + int hflag; /* header file */
  1588. + int lflag; /* client side stubs */
  1589. + int mflag; /* server side stubs */
  1590. + int nflag; /* netid flag */
  1591. + int sflag; /* server stubs for the given transport */
  1592. + int tflag; /* dispatch Table file */
  1593. + int Ssflag; /* produce server sample code */
  1594. + int Scflag; /* produce client sample code */
  1595. + char *infile; /* input module name */
  1596. + char *outfile; /* output module name */
  1597. +};
  1598. +
  1599. +static char * extendfile(char *file, char *ext);
  1600. +static void open_output(char *infile, char *outfile);
  1601. +static void add_warning(void);
  1602. +static void clear_args(void);
  1603. +static void open_input(char *infile, char *define);
  1604. +static int check_nettype(char *name, char **list_to_check);
  1605. +static void c_output(char *infile, char *define, int extend, char *outfile);
  1606. +static void c_initialize(void);
  1607. +static char * generate_guard(char *pathname);
  1608. +static void h_output(char *infile, char *define, int extend, char *outfile);
  1609. +static void s_output(int argc, char **argv, char *infile,
  1610. + char *define, int extend, char *outfile,
  1611. + int nomain, int netflag);
  1612. +static void l_output(char *infile, char *define, int extend, char *outfile);
  1613. +static void t_output(char *infile, char *define, int extend, char *outfile);
  1614. +static void svc_output(char *, char *, int, char *);
  1615. +static void clnt_output(char *, char *, int, char *);
  1616. +static int do_registers(int argc, char **argv);
  1617. +static void addarg(char *cp);
  1618. +static void putarg(int where, char *cp);
  1619. +static void checkfiles(char *infile, char *outfile);
  1620. +static int parseargs(int argc, char **argv, struct commandline *cmd);
  1621. +static void usage(void);
  1622. +static void options_usage(void);
  1623. +
  1624. +/*
  1625. +extern void write_sample_svc();
  1626. +int write_sample_clnt();
  1627. +void write_sample_clnt_main();
  1628. +
  1629. +static svc_output();
  1630. + */
  1631. +
  1632. +#define EXTEND 1 /* alias for TRUE */
  1633. +#define DONT_EXTEND 0 /* alias for FALSE */
  1634. +
  1635. +#define SVR4_CPP "/usr/ccs/lib/cpp"
  1636. +#define SUNOS_CPP "/lib/cpp"
  1637. +static int cppDefined = 0; /* explicit path for C preprocessor */
  1638. +
  1639. +
  1640. +static char *cmdname;
  1641. +
  1642. +static char *svcclosetime = "120";
  1643. +static char *CPP = SVR4_CPP;
  1644. +static char CPPFLAGS[] = "-C";
  1645. +static char pathbuf[MAXPATHLEN + 1];
  1646. +static char *allv[] = {
  1647. + "rpcgen", "-s", "udp", "-s", "tcp",
  1648. +};
  1649. +static int allc = sizeof(allv)/sizeof(allv[0]);
  1650. +static char *allnv[] = {
  1651. + "rpcgen", "-s", "netpath",
  1652. +};
  1653. +static int allnc = sizeof(allnv)/sizeof(allnv[0]);
  1654. +
  1655. +/*
  1656. + * machinations for handling expanding argument list
  1657. + */
  1658. +#if 0
  1659. +static void addarg(); /* add another argument to the list */
  1660. +static void putarg(); /* put argument at specified location */
  1661. +static void clear_args(); /* clear argument list */
  1662. +static void checkfiles(); /* check if out file already exists */
  1663. +#endif
  1664. +
  1665. +
  1666. +
  1667. +#define ARGLISTLEN 20
  1668. +#define FIXEDARGS 2
  1669. +
  1670. +static char *arglist[ARGLISTLEN];
  1671. +static int argcount = FIXEDARGS;
  1672. +
  1673. +
  1674. +int nonfatalerrors; /* errors */
  1675. +int inetdflag/* = 1*/; /* Support for inetd */ /* is now the default */
  1676. +int pmflag; /* Support for port monitors */
  1677. +int logflag; /* Use syslog instead of fprintf for errors */
  1678. +int tblflag; /* Support for dispatch table file */
  1679. +
  1680. +/* length at which to start doing an inline */
  1681. +#define INLINE 3
  1682. +
  1683. +int Inline = INLINE; /* length at which to start doing an inline. 3 = default
  1684. + * if 0, no xdr_inline code */
  1685. +
  1686. +int indefinitewait; /* If started by port monitors, hang till it wants */
  1687. +int exitnow; /* If started by port monitors, exit after the call */
  1688. +int timerflag; /* TRUE if !indefinite && !exitnow */
  1689. +int newstyle; /* newstyle of passing arguments (by value) */
  1690. +int Cflag = 0 ; /* ANSI C syntax */
  1691. +static int allfiles; /* generate all files */
  1692. +#ifdef linux
  1693. +int tirpcflag = 0; /* no tirpc by default */
  1694. +#else
  1695. +int tirpcflag = 1; /* generating code for tirpc, by default */
  1696. +#endif
  1697. +
  1698. +int
  1699. +main(int argc, char **argv)
  1700. +{
  1701. + struct commandline cmd;
  1702. +
  1703. + (void) memset((char *) &cmd, 0, sizeof(struct commandline));
  1704. + clear_args();
  1705. + if (!parseargs(argc, argv, &cmd))
  1706. + usage();
  1707. +
  1708. + if (cmd.cflag || cmd.hflag || cmd.lflag || cmd.tflag || cmd.sflag ||
  1709. + cmd.mflag || cmd.nflag || cmd.Ssflag || cmd.Scflag) {
  1710. + checkfiles(cmd.infile, cmd.outfile);
  1711. + } else
  1712. + checkfiles(cmd.infile, NULL);
  1713. +
  1714. + if (cmd.cflag) {
  1715. + c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
  1716. + } else if (cmd.hflag) {
  1717. + h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
  1718. + } else if (cmd.lflag) {
  1719. + l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
  1720. + } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
  1721. + s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
  1722. + cmd.outfile, cmd.mflag, cmd.nflag);
  1723. + } else if (cmd.tflag) {
  1724. + t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
  1725. + } else if (cmd.Ssflag) {
  1726. + svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND, cmd.outfile);
  1727. + } else if (cmd.Scflag) {
  1728. + clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND, cmd.outfile);
  1729. + } else {
  1730. + /* the rescans are required, since cpp may effect input */
  1731. + c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
  1732. + reinitialize();
  1733. + h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h");
  1734. + reinitialize();
  1735. + l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
  1736. + reinitialize();
  1737. + if (inetdflag || !tirpcflag)
  1738. + s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
  1739. + "_svc.c", cmd.mflag, cmd.nflag);
  1740. + else
  1741. + s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
  1742. + EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
  1743. + if (tblflag) {
  1744. + reinitialize();
  1745. + t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
  1746. + }
  1747. + if (allfiles) {
  1748. + reinitialize();
  1749. + svc_output(cmd.infile, "-DRPC_SERVER", EXTEND, "_server.c");
  1750. + }
  1751. + if (allfiles) {
  1752. + reinitialize();
  1753. + clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND, "_client.c");
  1754. + }
  1755. + }
  1756. + exit(nonfatalerrors);
  1757. + /* NOTREACHED */
  1758. +}
  1759. +
  1760. +/*
  1761. + * add extension to filename
  1762. + */
  1763. +static char *
  1764. +extendfile(char *file, char *ext)
  1765. +{
  1766. + char *res;
  1767. + char *p;
  1768. +
  1769. + res = alloc(strlen(file) + strlen(ext) + 1);
  1770. + if (res == NULL) {
  1771. + abort();
  1772. + }
  1773. + p = strrchr(file, '.');
  1774. + if (p == NULL) {
  1775. + p = file + strlen(file);
  1776. + }
  1777. + (void) strcpy(res, file);
  1778. + (void) strcpy(res + (p - file), ext);
  1779. + return (res);
  1780. +}
  1781. +
  1782. +/*
  1783. + * Open output file with given extension
  1784. + */
  1785. +static void
  1786. +open_output(char *infile, char *outfile)
  1787. +{
  1788. +
  1789. + if (outfile == NULL) {
  1790. + fout = stdout;
  1791. + return;
  1792. + }
  1793. +
  1794. + if (infile != NULL && streq(outfile, infile)) {
  1795. + f_print(stderr, "%s: output would overwrite %s\n", cmdname,
  1796. + infile);
  1797. + crash();
  1798. + }
  1799. + fout = fopen(outfile, "w");
  1800. + if (fout == NULL) {
  1801. + f_print(stderr, "%s: unable to open ", cmdname);
  1802. + perror(outfile);
  1803. + crash();
  1804. + }
  1805. + record_open(outfile);
  1806. +
  1807. +}
  1808. +
  1809. +static void
  1810. +add_warning(void)
  1811. +{
  1812. + f_print(fout, "/*\n");
  1813. + f_print(fout, " * Please do not edit this file.\n");
  1814. + f_print(fout, " * It was generated using rpcgen.\n");
  1815. + f_print(fout, " */\n\n");
  1816. +}
  1817. +
  1818. +/* clear list of arguments */
  1819. +static void
  1820. +clear_args(void)
  1821. +{
  1822. + int i;
  1823. + for( i=FIXEDARGS; i<ARGLISTLEN; i++ )
  1824. + arglist[i] = NULL;
  1825. + argcount = FIXEDARGS;
  1826. +}
  1827. +
  1828. +/*
  1829. + * Open input file with given define for C-preprocessor
  1830. + */
  1831. +static void
  1832. +open_input(char *infile, char *define)
  1833. +{
  1834. + int pd[2];
  1835. +
  1836. + infilename = (infile == NULL) ? "<stdin>" : infile;
  1837. + (void) pipe(pd);
  1838. + switch (fork()) {
  1839. + case 0:
  1840. + putarg(0, "cpp");
  1841. + putarg(1, CPPFLAGS);
  1842. + addarg(define);
  1843. + addarg(infile);
  1844. + addarg((char *)NULL);
  1845. + (void) close(1);
  1846. + (void) dup2(pd[1], 1);
  1847. + (void) close(pd[0]);
  1848. + if (cppDefined)
  1849. + execv(CPP, arglist);
  1850. + else {
  1851. + execvp("cpp", arglist);
  1852. + if (errno == ENOENT)
  1853. + execvp(SVR4_CPP, arglist);
  1854. + if (errno == ENOENT)
  1855. + execvp(SUNOS_CPP, arglist);
  1856. + }
  1857. + perror("execv");
  1858. + exit(1);
  1859. + case -1:
  1860. + perror("fork");
  1861. + exit(1);
  1862. + }
  1863. + (void) close(pd[1]);
  1864. + fin = fdopen(pd[0], "r");
  1865. + if (fin == NULL) {
  1866. + f_print(stderr, "%s: ", cmdname);
  1867. + perror(infilename);
  1868. + crash();
  1869. + }
  1870. +}
  1871. +
  1872. +/* valid tirpc nettypes */
  1873. +static char* valid_ti_nettypes[] =
  1874. +{
  1875. + "netpath",
  1876. + "visible",
  1877. + "circuit_v",
  1878. + "datagram_v",
  1879. + "circuit_n",
  1880. + "datagram_n",
  1881. + "udp",
  1882. + "tcp",
  1883. + "raw",
  1884. + NULL
  1885. +};
  1886. +
  1887. +/* valid inetd nettypes */
  1888. +static char* valid_i_nettypes[] =
  1889. +{
  1890. + "udp",
  1891. + "tcp",
  1892. + NULL
  1893. +};
  1894. +
  1895. +static int
  1896. +check_nettype(char *name, char **list_to_check)
  1897. +{
  1898. + int i;
  1899. + for( i = 0; list_to_check[i] != NULL; i++ ) {
  1900. + if( strcmp( name, list_to_check[i] ) == 0 ) {
  1901. + return 1;
  1902. + }
  1903. + }
  1904. + f_print( stderr, "illegal nettype :\'%s\'\n", name );
  1905. + return 0;
  1906. +}
  1907. +
  1908. +/*
  1909. + * Compile into an XDR routine output file
  1910. + */
  1911. +
  1912. +static void
  1913. +c_output(char *infile, char *define, int extend, char *outfile)
  1914. +{
  1915. + definition *def;
  1916. + char *include;
  1917. + char *outfilename;
  1918. + long tell;
  1919. +
  1920. + c_initialize();
  1921. + open_input(infile, define);
  1922. + outfilename = extend ? extendfile(infile, outfile) : outfile;
  1923. + open_output(infile, outfilename);
  1924. + add_warning();
  1925. + if (infile && (include = extendfile(infile, ".h"))) {
  1926. + f_print(fout, "#include \"%s\"\n", include);
  1927. + free(include);
  1928. + /* .h file already contains rpc/rpc.h */
  1929. + } else
  1930. + f_print(fout, "#include <rpc/rpc.h>\n");
  1931. + tell = ftell(fout);
  1932. + while ((def = get_definition()) != NULL) {
  1933. + emit(def);
  1934. + }
  1935. + if (extend && tell == ftell(fout)) {
  1936. + (void) unlink(outfilename);
  1937. + }
  1938. +}
  1939. +
  1940. +
  1941. +static void
  1942. +c_initialize(void)
  1943. +{
  1944. +
  1945. + /* add all the starting basic types */
  1946. +
  1947. + add_type(1,"int");
  1948. + add_type(1,"int32_t");
  1949. + add_type(1,"short");
  1950. + add_type(1,"bool");
  1951. +
  1952. + add_type(1,"u_int");
  1953. + add_type(1,"u_int32_t");
  1954. + add_type(1,"u_short");
  1955. +
  1956. +}
  1957. +
  1958. +char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
  1959. + char *(*proc)();\n\
  1960. + xdrproc_t xdr_arg;\n\
  1961. + unsigned len_arg;\n\
  1962. + xdrproc_t xdr_res;\n\
  1963. + unsigned len_res;\n\
  1964. +};\n";
  1965. +
  1966. +
  1967. +static char *
  1968. +generate_guard(char *pathname)
  1969. +{
  1970. + char* filename, *guard, *tmp;
  1971. +
  1972. + filename = strrchr(pathname, '/' ); /* find last component */
  1973. + filename = ((filename == 0) ? pathname : filename+1);
  1974. + guard = strdup(filename);
  1975. + /* convert to upper case */
  1976. + tmp = guard;
  1977. + while (*tmp) {
  1978. + if (islower(*tmp))
  1979. + *tmp = toupper(*tmp);
  1980. + tmp++;
  1981. + }
  1982. +
  1983. + guard = extendfile(guard, "_H_RPCGEN");
  1984. + return( guard );
  1985. +}
  1986. +
  1987. +/*
  1988. + * Compile into an XDR header file
  1989. + */
  1990. +static void
  1991. +h_output(char *infile, char *define, int extend, char *outfile)
  1992. +{
  1993. + definition *def;
  1994. + char *outfilename;
  1995. + long tell;
  1996. + char *guard;
  1997. + list *l;
  1998. +
  1999. + open_input(infile, define);
  2000. + outfilename = extend ? extendfile(infile, outfile) : outfile;
  2001. + open_output(infile, outfilename);
  2002. + add_warning();
  2003. + guard = generate_guard( outfilename ? outfilename: infile );
  2004. +
  2005. + f_print(fout,"#ifndef _%s\n#define _%s\n\n", guard,
  2006. + guard);
  2007. +
  2008. + f_print(fout, "#include <rpc/rpc.h>\n\n");
  2009. +
  2010. + f_print(fout, "#ifndef IXDR_GET_INT32\n");
  2011. + f_print(fout, "#define IXDR_GET_INT32(buf) IXDR_GET_LONG((buf))\n");
  2012. + f_print(fout, "#endif\n");
  2013. + f_print(fout, "#ifndef IXDR_PUT_INT32\n");
  2014. + f_print(fout, "#define IXDR_PUT_INT32(buf, v) IXDR_PUT_LONG((buf), (v))\n");
  2015. + f_print(fout, "#endif\n");
  2016. + f_print(fout, "#ifndef IXDR_GET_U_INT32\n");
  2017. + f_print(fout, "#define IXDR_GET_U_INT32(buf) IXDR_GET_U_LONG((buf))\n");
  2018. + f_print(fout, "#endif\n");
  2019. + f_print(fout, "#ifndef IXDR_PUT_U_INT32\n");
  2020. + f_print(fout, "#define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_U_LONG((buf), (v))\n");
  2021. + f_print(fout, "#endif\n");
  2022. +
  2023. + tell = ftell(fout);
  2024. + /* print data definitions */
  2025. + while ((def = get_definition()) != NULL) {
  2026. + print_datadef(def);
  2027. + }
  2028. +
  2029. + /* print function declarations.
  2030. + Do this after data definitions because they might be used as
  2031. + arguments for functions */
  2032. + for (l = defined; l != NULL; l = l->next) {
  2033. + print_funcdef(l->val);
  2034. + }
  2035. + if (extend && tell == ftell(fout)) {
  2036. + (void) unlink(outfilename);
  2037. + } else if (tblflag) {
  2038. + f_print(fout, rpcgen_table_dcl);
  2039. + }
  2040. + f_print(fout, "\n#endif /* !_%s */\n", guard);
  2041. +}
  2042. +
  2043. +/*
  2044. + * Compile into an RPC service
  2045. + */
  2046. +static void
  2047. +s_output(int argc, char **argv, char *infile, char *define, int extend,
  2048. + char *outfile, int nomain, int netflag)
  2049. +{
  2050. + char *include;
  2051. + definition *def;
  2052. + int foundprogram = 0;
  2053. + char *outfilename;
  2054. +
  2055. + open_input(infile, define);
  2056. + outfilename = extend ? extendfile(infile, outfile) : outfile;
  2057. + open_output(infile, outfilename);
  2058. + add_warning();
  2059. + if (infile && (include = extendfile(infile, ".h"))) {
  2060. + f_print(fout, "#include \"%s\"\n", include);
  2061. + free(include);
  2062. + } else
  2063. + f_print(fout, "#include <rpc/rpc.h>\n");
  2064. +
  2065. + f_print(fout, "#include <stdio.h>\n");
  2066. + f_print(fout, "#include <stdlib.h>/* getenv, exit */\n");
  2067. + if (Cflag) {
  2068. + f_print (fout, "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
  2069. + f_print (fout, "#include <string.h> /* strcmp */ \n");
  2070. + }
  2071. + if (strcmp(svcclosetime, "-1") == 0)
  2072. + indefinitewait = 1;
  2073. + else if (strcmp(svcclosetime, "0") == 0)
  2074. + exitnow = 1;
  2075. + else if (inetdflag || pmflag) {
  2076. + f_print(fout, "#include <signal.h>\n");
  2077. + timerflag = 1;
  2078. + }
  2079. +
  2080. +#ifndef linux
  2081. + if( !tirpcflag && inetdflag )
  2082. + f_print(fout, "#include <sys/ttycom.h>/* TIOCNOTTY */\n");
  2083. +#else
  2084. + if( !tirpcflag )
  2085. + f_print(fout, "#include <sys/ioctl.h>/* TIOCNOTTY */\n");
  2086. +#endif
  2087. + if( Cflag && (inetdflag || pmflag ) ) {
  2088. + f_print(fout, "#ifdef __cplusplus\n");
  2089. + f_print(fout, "#include <sysent.h> /* getdtablesize, open */\n");
  2090. + f_print(fout, "#endif /* __cplusplus */\n");
  2091. +
  2092. + if( tirpcflag )
  2093. + f_print(fout, "#include <unistd.h> /* setsid */\n");
  2094. + }
  2095. + if( tirpcflag )
  2096. + f_print(fout, "#include <sys/types.h>\n");
  2097. +
  2098. + f_print(fout, "#include <memory.h>\n");
  2099. +#ifndef linux
  2100. + f_print(fout, "#include <stropts.h>\n");
  2101. +#endif
  2102. + if (inetdflag || !tirpcflag ) {
  2103. + f_print(fout, "#include <sys/socket.h>\n");
  2104. + f_print(fout, "#include <netinet/in.h>\n");
  2105. + }
  2106. +
  2107. + if ( (netflag || pmflag) && tirpcflag ) {
  2108. + f_print(fout, "#include <netconfig.h>\n");
  2109. + }
  2110. + if (/*timerflag &&*/ tirpcflag)
  2111. + f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
  2112. + if (logflag || inetdflag || pmflag) {
  2113. +#ifdef linux
  2114. + f_print(fout, "#include <syslog.h>\n");
  2115. +#else
  2116. + f_print(fout, "#ifdef SYSLOG\n");
  2117. + f_print(fout, "#include <syslog.h>\n");
  2118. + f_print(fout, "#else\n");
  2119. + f_print(fout, "#define LOG_ERR 1\n");
  2120. + f_print(fout, "#define openlog(a, b, c)\n");
  2121. + f_print(fout, "#endif\n");
  2122. +#endif
  2123. + }
  2124. +
  2125. + /* for ANSI-C */
  2126. + f_print(fout, "\n#ifdef __STDC__\n#define SIG_PF void(*)(int)\n#endif\n");
  2127. +
  2128. + f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
  2129. + if (timerflag)
  2130. + f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime);
  2131. + while ((def = get_definition()) != NULL) {
  2132. + foundprogram |= (def->def_kind == DEF_PROGRAM);
  2133. + }
  2134. + if (extend && !foundprogram) {
  2135. + (void) unlink(outfilename);
  2136. + return;
  2137. + }
  2138. + write_most(infile, netflag, nomain);
  2139. + if (!nomain) {
  2140. + if( !do_registers(argc, argv) ) {
  2141. + if (outfilename)
  2142. + (void) unlink(outfilename);
  2143. + usage();
  2144. + }
  2145. + write_rest();
  2146. + }
  2147. +}
  2148. +
  2149. +/*
  2150. + * generate client side stubs
  2151. + */
  2152. +static void
  2153. +l_output(char *infile, char *define, int extend, char *outfile)
  2154. +{
  2155. + char *include;
  2156. + definition *def;
  2157. + int foundprogram = 0;
  2158. + char *outfilename;
  2159. +
  2160. + open_input(infile, define);
  2161. + outfilename = extend ? extendfile(infile, outfile) : outfile;
  2162. + open_output(infile, outfilename);
  2163. + add_warning();
  2164. + if (Cflag)
  2165. + f_print (fout, "#include <memory.h> /* for memset */\n");
  2166. + if (infile && (include = extendfile(infile, ".h"))) {
  2167. + f_print(fout, "#include \"%s\"\n", include);
  2168. + free(include);
  2169. + } else
  2170. + f_print(fout, "#include <rpc/rpc.h>\n");
  2171. + while ((def = get_definition()) != NULL) {
  2172. + foundprogram |= (def->def_kind == DEF_PROGRAM);
  2173. + }
  2174. + if (extend && !foundprogram) {
  2175. + (void) unlink(outfilename);
  2176. + return;
  2177. + }
  2178. + write_stubs();
  2179. +}
  2180. +
  2181. +/*
  2182. + * generate the dispatch table
  2183. + */
  2184. +static void
  2185. +t_output(char *infile, char *define, int extend, char *outfile)
  2186. +{
  2187. + definition *def;
  2188. + int foundprogram = 0;
  2189. + char *outfilename;
  2190. +
  2191. + open_input(infile, define);
  2192. + outfilename = extend ? extendfile(infile, outfile) : outfile;
  2193. + open_output(infile, outfilename);
  2194. + add_warning();
  2195. + while ((def = get_definition()) != NULL) {
  2196. + foundprogram |= (def->def_kind == DEF_PROGRAM);
  2197. + }
  2198. + if (extend && !foundprogram) {
  2199. + (void) unlink(outfilename);
  2200. + return;
  2201. + }
  2202. + write_tables();
  2203. +}
  2204. +
  2205. +/* sample routine for the server template */
  2206. +static void
  2207. +svc_output(char *infile, char *define, int extend, char *outfile)
  2208. +{
  2209. + definition *def;
  2210. + char *include;
  2211. + char *outfilename;
  2212. + long tell;
  2213. +
  2214. + open_input(infile, define);
  2215. + outfilename = extend ? extendfile(infile, outfile) : outfile;
  2216. + checkfiles(infile,outfilename); /*check if outfile already exists.
  2217. + if so, print an error message and exit*/
  2218. + open_output(infile, outfilename);
  2219. + add_sample_msg();
  2220. +
  2221. + if (infile && (include = extendfile(infile, ".h"))) {
  2222. + f_print(fout, "#include \"%s\"\n", include);
  2223. + free(include);
  2224. + } else
  2225. + f_print(fout, "#include <rpc/rpc.h>\n");
  2226. +
  2227. + tell = ftell(fout);
  2228. + while ((def = get_definition()) != NULL) {
  2229. + write_sample_svc(def);
  2230. + }
  2231. + if (extend && tell == ftell(fout)) {
  2232. + (void) unlink(outfilename);
  2233. + }
  2234. +}
  2235. +
  2236. +
  2237. +/* sample main routine for client */
  2238. +static void
  2239. +clnt_output(char *infile, char *define, int extend, char *outfile)
  2240. +{
  2241. + definition *def;
  2242. + char *include;
  2243. + char *outfilename;
  2244. + long tell;
  2245. + int has_program = 0;
  2246. +
  2247. + open_input(infile, define);
  2248. + outfilename = extend ? extendfile(infile, outfile) : outfile;
  2249. + checkfiles(infile, outfilename); /*check if outfile already exists.
  2250. + if so, print an error message and exit*/
  2251. +
  2252. + open_output(infile, outfilename);
  2253. + add_sample_msg();
  2254. + if (infile && (include = extendfile(infile, ".h"))) {
  2255. + f_print(fout, "#include \"%s\"\n", include);
  2256. + free(include);
  2257. + } else
  2258. + f_print(fout, "#include <rpc/rpc.h>\n");
  2259. + tell = ftell(fout);
  2260. + while ((def = get_definition()) != NULL) {
  2261. + has_program += write_sample_clnt(def);
  2262. + }
  2263. +
  2264. + if (has_program)
  2265. + write_sample_clnt_main();
  2266. +
  2267. + if (extend && tell == ftell(fout)) {
  2268. + (void) unlink(outfilename);
  2269. + }
  2270. +}
  2271. +
  2272. +/*
  2273. + * Perform registrations for service output
  2274. + * Return 0 if failed; 1 otherwise.
  2275. + */
  2276. +static int
  2277. +do_registers(int argc, char **argv)
  2278. +{
  2279. + int i;
  2280. +
  2281. + if (inetdflag || !tirpcflag) {
  2282. + for (i = 1; i < argc; i++) {
  2283. + if (streq(argv[i], "-s")) {
  2284. + if (!check_nettype(argv[i + 1], valid_i_nettypes))
  2285. + return 0;
  2286. + write_inetd_register(argv[i + 1]);
  2287. + i++;
  2288. + }
  2289. + }
  2290. + } else {
  2291. + for (i = 1; i < argc; i++)
  2292. + if (streq(argv[i], "-s")) {
  2293. + if (!check_nettype(argv[i + 1], valid_ti_nettypes))
  2294. + return 0;
  2295. + write_nettype_register(argv[i + 1]);
  2296. + i++;
  2297. + } else if (streq(argv[i], "-n")) {
  2298. + write_netid_register(argv[i + 1]);
  2299. + i++;
  2300. + }
  2301. + }
  2302. + return 1;
  2303. +}
  2304. +
  2305. +/*
  2306. + * Add another argument to the arg list
  2307. + */
  2308. +static void
  2309. +addarg(char *cp)
  2310. +{
  2311. + if (argcount >= ARGLISTLEN) {
  2312. + f_print(stderr, "rpcgen: too many defines\n");
  2313. + crash();
  2314. + /*NOTREACHED*/
  2315. + }
  2316. + arglist[argcount++] = cp;
  2317. +
  2318. +}
  2319. +
  2320. +static void
  2321. +putarg(int where, char *cp)
  2322. +{
  2323. + if (where >= ARGLISTLEN) {
  2324. + f_print(stderr, "rpcgen: arglist coding error\n");
  2325. + crash();
  2326. + /*NOTREACHED*/
  2327. + }
  2328. + arglist[where] = cp;
  2329. +
  2330. +}
  2331. +
  2332. +/*
  2333. + * if input file is stdin and an output file is specified then complain
  2334. + * if the file already exists. Otherwise the file may get overwritten
  2335. + * If input file does not exist, exit with an error
  2336. + */
  2337. +
  2338. +static void
  2339. +checkfiles(char *infile, char *outfile)
  2340. +{
  2341. +
  2342. + struct stat buf;
  2343. +
  2344. + if(infile) /* infile ! = NULL */
  2345. + if(stat(infile,&buf) < 0)
  2346. + {
  2347. + perror(infile);
  2348. + crash();
  2349. + };
  2350. + if (outfile) {
  2351. + if (stat(outfile, &buf) < 0)
  2352. + return; /* file does not exist */
  2353. + else {
  2354. + f_print(stderr,
  2355. + "file '%s' already exists and may be overwritten\n", outfile);
  2356. + crash();
  2357. + }
  2358. + }
  2359. +}
  2360. +
  2361. +/*
  2362. + * Parse command line arguments
  2363. + */
  2364. +static int
  2365. +parseargs(int argc, char **argv, struct commandline *cmd)
  2366. +{
  2367. + int i;
  2368. + int j;
  2369. + char c;
  2370. + char flag[(1 << 8 * sizeof(char))];
  2371. + int nflags;
  2372. +
  2373. + cmdname = argv[0];
  2374. + cmd->infile = cmd->outfile = NULL;
  2375. + if (argc < 2) {
  2376. + return (0);
  2377. + }
  2378. + allfiles = 0;
  2379. + flag['c'] = 0;
  2380. + flag['h'] = 0;
  2381. + flag['l'] = 0;
  2382. + flag['m'] = 0;
  2383. + flag['o'] = 0;
  2384. + flag['s'] = 0;
  2385. + flag['n'] = 0;
  2386. + flag['t'] = 0;
  2387. + flag['S'] = 0;
  2388. + flag['C'] = 0;
  2389. + for (i = 1; i < argc; i++) {
  2390. + if (argv[i][0] != '-') {
  2391. + if (cmd->infile) {
  2392. + f_print( stderr, "Cannot specify more than one input file!\n");
  2393. +
  2394. + return (0);
  2395. + }
  2396. + cmd->infile = argv[i];
  2397. + } else {
  2398. + for (j = 1; argv[i][j] != 0; j++) {
  2399. + c = argv[i][j];
  2400. + switch (c) {
  2401. + case 'a':
  2402. + allfiles = 1;
  2403. + break;
  2404. + case 'c':
  2405. + case 'h':
  2406. + case 'l':
  2407. + case 'm':
  2408. + case 't':
  2409. + if (flag[(int) c]) {
  2410. + return (0);
  2411. + }
  2412. + flag[(int) c] = 1;
  2413. + break;
  2414. + case 'S':
  2415. + /* sample flag: Ss or Sc.
  2416. + Ss means set flag['S'];
  2417. + Sc means set flag['C']; */
  2418. + c = argv[i][++j]; /* get next char */
  2419. + if( c == 's' )
  2420. + c = 'S';
  2421. + else if( c == 'c' )
  2422. + c = 'C';
  2423. + else
  2424. + return( 0 );
  2425. +
  2426. + if (flag[(int) c]) {
  2427. + return (0);
  2428. + }
  2429. + flag[(int) c] = 1;
  2430. + break;
  2431. + case 'C': /* ANSI C syntax */
  2432. + Cflag = 1;
  2433. + break;
  2434. +
  2435. + case 'b': /* turn TIRPC flag off for
  2436. + generating backward compatible
  2437. + */
  2438. + tirpcflag = 0;
  2439. + break;
  2440. +
  2441. + case 'I':
  2442. + inetdflag = 1;
  2443. + break;
  2444. + case 'N':
  2445. + newstyle = 1;
  2446. + break;
  2447. + case 'L':
  2448. + logflag = 1;
  2449. + break;
  2450. + case 'K':
  2451. + if (++i == argc) {
  2452. + return (0);
  2453. + }
  2454. + svcclosetime = argv[i];
  2455. + goto nextarg;
  2456. + case 'T':
  2457. + tblflag = 1;
  2458. + break;
  2459. + case 'i' :
  2460. + if (++i == argc) {
  2461. + return (0);
  2462. + }
  2463. + Inline = atoi(argv[i]);
  2464. + goto nextarg;
  2465. + case 'n':
  2466. + case 'o':
  2467. + case 's':
  2468. + if (argv[i][j - 1] != '-' ||
  2469. + argv[i][j + 1] != 0) {
  2470. + return (0);
  2471. + }
  2472. + flag[(int) c] = 1;
  2473. + if (++i == argc) {
  2474. + return (0);
  2475. + }
  2476. + if (c == 's') {
  2477. + if (!streq(argv[i], "udp") &&
  2478. + !streq(argv[i], "tcp")) {
  2479. + return (0);
  2480. + }
  2481. + } else if (c == 'o') {
  2482. + if (cmd->outfile) {
  2483. + return (0);
  2484. + }
  2485. + cmd->outfile = argv[i];
  2486. + }
  2487. + goto nextarg;
  2488. + case 'D':
  2489. + if (argv[i][j - 1] != '-') {
  2490. + return (0);
  2491. + }
  2492. + (void) addarg(argv[i]);
  2493. + goto nextarg;
  2494. + case 'Y':
  2495. + if (++i == argc) {
  2496. + return (0);
  2497. + }
  2498. + (void) strcpy(pathbuf, argv[i]);
  2499. + (void) strcat(pathbuf, "/cpp");
  2500. + CPP = pathbuf;
  2501. + cppDefined = 1;
  2502. + goto nextarg;
  2503. +
  2504. +
  2505. +
  2506. + default:
  2507. + return (0);
  2508. + }
  2509. + }
  2510. + nextarg:
  2511. + ;
  2512. + }
  2513. + }
  2514. +
  2515. + cmd->cflag = flag['c'];
  2516. + cmd->hflag = flag['h'];
  2517. + cmd->lflag = flag['l'];
  2518. + cmd->mflag = flag['m'];
  2519. + cmd->nflag = flag['n'];
  2520. + cmd->sflag = flag['s'];
  2521. + cmd->tflag = flag['t'];
  2522. + cmd->Ssflag = flag['S'];
  2523. + cmd->Scflag = flag['C'];
  2524. +
  2525. + if( tirpcflag ) {
  2526. + pmflag = inetdflag ? 0 : 1; /* pmflag or inetdflag is always TRUE */
  2527. + if( (inetdflag && cmd->nflag)) { /* netid not allowed with inetdflag */
  2528. + f_print(stderr, "Cannot use netid flag with inetd flag!\n");
  2529. + return (0);
  2530. + }
  2531. + } else { /* 4.1 mode */
  2532. + pmflag = 0; /* set pmflag only in tirpcmode */
  2533. + inetdflag = 1; /* inetdflag is TRUE by default */
  2534. + if( cmd->nflag ) { /* netid needs TIRPC */
  2535. + f_print( stderr, "Cannot use netid flag without TIRPC!\n");
  2536. + return( 0 );
  2537. + }
  2538. + }
  2539. +
  2540. + if( newstyle && ( tblflag || cmd->tflag) ) {
  2541. + f_print( stderr, "Cannot use table flags with newstyle!\n");
  2542. + return( 0 );
  2543. + }
  2544. +
  2545. + /* check no conflicts with file generation flags */
  2546. + nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
  2547. + cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + cmd->Scflag;
  2548. +
  2549. + if (nflags == 0) {
  2550. + if (cmd->outfile != NULL || cmd->infile == NULL) {
  2551. + return (0);
  2552. + }
  2553. + } else if (nflags > 1) {
  2554. + f_print( stderr, "Cannot have more than one file generation flag!\n");
  2555. + return (0);
  2556. + }
  2557. + return (1);
  2558. +}
  2559. +
  2560. +static void
  2561. +usage(void)
  2562. +{
  2563. + f_print(stderr, "usage: %s infile\n", cmdname);
  2564. + f_print(stderr, "\t%s [-a][-b][-C][-Dname[=value]] -i size [-I [-K seconds]] [-L][-N][-T] infile\n",
  2565. + cmdname);
  2566. + f_print(stderr, "\t%s [-c | -h | -l | -m | -t | -Sc | -Ss] [-o outfile] [infile]\n",
  2567. + cmdname);
  2568. + f_print(stderr, "\t%s [-s nettype]* [-o outfile] [infile]\n", cmdname);
  2569. + f_print(stderr, "\t%s [-n netid]* [-o outfile] [infile]\n", cmdname);
  2570. + options_usage();
  2571. + exit(1);
  2572. +}
  2573. +
  2574. +static void
  2575. +options_usage(void)
  2576. +{
  2577. + f_print(stderr, "options:\n");
  2578. + f_print(stderr, "-a\t\tgenerate all files, including samples\n");
  2579. + f_print(stderr, "-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n");
  2580. + f_print(stderr, "-c\t\tgenerate XDR routines\n");
  2581. + f_print(stderr, "-C\t\tANSI C mode\n");
  2582. + f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
  2583. + f_print(stderr, "-h\t\tgenerate header file\n");
  2584. + f_print(stderr, "-i size\t\tsize at which to start generating inline code\n");
  2585. + f_print(stderr, "-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n");
  2586. + f_print(stderr, "-K seconds\tserver exits after K seconds of inactivity\n");
  2587. + f_print(stderr, "-l\t\tgenerate client side stubs\n");
  2588. + f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
  2589. + f_print(stderr, "-m\t\tgenerate server side stubs\n");
  2590. + f_print(stderr, "-n netid\tgenerate server code that supports named netid\n");
  2591. + f_print(stderr, "-N\t\tsupports multiple arguments and call-by-value\n");
  2592. + f_print(stderr, "-o outfile\tname of the output file\n");
  2593. + f_print(stderr, "-s nettype\tgenerate server code that supports named nettype\n");
  2594. + f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote procedures\n");
  2595. + f_print(stderr, "-Ss\t\tgenerate sample server code that defines remote procedures\n");
  2596. + f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
  2597. + f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
  2598. + f_print(stderr, "-Y path\t\tdirectory name to find C preprocessor (cpp)\n");
  2599. +
  2600. + exit(1);
  2601. +}
  2602. diff --git a/rpcgen/rpc_output.h b/rpcgen/rpc_output.h
  2603. new file mode 100644
  2604. index 0000000..eb25a60
  2605. --- /dev/null
  2606. +++ b/rpcgen/rpc_output.h
  2607. @@ -0,0 +1,16 @@
  2608. +/*
  2609. + * rpc_output.h
  2610. + *
  2611. + * Declarations for output functions
  2612. + *
  2613. + */
  2614. +
  2615. +#ifndef RPCGEN_NEW_OUTPUT_H
  2616. +#define RPCGEN_NEW_OUTPUT_H
  2617. +
  2618. +void write_msg_out(void);
  2619. +int nullproc(proc_list *);
  2620. +void printarglist(proc_list *, char *, char *);
  2621. +void pdeclaration(char *, declaration *, int, char *);
  2622. +
  2623. +#endif /* RPCGEN_NEW_OUTPUT_H */
  2624. diff --git a/rpcgen/rpc_parse.c b/rpcgen/rpc_parse.c
  2625. new file mode 100644
  2626. index 0000000..b53a553
  2627. --- /dev/null
  2628. +++ b/rpcgen/rpc_parse.c
  2629. @@ -0,0 +1,609 @@
  2630. +/*
  2631. + * Copyright (c) 2009, Sun Microsystems, Inc.
  2632. + * All rights reserved.
  2633. + *
  2634. + * Redistribution and use in source and binary forms, with or without
  2635. + * modification, are permitted provided that the following conditions are met:
  2636. + * - Redistributions of source code must retain the above copyright notice,
  2637. + * this list of conditions and the following disclaimer.
  2638. + * - Redistributions in binary form must reproduce the above copyright notice,
  2639. + * this list of conditions and the following disclaimer in the documentation
  2640. + * and/or other materials provided with the distribution.
  2641. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  2642. + * contributors may be used to endorse or promote products derived
  2643. + * from this software without specific prior written permission.
  2644. + *
  2645. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  2646. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  2647. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  2648. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  2649. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  2650. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  2651. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  2652. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  2653. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  2654. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  2655. + * POSSIBILITY OF SUCH DAMAGE.
  2656. + */
  2657. +
  2658. +#if 0
  2659. +static char sccsid[] = "@(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI";
  2660. +#endif
  2661. +
  2662. +/*
  2663. + * rpc_parse.c, Parser for the RPC protocol compiler
  2664. + * Copyright (C) 1987 Sun Microsystems, Inc.
  2665. + */
  2666. +#include <stdio.h>
  2667. +#include <string.h>
  2668. +#include "rpc/types.h"
  2669. +#include "rpc_scan.h"
  2670. +#include "rpc_parse.h"
  2671. +#include "rpc_util.h"
  2672. +
  2673. +#define ARGNAME "arg"
  2674. +
  2675. +/*
  2676. +extern char *make_argname();
  2677. +extern char *strdup();
  2678. + */
  2679. +
  2680. +static void isdefined(definition *defp);
  2681. +static void def_struct(definition *defp);
  2682. +static void def_program(definition *defp);
  2683. +static void def_enum(definition *defp);
  2684. +static void def_const(definition *defp);
  2685. +static void def_union(definition *defp);
  2686. +static void check_type_name(char *name, int new_type);
  2687. +static void def_typedef(definition *defp);
  2688. +static void get_declaration(declaration *dec, defkind dkind);
  2689. +static void get_prog_declaration(declaration *dec, defkind dkind, int num);
  2690. +static void get_type(char **prefixp, char **typep, defkind dkind);
  2691. +static void unsigned_dec(char **typep);
  2692. +
  2693. +/*
  2694. + * return the next definition you see
  2695. + */
  2696. +definition *
  2697. +get_definition(void)
  2698. +{
  2699. + definition *defp;
  2700. + token tok;
  2701. +
  2702. + defp = ALLOC(definition);
  2703. + get_token(&tok);
  2704. + switch (tok.kind) {
  2705. + case TOK_STRUCT:
  2706. + def_struct(defp);
  2707. + break;
  2708. + case TOK_UNION:
  2709. + def_union(defp);
  2710. + break;
  2711. + case TOK_TYPEDEF:
  2712. + def_typedef(defp);
  2713. + break;
  2714. + case TOK_ENUM:
  2715. + def_enum(defp);
  2716. + break;
  2717. + case TOK_PROGRAM:
  2718. + def_program(defp);
  2719. + break;
  2720. + case TOK_CONST:
  2721. + def_const(defp);
  2722. + break;
  2723. + case TOK_EOF:
  2724. + free(defp);
  2725. + return (NULL);
  2726. + default:
  2727. + error("definition keyword expected");
  2728. + }
  2729. + scan(TOK_SEMICOLON, &tok);
  2730. + isdefined(defp);
  2731. + return (defp);
  2732. +}
  2733. +
  2734. +static void
  2735. +isdefined(definition *defp)
  2736. +{
  2737. + STOREVAL(&defined, defp);
  2738. +}
  2739. +
  2740. +static void
  2741. +def_struct(definition *defp)
  2742. +{
  2743. + token tok;
  2744. + declaration dec;
  2745. + decl_list *decls;
  2746. + decl_list **tailp;
  2747. +
  2748. + defp->def_kind = DEF_STRUCT;
  2749. +
  2750. + scan(TOK_IDENT, &tok);
  2751. + defp->def_name = tok.str;
  2752. + scan(TOK_LBRACE, &tok);
  2753. + tailp = &defp->def.st.decls;
  2754. + do {
  2755. + get_declaration(&dec, DEF_STRUCT);
  2756. + decls = ALLOC(decl_list);
  2757. + decls->decl = dec;
  2758. + *tailp = decls;
  2759. + tailp = &decls->next;
  2760. + scan(TOK_SEMICOLON, &tok);
  2761. + peek(&tok);
  2762. + } while (tok.kind != TOK_RBRACE);
  2763. + get_token(&tok);
  2764. + *tailp = NULL;
  2765. +}
  2766. +
  2767. +static void
  2768. +def_program(definition *defp)
  2769. +{
  2770. + token tok;
  2771. + declaration dec;
  2772. + decl_list *decls;
  2773. + decl_list **tailp;
  2774. + version_list *vlist;
  2775. + version_list **vtailp;
  2776. + proc_list *plist;
  2777. + proc_list **ptailp;
  2778. + int num_args;
  2779. + bool_t isvoid = FALSE; /* whether first argument is void */
  2780. + defp->def_kind = DEF_PROGRAM;
  2781. + scan(TOK_IDENT, &tok);
  2782. + defp->def_name = tok.str;
  2783. + scan(TOK_LBRACE, &tok);
  2784. + vtailp = &defp->def.pr.versions;
  2785. + tailp = &defp->def.st.decls;
  2786. + scan(TOK_VERSION, &tok);
  2787. + do {
  2788. + scan(TOK_IDENT, &tok);
  2789. + vlist = ALLOC(version_list);
  2790. + vlist->vers_name = tok.str;
  2791. + scan(TOK_LBRACE, &tok);
  2792. + ptailp = &vlist->procs;
  2793. + do {
  2794. + /* get result type */
  2795. + plist = ALLOC(proc_list);
  2796. + get_type(&plist->res_prefix, &plist->res_type,
  2797. + DEF_PROGRAM);
  2798. + if (streq(plist->res_type, "opaque")) {
  2799. + error("illegal result type");
  2800. + }
  2801. + scan(TOK_IDENT, &tok);
  2802. + plist->proc_name = tok.str;
  2803. + scan(TOK_LPAREN, &tok);
  2804. + /* get args - first one*/
  2805. + num_args = 1;
  2806. + isvoid = FALSE;
  2807. + /* type of DEF_PROGRAM in the first
  2808. + * get_prog_declaration and DEF_STURCT in the next
  2809. + * allows void as argument if it is the only argument
  2810. + */
  2811. + get_prog_declaration(&dec, DEF_PROGRAM, num_args);
  2812. + if (streq(dec.type, "void"))
  2813. + isvoid = TRUE;
  2814. + decls = ALLOC(decl_list);
  2815. + plist->args.decls = decls;
  2816. + decls->decl = dec;
  2817. + tailp = &decls->next;
  2818. + /* get args */
  2819. + while(peekscan(TOK_COMMA, &tok)) {
  2820. + num_args++;
  2821. + get_prog_declaration(&dec, DEF_STRUCT,
  2822. + num_args);
  2823. + decls = ALLOC(decl_list);
  2824. + decls->decl = dec;
  2825. + *tailp = decls;
  2826. + if (streq(dec.type, "void"))
  2827. + isvoid = TRUE;
  2828. + tailp = &decls->next;
  2829. + }
  2830. + /* multiple arguments are only allowed in newstyle */
  2831. + if( !newstyle && num_args > 1 ) {
  2832. + error("only one argument is allowed" );
  2833. + }
  2834. + if (isvoid && num_args > 1) {
  2835. + error("illegal use of void in program definition");
  2836. + }
  2837. + *tailp = NULL;
  2838. + scan(TOK_RPAREN, &tok);
  2839. + scan(TOK_EQUAL, &tok);
  2840. + scan_num(&tok);
  2841. + scan(TOK_SEMICOLON, &tok);
  2842. + plist->proc_num = tok.str;
  2843. + plist->arg_num = num_args;
  2844. + *ptailp = plist;
  2845. + ptailp = &plist->next;
  2846. + peek(&tok);
  2847. + } while (tok.kind != TOK_RBRACE);
  2848. + *ptailp = NULL;
  2849. + *vtailp = vlist;
  2850. + vtailp = &vlist->next;
  2851. + scan(TOK_RBRACE, &tok);
  2852. + scan(TOK_EQUAL, &tok);
  2853. + scan_num(&tok);
  2854. + vlist->vers_num = tok.str;
  2855. + /* make the argument structure name for each arg*/
  2856. + for(plist = vlist->procs; plist != NULL;
  2857. + plist = plist->next) {
  2858. + plist->args.argname = make_argname(plist->proc_name,
  2859. + vlist->vers_num);
  2860. + /* free the memory ??*/
  2861. + }
  2862. + scan(TOK_SEMICOLON, &tok);
  2863. + scan2(TOK_VERSION, TOK_RBRACE, &tok);
  2864. + } while (tok.kind == TOK_VERSION);
  2865. + scan(TOK_EQUAL, &tok);
  2866. + scan_num(&tok);
  2867. + defp->def.pr.prog_num = tok.str;
  2868. + *vtailp = NULL;
  2869. +}
  2870. +
  2871. +
  2872. +static void
  2873. +def_enum(definition *defp)
  2874. +{
  2875. + token tok;
  2876. + enumval_list *elist;
  2877. + enumval_list **tailp;
  2878. +
  2879. + defp->def_kind = DEF_ENUM;
  2880. + scan(TOK_IDENT, &tok);
  2881. + defp->def_name = tok.str;
  2882. + scan(TOK_LBRACE, &tok);
  2883. + tailp = &defp->def.en.vals;
  2884. + do {
  2885. + scan(TOK_IDENT, &tok);
  2886. + elist = ALLOC(enumval_list);
  2887. + elist->name = tok.str;
  2888. + elist->assignment = NULL;
  2889. + scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
  2890. + if (tok.kind == TOK_EQUAL) {
  2891. + scan_num(&tok);
  2892. + elist->assignment = tok.str;
  2893. + scan2(TOK_COMMA, TOK_RBRACE, &tok);
  2894. + }
  2895. + *tailp = elist;
  2896. + tailp = &elist->next;
  2897. + } while (tok.kind != TOK_RBRACE);
  2898. + *tailp = NULL;
  2899. +}
  2900. +
  2901. +static void
  2902. +def_const(definition *defp)
  2903. +{
  2904. + token tok;
  2905. +
  2906. + defp->def_kind = DEF_CONST;
  2907. + scan(TOK_IDENT, &tok);
  2908. + defp->def_name = tok.str;
  2909. + scan(TOK_EQUAL, &tok);
  2910. + scan2(TOK_IDENT, TOK_STRCONST, &tok);
  2911. + defp->def.co = tok.str;
  2912. +}
  2913. +
  2914. +static void
  2915. +def_union(definition *defp)
  2916. +{
  2917. + token tok;
  2918. + declaration dec;
  2919. + case_list *cases;
  2920. + case_list **tailp;
  2921. +
  2922. + defp->def_kind = DEF_UNION;
  2923. + scan(TOK_IDENT, &tok);
  2924. + defp->def_name = tok.str;
  2925. + scan(TOK_SWITCH, &tok);
  2926. + scan(TOK_LPAREN, &tok);
  2927. + get_declaration(&dec, DEF_UNION);
  2928. + defp->def.un.enum_decl = dec;
  2929. + tailp = &defp->def.un.cases;
  2930. + scan(TOK_RPAREN, &tok);
  2931. + scan(TOK_LBRACE, &tok);
  2932. + scan(TOK_CASE, &tok);
  2933. + while (tok.kind == TOK_CASE) {
  2934. + scan2(TOK_IDENT, TOK_CHARCONST, &tok);
  2935. + cases = ALLOC(case_list);
  2936. + cases->case_name = tok.str;
  2937. + scan(TOK_COLON, &tok);
  2938. + /* now peek at next token */
  2939. + if(peekscan(TOK_CASE,&tok))
  2940. + {
  2941. +
  2942. + do
  2943. + {
  2944. + scan2(TOK_IDENT, TOK_CHARCONST, &tok);
  2945. + cases->contflag=1; /* continued case statement */
  2946. + *tailp = cases;
  2947. + tailp = &cases->next;
  2948. + cases = ALLOC(case_list);
  2949. + cases->case_name = tok.str;
  2950. + scan(TOK_COLON, &tok);
  2951. +
  2952. + }while(peekscan(TOK_CASE,&tok));
  2953. + }
  2954. +
  2955. + get_declaration(&dec, DEF_UNION);
  2956. + cases->case_decl = dec;
  2957. + cases->contflag=0; /* no continued case statement */
  2958. + *tailp = cases;
  2959. + tailp = &cases->next;
  2960. + scan(TOK_SEMICOLON, &tok);
  2961. +
  2962. + scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
  2963. + }
  2964. + *tailp = NULL;
  2965. + if (tok.kind == TOK_DEFAULT) {
  2966. + scan(TOK_COLON, &tok);
  2967. + get_declaration(&dec, DEF_UNION);
  2968. + defp->def.un.default_decl = ALLOC(declaration);
  2969. + *defp->def.un.default_decl = dec;
  2970. + scan(TOK_SEMICOLON, &tok);
  2971. + scan(TOK_RBRACE, &tok);
  2972. + } else {
  2973. + defp->def.un.default_decl = NULL;
  2974. + }
  2975. +}
  2976. +
  2977. +static char* reserved_words[] =
  2978. +{
  2979. + "array",
  2980. + "bytes",
  2981. + "destroy",
  2982. + "free",
  2983. + "getpos",
  2984. + "inline",
  2985. + "pointer",
  2986. + "reference",
  2987. + "setpos",
  2988. + "sizeof",
  2989. + "union",
  2990. + "vector",
  2991. + NULL
  2992. + };
  2993. +
  2994. +static char* reserved_types[] =
  2995. +{
  2996. + "opaque",
  2997. + "string",
  2998. + NULL
  2999. + };
  3000. +
  3001. +/* check that the given name is not one that would eventually result in
  3002. + xdr routines that would conflict with internal XDR routines. */
  3003. +static void
  3004. +check_type_name(char *name, int new_type)
  3005. +{
  3006. + int i;
  3007. + char tmp[100];
  3008. +
  3009. + for( i = 0; reserved_words[i] != NULL; i++ ) {
  3010. + if( strcmp( name, reserved_words[i] ) == 0 ) {
  3011. + sprintf(tmp,
  3012. + "illegal (reserved) name :\'%s\' in type definition", name );
  3013. + error(tmp);
  3014. + }
  3015. + }
  3016. + if( new_type ) {
  3017. + for( i = 0; reserved_types[i] != NULL; i++ ) {
  3018. + if( strcmp( name, reserved_types[i] ) == 0 ) {
  3019. + sprintf(tmp,
  3020. + "illegal (reserved) name :\'%s\' in type definition", name );
  3021. + error(tmp);
  3022. + }
  3023. + }
  3024. + }
  3025. +}
  3026. +
  3027. +static void
  3028. +def_typedef(definition *defp)
  3029. +{
  3030. + declaration dec;
  3031. +
  3032. + defp->def_kind = DEF_TYPEDEF;
  3033. + get_declaration(&dec, DEF_TYPEDEF);
  3034. + defp->def_name = dec.name;
  3035. + check_type_name( dec.name, 1 );
  3036. + defp->def.ty.old_prefix = dec.prefix;
  3037. + defp->def.ty.old_type = dec.type;
  3038. + defp->def.ty.rel = dec.rel;
  3039. + defp->def.ty.array_max = dec.array_max;
  3040. +}
  3041. +
  3042. +static void
  3043. +get_declaration(declaration *dec, defkind dkind)
  3044. +{
  3045. + token tok;
  3046. +
  3047. + get_type(&dec->prefix, &dec->type, dkind);
  3048. + dec->rel = REL_ALIAS;
  3049. + if (streq(dec->type, "void")) {
  3050. + return;
  3051. + }
  3052. +
  3053. + check_type_name( dec->type, 0 );
  3054. +
  3055. + scan2(TOK_STAR, TOK_IDENT, &tok);
  3056. + if (tok.kind == TOK_STAR) {
  3057. + dec->rel = REL_POINTER;
  3058. + scan(TOK_IDENT, &tok);
  3059. + }
  3060. + dec->name = tok.str;
  3061. + if (peekscan(TOK_LBRACKET, &tok)) {
  3062. + if (dec->rel == REL_POINTER) {
  3063. + error("no array-of-pointer declarations -- use typedef");
  3064. + }
  3065. + dec->rel = REL_VECTOR;
  3066. + scan_num(&tok);
  3067. + dec->array_max = tok.str;
  3068. + scan(TOK_RBRACKET, &tok);
  3069. + } else if (peekscan(TOK_LANGLE, &tok)) {
  3070. + if (dec->rel == REL_POINTER) {
  3071. + error("no array-of-pointer declarations -- use typedef");
  3072. + }
  3073. + dec->rel = REL_ARRAY;
  3074. + if (peekscan(TOK_RANGLE, &tok)) {
  3075. + dec->array_max = "~0"; /* unspecified size, use max */
  3076. + } else {
  3077. + scan_num(&tok);
  3078. + dec->array_max = tok.str;
  3079. + scan(TOK_RANGLE, &tok);
  3080. + }
  3081. + }
  3082. + if (streq(dec->type, "opaque")) {
  3083. + if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
  3084. + error("array declaration expected");
  3085. + }
  3086. + } else if (streq(dec->type, "string")) {
  3087. + if (dec->rel != REL_ARRAY) {
  3088. + error("variable-length array declaration expected");
  3089. + }
  3090. + }
  3091. +}
  3092. +
  3093. +
  3094. +static void
  3095. +get_prog_declaration(declaration *dec, defkind dkind, int num)
  3096. +{
  3097. + token tok;
  3098. + char name[10]; /* argument name */
  3099. +
  3100. + if (dkind == DEF_PROGRAM) {
  3101. + peek(&tok);
  3102. + if (tok.kind == TOK_RPAREN) { /* no arguments */
  3103. + dec->rel = REL_ALIAS;
  3104. + dec->type = "void";
  3105. + dec->prefix = NULL;
  3106. + dec->name = NULL;
  3107. + return;
  3108. + }
  3109. + }
  3110. + get_type(&dec->prefix, &dec->type, dkind);
  3111. + dec->rel = REL_ALIAS;
  3112. + if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */
  3113. + strcpy(name, tok.str);
  3114. + else
  3115. + sprintf(name, "%s%d", ARGNAME, num); /* default name of argument */
  3116. +
  3117. + dec->name = (char *) strdup(name);
  3118. +
  3119. + if (streq(dec->type, "void")) {
  3120. + return;
  3121. + }
  3122. +
  3123. + if (streq(dec->type, "opaque")) {
  3124. + error("opaque -- illegal argument type");
  3125. + }
  3126. + if (peekscan(TOK_STAR, &tok)) {
  3127. + if (streq(dec->type, "string")) {
  3128. + error("pointer to string not allowed in program arguments\n");
  3129. + }
  3130. + dec->rel = REL_POINTER;
  3131. + if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */
  3132. + dec->name = strdup(tok.str);
  3133. + }
  3134. + if (peekscan(TOK_LANGLE, &tok)) {
  3135. + if (!streq(dec->type, "string")) {
  3136. + error("arrays cannot be declared as arguments to procedures -- use typedef");
  3137. + }
  3138. + dec->rel = REL_ARRAY;
  3139. + if (peekscan(TOK_RANGLE, &tok)) {
  3140. + dec->array_max = "~0";/* unspecified size, use max */
  3141. + } else {
  3142. + scan_num(&tok);
  3143. + dec->array_max = tok.str;
  3144. + scan(TOK_RANGLE, &tok);
  3145. + }
  3146. + }
  3147. + if (streq(dec->type, "string")) {
  3148. + if (dec->rel != REL_ARRAY) { /* .x specifies just string as
  3149. + * type of argument
  3150. + * - make it string<>
  3151. + */
  3152. + dec->rel = REL_ARRAY;
  3153. + dec->array_max = "~0";/* unspecified size, use max */
  3154. + }
  3155. + }
  3156. +}
  3157. +
  3158. +
  3159. +
  3160. +static void
  3161. +get_type(char **prefixp, char **typep, defkind dkind)
  3162. +{
  3163. + token tok;
  3164. +
  3165. + *prefixp = NULL;
  3166. + get_token(&tok);
  3167. + switch (tok.kind) {
  3168. + case TOK_IDENT:
  3169. + *typep = tok.str;
  3170. + break;
  3171. + case TOK_STRUCT:
  3172. + case TOK_ENUM:
  3173. + case TOK_UNION:
  3174. + *prefixp = tok.str;
  3175. + scan(TOK_IDENT, &tok);
  3176. + *typep = tok.str;
  3177. + break;
  3178. + case TOK_UNSIGNED:
  3179. + unsigned_dec(typep);
  3180. + break;
  3181. + case TOK_SHORT:
  3182. + *typep = "short";
  3183. + (void) peekscan(TOK_INT, &tok);
  3184. + break;
  3185. + case TOK_INT32:
  3186. + *typep = "int32_t";
  3187. + (void) peekscan(TOK_INT, &tok);
  3188. + break;
  3189. + case TOK_VOID:
  3190. + if (dkind != DEF_UNION && dkind != DEF_PROGRAM) {
  3191. + error("voids allowed only inside union and program definitions with one argument");
  3192. + }
  3193. + *typep = tok.str;
  3194. + break;
  3195. + case TOK_STRING:
  3196. + case TOK_OPAQUE:
  3197. + case TOK_CHAR:
  3198. + case TOK_INT:
  3199. + case TOK_FLOAT:
  3200. + case TOK_DOUBLE:
  3201. + case TOK_BOOL:
  3202. + *typep = tok.str;
  3203. + break;
  3204. + default:
  3205. + error("expected type specifier");
  3206. + }
  3207. +}
  3208. +
  3209. +static void
  3210. +unsigned_dec(char **typep)
  3211. +{
  3212. + token tok;
  3213. +
  3214. + peek(&tok);
  3215. + switch (tok.kind) {
  3216. + case TOK_CHAR:
  3217. + get_token(&tok);
  3218. + *typep = "u_char";
  3219. + break;
  3220. + case TOK_SHORT:
  3221. + get_token(&tok);
  3222. + *typep = "u_short";
  3223. + (void) peekscan(TOK_INT, &tok);
  3224. + break;
  3225. + case TOK_INT32:
  3226. + get_token(&tok);
  3227. + *typep = "u_int32_";
  3228. + (void) peekscan(TOK_INT, &tok);
  3229. + break;
  3230. + case TOK_INT:
  3231. + get_token(&tok);
  3232. + *typep = "u_int";
  3233. + break;
  3234. + default:
  3235. + *typep = "u_int";
  3236. + break;
  3237. + }
  3238. +}
  3239. diff --git a/rpcgen/rpc_parse.h b/rpcgen/rpc_parse.h
  3240. new file mode 100644
  3241. index 0000000..2afae10
  3242. --- /dev/null
  3243. +++ b/rpcgen/rpc_parse.h
  3244. @@ -0,0 +1,166 @@
  3245. +/*
  3246. + * Copyright (c) 2009, Sun Microsystems, Inc.
  3247. + * All rights reserved.
  3248. + *
  3249. + * Redistribution and use in source and binary forms, with or without
  3250. + * modification, are permitted provided that the following conditions are met:
  3251. + * - Redistributions of source code must retain the above copyright notice,
  3252. + * this list of conditions and the following disclaimer.
  3253. + * - Redistributions in binary form must reproduce the above copyright notice,
  3254. + * this list of conditions and the following disclaimer in the documentation
  3255. + * and/or other materials provided with the distribution.
  3256. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  3257. + * contributors may be used to endorse or promote products derived
  3258. + * from this software without specific prior written permission.
  3259. + *
  3260. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3261. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3262. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3263. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  3264. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  3265. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  3266. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  3267. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  3268. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  3269. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  3270. + * POSSIBILITY OF SUCH DAMAGE.
  3271. + */
  3272. +
  3273. +/* @(#)rpc_parse.h 1.3 90/08/29 (C) 1987 SMI */
  3274. +
  3275. +/*
  3276. + * rpc_parse.h, Definitions for the RPCL parser
  3277. + */
  3278. +
  3279. +enum defkind {
  3280. + DEF_CONST,
  3281. + DEF_STRUCT,
  3282. + DEF_UNION,
  3283. + DEF_ENUM,
  3284. + DEF_TYPEDEF,
  3285. + DEF_PROGRAM
  3286. +};
  3287. +typedef enum defkind defkind;
  3288. +
  3289. +typedef char *const_def;
  3290. +
  3291. +enum relation {
  3292. + REL_VECTOR, /* fixed length array */
  3293. + REL_ARRAY, /* variable length array */
  3294. + REL_POINTER, /* pointer */
  3295. + REL_ALIAS, /* simple */
  3296. +};
  3297. +typedef enum relation relation;
  3298. +
  3299. +struct typedef_def {
  3300. + char *old_prefix;
  3301. + char *old_type;
  3302. + relation rel;
  3303. + char *array_max;
  3304. +};
  3305. +typedef struct typedef_def typedef_def;
  3306. +
  3307. +struct enumval_list {
  3308. + char *name;
  3309. + char *assignment;
  3310. + struct enumval_list *next;
  3311. +};
  3312. +typedef struct enumval_list enumval_list;
  3313. +
  3314. +struct enum_def {
  3315. + enumval_list *vals;
  3316. +};
  3317. +typedef struct enum_def enum_def;
  3318. +
  3319. +struct declaration {
  3320. + char *prefix;
  3321. + char *type;
  3322. + char *name;
  3323. + relation rel;
  3324. + char *array_max;
  3325. +};
  3326. +typedef struct declaration declaration;
  3327. +
  3328. +struct decl_list {
  3329. + declaration decl;
  3330. + struct decl_list *next;
  3331. +};
  3332. +typedef struct decl_list decl_list;
  3333. +
  3334. +struct struct_def {
  3335. + decl_list *decls;
  3336. +};
  3337. +typedef struct struct_def struct_def;
  3338. +
  3339. +struct case_list {
  3340. + char *case_name;
  3341. + int contflag;
  3342. + declaration case_decl;
  3343. + struct case_list *next;
  3344. +};
  3345. +typedef struct case_list case_list;
  3346. +
  3347. +struct union_def {
  3348. + declaration enum_decl;
  3349. + case_list *cases;
  3350. + declaration *default_decl;
  3351. +};
  3352. +typedef struct union_def union_def;
  3353. +
  3354. +struct arg_list {
  3355. + char *argname; /* name of struct for arg*/
  3356. + decl_list *decls;
  3357. +};
  3358. +
  3359. +typedef struct arg_list arg_list;
  3360. +
  3361. +struct proc_list {
  3362. + char *proc_name;
  3363. + char *proc_num;
  3364. + arg_list args;
  3365. + int arg_num;
  3366. + char *res_type;
  3367. + char *res_prefix;
  3368. + struct proc_list *next;
  3369. +};
  3370. +typedef struct proc_list proc_list;
  3371. +
  3372. +struct version_list {
  3373. + char *vers_name;
  3374. + char *vers_num;
  3375. + proc_list *procs;
  3376. + struct version_list *next;
  3377. +};
  3378. +typedef struct version_list version_list;
  3379. +
  3380. +struct program_def {
  3381. + char *prog_num;
  3382. + version_list *versions;
  3383. +};
  3384. +typedef struct program_def program_def;
  3385. +
  3386. +struct definition {
  3387. + char *def_name;
  3388. + defkind def_kind;
  3389. + union {
  3390. + const_def co;
  3391. + struct_def st;
  3392. + union_def un;
  3393. + enum_def en;
  3394. + typedef_def ty;
  3395. + program_def pr;
  3396. + } def;
  3397. +};
  3398. +typedef struct definition definition;
  3399. +
  3400. +definition *get_definition();
  3401. +
  3402. +
  3403. +struct bas_type
  3404. +{
  3405. + char *name;
  3406. + int length;
  3407. + struct bas_type *next;
  3408. +};
  3409. +
  3410. +typedef struct bas_type bas_type;
  3411. diff --git a/rpcgen/rpc_sample.c b/rpcgen/rpc_sample.c
  3412. new file mode 100644
  3413. index 0000000..2b5c81b
  3414. --- /dev/null
  3415. +++ b/rpcgen/rpc_sample.c
  3416. @@ -0,0 +1,247 @@
  3417. +/*
  3418. + * Copyright (c) 2009, Sun Microsystems, Inc.
  3419. + * All rights reserved.
  3420. + *
  3421. + * Redistribution and use in source and binary forms, with or without
  3422. + * modification, are permitted provided that the following conditions are met:
  3423. + * - Redistributions of source code must retain the above copyright notice,
  3424. + * this list of conditions and the following disclaimer.
  3425. + * - Redistributions in binary form must reproduce the above copyright notice,
  3426. + * this list of conditions and the following disclaimer in the documentation
  3427. + * and/or other materials provided with the distribution.
  3428. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  3429. + * contributors may be used to endorse or promote products derived
  3430. + * from this software without specific prior written permission.
  3431. + *
  3432. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3433. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3434. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3435. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  3436. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  3437. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  3438. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  3439. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  3440. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  3441. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  3442. + * POSSIBILITY OF SUCH DAMAGE.
  3443. + */
  3444. +
  3445. +#if 0
  3446. +static char sccsid[] = "@(#)rpc_sample.c 1.1 90/08/30 (C) 1987 SMI";
  3447. +
  3448. +#endif
  3449. +
  3450. +/*
  3451. + * rpc_sample.c, Sample client-server code outputter for the RPC protocol compiler
  3452. + */
  3453. +
  3454. +#include <stdio.h>
  3455. +#include <string.h>
  3456. +#include "rpc_parse.h"
  3457. +#include "rpc_util.h"
  3458. +
  3459. +
  3460. +static char RQSTP[] = "rqstp";
  3461. +
  3462. +static void write_sample_client(char *program_name, version_list *vp);
  3463. +static void write_sample_server(definition * def);
  3464. +static void return_type(proc_list *plist);
  3465. +
  3466. +void
  3467. +write_sample_svc(definition *def)
  3468. +{
  3469. + if (def->def_kind != DEF_PROGRAM)
  3470. + return;
  3471. + write_sample_server(def);
  3472. +}
  3473. +
  3474. +
  3475. +int
  3476. +write_sample_clnt(definition *def)
  3477. +{
  3478. + version_list *vp;
  3479. + int count = 0;
  3480. +
  3481. + if (def->def_kind != DEF_PROGRAM)
  3482. + return (0);
  3483. + /* generate sample code for each version */
  3484. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  3485. + write_sample_client(def->def_name, vp);
  3486. + ++count;
  3487. + }
  3488. + return (count);
  3489. +}
  3490. +
  3491. +
  3492. +static void
  3493. +write_sample_client(char *program_name, version_list *vp)
  3494. +{
  3495. + proc_list *proc;
  3496. + int i;
  3497. + decl_list *l;
  3498. +
  3499. + f_print(fout, "\n\nvoid\n");
  3500. + pvname(program_name, vp->vers_num);
  3501. + if (Cflag)
  3502. + f_print(fout, "( char* host )\n{\n");
  3503. + else
  3504. + f_print(fout, "(host)\nchar *host;\n{\n");
  3505. + f_print(fout, "\tCLIENT *clnt;\n");
  3506. +
  3507. + i = 0;
  3508. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  3509. + f_print(fout, "\t");
  3510. + ptype(proc->res_prefix, proc->res_type, 1);
  3511. + f_print(fout, " *result_%d;\n", ++i);
  3512. + /* print out declarations for arguments */
  3513. + if (proc->arg_num < 2 && !newstyle) {
  3514. + f_print(fout, "\t");
  3515. + if (!streq(proc->args.decls->decl.type, "void"))
  3516. + ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
  3517. + else
  3518. + f_print(fout, "char* "); /* cannot have "void" type */
  3519. + f_print(fout, " ");
  3520. + pvname(proc->proc_name, vp->vers_num);
  3521. + f_print(fout, "_arg;\n");
  3522. + } else if (!streq(proc->args.decls->decl.type, "void")) {
  3523. + for (l = proc->args.decls; l != NULL; l = l->next) {
  3524. + f_print(fout, "\t");
  3525. + ptype(l->decl.prefix, l->decl.type, 1);
  3526. + f_print(fout, " ");
  3527. + pvname(proc->proc_name, vp->vers_num);
  3528. + f_print(fout, "_%s;\n", l->decl.name);
  3529. + /* pdeclaration(proc->args.argname, &l->decl, 1, ";\n" );*/
  3530. + }
  3531. + }
  3532. + }
  3533. +
  3534. + /* generate creation of client handle */
  3535. + f_print(fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n",
  3536. + program_name, vp->vers_name, tirpcflag ? "netpath" : "udp");
  3537. + f_print(fout, "\tif (clnt == NULL) {\n");
  3538. + f_print(fout, "\t\tclnt_pcreateerror(host);\n");
  3539. + f_print(fout, "\t\texit(1);\n\t}\n");
  3540. +
  3541. + /* generate calls to procedures */
  3542. + i = 0;
  3543. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  3544. + f_print(fout, "\tresult_%d = ", ++i);
  3545. + pvname(proc->proc_name, vp->vers_num);
  3546. + if (proc->arg_num < 2 && !newstyle) {
  3547. + f_print(fout, "(");
  3548. + if (streq(proc->args.decls->decl.type, "void")) /* cast to void* */
  3549. + f_print(fout, "(void*)");
  3550. + f_print(fout, "&");
  3551. + pvname(proc->proc_name, vp->vers_num);
  3552. + f_print(fout, "_arg, clnt);\n");
  3553. + } else if (streq(proc->args.decls->decl.type, "void")) {
  3554. + f_print(fout, "(clnt);\n");
  3555. + } else {
  3556. + f_print(fout, "(");
  3557. + for (l = proc->args.decls; l != NULL; l = l->next) {
  3558. + pvname(proc->proc_name, vp->vers_num);
  3559. + f_print(fout, "_%s, ", l->decl.name);
  3560. + }
  3561. + f_print(fout, "clnt);\n");
  3562. + }
  3563. + f_print(fout, "\tif (result_%d == NULL) {\n", i);
  3564. + f_print(fout, "\t\tclnt_perror(clnt, \"call failed:\");\n");
  3565. + f_print(fout, "\t}\n");
  3566. + }
  3567. +
  3568. + f_print(fout, "\tclnt_destroy( clnt );\n");
  3569. + f_print(fout, "}\n");
  3570. +}
  3571. +
  3572. +static void
  3573. +write_sample_server(definition * def)
  3574. +{
  3575. + version_list *vp;
  3576. + proc_list *proc;
  3577. +
  3578. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  3579. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  3580. + f_print(fout, "\n");
  3581. + /* if( Cflag )
  3582. + f_print( fout, "extern \"C\"{\n");
  3583. +*/
  3584. + return_type(proc);
  3585. + f_print(fout, "* \n");
  3586. + if (Cflag)
  3587. + pvname_svc(proc->proc_name, vp->vers_num);
  3588. + else
  3589. + pvname(proc->proc_name, vp->vers_num);
  3590. + printarglist(proc, RQSTP, "struct svc_req *");
  3591. +
  3592. + f_print(fout, "{\n");
  3593. + f_print(fout, "\n\tstatic ");
  3594. + if (!streq(proc->res_type, "void"))
  3595. + return_type(proc);
  3596. + else
  3597. + f_print(fout, "char*"); /* cannot have void type */
  3598. + /* f_print(fout, " result;\n", proc->res_type); */
  3599. + f_print(fout, " result;\n");
  3600. + f_print(fout,
  3601. + "\n\t/*\n\t * insert server code here\n\t */\n\n");
  3602. + if (!streq(proc->res_type, "void"))
  3603. + f_print(fout, "\treturn(&result);\n}\n");
  3604. + else /* cast back to void * */
  3605. + f_print(fout, "\treturn((void*) &result);\n}\n");
  3606. + /* if( Cflag)
  3607. + f_print( fout, "};\n");
  3608. +*/
  3609. +
  3610. + }
  3611. + }
  3612. +}
  3613. +
  3614. +
  3615. +
  3616. +static void
  3617. +return_type(proc_list *plist)
  3618. +{
  3619. + ptype( plist->res_prefix, plist->res_type, 1 );
  3620. +}
  3621. +
  3622. +void
  3623. +add_sample_msg(void)
  3624. +{
  3625. + f_print(fout, "/*\n");
  3626. + f_print(fout, " * This is sample code generated by rpcgen.\n");
  3627. + f_print(fout, " * These are only templates and you can use them\n");
  3628. + f_print(fout, " * as a guideline for developing your own functions.\n");
  3629. + f_print(fout, " */\n\n");
  3630. +}
  3631. +
  3632. +void
  3633. +write_sample_clnt_main(void)
  3634. +{
  3635. + list *l;
  3636. + definition *def;
  3637. + version_list *vp;
  3638. +
  3639. + f_print(fout, "\n\n" );
  3640. + if( Cflag )
  3641. + f_print(fout,"main( int argc, char* argv[] )\n{\n" );
  3642. + else
  3643. + f_print(fout, "main(argc, argv)\nint argc;\nchar *argv[];\n{\n" );
  3644. +
  3645. + f_print(fout, "\tchar *host;");
  3646. + f_print(fout, "\n\n\tif(argc < 2) {");
  3647. + f_print(fout, "\n\t\tprintf(\"usage: %%s server_host\\n\", argv[0]);\n" );
  3648. + f_print(fout, "\t\texit(1);\n\t}");
  3649. + f_print(fout, "\n\thost = argv[1];\n");
  3650. +
  3651. + for (l = defined; l != NULL; l = l->next) {
  3652. + def = l->val;
  3653. + if (def->def_kind != DEF_PROGRAM) {
  3654. + continue;
  3655. + }
  3656. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  3657. + f_print( fout, "\t" );
  3658. + pvname(def->def_name, vp->vers_num);
  3659. + f_print( fout, "( host );\n" );
  3660. + }
  3661. + }
  3662. + f_print(fout, "}\n");
  3663. +}
  3664. diff --git a/rpcgen/rpc_scan.c b/rpcgen/rpc_scan.c
  3665. new file mode 100644
  3666. index 0000000..f58fa9f
  3667. --- /dev/null
  3668. +++ b/rpcgen/rpc_scan.c
  3669. @@ -0,0 +1,474 @@
  3670. +/*
  3671. + * Copyright (c) 2009, Sun Microsystems, Inc.
  3672. + * All rights reserved.
  3673. + *
  3674. + * Redistribution and use in source and binary forms, with or without
  3675. + * modification, are permitted provided that the following conditions are met:
  3676. + * - Redistributions of source code must retain the above copyright notice,
  3677. + * this list of conditions and the following disclaimer.
  3678. + * - Redistributions in binary form must reproduce the above copyright notice,
  3679. + * this list of conditions and the following disclaimer in the documentation
  3680. + * and/or other materials provided with the distribution.
  3681. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  3682. + * contributors may be used to endorse or promote products derived
  3683. + * from this software without specific prior written permission.
  3684. + *
  3685. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3686. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3687. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3688. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  3689. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  3690. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  3691. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  3692. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  3693. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  3694. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  3695. + * POSSIBILITY OF SUCH DAMAGE.
  3696. + */
  3697. +
  3698. +#if 0
  3699. +static char sccsid[] = "@(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI";
  3700. +#endif
  3701. +
  3702. +/*
  3703. + * rpc_scan.c, Scanner for the RPC protocol compiler
  3704. + * Copyright (C) 1987, Sun Microsystems, Inc.
  3705. + */
  3706. +#include <stdio.h>
  3707. +#include <ctype.h>
  3708. +#include <string.h>
  3709. +#include "rpc_scan.h"
  3710. +#include "rpc_parse.h"
  3711. +#include "rpc_util.h"
  3712. +
  3713. +static void unget_token(token *tokp);
  3714. +static void findstrconst(char **str, char **val);
  3715. +static void findchrconst(char **str, char **val);
  3716. +static void findconst(char **str, char **val);
  3717. +static void findkind(char **mark, token *tokp);
  3718. +static int cppline(char *line);
  3719. +static int directive(char *line);
  3720. +static void printdirective(char *line);
  3721. +static void docppline(char *line, int *lineno, char **fname);
  3722. +
  3723. +#define startcomment(where) (where[0] == '/' && where[1] == '*')
  3724. +#define endcomment(where) (where[-1] == '*' && where[0] == '/')
  3725. +
  3726. +static int pushed = 0; /* is a token pushed */
  3727. +static token lasttok; /* last token, if pushed */
  3728. +
  3729. +/*
  3730. + * scan expecting 1 given token
  3731. + */
  3732. +void
  3733. +scan(tok_kind expect, token *tokp)
  3734. +{
  3735. + get_token(tokp);
  3736. + if (tokp->kind != expect) {
  3737. + expected1(expect);
  3738. + }
  3739. +}
  3740. +
  3741. +/*
  3742. + * scan expecting any of the 2 given tokens
  3743. + */
  3744. +void
  3745. +scan2(tok_kind expect1, tok_kind expect2, token *tokp)
  3746. +{
  3747. + get_token(tokp);
  3748. + if (tokp->kind != expect1 && tokp->kind != expect2) {
  3749. + expected2(expect1, expect2);
  3750. + }
  3751. +}
  3752. +
  3753. +/*
  3754. + * scan expecting any of the 3 given token
  3755. + */
  3756. +void
  3757. +scan3(tok_kind expect1, tok_kind expect2, tok_kind expect3, token *tokp)
  3758. +{
  3759. + get_token(tokp);
  3760. + if (tokp->kind != expect1 && tokp->kind != expect2
  3761. + && tokp->kind != expect3) {
  3762. + expected3(expect1, expect2, expect3);
  3763. + }
  3764. +}
  3765. +
  3766. +/*
  3767. + * scan expecting a constant, possibly symbolic
  3768. + */
  3769. +void
  3770. +scan_num(token *tokp)
  3771. +{
  3772. + get_token(tokp);
  3773. + switch (tokp->kind) {
  3774. + case TOK_IDENT:
  3775. + break;
  3776. + default:
  3777. + error("constant or identifier expected");
  3778. + }
  3779. +}
  3780. +
  3781. +/*
  3782. + * Peek at the next token
  3783. + */
  3784. +void
  3785. +peek(token *tokp)
  3786. +{
  3787. + get_token(tokp);
  3788. + unget_token(tokp);
  3789. +}
  3790. +
  3791. +/*
  3792. + * Peek at the next token and scan it if it matches what you expect
  3793. + */
  3794. +int
  3795. +peekscan(tok_kind expect, token *tokp)
  3796. +{
  3797. + peek(tokp);
  3798. + if (tokp->kind == expect) {
  3799. + get_token(tokp);
  3800. + return (1);
  3801. + }
  3802. + return (0);
  3803. +}
  3804. +
  3805. +/*
  3806. + * Get the next token, printing out any directive that are encountered.
  3807. + */
  3808. +void
  3809. +get_token(token *tokp)
  3810. +{
  3811. + int commenting;
  3812. +
  3813. + if (pushed) {
  3814. + pushed = 0;
  3815. + *tokp = lasttok;
  3816. + return;
  3817. + }
  3818. + commenting = 0;
  3819. + for (;;) {
  3820. + if (*where == 0) {
  3821. + for (;;) {
  3822. + if (!fgets(curline, MAXLINESIZE, fin)) {
  3823. + tokp->kind = TOK_EOF;
  3824. + *where = 0;
  3825. + return;
  3826. + }
  3827. + linenum++;
  3828. + if (commenting) {
  3829. + break;
  3830. + } else if (cppline(curline)) {
  3831. + docppline(curline, &linenum,
  3832. + &infilename);
  3833. + } else if (directive(curline)) {
  3834. + printdirective(curline);
  3835. + } else {
  3836. + break;
  3837. + }
  3838. + }
  3839. + where = curline;
  3840. + } else if (isspace(*where)) {
  3841. + while (isspace(*where)) {
  3842. + where++; /* eat */
  3843. + }
  3844. + } else if (commenting) {
  3845. + for (where++; *where; where++) {
  3846. + if (endcomment(where)) {
  3847. + where++;
  3848. + commenting--;
  3849. + break;
  3850. + }
  3851. + }
  3852. + } else if (startcomment(where)) {
  3853. + where += 2;
  3854. + commenting++;
  3855. + } else {
  3856. + break;
  3857. + }
  3858. + }
  3859. +
  3860. + /*
  3861. + * 'where' is not whitespace, comment or directive Must be a token!
  3862. + */
  3863. + switch (*where) {
  3864. + case ':':
  3865. + tokp->kind = TOK_COLON;
  3866. + where++;
  3867. + break;
  3868. + case ';':
  3869. + tokp->kind = TOK_SEMICOLON;
  3870. + where++;
  3871. + break;
  3872. + case ',':
  3873. + tokp->kind = TOK_COMMA;
  3874. + where++;
  3875. + break;
  3876. + case '=':
  3877. + tokp->kind = TOK_EQUAL;
  3878. + where++;
  3879. + break;
  3880. + case '*':
  3881. + tokp->kind = TOK_STAR;
  3882. + where++;
  3883. + break;
  3884. + case '[':
  3885. + tokp->kind = TOK_LBRACKET;
  3886. + where++;
  3887. + break;
  3888. + case ']':
  3889. + tokp->kind = TOK_RBRACKET;
  3890. + where++;
  3891. + break;
  3892. + case '{':
  3893. + tokp->kind = TOK_LBRACE;
  3894. + where++;
  3895. + break;
  3896. + case '}':
  3897. + tokp->kind = TOK_RBRACE;
  3898. + where++;
  3899. + break;
  3900. + case '(':
  3901. + tokp->kind = TOK_LPAREN;
  3902. + where++;
  3903. + break;
  3904. + case ')':
  3905. + tokp->kind = TOK_RPAREN;
  3906. + where++;
  3907. + break;
  3908. + case '<':
  3909. + tokp->kind = TOK_LANGLE;
  3910. + where++;
  3911. + break;
  3912. + case '>':
  3913. + tokp->kind = TOK_RANGLE;
  3914. + where++;
  3915. + break;
  3916. +
  3917. + case '"':
  3918. + tokp->kind = TOK_STRCONST;
  3919. + findstrconst(&where, &tokp->str);
  3920. + break;
  3921. + case '\'':
  3922. + tokp->kind = TOK_CHARCONST;
  3923. + findchrconst(&where, &tokp->str);
  3924. + break;
  3925. +
  3926. + case '-':
  3927. + case '0':
  3928. + case '1':
  3929. + case '2':
  3930. + case '3':
  3931. + case '4':
  3932. + case '5':
  3933. + case '6':
  3934. + case '7':
  3935. + case '8':
  3936. + case '9':
  3937. + tokp->kind = TOK_IDENT;
  3938. + findconst(&where, &tokp->str);
  3939. + break;
  3940. +
  3941. + default:
  3942. + if (!(isalpha(*where) || *where == '_')) {
  3943. + char buf[100];
  3944. + char *p;
  3945. +
  3946. + s_print(buf, "illegal character in file: ");
  3947. + p = buf + strlen(buf);
  3948. + if (isprint(*where)) {
  3949. + s_print(p, "%c", *where);
  3950. + } else {
  3951. + s_print(p, "%d", *where);
  3952. + }
  3953. + error(buf);
  3954. + }
  3955. + findkind(&where, tokp);
  3956. + break;
  3957. + }
  3958. +}
  3959. +
  3960. +static void
  3961. +unget_token(token *tokp)
  3962. +{
  3963. + lasttok = *tokp;
  3964. + pushed = 1;
  3965. +}
  3966. +
  3967. +static void
  3968. +findstrconst(char **str, char **val)
  3969. +{
  3970. + char *p;
  3971. + int size;
  3972. +
  3973. + p = *str;
  3974. + do {
  3975. + *p++;
  3976. + } while (*p && *p != '"');
  3977. + if (*p == 0) {
  3978. + error("unterminated string constant");
  3979. + }
  3980. + p++;
  3981. + size = p - *str;
  3982. + *val = alloc(size + 1);
  3983. + (void) strncpy(*val, *str, size);
  3984. + (*val)[size] = 0;
  3985. + *str = p;
  3986. +}
  3987. +
  3988. +static void
  3989. +findchrconst(char **str, char **val)
  3990. +{
  3991. + char *p;
  3992. + int size;
  3993. +
  3994. + p = *str;
  3995. + do {
  3996. + *p++;
  3997. + } while (*p && *p != '\'');
  3998. + if (*p == 0) {
  3999. + error("unterminated string constant");
  4000. + }
  4001. + p++;
  4002. + size = p - *str;
  4003. + if (size != 3) {
  4004. + error("empty char string");
  4005. + }
  4006. + *val = alloc(size + 1);
  4007. + (void) strncpy(*val, *str, size);
  4008. + (*val)[size] = 0;
  4009. + *str = p;
  4010. +}
  4011. +
  4012. +static void
  4013. +findconst(char **str, char **val)
  4014. +{
  4015. + char *p;
  4016. + int size;
  4017. +
  4018. + p = *str;
  4019. + if (*p == '0' && *(p + 1) == 'x') {
  4020. + p++;
  4021. + do {
  4022. + p++;
  4023. + } while (isxdigit(*p));
  4024. + } else {
  4025. + do {
  4026. + p++;
  4027. + } while (isdigit(*p));
  4028. + }
  4029. + size = p - *str;
  4030. + *val = alloc(size + 1);
  4031. + (void) strncpy(*val, *str, size);
  4032. + (*val)[size] = 0;
  4033. + *str = p;
  4034. +}
  4035. +
  4036. +static token symbols[] = {
  4037. + {TOK_CONST, "const"},
  4038. + {TOK_UNION, "union"},
  4039. + {TOK_SWITCH, "switch"},
  4040. + {TOK_CASE, "case"},
  4041. + {TOK_DEFAULT, "default"},
  4042. + {TOK_STRUCT, "struct"},
  4043. + {TOK_TYPEDEF, "typedef"},
  4044. + {TOK_ENUM, "enum"},
  4045. + {TOK_OPAQUE, "opaque"},
  4046. + {TOK_BOOL, "bool"},
  4047. + {TOK_VOID, "void"},
  4048. + {TOK_CHAR, "char"},
  4049. + {TOK_INT, "int"},
  4050. + {TOK_UNSIGNED, "unsigned"},
  4051. + {TOK_SHORT, "short"},
  4052. + {TOK_INT32, "int32"},
  4053. + {TOK_FLOAT, "float"},
  4054. + {TOK_DOUBLE, "double"},
  4055. + {TOK_STRING, "string"},
  4056. + {TOK_PROGRAM, "program"},
  4057. + {TOK_VERSION, "version"},
  4058. + {TOK_EOF, "??????"},
  4059. +};
  4060. +
  4061. +static void
  4062. +findkind(char **mark, token *tokp)
  4063. +{
  4064. + int len;
  4065. + token *s;
  4066. + char *str;
  4067. +
  4068. + str = *mark;
  4069. + for (s = symbols; s->kind != TOK_EOF; s++) {
  4070. + len = strlen(s->str);
  4071. + if (strncmp(str, s->str, len) == 0) {
  4072. + if (!isalnum(str[len]) && str[len] != '_') {
  4073. + tokp->kind = s->kind;
  4074. + tokp->str = s->str;
  4075. + *mark = str + len;
  4076. + return;
  4077. + }
  4078. + }
  4079. + }
  4080. + tokp->kind = TOK_IDENT;
  4081. + for (len = 0; isalnum(str[len]) || str[len] == '_'; len++);
  4082. + tokp->str = alloc(len + 1);
  4083. + (void) strncpy(tokp->str, str, len);
  4084. + tokp->str[len] = 0;
  4085. + *mark = str + len;
  4086. +}
  4087. +
  4088. +static int
  4089. +cppline(char *line)
  4090. +{
  4091. + return (line == curline && *line == '#');
  4092. +}
  4093. +
  4094. +static int
  4095. +directive(char *line)
  4096. +{
  4097. + return (line == curline && *line == '%');
  4098. +}
  4099. +
  4100. +static void
  4101. +printdirective(char *line)
  4102. +{
  4103. + f_print(fout, "%s", line + 1);
  4104. +}
  4105. +
  4106. +static void
  4107. +docppline(char *line, int *lineno, char **fname)
  4108. +{
  4109. + char *file;
  4110. + int num;
  4111. + char *p;
  4112. +
  4113. + line++;
  4114. + while (isspace(*line)) {
  4115. + line++;
  4116. + }
  4117. + num = atoi(line);
  4118. + while (isdigit(*line)) {
  4119. + line++;
  4120. + }
  4121. + while (isspace(*line)) {
  4122. + line++;
  4123. + }
  4124. + if (*line != '"') {
  4125. + error("preprocessor error");
  4126. + }
  4127. + line++;
  4128. + p = file = alloc(strlen(line) + 1);
  4129. + while (*line && *line != '"') {
  4130. + *p++ = *line++;
  4131. + }
  4132. + if (*line == 0) {
  4133. + error("preprocessor error");
  4134. + }
  4135. + *p = 0;
  4136. + if (*file == 0) {
  4137. + *fname = NULL;
  4138. + free(file);
  4139. + } else {
  4140. + *fname = file;
  4141. + }
  4142. + *lineno = num - 1;
  4143. +}
  4144. diff --git a/rpcgen/rpc_scan.h b/rpcgen/rpc_scan.h
  4145. new file mode 100644
  4146. index 0000000..16f688c
  4147. --- /dev/null
  4148. +++ b/rpcgen/rpc_scan.h
  4149. @@ -0,0 +1,103 @@
  4150. +/*
  4151. + * Copyright (c) 2009, Sun Microsystems, Inc.
  4152. + * All rights reserved.
  4153. + *
  4154. + * Redistribution and use in source and binary forms, with or without
  4155. + * modification, are permitted provided that the following conditions are met:
  4156. + * - Redistributions of source code must retain the above copyright notice,
  4157. + * this list of conditions and the following disclaimer.
  4158. + * - Redistributions in binary form must reproduce the above copyright notice,
  4159. + * this list of conditions and the following disclaimer in the documentation
  4160. + * and/or other materials provided with the distribution.
  4161. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  4162. + * contributors may be used to endorse or promote products derived
  4163. + * from this software without specific prior written permission.
  4164. + *
  4165. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  4166. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  4167. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  4168. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  4169. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  4170. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  4171. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  4172. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  4173. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  4174. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  4175. + * POSSIBILITY OF SUCH DAMAGE.
  4176. + */
  4177. +
  4178. +/* @(#)rpc_scan.h 1.3 90/08/29 (C) 1987 SMI */
  4179. +
  4180. +/*
  4181. + * rpc_scan.h, Definitions for the RPCL scanner
  4182. + */
  4183. +
  4184. +/*
  4185. + * kinds of tokens
  4186. + */
  4187. +enum tok_kind {
  4188. + TOK_IDENT,
  4189. + TOK_CHARCONST,
  4190. + TOK_STRCONST,
  4191. + TOK_LPAREN,
  4192. + TOK_RPAREN,
  4193. + TOK_LBRACE,
  4194. + TOK_RBRACE,
  4195. + TOK_LBRACKET,
  4196. + TOK_RBRACKET,
  4197. + TOK_LANGLE,
  4198. + TOK_RANGLE,
  4199. + TOK_STAR,
  4200. + TOK_COMMA,
  4201. + TOK_EQUAL,
  4202. + TOK_COLON,
  4203. + TOK_SEMICOLON,
  4204. + TOK_CONST,
  4205. + TOK_STRUCT,
  4206. + TOK_UNION,
  4207. + TOK_SWITCH,
  4208. + TOK_CASE,
  4209. + TOK_DEFAULT,
  4210. + TOK_ENUM,
  4211. + TOK_TYPEDEF,
  4212. + TOK_INT,
  4213. + TOK_SHORT,
  4214. + TOK_INT32,
  4215. + TOK_UNSIGNED,
  4216. + TOK_FLOAT,
  4217. + TOK_DOUBLE,
  4218. + TOK_OPAQUE,
  4219. + TOK_CHAR,
  4220. + TOK_STRING,
  4221. + TOK_BOOL,
  4222. + TOK_VOID,
  4223. + TOK_PROGRAM,
  4224. + TOK_VERSION,
  4225. + TOK_EOF
  4226. +};
  4227. +typedef enum tok_kind tok_kind;
  4228. +
  4229. +/*
  4230. + * a token
  4231. + */
  4232. +struct token {
  4233. + tok_kind kind;
  4234. + char *str;
  4235. +};
  4236. +typedef struct token token;
  4237. +
  4238. +
  4239. +/*
  4240. + * routine interface
  4241. + */
  4242. +void scan();
  4243. +void scan2();
  4244. +void scan3();
  4245. +void scan_num();
  4246. +void peek();
  4247. +int peekscan();
  4248. +void get_token();
  4249. +void expected1(tok_kind);
  4250. +void expected2(tok_kind, tok_kind);
  4251. +void expected3(tok_kind, tok_kind, tok_kind);
  4252. +
  4253. diff --git a/rpcgen/rpc_svcout.c b/rpcgen/rpc_svcout.c
  4254. new file mode 100644
  4255. index 0000000..284a529
  4256. --- /dev/null
  4257. +++ b/rpcgen/rpc_svcout.c
  4258. @@ -0,0 +1,882 @@
  4259. +/*
  4260. + * Copyright (c) 2009, Sun Microsystems, Inc.
  4261. + * All rights reserved.
  4262. + *
  4263. + * Redistribution and use in source and binary forms, with or without
  4264. + * modification, are permitted provided that the following conditions are met:
  4265. + * - Redistributions of source code must retain the above copyright notice,
  4266. + * this list of conditions and the following disclaimer.
  4267. + * - Redistributions in binary form must reproduce the above copyright notice,
  4268. + * this list of conditions and the following disclaimer in the documentation
  4269. + * and/or other materials provided with the distribution.
  4270. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  4271. + * contributors may be used to endorse or promote products derived
  4272. + * from this software without specific prior written permission.
  4273. + *
  4274. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  4275. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  4276. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  4277. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  4278. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  4279. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  4280. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  4281. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  4282. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  4283. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  4284. + * POSSIBILITY OF SUCH DAMAGE.
  4285. + */
  4286. +
  4287. +#if 0
  4288. + static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
  4289. +#endif
  4290. +
  4291. +/*
  4292. + * rpc_svcout.c, Server-skeleton outputter for the RPC protocol compiler
  4293. + */
  4294. +#include <stdio.h>
  4295. +#include <string.h>
  4296. +#include "rpc_parse.h"
  4297. +#include "rpc_util.h"
  4298. +#include "rpc_output.h"
  4299. +
  4300. +static void write_real_program(definition *def);
  4301. +static void write_program(definition *def, char *storage);
  4302. +static void printerr(char *err, char *transp);
  4303. +static void printif(char *proc, char *transp, char *prefix, char *arg);
  4304. +static void write_inetmost(char *infile);
  4305. +static void print_return(char *space);
  4306. +static void print_pmapunset(char *space);
  4307. +static void print_err_message(char *space);
  4308. +static void write_timeout_func(void);
  4309. +static void write_pm_most(char *infile, int netflag);
  4310. +static void write_rpc_svc_fg(char *infile, char *sp);
  4311. +static void open_log_file(char *infile, char *sp);
  4312. +
  4313. +static char RQSTP[] = "rqstp";
  4314. +static char TRANSP[] = "transp";
  4315. +static char ARG[] = "argument";
  4316. +static char RESULT[] = "result";
  4317. +static char ROUTINE[] = "local";
  4318. +
  4319. +char _errbuf[256]; /* For all messages */
  4320. +
  4321. +static void
  4322. +p_xdrfunc(char *rname, char *typename)
  4323. +{
  4324. + if (Cflag)
  4325. + f_print(fout, "\t\txdr_%s = (xdrproc_t) xdr_%s;\n", rname,
  4326. + stringfix(typename));
  4327. + else
  4328. + f_print(fout, "\t\txdr_%s = xdr_%s;\n", rname, stringfix(typename));
  4329. +}
  4330. +
  4331. +void
  4332. +internal_proctype(proc_list *plist)
  4333. +{
  4334. + f_print(fout, "static ");
  4335. + ptype( plist->res_prefix, plist->res_type, 1 );
  4336. + f_print( fout, "*" );
  4337. +}
  4338. +
  4339. +
  4340. +/*
  4341. + * write most of the service, that is, everything but the registrations.
  4342. + */
  4343. +void
  4344. +write_most(char *infile, int netflag, int nomain)
  4345. +{
  4346. + if (inetdflag || pmflag) {
  4347. + char* var_type;
  4348. + var_type = (nomain? "extern" : "static");
  4349. + f_print(fout, "%s int _rpcpmstart;", var_type );
  4350. + f_print(fout, "\t\t/* Started by a port monitor ? */\n");
  4351. + f_print(fout, "%s int _rpcfdtype;", var_type );
  4352. + f_print(fout, "\t\t/* Whether Stream or Datagram ? */\n");
  4353. + if (timerflag) {
  4354. + f_print(fout, "%s int _rpcsvcdirty;", var_type );
  4355. + f_print(fout, "\t/* Still serving ? */\n");
  4356. + }
  4357. + write_svc_aux( nomain );
  4358. + }
  4359. + /* write out dispatcher and stubs */
  4360. + write_programs( nomain? (char *)NULL : "static" );
  4361. +
  4362. + if( nomain )
  4363. + return;
  4364. +
  4365. + f_print(fout, "\nmain()\n");
  4366. + f_print(fout, "{\n");
  4367. + if (inetdflag) {
  4368. + write_inetmost(infile); /* Includes call to write_rpc_svc_fg() */
  4369. + } else {
  4370. + if( tirpcflag ) {
  4371. + if (netflag) {
  4372. + f_print(fout, "\tregister SVCXPRT *%s;\n", TRANSP);
  4373. + f_print(fout, "\tstruct netconfig *nconf = NULL;\n");
  4374. + }
  4375. + f_print(fout, "\tpid_t pid;\n");
  4376. + f_print(fout, "\tint i;\n");
  4377. + f_print(fout, "\tchar mname[FMNAMESZ + 1];\n\n");
  4378. + write_pm_most(infile, netflag);
  4379. + f_print(fout, "\telse {\n");
  4380. + write_rpc_svc_fg(infile, "\t\t");
  4381. + f_print(fout, "\t}\n");
  4382. + } else {
  4383. + f_print(fout, "\tregister SVCXPRT *%s;\n", TRANSP);
  4384. + f_print(fout, "\n");
  4385. + print_pmapunset("\t");
  4386. + }
  4387. + }
  4388. +
  4389. + if (logflag && !inetdflag) {
  4390. + open_log_file(infile, "\t");
  4391. + }
  4392. +}
  4393. +
  4394. +/*
  4395. + * write a registration for the given transport
  4396. + */
  4397. +void
  4398. +write_netid_register(char *transp)
  4399. +{
  4400. + list *l;
  4401. + definition *def;
  4402. + version_list *vp;
  4403. + char *sp;
  4404. + char tmpbuf[32];
  4405. +
  4406. + sp = "";
  4407. + f_print(fout, "\n");
  4408. + f_print(fout, "%s\tnconf = getnetconfigent(\"%s\");\n", sp, transp);
  4409. + f_print(fout, "%s\tif (nconf == NULL) {\n", sp);
  4410. + (void) sprintf(_errbuf, "cannot find %s netid.", transp);
  4411. + sprintf(tmpbuf, "%s\t\t", sp);
  4412. + print_err_message(tmpbuf);
  4413. + f_print(fout, "%s\t\texit(1);\n", sp);
  4414. + f_print(fout, "%s\t}\n", sp);
  4415. + f_print(fout, "%s\t%s = svc_tli_create(RPC_ANYFD, nconf, 0, 0, 0);\n",
  4416. + sp, TRANSP);
  4417. + f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
  4418. + (void) sprintf(_errbuf, "cannot create %s service.", transp);
  4419. + print_err_message(tmpbuf);
  4420. + f_print(fout, "%s\t\texit(1);\n", sp);
  4421. + f_print(fout, "%s\t}\n", sp);
  4422. +
  4423. + for (l = defined; l != NULL; l = l->next) {
  4424. + def = (definition *) l->val;
  4425. + if (def->def_kind != DEF_PROGRAM) {
  4426. + continue;
  4427. + }
  4428. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  4429. + f_print(fout,
  4430. + "%s\t(void) rpcb_unset(%s, %s, nconf);\n",
  4431. + sp, def->def_name, vp->vers_name);
  4432. + f_print(fout,
  4433. + "%s\tif (!svc_reg(%s, %s, %s, ",
  4434. + sp, TRANSP, def->def_name, vp->vers_name);
  4435. + pvname(def->def_name, vp->vers_num);
  4436. + f_print(fout, ", nconf)) {\n");
  4437. + (void) sprintf(_errbuf, "unable to register (%s, %s, %s).",
  4438. + def->def_name, vp->vers_name, transp);
  4439. + print_err_message(tmpbuf);
  4440. + f_print(fout, "%s\t\texit(1);\n", sp);
  4441. + f_print(fout, "%s\t}\n", sp);
  4442. + }
  4443. + }
  4444. + f_print(fout, "%s\tfreenetconfigent(nconf);\n", sp);
  4445. +}
  4446. +
  4447. +/*
  4448. + * write a registration for the given transport for TLI
  4449. + */
  4450. +void
  4451. +write_nettype_register(char *transp)
  4452. +{
  4453. + list *l;
  4454. + definition *def;
  4455. + version_list *vp;
  4456. +
  4457. + for (l = defined; l != NULL; l = l->next) {
  4458. + def = (definition *) l->val;
  4459. + if (def->def_kind != DEF_PROGRAM) {
  4460. + continue;
  4461. + }
  4462. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  4463. + f_print(fout, "\tif (!svc_create(");
  4464. + pvname(def->def_name, vp->vers_num);
  4465. + f_print(fout, ", %s, %s, \"%s\")) {\n ",
  4466. + def->def_name, vp->vers_name, transp);
  4467. + (void) sprintf(_errbuf,
  4468. + "unable to create (%s, %s) for %s.",
  4469. + def->def_name, vp->vers_name, transp);
  4470. + print_err_message("\t\t");
  4471. + f_print(fout, "\t\texit(1);\n");
  4472. + f_print(fout, "\t}\n");
  4473. + }
  4474. + }
  4475. +}
  4476. +
  4477. +/*
  4478. + * write the rest of the service
  4479. + */
  4480. +void
  4481. +write_rest(void)
  4482. +{
  4483. + f_print(fout, "\n");
  4484. + if (inetdflag) {
  4485. + f_print(fout, "\tif (%s == (SVCXPRT *)NULL) {\n", TRANSP);
  4486. + (void) sprintf(_errbuf, "could not create a handle");
  4487. + print_err_message("\t\t");
  4488. + f_print(fout, "\t\texit(1);\n");
  4489. + f_print(fout, "\t}\n");
  4490. + if (timerflag) {
  4491. + f_print(fout, "\tif (_rpcpmstart) {\n");
  4492. + f_print(fout,
  4493. + "\t\t(void) signal(SIGALRM, %s closedown);\n",
  4494. + Cflag? "(SIG_PF)" : "(void(*)())" );
  4495. + f_print(fout, "\t\t(void) alarm(_RPCSVC_CLOSEDOWN);\n");
  4496. + f_print(fout, "\t}\n");
  4497. + }
  4498. + }
  4499. + f_print(fout, "\tsvc_run();\n");
  4500. + (void) sprintf(_errbuf, "svc_run returned");
  4501. + print_err_message("\t");
  4502. + f_print(fout, "\texit(1);\n");
  4503. + f_print(fout, "\t/* NOTREACHED */\n");
  4504. + f_print(fout, "}\n");
  4505. +}
  4506. +
  4507. +void
  4508. +write_programs(char *storage)
  4509. +{
  4510. + list *l;
  4511. + definition *def;
  4512. +
  4513. + /* write out stubs for procedure definitions */
  4514. + for (l = defined; l != NULL; l = l->next) {
  4515. + def = (definition *) l->val;
  4516. + if (def->def_kind == DEF_PROGRAM) {
  4517. + write_real_program(def);
  4518. + }
  4519. + }
  4520. +
  4521. + /* write out dispatcher for each program */
  4522. + for (l = defined; l != NULL; l = l->next) {
  4523. + def = (definition *) l->val;
  4524. + if (def->def_kind == DEF_PROGRAM) {
  4525. + write_program(def, storage);
  4526. + }
  4527. + }
  4528. +
  4529. +
  4530. +}
  4531. +
  4532. +/* write out definition of internal function (e.g. _printmsg_1(...))
  4533. + which calls server's defintion of actual function (e.g. printmsg_1(...)).
  4534. + Unpacks single user argument of printmsg_1 to call-by-value format
  4535. + expected by printmsg_1. */
  4536. +static void
  4537. +write_real_program(definition *def)
  4538. +{
  4539. + version_list *vp;
  4540. + proc_list *proc;
  4541. + decl_list *l;
  4542. +
  4543. + if( !newstyle ) return; /* not needed for old style */
  4544. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  4545. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  4546. + f_print(fout, "\n");
  4547. + internal_proctype(proc);
  4548. + f_print(fout, "\n_");
  4549. + pvname(proc->proc_name, vp->vers_num);
  4550. + if( Cflag ) {
  4551. + f_print(fout, "(" );
  4552. + /* arg name */
  4553. + if (proc->arg_num > 1)
  4554. + f_print(fout, proc->args.argname);
  4555. + else
  4556. + ptype(proc->args.decls->decl.prefix,
  4557. + proc->args.decls->decl.type, 0);
  4558. + f_print(fout, " *argp, struct svc_req *%s)\n",
  4559. + RQSTP);
  4560. + } else {
  4561. + f_print(fout, "(argp, %s)\n", RQSTP );
  4562. + /* arg name */
  4563. + if (proc->arg_num > 1)
  4564. + f_print(fout, "\t%s *argp;\n", proc->args.argname);
  4565. + else {
  4566. + f_print(fout, "\t");
  4567. + ptype(proc->args.decls->decl.prefix,
  4568. + proc->args.decls->decl.type, 0);
  4569. + f_print(fout, " *argp;\n");
  4570. + }
  4571. + f_print(fout, " struct svc_req *%s;\n", RQSTP);
  4572. + }
  4573. +
  4574. + f_print(fout, "{\n");
  4575. + f_print(fout, "\treturn(");
  4576. + if( Cflag )
  4577. + pvname_svc(proc->proc_name, vp->vers_num);
  4578. + else
  4579. + pvname(proc->proc_name, vp->vers_num);
  4580. + f_print(fout, "(");
  4581. + if (proc->arg_num < 2) { /* single argument */
  4582. + if (!streq( proc->args.decls->decl.type, "void"))
  4583. + f_print(fout, "*argp, "); /* non-void */
  4584. + } else {
  4585. + for (l = proc->args.decls; l != NULL; l = l->next)
  4586. + f_print(fout, "argp->%s, ", l->decl.name);
  4587. + }
  4588. + f_print(fout, "%s));\n}\n", RQSTP);
  4589. + }
  4590. + }
  4591. +}
  4592. +
  4593. +static void
  4594. +write_program(definition *def, char *storage)
  4595. +{
  4596. + version_list *vp;
  4597. + proc_list *proc;
  4598. + int filled;
  4599. +
  4600. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  4601. + f_print(fout, "\n");
  4602. + if (storage != NULL) {
  4603. + f_print(fout, "%s ", storage);
  4604. + }
  4605. + f_print(fout, "void\n");
  4606. + pvname(def->def_name, vp->vers_num);
  4607. +
  4608. + if (Cflag) {
  4609. + f_print(fout, "(struct svc_req *%s, ", RQSTP);
  4610. + f_print(fout, "register SVCXPRT *%s)\n", TRANSP);
  4611. + } else {
  4612. + f_print(fout, "(%s, %s)\n", RQSTP, TRANSP);
  4613. + f_print(fout, " struct svc_req *%s;\n", RQSTP);
  4614. + f_print(fout, " register SVCXPRT *%s;\n", TRANSP);
  4615. + }
  4616. +
  4617. + f_print(fout, "{\n");
  4618. +
  4619. + filled = 0;
  4620. + f_print(fout, "\tunion {\n");
  4621. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  4622. + if (proc->arg_num < 2) { /* single argument */
  4623. + if (streq(proc->args.decls->decl.type,
  4624. + "void")) {
  4625. + continue;
  4626. + }
  4627. + filled = 1;
  4628. + f_print(fout, "\t\t");
  4629. + ptype(proc->args.decls->decl.prefix,
  4630. + proc->args.decls->decl.type, 0);
  4631. + pvname(proc->proc_name, vp->vers_num);
  4632. + f_print(fout, "_arg;\n");
  4633. +
  4634. + }
  4635. + else {
  4636. + filled = 1;
  4637. + f_print(fout, "\t\t%s", proc->args.argname);
  4638. + f_print(fout, " ");
  4639. + pvname(proc->proc_name, vp->vers_num);
  4640. + f_print(fout, "_arg;\n");
  4641. + }
  4642. + }
  4643. + if (!filled) {
  4644. + f_print(fout, "\t\tint fill;\n");
  4645. + }
  4646. + f_print(fout, "\t} %s;\n", ARG);
  4647. + f_print(fout, "\tchar *%s;\n", RESULT);
  4648. +
  4649. + if (Cflag) {
  4650. + f_print(fout, "\txdrproc_t xdr_%s, xdr_%s;\n", ARG, RESULT);
  4651. + f_print(fout,
  4652. + "\tchar *(*%s)(char *, struct svc_req *);\n",
  4653. + ROUTINE);
  4654. + } else {
  4655. + f_print(fout, "\tbool_t (*xdr_%s)(), (*xdr_%s)();\n", ARG, RESULT);
  4656. + f_print(fout, "\tchar *(*%s)();\n", ROUTINE);
  4657. + }
  4658. +
  4659. + f_print(fout, "\n");
  4660. +
  4661. + if (timerflag)
  4662. + f_print(fout, "\t_rpcsvcdirty = 1;\n");
  4663. + f_print(fout, "\tswitch (%s->rq_proc) {\n", RQSTP);
  4664. + if (!nullproc(vp->procs)) {
  4665. + f_print(fout, "\tcase NULLPROC:\n");
  4666. + f_print(fout,
  4667. + "\t\t(void) svc_sendreply(%s, (xdrproc_t) xdr_void, (char *)NULL);\n",
  4668. + TRANSP);
  4669. + print_return("\t\t");
  4670. + f_print(fout, "\n");
  4671. + }
  4672. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  4673. + f_print(fout, "\tcase %s:\n", proc->proc_name);
  4674. + if (proc->arg_num < 2) { /* single argument */
  4675. + p_xdrfunc( ARG, proc->args.decls->decl.type);
  4676. + } else {
  4677. + p_xdrfunc( ARG, proc->args.argname);
  4678. + }
  4679. + p_xdrfunc( RESULT, proc->res_type);
  4680. + if( Cflag )
  4681. + f_print(fout,
  4682. + "\t\t%s = (char *(*)(char *, struct svc_req *)) ",
  4683. + ROUTINE);
  4684. + else
  4685. + f_print(fout, "\t\t%s = (char *(*)()) ", ROUTINE);
  4686. +
  4687. + if (newstyle) { /* new style: calls internal routine */
  4688. + f_print(fout,"_");
  4689. + }
  4690. + /* Not sure about the following...
  4691. + * rpc_hout always generates foobar_1_svc for
  4692. + * the service procedure, so why should we use
  4693. + * foobar_1 here?! --okir */
  4694. +#if 0
  4695. + if( Cflag && !newstyle )
  4696. + pvname_svc(proc->proc_name, vp->vers_num);
  4697. + else
  4698. + pvname(proc->proc_name, vp->vers_num);
  4699. +#else
  4700. + pvname_svc(proc->proc_name, vp->vers_num);
  4701. +#endif
  4702. + f_print(fout, ";\n");
  4703. + f_print(fout, "\t\tbreak;\n\n");
  4704. + }
  4705. + f_print(fout, "\tdefault:\n");
  4706. + printerr("noproc", TRANSP);
  4707. + print_return("\t\t");
  4708. + f_print(fout, "\t}\n");
  4709. +
  4710. + f_print(fout, "\t(void) memset((char *)&%s, 0, sizeof (%s));\n", ARG, ARG);
  4711. + if (Cflag)
  4712. + printif("getargs", TRANSP, "(caddr_t) &", ARG);
  4713. + else
  4714. + printif("getargs", TRANSP, "&", ARG);
  4715. + printerr("decode", TRANSP);
  4716. + print_return("\t\t");
  4717. + f_print(fout, "\t}\n");
  4718. +
  4719. + if (Cflag)
  4720. + f_print(fout, "\t%s = (*%s)((char *)&%s, %s);\n",
  4721. + RESULT, ROUTINE, ARG, RQSTP);
  4722. + else
  4723. + f_print(fout, "\t%s = (*%s)(&%s, %s);\n",
  4724. + RESULT, ROUTINE, ARG, RQSTP);
  4725. + f_print(fout,
  4726. + "\tif (%s != NULL && !svc_sendreply(%s, "
  4727. + "(xdrproc_t) xdr_%s, %s)) {\n",
  4728. + RESULT, TRANSP, RESULT, RESULT);
  4729. + printerr("systemerr", TRANSP);
  4730. + f_print(fout, "\t}\n");
  4731. +
  4732. + if (Cflag)
  4733. + printif("freeargs", TRANSP, "(caddr_t) &", ARG);
  4734. + else
  4735. + printif("freeargs", TRANSP, "&", ARG);
  4736. + (void) sprintf(_errbuf, "unable to free arguments");
  4737. + print_err_message("\t\t");
  4738. + f_print(fout, "\t\texit(1);\n");
  4739. + f_print(fout, "\t}\n");
  4740. + print_return("\t");
  4741. + f_print(fout, "}\n");
  4742. + }
  4743. +}
  4744. +
  4745. +static void
  4746. +printerr(char *err, char *transp)
  4747. +{
  4748. + f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
  4749. +}
  4750. +
  4751. +static void
  4752. +printif(char *proc, char *transp, char *prefix, char *arg)
  4753. +{
  4754. + f_print(fout, "\tif (!svc_%s(%s, (xdrproc_t) xdr_%s, (caddr_t) %s%s)) {\n",
  4755. + proc, transp, arg, prefix, arg);
  4756. +}
  4757. +
  4758. +int
  4759. +nullproc(proc_list *proc)
  4760. +{
  4761. + for (; proc != NULL; proc = proc->next) {
  4762. + if (streq(proc->proc_num, "0")) {
  4763. + return (1);
  4764. + }
  4765. + }
  4766. + return (0);
  4767. +}
  4768. +
  4769. +static void
  4770. +write_inetmost(char *infile)
  4771. +{
  4772. + f_print(fout, "\tregister SVCXPRT *%s;\n", TRANSP);
  4773. + f_print(fout, "\tint sock;\n");
  4774. + f_print(fout, "\tint proto;\n");
  4775. + f_print(fout, "\tstruct sockaddr_in saddr;\n");
  4776. + f_print(fout, "\tint asize = sizeof (saddr);\n");
  4777. + f_print(fout, "\n");
  4778. + f_print(fout,
  4779. + "\tif (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) {\n");
  4780. + f_print(fout, "\t\tint ssize = sizeof (int);\n\n");
  4781. + f_print(fout, "\t\tif (saddr.sin_family != AF_INET)\n");
  4782. + f_print(fout, "\t\t\texit(1);\n");
  4783. + f_print(fout, "\t\tif (getsockopt(0, SOL_SOCKET, SO_TYPE,\n");
  4784. + f_print(fout, "\t\t\t\t(char *)&_rpcfdtype, &ssize) == -1)\n");
  4785. + f_print(fout, "\t\t\texit(1);\n");
  4786. + f_print(fout, "\t\tsock = 0;\n");
  4787. + f_print(fout, "\t\t_rpcpmstart = 1;\n");
  4788. + f_print(fout, "\t\tproto = 0;\n");
  4789. + open_log_file(infile, "\t\t");
  4790. + f_print(fout, "\t} else {\n");
  4791. + write_rpc_svc_fg(infile, "\t\t");
  4792. + f_print(fout, "\t\tsock = RPC_ANYSOCK;\n");
  4793. + print_pmapunset("\t\t");
  4794. + f_print(fout, "\t}\n");
  4795. +}
  4796. +
  4797. +static void
  4798. +print_return(char *space)
  4799. +{
  4800. + if (exitnow)
  4801. + f_print(fout, "%sexit(0);\n", space);
  4802. + else {
  4803. + if (timerflag)
  4804. + f_print(fout, "%s_rpcsvcdirty = 0;\n", space);
  4805. + f_print(fout, "%sreturn;\n", space);
  4806. + }
  4807. +}
  4808. +
  4809. +static void
  4810. +print_pmapunset(char *space)
  4811. +{
  4812. + list *l;
  4813. + definition *def;
  4814. + version_list *vp;
  4815. +
  4816. + for (l = defined; l != NULL; l = l->next) {
  4817. + def = (definition *) l->val;
  4818. + if (def->def_kind == DEF_PROGRAM) {
  4819. + for (vp = def->def.pr.versions; vp != NULL;
  4820. + vp = vp->next) {
  4821. + f_print(fout, "%s(void) pmap_unset(%s, %s);\n",
  4822. + space, def->def_name, vp->vers_name);
  4823. + }
  4824. + }
  4825. + }
  4826. +}
  4827. +
  4828. +static void
  4829. +print_err_message(char *space)
  4830. +{
  4831. + if (logflag)
  4832. + f_print(fout, "%ssyslog(LOG_ERR, \"%s\");\n", space, _errbuf);
  4833. + else if (inetdflag || pmflag)
  4834. + f_print(fout, "%s_msgout(\"%s\");\n", space, _errbuf);
  4835. + else
  4836. + f_print(fout, "%sfprintf(stderr, \"%s\");\n", space, _errbuf);
  4837. +}
  4838. +
  4839. +/*
  4840. + * Write the server auxiliary function ( _msgout, timeout)
  4841. + */
  4842. +void
  4843. +write_svc_aux(int nomain)
  4844. +{
  4845. + if (!logflag)
  4846. + write_msg_out();
  4847. + if( !nomain )
  4848. + write_timeout_func();
  4849. +}
  4850. +
  4851. +/*
  4852. + * Write the _msgout function
  4853. + */
  4854. +void
  4855. +write_msg_out(void)
  4856. +{
  4857. + f_print(fout, "\n");
  4858. + f_print(fout, "static\n");
  4859. + if( !Cflag ) {
  4860. + f_print(fout, "void _msgout(msg)\n");
  4861. + f_print(fout, "\tchar *msg;\n");
  4862. + } else {
  4863. + f_print(fout, "void _msgout(char* msg)\n");
  4864. + }
  4865. + f_print(fout, "{\n");
  4866. + f_print(fout, "#ifdef RPC_SVC_FG\n");
  4867. + if (inetdflag || pmflag)
  4868. + f_print(fout, "\tif (_rpcpmstart)\n");
  4869. + f_print(fout, "\t\tsyslog(LOG_ERR, \"%%s\", msg);\n");
  4870. + f_print(fout, "\telse\n");
  4871. + f_print(fout, "\t\t(void) fprintf(stderr, \"%%s\\n\", msg);\n");
  4872. + f_print(fout, "#else\n");
  4873. + f_print(fout, "\tsyslog(LOG_ERR, \"%%s\", msg);\n");
  4874. + f_print(fout, "#endif\n");
  4875. + f_print(fout, "}\n");
  4876. +}
  4877. +
  4878. +/*
  4879. + * Write the timeout function
  4880. + */
  4881. +static void
  4882. +write_timeout_func(void)
  4883. +{
  4884. + if (!timerflag)
  4885. + return;
  4886. + f_print(fout, "\n");
  4887. + f_print(fout, "static void\n");
  4888. + f_print(fout, "closedown()\n");
  4889. + f_print(fout, "{\n");
  4890. + f_print(fout, "\tif (_rpcsvcdirty == 0) {\n");
  4891. + f_print(fout, "\t\tstatic int size;\n");
  4892. + f_print(fout, "\t\tint i, openfd;\n");
  4893. + if (tirpcflag && pmflag) {
  4894. + f_print(fout, "\t\tstruct t_info tinfo;\n\n");
  4895. + f_print(fout, "\t\tif (!t_getinfo(0, &tinfo) && (tinfo.servtype == T_CLTS))\n");
  4896. + } else {
  4897. + f_print(fout, "\n\t\tif (_rpcfdtype == SOCK_DGRAM)\n");
  4898. + }
  4899. + f_print(fout, "\t\t\texit(0);\n");
  4900. + f_print(fout, "\t\tif (size == 0) {\n");
  4901. + if( tirpcflag ) {
  4902. + f_print(fout, "\t\t\tstruct rlimit rl;\n\n");
  4903. + f_print(fout, "\t\t\trl.rlim_max = 0;\n");
  4904. + f_print(fout, "\t\t\tgetrlimit(RLIMIT_NOFILE, &rl);\n");
  4905. + f_print(fout, "\t\t\tif ((size = rl.rlim_max) == 0)\n");
  4906. + f_print(fout, "\t\t\t\treturn;\n");
  4907. + } else {
  4908. + f_print(fout, "\t\t\tsize = getdtablesize();\n");
  4909. + }
  4910. + f_print(fout, "\t\t}\n");
  4911. + f_print(fout, "\t\tfor (i = 0, openfd = 0; i < size && openfd < 2; i++)\n");
  4912. + f_print(fout, "\t\t\tif (FD_ISSET(i, &svc_fdset))\n");
  4913. + f_print(fout, "\t\t\t\topenfd++;\n");
  4914. + f_print(fout, "\t\tif (openfd <= 1)\n");
  4915. + f_print(fout, "\t\t\texit(0);\n");
  4916. + f_print(fout, "\t}\n");
  4917. + f_print(fout, "\t(void) alarm(_RPCSVC_CLOSEDOWN);\n");
  4918. + f_print(fout, "}\n");
  4919. +}
  4920. +
  4921. +/*
  4922. + * Write the most of port monitor support
  4923. + */
  4924. +static void
  4925. +write_pm_most(char *infile, int netflag)
  4926. +{
  4927. + list *l;
  4928. + definition *def;
  4929. + version_list *vp;
  4930. +
  4931. + f_print(fout, "\tif (!ioctl(0, I_LOOK, mname) &&\n");
  4932. + f_print(fout, "\t\t(!strcmp(mname, \"sockmod\") ||");
  4933. + f_print(fout, " !strcmp(mname, \"timod\"))) {\n");
  4934. + f_print(fout, "\t\tchar *netid;\n");
  4935. + if (!netflag) { /* Not included by -n option */
  4936. + f_print(fout, "\t\tstruct netconfig *nconf = NULL;\n");
  4937. + f_print(fout, "\t\tSVCXPRT *%s;\n", TRANSP);
  4938. + }
  4939. + if( timerflag )
  4940. + f_print(fout, "\t\tint pmclose;\n");
  4941. +/* not necessary, defined in /usr/include/stdlib */
  4942. +/* f_print(fout, "\t\textern char *getenv();\n");*/
  4943. + f_print(fout, "\n");
  4944. + f_print(fout, "\t\t_rpcpmstart = 1;\n");
  4945. + if (logflag)
  4946. + open_log_file(infile, "\t\t");
  4947. + f_print(fout, "\t\tif ((netid = getenv(\"NLSPROVIDER\")) == NULL) {\n");
  4948. + sprintf(_errbuf, "cannot get transport name");
  4949. + print_err_message("\t\t\t");
  4950. + f_print(fout, "\t\t} else if ((nconf = getnetconfigent(netid)) == NULL) {\n");
  4951. + sprintf(_errbuf, "cannot get transport info");
  4952. + print_err_message("\t\t\t");
  4953. + f_print(fout, "\t\t}\n");
  4954. + /*
  4955. + * A kludgy support for inetd services. Inetd only works with
  4956. + * sockmod, and RPC works only with timod, hence all this jugglery
  4957. + */
  4958. + f_print(fout, "\t\tif (strcmp(mname, \"sockmod\") == 0) {\n");
  4959. + f_print(fout, "\t\t\tif (ioctl(0, I_POP, 0) || ioctl(0, I_PUSH, \"timod\")) {\n");
  4960. + sprintf(_errbuf, "could not get the right module");
  4961. + print_err_message("\t\t\t\t");
  4962. + f_print(fout, "\t\t\t\texit(1);\n");
  4963. + f_print(fout, "\t\t\t}\n");
  4964. + f_print(fout, "\t\t}\n");
  4965. + if( timerflag )
  4966. + f_print(fout, "\t\tpmclose = (t_getstate(0) != T_DATAXFER);\n");
  4967. + f_print(fout, "\t\tif ((%s = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {\n",
  4968. + TRANSP);
  4969. + sprintf(_errbuf, "cannot create server handle");
  4970. + print_err_message("\t\t\t");
  4971. + f_print(fout, "\t\t\texit(1);\n");
  4972. + f_print(fout, "\t\t}\n");
  4973. + f_print(fout, "\t\tif (nconf)\n");
  4974. + f_print(fout, "\t\t\tfreenetconfigent(nconf);\n");
  4975. + for (l = defined; l != NULL; l = l->next) {
  4976. + def = (definition *) l->val;
  4977. + if (def->def_kind != DEF_PROGRAM) {
  4978. + continue;
  4979. + }
  4980. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  4981. + f_print(fout,
  4982. + "\t\tif (!svc_reg(%s, %s, %s, ",
  4983. + TRANSP, def->def_name, vp->vers_name);
  4984. + pvname(def->def_name, vp->vers_num);
  4985. + f_print(fout, ", 0)) {\n");
  4986. + (void) sprintf(_errbuf, "unable to register (%s, %s).",
  4987. + def->def_name, vp->vers_name);
  4988. + print_err_message("\t\t\t");
  4989. + f_print(fout, "\t\t\texit(1);\n");
  4990. + f_print(fout, "\t\t}\n");
  4991. + }
  4992. + }
  4993. + if (timerflag) {
  4994. + f_print(fout, "\t\tif (pmclose) {\n");
  4995. + f_print(fout, "\t\t\t(void) signal(SIGALRM, %s closedown);\n",
  4996. + Cflag? "(SIG_PF)" : "(void(*)())" );
  4997. + f_print(fout, "\t\t\t(void) alarm(_RPCSVC_CLOSEDOWN);\n");
  4998. + f_print(fout, "\t\t}\n");
  4999. + }
  5000. + f_print(fout, "\t\tsvc_run();\n");
  5001. + f_print(fout, "\t\texit(1);\n");
  5002. + f_print(fout, "\t\t/* NOTREACHED */\n");
  5003. + f_print(fout, "\t}\n");
  5004. +}
  5005. +
  5006. +/*
  5007. + * Support for backgrounding the server if self started.
  5008. + */
  5009. +static void
  5010. +write_rpc_svc_fg(char *infile, char *sp)
  5011. +{
  5012. + f_print(fout, "#ifndef RPC_SVC_FG\n");
  5013. + f_print(fout, "%sint size;\n", sp);
  5014. + if( tirpcflag )
  5015. + f_print(fout, "%sstruct rlimit rl;\n", sp);
  5016. + if (inetdflag)
  5017. + f_print(fout, "%sint pid, i;\n\n", sp);
  5018. + f_print(fout, "%spid = fork();\n", sp);
  5019. + f_print(fout, "%sif (pid < 0) {\n", sp);
  5020. + f_print(fout, "%s\tperror(\"cannot fork\");\n", sp);
  5021. + f_print(fout, "%s\texit(1);\n", sp);
  5022. + f_print(fout, "%s}\n", sp);
  5023. + f_print(fout, "%sif (pid)\n", sp);
  5024. + f_print(fout, "%s\texit(0);\n", sp);
  5025. + /* get number of file descriptors */
  5026. + if( tirpcflag ) {
  5027. + f_print(fout, "%srl.rlim_max = 0;\n", sp);
  5028. + f_print(fout, "%sgetrlimit(RLIMIT_NOFILE, &rl);\n", sp);
  5029. + f_print(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp);
  5030. + f_print(fout, "%s\texit(1);\n", sp);
  5031. + } else {
  5032. + f_print(fout, "%ssize = getdtablesize();\n", sp);
  5033. + }
  5034. +
  5035. + f_print(fout, "%sfor (i = 0; i < size; i++)\n", sp);
  5036. + f_print(fout, "%s\t(void) close(i);\n", sp);
  5037. + /* Redirect stderr and stdout to console */
  5038. + f_print(fout, "%si = open(\"/dev/console\", 2);\n", sp);
  5039. + f_print(fout, "%s(void) dup2(i, 1);\n", sp);
  5040. + f_print(fout, "%s(void) dup2(i, 2);\n", sp);
  5041. + /* This removes control of the controlling terminal */
  5042. + if( tirpcflag )
  5043. + f_print(fout, "%ssetsid();\n", sp);
  5044. + else {
  5045. + f_print(fout, "%si = open(\"/dev/tty\", 2);\n", sp);
  5046. + f_print(fout, "%sif (i >= 0) {\n", sp);
  5047. + f_print(fout, "%s\t(void) ioctl(i, TIOCNOTTY, (char *)NULL);\n", sp);;
  5048. + f_print(fout, "%s\t(void) close(i);\n", sp);
  5049. + f_print(fout, "%s}\n", sp);
  5050. + }
  5051. + if (!logflag)
  5052. + open_log_file(infile, sp);
  5053. + f_print(fout, "#endif\n");
  5054. + if (logflag)
  5055. + open_log_file(infile, sp);
  5056. +}
  5057. +
  5058. +static void
  5059. +open_log_file(char *infile, char *sp)
  5060. +{
  5061. + char *s;
  5062. +
  5063. + s = strrchr(infile, '.');
  5064. + if (s)
  5065. + *s = '\0';
  5066. + f_print(fout,"%sopenlog(\"%s\", LOG_PID, LOG_DAEMON);\n", sp, infile);
  5067. + if (s)
  5068. + *s = '.';
  5069. +}
  5070. +
  5071. +
  5072. +
  5073. +
  5074. +/*
  5075. + * write a registration for the given transport for Inetd
  5076. + */
  5077. +void
  5078. +write_inetd_register(char *transp)
  5079. +{
  5080. + list *l;
  5081. + definition *def;
  5082. + version_list *vp;
  5083. + char *sp;
  5084. + int isudp;
  5085. + char tmpbuf[32];
  5086. +
  5087. + if (inetdflag)
  5088. + sp = "\t";
  5089. + else
  5090. + sp = "";
  5091. + if (streq(transp, "udp"))
  5092. + isudp = 1;
  5093. + else
  5094. + isudp = 0;
  5095. + f_print(fout, "\n");
  5096. + if (inetdflag) {
  5097. + f_print(fout, "\tif ((_rpcfdtype == 0) || (_rpcfdtype == %s)) {\n",
  5098. + isudp ? "SOCK_DGRAM" : "SOCK_STREAM");
  5099. + }
  5100. + f_print(fout, "%s\t%s = svc%s_create(%s",
  5101. + sp, TRANSP, transp, inetdflag? "sock": "RPC_ANYSOCK");
  5102. + if (!isudp)
  5103. + f_print(fout, ", 0, 0");
  5104. + f_print(fout, ");\n");
  5105. + f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
  5106. + (void) sprintf(_errbuf, "cannot create %s service.", transp);
  5107. + (void) sprintf(tmpbuf, "%s\t\t", sp);
  5108. + print_err_message(tmpbuf);
  5109. + f_print(fout, "%s\t\texit(1);\n", sp);
  5110. + f_print(fout, "%s\t}\n", sp);
  5111. +
  5112. + if (inetdflag) {
  5113. + f_print(fout, "%s\tif (!_rpcpmstart)\n\t", sp);
  5114. + f_print(fout, "%s\tproto = IPPROTO_%s;\n",
  5115. + sp, isudp ? "UDP": "TCP");
  5116. + }
  5117. + for (l = defined; l != NULL; l = l->next) {
  5118. + def = (definition *) l->val;
  5119. + if (def->def_kind != DEF_PROGRAM) {
  5120. + continue;
  5121. + }
  5122. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  5123. + f_print(fout, "%s\tif (!svc_register(%s, %s, %s, ",
  5124. + sp, TRANSP, def->def_name, vp->vers_name);
  5125. + pvname(def->def_name, vp->vers_num);
  5126. + if (inetdflag)
  5127. + f_print(fout, ", proto)) {\n");
  5128. + else
  5129. + f_print(fout, ", IPPROTO_%s)) {\n",
  5130. + isudp ? "UDP": "TCP");
  5131. + (void) sprintf(_errbuf, "unable to register (%s, %s, %s).",
  5132. + def->def_name, vp->vers_name, transp);
  5133. + print_err_message(tmpbuf);
  5134. + f_print(fout, "%s\t\texit(1);\n", sp);
  5135. + f_print(fout, "%s\t}\n", sp);
  5136. + }
  5137. + }
  5138. + if (inetdflag)
  5139. + f_print(fout, "\t}\n");
  5140. +}
  5141. diff --git a/rpcgen/rpc_tblout.c b/rpcgen/rpc_tblout.c
  5142. new file mode 100644
  5143. index 0000000..ae002f7
  5144. --- /dev/null
  5145. +++ b/rpcgen/rpc_tblout.c
  5146. @@ -0,0 +1,165 @@
  5147. +/*
  5148. + * Copyright (c) 2009, Sun Microsystems, Inc.
  5149. + * All rights reserved.
  5150. + *
  5151. + * Redistribution and use in source and binary forms, with or without
  5152. + * modification, are permitted provided that the following conditions are met:
  5153. + * - Redistributions of source code must retain the above copyright notice,
  5154. + * this list of conditions and the following disclaimer.
  5155. + * - Redistributions in binary form must reproduce the above copyright notice,
  5156. + * this list of conditions and the following disclaimer in the documentation
  5157. + * and/or other materials provided with the distribution.
  5158. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  5159. + * contributors may be used to endorse or promote products derived
  5160. + * from this software without specific prior written permission.
  5161. + *
  5162. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  5163. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  5164. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  5165. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  5166. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  5167. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  5168. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  5169. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  5170. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  5171. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  5172. + * POSSIBILITY OF SUCH DAMAGE.
  5173. + */
  5174. +
  5175. +#if 0
  5176. +static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
  5177. +#endif
  5178. +
  5179. +/*
  5180. + * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
  5181. + */
  5182. +#include <stdio.h>
  5183. +#include <string.h>
  5184. +#include "rpc_parse.h"
  5185. +#include "rpc_util.h"
  5186. +#include "rpc_output.h"
  5187. +
  5188. +static void write_table(definition *def);
  5189. +static void printit(char *prefix, char *type);
  5190. +
  5191. +#define TABSIZE 8
  5192. +#define TABCOUNT 5
  5193. +#define TABSTOP (TABSIZE*TABCOUNT)
  5194. +
  5195. +static char tabstr[TABCOUNT+1] = "\t\t\t\t\t";
  5196. +
  5197. +static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
  5198. +static char tbl_end[] = "};\n";
  5199. +
  5200. +static char null_entry[] = "\n\t(char *(*)())0,\n\
  5201. + \t(xdrproc_t) xdr_void,\t\t\t0,\n\
  5202. + \t(xdrproc_t) xdr_void,\t\t\t0,\n";
  5203. +
  5204. +
  5205. +static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
  5206. +
  5207. +void
  5208. +write_tables(void)
  5209. +{
  5210. + list *l;
  5211. + definition *def;
  5212. +
  5213. + f_print(fout, "\n");
  5214. + for (l = defined; l != NULL; l = l->next) {
  5215. + def = (definition *) l->val;
  5216. + if (def->def_kind == DEF_PROGRAM) {
  5217. + write_table(def);
  5218. + }
  5219. + }
  5220. +}
  5221. +
  5222. +static void
  5223. +write_table(definition *def)
  5224. +{
  5225. + version_list *vp;
  5226. + proc_list *proc;
  5227. + int current;
  5228. + int expected;
  5229. + char progvers[100];
  5230. + int warning;
  5231. +
  5232. + for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  5233. + warning = 0;
  5234. + s_print(progvers, "%s_%s",
  5235. + locase(def->def_name), vp->vers_num);
  5236. + /* print the table header */
  5237. + f_print(fout, tbl_hdr, progvers);
  5238. +
  5239. + if (nullproc(vp->procs)) {
  5240. + expected = 0;
  5241. + } else {
  5242. + expected = 1;
  5243. + f_print(fout, null_entry);
  5244. + }
  5245. + for (proc = vp->procs; proc != NULL; proc = proc->next) {
  5246. + current = atoi(proc->proc_num);
  5247. + if (current != expected++) {
  5248. + f_print(fout,
  5249. + "\n/*\n * WARNING: table out of order\n */\n");
  5250. + if (warning == 0) {
  5251. + f_print(stderr,
  5252. + "WARNING %s table is out of order\n",
  5253. + progvers);
  5254. + warning = 1;
  5255. + nonfatalerrors = 1;
  5256. + }
  5257. + expected = current + 1;
  5258. + }
  5259. + f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
  5260. +
  5261. + /* routine to invoke */
  5262. + if( Cflag && !newstyle )
  5263. + pvname_svc(proc->proc_name, vp->vers_num);
  5264. + else {
  5265. + if( newstyle )
  5266. + f_print( fout, "_"); /* calls internal func */
  5267. + pvname(proc->proc_name, vp->vers_num);
  5268. + }
  5269. + f_print(fout, "),\n");
  5270. +
  5271. + /* argument info */
  5272. + if( proc->arg_num > 1 )
  5273. + printit((char*) NULL, proc->args.argname );
  5274. + else
  5275. + /* do we have to do something special for newstyle */
  5276. + printit( proc->args.decls->decl.prefix,
  5277. + proc->args.decls->decl.type );
  5278. + /* result info */
  5279. + printit(proc->res_prefix, proc->res_type);
  5280. + }
  5281. +
  5282. + /* print the table trailer */
  5283. + f_print(fout, tbl_end);
  5284. + f_print(fout, tbl_nproc, progvers, progvers, progvers);
  5285. + }
  5286. +}
  5287. +
  5288. +static void
  5289. +printit(char *prefix, char *type)
  5290. +{
  5291. + int len;
  5292. + int tabs;
  5293. +
  5294. +
  5295. + len = fprintf(fout, "\txdr_%s,", stringfix(type));
  5296. + /* account for leading tab expansion */
  5297. + len += TABSIZE - 1;
  5298. + /* round up to tabs required */
  5299. + tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
  5300. + f_print(fout, "%s", &tabstr[TABCOUNT-tabs]);
  5301. +
  5302. + if (streq(type, "void")) {
  5303. + f_print(fout, "0");
  5304. + } else {
  5305. + f_print(fout, "sizeof ( ");
  5306. + /* XXX: should "follow" be 1 ??? */
  5307. + ptype(prefix, type, 0);
  5308. + f_print(fout, ")");
  5309. + }
  5310. + f_print(fout, ",\n");
  5311. +}
  5312. diff --git a/rpcgen/rpc_util.c b/rpcgen/rpc_util.c
  5313. new file mode 100644
  5314. index 0000000..b67be57
  5315. --- /dev/null
  5316. +++ b/rpcgen/rpc_util.c
  5317. @@ -0,0 +1,479 @@
  5318. +/*
  5319. + * Copyright (c) 2009, Sun Microsystems, Inc.
  5320. + * All rights reserved.
  5321. + *
  5322. + * Redistribution and use in source and binary forms, with or without
  5323. + * modification, are permitted provided that the following conditions are met:
  5324. + * - Redistributions of source code must retain the above copyright notice,
  5325. + * this list of conditions and the following disclaimer.
  5326. + * - Redistributions in binary form must reproduce the above copyright notice,
  5327. + * this list of conditions and the following disclaimer in the documentation
  5328. + * and/or other materials provided with the distribution.
  5329. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  5330. + * contributors may be used to endorse or promote products derived
  5331. + * from this software without specific prior written permission.
  5332. + *
  5333. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  5334. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  5335. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  5336. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  5337. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  5338. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  5339. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  5340. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  5341. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  5342. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  5343. + * POSSIBILITY OF SUCH DAMAGE.
  5344. + */
  5345. +
  5346. +#if 0
  5347. +static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI";
  5348. +#endif
  5349. +
  5350. +/*
  5351. + * rpc_util.c, Utility routines for the RPC protocol compiler
  5352. + */
  5353. +#include <stdio.h>
  5354. +#include <memory.h>
  5355. +#include <ctype.h>
  5356. +#include <unistd.h>
  5357. +#include "rpc_scan.h"
  5358. +#include "rpc_parse.h"
  5359. +#include "rpc_util.h"
  5360. +
  5361. +static void printwhere(void);
  5362. +
  5363. +
  5364. +#define ARGEXT "argument"
  5365. +
  5366. +char curline[MAXLINESIZE]; /* current read line */
  5367. +char *where = curline; /* current point in line */
  5368. +int linenum = 0; /* current line number */
  5369. +
  5370. +char *infilename; /* input filename */
  5371. +
  5372. +#define NFILES 7
  5373. +char *outfiles[NFILES]; /* output file names */
  5374. +int nfiles;
  5375. +
  5376. +FILE *fout; /* file pointer of current output */
  5377. +FILE *fin; /* file pointer of current input */
  5378. +
  5379. +list *defined; /* list of defined things */
  5380. +
  5381. +/*
  5382. + * Reinitialize the world
  5383. + */
  5384. +void
  5385. +reinitialize(void)
  5386. +{
  5387. + memset(curline, 0, MAXLINESIZE);
  5388. + where = curline;
  5389. + linenum = 0;
  5390. + defined = NULL;
  5391. +}
  5392. +
  5393. +/*
  5394. + * string equality
  5395. + */
  5396. +int
  5397. +streq(char *a, char *b)
  5398. +{
  5399. + return (strcmp(a, b) == 0);
  5400. +}
  5401. +
  5402. +/*
  5403. + * find a value in a list
  5404. + */
  5405. +definition *
  5406. +findval(list *lst, char *val, int (*cmp)(definition *, char *))
  5407. +{
  5408. +
  5409. + for (; lst != NULL; lst = lst->next) {
  5410. + if ((*cmp) (lst->val, val)) {
  5411. + return (lst->val);
  5412. + }
  5413. + }
  5414. + return (NULL);
  5415. +}
  5416. +
  5417. +/*
  5418. + * store a value in a list
  5419. + */
  5420. +void
  5421. +storeval(lstp, val)
  5422. + list **lstp;
  5423. + definition *val;
  5424. +{
  5425. + list **l;
  5426. + list *lst;
  5427. +
  5428. +
  5429. + for (l = lstp; *l != NULL; l = (list **) & (*l)->next);
  5430. + lst = ALLOC(list);
  5431. + lst->val = val;
  5432. + lst->next = NULL;
  5433. + *l = lst;
  5434. +}
  5435. +
  5436. +static int
  5437. +findit(definition *def, char *type)
  5438. +{
  5439. + return (streq(def->def_name, type));
  5440. +}
  5441. +
  5442. +static char *
  5443. +fixit(char *type, char *orig)
  5444. +{
  5445. + definition *def;
  5446. +
  5447. + def = (definition *) FINDVAL(defined, type, findit);
  5448. + if (def == NULL || def->def_kind != DEF_TYPEDEF) {
  5449. + return (orig);
  5450. + }
  5451. + switch (def->def.ty.rel) {
  5452. + case REL_VECTOR:
  5453. + return (def->def.ty.old_type);
  5454. + case REL_ALIAS:
  5455. + return (fixit(def->def.ty.old_type, orig));
  5456. + default:
  5457. + return (orig);
  5458. + }
  5459. +}
  5460. +
  5461. +char *
  5462. +fixtype(char *type)
  5463. +{
  5464. + return (fixit(type, type));
  5465. +}
  5466. +
  5467. +char *
  5468. +stringfix(char *type)
  5469. +{
  5470. + if (streq(type, "string")) {
  5471. + return ("wrapstring");
  5472. + } else {
  5473. + return (type);
  5474. + }
  5475. +}
  5476. +
  5477. +void
  5478. +ptype(char *prefix, char *type, int follow)
  5479. +{
  5480. + if (prefix != NULL) {
  5481. + if (streq(prefix, "enum")) {
  5482. + f_print(fout, "enum ");
  5483. + } else {
  5484. + f_print(fout, "struct ");
  5485. + }
  5486. + }
  5487. + if (streq(type, "bool")) {
  5488. + f_print(fout, "bool_t ");
  5489. + } else if (streq(type, "string")) {
  5490. + f_print(fout, "char *");
  5491. + } else {
  5492. + f_print(fout, "%s ", follow ? fixtype(type) : type);
  5493. + }
  5494. +}
  5495. +
  5496. +static int
  5497. +typedefed(definition *def, char *type)
  5498. +{
  5499. + if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) {
  5500. + return (0);
  5501. + } else {
  5502. + return (streq(def->def_name, type));
  5503. + }
  5504. +}
  5505. +
  5506. +int
  5507. +isvectordef(char *type, relation rel)
  5508. +{
  5509. + definition *def;
  5510. +
  5511. + for (;;) {
  5512. + switch (rel) {
  5513. + case REL_VECTOR:
  5514. + return (!streq(type, "string"));
  5515. + case REL_ARRAY:
  5516. + return (0);
  5517. + case REL_POINTER:
  5518. + return (0);
  5519. + case REL_ALIAS:
  5520. + def = (definition *) FINDVAL(defined, type, typedefed);
  5521. + if (def == NULL) {
  5522. + return (0);
  5523. + }
  5524. + type = def->def.ty.old_type;
  5525. + rel = def->def.ty.rel;
  5526. + }
  5527. + }
  5528. +}
  5529. +
  5530. +char *
  5531. +locase(char *str)
  5532. +{
  5533. + char c;
  5534. + static char buf[100];
  5535. + char *p = buf;
  5536. +
  5537. + while ((c = *str++) != '\0') {
  5538. + *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
  5539. + }
  5540. + *p = 0;
  5541. + return (buf);
  5542. +}
  5543. +
  5544. +void
  5545. +pvname_svc(char *pname, char *vnum)
  5546. +{
  5547. + f_print(fout, "%s_%s_svc", locase(pname), vnum);
  5548. +}
  5549. +
  5550. +void
  5551. +pvname(char *pname, char *vnum)
  5552. +{
  5553. + f_print(fout, "%s_%s", locase(pname), vnum);
  5554. +}
  5555. +
  5556. +/*
  5557. + * print a useful (?) error message, and then die
  5558. + */
  5559. +void
  5560. +error(char *msg)
  5561. +{
  5562. + printwhere();
  5563. + f_print(stderr, "%s, line %d: ", infilename, linenum);
  5564. + f_print(stderr, "%s\n", msg);
  5565. + crash();
  5566. +}
  5567. +
  5568. +/*
  5569. + * Something went wrong, unlink any files that we may have created and then
  5570. + * die.
  5571. + */
  5572. +void
  5573. +crash(void)
  5574. +{
  5575. + int i;
  5576. +
  5577. + for (i = 0; i < nfiles; i++) {
  5578. + (void) unlink(outfiles[i]);
  5579. + }
  5580. + exit(1);
  5581. +}
  5582. +
  5583. +void
  5584. +record_open(char *file)
  5585. +{
  5586. + if (nfiles < NFILES) {
  5587. + outfiles[nfiles++] = file;
  5588. + } else {
  5589. + f_print(stderr, "too many files!\n");
  5590. + crash();
  5591. + }
  5592. +}
  5593. +
  5594. +static char expectbuf[100];
  5595. +static char *toktostr();
  5596. +
  5597. +/*
  5598. + * error, token encountered was not the expected one
  5599. + */
  5600. +void
  5601. +expected1(exp1)
  5602. + tok_kind exp1;
  5603. +{
  5604. + s_print(expectbuf, "expected '%s'",
  5605. + toktostr(exp1));
  5606. + error(expectbuf);
  5607. +}
  5608. +
  5609. +/*
  5610. + * error, token encountered was not one of two expected ones
  5611. + */
  5612. +void
  5613. +expected2(exp1, exp2)
  5614. + tok_kind exp1, exp2;
  5615. +{
  5616. + s_print(expectbuf, "expected '%s' or '%s'",
  5617. + toktostr(exp1),
  5618. + toktostr(exp2));
  5619. + error(expectbuf);
  5620. +}
  5621. +
  5622. +/*
  5623. + * error, token encountered was not one of 3 expected ones
  5624. + */
  5625. +void
  5626. +expected3(exp1, exp2, exp3)
  5627. + tok_kind exp1, exp2, exp3;
  5628. +{
  5629. + s_print(expectbuf, "expected '%s', '%s' or '%s'",
  5630. + toktostr(exp1),
  5631. + toktostr(exp2),
  5632. + toktostr(exp3));
  5633. + error(expectbuf);
  5634. +}
  5635. +
  5636. +void
  5637. +tabify(f, tab)
  5638. + FILE *f;
  5639. + int tab;
  5640. +{
  5641. + while (tab--) {
  5642. + (void) fputc('\t', f);
  5643. + }
  5644. +}
  5645. +
  5646. +
  5647. +static token tokstrings[] = {
  5648. + {TOK_IDENT, "identifier"},
  5649. + {TOK_CONST, "const"},
  5650. + {TOK_RPAREN, ")"},
  5651. + {TOK_LPAREN, "("},
  5652. + {TOK_RBRACE, "}"},
  5653. + {TOK_LBRACE, "{"},
  5654. + {TOK_LBRACKET, "["},
  5655. + {TOK_RBRACKET, "]"},
  5656. + {TOK_STAR, "*"},
  5657. + {TOK_COMMA, ","},
  5658. + {TOK_EQUAL, "="},
  5659. + {TOK_COLON, ":"},
  5660. + {TOK_SEMICOLON, ";"},
  5661. + {TOK_UNION, "union"},
  5662. + {TOK_STRUCT, "struct"},
  5663. + {TOK_SWITCH, "switch"},
  5664. + {TOK_CASE, "case"},
  5665. + {TOK_DEFAULT, "default"},
  5666. + {TOK_ENUM, "enum"},
  5667. + {TOK_TYPEDEF, "typedef"},
  5668. + {TOK_INT, "int"},
  5669. + {TOK_SHORT, "short"},
  5670. + {TOK_INT32, "int32"},
  5671. + {TOK_UNSIGNED, "unsigned"},
  5672. + {TOK_DOUBLE, "double"},
  5673. + {TOK_FLOAT, "float"},
  5674. + {TOK_CHAR, "char"},
  5675. + {TOK_STRING, "string"},
  5676. + {TOK_OPAQUE, "opaque"},
  5677. + {TOK_BOOL, "bool"},
  5678. + {TOK_VOID, "void"},
  5679. + {TOK_PROGRAM, "program"},
  5680. + {TOK_VERSION, "version"},
  5681. + {TOK_EOF, "??????"}
  5682. +};
  5683. +
  5684. +static char *
  5685. +toktostr(kind)
  5686. + tok_kind kind;
  5687. +{
  5688. + token *sp;
  5689. +
  5690. + for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++);
  5691. + return (sp->str);
  5692. +}
  5693. +
  5694. +static void
  5695. +printbuf(void)
  5696. +{
  5697. + char c;
  5698. + int i;
  5699. + int cnt;
  5700. +
  5701. +# define TABSIZE 4
  5702. +
  5703. + for (i = 0; (c = curline[i]) != '\0'; i++) {
  5704. + if (c == '\t') {
  5705. + cnt = 8 - (i % TABSIZE);
  5706. + c = ' ';
  5707. + } else {
  5708. + cnt = 1;
  5709. + }
  5710. + while (cnt--) {
  5711. + (void) fputc(c, stderr);
  5712. + }
  5713. + }
  5714. +}
  5715. +
  5716. +static void
  5717. +printwhere(void)
  5718. +{
  5719. + int i;
  5720. + char c;
  5721. + int cnt;
  5722. +
  5723. + printbuf();
  5724. + for (i = 0; i < where - curline; i++) {
  5725. + c = curline[i];
  5726. + if (c == '\t') {
  5727. + cnt = 8 - (i % TABSIZE);
  5728. + } else {
  5729. + cnt = 1;
  5730. + }
  5731. + while (cnt--) {
  5732. + (void) fputc('^', stderr);
  5733. + }
  5734. + }
  5735. + (void) fputc('\n', stderr);
  5736. +}
  5737. +
  5738. +char *
  5739. +make_argname(char *pname, char *vname)
  5740. +{
  5741. + char *name;
  5742. +
  5743. + name = malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3);
  5744. + if (!name) {
  5745. + fprintf(stderr, "failed in malloc");
  5746. + exit(1);
  5747. + }
  5748. + sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT);
  5749. + return(name);
  5750. +}
  5751. +
  5752. +bas_type *typ_list_h;
  5753. +bas_type *typ_list_t;
  5754. +
  5755. +void
  5756. +add_type(int len, char *type)
  5757. +{
  5758. + bas_type *ptr;
  5759. +
  5760. +
  5761. + if ((ptr = (bas_type *) malloc(sizeof(bas_type))) == (bas_type *) NULL) {
  5762. + fprintf(stderr, "failed in malloc");
  5763. + exit(1);
  5764. + }
  5765. + ptr->name = type;
  5766. + ptr->length = len;
  5767. + ptr->next = NULL;
  5768. + if (typ_list_t == NULL) {
  5769. +
  5770. + typ_list_t = ptr;
  5771. + typ_list_h = ptr;
  5772. + } else {
  5773. +
  5774. + typ_list_t->next = ptr;
  5775. + typ_list_t = ptr;
  5776. + }
  5777. +}
  5778. +
  5779. +
  5780. +bas_type *
  5781. +find_type(char *type)
  5782. +{
  5783. + bas_type *ptr;
  5784. +
  5785. + ptr = typ_list_h;
  5786. +
  5787. +
  5788. + while (ptr != NULL) {
  5789. + if (strcmp(ptr->name, type) == 0)
  5790. + return (ptr);
  5791. + else
  5792. + ptr = ptr->next;
  5793. + };
  5794. + return (NULL);
  5795. +}
  5796. +
  5797. diff --git a/rpcgen/rpc_util.h b/rpcgen/rpc_util.h
  5798. new file mode 100644
  5799. index 0000000..fa115be
  5800. --- /dev/null
  5801. +++ b/rpcgen/rpc_util.h
  5802. @@ -0,0 +1,166 @@
  5803. +/*
  5804. + * Copyright (c) 2009, Sun Microsystems, Inc.
  5805. + * All rights reserved.
  5806. + *
  5807. + * Redistribution and use in source and binary forms, with or without
  5808. + * modification, are permitted provided that the following conditions are met:
  5809. + * - Redistributions of source code must retain the above copyright notice,
  5810. + * this list of conditions and the following disclaimer.
  5811. + * - Redistributions in binary form must reproduce the above copyright notice,
  5812. + * this list of conditions and the following disclaimer in the documentation
  5813. + * and/or other materials provided with the distribution.
  5814. + * - Neither the name of Sun Microsystems, Inc. nor the names of its
  5815. + * contributors may be used to endorse or promote products derived
  5816. + * from this software without specific prior written permission.
  5817. + *
  5818. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  5819. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  5820. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  5821. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  5822. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  5823. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  5824. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  5825. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  5826. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  5827. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  5828. + * POSSIBILITY OF SUCH DAMAGE.
  5829. + */
  5830. +
  5831. +/* @(#)rpc_util.h 1.5 90/08/29 (C) 1987 SMI */
  5832. +
  5833. +/*
  5834. + * rpc_util.h, Useful definitions for the RPC protocol compiler
  5835. + */
  5836. +
  5837. +#include <stdlib.h>
  5838. +
  5839. +#define alloc(size) malloc((unsigned)(size))
  5840. +#define ALLOC(object) (object *) malloc(sizeof(object))
  5841. +
  5842. +#define s_print (void) sprintf
  5843. +#define f_print (void) fprintf
  5844. +
  5845. +struct list {
  5846. + definition *val;
  5847. + struct list *next;
  5848. +};
  5849. +typedef struct list list;
  5850. +
  5851. +#define PUT 1
  5852. +#define GET 2
  5853. +
  5854. +/*
  5855. + * Global variables
  5856. + */
  5857. +#define MAXLINESIZE 1024
  5858. +extern char curline[MAXLINESIZE];
  5859. +extern char *where;
  5860. +extern int linenum;
  5861. +
  5862. +extern char *infilename;
  5863. +extern FILE *fout;
  5864. +extern FILE *fin;
  5865. +
  5866. +extern list *defined;
  5867. +
  5868. +
  5869. +extern bas_type *typ_list_h;
  5870. +extern bas_type *typ_list_t;
  5871. +
  5872. +/*
  5873. + * All the option flags
  5874. + */
  5875. +extern int inetdflag;
  5876. +extern int pmflag;
  5877. +extern int tblflag;
  5878. +extern int logflag;
  5879. +extern int newstyle;
  5880. +extern int Cflag; /* C++ flag */
  5881. +extern int tirpcflag; /* flag for generating tirpc code */
  5882. +extern int Inline; /* if this is 0, then do not generate inline code */
  5883. +
  5884. +/*
  5885. + * Other flags related with inetd jumpstart.
  5886. + */
  5887. +extern int indefinitewait;
  5888. +extern int exitnow;
  5889. +extern int timerflag;
  5890. +
  5891. +extern int nonfatalerrors;
  5892. +
  5893. +/*
  5894. + * rpc_util routines
  5895. + */
  5896. +void storeval();
  5897. +
  5898. +#define STOREVAL(list,item) \
  5899. + storeval(list,item)
  5900. +
  5901. +definition *findval();
  5902. +
  5903. +#define FINDVAL(list,item,finder) \
  5904. + findval(list, item, finder)
  5905. +
  5906. +
  5907. +/*
  5908. + * rpc_cout routines
  5909. + */
  5910. +void cprint(void);
  5911. +void emit(definition *);
  5912. +
  5913. +/*
  5914. + * rpc_hout routines
  5915. + */
  5916. +void print_datadef(definition *);
  5917. +void print_funcdef(definition *);
  5918. +
  5919. +/*
  5920. + * rpc_svcout routines
  5921. + */
  5922. +void write_most(char *, int, int);
  5923. +void write_register(void);
  5924. +void write_netid_register(char *);
  5925. +void write_nettype_register(char *);
  5926. +void write_inetd_register(char *);
  5927. +void write_rest(void);
  5928. +void write_programs(char *);
  5929. +void write_svc_aux(int);
  5930. +
  5931. +/*
  5932. + * rpc_clntout routines
  5933. + */
  5934. +void write_stubs(void);
  5935. +void printarglist(proc_list *, char *, char *);
  5936. +
  5937. +/*
  5938. + * rpc_tblout routines
  5939. + */
  5940. +void write_tables(void);
  5941. +
  5942. +/*
  5943. + * rpc_util
  5944. + */
  5945. +void pvname_svc(char *, char *);
  5946. +void pvname(char *, char *);
  5947. +void ptype(char *, char *, int);
  5948. +char * make_argname(char *, char *);
  5949. +void add_type(int, char *);
  5950. +void reinitialize(void);
  5951. +void crash(void);
  5952. +void error(char *);
  5953. +char *fixtype(char *);
  5954. +char *stringfix(char *);
  5955. +char *locase(char *);
  5956. +int isvectordef(char *, relation);
  5957. +int streq(char *, char *);
  5958. +void tabify(FILE *, int);
  5959. +void record_open(char *);
  5960. +bas_type *find_type(char *type);
  5961. +
  5962. +/*
  5963. + * rpc_sample
  5964. + */
  5965. +void write_sample_svc(definition *);
  5966. +int write_sample_clnt(definition *);
  5967. +void write_sample_clnt_main(void);
  5968. +void add_sample_msg(void);
  5969. diff --git a/rpcgen/rpcgen.1 b/rpcgen/rpcgen.1
  5970. new file mode 100644
  5971. index 0000000..89df7ed
  5972. --- /dev/null
  5973. +++ b/rpcgen/rpcgen.1
  5974. @@ -0,0 +1,521 @@
  5975. +.\" @(#)rpcgen.1 1.35 93/06/02 SMI
  5976. +.\" $FreeBSD: src/usr.bin/rpcgen/rpcgen.1,v 1.12.2.4 2002/06/21 15:28:50 charnier Exp $
  5977. +.\" Copyright 1985-1993 Sun Microsystems, Inc.
  5978. +.Dd March 28, 1993
  5979. +.Dt RPCGEN 1
  5980. +.Os
  5981. +.Sh NAME
  5982. +.Nm rpcgen
  5983. +.Nd an RPC protocol compiler
  5984. +.Sh SYNOPSIS
  5985. +.Nm
  5986. +.Ar infile
  5987. +.Nm
  5988. +.Op Fl a
  5989. +.Op Fl b
  5990. +.Op Fl C
  5991. +.Oo
  5992. +.Fl D Ns Ar name Ns Op Ar =value
  5993. +.Oc
  5994. +.Op Fl i Ar size
  5995. +.Op Fl I Op Fl K Ar seconds
  5996. +.Op Fl L
  5997. +.Op Fl M
  5998. +.Op Fl N
  5999. +.Op Fl T
  6000. +.Op Fl Y Ar pathname
  6001. +.Ar infile
  6002. +.Nm
  6003. +.Oo
  6004. +.Fl c |
  6005. +.Fl h |
  6006. +.Fl l |
  6007. +.Fl m |
  6008. +.Fl t |
  6009. +.Fl \&Sc |
  6010. +.Fl \&Ss |
  6011. +.Fl \&Sm
  6012. +.Oc
  6013. +.Op Fl o Ar outfile
  6014. +.Op Ar infile
  6015. +.Nm
  6016. +.Op Fl s Ar nettype
  6017. +.Op Fl o Ar outfile
  6018. +.Op Ar infile
  6019. +.Nm
  6020. +.Op Fl n Ar netid
  6021. +.Op Fl o Ar outfile
  6022. +.Op Ar infile
  6023. +.\" .SH AVAILABILITY
  6024. +.\" .LP
  6025. +.\" SUNWcsu
  6026. +.Sh DESCRIPTION
  6027. +The
  6028. +.Nm
  6029. +utility is a tool that generates C code to implement an
  6030. +.Tn RPC
  6031. +protocol.
  6032. +The input to
  6033. +.Nm
  6034. +is a language similar to C known as
  6035. +.Tn RPC
  6036. +Language (Remote Procedure Call Language).
  6037. +.Pp
  6038. +The
  6039. +.Nm
  6040. +utility is normally used as in the first synopsis where
  6041. +it takes an input file and generates three output files.
  6042. +If the
  6043. +.Ar infile
  6044. +is named
  6045. +.Pa proto.x ,
  6046. +then
  6047. +.Nm
  6048. +generates a header in
  6049. +.Pa proto.h ,
  6050. +XDR routines in
  6051. +.Pa proto_xdr.c ,
  6052. +server-side stubs in
  6053. +.Pa proto_svc.c ,
  6054. +and client-side stubs in
  6055. +.Pa proto_clnt.c .
  6056. +With the
  6057. +.Fl T
  6058. +option,
  6059. +it also generates the
  6060. +.Tn RPC
  6061. +dispatch table in
  6062. +.Pa proto_tbl.i .
  6063. +.Pp
  6064. +The
  6065. +.Nm
  6066. +utility can also generate sample client and server files
  6067. +that can be customized to suit a particular application.
  6068. +The
  6069. +.Fl \&Sc ,
  6070. +.Fl \&Ss
  6071. +and
  6072. +.Fl \&Sm
  6073. +options generate sample client, server and makefile, respectively.
  6074. +The
  6075. +.Fl a
  6076. +option generates all files, including sample files.
  6077. +If the
  6078. +.Ar infile
  6079. +is
  6080. +.Pa proto.x ,
  6081. +then the client side sample file is written to
  6082. +.Pa proto_client.c ,
  6083. +the server side sample file to
  6084. +.Pa proto_server.c
  6085. +and the sample makefile to
  6086. +.Pa makefile.proto .
  6087. +.Pp
  6088. +The server created can be started both by the port monitors
  6089. +(for example,
  6090. +.Xr inetd 8 )
  6091. +or by itself.
  6092. +When it is started by a port monitor,
  6093. +it creates servers only for the transport for which
  6094. +the file descriptor
  6095. +.Em 0
  6096. +was passed.
  6097. +The name of the transport must be specified
  6098. +by setting up the environment variable
  6099. +.Ev PM_TRANSPORT .
  6100. +When the server generated by
  6101. +.Nm
  6102. +is executed,
  6103. +it creates server handles for all the transports
  6104. +specified in
  6105. +.Ev NETPATH
  6106. +environment variable,
  6107. +or if it is unset,
  6108. +it creates server handles for all the visible transports from
  6109. +.Pa /etc/netconfig
  6110. +file.
  6111. +Note:
  6112. +the transports are chosen at run time and not at compile time.
  6113. +When the server is self-started,
  6114. +it backgrounds itself by default.
  6115. +A special define symbol
  6116. +.Em RPC_SVC_FG
  6117. +can be used to run the server process in foreground.
  6118. +.Pp
  6119. +The second synopsis provides special features which allow
  6120. +for the creation of more sophisticated
  6121. +.Tn RPC
  6122. +servers.
  6123. +These features include support for user provided
  6124. +.Em #defines
  6125. +and
  6126. +.Tn RPC
  6127. +dispatch tables.
  6128. +The entries in the
  6129. +.Tn RPC
  6130. +dispatch table contain:
  6131. +.Bl -bullet -offset indent -compact
  6132. +.It
  6133. +pointers to the service routine corresponding to that procedure,
  6134. +.It
  6135. +a pointer to the input and output arguments,
  6136. +.It
  6137. +the size of these routines.
  6138. +.El
  6139. +A server can use the dispatch table to check authorization
  6140. +and then to execute the service routine;
  6141. +a client library may use it to deal with the details of storage
  6142. +management and XDR data conversion.
  6143. +.Pp
  6144. +The other three synopses shown above are used when
  6145. +one does not want to generate all the output files,
  6146. +but only a particular one.
  6147. +See the
  6148. +.Sx EXAMPLES
  6149. +section below for examples of
  6150. +.Nm
  6151. +usage.
  6152. +When
  6153. +.Nm
  6154. +is executed with the
  6155. +.Fl s
  6156. +option,
  6157. +it creates servers for that particular class of transports.
  6158. +When
  6159. +executed with the
  6160. +.Fl n
  6161. +option,
  6162. +it creates a server for the transport specified by
  6163. +.Ar netid .
  6164. +If
  6165. +.Ar infile
  6166. +is not specified,
  6167. +.Nm
  6168. +accepts the standard input.
  6169. +.Pp
  6170. +The C preprocessor,
  6171. +.Em cc -E
  6172. +is run on the input file before it is actually interpreted by
  6173. +.Nm .
  6174. +For each type of output file,
  6175. +.Nm
  6176. +defines a special preprocessor symbol for use by the
  6177. +.Nm
  6178. +programmer:
  6179. +.Bl -tag -width indent
  6180. +.It RPC_HDR
  6181. +defined when compiling into headers
  6182. +.It RPC_XDR
  6183. +defined when compiling into XDR routines
  6184. +.It RPC_SVC
  6185. +defined when compiling into server-side stubs
  6186. +.It RPC_CLNT
  6187. +defined when compiling into client-side stubs
  6188. +.It RPC_TBL
  6189. +defined when compiling into RPC dispatch tables
  6190. +.El
  6191. +.Pp
  6192. +Any line beginning with
  6193. +.Dq %
  6194. +is passed directly into the output file,
  6195. +uninterpreted by
  6196. +.Nm .
  6197. +To specify the path name of the C preprocessor use
  6198. +.Fl Y
  6199. +flag.
  6200. +.Pp
  6201. +For every data type referred to in
  6202. +.Ar infile ,
  6203. +.Nm
  6204. +assumes that there exists a
  6205. +routine with the string
  6206. +.Em xdr_
  6207. +prepended to the name of the data type.
  6208. +If this routine does not exist in the
  6209. +.Tn RPC/XDR
  6210. +library, it must be provided.
  6211. +Providing an undefined data type
  6212. +allows customization of
  6213. +.Xr xdr 3
  6214. +routines.
  6215. +.Sh OPTIONS
  6216. +The following options are available:
  6217. +.Bl -tag -width indent
  6218. +.It Fl a
  6219. +Generate all files, including sample files.
  6220. +.It Fl b
  6221. +Backward compatibility mode.
  6222. +Generate transport specific
  6223. +.Tn RPC
  6224. +code for older versions
  6225. +of the operating system.
  6226. +.Pp
  6227. +Note: in
  6228. +.Fx ,
  6229. +this compatibility flag is turned on by
  6230. +default since
  6231. +.Fx
  6232. +supports only the older
  6233. +.Tn ONC RPC
  6234. +library.
  6235. +.It Fl c
  6236. +Compile into
  6237. +.Tn XDR
  6238. +routines.
  6239. +.It Fl C
  6240. +Generate header and stub files which can be used with
  6241. +.Tn ANSI
  6242. +C compilers. Headers generated with this flag can also be
  6243. +used with C++ programs.
  6244. +.It Fl D Ns Ar name
  6245. +.It Fl D Ns Ar name=value
  6246. +.\".It Fl D Ns Ar name Ns Op Ar =value
  6247. +Define a symbol
  6248. +.Ar name .
  6249. +Equivalent to the
  6250. +.Em #define
  6251. +directive in the source.
  6252. +If no
  6253. +.Ar value
  6254. +is given,
  6255. +.Ar value
  6256. +is defined as
  6257. +.Em 1 .
  6258. +This option may be specified more than once.
  6259. +.It Fl h
  6260. +Compile into C data-definitions (a header).
  6261. +.Fl T
  6262. +option can be used in conjunction to produce a
  6263. +header which supports
  6264. +.Tn RPC
  6265. +dispatch tables.
  6266. +.It Fl i Ar size
  6267. +Size at which to start generating inline code.
  6268. +This option is useful for optimization.
  6269. +The default size is 5.
  6270. +.Pp
  6271. +Note: in order to provide backwards compatibility with the older
  6272. +.Nm
  6273. +on the
  6274. +.Fx
  6275. +platform, the default is actually 0 (which means
  6276. +that inline code generation is disabled by default). You must specify
  6277. +a non-zero value explicitly to override this default.
  6278. +.It Fl I
  6279. +Compile support for
  6280. +.Xr inetd 8
  6281. +in the server side stubs.
  6282. +Such servers can be self-started or can be started by
  6283. +.Nm inetd .
  6284. +When the server is self-started, it backgrounds itself by default.
  6285. +A special define symbol
  6286. +.Em RPC_SVC_FG
  6287. +can be used to run the
  6288. +server process in foreground, or the user may simply compile without
  6289. +the
  6290. +.Fl I
  6291. +option.
  6292. +.Pp
  6293. +If there are no pending client requests, the
  6294. +.Nm inetd
  6295. +servers exit after 120 seconds (default).
  6296. +The default can be changed with the
  6297. +.Fl K
  6298. +option.
  6299. +All the error messages for
  6300. +.Nm inetd
  6301. +servers
  6302. +are always logged with
  6303. +.Xr syslog 3 .
  6304. +.\" .IP
  6305. +.\" Note:
  6306. +.\" this option is supported for backward compatibility only.
  6307. +.\" By default,
  6308. +.\" .B rpcgen
  6309. +.\" generates servers that can be invoked through portmonitors.
  6310. +.Pp
  6311. +.It Fl K Ar seconds
  6312. +By default, services created using
  6313. +.Nm
  6314. +and invoked through
  6315. +port monitors wait 120 seconds
  6316. +after servicing a request before exiting.
  6317. +That interval can be changed using the
  6318. +.Fl K
  6319. +flag.
  6320. +To create a server that exits immediately upon servicing a request,
  6321. +use
  6322. +.Fl K Ar 0 .
  6323. +To create a server that never exits, the appropriate argument is
  6324. +.Fl k Ar -1 .
  6325. +.Pp
  6326. +When monitoring for a server,
  6327. +some portmonitors
  6328. +.Em always
  6329. +spawn a new process in response to a service request.
  6330. +If it is known that a server will be used with such a monitor, the
  6331. +server should exit immediately on completion.
  6332. +For such servers,
  6333. +.Nm
  6334. +should be used with
  6335. +.Fl K Ar 0 .
  6336. +.It Fl l
  6337. +Compile into client-side stubs.
  6338. +.It Fl L
  6339. +When the servers are started in foreground, use
  6340. +.Xr syslog 3
  6341. +to log the server errors instead of printing them on the standard
  6342. +error.
  6343. +.It Fl m
  6344. +Compile into server-side stubs,
  6345. +but do not generate a
  6346. +.Qq main
  6347. +routine.
  6348. +This option is useful for doing callback-routines
  6349. +and for users who need to write their own
  6350. +.Qq main
  6351. +routine to do initialization.
  6352. +.It Fl M
  6353. +Generate multithread-safe stubs for passing arguments and results between
  6354. +rpcgen generated code and user written code.
  6355. +This option is useful
  6356. +for users who want to use threads in their code.
  6357. +However, the
  6358. +.Xr rpc_svc_calls 3
  6359. +functions are not yet MT-safe, which means that rpcgen generated server-side
  6360. +code will not be MT-safe.
  6361. +.It Fl N
  6362. +This option allows procedures to have multiple arguments.
  6363. +It also uses the style of parameter passing that closely resembles C.
  6364. +So, when passing an argument to a remote procedure, you do not have to
  6365. +pass a pointer to the argument, but can pass the argument itself.
  6366. +This behavior is different from the old style of
  6367. +.Nm
  6368. +generated code.
  6369. +To maintain backward compatibility,
  6370. +this option is not the default.
  6371. +.It Fl n Ar netid
  6372. +Compile into server-side stubs for the transport
  6373. +specified by
  6374. +.Ar netid .
  6375. +There should be an entry for
  6376. +.Ar netid
  6377. +in the
  6378. +netconfig database.
  6379. +This option may be specified more than once,
  6380. +so as to compile a server that serves multiple transports.
  6381. +.It Fl o Ar outfile
  6382. +Specify the name of the output file.
  6383. +If none is specified,
  6384. +standard output is used
  6385. +(
  6386. +.Fl c ,
  6387. +.Fl h ,
  6388. +.Fl l ,
  6389. +.Fl m ,
  6390. +.Fl n ,
  6391. +.Fl s ,
  6392. +.Fl \&Sc ,
  6393. +.Fl \&Sm ,
  6394. +.Fl \&Ss ,
  6395. +and
  6396. +.Fl t
  6397. +modes only).
  6398. +.It Fl s Ar nettype
  6399. +Compile into server-side stubs for all the
  6400. +transports belonging to the class
  6401. +.Ar nettype .
  6402. +The supported classes are
  6403. +.Em netpath ,
  6404. +.Em visible ,
  6405. +.Em circuit_n ,
  6406. +.Em circuit_v ,
  6407. +.Em datagram_n ,
  6408. +.Em datagram_v ,
  6409. +.Em tcp ,
  6410. +and
  6411. +.Em udp
  6412. +(see
  6413. +.Xr rpc 3
  6414. +for the meanings associated with these classes).
  6415. +This option may be specified more than once.
  6416. +Note:
  6417. +the transports are chosen at run time and not at compile time.
  6418. +.It Fl \&Sc
  6419. +Generate sample client code that uses remote procedure calls.
  6420. +.It Fl \&Sm
  6421. +Generate a sample
  6422. +.Pa Makefile
  6423. +which can be used for compiling the application.
  6424. +.It Fl \&Ss
  6425. +Generate sample server code that uses remote procedure calls.
  6426. +.It Fl t
  6427. +Compile into
  6428. +.Tn RPC
  6429. +dispatch table.
  6430. +.It Fl T
  6431. +Generate the code to support
  6432. +.Tn RPC
  6433. +dispatch tables.
  6434. +.Pp
  6435. +The options
  6436. +.Fl c ,
  6437. +.Fl h ,
  6438. +.Fl l ,
  6439. +.Fl m ,
  6440. +.Fl s ,
  6441. +.Fl \&Sc ,
  6442. +.Fl \&Sm ,
  6443. +.Fl \&Ss ,
  6444. +and
  6445. +.Fl t
  6446. +are used exclusively to generate a particular type of file,
  6447. +while the options
  6448. +.Fl D
  6449. +and
  6450. +.Fl T
  6451. +are global and can be used with the other options.
  6452. +.It Fl Y Ar pathname
  6453. +Give the name of the directory where
  6454. +.Nm
  6455. +will start looking for the C-preprocessor.
  6456. +.El
  6457. +.Sh EXAMPLES
  6458. +The following example:
  6459. +.Dl example% rpcgen -T prot.x
  6460. +.Pp
  6461. +generates all the five files:
  6462. +.Pa prot.h ,
  6463. +.Pa prot_clnt.c ,
  6464. +.Pa prot_svc.c ,
  6465. +.Pa prot_xdr.c
  6466. +and
  6467. +.Pa prot_tbl.i .
  6468. +.Pp
  6469. +The following example sends the C data-definitions (header)
  6470. +to the standard output.
  6471. +.Dl example% rpcgen -h prot.x
  6472. +.Pp
  6473. +To send the test version of the
  6474. +.Fl D Ns Ar TEST ,
  6475. +server side stubs for
  6476. +all the transport belonging to the class
  6477. +.Ar datagram_n
  6478. +to standard output, use:
  6479. +.Dl example% rpcgen -s datagram_n -DTEST prot.x
  6480. +.Pp
  6481. +To create the server side stubs for the transport indicated
  6482. +by
  6483. +.Ar netid
  6484. +tcp,
  6485. +use:
  6486. +.Dl example% rpcgen -n tcp -o prot_svc.c prot.x
  6487. +.Sh SEE ALSO
  6488. +.Xr cc 1 ,
  6489. +.Xr rpc 3 ,
  6490. +.Xr syslog 3 ,
  6491. +.Xr inetd 8
  6492. +.\" .BR rpc_svc_calls (3)
  6493. +.Rs
  6494. +.%T The rpcgen chapter in the NETP manual
  6495. +.Re
  6496. --
  6497. 1.7.9.5