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

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