mxmldoc.c 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797
  1. /*#define DEBUG 1*/
  2. /*
  3. * "$Id: mxmldoc.c 451 2014-01-04 21:50:06Z msweet $"
  4. *
  5. * Documentation generator using Mini-XML, a small XML-like file parsing
  6. * library.
  7. *
  8. * Copyright 2003-2014 by Michael R Sweet.
  9. *
  10. * These coded instructions, statements, and computer programs are the
  11. * property of Michael R Sweet and are protected by Federal copyright
  12. * law. Distribution and use rights are outlined in the file "COPYING"
  13. * which should have been included with this file. If this file is
  14. * missing or damaged, see the license at:
  15. *
  16. * http://www.minixml.org/
  17. */
  18. /*
  19. * Include necessary headers...
  20. */
  21. #include "config.h"
  22. #include "mxml.h"
  23. #include <time.h>
  24. #include <sys/stat.h>
  25. #ifndef WIN32
  26. # include <dirent.h>
  27. # include <unistd.h>
  28. #endif /* !WIN32 */
  29. #ifdef __APPLE__
  30. # include <spawn.h>
  31. # include <sys/wait.h>
  32. extern char **environ;
  33. #endif /* __APPLE__ */
  34. /*
  35. * This program scans source and header files and produces public API
  36. * documentation for code that conforms to the CUPS Configuration
  37. * Management Plan (CMP) coding standards. Please see the following web
  38. * page for details:
  39. *
  40. * http://www.cups.org/cmp.html
  41. *
  42. * Using Mini-XML, this program creates and maintains an XML representation
  43. * of the public API code documentation which can then be converted to HTML
  44. * as desired. The following is a poor-man's schema:
  45. *
  46. * <?xml version="1.0"?>
  47. * <mxmldoc xmlns="http://www.easysw.com"
  48. * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  49. * xsi:schemaLocation="http://www.minixml.org/mxmldoc.xsd">
  50. *
  51. * <namespace name=""> [optional...]
  52. * <constant name="">
  53. * <description>descriptive text</description>
  54. * </constant>
  55. *
  56. * <enumeration name="">
  57. * <description>descriptive text</description>
  58. * <constant name="">...</constant>
  59. * </enumeration>
  60. *
  61. * <typedef name="">
  62. * <description>descriptive text</description>
  63. * <type>type string</type>
  64. * </typedef>
  65. *
  66. * <function name="" scope="">
  67. * <description>descriptive text</description>
  68. * <argument name="" direction="I|O|IO" default="">
  69. * <description>descriptive text</description>
  70. * <type>type string</type>
  71. * </argument>
  72. * <returnvalue>
  73. * <description>descriptive text</description>
  74. * <type>type string</type>
  75. * </returnvalue>
  76. * <seealso>function names separated by spaces</seealso>
  77. * </function>
  78. *
  79. * <variable name="" scope="">
  80. * <description>descriptive text</description>
  81. * <type>type string</type>
  82. * </variable>
  83. *
  84. * <struct name="">
  85. * <description>descriptive text</description>
  86. * <variable name="">...</variable>
  87. * <function name="">...</function>
  88. * </struct>
  89. *
  90. * <union name="">
  91. * <description>descriptive text</description>
  92. * <variable name="">...</variable>
  93. * </union>
  94. *
  95. * <class name="" parent="">
  96. * <description>descriptive text</description>
  97. * <class name="">...</class>
  98. * <enumeration name="">...</enumeration>
  99. * <function name="">...</function>
  100. * <struct name="">...</struct>
  101. * <variable name="">...</variable>
  102. * </class>
  103. * </namespace>
  104. * </mxmldoc>
  105. */
  106. /*
  107. * Basic states for file parser...
  108. */
  109. #define STATE_NONE 0 /* No state - whitespace, etc. */
  110. #define STATE_PREPROCESSOR 1 /* Preprocessor directive */
  111. #define STATE_C_COMMENT 2 /* Inside a C comment */
  112. #define STATE_CXX_COMMENT 3 /* Inside a C++ comment */
  113. #define STATE_STRING 4 /* Inside a string constant */
  114. #define STATE_CHARACTER 5 /* Inside a character constant */
  115. #define STATE_IDENTIFIER 6 /* Inside a keyword/identifier */
  116. /*
  117. * Output modes...
  118. */
  119. #define OUTPUT_NONE 0 /* No output */
  120. #define OUTPUT_HTML 1 /* Output HTML */
  121. #define OUTPUT_XML 2 /* Output XML */
  122. #define OUTPUT_MAN 3 /* Output nroff/man */
  123. #define OUTPUT_TOKENS 4 /* Output docset Tokens.xml file */
  124. /*
  125. * Local functions...
  126. */
  127. static mxml_node_t *add_variable(mxml_node_t *parent, const char *name,
  128. mxml_node_t *type);
  129. static mxml_node_t *find_public(mxml_node_t *node, mxml_node_t *top,
  130. const char *name);
  131. static char *get_comment_info(mxml_node_t *description);
  132. static char *get_text(mxml_node_t *node, char *buffer, int buflen);
  133. static mxml_type_t load_cb(mxml_node_t *node);
  134. static mxml_node_t *new_documentation(mxml_node_t **mxmldoc);
  135. static int remove_directory(const char *path);
  136. static void safe_strcpy(char *dst, const char *src);
  137. static int scan_file(const char *filename, FILE *fp,
  138. mxml_node_t *doc);
  139. static void sort_node(mxml_node_t *tree, mxml_node_t *func);
  140. static void update_comment(mxml_node_t *parent,
  141. mxml_node_t *comment);
  142. static void usage(const char *option);
  143. static void write_description(FILE *out, mxml_node_t *description,
  144. const char *element, int summary);
  145. static void write_element(FILE *out, mxml_node_t *doc,
  146. mxml_node_t *element, int mode);
  147. static void write_file(FILE *out, const char *file);
  148. static void write_function(FILE *out, mxml_node_t *doc,
  149. mxml_node_t *function, int level);
  150. static void write_html(const char *section, const char *title,
  151. const char *footerfile,
  152. const char *headerfile,
  153. const char *introfile, const char *cssfile,
  154. const char *framefile,
  155. const char *docset, const char *docversion,
  156. const char *feedname, const char *feedurl,
  157. mxml_node_t *doc);
  158. static void write_html_head(FILE *out, const char *section,
  159. const char *title, const char *cssfile);
  160. static void write_man(const char *man_name, const char *section,
  161. const char *title, const char *headerfile,
  162. const char *footerfile, const char *introfile,
  163. mxml_node_t *doc);
  164. static void write_scu(FILE *out, mxml_node_t *doc,
  165. mxml_node_t *scut);
  166. static void write_string(FILE *out, const char *s, int mode);
  167. static void write_toc(FILE *out, mxml_node_t *doc,
  168. const char *introfile, const char *target,
  169. int xml);
  170. static void write_tokens(FILE *out, mxml_node_t *doc,
  171. const char *path);
  172. static const char *ws_cb(mxml_node_t *node, int where);
  173. /*
  174. * 'main()' - Main entry for test program.
  175. */
  176. int /* O - Exit status */
  177. main(int argc, /* I - Number of command-line args */
  178. char *argv[]) /* I - Command-line args */
  179. {
  180. int i; /* Looping var */
  181. int len; /* Length of argument */
  182. FILE *fp; /* File to read */
  183. mxml_node_t *doc; /* XML documentation tree */
  184. mxml_node_t *mxmldoc; /* mxmldoc node */
  185. const char *cssfile, /* CSS stylesheet file */
  186. *docset, /* Documentation set directory */
  187. *docversion, /* Documentation set version */
  188. *feedname, /* Feed name for documentation set */
  189. *feedurl, /* Feed URL for documentation set */
  190. *footerfile, /* Footer file */
  191. *framefile, /* Framed HTML basename */
  192. *headerfile, /* Header file */
  193. *introfile, /* Introduction file */
  194. *name, /* Name of manpage */
  195. *path, /* Path to help file for tokens */
  196. *section, /* Section/keywords of documentation */
  197. *title, /* Title of documentation */
  198. *xmlfile; /* XML file */
  199. int mode, /* Output mode */
  200. update; /* Updated XML file */
  201. /*
  202. * Check arguments...
  203. */
  204. cssfile = NULL;
  205. doc = NULL;
  206. docset = NULL;
  207. docversion = NULL;
  208. feedname = NULL;
  209. feedurl = NULL;
  210. footerfile = NULL;
  211. framefile = NULL;
  212. headerfile = NULL;
  213. introfile = NULL;
  214. mode = OUTPUT_HTML;
  215. mxmldoc = NULL;
  216. name = NULL;
  217. path = NULL;
  218. section = NULL;
  219. title = NULL;
  220. update = 0;
  221. xmlfile = NULL;
  222. for (i = 1; i < argc; i ++)
  223. if (!strcmp(argv[i], "--help"))
  224. {
  225. /*
  226. * Show help...
  227. */
  228. usage(NULL);
  229. }
  230. else if (!strcmp(argv[i], "--version"))
  231. {
  232. /*
  233. * Show version...
  234. */
  235. puts(MXML_VERSION + 10);
  236. return (0);
  237. }
  238. else if (!strcmp(argv[i], "--css") && !cssfile)
  239. {
  240. /*
  241. * Set CSS stylesheet file...
  242. */
  243. i ++;
  244. if (i < argc)
  245. cssfile = argv[i];
  246. else
  247. usage(NULL);
  248. }
  249. else if (!strcmp(argv[i], "--docset") && !docset)
  250. {
  251. /*
  252. * Set documentation set directory...
  253. */
  254. i ++;
  255. if (i < argc)
  256. docset = argv[i];
  257. else
  258. usage(NULL);
  259. }
  260. else if (!strcmp(argv[i], "--docversion") && !docversion)
  261. {
  262. /*
  263. * Set documentation set directory...
  264. */
  265. i ++;
  266. if (i < argc)
  267. docversion = argv[i];
  268. else
  269. usage(NULL);
  270. }
  271. else if (!strcmp(argv[i], "--footer") && !footerfile)
  272. {
  273. /*
  274. * Set footer file...
  275. */
  276. i ++;
  277. if (i < argc)
  278. footerfile = argv[i];
  279. else
  280. usage(NULL);
  281. }
  282. else if (!strcmp(argv[i], "--feedname") && !feedname)
  283. {
  284. /*
  285. * Set documentation set feed name...
  286. */
  287. i ++;
  288. if (i < argc)
  289. feedname = argv[i];
  290. else
  291. usage(NULL);
  292. }
  293. else if (!strcmp(argv[i], "--feedurl") && !feedurl)
  294. {
  295. /*
  296. * Set documentation set feed name...
  297. */
  298. i ++;
  299. if (i < argc)
  300. feedurl = argv[i];
  301. else
  302. usage(NULL);
  303. }
  304. else if (!strcmp(argv[i], "--framed") && !framefile)
  305. {
  306. /*
  307. * Set base filename for framed HTML output...
  308. */
  309. i ++;
  310. if (i < argc)
  311. framefile = argv[i];
  312. else
  313. usage(NULL);
  314. }
  315. else if (!strcmp(argv[i], "--header") && !headerfile)
  316. {
  317. /*
  318. * Set header file...
  319. */
  320. i ++;
  321. if (i < argc)
  322. headerfile = argv[i];
  323. else
  324. usage(NULL);
  325. }
  326. else if (!strcmp(argv[i], "--intro") && !introfile)
  327. {
  328. /*
  329. * Set intro file...
  330. */
  331. i ++;
  332. if (i < argc)
  333. introfile = argv[i];
  334. else
  335. usage(NULL);
  336. }
  337. else if (!strcmp(argv[i], "--man") && !name)
  338. {
  339. /*
  340. * Output manpage...
  341. */
  342. i ++;
  343. if (i < argc)
  344. {
  345. mode = OUTPUT_MAN;
  346. name = argv[i];
  347. }
  348. else
  349. usage(NULL);
  350. }
  351. else if (!strcmp(argv[i], "--no-output"))
  352. mode = OUTPUT_NONE;
  353. else if (!strcmp(argv[i], "--section") && !section)
  354. {
  355. /*
  356. * Set section/keywords...
  357. */
  358. i ++;
  359. if (i < argc)
  360. section = argv[i];
  361. else
  362. usage(NULL);
  363. }
  364. else if (!strcmp(argv[i], "--title") && !title)
  365. {
  366. /*
  367. * Set title...
  368. */
  369. i ++;
  370. if (i < argc)
  371. title = argv[i];
  372. else
  373. usage(NULL);
  374. }
  375. else if (!strcmp(argv[i], "--tokens"))
  376. {
  377. /*
  378. * Output Tokens.xml file...
  379. */
  380. mode = OUTPUT_TOKENS;
  381. i ++;
  382. if (i < argc)
  383. path = argv[i];
  384. else
  385. usage(NULL);
  386. }
  387. else if (argv[i][0] == '-')
  388. {
  389. /*
  390. * Unknown/bad option...
  391. */
  392. usage(argv[i]);
  393. }
  394. else
  395. {
  396. /*
  397. * Process XML or source file...
  398. */
  399. len = (int)strlen(argv[i]);
  400. if (len > 4 && !strcmp(argv[i] + len - 4, ".xml"))
  401. {
  402. /*
  403. * Set XML file...
  404. */
  405. if (xmlfile)
  406. usage(NULL);
  407. xmlfile = argv[i];
  408. if (!doc)
  409. {
  410. if ((fp = fopen(argv[i], "r")) != NULL)
  411. {
  412. /*
  413. * Read the existing XML file...
  414. */
  415. doc = mxmlLoadFile(NULL, fp, load_cb);
  416. fclose(fp);
  417. if (!doc)
  418. {
  419. mxmldoc = NULL;
  420. fprintf(stderr,
  421. "mxmldoc: Unable to read the XML documentation file "
  422. "\"%s\"!\n", argv[i]);
  423. }
  424. else if ((mxmldoc = mxmlFindElement(doc, doc, "mxmldoc", NULL,
  425. NULL, MXML_DESCEND)) == NULL)
  426. {
  427. fprintf(stderr,
  428. "mxmldoc: XML documentation file \"%s\" is missing "
  429. "<mxmldoc> node!!\n", argv[i]);
  430. mxmlDelete(doc);
  431. doc = NULL;
  432. }
  433. }
  434. else
  435. {
  436. doc = NULL;
  437. mxmldoc = NULL;
  438. }
  439. if (!doc)
  440. doc = new_documentation(&mxmldoc);
  441. }
  442. }
  443. else
  444. {
  445. /*
  446. * Load source file...
  447. */
  448. update = 1;
  449. if (!doc)
  450. doc = new_documentation(&mxmldoc);
  451. if ((fp = fopen(argv[i], "r")) == NULL)
  452. {
  453. fprintf(stderr, "mxmldoc: Unable to open source file \"%s\": %s\n",
  454. argv[i], strerror(errno));
  455. mxmlDelete(doc);
  456. return (1);
  457. }
  458. else if (scan_file(argv[i], fp, mxmldoc))
  459. {
  460. fclose(fp);
  461. mxmlDelete(doc);
  462. return (1);
  463. }
  464. else
  465. fclose(fp);
  466. }
  467. }
  468. if (update && xmlfile)
  469. {
  470. /*
  471. * Save the updated XML documentation file...
  472. */
  473. if ((fp = fopen(xmlfile, "w")) != NULL)
  474. {
  475. /*
  476. * Write over the existing XML file...
  477. */
  478. mxmlSetWrapMargin(0);
  479. if (mxmlSaveFile(doc, fp, ws_cb))
  480. {
  481. fprintf(stderr,
  482. "mxmldoc: Unable to write the XML documentation file \"%s\": "
  483. "%s!\n", xmlfile, strerror(errno));
  484. fclose(fp);
  485. mxmlDelete(doc);
  486. return (1);
  487. }
  488. fclose(fp);
  489. }
  490. else
  491. {
  492. fprintf(stderr,
  493. "mxmldoc: Unable to create the XML documentation file \"%s\": "
  494. "%s!\n", xmlfile, strerror(errno));
  495. mxmlDelete(doc);
  496. return (1);
  497. }
  498. }
  499. switch (mode)
  500. {
  501. case OUTPUT_HTML :
  502. /*
  503. * Write HTML documentation...
  504. */
  505. write_html(section, title ? title : "Documentation", footerfile,
  506. headerfile, introfile, cssfile, framefile, docset,
  507. docversion, feedname, feedurl, mxmldoc);
  508. break;
  509. case OUTPUT_MAN :
  510. /*
  511. * Write manpage documentation...
  512. */
  513. write_man(name, section, title, footerfile, headerfile, introfile,
  514. mxmldoc);
  515. break;
  516. case OUTPUT_TOKENS :
  517. fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  518. "<Tokens version=\"1.0\">\n", stdout);
  519. write_tokens(stdout, mxmldoc, path);
  520. fputs("</Tokens>\n", stdout);
  521. break;
  522. }
  523. /*
  524. * Delete the tree and return...
  525. */
  526. mxmlDelete(doc);
  527. return (0);
  528. }
  529. /*
  530. * 'add_variable()' - Add a variable or argument.
  531. */
  532. static mxml_node_t * /* O - New variable/argument */
  533. add_variable(mxml_node_t *parent, /* I - Parent node */
  534. const char *name, /* I - "argument" or "variable" */
  535. mxml_node_t *type) /* I - Type nodes */
  536. {
  537. mxml_node_t *variable, /* New variable */
  538. *node, /* Current node */
  539. *next; /* Next node */
  540. char buffer[16384], /* String buffer */
  541. *bufptr; /* Pointer into buffer */
  542. #ifdef DEBUG
  543. fprintf(stderr, "add_variable(parent=%p, name=\"%s\", type=%p)\n",
  544. parent, name, type);
  545. #endif /* DEBUG */
  546. /*
  547. * Range check input...
  548. */
  549. if (!type || !type->child)
  550. return (NULL);
  551. /*
  552. * Create the variable/argument node...
  553. */
  554. variable = mxmlNewElement(parent, name);
  555. /*
  556. * Check for a default value...
  557. */
  558. for (node = type->child; node; node = node->next)
  559. if (!strcmp(node->value.text.string, "="))
  560. break;
  561. if (node)
  562. {
  563. /*
  564. * Default value found, copy it and add as a "default" attribute...
  565. */
  566. for (bufptr = buffer; node; bufptr += strlen(bufptr))
  567. {
  568. if (node->value.text.whitespace && bufptr > buffer)
  569. *bufptr++ = ' ';
  570. strcpy(bufptr, node->value.text.string);
  571. next = node->next;
  572. mxmlDelete(node);
  573. node = next;
  574. }
  575. mxmlElementSetAttr(variable, "default", buffer);
  576. }
  577. /*
  578. * Extract the argument/variable name...
  579. */
  580. if (type->last_child->value.text.string[0] == ')')
  581. {
  582. /*
  583. * Handle "type (*name)(args)"...
  584. */
  585. for (node = type->child; node; node = node->next)
  586. if (node->value.text.string[0] == '(')
  587. break;
  588. for (bufptr = buffer; node; bufptr += strlen(bufptr))
  589. {
  590. if (node->value.text.whitespace && bufptr > buffer)
  591. *bufptr++ = ' ';
  592. strcpy(bufptr, node->value.text.string);
  593. next = node->next;
  594. mxmlDelete(node);
  595. node = next;
  596. }
  597. }
  598. else
  599. {
  600. /*
  601. * Handle "type name"...
  602. */
  603. strcpy(buffer, type->last_child->value.text.string);
  604. mxmlDelete(type->last_child);
  605. }
  606. /*
  607. * Set the name...
  608. */
  609. mxmlElementSetAttr(variable, "name", buffer);
  610. /*
  611. * Add the remaining type information to the variable node...
  612. */
  613. mxmlAdd(variable, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type);
  614. /*
  615. * Add new new variable node...
  616. */
  617. return (variable);
  618. }
  619. /*
  620. * 'find_public()' - Find a public function, type, etc.
  621. */
  622. static mxml_node_t * /* I - Found node or NULL */
  623. find_public(mxml_node_t *node, /* I - Current node */
  624. mxml_node_t *top, /* I - Top node */
  625. const char *name) /* I - Name of element */
  626. {
  627. mxml_node_t *description, /* Description node */
  628. *comment; /* Comment node */
  629. for (node = mxmlFindElement(node, top, name, NULL, NULL,
  630. node == top ? MXML_DESCEND_FIRST :
  631. MXML_NO_DESCEND);
  632. node;
  633. node = mxmlFindElement(node, top, name, NULL, NULL, MXML_NO_DESCEND))
  634. {
  635. /*
  636. * Get the description for this node...
  637. */
  638. description = mxmlFindElement(node, node, "description", NULL, NULL,
  639. MXML_DESCEND_FIRST);
  640. /*
  641. * A missing or empty description signals a private node...
  642. */
  643. if (!description)
  644. continue;
  645. /*
  646. * Look for @private@ in the comment text...
  647. */
  648. for (comment = description->child; comment; comment = comment->next)
  649. if ((comment->type == MXML_TEXT &&
  650. strstr(comment->value.text.string, "@private@")) ||
  651. (comment->type == MXML_OPAQUE &&
  652. strstr(comment->value.opaque, "@private@")))
  653. break;
  654. if (!comment)
  655. {
  656. /*
  657. * No @private@, so return this node...
  658. */
  659. return (node);
  660. }
  661. }
  662. /*
  663. * If we get here, there are no (more) public nodes...
  664. */
  665. return (NULL);
  666. }
  667. /*
  668. * 'get_comment_info()' - Get info from comment.
  669. */
  670. static char * /* O - Info from comment */
  671. get_comment_info(
  672. mxml_node_t *description) /* I - Description node */
  673. {
  674. char text[10240], /* Description text */
  675. since[255], /* @since value */
  676. *ptr; /* Pointer into text */
  677. static char info[1024]; /* Info string */
  678. if (!description)
  679. return ("");
  680. get_text(description, text, sizeof(text));
  681. for (ptr = strchr(text, '@'); ptr; ptr = strchr(ptr + 1, '@'))
  682. {
  683. if (!strncmp(ptr, "@deprecated@", 12))
  684. return ("<span class=\"info\">&nbsp;DEPRECATED&nbsp;</span>");
  685. else if (!strncmp(ptr, "@since ", 7))
  686. {
  687. strncpy(since, ptr + 7, sizeof(since) - 1);
  688. since[sizeof(since) - 1] = '\0';
  689. if ((ptr = strchr(since, '@')) != NULL)
  690. *ptr = '\0';
  691. snprintf(info, sizeof(info), "<span class=\"info\">&nbsp;%s&nbsp;</span>", since);
  692. return (info);
  693. }
  694. }
  695. return ("");
  696. }
  697. /*
  698. * 'get_text()' - Get the text for a node.
  699. */
  700. static char * /* O - Text in node */
  701. get_text(mxml_node_t *node, /* I - Node to get */
  702. char *buffer, /* I - Buffer */
  703. int buflen) /* I - Size of buffer */
  704. {
  705. char *ptr, /* Pointer into buffer */
  706. *end; /* End of buffer */
  707. int len; /* Length of node */
  708. mxml_node_t *current; /* Current node */
  709. ptr = buffer;
  710. end = buffer + buflen - 1;
  711. for (current = node->child; current && ptr < end; current = current->next)
  712. {
  713. if (current->type == MXML_TEXT)
  714. {
  715. if (current->value.text.whitespace)
  716. *ptr++ = ' ';
  717. len = (int)strlen(current->value.text.string);
  718. if (len > (int)(end - ptr))
  719. len = (int)(end - ptr);
  720. memcpy(ptr, current->value.text.string, len);
  721. ptr += len;
  722. }
  723. else if (current->type == MXML_OPAQUE)
  724. {
  725. len = (int)strlen(current->value.opaque);
  726. if (len > (int)(end - ptr))
  727. len = (int)(end - ptr);
  728. memcpy(ptr, current->value.opaque, len);
  729. ptr += len;
  730. }
  731. }
  732. *ptr = '\0';
  733. return (buffer);
  734. }
  735. /*
  736. * 'load_cb()' - Set the type of child nodes.
  737. */
  738. static mxml_type_t /* O - Node type */
  739. load_cb(mxml_node_t *node) /* I - Node */
  740. {
  741. if (!strcmp(node->value.element.name, "description"))
  742. return (MXML_OPAQUE);
  743. else
  744. return (MXML_TEXT);
  745. }
  746. /*
  747. * 'new_documentation()' - Create a new documentation tree.
  748. */
  749. static mxml_node_t * /* O - New documentation */
  750. new_documentation(mxml_node_t **mxmldoc)/* O - mxmldoc node */
  751. {
  752. mxml_node_t *doc; /* New documentation */
  753. /*
  754. * Create an empty XML documentation file...
  755. */
  756. doc = mxmlNewXML(NULL);
  757. *mxmldoc = mxmlNewElement(doc, "mxmldoc");
  758. mxmlElementSetAttr(*mxmldoc, "xmlns", "http://www.easysw.com");
  759. mxmlElementSetAttr(*mxmldoc, "xmlns:xsi",
  760. "http://www.w3.org/2001/XMLSchema-instance");
  761. mxmlElementSetAttr(*mxmldoc, "xsi:schemaLocation",
  762. "http://www.minixml.org/mxmldoc.xsd");
  763. return (doc);
  764. }
  765. /*
  766. * 'remove_directory()' - Remove a directory.
  767. */
  768. static int /* O - 1 on success, 0 on failure */
  769. remove_directory(const char *path) /* I - Directory to remove */
  770. {
  771. #ifdef WIN32
  772. /* TODO: Add Windows directory removal code */
  773. #else
  774. DIR *dir; /* Directory */
  775. struct dirent *dent; /* Current directory entry */
  776. char filename[1024]; /* Current filename */
  777. struct stat fileinfo; /* File information */
  778. if ((dir = opendir(path)) == NULL)
  779. {
  780. fprintf(stderr, "mxmldoc: Unable to open directory \"%s\": %s\n", path,
  781. strerror(errno));
  782. return (0);
  783. }
  784. while ((dent = readdir(dir)) != NULL)
  785. {
  786. /*
  787. * Skip "." and ".."...
  788. */
  789. if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
  790. continue;
  791. /*
  792. * See if we have a file or directory...
  793. */
  794. snprintf(filename, sizeof(filename), "%s/%s", path, dent->d_name);
  795. if (stat(filename, &fileinfo))
  796. {
  797. fprintf(stderr, "mxmldoc: Unable to stat \"%s\": %s\n", filename,
  798. strerror(errno));
  799. closedir(dir);
  800. return (0);
  801. }
  802. if (S_ISDIR(fileinfo.st_mode))
  803. {
  804. if (!remove_directory(filename))
  805. {
  806. closedir(dir);
  807. return (0);
  808. }
  809. }
  810. else if (unlink(filename))
  811. {
  812. fprintf(stderr, "mxmldoc: Unable to remove \"%s\": %s\n", filename,
  813. strerror(errno));
  814. closedir(dir);
  815. return (0);
  816. }
  817. }
  818. closedir(dir);
  819. if (rmdir(path))
  820. {
  821. fprintf(stderr, "mxmldoc: Unable to remove directory \"%s\": %s\n", path,
  822. strerror(errno));
  823. return (0);
  824. }
  825. #endif /* WIN32 */
  826. return (1);
  827. }
  828. /*
  829. * 'safe_strcpy()' - Copy a string allowing for overlapping strings.
  830. */
  831. static void
  832. safe_strcpy(char *dst, /* I - Destination string */
  833. const char *src) /* I - Source string */
  834. {
  835. while (*src)
  836. *dst++ = *src++;
  837. *dst = '\0';
  838. }
  839. /*
  840. * 'scan_file()' - Scan a source file.
  841. */
  842. static int /* O - 0 on success, -1 on error */
  843. scan_file(const char *filename, /* I - Filename */
  844. FILE *fp, /* I - File to scan */
  845. mxml_node_t *tree) /* I - Function tree */
  846. {
  847. int state, /* Current parser state */
  848. braces, /* Number of braces active */
  849. parens; /* Number of active parenthesis */
  850. int ch; /* Current character */
  851. char buffer[65536], /* String buffer */
  852. *bufptr; /* Pointer into buffer */
  853. const char *scope; /* Current variable/function scope */
  854. mxml_node_t *comment, /* <comment> node */
  855. *constant, /* <constant> node */
  856. *enumeration, /* <enumeration> node */
  857. *function, /* <function> node */
  858. *fstructclass, /* function struct/class node */
  859. *structclass, /* <struct> or <class> node */
  860. *typedefnode, /* <typedef> node */
  861. *variable, /* <variable> or <argument> node */
  862. *returnvalue, /* <returnvalue> node */
  863. *type, /* <type> node */
  864. *description, /* <description> node */
  865. *node, /* Current node */
  866. *next; /* Next node */
  867. #if DEBUG > 1
  868. mxml_node_t *temp; /* Temporary node */
  869. int oldstate, /* Previous state */
  870. oldch; /* Old character */
  871. static const char *states[] = /* State strings */
  872. {
  873. "STATE_NONE",
  874. "STATE_PREPROCESSOR",
  875. "STATE_C_COMMENT",
  876. "STATE_CXX_COMMENT",
  877. "STATE_STRING",
  878. "STATE_CHARACTER",
  879. "STATE_IDENTIFIER"
  880. };
  881. #endif /* DEBUG > 1 */
  882. #ifdef DEBUG
  883. fprintf(stderr, "scan_file(filename=\"%s\", fp=%p, tree=%p)\n", filename,
  884. fp, tree);
  885. #endif /* DEBUG */
  886. /*
  887. * Initialize the finite state machine...
  888. */
  889. state = STATE_NONE;
  890. braces = 0;
  891. parens = 0;
  892. bufptr = buffer;
  893. comment = mxmlNewElement(MXML_NO_PARENT, "temp");
  894. constant = NULL;
  895. enumeration = NULL;
  896. function = NULL;
  897. variable = NULL;
  898. returnvalue = NULL;
  899. type = NULL;
  900. description = NULL;
  901. typedefnode = NULL;
  902. structclass = NULL;
  903. fstructclass = NULL;
  904. if (!strcmp(tree->value.element.name, "class"))
  905. scope = "private";
  906. else
  907. scope = NULL;
  908. /*
  909. * Read until end-of-file...
  910. */
  911. while ((ch = getc(fp)) != EOF)
  912. {
  913. #if DEBUG > 1
  914. oldstate = state;
  915. oldch = ch;
  916. #endif /* DEBUG > 1 */
  917. switch (state)
  918. {
  919. case STATE_NONE : /* No state - whitespace, etc. */
  920. switch (ch)
  921. {
  922. case '/' : /* Possible C/C++ comment */
  923. ch = getc(fp);
  924. bufptr = buffer;
  925. if (ch == '*')
  926. state = STATE_C_COMMENT;
  927. else if (ch == '/')
  928. state = STATE_CXX_COMMENT;
  929. else
  930. {
  931. ungetc(ch, fp);
  932. if (type)
  933. {
  934. #ifdef DEBUG
  935. fputs("Identifier: <<<< / >>>\n", stderr);
  936. #endif /* DEBUG */
  937. ch = type->last_child->value.text.string[0];
  938. mxmlNewText(type, isalnum(ch) || ch == '_', "/");
  939. }
  940. }
  941. break;
  942. case '#' : /* Preprocessor */
  943. #ifdef DEBUG
  944. fputs(" #preprocessor...\n", stderr);
  945. #endif /* DEBUG */
  946. state = STATE_PREPROCESSOR;
  947. break;
  948. case '\'' : /* Character constant */
  949. state = STATE_CHARACTER;
  950. bufptr = buffer;
  951. *bufptr++ = ch;
  952. break;
  953. case '\"' : /* String constant */
  954. state = STATE_STRING;
  955. bufptr = buffer;
  956. *bufptr++ = ch;
  957. break;
  958. case '{' :
  959. #ifdef DEBUG
  960. fprintf(stderr, " open brace, function=%p, type=%p...\n",
  961. function, type);
  962. if (type)
  963. fprintf(stderr, " type->child=\"%s\"...\n",
  964. type->child->value.text.string);
  965. #endif /* DEBUG */
  966. if (function)
  967. {
  968. if (fstructclass)
  969. {
  970. sort_node(fstructclass, function);
  971. fstructclass = NULL;
  972. }
  973. else
  974. sort_node(tree, function);
  975. function = NULL;
  976. }
  977. else if (type && type->child &&
  978. ((!strcmp(type->child->value.text.string, "typedef") &&
  979. type->child->next &&
  980. (!strcmp(type->child->next->value.text.string, "struct") ||
  981. !strcmp(type->child->next->value.text.string, "union") ||
  982. !strcmp(type->child->next->value.text.string, "class"))) ||
  983. !strcmp(type->child->value.text.string, "union") ||
  984. !strcmp(type->child->value.text.string, "struct") ||
  985. !strcmp(type->child->value.text.string, "class")))
  986. {
  987. /*
  988. * Start of a class or structure...
  989. */
  990. if (!strcmp(type->child->value.text.string, "typedef"))
  991. {
  992. #ifdef DEBUG
  993. fputs(" starting typedef...\n", stderr);
  994. #endif /* DEBUG */
  995. typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef");
  996. mxmlDelete(type->child);
  997. }
  998. else
  999. typedefnode = NULL;
  1000. structclass = mxmlNewElement(MXML_NO_PARENT,
  1001. type->child->value.text.string);
  1002. #ifdef DEBUG
  1003. fprintf(stderr, "%c%s: <<<< %s >>>\n",
  1004. toupper(type->child->value.text.string[0]),
  1005. type->child->value.text.string + 1,
  1006. type->child->next ?
  1007. type->child->next->value.text.string : "(noname)");
  1008. fputs(" type =", stderr);
  1009. for (node = type->child; node; node = node->next)
  1010. fprintf(stderr, " \"%s\"", node->value.text.string);
  1011. putc('\n', stderr);
  1012. fprintf(stderr, " scope = %s\n", scope ? scope : "(null)");
  1013. #endif /* DEBUG */
  1014. if (type->child->next)
  1015. {
  1016. mxmlElementSetAttr(structclass, "name",
  1017. type->child->next->value.text.string);
  1018. sort_node(tree, structclass);
  1019. }
  1020. if (typedefnode && type->child)
  1021. type->child->value.text.whitespace = 0;
  1022. else if (structclass && type->child &&
  1023. type->child->next && type->child->next->next)
  1024. {
  1025. for (bufptr = buffer, node = type->child->next->next;
  1026. node;
  1027. bufptr += strlen(bufptr))
  1028. {
  1029. if (node->value.text.whitespace && bufptr > buffer)
  1030. *bufptr++ = ' ';
  1031. strcpy(bufptr, node->value.text.string);
  1032. next = node->next;
  1033. mxmlDelete(node);
  1034. node = next;
  1035. }
  1036. mxmlElementSetAttr(structclass, "parent", buffer);
  1037. mxmlDelete(type);
  1038. type = NULL;
  1039. }
  1040. else
  1041. {
  1042. mxmlDelete(type);
  1043. type = NULL;
  1044. }
  1045. if (typedefnode && comment->last_child)
  1046. {
  1047. /*
  1048. * Copy comment for typedef as well as class/struct/union...
  1049. */
  1050. mxmlNewText(comment, 0,
  1051. comment->last_child->value.text.string);
  1052. description = mxmlNewElement(typedefnode, "description");
  1053. #ifdef DEBUG
  1054. fprintf(stderr,
  1055. " duplicating comment %p/%p for typedef...\n",
  1056. comment->last_child, comment->child);
  1057. #endif /* DEBUG */
  1058. update_comment(typedefnode, comment->last_child);
  1059. mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
  1060. comment->last_child);
  1061. }
  1062. description = mxmlNewElement(structclass, "description");
  1063. #ifdef DEBUG
  1064. fprintf(stderr, " adding comment %p/%p to %s...\n",
  1065. comment->last_child, comment->child,
  1066. structclass->value.element.name);
  1067. #endif /* DEBUG */
  1068. update_comment(structclass, comment->last_child);
  1069. mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
  1070. comment->last_child);
  1071. if (scan_file(filename, fp, structclass))
  1072. {
  1073. mxmlDelete(comment);
  1074. return (-1);
  1075. }
  1076. #ifdef DEBUG
  1077. fputs(" ended typedef...\n", stderr);
  1078. #endif /* DEBUG */
  1079. structclass = NULL;
  1080. break;
  1081. }
  1082. else if (type && type->child && type->child->next &&
  1083. (!strcmp(type->child->value.text.string, "enum") ||
  1084. (!strcmp(type->child->value.text.string, "typedef") &&
  1085. !strcmp(type->child->next->value.text.string, "enum"))))
  1086. {
  1087. /*
  1088. * Enumeration type...
  1089. */
  1090. if (!strcmp(type->child->value.text.string, "typedef"))
  1091. {
  1092. #ifdef DEBUG
  1093. fputs(" starting typedef...\n", stderr);
  1094. #endif /* DEBUG */
  1095. typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef");
  1096. mxmlDelete(type->child);
  1097. }
  1098. else
  1099. typedefnode = NULL;
  1100. enumeration = mxmlNewElement(MXML_NO_PARENT, "enumeration");
  1101. #ifdef DEBUG
  1102. fprintf(stderr, "Enumeration: <<<< %s >>>\n",
  1103. type->child->next ?
  1104. type->child->next->value.text.string : "(noname)");
  1105. #endif /* DEBUG */
  1106. if (type->child->next)
  1107. {
  1108. mxmlElementSetAttr(enumeration, "name",
  1109. type->child->next->value.text.string);
  1110. sort_node(tree, enumeration);
  1111. }
  1112. if (typedefnode && type->child)
  1113. type->child->value.text.whitespace = 0;
  1114. else
  1115. {
  1116. mxmlDelete(type);
  1117. type = NULL;
  1118. }
  1119. if (typedefnode && comment->last_child)
  1120. {
  1121. /*
  1122. * Copy comment for typedef as well as class/struct/union...
  1123. */
  1124. mxmlNewText(comment, 0,
  1125. comment->last_child->value.text.string);
  1126. description = mxmlNewElement(typedefnode, "description");
  1127. #ifdef DEBUG
  1128. fprintf(stderr,
  1129. " duplicating comment %p/%p for typedef...\n",
  1130. comment->last_child, comment->child);
  1131. #endif /* DEBUG */
  1132. update_comment(typedefnode, comment->last_child);
  1133. mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
  1134. comment->last_child);
  1135. }
  1136. description = mxmlNewElement(enumeration, "description");
  1137. #ifdef DEBUG
  1138. fprintf(stderr, " adding comment %p/%p to enumeration...\n",
  1139. comment->last_child, comment->child);
  1140. #endif /* DEBUG */
  1141. update_comment(enumeration, comment->last_child);
  1142. mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
  1143. comment->last_child);
  1144. }
  1145. else if (type && type->child &&
  1146. !strcmp(type->child->value.text.string, "extern"))
  1147. {
  1148. if (scan_file(filename, fp, tree))
  1149. {
  1150. mxmlDelete(comment);
  1151. return (-1);
  1152. }
  1153. }
  1154. else if (type)
  1155. {
  1156. mxmlDelete(type);
  1157. type = NULL;
  1158. }
  1159. braces ++;
  1160. function = NULL;
  1161. variable = NULL;
  1162. break;
  1163. case '}' :
  1164. #ifdef DEBUG
  1165. fputs(" close brace...\n", stderr);
  1166. #endif /* DEBUG */
  1167. if (structclass)
  1168. scope = NULL;
  1169. if (!typedefnode)
  1170. enumeration = NULL;
  1171. constant = NULL;
  1172. structclass = NULL;
  1173. if (braces > 0)
  1174. braces --;
  1175. else
  1176. {
  1177. mxmlDelete(comment);
  1178. return (0);
  1179. }
  1180. break;
  1181. case '(' :
  1182. if (type)
  1183. {
  1184. #ifdef DEBUG
  1185. fputs("Identifier: <<<< ( >>>\n", stderr);
  1186. #endif /* DEBUG */
  1187. mxmlNewText(type, 0, "(");
  1188. }
  1189. parens ++;
  1190. break;
  1191. case ')' :
  1192. if (type && parens)
  1193. {
  1194. #ifdef DEBUG
  1195. fputs("Identifier: <<<< ) >>>\n", stderr);
  1196. #endif /* DEBUG */
  1197. mxmlNewText(type, 0, ")");
  1198. }
  1199. if (function && type && !parens)
  1200. {
  1201. /*
  1202. * Check for "void" argument...
  1203. */
  1204. if (type->child && type->child->next)
  1205. variable = add_variable(function, "argument", type);
  1206. else
  1207. mxmlDelete(type);
  1208. type = NULL;
  1209. }
  1210. if (parens > 0)
  1211. parens --;
  1212. break;
  1213. case ';' :
  1214. #ifdef DEBUG
  1215. fputs("Identifier: <<<< ; >>>\n", stderr);
  1216. fprintf(stderr, " enumeration=%p, function=%p, type=%p, type->child=%p, typedefnode=%p\n",
  1217. enumeration, function, type, type ? type->child : NULL, typedefnode);
  1218. #endif /* DEBUG */
  1219. if (function)
  1220. {
  1221. if (!strcmp(tree->value.element.name, "class"))
  1222. {
  1223. #ifdef DEBUG
  1224. fputs(" ADDING FUNCTION TO CLASS\n", stderr);
  1225. #endif /* DEBUG */
  1226. sort_node(tree, function);
  1227. }
  1228. else
  1229. mxmlDelete(function);
  1230. function = NULL;
  1231. variable = NULL;
  1232. }
  1233. if (type)
  1234. {
  1235. /*
  1236. * See if we have a typedef...
  1237. */
  1238. if (type->child &&
  1239. !strcmp(type->child->value.text.string, "typedef"))
  1240. {
  1241. /*
  1242. * Yes, add it!
  1243. */
  1244. typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef");
  1245. for (node = type->child->next; node; node = node->next)
  1246. if (!strcmp(node->value.text.string, "("))
  1247. break;
  1248. if (node)
  1249. {
  1250. for (node = node->next; node; node = node->next)
  1251. if (strcmp(node->value.text.string, "*"))
  1252. break;
  1253. }
  1254. if (!node)
  1255. node = type->last_child;
  1256. #ifdef DEBUG
  1257. fprintf(stderr, " ADDING TYPEDEF FOR %p(%s)...\n",
  1258. node, node->value.text.string);
  1259. #endif /* DEBUG */
  1260. mxmlElementSetAttr(typedefnode, "name",
  1261. node->value.text.string);
  1262. sort_node(tree, typedefnode);
  1263. if (type->child != node)
  1264. mxmlDelete(type->child);
  1265. mxmlDelete(node);
  1266. if (type->child)
  1267. type->child->value.text.whitespace = 0;
  1268. mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
  1269. type);
  1270. type = NULL;
  1271. break;
  1272. }
  1273. else if (typedefnode && enumeration)
  1274. {
  1275. /*
  1276. * Add enum typedef...
  1277. */
  1278. node = type->child;
  1279. #ifdef DEBUG
  1280. fprintf(stderr, " ADDING TYPEDEF FOR %p(%s)...\n",
  1281. node, node->value.text.string);
  1282. #endif /* DEBUG */
  1283. mxmlElementSetAttr(typedefnode, "name",
  1284. node->value.text.string);
  1285. sort_node(tree, typedefnode);
  1286. mxmlDelete(type);
  1287. type = mxmlNewElement(typedefnode, "type");
  1288. mxmlNewText(type, 0, "enum");
  1289. mxmlNewText(type, 1,
  1290. mxmlElementGetAttr(enumeration, "name"));
  1291. enumeration = NULL;
  1292. type = NULL;
  1293. break;
  1294. }
  1295. mxmlDelete(type);
  1296. type = NULL;
  1297. }
  1298. break;
  1299. case ':' :
  1300. if (type)
  1301. {
  1302. #ifdef DEBUG
  1303. fputs("Identifier: <<<< : >>>\n", stderr);
  1304. #endif /* DEBUG */
  1305. mxmlNewText(type, 1, ":");
  1306. }
  1307. break;
  1308. case '*' :
  1309. if (type)
  1310. {
  1311. #ifdef DEBUG
  1312. fputs("Identifier: <<<< * >>>\n", stderr);
  1313. #endif /* DEBUG */
  1314. ch = type->last_child->value.text.string[0];
  1315. mxmlNewText(type, isalnum(ch) || ch == '_', "*");
  1316. }
  1317. break;
  1318. case ',' :
  1319. if (type && !enumeration)
  1320. {
  1321. #ifdef DEBUG
  1322. fputs("Identifier: <<<< , >>>\n", stderr);
  1323. #endif /* DEBUG */
  1324. mxmlNewText(type, 0, ",");
  1325. }
  1326. break;
  1327. case '&' :
  1328. if (type)
  1329. {
  1330. #ifdef DEBUG
  1331. fputs("Identifier: <<<< & >>>\n", stderr);
  1332. #endif /* DEBUG */
  1333. mxmlNewText(type, 1, "&");
  1334. }
  1335. break;
  1336. case '+' :
  1337. if (type)
  1338. {
  1339. #ifdef DEBUG
  1340. fputs("Identifier: <<<< + >>>\n", stderr);
  1341. #endif /* DEBUG */
  1342. ch = type->last_child->value.text.string[0];
  1343. mxmlNewText(type, isalnum(ch) || ch == '_', "+");
  1344. }
  1345. break;
  1346. case '-' :
  1347. if (type)
  1348. {
  1349. #ifdef DEBUG
  1350. fputs("Identifier: <<<< - >>>\n", stderr);
  1351. #endif /* DEBUG */
  1352. ch = type->last_child->value.text.string[0];
  1353. mxmlNewText(type, isalnum(ch) || ch == '_', "-");
  1354. }
  1355. break;
  1356. case '=' :
  1357. if (type)
  1358. {
  1359. #ifdef DEBUG
  1360. fputs("Identifier: <<<< = >>>\n", stderr);
  1361. #endif /* DEBUG */
  1362. ch = type->last_child->value.text.string[0];
  1363. mxmlNewText(type, isalnum(ch) || ch == '_', "=");
  1364. }
  1365. break;
  1366. default : /* Other */
  1367. if (isalnum(ch) || ch == '_' || ch == '.' || ch == ':' || ch == '~')
  1368. {
  1369. state = STATE_IDENTIFIER;
  1370. bufptr = buffer;
  1371. *bufptr++ = ch;
  1372. }
  1373. break;
  1374. }
  1375. break;
  1376. case STATE_PREPROCESSOR : /* Preprocessor directive */
  1377. if (ch == '\n')
  1378. state = STATE_NONE;
  1379. else if (ch == '\\')
  1380. getc(fp);
  1381. break;
  1382. case STATE_C_COMMENT : /* Inside a C comment */
  1383. switch (ch)
  1384. {
  1385. case '\n' :
  1386. while ((ch = getc(fp)) != EOF)
  1387. if (ch == '*')
  1388. {
  1389. ch = getc(fp);
  1390. if (ch == '/')
  1391. {
  1392. *bufptr = '\0';
  1393. if (comment->child != comment->last_child)
  1394. {
  1395. #ifdef DEBUG
  1396. fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n",
  1397. comment->child,
  1398. comment->child ? comment->child->value.text.string : "",
  1399. comment->last_child,
  1400. comment->last_child ? comment->last_child->value.text.string : "");
  1401. #endif /* DEBUG */
  1402. mxmlDelete(comment->child);
  1403. #ifdef DEBUG
  1404. fprintf(stderr, " new comment %p, last comment %p...\n",
  1405. comment->child, comment->last_child);
  1406. #endif /* DEBUG */
  1407. }
  1408. #ifdef DEBUG
  1409. fprintf(stderr,
  1410. " processing comment, variable=%p, "
  1411. "constant=%p, typedefnode=%p, tree=\"%s\"\n",
  1412. variable, constant, typedefnode,
  1413. tree->value.element.name);
  1414. #endif /* DEBUG */
  1415. if (variable)
  1416. {
  1417. if (strstr(buffer, "@private@"))
  1418. {
  1419. /*
  1420. * Delete private variables...
  1421. */
  1422. mxmlDelete(variable);
  1423. }
  1424. else
  1425. {
  1426. description = mxmlNewElement(variable, "description");
  1427. #ifdef DEBUG
  1428. fprintf(stderr,
  1429. " adding comment %p/%p to variable...\n",
  1430. comment->last_child, comment->child);
  1431. #endif /* DEBUG */
  1432. mxmlNewText(comment, 0, buffer);
  1433. update_comment(variable,
  1434. mxmlNewText(description, 0, buffer));
  1435. }
  1436. variable = NULL;
  1437. }
  1438. else if (constant)
  1439. {
  1440. if (strstr(buffer, "@private@"))
  1441. {
  1442. /*
  1443. * Delete private constants...
  1444. */
  1445. mxmlDelete(constant);
  1446. }
  1447. else
  1448. {
  1449. description = mxmlNewElement(constant, "description");
  1450. #ifdef DEBUG
  1451. fprintf(stderr,
  1452. " adding comment %p/%p to constant...\n",
  1453. comment->last_child, comment->child);
  1454. #endif /* DEBUG */
  1455. mxmlNewText(comment, 0, buffer);
  1456. update_comment(constant,
  1457. mxmlNewText(description, 0, buffer));
  1458. }
  1459. constant = NULL;
  1460. }
  1461. else if (typedefnode)
  1462. {
  1463. if (strstr(buffer, "@private@"))
  1464. {
  1465. /*
  1466. * Delete private typedefs...
  1467. */
  1468. mxmlDelete(typedefnode);
  1469. if (structclass)
  1470. {
  1471. mxmlDelete(structclass);
  1472. structclass = NULL;
  1473. }
  1474. if (enumeration)
  1475. {
  1476. mxmlDelete(enumeration);
  1477. enumeration = NULL;
  1478. }
  1479. }
  1480. else
  1481. {
  1482. description = mxmlNewElement(typedefnode, "description");
  1483. #ifdef DEBUG
  1484. fprintf(stderr,
  1485. " adding comment %p/%p to typedef %s...\n",
  1486. comment->last_child, comment->child,
  1487. mxmlElementGetAttr(typedefnode, "name"));
  1488. #endif /* DEBUG */
  1489. mxmlNewText(comment, 0, buffer);
  1490. update_comment(typedefnode,
  1491. mxmlNewText(description, 0, buffer));
  1492. if (structclass)
  1493. {
  1494. description = mxmlNewElement(structclass, "description");
  1495. update_comment(structclass,
  1496. mxmlNewText(description, 0, buffer));
  1497. }
  1498. else if (enumeration)
  1499. {
  1500. description = mxmlNewElement(enumeration, "description");
  1501. update_comment(enumeration,
  1502. mxmlNewText(description, 0, buffer));
  1503. }
  1504. }
  1505. typedefnode = NULL;
  1506. }
  1507. else if (strcmp(tree->value.element.name, "mxmldoc") &&
  1508. !mxmlFindElement(tree, tree, "description",
  1509. NULL, NULL, MXML_DESCEND_FIRST))
  1510. {
  1511. description = mxmlNewElement(tree, "description");
  1512. #ifdef DEBUG
  1513. fprintf(stderr, " adding comment %p/%p to parent...\n",
  1514. comment->last_child, comment->child);
  1515. #endif /* DEBUG */
  1516. mxmlNewText(comment, 0, buffer);
  1517. update_comment(tree,
  1518. mxmlNewText(description, 0, buffer));
  1519. }
  1520. else
  1521. {
  1522. #ifdef DEBUG
  1523. fprintf(stderr, " before adding comment, child=%p, last_child=%p\n",
  1524. comment->child, comment->last_child);
  1525. #endif /* DEBUG */
  1526. mxmlNewText(comment, 0, buffer);
  1527. #ifdef DEBUG
  1528. fprintf(stderr, " after adding comment, child=%p, last_child=%p\n",
  1529. comment->child, comment->last_child);
  1530. #endif /* DEBUG */
  1531. }
  1532. #ifdef DEBUG
  1533. fprintf(stderr, "C comment: <<<< %s >>>\n", buffer);
  1534. #endif /* DEBUG */
  1535. state = STATE_NONE;
  1536. break;
  1537. }
  1538. else
  1539. ungetc(ch, fp);
  1540. }
  1541. else if (ch == '\n' && bufptr > buffer &&
  1542. bufptr < (buffer + sizeof(buffer) - 1))
  1543. *bufptr++ = ch;
  1544. else if (!isspace(ch))
  1545. break;
  1546. if (ch != EOF)
  1547. ungetc(ch, fp);
  1548. if (bufptr > buffer && bufptr < (buffer + sizeof(buffer) - 1))
  1549. *bufptr++ = '\n';
  1550. break;
  1551. case '/' :
  1552. if (ch == '/' && bufptr > buffer && bufptr[-1] == '*')
  1553. {
  1554. while (bufptr > buffer &&
  1555. (bufptr[-1] == '*' || isspace(bufptr[-1] & 255)))
  1556. bufptr --;
  1557. *bufptr = '\0';
  1558. if (comment->child != comment->last_child)
  1559. {
  1560. #ifdef DEBUG
  1561. fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n",
  1562. comment->child,
  1563. comment->child ? comment->child->value.text.string : "",
  1564. comment->last_child,
  1565. comment->last_child ? comment->last_child->value.text.string : "");
  1566. #endif /* DEBUG */
  1567. mxmlDelete(comment->child);
  1568. #ifdef DEBUG
  1569. fprintf(stderr, " new comment %p, last comment %p...\n",
  1570. comment->child, comment->last_child);
  1571. #endif /* DEBUG */
  1572. }
  1573. #ifdef DEBUG
  1574. fprintf(stderr,
  1575. " processing comment, variable=%p, "
  1576. "constant=%p, typedefnode=%p, tree=\"%s\"\n",
  1577. variable, constant, typedefnode,
  1578. tree->value.element.name);
  1579. #endif /* DEBUG */
  1580. if (variable)
  1581. {
  1582. if (strstr(buffer, "@private@"))
  1583. {
  1584. /*
  1585. * Delete private variables...
  1586. */
  1587. mxmlDelete(variable);
  1588. }
  1589. else
  1590. {
  1591. description = mxmlNewElement(variable, "description");
  1592. #ifdef DEBUG
  1593. fprintf(stderr, " adding comment %p/%p to variable...\n",
  1594. comment->last_child, comment->child);
  1595. #endif /* DEBUG */
  1596. mxmlNewText(comment, 0, buffer);
  1597. update_comment(variable,
  1598. mxmlNewText(description, 0, buffer));
  1599. }
  1600. variable = NULL;
  1601. }
  1602. else if (constant)
  1603. {
  1604. if (strstr(buffer, "@private@"))
  1605. {
  1606. /*
  1607. * Delete private constants...
  1608. */
  1609. mxmlDelete(constant);
  1610. }
  1611. else
  1612. {
  1613. description = mxmlNewElement(constant, "description");
  1614. #ifdef DEBUG
  1615. fprintf(stderr, " adding comment %p/%p to constant...\n",
  1616. comment->last_child, comment->child);
  1617. #endif /* DEBUG */
  1618. mxmlNewText(comment, 0, buffer);
  1619. update_comment(constant,
  1620. mxmlNewText(description, 0, buffer));
  1621. }
  1622. constant = NULL;
  1623. }
  1624. else if (typedefnode)
  1625. {
  1626. if (strstr(buffer, "@private@"))
  1627. {
  1628. /*
  1629. * Delete private typedefs...
  1630. */
  1631. mxmlDelete(typedefnode);
  1632. if (structclass)
  1633. {
  1634. mxmlDelete(structclass);
  1635. structclass = NULL;
  1636. }
  1637. if (enumeration)
  1638. {
  1639. mxmlDelete(enumeration);
  1640. enumeration = NULL;
  1641. }
  1642. }
  1643. else
  1644. {
  1645. description = mxmlNewElement(typedefnode, "description");
  1646. #ifdef DEBUG
  1647. fprintf(stderr,
  1648. " adding comment %p/%p to typedef %s...\n",
  1649. comment->last_child, comment->child,
  1650. mxmlElementGetAttr(typedefnode, "name"));
  1651. #endif /* DEBUG */
  1652. mxmlNewText(comment, 0, buffer);
  1653. update_comment(typedefnode,
  1654. mxmlNewText(description, 0, buffer));
  1655. if (structclass)
  1656. {
  1657. description = mxmlNewElement(structclass, "description");
  1658. update_comment(structclass,
  1659. mxmlNewText(description, 0, buffer));
  1660. }
  1661. else if (enumeration)
  1662. {
  1663. description = mxmlNewElement(enumeration, "description");
  1664. update_comment(enumeration,
  1665. mxmlNewText(description, 0, buffer));
  1666. }
  1667. }
  1668. typedefnode = NULL;
  1669. }
  1670. else if (strcmp(tree->value.element.name, "mxmldoc") &&
  1671. !mxmlFindElement(tree, tree, "description",
  1672. NULL, NULL, MXML_DESCEND_FIRST))
  1673. {
  1674. description = mxmlNewElement(tree, "description");
  1675. #ifdef DEBUG
  1676. fprintf(stderr, " adding comment %p/%p to parent...\n",
  1677. comment->last_child, comment->child);
  1678. #endif /* DEBUG */
  1679. mxmlNewText(comment, 0, buffer);
  1680. update_comment(tree,
  1681. mxmlNewText(description, 0, buffer));
  1682. }
  1683. else
  1684. mxmlNewText(comment, 0, buffer);
  1685. #ifdef DEBUG
  1686. fprintf(stderr, "C comment: <<<< %s >>>\n", buffer);
  1687. #endif /* DEBUG */
  1688. state = STATE_NONE;
  1689. break;
  1690. }
  1691. default :
  1692. if (ch == ' ' && bufptr == buffer)
  1693. break;
  1694. if (bufptr < (buffer + sizeof(buffer) - 1))
  1695. *bufptr++ = ch;
  1696. break;
  1697. }
  1698. break;
  1699. case STATE_CXX_COMMENT : /* Inside a C++ comment */
  1700. if (ch == '\n')
  1701. {
  1702. state = STATE_NONE;
  1703. *bufptr = '\0';
  1704. if (comment->child != comment->last_child)
  1705. {
  1706. #ifdef DEBUG
  1707. fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n",
  1708. comment->child,
  1709. comment->child ? comment->child->value.text.string : "",
  1710. comment->last_child,
  1711. comment->last_child ? comment->last_child->value.text.string : "");
  1712. #endif /* DEBUG */
  1713. mxmlDelete(comment->child);
  1714. #ifdef DEBUG
  1715. fprintf(stderr, " new comment %p, last comment %p...\n",
  1716. comment->child, comment->last_child);
  1717. #endif /* DEBUG */
  1718. }
  1719. if (variable)
  1720. {
  1721. if (strstr(buffer, "@private@"))
  1722. {
  1723. /*
  1724. * Delete private variables...
  1725. */
  1726. mxmlDelete(variable);
  1727. }
  1728. else
  1729. {
  1730. description = mxmlNewElement(variable, "description");
  1731. #ifdef DEBUG
  1732. fprintf(stderr, " adding comment %p/%p to variable...\n",
  1733. comment->last_child, comment->child);
  1734. #endif /* DEBUG */
  1735. mxmlNewText(comment, 0, buffer);
  1736. update_comment(variable,
  1737. mxmlNewText(description, 0, buffer));
  1738. }
  1739. variable = NULL;
  1740. }
  1741. else if (constant)
  1742. {
  1743. if (strstr(buffer, "@private@"))
  1744. {
  1745. /*
  1746. * Delete private constants...
  1747. */
  1748. mxmlDelete(constant);
  1749. }
  1750. else
  1751. {
  1752. description = mxmlNewElement(constant, "description");
  1753. #ifdef DEBUG
  1754. fprintf(stderr, " adding comment %p/%p to constant...\n",
  1755. comment->last_child, comment->child);
  1756. #endif /* DEBUG */
  1757. mxmlNewText(comment, 0, buffer);
  1758. update_comment(constant,
  1759. mxmlNewText(description, 0, buffer));
  1760. }
  1761. constant = NULL;
  1762. }
  1763. else if (typedefnode)
  1764. {
  1765. if (strstr(buffer, "@private@"))
  1766. {
  1767. /*
  1768. * Delete private typedefs...
  1769. */
  1770. mxmlDelete(typedefnode);
  1771. typedefnode = NULL;
  1772. if (structclass)
  1773. {
  1774. mxmlDelete(structclass);
  1775. structclass = NULL;
  1776. }
  1777. if (enumeration)
  1778. {
  1779. mxmlDelete(enumeration);
  1780. enumeration = NULL;
  1781. }
  1782. }
  1783. else
  1784. {
  1785. description = mxmlNewElement(typedefnode, "description");
  1786. #ifdef DEBUG
  1787. fprintf(stderr, " adding comment %p/%p to typedef %s...\n",
  1788. comment->last_child, comment->child,
  1789. mxmlElementGetAttr(typedefnode, "name"));
  1790. #endif /* DEBUG */
  1791. mxmlNewText(comment, 0, buffer);
  1792. update_comment(typedefnode,
  1793. mxmlNewText(description, 0, buffer));
  1794. if (structclass)
  1795. {
  1796. description = mxmlNewElement(structclass, "description");
  1797. update_comment(structclass,
  1798. mxmlNewText(description, 0, buffer));
  1799. }
  1800. else if (enumeration)
  1801. {
  1802. description = mxmlNewElement(enumeration, "description");
  1803. update_comment(enumeration,
  1804. mxmlNewText(description, 0, buffer));
  1805. }
  1806. }
  1807. }
  1808. else if (strcmp(tree->value.element.name, "mxmldoc") &&
  1809. !mxmlFindElement(tree, tree, "description",
  1810. NULL, NULL, MXML_DESCEND_FIRST))
  1811. {
  1812. description = mxmlNewElement(tree, "description");
  1813. #ifdef DEBUG
  1814. fprintf(stderr, " adding comment %p/%p to parent...\n",
  1815. comment->last_child, comment->child);
  1816. #endif /* DEBUG */
  1817. mxmlNewText(comment, 0, buffer);
  1818. update_comment(tree,
  1819. mxmlNewText(description, 0, buffer));
  1820. }
  1821. else
  1822. mxmlNewText(comment, 0, buffer);
  1823. #ifdef DEBUG
  1824. fprintf(stderr, "C++ comment: <<<< %s >>>\n", buffer);
  1825. #endif /* DEBUG */
  1826. }
  1827. else if (ch == ' ' && bufptr == buffer)
  1828. break;
  1829. else if (bufptr < (buffer + sizeof(buffer) - 1))
  1830. *bufptr++ = ch;
  1831. break;
  1832. case STATE_STRING : /* Inside a string constant */
  1833. *bufptr++ = ch;
  1834. if (ch == '\\')
  1835. *bufptr++ = getc(fp);
  1836. else if (ch == '\"')
  1837. {
  1838. *bufptr = '\0';
  1839. if (type)
  1840. mxmlNewText(type, type->child != NULL, buffer);
  1841. state = STATE_NONE;
  1842. }
  1843. break;
  1844. case STATE_CHARACTER : /* Inside a character constant */
  1845. *bufptr++ = ch;
  1846. if (ch == '\\')
  1847. *bufptr++ = getc(fp);
  1848. else if (ch == '\'')
  1849. {
  1850. *bufptr = '\0';
  1851. if (type)
  1852. mxmlNewText(type, type->child != NULL, buffer);
  1853. state = STATE_NONE;
  1854. }
  1855. break;
  1856. case STATE_IDENTIFIER : /* Inside a keyword or identifier */
  1857. if (isalnum(ch) || ch == '_' || ch == '[' || ch == ']' ||
  1858. (ch == ',' && (parens > 1 || (type && !enumeration && !function))) ||
  1859. ch == ':' || ch == '.' || ch == '~')
  1860. {
  1861. if (bufptr < (buffer + sizeof(buffer) - 1))
  1862. *bufptr++ = ch;
  1863. }
  1864. else
  1865. {
  1866. ungetc(ch, fp);
  1867. *bufptr = '\0';
  1868. state = STATE_NONE;
  1869. #ifdef DEBUG
  1870. fprintf(stderr, " braces=%d, type=%p, type->child=%p, buffer=\"%s\"\n",
  1871. braces, type, type ? type->child : NULL, buffer);
  1872. #endif /* DEBUG */
  1873. if (!braces)
  1874. {
  1875. if (!type || !type->child)
  1876. {
  1877. if (!strcmp(tree->value.element.name, "class"))
  1878. {
  1879. if (!strcmp(buffer, "public") ||
  1880. !strcmp(buffer, "public:"))
  1881. {
  1882. scope = "public";
  1883. #ifdef DEBUG
  1884. fputs(" scope = public\n", stderr);
  1885. #endif /* DEBUG */
  1886. break;
  1887. }
  1888. else if (!strcmp(buffer, "private") ||
  1889. !strcmp(buffer, "private:"))
  1890. {
  1891. scope = "private";
  1892. #ifdef DEBUG
  1893. fputs(" scope = private\n", stderr);
  1894. #endif /* DEBUG */
  1895. break;
  1896. }
  1897. else if (!strcmp(buffer, "protected") ||
  1898. !strcmp(buffer, "protected:"))
  1899. {
  1900. scope = "protected";
  1901. #ifdef DEBUG
  1902. fputs(" scope = protected\n", stderr);
  1903. #endif /* DEBUG */
  1904. break;
  1905. }
  1906. }
  1907. }
  1908. if (!type)
  1909. type = mxmlNewElement(MXML_NO_PARENT, "type");
  1910. #ifdef DEBUG
  1911. fprintf(stderr, " function=%p (%s), type->child=%p, ch='%c', parens=%d\n",
  1912. function,
  1913. function ? mxmlElementGetAttr(function, "name") : "null",
  1914. type->child, ch, parens);
  1915. #endif /* DEBUG */
  1916. if (!function && ch == '(')
  1917. {
  1918. if (type->child &&
  1919. !strcmp(type->child->value.text.string, "extern"))
  1920. {
  1921. /*
  1922. * Remove external declarations...
  1923. */
  1924. mxmlDelete(type);
  1925. type = NULL;
  1926. break;
  1927. }
  1928. if (type->child &&
  1929. !strcmp(type->child->value.text.string, "static") &&
  1930. !strcmp(tree->value.element.name, "mxmldoc"))
  1931. {
  1932. /*
  1933. * Remove static functions...
  1934. */
  1935. mxmlDelete(type);
  1936. type = NULL;
  1937. break;
  1938. }
  1939. function = mxmlNewElement(MXML_NO_PARENT, "function");
  1940. if ((bufptr = strchr(buffer, ':')) != NULL && bufptr[1] == ':')
  1941. {
  1942. *bufptr = '\0';
  1943. bufptr += 2;
  1944. if ((fstructclass =
  1945. mxmlFindElement(tree, tree, "class", "name", buffer,
  1946. MXML_DESCEND_FIRST)) == NULL)
  1947. fstructclass =
  1948. mxmlFindElement(tree, tree, "struct", "name", buffer,
  1949. MXML_DESCEND_FIRST);
  1950. }
  1951. else
  1952. bufptr = buffer;
  1953. mxmlElementSetAttr(function, "name", bufptr);
  1954. if (scope)
  1955. mxmlElementSetAttr(function, "scope", scope);
  1956. #ifdef DEBUG
  1957. fprintf(stderr, "function: %s\n", buffer);
  1958. fprintf(stderr, " scope = %s\n", scope ? scope : "(null)");
  1959. fprintf(stderr, " comment = %p\n", comment);
  1960. fprintf(stderr, " child = (%p) %s\n",
  1961. comment->child,
  1962. comment->child ?
  1963. comment->child->value.text.string : "(null)");
  1964. fprintf(stderr, " last_child = (%p) %s\n",
  1965. comment->last_child,
  1966. comment->last_child ?
  1967. comment->last_child->value.text.string : "(null)");
  1968. #endif /* DEBUG */
  1969. if (type->last_child &&
  1970. strcmp(type->last_child->value.text.string, "void"))
  1971. {
  1972. returnvalue = mxmlNewElement(function, "returnvalue");
  1973. mxmlAdd(returnvalue, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type);
  1974. description = mxmlNewElement(returnvalue, "description");
  1975. #ifdef DEBUG
  1976. fprintf(stderr, " adding comment %p/%p to returnvalue...\n",
  1977. comment->last_child, comment->child);
  1978. #endif /* DEBUG */
  1979. update_comment(returnvalue, comment->last_child);
  1980. mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
  1981. comment->last_child);
  1982. }
  1983. else
  1984. mxmlDelete(type);
  1985. description = mxmlNewElement(function, "description");
  1986. #ifdef DEBUG
  1987. fprintf(stderr, " adding comment %p/%p to function...\n",
  1988. comment->last_child, comment->child);
  1989. #endif /* DEBUG */
  1990. update_comment(function, comment->last_child);
  1991. mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
  1992. comment->last_child);
  1993. type = NULL;
  1994. }
  1995. else if (function && ((ch == ')' && parens == 1) || ch == ','))
  1996. {
  1997. /*
  1998. * Argument definition...
  1999. */
  2000. if (strcmp(buffer, "void"))
  2001. {
  2002. mxmlNewText(type, type->child != NULL &&
  2003. type->last_child->value.text.string[0] != '(' &&
  2004. type->last_child->value.text.string[0] != '*',
  2005. buffer);
  2006. #ifdef DEBUG
  2007. fprintf(stderr, "Argument: <<<< %s >>>\n", buffer);
  2008. #endif /* DEBUG */
  2009. variable = add_variable(function, "argument", type);
  2010. }
  2011. else
  2012. mxmlDelete(type);
  2013. type = NULL;
  2014. }
  2015. else if (type->child && !function && (ch == ';' || ch == ','))
  2016. {
  2017. #ifdef DEBUG
  2018. fprintf(stderr, " got semicolon, typedefnode=%p, structclass=%p\n",
  2019. typedefnode, structclass);
  2020. #endif /* DEBUG */
  2021. if (typedefnode || structclass)
  2022. {
  2023. #ifdef DEBUG
  2024. fprintf(stderr, "Typedef/struct/class: <<<< %s >>>>\n", buffer);
  2025. #endif /* DEBUG */
  2026. if (typedefnode)
  2027. {
  2028. mxmlElementSetAttr(typedefnode, "name", buffer);
  2029. sort_node(tree, typedefnode);
  2030. }
  2031. if (structclass && !mxmlElementGetAttr(structclass, "name"))
  2032. {
  2033. #ifdef DEBUG
  2034. fprintf(stderr, "setting struct/class name to %s!\n",
  2035. type->last_child->value.text.string);
  2036. #endif /* DEBUG */
  2037. mxmlElementSetAttr(structclass, "name", buffer);
  2038. sort_node(tree, structclass);
  2039. structclass = NULL;
  2040. }
  2041. if (typedefnode)
  2042. mxmlAdd(typedefnode, MXML_ADD_BEFORE, MXML_ADD_TO_PARENT,
  2043. type);
  2044. else
  2045. mxmlDelete(type);
  2046. type = NULL;
  2047. typedefnode = NULL;
  2048. }
  2049. else if (type->child &&
  2050. !strcmp(type->child->value.text.string, "typedef"))
  2051. {
  2052. /*
  2053. * Simple typedef...
  2054. */
  2055. #ifdef DEBUG
  2056. fprintf(stderr, "Typedef: <<<< %s >>>\n", buffer);
  2057. #endif /* DEBUG */
  2058. typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef");
  2059. mxmlElementSetAttr(typedefnode, "name", buffer);
  2060. mxmlDelete(type->child);
  2061. sort_node(tree, typedefnode);
  2062. if (type->child)
  2063. type->child->value.text.whitespace = 0;
  2064. mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type);
  2065. type = NULL;
  2066. }
  2067. else if (!parens)
  2068. {
  2069. /*
  2070. * Variable definition...
  2071. */
  2072. if (type->child &&
  2073. !strcmp(type->child->value.text.string, "static") &&
  2074. !strcmp(tree->value.element.name, "mxmldoc"))
  2075. {
  2076. /*
  2077. * Remove static functions...
  2078. */
  2079. mxmlDelete(type);
  2080. type = NULL;
  2081. break;
  2082. }
  2083. mxmlNewText(type, type->child != NULL &&
  2084. type->last_child->value.text.string[0] != '(' &&
  2085. type->last_child->value.text.string[0] != '*',
  2086. buffer);
  2087. #ifdef DEBUG
  2088. fprintf(stderr, "Variable: <<<< %s >>>>\n", buffer);
  2089. fprintf(stderr, " scope = %s\n", scope ? scope : "(null)");
  2090. #endif /* DEBUG */
  2091. variable = add_variable(MXML_NO_PARENT, "variable", type);
  2092. type = NULL;
  2093. sort_node(tree, variable);
  2094. if (scope)
  2095. mxmlElementSetAttr(variable, "scope", scope);
  2096. }
  2097. }
  2098. else
  2099. {
  2100. #ifdef DEBUG
  2101. fprintf(stderr, "Identifier: <<<< %s >>>>\n", buffer);
  2102. #endif /* DEBUG */
  2103. mxmlNewText(type, type->child != NULL &&
  2104. type->last_child->value.text.string[0] != '(' &&
  2105. type->last_child->value.text.string[0] != '*',
  2106. buffer);
  2107. }
  2108. }
  2109. else if (enumeration && !isdigit(buffer[0] & 255))
  2110. {
  2111. #ifdef DEBUG
  2112. fprintf(stderr, "Constant: <<<< %s >>>\n", buffer);
  2113. #endif /* DEBUG */
  2114. constant = mxmlNewElement(MXML_NO_PARENT, "constant");
  2115. mxmlElementSetAttr(constant, "name", buffer);
  2116. sort_node(enumeration, constant);
  2117. }
  2118. else if (type)
  2119. {
  2120. mxmlDelete(type);
  2121. type = NULL;
  2122. }
  2123. }
  2124. break;
  2125. }
  2126. #if DEBUG > 1
  2127. if (state != oldstate)
  2128. {
  2129. fprintf(stderr, " changed states from %s to %s on receipt of character '%c'...\n",
  2130. states[oldstate], states[state], oldch);
  2131. fprintf(stderr, " variable = %p\n", variable);
  2132. if (type)
  2133. {
  2134. fputs(" type =", stderr);
  2135. for (temp = type->child; temp; temp = temp->next)
  2136. fprintf(stderr, " \"%s\"", temp->value.text.string);
  2137. fputs("\n", stderr);
  2138. }
  2139. }
  2140. #endif /* DEBUG > 1 */
  2141. }
  2142. mxmlDelete(comment);
  2143. /*
  2144. * All done, return with no errors...
  2145. */
  2146. return (0);
  2147. }
  2148. /*
  2149. * 'sort_node()' - Insert a node sorted into a tree.
  2150. */
  2151. static void
  2152. sort_node(mxml_node_t *tree, /* I - Tree to sort into */
  2153. mxml_node_t *node) /* I - Node to add */
  2154. {
  2155. mxml_node_t *temp; /* Current node */
  2156. const char *tempname, /* Name of current node */
  2157. *nodename, /* Name of node */
  2158. *scope; /* Scope */
  2159. #if DEBUG > 1
  2160. fprintf(stderr, " sort_node(tree=%p, node=%p)\n", tree, node);
  2161. #endif /* DEBUG > 1 */
  2162. /*
  2163. * Range check input...
  2164. */
  2165. if (!tree || !node || node->parent == tree)
  2166. return;
  2167. /*
  2168. * Get the node name...
  2169. */
  2170. if ((nodename = mxmlElementGetAttr(node, "name")) == NULL)
  2171. return;
  2172. if (nodename[0] == '_')
  2173. return; /* Hide private names */
  2174. #if DEBUG > 1
  2175. fprintf(stderr, " nodename=%p (\"%s\")\n", nodename, nodename);
  2176. #endif /* DEBUG > 1 */
  2177. /*
  2178. * Delete any existing definition at this level, if one exists...
  2179. */
  2180. if ((temp = mxmlFindElement(tree, tree, node->value.element.name,
  2181. "name", nodename, MXML_DESCEND_FIRST)) != NULL)
  2182. {
  2183. /*
  2184. * Copy the scope if needed...
  2185. */
  2186. if ((scope = mxmlElementGetAttr(temp, "scope")) != NULL &&
  2187. mxmlElementGetAttr(node, "scope") == NULL)
  2188. {
  2189. #ifdef DEBUG
  2190. fprintf(stderr, " copying scope %s for %s\n", scope, nodename);
  2191. #endif /* DEBUG */
  2192. mxmlElementSetAttr(node, "scope", scope);
  2193. }
  2194. mxmlDelete(temp);
  2195. }
  2196. /*
  2197. * Add the node into the tree at the proper place...
  2198. */
  2199. for (temp = tree->child; temp; temp = temp->next)
  2200. {
  2201. #if DEBUG > 1
  2202. fprintf(stderr, " temp=%p\n", temp);
  2203. #endif /* DEBUG > 1 */
  2204. if ((tempname = mxmlElementGetAttr(temp, "name")) == NULL)
  2205. continue;
  2206. #if DEBUG > 1
  2207. fprintf(stderr, " tempname=%p (\"%s\")\n", tempname, tempname);
  2208. #endif /* DEBUG > 1 */
  2209. if (strcmp(nodename, tempname) < 0)
  2210. break;
  2211. }
  2212. if (temp)
  2213. mxmlAdd(tree, MXML_ADD_BEFORE, temp, node);
  2214. else
  2215. mxmlAdd(tree, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, node);
  2216. }
  2217. /*
  2218. * 'update_comment()' - Update a comment node.
  2219. */
  2220. static void
  2221. update_comment(mxml_node_t *parent, /* I - Parent node */
  2222. mxml_node_t *comment) /* I - Comment node */
  2223. {
  2224. char *ptr; /* Pointer into comment */
  2225. #ifdef DEBUG
  2226. fprintf(stderr, "update_comment(parent=%p, comment=%p)\n",
  2227. parent, comment);
  2228. #endif /* DEBUG */
  2229. /*
  2230. * Range check the input...
  2231. */
  2232. if (!parent || !comment)
  2233. return;
  2234. /*
  2235. * Convert "\/" to "/"...
  2236. */
  2237. for (ptr = strstr(comment->value.text.string, "\\/");
  2238. ptr;
  2239. ptr = strstr(ptr, "\\/"))
  2240. safe_strcpy(ptr, ptr + 1);
  2241. /*
  2242. * Update the comment...
  2243. */
  2244. ptr = comment->value.text.string;
  2245. if (*ptr == '\'')
  2246. {
  2247. /*
  2248. * Convert "'name()' - description" to "description".
  2249. */
  2250. for (ptr ++; *ptr && *ptr != '\''; ptr ++);
  2251. if (*ptr == '\'')
  2252. {
  2253. ptr ++;
  2254. while (isspace(*ptr & 255))
  2255. ptr ++;
  2256. if (*ptr == '-')
  2257. ptr ++;
  2258. while (isspace(*ptr & 255))
  2259. ptr ++;
  2260. safe_strcpy(comment->value.text.string, ptr);
  2261. }
  2262. }
  2263. else if (!strncmp(ptr, "I ", 2) || !strncmp(ptr, "O ", 2) ||
  2264. !strncmp(ptr, "IO ", 3))
  2265. {
  2266. /*
  2267. * 'Convert "I - description", "IO - description", or "O - description"
  2268. * to description + direction attribute.
  2269. */
  2270. ptr = strchr(ptr, ' ');
  2271. *ptr++ = '\0';
  2272. if (!strcmp(parent->value.element.name, "argument"))
  2273. mxmlElementSetAttr(parent, "direction", comment->value.text.string);
  2274. while (isspace(*ptr & 255))
  2275. ptr ++;
  2276. if (*ptr == '-')
  2277. ptr ++;
  2278. while (isspace(*ptr & 255))
  2279. ptr ++;
  2280. safe_strcpy(comment->value.text.string, ptr);
  2281. }
  2282. /*
  2283. * Eliminate leading and trailing *'s...
  2284. */
  2285. for (ptr = comment->value.text.string; *ptr == '*'; ptr ++);
  2286. for (; isspace(*ptr & 255); ptr ++);
  2287. if (ptr > comment->value.text.string)
  2288. safe_strcpy(comment->value.text.string, ptr);
  2289. for (ptr = comment->value.text.string + strlen(comment->value.text.string) - 1;
  2290. ptr > comment->value.text.string && *ptr == '*';
  2291. ptr --)
  2292. *ptr = '\0';
  2293. for (; ptr > comment->value.text.string && isspace(*ptr & 255); ptr --)
  2294. *ptr = '\0';
  2295. #ifdef DEBUG
  2296. fprintf(stderr, " updated comment = %s\n", comment->value.text.string);
  2297. #endif /* DEBUG */
  2298. }
  2299. /*
  2300. * 'usage()' - Show program usage...
  2301. */
  2302. static void
  2303. usage(const char *option) /* I - Unknown option */
  2304. {
  2305. if (option)
  2306. printf("mxmldoc: Bad option \"%s\"!\n\n", option);
  2307. puts("Usage: mxmldoc [options] [filename.xml] [source files] >filename.html");
  2308. puts("Options:");
  2309. puts(" --css filename.css Set CSS stylesheet file");
  2310. puts(" --docset bundleid.docset Generate documentation set");
  2311. puts(" --docversion version Set documentation version");
  2312. puts(" --feedname name Set documentation set feed name");
  2313. puts(" --feedurl url Set documentation set feed URL");
  2314. puts(" --footer footerfile Set footer file");
  2315. puts(" --framed basename Generate framed HTML to basename*.html");
  2316. puts(" --header headerfile Set header file");
  2317. puts(" --intro introfile Set introduction file");
  2318. puts(" --man name Generate man page");
  2319. puts(" --no-output Do no generate documentation file");
  2320. puts(" --section section Set section name");
  2321. puts(" --title title Set documentation title");
  2322. puts(" --tokens path Generate Xcode docset Tokens.xml file");
  2323. puts(" --version Show mxmldoc/Mini-XML version");
  2324. exit(1);
  2325. }
  2326. /*
  2327. * 'write_description()' - Write the description text.
  2328. */
  2329. static void
  2330. write_description(
  2331. FILE *out, /* I - Output file */
  2332. mxml_node_t *description, /* I - Description node */
  2333. const char *element, /* I - HTML element, if any */
  2334. int summary) /* I - Show summary */
  2335. {
  2336. char text[10240], /* Text for description */
  2337. *start, /* Start of code/link */
  2338. *ptr; /* Pointer into text */
  2339. int col; /* Current column */
  2340. if (!description)
  2341. return;
  2342. get_text(description, text, sizeof(text));
  2343. ptr = strstr(text, "\n\n");
  2344. if (summary)
  2345. {
  2346. if (ptr)
  2347. *ptr = '\0';
  2348. ptr = text;
  2349. }
  2350. else if (!ptr || !ptr[2])
  2351. return;
  2352. else
  2353. ptr += 2;
  2354. if (element && *element)
  2355. fprintf(out, "<%s class=\"%s\">", element,
  2356. summary ? "description" : "discussion");
  2357. else if (!summary)
  2358. fputs(".PP\n", out);
  2359. for (col = 0; *ptr; ptr ++)
  2360. {
  2361. if (*ptr == '@' &&
  2362. (!strncmp(ptr + 1, "deprecated@", 11) ||
  2363. !strncmp(ptr + 1, "since ", 6)))
  2364. {
  2365. ptr ++;
  2366. while (*ptr && *ptr != '@')
  2367. ptr ++;
  2368. if (!*ptr)
  2369. return;
  2370. }
  2371. else if (!strncmp(ptr, "@code ", 6))
  2372. {
  2373. for (ptr += 6; isspace(*ptr & 255); ptr ++);
  2374. for (start = ptr, ptr ++; *ptr && *ptr != '@'; ptr ++);
  2375. if (*ptr)
  2376. *ptr = '\0';
  2377. else
  2378. ptr --;
  2379. if (element && *element)
  2380. {
  2381. fputs("<code>", out);
  2382. for (; *start; start ++)
  2383. {
  2384. if (*start == '<')
  2385. fputs("&lt;", out);
  2386. else if (*start == '>')
  2387. fputs("&gt;", out);
  2388. else if (*start == '&')
  2389. fputs("&amp;", out);
  2390. else
  2391. putc(*start, out);
  2392. }
  2393. fputs("</code>", out);
  2394. }
  2395. else if (element)
  2396. fputs(start, out);
  2397. else
  2398. fprintf(out, "\\fB%s\\fR", start);
  2399. }
  2400. else if (!strncmp(ptr, "@link ", 6))
  2401. {
  2402. for (ptr += 6; isspace(*ptr & 255); ptr ++);
  2403. for (start = ptr, ptr ++; *ptr && *ptr != '@'; ptr ++);
  2404. if (*ptr)
  2405. *ptr = '\0';
  2406. else
  2407. ptr --;
  2408. if (element && *element)
  2409. fprintf(out, "<a href=\"#%s\"><code>%s</code></a>", start, start);
  2410. else if (element)
  2411. fputs(start, out);
  2412. else
  2413. fprintf(out, "\\fI%s\\fR", start);
  2414. }
  2415. else if (element)
  2416. {
  2417. if (*ptr == '&')
  2418. fputs("&amp;", out);
  2419. else if (*ptr == '<')
  2420. fputs("&lt;", out);
  2421. else if (*ptr == '>')
  2422. fputs("&gt;", out);
  2423. else if (*ptr == '\"')
  2424. fputs("&quot;", out);
  2425. else if (*ptr & 128)
  2426. {
  2427. /*
  2428. * Convert UTF-8 to Unicode constant...
  2429. */
  2430. int ch; /* Unicode character */
  2431. ch = *ptr & 255;
  2432. if ((ch & 0xe0) == 0xc0)
  2433. {
  2434. ch = ((ch & 0x1f) << 6) | (ptr[1] & 0x3f);
  2435. ptr ++;
  2436. }
  2437. else if ((ch & 0xf0) == 0xe0)
  2438. {
  2439. ch = ((((ch * 0x0f) << 6) | (ptr[1] & 0x3f)) << 6) | (ptr[2] & 0x3f);
  2440. ptr += 2;
  2441. }
  2442. if (ch == 0xa0)
  2443. {
  2444. /*
  2445. * Handle non-breaking space as-is...
  2446. */
  2447. fputs("&nbsp;", out);
  2448. }
  2449. else
  2450. fprintf(out, "&#x%x;", ch);
  2451. }
  2452. else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@')
  2453. {
  2454. fputs("<br>\n<br>\n", out);
  2455. ptr ++;
  2456. }
  2457. else
  2458. putc(*ptr, out);
  2459. }
  2460. else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@')
  2461. {
  2462. fputs("\n.PP\n", out);
  2463. ptr ++;
  2464. }
  2465. else
  2466. {
  2467. if (*ptr == '\\' || (*ptr == '.' && col == 0))
  2468. putc('\\', out);
  2469. putc(*ptr, out);
  2470. if (*ptr == '\n')
  2471. col = 0;
  2472. else
  2473. col ++;
  2474. }
  2475. }
  2476. if (element && *element)
  2477. fprintf(out, "</%s>\n", element);
  2478. else if (!element)
  2479. putc('\n', out);
  2480. }
  2481. /*
  2482. * 'write_element()' - Write an element's text nodes.
  2483. */
  2484. static void
  2485. write_element(FILE *out, /* I - Output file */
  2486. mxml_node_t *doc, /* I - Document tree */
  2487. mxml_node_t *element, /* I - Element to write */
  2488. int mode) /* I - Output mode */
  2489. {
  2490. mxml_node_t *node; /* Current node */
  2491. if (!element)
  2492. return;
  2493. for (node = element->child;
  2494. node;
  2495. node = mxmlWalkNext(node, element, MXML_NO_DESCEND))
  2496. if (node->type == MXML_TEXT)
  2497. {
  2498. if (node->value.text.whitespace)
  2499. putc(' ', out);
  2500. if (mode == OUTPUT_HTML &&
  2501. (mxmlFindElement(doc, doc, "class", "name", node->value.text.string,
  2502. MXML_DESCEND) ||
  2503. mxmlFindElement(doc, doc, "enumeration", "name",
  2504. node->value.text.string, MXML_DESCEND) ||
  2505. mxmlFindElement(doc, doc, "struct", "name", node->value.text.string,
  2506. MXML_DESCEND) ||
  2507. mxmlFindElement(doc, doc, "typedef", "name", node->value.text.string,
  2508. MXML_DESCEND) ||
  2509. mxmlFindElement(doc, doc, "union", "name", node->value.text.string,
  2510. MXML_DESCEND)))
  2511. {
  2512. fputs("<a href=\"#", out);
  2513. write_string(out, node->value.text.string, mode);
  2514. fputs("\">", out);
  2515. write_string(out, node->value.text.string, mode);
  2516. fputs("</a>", out);
  2517. }
  2518. else
  2519. write_string(out, node->value.text.string, mode);
  2520. }
  2521. if (!strcmp(element->value.element.name, "type") &&
  2522. element->last_child->value.text.string[0] != '*')
  2523. putc(' ', out);
  2524. }
  2525. /*
  2526. * 'write_file()' - Copy a file to the output.
  2527. */
  2528. static void
  2529. write_file(FILE *out, /* I - Output file */
  2530. const char *file) /* I - File to copy */
  2531. {
  2532. FILE *fp; /* Copy file */
  2533. char line[8192]; /* Line from file */
  2534. if ((fp = fopen(file, "r")) == NULL)
  2535. {
  2536. fprintf(stderr, "mxmldoc: Unable to open \"%s\": %s\n", file,
  2537. strerror(errno));
  2538. return;
  2539. }
  2540. while (fgets(line, sizeof(line), fp))
  2541. fputs(line, out);
  2542. fclose(fp);
  2543. }
  2544. /*
  2545. * 'write_function()' - Write documentation for a function.
  2546. */
  2547. static void
  2548. write_function(FILE *out, /* I - Output file */
  2549. mxml_node_t *doc, /* I - Document */
  2550. mxml_node_t *function, /* I - Function */
  2551. int level) /* I - Base heading level */
  2552. {
  2553. mxml_node_t *arg, /* Current argument */
  2554. *adesc, /* Description of argument */
  2555. *description, /* Description of function */
  2556. *type, /* Type for argument */
  2557. *node; /* Node in description */
  2558. const char *name, /* Name of function/type */
  2559. *defval; /* Default value */
  2560. char prefix; /* Prefix character */
  2561. char *sep; /* Newline separator */
  2562. name = mxmlElementGetAttr(function, "name");
  2563. description = mxmlFindElement(function, function, "description", NULL,
  2564. NULL, MXML_DESCEND_FIRST);
  2565. fprintf(out, "<h%d class=\"%s\">%s<a name=\"%s\">%s</a></h%d>\n",
  2566. level, level == 3 ? "function" : "method",
  2567. get_comment_info(description), name, name, level);
  2568. if (description)
  2569. write_description(out, description, "p", 1);
  2570. fputs("<p class=\"code\">\n", out);
  2571. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  2572. NULL, MXML_DESCEND_FIRST);
  2573. if (arg)
  2574. write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL,
  2575. NULL, MXML_DESCEND_FIRST),
  2576. OUTPUT_HTML);
  2577. else
  2578. fputs("void ", out);
  2579. fprintf(out, "%s ", name);
  2580. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  2581. MXML_DESCEND_FIRST), prefix = '(';
  2582. arg;
  2583. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  2584. MXML_NO_DESCEND), prefix = ',')
  2585. {
  2586. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  2587. MXML_DESCEND_FIRST);
  2588. fprintf(out, "%c<br>\n&nbsp;&nbsp;&nbsp;&nbsp;", prefix);
  2589. if (type->child)
  2590. write_element(out, doc, type, OUTPUT_HTML);
  2591. fputs(mxmlElementGetAttr(arg, "name"), out);
  2592. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  2593. fprintf(out, " %s", defval);
  2594. }
  2595. if (prefix == '(')
  2596. fputs("(void);</p>\n", out);
  2597. else
  2598. {
  2599. fprintf(out,
  2600. "<br>\n);</p>\n"
  2601. "<h%d class=\"parameters\">Parameters</h%d>\n"
  2602. "<dl>\n", level + 1, level + 1);
  2603. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  2604. MXML_DESCEND_FIRST);
  2605. arg;
  2606. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  2607. MXML_NO_DESCEND))
  2608. {
  2609. fprintf(out, "<dt>%s</dt>\n", mxmlElementGetAttr(arg, "name"));
  2610. adesc = mxmlFindElement(arg, arg, "description", NULL, NULL,
  2611. MXML_DESCEND_FIRST);
  2612. write_description(out, adesc, "dd", 1);
  2613. write_description(out, adesc, "dd", 0);
  2614. }
  2615. fputs("</dl>\n", out);
  2616. }
  2617. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  2618. NULL, MXML_DESCEND_FIRST);
  2619. if (arg)
  2620. {
  2621. fprintf(out, "<h%d class=\"returnvalue\">Return Value</h%d>\n", level + 1,
  2622. level + 1);
  2623. adesc = mxmlFindElement(arg, arg, "description", NULL, NULL,
  2624. MXML_DESCEND_FIRST);
  2625. write_description(out, adesc, "p", 1);
  2626. write_description(out, adesc, "p", 0);
  2627. }
  2628. if (description)
  2629. {
  2630. for (node = description->child; node; node = node->next)
  2631. if (node->value.text.string &&
  2632. (sep = strstr(node->value.text.string, "\n\n")) != NULL)
  2633. {
  2634. sep += 2;
  2635. if (*sep && strncmp(sep, "@since ", 7) &&
  2636. strncmp(sep, "@deprecated@", 12))
  2637. break;
  2638. }
  2639. if (node)
  2640. {
  2641. fprintf(out, "<h%d class=\"discussion\">Discussion</h%d>\n", level + 1,
  2642. level + 1);
  2643. write_description(out, description, "p", 0);
  2644. }
  2645. }
  2646. }
  2647. /*
  2648. * 'write_html()' - Write HTML documentation.
  2649. */
  2650. static void
  2651. write_html(const char *section, /* I - Section */
  2652. const char *title, /* I - Title */
  2653. const char *footerfile, /* I - Footer file */
  2654. const char *headerfile, /* I - Header file */
  2655. const char *introfile, /* I - Intro file */
  2656. const char *cssfile, /* I - Stylesheet file */
  2657. const char *framefile, /* I - Framed HTML basename */
  2658. const char *docset, /* I - Documentation set directory */
  2659. const char *docversion, /* I - Documentation set version */
  2660. const char *feedname, /* I - Feed name for doc set */
  2661. const char *feedurl, /* I - Feed URL for doc set */
  2662. mxml_node_t *doc) /* I - XML documentation */
  2663. {
  2664. FILE *out; /* Output file */
  2665. mxml_node_t *function, /* Current function */
  2666. *scut, /* Struct/class/union/typedef */
  2667. *arg, /* Current argument */
  2668. *description, /* Description of function/var */
  2669. *type; /* Type for argument */
  2670. const char *name, /* Name of function/type */
  2671. *defval, /* Default value */
  2672. *basename; /* Base filename for framed output */
  2673. char filename[1024]; /* Current output filename */
  2674. if (framefile)
  2675. {
  2676. /*
  2677. * Get the basename of the frame file...
  2678. */
  2679. if ((basename = strrchr(framefile, '/')) != NULL)
  2680. basename ++;
  2681. else
  2682. basename = framefile;
  2683. if (strstr(basename, ".html"))
  2684. fputs("mxmldoc: Frame base name should not contain .html extension!\n",
  2685. stderr);
  2686. /*
  2687. * Create the container HTML file for the frames...
  2688. */
  2689. snprintf(filename, sizeof(filename), "%s.html", framefile);
  2690. if ((out = fopen(filename, "w")) == NULL)
  2691. {
  2692. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2693. strerror(errno));
  2694. return;
  2695. }
  2696. fputs("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" "
  2697. "\"http://www.w3.org/TR/html4/frameset.dtd\">\n"
  2698. "<html>\n"
  2699. "<head>\n"
  2700. "\t<title>", out);
  2701. write_string(out, title, OUTPUT_HTML);
  2702. fputs("</title>\n", out);
  2703. if (section)
  2704. fprintf(out, "\t<meta name=\"keywords\" content=\"%s\">\n", section);
  2705. fputs("\t<meta http-equiv=\"Content-Type\" "
  2706. "content=\"text/html;charset=utf-8\">\n"
  2707. "\t<meta name=\"creator\" content=\"" MXML_VERSION "\">\n"
  2708. "</head>\n", out);
  2709. fputs("<frameset cols=\"250,*\">\n", out);
  2710. fprintf(out, "<frame src=\"%s-toc.html\">\n", basename);
  2711. fprintf(out, "<frame name=\"body\" src=\"%s-body.html\">\n", basename);
  2712. fputs("</frameset>\n"
  2713. "<noframes>\n"
  2714. "<h1>", out);
  2715. write_string(out, title, OUTPUT_HTML);
  2716. fprintf(out,
  2717. "</h1>\n"
  2718. "<ul>\n"
  2719. "\t<li><a href=\"%s-toc.html\">Table of Contents</a></li>\n"
  2720. "\t<li><a href=\"%s-body.html\">Body</a></li>\n"
  2721. "</ul>\n", basename, basename);
  2722. fputs("</noframes>\n"
  2723. "</html>\n", out);
  2724. fclose(out);
  2725. /*
  2726. * Write the table-of-contents file...
  2727. */
  2728. snprintf(filename, sizeof(filename), "%s-toc.html", framefile);
  2729. if ((out = fopen(filename, "w")) == NULL)
  2730. {
  2731. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2732. strerror(errno));
  2733. return;
  2734. }
  2735. write_html_head(out, section, title, cssfile);
  2736. snprintf(filename, sizeof(filename), "%s-body.html", basename);
  2737. fputs("<div class=\"contents\">\n", out);
  2738. fprintf(out, "<h1 class=\"title\"><a href=\"%s\" target=\"body\">",
  2739. filename);
  2740. write_string(out, title, OUTPUT_HTML);
  2741. fputs("</a></h1>\n", out);
  2742. write_toc(out, doc, introfile, filename, 0);
  2743. fputs("</div>\n"
  2744. "</body>\n"
  2745. "</html>\n", out);
  2746. fclose(out);
  2747. /*
  2748. * Finally, open the body file...
  2749. */
  2750. snprintf(filename, sizeof(filename), "%s-body.html", framefile);
  2751. if ((out = fopen(filename, "w")) == NULL)
  2752. {
  2753. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2754. strerror(errno));
  2755. return;
  2756. }
  2757. }
  2758. else if (docset)
  2759. {
  2760. /*
  2761. * Create an Xcode documentation set - start by removing any existing
  2762. * output directory...
  2763. */
  2764. #ifdef __APPLE__
  2765. const char *id; /* Identifier */
  2766. if (!access(docset, 0) && !remove_directory(docset))
  2767. return;
  2768. /*
  2769. * Then make the Apple standard bundle directory structure...
  2770. */
  2771. if (mkdir(docset, 0755))
  2772. {
  2773. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", docset,
  2774. strerror(errno));
  2775. return;
  2776. }
  2777. snprintf(filename, sizeof(filename), "%s/Contents", docset);
  2778. if (mkdir(filename, 0755))
  2779. {
  2780. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2781. strerror(errno));
  2782. return;
  2783. }
  2784. snprintf(filename, sizeof(filename), "%s/Contents/Resources", docset);
  2785. if (mkdir(filename, 0755))
  2786. {
  2787. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2788. strerror(errno));
  2789. return;
  2790. }
  2791. snprintf(filename, sizeof(filename), "%s/Contents/Resources/Documentation",
  2792. docset);
  2793. if (mkdir(filename, 0755))
  2794. {
  2795. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2796. strerror(errno));
  2797. return;
  2798. }
  2799. /*
  2800. * The Info.plist file, which describes the documentation set...
  2801. */
  2802. if ((id = strrchr(docset, '/')) != NULL)
  2803. id ++;
  2804. else
  2805. id = docset;
  2806. snprintf(filename, sizeof(filename), "%s/Contents/Info.plist", docset);
  2807. if ((out = fopen(filename, "w")) == NULL)
  2808. {
  2809. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2810. strerror(errno));
  2811. return;
  2812. }
  2813. fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2814. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  2815. "<plist version=\"1.0\">\n"
  2816. "<dict>\n"
  2817. "\t<key>CFBundleIdentifier</key>\n"
  2818. "\t<string>", out);
  2819. write_string(out, id, OUTPUT_HTML);
  2820. fputs("</string>\n"
  2821. "\t<key>CFBundleName</key>\n"
  2822. "\t<string>", out);
  2823. write_string(out, title, OUTPUT_HTML);
  2824. fputs("</string>\n"
  2825. "\t<key>CFBundleVersion</key>\n"
  2826. "\t<string>", out);
  2827. write_string(out, docversion ? docversion : "0.0", OUTPUT_HTML);
  2828. fputs("</string>\n"
  2829. "\t<key>CFBundleShortVersionString</key>\n"
  2830. "\t<string>", out);
  2831. write_string(out, docversion ? docversion : "0.0", OUTPUT_HTML);
  2832. fputs("</string>\n", out);
  2833. if (feedname)
  2834. {
  2835. fputs("\t<key>DocSetFeedName</key>\n"
  2836. "\t<string>", out);
  2837. write_string(out, feedname ? feedname : title, OUTPUT_HTML);
  2838. fputs("</string>\n", out);
  2839. }
  2840. if (feedurl)
  2841. {
  2842. fputs("\t<key>DocSetFeedURL</key>\n"
  2843. "\t<string>", out);
  2844. write_string(out, feedurl, OUTPUT_HTML);
  2845. fputs("</string>\n", out);
  2846. }
  2847. fputs("</dict>\n"
  2848. "</plist>\n", out);
  2849. fclose(out);
  2850. /*
  2851. * Next the Nodes.xml file...
  2852. */
  2853. snprintf(filename, sizeof(filename), "%s/Contents/Resources/Nodes.xml",
  2854. docset);
  2855. if ((out = fopen(filename, "w")) == NULL)
  2856. {
  2857. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2858. strerror(errno));
  2859. return;
  2860. }
  2861. fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2862. "<DocSetNodes version=\"1.0\">\n"
  2863. "<TOC>\n"
  2864. "<Node id=\"0\">\n"
  2865. "<Name>", out);
  2866. write_string(out, title, OUTPUT_HTML);
  2867. fputs("</Name>\n"
  2868. "<Path>Documentation/index.html</Path>\n"
  2869. "<Subnodes>\n", out);
  2870. write_toc(out, doc, introfile, NULL, 1);
  2871. fputs("</Subnodes>\n"
  2872. "</Node>\n"
  2873. "</TOC>\n"
  2874. "</DocSetNodes>\n", out);
  2875. fclose(out);
  2876. /*
  2877. * Then the Tokens.xml file...
  2878. */
  2879. snprintf(filename, sizeof(filename), "%s/Contents/Resources/Tokens.xml",
  2880. docset);
  2881. if ((out = fopen(filename, "w")) == NULL)
  2882. {
  2883. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2884. strerror(errno));
  2885. return;
  2886. }
  2887. fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2888. "<Tokens version=\"1.0\">\n", out);
  2889. write_tokens(out, doc, "index.html");
  2890. fputs("</Tokens>\n", out);
  2891. fclose(out);
  2892. /*
  2893. * Finally the HTML file...
  2894. */
  2895. snprintf(filename, sizeof(filename),
  2896. "%s/Contents/Resources/Documentation/index.html",
  2897. docset);
  2898. if ((out = fopen(filename, "w")) == NULL)
  2899. {
  2900. fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename,
  2901. strerror(errno));
  2902. return;
  2903. }
  2904. #else
  2905. fputs("mxmldoc: Xcode documentation sets can only be created on "
  2906. "Mac OS X.\n", stderr);
  2907. return;
  2908. #endif /* __APPLE__ */
  2909. }
  2910. else
  2911. out = stdout;
  2912. /*
  2913. * Standard header...
  2914. */
  2915. write_html_head(out, section, title, cssfile);
  2916. fputs("<div class='body'>\n", out);
  2917. /*
  2918. * Header...
  2919. */
  2920. if (headerfile)
  2921. {
  2922. /*
  2923. * Use custom header...
  2924. */
  2925. write_file(out, headerfile);
  2926. }
  2927. else
  2928. {
  2929. /*
  2930. * Use standard header...
  2931. */
  2932. fputs("<h1 class=\"title\">", out);
  2933. write_string(out, title, OUTPUT_HTML);
  2934. fputs("</h1>\n", out);
  2935. }
  2936. /*
  2937. * Table of contents...
  2938. */
  2939. if (!framefile)
  2940. write_toc(out, doc, introfile, NULL, 0);
  2941. /*
  2942. * Intro...
  2943. */
  2944. if (introfile)
  2945. write_file(out, introfile);
  2946. /*
  2947. * List of classes...
  2948. */
  2949. if ((scut = find_public(doc, doc, "class")) != NULL)
  2950. {
  2951. fputs("<h2 class=\"title\"><a name=\"CLASSES\">Classes</a></h2>\n", out);
  2952. while (scut)
  2953. {
  2954. write_scu(out, doc, scut);
  2955. scut = find_public(scut, doc, "class");
  2956. }
  2957. }
  2958. /*
  2959. * List of functions...
  2960. */
  2961. if ((function = find_public(doc, doc, "function")) != NULL)
  2962. {
  2963. fputs("<h2 class=\"title\"><a name=\"FUNCTIONS\">Functions</a></h2>\n", out);
  2964. while (function)
  2965. {
  2966. write_function(out, doc, function, 3);
  2967. function = find_public(function, doc, "function");
  2968. }
  2969. }
  2970. /*
  2971. * List of types...
  2972. */
  2973. if ((scut = find_public(doc, doc, "typedef")) != NULL)
  2974. {
  2975. fputs("<h2 class=\"title\"><a name=\"TYPES\">Data Types</a></h2>\n", out);
  2976. while (scut)
  2977. {
  2978. name = mxmlElementGetAttr(scut, "name");
  2979. description = mxmlFindElement(scut, scut, "description", NULL,
  2980. NULL, MXML_DESCEND_FIRST);
  2981. fprintf(out, "<h3 class=\"typedef\">%s<a name=\"%s\">%s</a></h3>\n",
  2982. get_comment_info(description), name, name);
  2983. if (description)
  2984. write_description(out, description, "p", 1);
  2985. fputs("<p class=\"code\">\n"
  2986. "typedef ", out);
  2987. type = mxmlFindElement(scut, scut, "type", NULL, NULL,
  2988. MXML_DESCEND_FIRST);
  2989. for (type = type->child; type; type = type->next)
  2990. if (!strcmp(type->value.text.string, "("))
  2991. break;
  2992. else
  2993. {
  2994. if (type->value.text.whitespace)
  2995. putc(' ', out);
  2996. if (mxmlFindElement(doc, doc, "class", "name",
  2997. type->value.text.string, MXML_DESCEND) ||
  2998. mxmlFindElement(doc, doc, "enumeration", "name",
  2999. type->value.text.string, MXML_DESCEND) ||
  3000. mxmlFindElement(doc, doc, "struct", "name",
  3001. type->value.text.string, MXML_DESCEND) ||
  3002. mxmlFindElement(doc, doc, "typedef", "name",
  3003. type->value.text.string, MXML_DESCEND) ||
  3004. mxmlFindElement(doc, doc, "union", "name",
  3005. type->value.text.string, MXML_DESCEND))
  3006. {
  3007. fputs("<a href=\"#", out);
  3008. write_string(out, type->value.text.string, OUTPUT_HTML);
  3009. fputs("\">", out);
  3010. write_string(out, type->value.text.string, OUTPUT_HTML);
  3011. fputs("</a>", out);
  3012. }
  3013. else
  3014. write_string(out, type->value.text.string, OUTPUT_HTML);
  3015. }
  3016. if (type)
  3017. {
  3018. /*
  3019. * Output function type...
  3020. */
  3021. if (type->prev && type->prev->value.text.string[0] != '*')
  3022. putc(' ', out);
  3023. fprintf(out, "(*%s", name);
  3024. for (type = type->next->next; type; type = type->next)
  3025. {
  3026. if (type->value.text.whitespace)
  3027. putc(' ', out);
  3028. if (mxmlFindElement(doc, doc, "class", "name",
  3029. type->value.text.string, MXML_DESCEND) ||
  3030. mxmlFindElement(doc, doc, "enumeration", "name",
  3031. type->value.text.string, MXML_DESCEND) ||
  3032. mxmlFindElement(doc, doc, "struct", "name",
  3033. type->value.text.string, MXML_DESCEND) ||
  3034. mxmlFindElement(doc, doc, "typedef", "name",
  3035. type->value.text.string, MXML_DESCEND) ||
  3036. mxmlFindElement(doc, doc, "union", "name",
  3037. type->value.text.string, MXML_DESCEND))
  3038. {
  3039. fputs("<a href=\"#", out);
  3040. write_string(out, type->value.text.string, OUTPUT_HTML);
  3041. fputs("\">", out);
  3042. write_string(out, type->value.text.string, OUTPUT_HTML);
  3043. fputs("</a>", out);
  3044. }
  3045. else
  3046. write_string(out, type->value.text.string, OUTPUT_HTML);
  3047. }
  3048. fputs(";\n", out);
  3049. }
  3050. else
  3051. {
  3052. type = mxmlFindElement(scut, scut, "type", NULL, NULL,
  3053. MXML_DESCEND_FIRST);
  3054. if (type->last_child->value.text.string[0] != '*')
  3055. putc(' ', out);
  3056. fprintf(out, "%s;\n", name);
  3057. }
  3058. fputs("</p>\n", out);
  3059. scut = find_public(scut, doc, "typedef");
  3060. }
  3061. }
  3062. /*
  3063. * List of structures...
  3064. */
  3065. if ((scut = find_public(doc, doc, "struct")) != NULL)
  3066. {
  3067. fputs("<h2 class=\"title\"><a name=\"STRUCTURES\">Structures</a></h2>\n",
  3068. out);
  3069. while (scut)
  3070. {
  3071. write_scu(out, doc, scut);
  3072. scut = find_public(scut, doc, "struct");
  3073. }
  3074. }
  3075. /*
  3076. * List of unions...
  3077. */
  3078. if ((scut = find_public(doc, doc, "union")) != NULL)
  3079. {
  3080. fputs("<h2 class=\"title\"><a name=\"UNIONS\">Unions</a></h2>\n", out);
  3081. while (scut)
  3082. {
  3083. write_scu(out, doc, scut);
  3084. scut = find_public(scut, doc, "union");
  3085. }
  3086. }
  3087. /*
  3088. * Variables...
  3089. */
  3090. if ((arg = find_public(doc, doc, "variable")) != NULL)
  3091. {
  3092. fputs("<h2 class=\"title\"><a name=\"VARIABLES\">Variables</a></h2>\n",
  3093. out);
  3094. while (arg)
  3095. {
  3096. name = mxmlElementGetAttr(arg, "name");
  3097. description = mxmlFindElement(arg, arg, "description", NULL,
  3098. NULL, MXML_DESCEND_FIRST);
  3099. fprintf(out, "<h3 class=\"variable\">%s<a name=\"%s\">%s</a></h3>\n",
  3100. get_comment_info(description), name, name);
  3101. if (description)
  3102. write_description(out, description, "p", 1);
  3103. fputs("<p class=\"code\">", out);
  3104. write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL,
  3105. NULL, MXML_DESCEND_FIRST),
  3106. OUTPUT_HTML);
  3107. fputs(mxmlElementGetAttr(arg, "name"), out);
  3108. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  3109. fprintf(out, " %s", defval);
  3110. fputs(";</p>\n", out);
  3111. arg = find_public(arg, doc, "variable");
  3112. }
  3113. }
  3114. /*
  3115. * List of enumerations...
  3116. */
  3117. if ((scut = find_public(doc, doc, "enumeration")) != NULL)
  3118. {
  3119. fputs("<h2 class=\"title\"><a name=\"ENUMERATIONS\">Constants</a></h2>\n",
  3120. out);
  3121. while (scut)
  3122. {
  3123. name = mxmlElementGetAttr(scut, "name");
  3124. description = mxmlFindElement(scut, scut, "description", NULL,
  3125. NULL, MXML_DESCEND_FIRST);
  3126. fprintf(out, "<h3 class=\"enumeration\">%s<a name=\"%s\">%s</a></h3>\n",
  3127. get_comment_info(description), name, name);
  3128. if (description)
  3129. write_description(out, description, "p", 1);
  3130. fputs("<h4 class=\"constants\">Constants</h4>\n"
  3131. "<dl>\n", out);
  3132. for (arg = mxmlFindElement(scut, scut, "constant", NULL, NULL,
  3133. MXML_DESCEND_FIRST);
  3134. arg;
  3135. arg = mxmlFindElement(arg, scut, "constant", NULL, NULL,
  3136. MXML_NO_DESCEND))
  3137. {
  3138. description = mxmlFindElement(arg, arg, "description", NULL,
  3139. NULL, MXML_DESCEND_FIRST);
  3140. fprintf(out, "<dt>%s %s</dt>\n",
  3141. mxmlElementGetAttr(arg, "name"), get_comment_info(description));
  3142. write_description(out, description, "dd", 1);
  3143. write_description(out, description, "dd", 0);
  3144. }
  3145. fputs("</dl>\n", out);
  3146. scut = find_public(scut, doc, "enumeration");
  3147. }
  3148. }
  3149. /*
  3150. * Footer...
  3151. */
  3152. if (footerfile)
  3153. {
  3154. /*
  3155. * Use custom footer...
  3156. */
  3157. write_file(out, footerfile);
  3158. }
  3159. fputs("</div>\n"
  3160. "</body>\n"
  3161. "</html>\n", out);
  3162. /*
  3163. * Close output file as needed...
  3164. */
  3165. if (out != stdout)
  3166. fclose(out);
  3167. #ifdef __APPLE__
  3168. /*
  3169. * When generating document sets, run the docsetutil program to index it...
  3170. */
  3171. if (docset)
  3172. {
  3173. int argc = 0; /* Argument count */
  3174. const char *args[5]; /* Argument array */
  3175. pid_t pid; /* Process ID */
  3176. int status; /* Exit status */
  3177. args[argc++] = "/usr/bin/xcrun";
  3178. args[argc++] = "docsetutil";
  3179. args[argc++] = "index";
  3180. args[argc++] = docset;
  3181. args[argc ] = NULL;
  3182. if (posix_spawn(&pid, args[0], NULL, NULL, (char **)args, environ))
  3183. {
  3184. fprintf(stderr, "mxmldoc: Unable to index documentation set \"%s\": %s\n",
  3185. docset, strerror(errno));
  3186. }
  3187. else
  3188. {
  3189. while (wait(&status) != pid);
  3190. if (status)
  3191. {
  3192. if (WIFEXITED(status))
  3193. fprintf(stderr, "mxmldoc: docsetutil exited with status %d\n",
  3194. WEXITSTATUS(status));
  3195. else
  3196. fprintf(stderr, "mxmldoc: docsetutil crashed with signal %d\n",
  3197. WTERMSIG(status));
  3198. }
  3199. else
  3200. {
  3201. /*
  3202. * Remove unneeded temporary XML files...
  3203. */
  3204. snprintf(filename, sizeof(filename), "%s/Contents/Resources/Nodes.xml",
  3205. docset);
  3206. unlink(filename);
  3207. snprintf(filename, sizeof(filename), "%s/Contents/Resources/Tokens.xml",
  3208. docset);
  3209. unlink(filename);
  3210. }
  3211. }
  3212. }
  3213. #endif /* __APPLE__ */
  3214. }
  3215. /*
  3216. * 'write_html_head()' - Write the standard HTML header.
  3217. */
  3218. static void
  3219. write_html_head(FILE *out, /* I - Output file */
  3220. const char *section, /* I - Section */
  3221. const char *title, /* I - Title */
  3222. const char *cssfile) /* I - Stylesheet */
  3223. {
  3224. fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
  3225. "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
  3226. "<html>\n", out);
  3227. if (section)
  3228. fprintf(out, "<!-- SECTION: %s -->\n", section);
  3229. fputs("<head>\n"
  3230. "\t<title>", out);
  3231. write_string(out, title, OUTPUT_HTML);
  3232. fputs("\t</title>\n", out);
  3233. if (section)
  3234. fprintf(out, "\t<meta name=\"keywords\" content=\"%s\">\n", section);
  3235. fputs("\t<meta http-equiv=\"Content-Type\" "
  3236. "content=\"text/html;charset=utf-8\">\n"
  3237. "\t<meta name=\"creator\" content=\"" MXML_VERSION "\">\n"
  3238. "<style type=\"text/css\"><!--\n", out);
  3239. if (cssfile)
  3240. {
  3241. /*
  3242. * Use custom stylesheet file...
  3243. */
  3244. write_file(out, cssfile);
  3245. }
  3246. else
  3247. {
  3248. /*
  3249. * Use standard stylesheet...
  3250. */
  3251. fputs("body, p, h1, h2, h3, h4 {\n"
  3252. " font-family: \"lucida grande\", geneva, helvetica, arial, "
  3253. "sans-serif;\n"
  3254. "}\n"
  3255. "div.body h1 {\n"
  3256. " font-size: 250%;\n"
  3257. " font-weight: bold;\n"
  3258. " margin: 0;\n"
  3259. "}\n"
  3260. "div.body h2 {\n"
  3261. " font-size: 250%;\n"
  3262. " margin-top: 1.5em;\n"
  3263. "}\n"
  3264. "div.body h3 {\n"
  3265. " font-size: 150%;\n"
  3266. " margin-bottom: 0.5em;\n"
  3267. " margin-top: 1.5em;\n"
  3268. "}\n"
  3269. "div.body h4 {\n"
  3270. " font-size: 110%;\n"
  3271. " margin-bottom: 0.5em;\n"
  3272. " margin-top: 1.5em;\n"
  3273. "}\n"
  3274. "div.body h5 {\n"
  3275. " font-size: 100%;\n"
  3276. " margin-bottom: 0.5em;\n"
  3277. " margin-top: 1.5em;\n"
  3278. "}\n"
  3279. "div.contents {\n"
  3280. " background: #e8e8e8;\n"
  3281. " border: solid thin black;\n"
  3282. " padding: 10px;\n"
  3283. "}\n"
  3284. "div.contents h1 {\n"
  3285. " font-size: 110%;\n"
  3286. "}\n"
  3287. "div.contents h2 {\n"
  3288. " font-size: 100%;\n"
  3289. "}\n"
  3290. "div.contents ul.contents {\n"
  3291. " font-size: 80%;\n"
  3292. "}\n"
  3293. ".class {\n"
  3294. " border-bottom: solid 2px gray;\n"
  3295. "}\n"
  3296. ".constants {\n"
  3297. "}\n"
  3298. ".description {\n"
  3299. " margin-top: 0.5em;\n"
  3300. "}\n"
  3301. ".discussion {\n"
  3302. "}\n"
  3303. ".enumeration {\n"
  3304. " border-bottom: solid 2px gray;\n"
  3305. "}\n"
  3306. ".function {\n"
  3307. " border-bottom: solid 2px gray;\n"
  3308. " margin-bottom: 0;\n"
  3309. "}\n"
  3310. ".members {\n"
  3311. "}\n"
  3312. ".method {\n"
  3313. "}\n"
  3314. ".parameters {\n"
  3315. "}\n"
  3316. ".returnvalue {\n"
  3317. "}\n"
  3318. ".struct {\n"
  3319. " border-bottom: solid 2px gray;\n"
  3320. "}\n"
  3321. ".typedef {\n"
  3322. " border-bottom: solid 2px gray;\n"
  3323. "}\n"
  3324. ".union {\n"
  3325. " border-bottom: solid 2px gray;\n"
  3326. "}\n"
  3327. ".variable {\n"
  3328. "}\n"
  3329. "code, p.code, pre, ul.code li {\n"
  3330. " font-family: monaco, courier, monospace;\n"
  3331. " font-size: 90%;\n"
  3332. "}\n"
  3333. "a:link, a:visited {\n"
  3334. " text-decoration: none;\n"
  3335. "}\n"
  3336. "span.info {\n"
  3337. " background: black;\n"
  3338. " border: solid thin black;\n"
  3339. " color: white;\n"
  3340. " font-size: 80%;\n"
  3341. " font-style: italic;\n"
  3342. " font-weight: bold;\n"
  3343. " white-space: nowrap;\n"
  3344. "}\n"
  3345. "h3 span.info, h4 span.info {\n"
  3346. " float: right;\n"
  3347. " font-size: 100%;\n"
  3348. "}\n"
  3349. "ul.code, ul.contents, ul.subcontents {\n"
  3350. " list-style-type: none;\n"
  3351. " margin: 0;\n"
  3352. " padding-left: 0;\n"
  3353. "}\n"
  3354. "ul.code li {\n"
  3355. " margin: 0;\n"
  3356. "}\n"
  3357. "ul.contents > li {\n"
  3358. " margin-top: 1em;\n"
  3359. "}\n"
  3360. "ul.contents li ul.code, ul.contents li ul.subcontents {\n"
  3361. " padding-left: 2em;\n"
  3362. "}\n"
  3363. "div.body dl {\n"
  3364. " margin-top: 0;\n"
  3365. "}\n"
  3366. "div.body dt {\n"
  3367. " font-style: italic;\n"
  3368. " margin-top: 0;\n"
  3369. "}\n"
  3370. "div.body dd {\n"
  3371. " margin-bottom: 0.5em;\n"
  3372. "}\n"
  3373. "h1.title {\n"
  3374. "}\n"
  3375. "h2.title {\n"
  3376. " border-bottom: solid 2px black;\n"
  3377. "}\n"
  3378. "h3.title {\n"
  3379. " border-bottom: solid 2px black;\n"
  3380. "}\n", out);
  3381. }
  3382. fputs("--></style>\n"
  3383. "</head>\n"
  3384. "<body>\n", out);
  3385. }
  3386. /*
  3387. * 'write_man()' - Write manpage documentation.
  3388. */
  3389. static void
  3390. write_man(const char *man_name, /* I - Name of manpage */
  3391. const char *section, /* I - Section */
  3392. const char *title, /* I - Title */
  3393. const char *footerfile, /* I - Footer file */
  3394. const char *headerfile, /* I - Header file */
  3395. const char *introfile, /* I - Intro file */
  3396. mxml_node_t *doc) /* I - XML documentation */
  3397. {
  3398. int i; /* Looping var */
  3399. mxml_node_t *function, /* Current function */
  3400. *scut, /* Struct/class/union/typedef */
  3401. *arg, /* Current argument */
  3402. *description, /* Description of function/var */
  3403. *type; /* Type for argument */
  3404. const char *name, /* Name of function/type */
  3405. *cname, /* Class name */
  3406. *defval, /* Default value */
  3407. *parent; /* Parent class */
  3408. int inscope; /* Variable/method scope */
  3409. char prefix; /* Prefix character */
  3410. time_t curtime; /* Current time */
  3411. struct tm *curdate; /* Current date */
  3412. char buffer[1024]; /* String buffer */
  3413. static const char * const scopes[] = /* Scope strings */
  3414. {
  3415. "private",
  3416. "protected",
  3417. "public"
  3418. };
  3419. /*
  3420. * Standard man page...
  3421. */
  3422. curtime = time(NULL);
  3423. curdate = localtime(&curtime);
  3424. strftime(buffer, sizeof(buffer), "%x", curdate);
  3425. printf(".TH %s %s \"%s\" \"%s\" \"%s\"\n", man_name, section ? section : "3",
  3426. title ? title : "", buffer, title ? title : "");
  3427. /*
  3428. * Header...
  3429. */
  3430. if (headerfile)
  3431. {
  3432. /*
  3433. * Use custom header...
  3434. */
  3435. write_file(stdout, headerfile);
  3436. }
  3437. else
  3438. {
  3439. /*
  3440. * Use standard header...
  3441. */
  3442. puts(".SH NAME");
  3443. printf("%s \\- %s\n", man_name, title ? title : man_name);
  3444. }
  3445. /*
  3446. * Intro...
  3447. */
  3448. if (introfile)
  3449. write_file(stdout, introfile);
  3450. /*
  3451. * List of classes...
  3452. */
  3453. if (find_public(doc, doc, "class"))
  3454. {
  3455. puts(".SH CLASSES");
  3456. for (scut = find_public(doc, doc, "class");
  3457. scut;
  3458. scut = find_public(scut, doc, "class"))
  3459. {
  3460. cname = mxmlElementGetAttr(scut, "name");
  3461. description = mxmlFindElement(scut, scut, "description", NULL,
  3462. NULL, MXML_DESCEND_FIRST);
  3463. printf(".SS %s\n", cname);
  3464. write_description(stdout, description, NULL, 1);
  3465. printf(".PP\n"
  3466. ".nf\n"
  3467. "class %s", cname);
  3468. if ((parent = mxmlElementGetAttr(scut, "parent")) != NULL)
  3469. printf(" %s", parent);
  3470. puts("\n{");
  3471. for (i = 0; i < 3; i ++)
  3472. {
  3473. inscope = 0;
  3474. for (arg = mxmlFindElement(scut, scut, "variable", "scope", scopes[i],
  3475. MXML_DESCEND_FIRST);
  3476. arg;
  3477. arg = mxmlFindElement(arg, scut, "variable", "scope", scopes[i],
  3478. MXML_NO_DESCEND))
  3479. {
  3480. if (!inscope)
  3481. {
  3482. inscope = 1;
  3483. printf(" %s:\n", scopes[i]);
  3484. }
  3485. printf(" ");
  3486. write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL,
  3487. NULL, MXML_DESCEND_FIRST),
  3488. OUTPUT_MAN);
  3489. printf("%s;\n", mxmlElementGetAttr(arg, "name"));
  3490. }
  3491. for (function = mxmlFindElement(scut, scut, "function", "scope",
  3492. scopes[i], MXML_DESCEND_FIRST);
  3493. function;
  3494. function = mxmlFindElement(function, scut, "function", "scope",
  3495. scopes[i], MXML_NO_DESCEND))
  3496. {
  3497. if (!inscope)
  3498. {
  3499. inscope = 1;
  3500. printf(" %s:\n", scopes[i]);
  3501. }
  3502. name = mxmlElementGetAttr(function, "name");
  3503. printf(" ");
  3504. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  3505. NULL, MXML_DESCEND_FIRST);
  3506. if (arg)
  3507. write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL,
  3508. NULL, MXML_DESCEND_FIRST),
  3509. OUTPUT_MAN);
  3510. else if (strcmp(cname, name) && strcmp(cname, name + 1))
  3511. fputs("void ", stdout);
  3512. printf("%s", name);
  3513. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  3514. MXML_DESCEND_FIRST), prefix = '(';
  3515. arg;
  3516. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  3517. MXML_NO_DESCEND), prefix = ',')
  3518. {
  3519. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  3520. MXML_DESCEND_FIRST);
  3521. putchar(prefix);
  3522. if (prefix == ',')
  3523. putchar(' ');
  3524. if (type->child)
  3525. write_element(stdout, doc, type, OUTPUT_MAN);
  3526. fputs(mxmlElementGetAttr(arg, "name"), stdout);
  3527. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  3528. printf(" %s", defval);
  3529. }
  3530. if (prefix == '(')
  3531. puts("(void);");
  3532. else
  3533. puts(");");
  3534. }
  3535. }
  3536. puts("};\n"
  3537. ".fi");
  3538. write_description(stdout, description, NULL, 0);
  3539. }
  3540. }
  3541. /*
  3542. * List of enumerations...
  3543. */
  3544. if (find_public(doc, doc, "enumeration"))
  3545. {
  3546. puts(".SH ENUMERATIONS");
  3547. for (scut = find_public(doc, doc, "enumeration");
  3548. scut;
  3549. scut = find_public(scut, doc, "enumeration"))
  3550. {
  3551. name = mxmlElementGetAttr(scut, "name");
  3552. description = mxmlFindElement(scut, scut, "description", NULL,
  3553. NULL, MXML_DESCEND_FIRST);
  3554. printf(".SS %s\n", name);
  3555. write_description(stdout, description, NULL, 1);
  3556. write_description(stdout, description, NULL, 0);
  3557. for (arg = mxmlFindElement(scut, scut, "constant", NULL, NULL,
  3558. MXML_DESCEND_FIRST);
  3559. arg;
  3560. arg = mxmlFindElement(arg, scut, "constant", NULL, NULL,
  3561. MXML_NO_DESCEND))
  3562. {
  3563. description = mxmlFindElement(arg, arg, "description", NULL,
  3564. NULL, MXML_DESCEND_FIRST);
  3565. printf(".TP 5\n%s\n.br\n", mxmlElementGetAttr(arg, "name"));
  3566. write_description(stdout, description, NULL, 1);
  3567. }
  3568. }
  3569. }
  3570. /*
  3571. * List of functions...
  3572. */
  3573. if (find_public(doc, doc, "function"))
  3574. {
  3575. puts(".SH FUNCTIONS");
  3576. for (function = find_public(doc, doc, "function");
  3577. function;
  3578. function = find_public(function, doc, "function"))
  3579. {
  3580. name = mxmlElementGetAttr(function, "name");
  3581. description = mxmlFindElement(function, function, "description", NULL,
  3582. NULL, MXML_DESCEND_FIRST);
  3583. printf(".SS %s\n", name);
  3584. write_description(stdout, description, NULL, 1);
  3585. puts(".PP\n"
  3586. ".nf");
  3587. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  3588. NULL, MXML_DESCEND_FIRST);
  3589. if (arg)
  3590. write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL,
  3591. NULL, MXML_DESCEND_FIRST),
  3592. OUTPUT_MAN);
  3593. else
  3594. fputs("void", stdout);
  3595. printf(" %s ", name);
  3596. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  3597. MXML_DESCEND_FIRST), prefix = '(';
  3598. arg;
  3599. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  3600. MXML_NO_DESCEND), prefix = ',')
  3601. {
  3602. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  3603. MXML_DESCEND_FIRST);
  3604. printf("%c\n ", prefix);
  3605. if (type->child)
  3606. write_element(stdout, doc, type, OUTPUT_MAN);
  3607. fputs(mxmlElementGetAttr(arg, "name"), stdout);
  3608. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  3609. printf(" %s", defval);
  3610. }
  3611. if (prefix == '(')
  3612. puts("(void);");
  3613. else
  3614. puts("\n);");
  3615. puts(".fi");
  3616. write_description(stdout, description, NULL, 0);
  3617. }
  3618. }
  3619. /*
  3620. * List of structures...
  3621. */
  3622. if (find_public(doc, doc, "struct"))
  3623. {
  3624. puts(".SH STRUCTURES");
  3625. for (scut = find_public(doc, doc, "struct");
  3626. scut;
  3627. scut = find_public(scut, doc, "struct"))
  3628. {
  3629. cname = mxmlElementGetAttr(scut, "name");
  3630. description = mxmlFindElement(scut, scut, "description", NULL,
  3631. NULL, MXML_DESCEND_FIRST);
  3632. printf(".SS %s\n", cname);
  3633. write_description(stdout, description, NULL, 1);
  3634. printf(".PP\n"
  3635. ".nf\n"
  3636. "struct %s\n{\n", cname);
  3637. for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL,
  3638. MXML_DESCEND_FIRST);
  3639. arg;
  3640. arg = mxmlFindElement(arg, scut, "variable", NULL, NULL,
  3641. MXML_NO_DESCEND))
  3642. {
  3643. printf(" ");
  3644. write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL,
  3645. NULL, MXML_DESCEND_FIRST),
  3646. OUTPUT_MAN);
  3647. printf("%s;\n", mxmlElementGetAttr(arg, "name"));
  3648. }
  3649. for (function = mxmlFindElement(scut, scut, "function", NULL, NULL,
  3650. MXML_DESCEND_FIRST);
  3651. function;
  3652. function = mxmlFindElement(function, scut, "function", NULL, NULL,
  3653. MXML_NO_DESCEND))
  3654. {
  3655. name = mxmlElementGetAttr(function, "name");
  3656. printf(" ");
  3657. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  3658. NULL, MXML_DESCEND_FIRST);
  3659. if (arg)
  3660. write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL,
  3661. NULL, MXML_DESCEND_FIRST),
  3662. OUTPUT_MAN);
  3663. else if (strcmp(cname, name) && strcmp(cname, name + 1))
  3664. fputs("void ", stdout);
  3665. fputs(name, stdout);
  3666. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  3667. MXML_DESCEND_FIRST), prefix = '(';
  3668. arg;
  3669. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  3670. MXML_NO_DESCEND), prefix = ',')
  3671. {
  3672. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  3673. MXML_DESCEND_FIRST);
  3674. putchar(prefix);
  3675. if (prefix == ',')
  3676. putchar(' ');
  3677. if (type->child)
  3678. write_element(stdout, doc, type, OUTPUT_MAN);
  3679. fputs(mxmlElementGetAttr(arg, "name"), stdout);
  3680. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  3681. printf(" %s", defval);
  3682. }
  3683. if (prefix == '(')
  3684. puts("(void);");
  3685. else
  3686. puts(");");
  3687. }
  3688. puts("};\n"
  3689. ".fi");
  3690. write_description(stdout, description, NULL, 0);
  3691. }
  3692. }
  3693. /*
  3694. * List of types...
  3695. */
  3696. if (find_public(doc, doc, "typedef"))
  3697. {
  3698. puts(".SH TYPES");
  3699. for (scut = find_public(doc, doc, "typedef");
  3700. scut;
  3701. scut = find_public(scut, doc, "typedef"))
  3702. {
  3703. name = mxmlElementGetAttr(scut, "name");
  3704. description = mxmlFindElement(scut, scut, "description", NULL,
  3705. NULL, MXML_DESCEND_FIRST);
  3706. printf(".SS %s\n", name);
  3707. write_description(stdout, description, NULL, 1);
  3708. fputs(".PP\n"
  3709. ".nf\n"
  3710. "typedef ", stdout);
  3711. type = mxmlFindElement(scut, scut, "type", NULL, NULL,
  3712. MXML_DESCEND_FIRST);
  3713. for (type = type->child; type; type = type->next)
  3714. if (!strcmp(type->value.text.string, "("))
  3715. break;
  3716. else
  3717. {
  3718. if (type->value.text.whitespace)
  3719. putchar(' ');
  3720. write_string(stdout, type->value.text.string, OUTPUT_MAN);
  3721. }
  3722. if (type)
  3723. {
  3724. /*
  3725. * Output function type...
  3726. */
  3727. printf(" (*%s", name);
  3728. for (type = type->next->next; type; type = type->next)
  3729. {
  3730. if (type->value.text.whitespace)
  3731. putchar(' ');
  3732. write_string(stdout, type->value.text.string, OUTPUT_MAN);
  3733. }
  3734. puts(";");
  3735. }
  3736. else
  3737. printf(" %s;\n", name);
  3738. puts(".fi");
  3739. write_description(stdout, description, NULL, 0);
  3740. }
  3741. }
  3742. /*
  3743. * List of unions...
  3744. */
  3745. if (find_public(doc, doc, "union"))
  3746. {
  3747. puts(".SH UNIONS");
  3748. for (scut = find_public(doc, doc, "union");
  3749. scut;
  3750. scut = find_public(scut, doc, "union"))
  3751. {
  3752. name = mxmlElementGetAttr(scut, "name");
  3753. description = mxmlFindElement(scut, scut, "description", NULL,
  3754. NULL, MXML_DESCEND_FIRST);
  3755. printf(".SS %s\n", name);
  3756. write_description(stdout, description, NULL, 1);
  3757. printf(".PP\n"
  3758. ".nf\n"
  3759. "union %s\n{\n", name);
  3760. for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL,
  3761. MXML_DESCEND_FIRST);
  3762. arg;
  3763. arg = mxmlFindElement(arg, scut, "variable", NULL, NULL,
  3764. MXML_NO_DESCEND))
  3765. {
  3766. printf(" ");
  3767. write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL,
  3768. NULL, MXML_DESCEND_FIRST),
  3769. OUTPUT_MAN);
  3770. printf("%s;\n", mxmlElementGetAttr(arg, "name"));
  3771. }
  3772. puts("};\n"
  3773. ".fi");
  3774. write_description(stdout, description, NULL, 0);
  3775. }
  3776. }
  3777. /*
  3778. * Variables...
  3779. */
  3780. if (find_public(doc, doc, "variable"))
  3781. {
  3782. puts(".SH VARIABLES");
  3783. for (arg = find_public(doc, doc, "variable");
  3784. arg;
  3785. arg = find_public(arg, doc, "variable"))
  3786. {
  3787. name = mxmlElementGetAttr(arg, "name");
  3788. description = mxmlFindElement(arg, arg, "description", NULL,
  3789. NULL, MXML_DESCEND_FIRST);
  3790. printf(".SS %s\n", name);
  3791. write_description(stdout, description, NULL, 1);
  3792. puts(".PP\n"
  3793. ".nf");
  3794. write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL,
  3795. NULL, MXML_DESCEND_FIRST),
  3796. OUTPUT_MAN);
  3797. fputs(mxmlElementGetAttr(arg, "name"), stdout);
  3798. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  3799. printf(" %s", defval);
  3800. puts(";\n"
  3801. ".fi");
  3802. write_description(stdout, description, NULL, 0);
  3803. }
  3804. }
  3805. if (footerfile)
  3806. {
  3807. /*
  3808. * Use custom footer...
  3809. */
  3810. write_file(stdout, footerfile);
  3811. }
  3812. }
  3813. /*
  3814. * 'write_scu()' - Write a structure, class, or union.
  3815. */
  3816. static void
  3817. write_scu(FILE *out, /* I - Output file */
  3818. mxml_node_t *doc, /* I - Document */
  3819. mxml_node_t *scut) /* I - Structure, class, or union */
  3820. {
  3821. int i; /* Looping var */
  3822. mxml_node_t *function, /* Current function */
  3823. *arg, /* Current argument */
  3824. *description, /* Description of function/var */
  3825. *type; /* Type for argument */
  3826. const char *name, /* Name of function/type */
  3827. *cname, /* Class name */
  3828. *defval, /* Default value */
  3829. *parent, /* Parent class */
  3830. *scope; /* Scope for variable/function */
  3831. int inscope, /* Variable/method scope */
  3832. maxscope; /* Maximum scope */
  3833. char prefix; /* Prefix character */
  3834. static const char * const scopes[] = /* Scope strings */
  3835. {
  3836. "private",
  3837. "protected",
  3838. "public"
  3839. };
  3840. cname = mxmlElementGetAttr(scut, "name");
  3841. description = mxmlFindElement(scut, scut, "description", NULL,
  3842. NULL, MXML_DESCEND_FIRST);
  3843. fprintf(out, "<h3 class=\"%s\">%s<a name=\"%s\">%s</a></h3>\n",
  3844. scut->value.element.name, get_comment_info(description), cname,
  3845. cname);
  3846. if (description)
  3847. write_description(out, description, "p", 1);
  3848. fprintf(out, "<p class=\"code\">%s %s", scut->value.element.name, cname);
  3849. if ((parent = mxmlElementGetAttr(scut, "parent")) != NULL)
  3850. fprintf(out, " %s", parent);
  3851. fputs(" {<br>\n", out);
  3852. maxscope = !strcmp(scut->value.element.name, "class") ? 3 : 1;
  3853. for (i = 0; i < maxscope; i ++)
  3854. {
  3855. inscope = maxscope == 1;
  3856. for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL,
  3857. MXML_DESCEND_FIRST);
  3858. arg;
  3859. arg = mxmlFindElement(arg, scut, "variable", NULL, NULL,
  3860. MXML_NO_DESCEND))
  3861. {
  3862. if (maxscope > 1 &&
  3863. ((scope = mxmlElementGetAttr(arg, "scope")) == NULL ||
  3864. strcmp(scope, scopes[i])))
  3865. continue;
  3866. if (!inscope)
  3867. {
  3868. inscope = 1;
  3869. fprintf(out, "&nbsp;&nbsp;%s:<br>\n", scopes[i]);
  3870. }
  3871. fputs("&nbsp;&nbsp;&nbsp;&nbsp;", out);
  3872. write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL,
  3873. NULL, MXML_DESCEND_FIRST),
  3874. OUTPUT_HTML);
  3875. fprintf(out, "%s;<br>\n", mxmlElementGetAttr(arg, "name"));
  3876. }
  3877. for (function = mxmlFindElement(scut, scut, "function", NULL, NULL,
  3878. MXML_DESCEND_FIRST);
  3879. function;
  3880. function = mxmlFindElement(function, scut, "function", NULL, NULL,
  3881. MXML_NO_DESCEND))
  3882. {
  3883. if (maxscope > 1 &&
  3884. ((scope = mxmlElementGetAttr(arg, "scope")) == NULL ||
  3885. strcmp(scope, scopes[i])))
  3886. continue;
  3887. if (!inscope)
  3888. {
  3889. inscope = 1;
  3890. fprintf(out, "&nbsp;&nbsp;%s:<br>\n", scopes[i]);
  3891. }
  3892. name = mxmlElementGetAttr(function, "name");
  3893. fputs("&nbsp;&nbsp;&nbsp;&nbsp;", out);
  3894. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  3895. NULL, MXML_DESCEND_FIRST);
  3896. if (arg)
  3897. write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL,
  3898. NULL, MXML_DESCEND_FIRST),
  3899. OUTPUT_HTML);
  3900. else if (strcmp(cname, name) && strcmp(cname, name + 1))
  3901. fputs("void ", out);
  3902. fprintf(out, "<a href=\"#%s.%s\">%s</a>", cname, name, name);
  3903. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  3904. MXML_DESCEND_FIRST), prefix = '(';
  3905. arg;
  3906. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  3907. MXML_NO_DESCEND), prefix = ',')
  3908. {
  3909. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  3910. MXML_DESCEND_FIRST);
  3911. putc(prefix, out);
  3912. if (prefix == ',')
  3913. putc(' ', out);
  3914. if (type->child)
  3915. write_element(out, doc, type, OUTPUT_HTML);
  3916. fputs(mxmlElementGetAttr(arg, "name"), out);
  3917. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  3918. fprintf(out, " %s", defval);
  3919. }
  3920. if (prefix == '(')
  3921. fputs("(void);<br>\n", out);
  3922. else
  3923. fputs(");<br>\n", out);
  3924. }
  3925. }
  3926. fputs("};</p>\n"
  3927. "<h4 class=\"members\">Members</h4>\n"
  3928. "<dl>\n", out);
  3929. for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL,
  3930. MXML_DESCEND_FIRST);
  3931. arg;
  3932. arg = mxmlFindElement(arg, scut, "variable", NULL, NULL,
  3933. MXML_NO_DESCEND))
  3934. {
  3935. description = mxmlFindElement(arg, arg, "description", NULL,
  3936. NULL, MXML_DESCEND_FIRST);
  3937. fprintf(out, "<dt>%s %s</dt>\n",
  3938. mxmlElementGetAttr(arg, "name"), get_comment_info(description));
  3939. write_description(out, description, "dd", 1);
  3940. write_description(out, description, "dd", 0);
  3941. }
  3942. fputs("</dl>\n", out);
  3943. for (function = mxmlFindElement(scut, scut, "function", NULL, NULL,
  3944. MXML_DESCEND_FIRST);
  3945. function;
  3946. function = mxmlFindElement(function, scut, "function", NULL, NULL,
  3947. MXML_NO_DESCEND))
  3948. {
  3949. write_function(out, doc, function, 4);
  3950. }
  3951. }
  3952. /*
  3953. * 'write_string()' - Write a string, quoting HTML special chars as needed.
  3954. */
  3955. static void
  3956. write_string(FILE *out, /* I - Output file */
  3957. const char *s, /* I - String to write */
  3958. int mode) /* I - Output mode */
  3959. {
  3960. switch (mode)
  3961. {
  3962. case OUTPUT_HTML :
  3963. case OUTPUT_XML :
  3964. while (*s)
  3965. {
  3966. if (*s == '&')
  3967. fputs("&amp;", out);
  3968. else if (*s == '<')
  3969. fputs("&lt;", out);
  3970. else if (*s == '>')
  3971. fputs("&gt;", out);
  3972. else if (*s == '\"')
  3973. fputs("&quot;", out);
  3974. else if (*s & 128)
  3975. {
  3976. /*
  3977. * Convert UTF-8 to Unicode constant...
  3978. */
  3979. int ch; /* Unicode character */
  3980. ch = *s & 255;
  3981. if ((ch & 0xe0) == 0xc0)
  3982. {
  3983. ch = ((ch & 0x1f) << 6) | (s[1] & 0x3f);
  3984. s ++;
  3985. }
  3986. else if ((ch & 0xf0) == 0xe0)
  3987. {
  3988. ch = ((((ch * 0x0f) << 6) | (s[1] & 0x3f)) << 6) | (s[2] & 0x3f);
  3989. s += 2;
  3990. }
  3991. if (ch == 0xa0)
  3992. {
  3993. /*
  3994. * Handle non-breaking space as-is...
  3995. */
  3996. fputs("&nbsp;", out);
  3997. }
  3998. else
  3999. fprintf(out, "&#x%x;", ch);
  4000. }
  4001. else
  4002. putc(*s, out);
  4003. s ++;
  4004. }
  4005. break;
  4006. case OUTPUT_MAN :
  4007. while (*s)
  4008. {
  4009. if (*s == '\\' || *s == '-')
  4010. putc('\\', out);
  4011. putc(*s++, out);
  4012. }
  4013. break;
  4014. }
  4015. }
  4016. /*
  4017. * 'write_toc()' - Write a table-of-contents.
  4018. */
  4019. static void
  4020. write_toc(FILE *out, /* I - Output file */
  4021. mxml_node_t *doc, /* I - Document */
  4022. const char *introfile, /* I - Introduction file */
  4023. const char *target, /* I - Target name */
  4024. int xml) /* I - Write XML nodes? */
  4025. {
  4026. FILE *fp; /* Intro file */
  4027. mxml_node_t *function, /* Current function */
  4028. *scut, /* Struct/class/union/typedef */
  4029. *arg, /* Current argument */
  4030. *description; /* Description of function/var */
  4031. const char *name, /* Name of function/type */
  4032. *targetattr; /* Target attribute, if any */
  4033. int xmlid = 1; /* Current XML node ID */
  4034. /*
  4035. * If target is set, it is the frame file that contains the body.
  4036. * Otherwise, we are creating a single-file...
  4037. */
  4038. if (target)
  4039. targetattr = " target=\"body\"";
  4040. else
  4041. targetattr = "";
  4042. /*
  4043. * The table-of-contents is a nested unordered list. Start by
  4044. * reading any intro file to see if there are any headings there.
  4045. */
  4046. if (!xml)
  4047. fputs("<h2 class=\"title\">Contents</h2>\n"
  4048. "<ul class=\"contents\">\n", out);
  4049. if (introfile && (fp = fopen(introfile, "r")) != NULL)
  4050. {
  4051. char line[8192], /* Line from file */
  4052. *ptr, /* Pointer in line */
  4053. *end, /* End of line */
  4054. *anchor, /* Anchor name */
  4055. quote, /* Quote character for value */
  4056. level = '2', /* Current heading level */
  4057. newlevel; /* New heading level */
  4058. int inelement; /* In an element? */
  4059. while (fgets(line, sizeof(line), fp))
  4060. {
  4061. /*
  4062. * See if this line has a heading...
  4063. */
  4064. if ((ptr = strstr(line, "<h")) == NULL &&
  4065. (ptr = strstr(line, "<H")) == NULL)
  4066. continue;
  4067. if (ptr[2] != '2' && ptr[2] != '3')
  4068. continue;
  4069. newlevel = ptr[2];
  4070. /*
  4071. * Make sure we have the whole heading...
  4072. */
  4073. while (!strstr(line, "</h") && !strstr(line, "</H"))
  4074. {
  4075. end = line + strlen(line);
  4076. if (end == (line + sizeof(line) - 1) ||
  4077. !fgets(end, (int)(sizeof(line) - (end - line)), fp))
  4078. break;
  4079. }
  4080. /*
  4081. * Convert newlines and tabs to spaces...
  4082. */
  4083. for (ptr = line; *ptr; ptr ++)
  4084. if (isspace(*ptr & 255))
  4085. *ptr = ' ';
  4086. /*
  4087. * Find the anchor and text...
  4088. */
  4089. for (ptr = strchr(line, '<'); ptr; ptr = strchr(ptr + 1, '<'))
  4090. if (!strncmp(ptr, "<A NAME=", 8) || !strncmp(ptr, "<a name=", 8))
  4091. break;
  4092. if (!ptr)
  4093. continue;
  4094. ptr += 8;
  4095. inelement = 1;
  4096. if (*ptr == '\'' || *ptr == '\"')
  4097. {
  4098. /*
  4099. * Quoted anchor...
  4100. */
  4101. quote = *ptr++;
  4102. anchor = ptr;
  4103. while (*ptr && *ptr != quote)
  4104. ptr ++;
  4105. if (!*ptr)
  4106. continue;
  4107. *ptr++ = '\0';
  4108. }
  4109. else
  4110. {
  4111. /*
  4112. * Non-quoted anchor...
  4113. */
  4114. anchor = ptr;
  4115. while (*ptr && *ptr != '>' && !isspace(*ptr & 255))
  4116. ptr ++;
  4117. if (!*ptr)
  4118. continue;
  4119. if (*ptr == '>')
  4120. inelement = 0;
  4121. *ptr++ = '\0';
  4122. }
  4123. /*
  4124. * Write text until we see "</A>"...
  4125. */
  4126. if (xml)
  4127. {
  4128. if (newlevel < level)
  4129. fputs("</Node>\n"
  4130. "</Subnodes></Node>\n", out);
  4131. else if (newlevel > level && newlevel == '3')
  4132. fputs("<Subnodes>\n", out);
  4133. else if (xmlid > 1)
  4134. fputs("</Node>\n", out);
  4135. level = newlevel;
  4136. fprintf(out, "<Node id=\"%d\">\n"
  4137. "<Path>Documentation/index.html</Path>\n"
  4138. "<Anchor>%s</Anchor>\n"
  4139. "<Name>", xmlid ++, anchor);
  4140. quote = 0;
  4141. while (*ptr)
  4142. {
  4143. if (inelement)
  4144. {
  4145. if (*ptr == quote)
  4146. quote = 0;
  4147. else if (*ptr == '>')
  4148. inelement = 0;
  4149. else if (*ptr == '\'' || *ptr == '\"')
  4150. quote = *ptr;
  4151. }
  4152. else if (*ptr == '<')
  4153. {
  4154. if (!strncmp(ptr, "</A>", 4) || !strncmp(ptr, "</a>", 4))
  4155. break;
  4156. inelement = 1;
  4157. }
  4158. else
  4159. putc(*ptr, out);
  4160. ptr ++;
  4161. }
  4162. fputs("</Name>\n", out);
  4163. }
  4164. else
  4165. {
  4166. if (newlevel < level)
  4167. fputs("</li>\n"
  4168. "</ul></li>\n", out);
  4169. else if (newlevel > level)
  4170. fputs("<ul class=\"subcontents\">\n", out);
  4171. else if (xmlid > 1)
  4172. fputs("</li>\n", out);
  4173. level = newlevel;
  4174. xmlid ++;
  4175. fprintf(out, "%s<li><a href=\"%s#%s\"%s>", level > '2' ? "\t" : "",
  4176. target ? target : "", anchor, targetattr);
  4177. quote = 0;
  4178. while (*ptr)
  4179. {
  4180. if (inelement)
  4181. {
  4182. if (*ptr == quote)
  4183. quote = 0;
  4184. else if (*ptr == '>')
  4185. inelement = 0;
  4186. else if (*ptr == '\'' || *ptr == '\"')
  4187. quote = *ptr;
  4188. }
  4189. else if (*ptr == '<')
  4190. {
  4191. if (!strncmp(ptr, "</A>", 4) || !strncmp(ptr, "</a>", 4))
  4192. break;
  4193. inelement = 1;
  4194. }
  4195. else
  4196. putc(*ptr, out);
  4197. ptr ++;
  4198. }
  4199. fputs("</a>", out);
  4200. }
  4201. }
  4202. if (level > '1')
  4203. {
  4204. if (xml)
  4205. {
  4206. fputs("</Node>\n", out);
  4207. if (level == '3')
  4208. fputs("</Subnodes></Node>\n", out);
  4209. }
  4210. else
  4211. {
  4212. fputs("</li>\n", out);
  4213. if (level == '3')
  4214. fputs("</ul></li>\n", out);
  4215. }
  4216. }
  4217. fclose(fp);
  4218. }
  4219. /*
  4220. * Next the classes...
  4221. */
  4222. if ((scut = find_public(doc, doc, "class")) != NULL)
  4223. {
  4224. if (xml)
  4225. fprintf(out, "<Node id=\"%d\">\n"
  4226. "<Path>Documentation/index.html</Path>\n"
  4227. "<Anchor>CLASSES</Anchor>\n"
  4228. "<Name>Classes</Name>\n"
  4229. "<Subnodes>\n", xmlid ++);
  4230. else
  4231. fprintf(out, "<li><a href=\"%s#CLASSES\"%s>Classes</a>"
  4232. "<ul class=\"code\">\n",
  4233. target ? target : "", targetattr);
  4234. while (scut)
  4235. {
  4236. name = mxmlElementGetAttr(scut, "name");
  4237. description = mxmlFindElement(scut, scut, "description",
  4238. NULL, NULL, MXML_DESCEND_FIRST);
  4239. if (xml)
  4240. {
  4241. fprintf(out, "<Node id=\"%d\">\n"
  4242. "<Path>Documentation/index.html</Path>\n"
  4243. "<Anchor>%s</Anchor>\n"
  4244. "<Name>%s</Name>\n"
  4245. "</Node>\n", xmlid ++, name, name);
  4246. }
  4247. else
  4248. {
  4249. fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"",
  4250. target ? target : "", name, targetattr);
  4251. write_description(out, description, "", 1);
  4252. fprintf(out, "\">%s</a></li>\n", name);
  4253. }
  4254. scut = find_public(scut, doc, "class");
  4255. }
  4256. if (xml)
  4257. fputs("</Subnodes></Node>\n", out);
  4258. else
  4259. fputs("</ul></li>\n", out);
  4260. }
  4261. /*
  4262. * Functions...
  4263. */
  4264. if ((function = find_public(doc, doc, "function")) != NULL)
  4265. {
  4266. if (xml)
  4267. fprintf(out, "<Node id=\"%d\">\n"
  4268. "<Path>Documentation/index.html</Path>\n"
  4269. "<Anchor>FUNCTIONS</Anchor>\n"
  4270. "<Name>Functions</Name>\n"
  4271. "<Subnodes>\n", xmlid ++);
  4272. else
  4273. fprintf(out, "<li><a href=\"%s#FUNCTIONS\"%s>Functions</a>"
  4274. "<ul class=\"code\">\n", target ? target : "", targetattr);
  4275. while (function)
  4276. {
  4277. name = mxmlElementGetAttr(function, "name");
  4278. description = mxmlFindElement(function, function, "description",
  4279. NULL, NULL, MXML_DESCEND_FIRST);
  4280. if (xml)
  4281. {
  4282. fprintf(out, "<Node id=\"%d\">\n"
  4283. "<Path>Documentation/index.html</Path>\n"
  4284. "<Anchor>%s</Anchor>\n"
  4285. "<Name>%s</Name>\n"
  4286. "</Node>\n", xmlid ++, name, name);
  4287. }
  4288. else
  4289. {
  4290. fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"",
  4291. target ? target : "", name, targetattr);
  4292. write_description(out, description, "", 1);
  4293. fprintf(out, "\">%s</a></li>\n", name);
  4294. }
  4295. function = find_public(function, doc, "function");
  4296. }
  4297. if (xml)
  4298. fputs("</Subnodes></Node>\n", out);
  4299. else
  4300. fputs("</ul></li>\n", out);
  4301. }
  4302. /*
  4303. * Data types...
  4304. */
  4305. if ((scut = find_public(doc, doc, "typedef")) != NULL)
  4306. {
  4307. if (xml)
  4308. fprintf(out, "<Node id=\"%d\">\n"
  4309. "<Path>Documentation/index.html</Path>\n"
  4310. "<Anchor>TYPES</Anchor>\n"
  4311. "<Name>Data Types</Name>\n"
  4312. "<Subnodes>\n", xmlid ++);
  4313. else
  4314. fprintf(out, "<li><a href=\"%s#TYPES\"%s>Data Types</a>"
  4315. "<ul class=\"code\">\n", target ? target : "", targetattr);
  4316. while (scut)
  4317. {
  4318. name = mxmlElementGetAttr(scut, "name");
  4319. description = mxmlFindElement(scut, scut, "description",
  4320. NULL, NULL, MXML_DESCEND_FIRST);
  4321. if (xml)
  4322. {
  4323. fprintf(out, "<Node id=\"%d\">\n"
  4324. "<Path>Documentation/index.html</Path>\n"
  4325. "<Anchor>%s</Anchor>\n"
  4326. "<Name>%s</Name>\n"
  4327. "</Node>\n", xmlid ++, name, name);
  4328. }
  4329. else
  4330. {
  4331. fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"",
  4332. target ? target : "", name, targetattr);
  4333. write_description(out, description, "", 1);
  4334. fprintf(out, "\">%s</a></li>\n", name);
  4335. }
  4336. scut = find_public(scut, doc, "typedef");
  4337. }
  4338. if (xml)
  4339. fputs("</Subnodes></Node>\n", out);
  4340. else
  4341. fputs("</ul></li>\n", out);
  4342. }
  4343. /*
  4344. * Structures...
  4345. */
  4346. if ((scut = find_public(doc, doc, "struct")) != NULL)
  4347. {
  4348. if (xml)
  4349. fprintf(out, "<Node id=\"%d\">\n"
  4350. "<Path>Documentation/index.html</Path>\n"
  4351. "<Anchor>STRUCTURES</Anchor>\n"
  4352. "<Name>Structures</Name>\n"
  4353. "<Subnodes>\n", xmlid ++);
  4354. else
  4355. fprintf(out, "<li><a href=\"%s#STRUCTURES\"%s>Structures</a>"
  4356. "<ul class=\"code\">\n", target ? target : "", targetattr);
  4357. while (scut)
  4358. {
  4359. name = mxmlElementGetAttr(scut, "name");
  4360. description = mxmlFindElement(scut, scut, "description",
  4361. NULL, NULL, MXML_DESCEND_FIRST);
  4362. if (xml)
  4363. {
  4364. fprintf(out, "<Node id=\"%d\">\n"
  4365. "<Path>Documentation/index.html</Path>\n"
  4366. "<Anchor>%s</Anchor>\n"
  4367. "<Name>%s</Name>\n"
  4368. "</Node>\n", xmlid ++, name, name);
  4369. }
  4370. else
  4371. {
  4372. fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"",
  4373. target ? target : "", name, targetattr);
  4374. write_description(out, description, "", 1);
  4375. fprintf(out, "\">%s</a></li>\n", name);
  4376. }
  4377. scut = find_public(scut, doc, "struct");
  4378. }
  4379. if (xml)
  4380. fputs("</Subnodes></Node>\n", out);
  4381. else
  4382. fputs("</ul></li>\n", out);
  4383. }
  4384. /*
  4385. * Unions...
  4386. */
  4387. if ((scut = find_public(doc, doc, "union")) != NULL)
  4388. {
  4389. if (xml)
  4390. fprintf(out, "<Node id=\"%d\">\n"
  4391. "<Path>Documentation/index.html</Path>\n"
  4392. "<Anchor>UNIONS</Anchor>\n"
  4393. "<Name>Unions</Name>\n"
  4394. "<Subnodes>\n", xmlid ++);
  4395. else
  4396. fprintf(out,
  4397. "<li><a href=\"%s#UNIONS\"%s>Unions</a><ul class=\"code\">\n",
  4398. target ? target : "", targetattr);
  4399. while (scut)
  4400. {
  4401. name = mxmlElementGetAttr(scut, "name");
  4402. description = mxmlFindElement(scut, scut, "description",
  4403. NULL, NULL, MXML_DESCEND_FIRST);
  4404. if (xml)
  4405. {
  4406. fprintf(out, "<Node id=\"%d\">\n"
  4407. "<Path>Documentation/index.html</Path>\n"
  4408. "<Anchor>%s</Anchor>\n"
  4409. "<Name>%s</Name>\n"
  4410. "</Node>\n", xmlid ++, name, name);
  4411. }
  4412. else
  4413. {
  4414. fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"",
  4415. target ? target : "", name, targetattr);
  4416. write_description(out, description, "", 1);
  4417. fprintf(out, "\">%s</a></li>\n", name);
  4418. }
  4419. scut = find_public(scut, doc, "union");
  4420. }
  4421. if (xml)
  4422. fputs("</Subnodes></Node>\n", out);
  4423. else
  4424. fputs("</ul></li>\n", out);
  4425. }
  4426. /*
  4427. * Globals variables...
  4428. */
  4429. if ((arg = find_public(doc, doc, "variable")) != NULL)
  4430. {
  4431. if (xml)
  4432. fprintf(out, "<Node id=\"%d\">\n"
  4433. "<Path>Documentation/index.html</Path>\n"
  4434. "<Anchor>VARIABLES</Anchor>\n"
  4435. "<Name>Variables</Name>\n"
  4436. "<Subnodes>\n", xmlid ++);
  4437. else
  4438. fprintf(out, "<li><a href=\"%s#VARIABLES\"%s>Variables</a>"
  4439. "<ul class=\"code\">\n", target ? target : "", targetattr);
  4440. while (arg)
  4441. {
  4442. name = mxmlElementGetAttr(arg, "name");
  4443. description = mxmlFindElement(arg, arg, "description",
  4444. NULL, NULL, MXML_DESCEND_FIRST);
  4445. if (xml)
  4446. {
  4447. fprintf(out, "<Node id=\"%d\">\n"
  4448. "<Path>Documentation/index.html</Path>\n"
  4449. "<Anchor>%s</Anchor>\n"
  4450. "<Name>%s</Name>\n"
  4451. "</Node>\n", xmlid ++, name, name);
  4452. }
  4453. else
  4454. {
  4455. fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"",
  4456. target ? target : "", name, targetattr);
  4457. write_description(out, description, "", 1);
  4458. fprintf(out, "\">%s</a></li>\n", name);
  4459. }
  4460. arg = find_public(arg, doc, "variable");
  4461. }
  4462. if (xml)
  4463. fputs("</Subnodes></Node>\n", out);
  4464. else
  4465. fputs("</ul></li>\n", out);
  4466. }
  4467. /*
  4468. * Enumerations/constants...
  4469. */
  4470. if ((scut = find_public(doc, doc, "enumeration")) != NULL)
  4471. {
  4472. if (xml)
  4473. fprintf(out, "<Node id=\"%d\">\n"
  4474. "<Path>Documentation/index.html</Path>\n"
  4475. "<Anchor>ENUMERATIONS</Anchor>\n"
  4476. "<Name>Constants</Name>\n"
  4477. "<Subnodes>\n", xmlid ++);
  4478. else
  4479. fprintf(out, "<li><a href=\"%s#ENUMERATIONS\"%s>Constants</a>"
  4480. "<ul class=\"code\">\n", target ? target : "", targetattr);
  4481. while (scut)
  4482. {
  4483. name = mxmlElementGetAttr(scut, "name");
  4484. description = mxmlFindElement(scut, scut, "description",
  4485. NULL, NULL, MXML_DESCEND_FIRST);
  4486. if (xml)
  4487. {
  4488. fprintf(out, "<Node id=\"%d\">\n"
  4489. "<Path>Documentation/index.html</Path>\n"
  4490. "<Anchor>%s</Anchor>\n"
  4491. "<Name>%s</Name>\n"
  4492. "</Node>\n", xmlid ++, name, name);
  4493. }
  4494. else
  4495. {
  4496. fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"",
  4497. target ? target : "", name, targetattr);
  4498. write_description(out, description, "", 1);
  4499. fprintf(out, "\">%s</a></li>\n", name);
  4500. }
  4501. scut = find_public(scut, doc, "enumeration");
  4502. }
  4503. if (xml)
  4504. fputs("</Subnodes></Node>\n", out);
  4505. else
  4506. fputs("</ul></li>\n", out);
  4507. }
  4508. /*
  4509. * Close out the HTML table-of-contents list as needed...
  4510. */
  4511. if (!xml)
  4512. fputs("</ul>\n", out);
  4513. }
  4514. /*
  4515. * 'write_tokens()' - Write <Token> nodes for all APIs.
  4516. */
  4517. static void
  4518. write_tokens(FILE *out, /* I - Output file */
  4519. mxml_node_t *doc, /* I - Document */
  4520. const char *path) /* I - Path to help file */
  4521. {
  4522. mxml_node_t *function, /* Current function */
  4523. *scut, /* Struct/class/union/typedef */
  4524. *arg, /* Current argument */
  4525. *description, /* Description of function/var */
  4526. *type, /* Type node */
  4527. *node; /* Current child node */
  4528. const char *name, /* Name of function/type */
  4529. *cename, /* Current class/enum name */
  4530. *defval; /* Default value for argument */
  4531. char prefix; /* Prefix for declarations */
  4532. /*
  4533. * Classes...
  4534. */
  4535. if ((scut = find_public(doc, doc, "class")) != NULL)
  4536. {
  4537. while (scut)
  4538. {
  4539. cename = mxmlElementGetAttr(scut, "name");
  4540. description = mxmlFindElement(scut, scut, "description",
  4541. NULL, NULL, MXML_DESCEND_FIRST);
  4542. fprintf(out, "<Token>\n"
  4543. "<Path>Documentation/%s</Path>\n"
  4544. "<Anchor>%s</Anchor>\n"
  4545. "<TokenIdentifier>//apple_ref/cpp/cl/%s</TokenIdentifier>\n"
  4546. "<Abstract>", path, cename, cename);
  4547. write_description(out, description, "", 1);
  4548. fputs("</Abstract>\n"
  4549. "</Token>\n", out);
  4550. if ((function = find_public(scut, scut, "function")) != NULL)
  4551. {
  4552. while (function)
  4553. {
  4554. name = mxmlElementGetAttr(function, "name");
  4555. description = mxmlFindElement(function, function, "description",
  4556. NULL, NULL, MXML_DESCEND_FIRST);
  4557. fprintf(out, "<Token>\n"
  4558. "<Path>Documentation/%s</Path>\n"
  4559. "<Anchor>%s.%s</Anchor>\n"
  4560. "<TokenIdentifier>//apple_ref/cpp/clm/%s/%s", path,
  4561. cename, name, cename, name);
  4562. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  4563. NULL, MXML_DESCEND_FIRST);
  4564. if (arg && (type = mxmlFindElement(arg, arg, "type", NULL,
  4565. NULL, MXML_DESCEND_FIRST)) != NULL)
  4566. {
  4567. for (node = type->child; node; node = node->next)
  4568. fputs(node->value.text.string, out);
  4569. }
  4570. else if (strcmp(cename, name) && strcmp(cename, name + 1))
  4571. fputs("void", out);
  4572. fputs("/", out);
  4573. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  4574. MXML_DESCEND_FIRST), prefix = '(';
  4575. arg;
  4576. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  4577. MXML_NO_DESCEND), prefix = ',')
  4578. {
  4579. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  4580. MXML_DESCEND_FIRST);
  4581. putc(prefix, out);
  4582. for (node = type->child; node; node = node->next)
  4583. fputs(node->value.text.string, out);
  4584. fputs(mxmlElementGetAttr(arg, "name"), out);
  4585. }
  4586. if (prefix == '(')
  4587. fputs("(void", out);
  4588. fputs(")</TokenIdentifier>\n"
  4589. "<Abstract>", out);
  4590. write_description(out, description, "", 1);
  4591. fputs("</Abstract>\n"
  4592. "<Declaration>", out);
  4593. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  4594. NULL, MXML_DESCEND_FIRST);
  4595. if (arg)
  4596. write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL,
  4597. NULL, MXML_DESCEND_FIRST),
  4598. OUTPUT_XML);
  4599. else if (strcmp(cename, name) && strcmp(cename, name + 1))
  4600. fputs("void ", out);
  4601. fputs(name, out);
  4602. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  4603. MXML_DESCEND_FIRST), prefix = '(';
  4604. arg;
  4605. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  4606. MXML_NO_DESCEND), prefix = ',')
  4607. {
  4608. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  4609. MXML_DESCEND_FIRST);
  4610. putc(prefix, out);
  4611. if (prefix == ',')
  4612. putc(' ', out);
  4613. if (type->child)
  4614. write_element(out, doc, type, OUTPUT_XML);
  4615. fputs(mxmlElementGetAttr(arg, "name"), out);
  4616. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  4617. fprintf(out, " %s", defval);
  4618. }
  4619. if (prefix == '(')
  4620. fputs("(void);", out);
  4621. else
  4622. fputs(");", out);
  4623. fputs("</Declaration>\n"
  4624. "</Token>\n", out);
  4625. function = find_public(function, doc, "function");
  4626. }
  4627. }
  4628. scut = find_public(scut, doc, "class");
  4629. }
  4630. }
  4631. /*
  4632. * Functions...
  4633. */
  4634. if ((function = find_public(doc, doc, "function")) != NULL)
  4635. {
  4636. while (function)
  4637. {
  4638. name = mxmlElementGetAttr(function, "name");
  4639. description = mxmlFindElement(function, function, "description",
  4640. NULL, NULL, MXML_DESCEND_FIRST);
  4641. fprintf(out, "<Token>\n"
  4642. "<Path>Documentation/%s</Path>\n"
  4643. "<Anchor>%s</Anchor>\n"
  4644. "<TokenIdentifier>//apple_ref/c/func/%s</TokenIdentifier>\n"
  4645. "<Abstract>", path, name, name);
  4646. write_description(out, description, "", 1);
  4647. fputs("</Abstract>\n"
  4648. "<Declaration>", out);
  4649. arg = mxmlFindElement(function, function, "returnvalue", NULL,
  4650. NULL, MXML_DESCEND_FIRST);
  4651. if (arg)
  4652. write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL,
  4653. NULL, MXML_DESCEND_FIRST),
  4654. OUTPUT_XML);
  4655. else // if (strcmp(cname, name) && strcmp(cname, name + 1))
  4656. fputs("void ", out);
  4657. fputs(name, out);
  4658. for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
  4659. MXML_DESCEND_FIRST), prefix = '(';
  4660. arg;
  4661. arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
  4662. MXML_NO_DESCEND), prefix = ',')
  4663. {
  4664. type = mxmlFindElement(arg, arg, "type", NULL, NULL,
  4665. MXML_DESCEND_FIRST);
  4666. putc(prefix, out);
  4667. if (prefix == ',')
  4668. putc(' ', out);
  4669. if (type->child)
  4670. write_element(out, doc, type, OUTPUT_XML);
  4671. fputs(mxmlElementGetAttr(arg, "name"), out);
  4672. if ((defval = mxmlElementGetAttr(arg, "default")) != NULL)
  4673. fprintf(out, " %s", defval);
  4674. }
  4675. if (prefix == '(')
  4676. fputs("(void);", out);
  4677. else
  4678. fputs(");", out);
  4679. fputs("</Declaration>\n"
  4680. "</Token>\n", out);
  4681. function = find_public(function, doc, "function");
  4682. }
  4683. }
  4684. /*
  4685. * Data types...
  4686. */
  4687. if ((scut = find_public(doc, doc, "typedef")) != NULL)
  4688. {
  4689. while (scut)
  4690. {
  4691. name = mxmlElementGetAttr(scut, "name");
  4692. description = mxmlFindElement(scut, scut, "description",
  4693. NULL, NULL, MXML_DESCEND_FIRST);
  4694. fprintf(out, "<Token>\n"
  4695. "<Path>Documentation/%s</Path>\n"
  4696. "<Anchor>%s</Anchor>\n"
  4697. "<TokenIdentifier>//apple_ref/c/tdef/%s</TokenIdentifier>\n"
  4698. "<Abstract>", path, name, name);
  4699. write_description(out, description, "", 1);
  4700. fputs("</Abstract>\n"
  4701. "</Token>\n", out);
  4702. scut = find_public(scut, doc, "typedef");
  4703. }
  4704. }
  4705. /*
  4706. * Structures...
  4707. */
  4708. if ((scut = find_public(doc, doc, "struct")) != NULL)
  4709. {
  4710. while (scut)
  4711. {
  4712. name = mxmlElementGetAttr(scut, "name");
  4713. description = mxmlFindElement(scut, scut, "description",
  4714. NULL, NULL, MXML_DESCEND_FIRST);
  4715. fprintf(out, "<Token>\n"
  4716. "<Path>Documentation/%s</Path>\n"
  4717. "<Anchor>%s</Anchor>\n"
  4718. "<TokenIdentifier>//apple_ref/c/tag/%s</TokenIdentifier>\n"
  4719. "<Abstract>", path, name, name);
  4720. write_description(out, description, "", 1);
  4721. fputs("</Abstract>\n"
  4722. "</Token>\n", out);
  4723. scut = find_public(scut, doc, "struct");
  4724. }
  4725. }
  4726. /*
  4727. * Unions...
  4728. */
  4729. if ((scut = find_public(doc, doc, "union")) != NULL)
  4730. {
  4731. while (scut)
  4732. {
  4733. name = mxmlElementGetAttr(scut, "name");
  4734. description = mxmlFindElement(scut, scut, "description",
  4735. NULL, NULL, MXML_DESCEND_FIRST);
  4736. fprintf(out, "<Token>\n"
  4737. "<Path>Documentation/%s</Path>\n"
  4738. "<Anchor>%s</Anchor>\n"
  4739. "<TokenIdentifier>//apple_ref/c/tag/%s</TokenIdentifier>\n"
  4740. "<Abstract>", path, name, name);
  4741. write_description(out, description, "", 1);
  4742. fputs("</Abstract>\n"
  4743. "</Token>\n", out);
  4744. scut = find_public(scut, doc, "union");
  4745. }
  4746. }
  4747. /*
  4748. * Globals variables...
  4749. */
  4750. if ((arg = find_public(doc, doc, "variable")) != NULL)
  4751. {
  4752. while (arg)
  4753. {
  4754. name = mxmlElementGetAttr(arg, "name");
  4755. description = mxmlFindElement(arg, arg, "description",
  4756. NULL, NULL, MXML_DESCEND_FIRST);
  4757. fprintf(out, "<Token>\n"
  4758. "<Path>Documentation/%s</Path>\n"
  4759. "<Anchor>%s</Anchor>\n"
  4760. "<TokenIdentifier>//apple_ref/c/data/%s</TokenIdentifier>\n"
  4761. "<Abstract>", path, name, name);
  4762. write_description(out, description, "", 1);
  4763. fputs("</Abstract>\n"
  4764. "</Token>\n", out);
  4765. arg = find_public(arg, doc, "variable");
  4766. }
  4767. }
  4768. /*
  4769. * Enumerations/constants...
  4770. */
  4771. if ((scut = find_public(doc, doc, "enumeration")) != NULL)
  4772. {
  4773. while (scut)
  4774. {
  4775. cename = mxmlElementGetAttr(scut, "name");
  4776. description = mxmlFindElement(scut, scut, "description",
  4777. NULL, NULL, MXML_DESCEND_FIRST);
  4778. fprintf(out, "<Token>\n"
  4779. "<Path>Documentation/%s</Path>\n"
  4780. "<Anchor>%s</Anchor>\n"
  4781. "<TokenIdentifier>//apple_ref/c/tag/%s</TokenIdentifier>\n"
  4782. "<Abstract>", path, cename, cename);
  4783. write_description(out, description, "", 1);
  4784. fputs("</Abstract>\n"
  4785. "</Token>\n", out);
  4786. for (arg = mxmlFindElement(scut, scut, "constant", NULL, NULL,
  4787. MXML_DESCEND_FIRST);
  4788. arg;
  4789. arg = mxmlFindElement(arg, scut, "constant", NULL, NULL,
  4790. MXML_NO_DESCEND))
  4791. {
  4792. name = mxmlElementGetAttr(arg, "name");
  4793. description = mxmlFindElement(arg, arg, "description", NULL,
  4794. NULL, MXML_DESCEND_FIRST);
  4795. fprintf(out, "<Token>\n"
  4796. "<Path>Documentation/%s</Path>\n"
  4797. "<Anchor>%s</Anchor>\n"
  4798. "<TokenIdentifier>//apple_ref/c/econst/%s</TokenIdentifier>\n"
  4799. "<Abstract>", path, cename, name);
  4800. write_description(out, description, "", 1);
  4801. fputs("</Abstract>\n"
  4802. "</Token>\n", out);
  4803. }
  4804. scut = find_public(scut, doc, "enumeration");
  4805. }
  4806. }
  4807. }
  4808. /*
  4809. * 'ws_cb()' - Whitespace callback for saving.
  4810. */
  4811. static const char * /* O - Whitespace string or NULL for none */
  4812. ws_cb(mxml_node_t *node, /* I - Element node */
  4813. int where) /* I - Where value */
  4814. {
  4815. const char *name; /* Name of element */
  4816. int depth; /* Depth of node */
  4817. static const char *spaces = " ";
  4818. /* Whitespace (40 spaces) for indent */
  4819. name = node->value.element.name;
  4820. switch (where)
  4821. {
  4822. case MXML_WS_BEFORE_CLOSE :
  4823. if (strcmp(name, "argument") &&
  4824. strcmp(name, "class") &&
  4825. strcmp(name, "constant") &&
  4826. strcmp(name, "enumeration") &&
  4827. strcmp(name, "function") &&
  4828. strcmp(name, "mxmldoc") &&
  4829. strcmp(name, "namespace") &&
  4830. strcmp(name, "returnvalue") &&
  4831. strcmp(name, "struct") &&
  4832. strcmp(name, "typedef") &&
  4833. strcmp(name, "union") &&
  4834. strcmp(name, "variable"))
  4835. return (NULL);
  4836. for (depth = -4; node; node = node->parent, depth += 2);
  4837. if (depth > 40)
  4838. return (spaces);
  4839. else if (depth < 2)
  4840. return (NULL);
  4841. else
  4842. return (spaces + 40 - depth);
  4843. case MXML_WS_AFTER_CLOSE :
  4844. return ("\n");
  4845. case MXML_WS_BEFORE_OPEN :
  4846. for (depth = -4; node; node = node->parent, depth += 2);
  4847. if (depth > 40)
  4848. return (spaces);
  4849. else if (depth < 2)
  4850. return (NULL);
  4851. else
  4852. return (spaces + 40 - depth);
  4853. default :
  4854. case MXML_WS_AFTER_OPEN :
  4855. if (strcmp(name, "argument") &&
  4856. strcmp(name, "class") &&
  4857. strcmp(name, "constant") &&
  4858. strcmp(name, "enumeration") &&
  4859. strcmp(name, "function") &&
  4860. strcmp(name, "mxmldoc") &&
  4861. strcmp(name, "namespace") &&
  4862. strcmp(name, "returnvalue") &&
  4863. strcmp(name, "struct") &&
  4864. strcmp(name, "typedef") &&
  4865. strcmp(name, "union") &&
  4866. strcmp(name, "variable") &&
  4867. strncmp(name, "?xml", 4))
  4868. return (NULL);
  4869. else
  4870. return ("\n");
  4871. }
  4872. }
  4873. /*
  4874. * End of "$Id: mxmldoc.c 451 2014-01-04 21:50:06Z msweet $".
  4875. */