0003-Add-rpcgen-program-from-nfs-utils-sources.patch 164 KB

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