vms.c 179 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752
  1. /*
  2. Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 2009-Jan-02 or later
  4. (the contents of which are also included in unzip.h) for terms of use.
  5. If, for some reason, all these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  7. */
  8. /*---------------------------------------------------------------------------
  9. vms.c Igor Mandrichenko and others
  10. This file contains routines to extract VMS file attributes from a zipfile
  11. extra field and create a file with these attributes. The code was almost
  12. entirely written by Igor, with a couple of routines by GRR and lots of
  13. modifications and fixes by Christian Spieler.
  14. Contains: check_format()
  15. open_outfile()
  16. find_vms_attrs()
  17. flush()
  18. close_outfile()
  19. defer_dir_attribs()
  20. set_direc_attribs()
  21. dos_to_unix_time() (TIMESTAMP only)
  22. stamp_file() (TIMESTAMP only)
  23. vms_msg_text()
  24. do_wild()
  25. mapattr()
  26. mapname()
  27. checkdir()
  28. check_for_newer()
  29. return_VMS
  30. screensize()
  31. screenlinewrap()
  32. version()
  33. ---------------------------------------------------------------------------*/
  34. #ifdef VMS /* VMS only! */
  35. #define UNZIP_INTERNAL
  36. #include "unzip.h"
  37. #include "crc32.h"
  38. #include "vms.h"
  39. #include "vmsdefs.h"
  40. #ifdef MORE
  41. # include <ttdef.h>
  42. #endif
  43. #include <unixlib.h>
  44. #include <dvidef.h>
  45. #include <ssdef.h>
  46. #include <stsdef.h>
  47. /* Workaround for broken header files of older DECC distributions
  48. * that are incompatible with the /NAMES=AS_IS qualifier. */
  49. #define lib$getdvi LIB$GETDVI
  50. #define lib$getsyi LIB$GETSYI
  51. #define lib$sys_getmsg LIB$SYS_GETMSG
  52. #include <lib$routines.h>
  53. #ifndef EEXIST
  54. # include <errno.h> /* For mkdir() status codes */
  55. #endif
  56. /* On VAX, define Goofy VAX Type-Cast to obviate /standard = vaxc.
  57. Otherwise, lame system headers on VAX cause compiler warnings.
  58. (GNU C may define vax but not __VAX.)
  59. */
  60. #ifdef vax
  61. # define __VAX 1
  62. #endif
  63. #ifdef __VAX
  64. # define GVTC (unsigned int)
  65. #else
  66. # define GVTC
  67. #endif
  68. /* With GNU C, some FAB bits may be declared only as masks, not as
  69. * structure bits.
  70. */
  71. #ifdef __GNUC__
  72. # define OLD_FABDEF 1
  73. #endif
  74. #define ASYNCH_QIO /* Use asynchronous PK-style QIO writes */
  75. /* buffer size for a single block write (using RMS or QIO WRITEVBLK),
  76. must be less than 64k and a multiple of 512 ! */
  77. #define BUFS512 (((OUTBUFSIZ>0xFFFF) ? 0xFFFF : OUTBUFSIZ) & (~511))
  78. /* buffer size for record output (RMS limit for max. record size) */
  79. #define BUFSMAXREC 32767
  80. /* allocation size for RMS and QIO output buffers */
  81. #define BUFSALLOC (BUFS512 * 2 > BUFSMAXREC ? BUFS512 * 2 : BUFSMAXREC)
  82. /* locbuf size */
  83. /* VMS success or warning status */
  84. #define OK(s) (((s) & STS$M_SUCCESS) != 0)
  85. #define STRICMP(s1, s2) STRNICMP(s1, s2, 2147483647)
  86. /* Interactive inquiry response codes for replace(). */
  87. #define REPL_NO_EXTRACT 0
  88. #define REPL_NEW_VERSION 1
  89. #define REPL_OVERWRITE 2
  90. #define REPL_ERRLV_WARN 256
  91. #define REPL_TASKMASK 255
  92. /* 2008-09-13 CS.
  93. * Note: In extract.c, there are similar strings "InvalidResponse" and
  94. * "AssumeNone" defined. However, as the UI functionality of the VMS
  95. * "version-aware" query is slightly different from the generic variant,
  96. * these strings are kept separate for now to allow independent
  97. * "fine tuning" without affecting the other variant of the
  98. * "overwrite or ..." user query.
  99. */
  100. ZCONST char Far InvalidResponse[] =
  101. "error: invalid response [%.1s]\n";
  102. ZCONST char Far AssumeNo[] =
  103. "\n(EOF or read error, treating as \"[N]o extract (all)\" ...)\n";
  104. #ifdef SET_DIR_ATTRIB
  105. /* Structure for holding directory attribute data for final processing
  106. * after all files are in place.
  107. */
  108. typedef struct vmsdirattr {
  109. struct vmsdirattr *next; /* link to next in (linked) list */
  110. char *fn; /* file (directory) name */
  111. /* Non-VMS attributes data */
  112. ulg mod_dos_datetime; /* G.lrec.last_mod_dos_datetime */
  113. unsigned perms; /* same as min_info.file_attr */
  114. unsigned xlen; /* G.lrec.extra_field_length */
  115. char buf[1]; /* data buffer (extra_field, fn) */
  116. } vmsdirattr;
  117. #define VmsAtt(d) ((vmsdirattr *)d) /* typecast shortcut */
  118. #endif /* SET_DIR_ATTRIB */
  119. /*
  120. * Local static storage
  121. */
  122. static struct FAB fileblk; /* File Access Block */
  123. static struct XABDAT dattim; /* date-time XAB */
  124. static struct XABRDT rdt; /* revision date-time XAB */
  125. static struct RAB rab; /* Record Access Block */
  126. static struct NAM_STRUCT nam; /* name block */
  127. static struct FAB *outfab = NULL;
  128. static struct RAB *outrab = NULL;
  129. static struct XABFHC *xabfhc = NULL; /* file header characteristics */
  130. static struct XABDAT *xabdat = NULL; /* date-time */
  131. static struct XABRDT *xabrdt = NULL; /* revision date-time */
  132. static struct XABPRO *xabpro = NULL; /* protection */
  133. static struct XABKEY *xabkey = NULL; /* key (indexed) */
  134. static struct XABALL *xaball = NULL; /* allocation */
  135. static struct XAB *first_xab = NULL, *last_xab = NULL;
  136. static int replace_code_all = -1; /* All-file response for replace(). */
  137. static uch rfm;
  138. static uch locbuf[BUFSALLOC]; /* Space for 2 buffers of BUFS512 */
  139. static unsigned loccnt = 0;
  140. static uch *locptr;
  141. static char got_eol = 0;
  142. struct bufdsc
  143. {
  144. struct bufdsc *next;
  145. uch *buf;
  146. unsigned bufcnt;
  147. };
  148. static struct bufdsc b1, b2, *curbuf; /* buffer ring for asynchronous I/O */
  149. static int _flush_blocks(__GPRO__ uch *rawbuf, unsigned size, int final_flag);
  150. static int _flush_stream(__GPRO__ uch *rawbuf, unsigned size, int final_flag);
  151. static int _flush_varlen(__GPRO__ uch *rawbuf, unsigned size, int final_flag);
  152. static int _flush_qio(__GPRO__ uch *rawbuf, unsigned size, int final_flag);
  153. static int _close_rms(__GPRO);
  154. static int _close_qio(__GPRO);
  155. #ifdef ASYNCH_QIO
  156. static int WriteQIO(__GPRO__ uch *buf, unsigned len);
  157. #endif
  158. static int WriteBuffer(__GPRO__ uch *buf, unsigned len);
  159. static int WriteRecord(__GPRO__ uch *rec, unsigned len);
  160. static int (*_flush_routine)(__GPRO__ uch *rawbuf, unsigned size,
  161. int final_flag);
  162. static int (*_close_routine)(__GPRO);
  163. #ifdef SYMLINKS
  164. static int _read_link_rms(__GPRO__ int byte_count, char *link_text_buf);
  165. #endif /* SYMLINKS */
  166. static void init_buf_ring(void);
  167. static void set_default_datetime_XABs(__GPRO);
  168. static int create_default_output(__GPRO);
  169. static int create_rms_output(__GPRO);
  170. static int create_qio_output(__GPRO);
  171. static int replace(__GPRO);
  172. static int replace_rms_newversion(__GPRO);
  173. static int replace_rms_overwrite(__GPRO);
  174. static int find_vms_attrs(__GPRO__ int set_date_time);
  175. static void free_up(void);
  176. #ifdef CHECK_VERSIONS
  177. static int get_vms_version(char *verbuf, int len);
  178. #endif /* CHECK_VERSIONS */
  179. static unsigned find_eol(ZCONST uch *p, unsigned n, unsigned *l);
  180. #ifdef SET_DIR_ATTRIB
  181. static char *vms_path_fixdown(ZCONST char *dir_spec, char *dir_file);
  182. #endif
  183. #ifdef TIMESTAMP
  184. static time_t mkgmtime(struct tm *tm);
  185. static void uxtime2vmstime(time_t utimeval, long int binval[2]);
  186. #endif /* TIMESTAMP */
  187. static int vms_msg_fetch(int status);
  188. static void vms_msg(__GPRO__ ZCONST char *string, int status);
  189. /*
  190. 2005-02-14 SMS.
  191. Added some ODS5 support:
  192. Use longer name structures in NAML, where available.
  193. Locate special characters mindful of "^" escapes.
  194. */
  195. /* Hex digit table. */
  196. char hex_digit[16] = {
  197. '0', '1', '2', '3', '4', '5', '6', '7',
  198. '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
  199. };
  200. /* Character property table for converting Zip file names to
  201. (simpler) ODS2 or (escaped) ODS5 extended file names.
  202. ODS2 valid characters: 0-9 A-Z a-z $ - _
  203. ODS5 Invalid characters:
  204. C0 control codes (0x00 to 0x1F inclusive)
  205. Asterisk (*)
  206. Question mark (?)
  207. ODS5 Invalid characters only in VMS V7.2 (which no one runs, right?):
  208. Double quotation marks (")
  209. Backslash (\)
  210. Colon (:)
  211. Left angle bracket (<)
  212. Right angle bracket (>)
  213. Slash (/)
  214. Vertical bar (|)
  215. Characters escaped by "^":
  216. SP ! " # % & ' ( ) + , . : ; =
  217. @ [ \ ] ^ ` { | } ~
  218. Either "^_" or "^ " is accepted as a space. Period (.) is a special
  219. case. Note that un-escaped < and > can also confuse a directory
  220. spec.
  221. Characters put out as ^xx:
  222. 7F (DEL)
  223. 80-9F (C1 control characters)
  224. A0 (nonbreaking space)
  225. FF (Latin small letter y diaeresis)
  226. Other cases:
  227. Unicode: "^Uxxxx", where "xxxx" is four hex digits.
  228. Property table values:
  229. Normal ODS2 1
  230. Lower-case ODS2 2
  231. Period 4
  232. Space 8
  233. ODS5 simple 16
  234. ODS5 1-char escape 32
  235. ODS5 hex-hex escape 64
  236. */
  237. unsigned char char_prop[256] = {
  238. /* NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI */
  239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  240. /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US */
  241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  242. /* SP ! " # $ % & ' ( ) * + , - . / */
  243. 8, 32, 32, 32, 17, 32, 32, 32, 32, 32, 0, 32, 32, 17, 4, 0,
  244. /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
  245. 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 32, 32, 32, 32, 32, 32,
  246. /* @ A B C D E F G H I J K L M N O */
  247. 32, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
  248. /* P Q R S T U V W X Y Z [ \ ] ^ _ */
  249. 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 32, 32, 32, 32, 17,
  250. /* ` a b c d e f g h i j k l m n o */
  251. 32, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
  252. /* p q r s t u v w x y z { | } ~ DEL */
  253. 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 32, 32, 32, 32, 64,
  254. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  255. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  256. 64, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  257. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  258. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  259. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  260. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  261. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 64
  262. };
  263. /* 2004-11-23 SMS.
  264. *
  265. * get_rms_defaults().
  266. *
  267. * Get user-specified values from (DCL) SET RMS_DEFAULT. FAB/RAB
  268. * items of particular interest are:
  269. *
  270. * fab$w_deq default extension quantity (blocks) (write).
  271. * rab$b_mbc multi-block count.
  272. * rab$b_mbf multi-buffer count (used with rah and wbh).
  273. */
  274. #define DIAG_FLAG (uO.vflag >= 3)
  275. /* Default RMS parameter values.
  276. * The default extend quantity (deq) should not matter much here, as the
  277. * initial allocation should always be set according to the known file
  278. * size, and no extension should be needed.
  279. */
  280. #define RMS_DEQ_DEFAULT 16384 /* About 1/4 the max (65535 blocks). */
  281. #define RMS_MBC_DEFAULT 127 /* The max, */
  282. #define RMS_MBF_DEFAULT 2 /* Enough to enable rah and wbh. */
  283. /* GETJPI item descriptor structure. */
  284. typedef struct
  285. {
  286. short buf_len;
  287. short itm_cod;
  288. void *buf;
  289. int *ret_len;
  290. } jpi_item_t;
  291. /* Durable storage */
  292. static int rms_defaults_known = 0;
  293. /* JPI item buffers. */
  294. static unsigned short rms_ext;
  295. static char rms_mbc;
  296. static unsigned char rms_mbf;
  297. /* Active RMS item values. */
  298. unsigned short rms_ext_active;
  299. char rms_mbc_active;
  300. unsigned char rms_mbf_active;
  301. /* GETJPI item lengths. */
  302. static int rms_ext_len; /* Should come back 2. */
  303. static int rms_mbc_len; /* Should come back 1. */
  304. static int rms_mbf_len; /* Should come back 1. */
  305. /* Desperation attempts to define unknown macros. Probably doomed.
  306. * If these get used, expect sys$getjpiw() to return %x00000014 =
  307. * %SYSTEM-F-BADPARAM, bad parameter value.
  308. * They keep compilers with old header files quiet, though.
  309. */
  310. #ifndef JPI$_RMS_EXTEND_SIZE
  311. # define JPI$_RMS_EXTEND_SIZE 542
  312. #endif /* ndef JPI$_RMS_EXTEND_SIZE */
  313. #ifndef JPI$_RMS_DFMBC
  314. # define JPI$_RMS_DFMBC 535
  315. #endif /* ndef JPI$_RMS_DFMBC */
  316. #ifndef JPI$_RMS_DFMBFSDK
  317. # define JPI$_RMS_DFMBFSDK 536
  318. #endif /* ndef JPI$_RMS_DFMBFSDK */
  319. /* GETJPI item descriptor set. */
  320. struct
  321. {
  322. jpi_item_t rms_ext_itm;
  323. jpi_item_t rms_mbc_itm;
  324. jpi_item_t rms_mbf_itm;
  325. int term;
  326. } jpi_itm_lst =
  327. { { 2, JPI$_RMS_EXTEND_SIZE, &rms_ext, &rms_ext_len },
  328. { 1, JPI$_RMS_DFMBC, &rms_mbc, &rms_mbc_len },
  329. { 1, JPI$_RMS_DFMBFSDK, &rms_mbf, &rms_mbf_len },
  330. 0
  331. };
  332. static int get_rms_defaults()
  333. {
  334. int sts;
  335. /* Get process RMS_DEFAULT values. */
  336. sts = sys$getjpiw(0, 0, 0, &jpi_itm_lst, 0, 0, 0);
  337. if ((sts & STS$M_SEVERITY) != STS$K_SUCCESS)
  338. {
  339. /* Failed. Don't try again. */
  340. rms_defaults_known = -1;
  341. }
  342. else
  343. {
  344. /* Fine, but don't come back. */
  345. rms_defaults_known = 1;
  346. }
  347. /* Limit the active values according to the RMS_DEFAULT values. */
  348. if (rms_defaults_known > 0)
  349. {
  350. /* Set the default values. */
  351. rms_ext_active = RMS_DEQ_DEFAULT;
  352. rms_mbc_active = RMS_MBC_DEFAULT;
  353. rms_mbf_active = RMS_MBF_DEFAULT;
  354. /* Default extend quantity. Use the user value, if set. */
  355. if (rms_ext > 0)
  356. {
  357. rms_ext_active = rms_ext;
  358. }
  359. /* Default multi-block count. Use the user value, if set. */
  360. if (rms_mbc > 0)
  361. {
  362. rms_mbc_active = rms_mbc;
  363. }
  364. /* Default multi-buffer count. Use the user value, if set. */
  365. if (rms_mbf > 0)
  366. {
  367. rms_mbf_active = rms_mbf;
  368. }
  369. }
  370. if (DIAG_FLAG)
  371. {
  372. fprintf(stderr, "Get RMS defaults. getjpi sts = %%x%08x.\n", sts);
  373. if (rms_defaults_known > 0)
  374. {
  375. fprintf(stderr,
  376. " Default: deq = %6d, mbc = %3d, mbf = %3d.\n",
  377. rms_ext, rms_mbc, rms_mbf);
  378. }
  379. }
  380. return sts;
  381. }
  382. int check_format(__G)
  383. __GDEF
  384. {
  385. int rtype;
  386. int sts;
  387. struct FAB fab;
  388. #ifdef NAML$C_MAXRSS
  389. struct NAML nam;
  390. #endif
  391. fab = cc$rms_fab; /* Initialize FAB. */
  392. #ifdef NAML$C_MAXRSS
  393. nam = cc$rms_naml; /* Initialize NAML. */
  394. fab.fab$l_naml = &nam; /* Point FAB to NAML. */
  395. fab.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  396. fab.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  397. #endif /* NAML$C_MAXRSS */
  398. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNA = G.zipfn;
  399. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNS = strlen(G.zipfn);
  400. if (ERR(sts = sys$open(&fab)))
  401. {
  402. Info(slide, 1, ((char *)slide, "\n\
  403. error: cannot open zipfile [ %s ].\n",
  404. FnFilter1(G.zipfn)));
  405. vms_msg(__G__ " sys$open() error: ", sts);
  406. return PK_ERR;
  407. }
  408. rtype = fab.fab$b_rfm;
  409. sys$close(&fab);
  410. if (rtype == FAB$C_VAR || rtype == FAB$C_VFC)
  411. {
  412. Info(slide, 1, ((char *)slide, "\n\
  413. Error: zipfile is in variable-length record format. Please\n\
  414. run \"bilf l %s\" to convert the zipfile to stream-LF\n\
  415. record format. (BILF is available at various VMS archives.)\n\n",
  416. FnFilter1(G.zipfn)));
  417. return PK_ERR;
  418. }
  419. return PK_COOL;
  420. }
  421. #define PRINTABLE_FORMAT(x) ( (x) == FAB$C_VAR \
  422. || (x) == FAB$C_STMLF \
  423. || (x) == FAB$C_STMCR \
  424. || (x) == FAB$C_STM )
  425. /* VMS extra field types */
  426. #define VAT_NONE 0
  427. #define VAT_IZ 1 /* old Info-ZIP format */
  428. #define VAT_PK 2 /* PKWARE format */
  429. /*
  430. * open_outfile() assignments:
  431. *
  432. * VMS attributes ? create_xxx _flush_xxx
  433. * ---------------- ---------- ----------
  434. * not found 'default' text mode ?
  435. * yes -> 'stream'
  436. * no -> 'block'
  437. *
  438. * yes, in IZ format 'rms' uO.cflag ?
  439. * yes -> switch (fab.rfm)
  440. * VAR -> 'varlen'
  441. * STM* -> 'stream'
  442. * default -> 'block'
  443. * no -> 'block'
  444. *
  445. * yes, in PK format 'qio' uO.cflag ?
  446. * yes -> switch (pka_rattr)
  447. * VAR -> 'varlen'
  448. * STM* -> 'stream'
  449. * default -> 'block'
  450. * no -> 'qio'
  451. *
  452. * "text mode" == G.pInfo->textmode || (uO.cflag && !uO.bflag)
  453. * (simplified, for complete expression see create_default_output() code)
  454. */
  455. /* The VMS version of open_outfile() supports special return codes:
  456. * OPENOUT_OK a file has been opened normally
  457. * OPENOUT_FAILED the file open process failed
  458. * OPENOUT_SKIPOK file open skipped at user request, err level OK
  459. * OPENOUT_SKIPWARN file open skipped at user request, err level WARN
  460. */
  461. int open_outfile(__G)
  462. __GDEF
  463. {
  464. /* Get process RMS_DEFAULT values, if not already done. */
  465. if (rms_defaults_known == 0)
  466. {
  467. get_rms_defaults();
  468. }
  469. switch (find_vms_attrs(__G__ (uO.D_flag <= 1)))
  470. {
  471. case VAT_NONE:
  472. default:
  473. return create_default_output(__G);
  474. case VAT_IZ:
  475. return create_rms_output(__G);
  476. case VAT_PK:
  477. return create_qio_output(__G);
  478. }
  479. }
  480. static void init_buf_ring()
  481. {
  482. locptr = &locbuf[0];
  483. loccnt = 0;
  484. b1.buf = &locbuf[0];
  485. b1.bufcnt = 0;
  486. b1.next = &b2;
  487. b2.buf = &locbuf[BUFS512];
  488. b2.bufcnt = 0;
  489. b2.next = &b1;
  490. curbuf = &b1;
  491. }
  492. /* Static data storage for time conversion: */
  493. /* string constants for month names */
  494. static ZCONST char *month[] =
  495. {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
  496. "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
  497. /* buffer for time string */
  498. static char timbuf[24]; /* length = first entry in "date_str" + 1 */
  499. /* fixed-length string descriptor for timbuf: */
  500. static ZCONST struct dsc$descriptor date_str =
  501. {sizeof(timbuf)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S, timbuf};
  502. static void set_default_datetime_XABs(__GPRO)
  503. {
  504. unsigned yr, mo, dy, hh, mm, ss;
  505. #ifdef USE_EF_UT_TIME
  506. iztimes z_utime;
  507. struct tm *t;
  508. if (G.extra_field &&
  509. #ifdef IZ_CHECK_TZ
  510. G.tz_is_valid &&
  511. #endif
  512. (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
  513. G.lrec.last_mod_dos_datetime, &z_utime, NULL)
  514. & EB_UT_FL_MTIME))
  515. t = localtime(&(z_utime.mtime));
  516. else
  517. t = (struct tm *)NULL;
  518. if (t != (struct tm *)NULL)
  519. {
  520. yr = t->tm_year + 1900;
  521. mo = t->tm_mon;
  522. dy = t->tm_mday;
  523. hh = t->tm_hour;
  524. mm = t->tm_min;
  525. ss = t->tm_sec;
  526. }
  527. else
  528. {
  529. yr = ((G.lrec.last_mod_dos_datetime >> 25) & 0x7f) + 1980;
  530. mo = ((G.lrec.last_mod_dos_datetime >> 21) & 0x0f) - 1;
  531. dy = (G.lrec.last_mod_dos_datetime >> 16) & 0x1f;
  532. hh = (G.lrec.last_mod_dos_datetime >> 11) & 0x1f;
  533. mm = (G.lrec.last_mod_dos_datetime >> 5) & 0x3f;
  534. ss = (G.lrec.last_mod_dos_datetime << 1) & 0x3e;
  535. }
  536. #else /* !USE_EF_UT_TIME */
  537. yr = ((G.lrec.last_mod_dos_datetime >> 25) & 0x7f) + 1980;
  538. mo = ((G.lrec.last_mod_dos_datetime >> 21) & 0x0f) - 1;
  539. dy = (G.lrec.last_mod_dos_datetime >> 16) & 0x1f;
  540. hh = (G.lrec.last_mod_dos_datetime >> 11) & 0x1f;
  541. mm = (G.lrec.last_mod_dos_datetime >> 5) & 0x3f;
  542. ss = (G.lrec.last_mod_dos_datetime << 1) & 0x1f;
  543. #endif /* ?USE_EF_UT_TIME */
  544. dattim = cc$rms_xabdat; /* fill XABs with default values */
  545. rdt = cc$rms_xabrdt;
  546. sprintf(timbuf, "%02u-%3s-%04u %02u:%02u:%02u.00",
  547. dy, month[mo], yr, hh, mm, ss);
  548. sys$bintim(&date_str, &dattim.xab$q_cdt);
  549. memcpy(&rdt.xab$q_rdt, &dattim.xab$q_cdt, sizeof(rdt.xab$q_rdt));
  550. }
  551. /* The following return codes are supported:
  552. * OPENOUT_OK a file has been opened normally
  553. * OPENOUT_FAILED the file open process failed
  554. * OPENOUT_SKIPOK file open skipped at user request, err level OK
  555. * OPENOUT_SKIPWARN file open skipped at user request, err level WARN
  556. */
  557. static int create_default_output(__GPRO)
  558. {
  559. int ierr;
  560. int text_output, bin_fixed;
  561. /* Extract the file in text format (Variable_length by default,
  562. * Stream_LF with "-S" (/TEXT = STMLF), when
  563. * a) explicitly requested by the user (through the -a option),
  564. * and it is not a symbolic link,
  565. * or
  566. * b) piping to SYS$OUTPUT, unless "binary" piping was requested
  567. * by the user (through the -b option).
  568. */
  569. text_output = (G.pInfo->textmode
  570. #ifdef SYMLINKS
  571. && !G.symlnk
  572. #endif
  573. ) ||
  574. (uO.cflag &&
  575. (!uO.bflag || (!(uO.bflag - 1) && G.pInfo->textfile)));
  576. /* Use fixed length 512 byte record format for disk file when
  577. * a) explicitly requested by the user (-b option),
  578. * and
  579. * b) it is not a symbolic link,
  580. * and
  581. * c) it is not extracted in text mode.
  582. */
  583. bin_fixed = !text_output &&
  584. #ifdef SYMLINKS
  585. !G.symlnk &&
  586. #endif
  587. (uO.bflag != 0) && ((uO.bflag != 1) || !G.pInfo->textfile);
  588. rfm = FAB$C_STMLF; /* Default, stream-LF format from VMS or UNIX */
  589. if (!uO.cflag) /* Redirect output */
  590. {
  591. rab = cc$rms_rab; /* Initialize RAB. */
  592. fileblk = cc$rms_fab; /* Initialize FAB. */
  593. fileblk.fab$l_xab = NULL; /* No XABs. */
  594. rab.rab$l_fab = &fileblk; /* Point RAB to FAB. */
  595. outfab = &fileblk; /* Set pointers used elsewhere. */
  596. outrab = &rab;
  597. if (text_output && (!uO.S_flag))
  598. { /* Default format for output `real' text file */
  599. fileblk.fab$b_rfm = FAB$C_VAR; /* variable length records */
  600. fileblk.fab$b_rat = FAB$M_CR; /* implied (CR) carriage ctrl */
  601. }
  602. else if (bin_fixed)
  603. { /* Default format for output `real' binary file */
  604. fileblk.fab$b_rfm = FAB$C_FIX; /* fixed length records */
  605. fileblk.fab$w_mrs = 512; /* record size 512 bytes */
  606. fileblk.fab$b_rat = 0; /* no carriage ctrl */
  607. }
  608. else
  609. { /* Default format for output misc (bin or text) file */
  610. fileblk.fab$b_rfm = FAB$C_STMLF; /* stream-LF record format */
  611. fileblk.fab$b_rat = FAB$M_CR; /* implied (CR) carriage ctrl */
  612. }
  613. #ifdef NAML$C_MAXRSS
  614. nam = CC_RMS_NAM; /* Initialize NAML. */
  615. fileblk.FAB_NAM = &nam; /* Point FAB to NAML. */
  616. fileblk.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  617. fileblk.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  618. #endif /* NAML$C_MAXRSS */
  619. FAB_OR_NAML(fileblk, nam).FAB_OR_NAML_FNA = G.filename;
  620. FAB_OR_NAML(fileblk, nam).FAB_OR_NAML_FNS = strlen(G.filename);
  621. /* Prepare date-time XABs, unless user requests not to. */
  622. if (uO.D_flag <= 1) {
  623. set_default_datetime_XABs(__G);
  624. dattim.xab$l_nxt = fileblk.fab$l_xab;
  625. fileblk.fab$l_xab = (void *) &dattim;
  626. }
  627. /* 2005-02-14 SMS. What does this mean? ----vvvvvvvvvvvvvvvvvvvvvvvvvvv */
  628. fileblk.fab$w_ifi = 0; /* Clear IFI. It may be nonzero after ZIP */
  629. fileblk.fab$b_fac = FAB$M_BRO | FAB$M_PUT; /* {block|record} output */
  630. #ifdef SYMLINKS
  631. if (G.symlnk)
  632. /* Symlink file is read back to retrieve the link text. */
  633. fileblk.fab$b_fac |= FAB$M_GET;
  634. #endif
  635. /* 2004-11-23 SMS.
  636. * If RMS_DEFAULT values have been determined, and have not been
  637. * set by the user, then set some FAB/RAB parameters for faster
  638. * output. User-specified RMS_DEFAULT values override the
  639. * built-in default values, so if the RMS_DEFAULT values could
  640. * not be determined, then these (possibly unwise) values could
  641. * not be overridden, and hence will not be set. Honestly,
  642. * this seems to be excessively cautious, but only old VMS
  643. * versions will be affected.
  644. */
  645. /* If RMS_DEFAULT (and adjusted active) values are available,
  646. * then set the FAB/RAB parameters. If RMS_DEFAULT values are
  647. * not available, then suffer with the default behavior.
  648. */
  649. if (rms_defaults_known > 0)
  650. {
  651. /* Set the FAB/RAB parameters accordingly. */
  652. fileblk.fab$w_deq = rms_ext_active;
  653. rab.rab$b_mbc = rms_mbc_active;
  654. rab.rab$b_mbf = rms_mbf_active;
  655. #ifdef OLD_FABDEF
  656. /* Truncate at EOF on close, as we may over-extend. */
  657. fileblk.fab$l_fop |= FAB$M_TEF ;
  658. /* If using multiple buffers, enable write-behind. */
  659. if (rms_mbf_active > 1)
  660. {
  661. rab.rab$l_rop |= RAB$M_WBH;
  662. }
  663. }
  664. /* Set the initial file allocation according to the file
  665. * size. Also set the "sequential access only" flag, as
  666. * otherwise, on a file system with highwater marking
  667. * enabled, allocating space for a large file may lock the
  668. * disk for a long time (minutes).
  669. */
  670. fileblk.fab$l_alq = (unsigned) (G.lrec.ucsize+ 511)/ 512;
  671. fileblk.fab$l_fop |= FAB$M_SQO;
  672. #else /* !OLD_FABDEF */
  673. /* Truncate at EOF on close, as we may over-extend. */
  674. fileblk.fab$v_tef = 1;
  675. /* If using multiple buffers, enable write-behind. */
  676. if (rms_mbf_active > 1)
  677. {
  678. rab.rab$v_wbh = 1;
  679. }
  680. }
  681. /* Set the initial file allocation according to the file
  682. * size. Also set the "sequential access only" flag, as
  683. * otherwise, on a file system with highwater marking
  684. * enabled, allocating space for a large file may lock the
  685. * disk for a long time (minutes).
  686. */
  687. fileblk.fab$l_alq = (unsigned) (G.lrec.ucsize+ 511)/ 512;
  688. fileblk.fab$v_sqo = 1;
  689. #endif /* ?OLD_FABDEF */
  690. ierr = sys$create(outfab);
  691. if (ierr == RMS$_FEX)
  692. {
  693. /* File exists.
  694. * Consider command-line options, or ask the user what to do.
  695. */
  696. ierr = replace(__G);
  697. switch (ierr & REPL_TASKMASK)
  698. {
  699. case REPL_NO_EXTRACT: /* No extract. */
  700. free_up();
  701. return ((ierr & REPL_ERRLV_WARN)
  702. ? OPENOUT_SKIPWARN : OPENOUT_SKIPOK);
  703. case REPL_NEW_VERSION: /* Create a new version. */
  704. ierr = replace_rms_newversion(__G);
  705. break;
  706. case REPL_OVERWRITE: /* Overwrite the existing file. */
  707. ierr = replace_rms_overwrite(__G);
  708. break;
  709. }
  710. }
  711. if (ERR(ierr))
  712. {
  713. char buf[NAM_MAXRSS + 128]; /* Name length + message length. */
  714. sprintf(buf, "[ Cannot create ($create) output file %s ]\n",
  715. G.filename);
  716. vms_msg(__G__ buf, ierr);
  717. if (fileblk.fab$l_stv != 0)
  718. {
  719. vms_msg(__G__ "", fileblk.fab$l_stv);
  720. }
  721. free_up();
  722. return OPENOUT_FAILED;
  723. }
  724. if (!text_output)
  725. {
  726. rab.rab$l_rop |= (RAB$M_BIO | RAB$M_ASY);
  727. }
  728. rab.rab$b_rac = RAB$C_SEQ;
  729. if ((ierr = sys$connect(&rab)) != RMS$_NORMAL)
  730. {
  731. #ifdef DEBUG
  732. vms_msg(__G__ "create_default_output: sys$connect failed.\n", ierr);
  733. if (fileblk.fab$l_stv != 0)
  734. {
  735. vms_msg(__G__ "", fileblk.fab$l_stv);
  736. }
  737. #endif
  738. Info(slide, 1, ((char *)slide,
  739. "Cannot create ($connect) output file: %s\n",
  740. FnFilter1(G.filename)));
  741. free_up();
  742. return OPENOUT_FAILED;
  743. }
  744. } /* end if (!uO.cflag) */
  745. init_buf_ring();
  746. _flush_routine = text_output ? got_eol=0,_flush_stream : _flush_blocks;
  747. _close_routine = _close_rms;
  748. return OPENOUT_OK;
  749. }
  750. /* The following return codes are supported:
  751. * OPENOUT_OK a file has been opened normally
  752. * OPENOUT_FAILED the file open process failed
  753. * OPENOUT_SKIPOK file open skipped at user request, err level OK
  754. * OPENOUT_SKIPWARN file open skipped at user request, err level WARN
  755. */
  756. static int create_rms_output(__GPRO)
  757. {
  758. int ierr;
  759. int text_output;
  760. /* extract the file in text (variable-length) format, when
  761. * piping to SYS$OUTPUT, unless "binary" piping was requested
  762. * by the user (through the -b option); the "-a" option is
  763. * ignored when extracting zip entries with VMS attributes saved
  764. */
  765. text_output = uO.cflag &&
  766. (!uO.bflag || (!(uO.bflag - 1) && G.pInfo->textfile));
  767. rfm = outfab->fab$b_rfm; /* Use record format from VMS extra field */
  768. if (uO.cflag) /* SYS$OUTPUT */
  769. {
  770. if (text_output && !PRINTABLE_FORMAT(rfm))
  771. {
  772. Info(slide, 1, ((char *)slide,
  773. "[ File %s has illegal record format to put to screen ]\n",
  774. FnFilter1(G.filename)));
  775. free_up();
  776. return OPENOUT_FAILED;
  777. }
  778. }
  779. else /* File output */
  780. {
  781. rab = cc$rms_rab; /* Initialize RAB. */
  782. /* The output FAB has already been initialized with the values
  783. * found in the Zip file's "VMS attributes" extra field.
  784. */
  785. #ifdef NAML$C_MAXRSS
  786. nam = CC_RMS_NAM; /* Initialize NAML. */
  787. outfab->FAB_NAM = &nam; /* Point FAB to NAML. */
  788. outfab->fab$l_dna = (char *) -1; /* Using NAML for default name. */
  789. outfab->fab$l_fna = (char *) -1; /* Using NAML for file name. */
  790. #endif /* NAML$C_MAXRSS */
  791. FAB_OR_NAML(*outfab, nam).FAB_OR_NAML_FNA = G.filename;
  792. FAB_OR_NAML(*outfab, nam).FAB_OR_NAML_FNS = strlen(G.filename);
  793. /* Prepare date-time XABs, unless user requests not to. */
  794. if (uO.D_flag <= 1) {
  795. /* If no XAB date/time, use attributes from non-VMS fields. */
  796. if (!(xabdat && xabrdt))
  797. {
  798. set_default_datetime_XABs(__G);
  799. if (xabdat == NULL)
  800. {
  801. dattim.xab$l_nxt = outfab->fab$l_xab;
  802. outfab->fab$l_xab = (void *) &dattim;
  803. }
  804. }
  805. }
  806. /* 2005-02-14 SMS. What does this mean? ----vvvvvvvvvvvvvvvvvvvvvvvvvvv */
  807. outfab->fab$w_ifi = 0; /* Clear IFI. It may be nonzero after ZIP */
  808. outfab->fab$b_fac = FAB$M_BIO | FAB$M_PUT; /* block-mode output */
  809. #ifdef SYMLINKS
  810. /* 2007-02-28 SMS.
  811. * VMS/RMS symlink properties will be restored naturally when
  812. * the link file is recreated this way, so there's no need to do
  813. * the deferred symlink post-processing step for this file.
  814. * Therefore, clear the pInfo->symlink flag here, and the symlink
  815. * "close file" processor will only display the link text.
  816. */
  817. if (G.symlnk) {
  818. G.pInfo->symlink = 0;
  819. if (QCOND2) {
  820. /* Symlink file is read back to display the link text. */
  821. outfab->fab$b_fac |= FAB$M_GET;
  822. }
  823. }
  824. #endif /* SYMLINKS */
  825. /* 2004-11-23 SMS.
  826. * Set the "sequential access only" flag, as otherwise, on a
  827. * file system with highwater marking enabled, allocating space
  828. * for a large file may lock the disk for a long time (minutes).
  829. */
  830. #ifdef OLD_FABDEF
  831. outfab-> fab$l_fop |= FAB$M_SQO;
  832. #else /* !OLD_FABDEF */
  833. outfab-> fab$v_sqo = 1;
  834. #endif /* ?OLD_FABDEF */
  835. ierr = sys$create(outfab);
  836. if (ierr == RMS$_FEX)
  837. {
  838. /* File exists.
  839. * Consider command-line options, or ask the user what to do.
  840. */
  841. ierr = replace(__G);
  842. switch (ierr & REPL_TASKMASK)
  843. {
  844. case REPL_NO_EXTRACT: /* No extract. */
  845. free_up();
  846. return ((ierr & REPL_ERRLV_WARN)
  847. ? OPENOUT_SKIPWARN : OPENOUT_SKIPOK);
  848. case REPL_NEW_VERSION: /* Create a new version. */
  849. ierr = replace_rms_newversion(__G);
  850. break;
  851. case REPL_OVERWRITE: /* Overwrite the existing file. */
  852. ierr = replace_rms_overwrite(__G);
  853. break;
  854. }
  855. }
  856. if (ERR(ierr))
  857. {
  858. char buf[NAM_MAXRSS + 128]; /* Name length + message length. */
  859. sprintf(buf, "[ Cannot create ($create) output file %s ]\n",
  860. G.filename);
  861. vms_msg(__G__ buf, ierr);
  862. if (outfab->fab$l_stv != 0)
  863. {
  864. vms_msg(__G__ "", outfab->fab$l_stv);
  865. }
  866. free_up();
  867. return OPENOUT_FAILED;
  868. }
  869. if (outfab->fab$b_org & (FAB$C_REL | FAB$C_IDX)) {
  870. /* relative and indexed files require explicit allocation */
  871. ierr = sys$extend(outfab);
  872. if (ERR(ierr))
  873. {
  874. char buf[NAM_MAXRSS + 128]; /* Name length + msg length. */
  875. sprintf(buf, "[ Cannot allocate space for %s ]\n", G.filename);
  876. vms_msg(__G__ buf, ierr);
  877. if (outfab->fab$l_stv != 0)
  878. {
  879. vms_msg(__G__ "", outfab->fab$l_stv);
  880. }
  881. free_up();
  882. return OPENOUT_FAILED;
  883. }
  884. }
  885. outrab = &rab;
  886. rab.rab$l_fab = outfab;
  887. {
  888. rab.rab$l_rop |= (RAB$M_BIO | RAB$M_ASY);
  889. }
  890. rab.rab$b_rac = RAB$C_SEQ;
  891. if ((ierr = sys$connect(outrab)) != RMS$_NORMAL)
  892. {
  893. #ifdef DEBUG
  894. vms_msg(__G__ "create_rms_output: sys$connect failed.\n", ierr);
  895. if (outfab->fab$l_stv != 0)
  896. {
  897. vms_msg(__G__ "", outfab->fab$l_stv);
  898. }
  899. #endif
  900. Info(slide, 1, ((char *)slide,
  901. "Cannot create ($connect) output file: %s\n",
  902. FnFilter1(G.filename)));
  903. free_up();
  904. return OPENOUT_FAILED;
  905. }
  906. } /* end if (!uO.cflag) */
  907. init_buf_ring();
  908. if ( text_output )
  909. switch (rfm)
  910. {
  911. case FAB$C_VAR:
  912. _flush_routine = _flush_varlen;
  913. break;
  914. case FAB$C_STM:
  915. case FAB$C_STMCR:
  916. case FAB$C_STMLF:
  917. _flush_routine = _flush_stream;
  918. got_eol = 0;
  919. break;
  920. default:
  921. _flush_routine = _flush_blocks;
  922. break;
  923. }
  924. else
  925. _flush_routine = _flush_blocks;
  926. _close_routine = _close_rms;
  927. return OPENOUT_OK;
  928. }
  929. static int pka_devchn;
  930. static int pka_io_pending;
  931. static unsigned pka_vbn;
  932. /* IOSB for QIO[W] read and write operations. */
  933. #if defined(__DECC) || defined(__DECCXX)
  934. #pragma __member_alignment __save
  935. #pragma __nomember_alignment
  936. #endif /* __DECC || __DECCXX */
  937. static struct
  938. {
  939. unsigned short status;
  940. unsigned int count; /* Unaligned ! */
  941. unsigned short dummy;
  942. } pka_io_iosb;
  943. #if defined(__DECC) || defined(__DECCXX)
  944. #pragma __member_alignment __restore
  945. #endif /* __DECC || __DECCXX */
  946. /* IOSB for QIO[W] miscellaneous ACP operations. */
  947. static struct
  948. {
  949. unsigned short status;
  950. unsigned short dummy;
  951. unsigned int count;
  952. } pka_acp_iosb;
  953. static struct fibdef pka_fib;
  954. static struct atrdef pka_atr[VMS_MAX_ATRCNT];
  955. static int pka_idx;
  956. static ulg pka_uchar;
  957. static struct fatdef pka_rattr;
  958. /* Directory attribute storage, descriptor (list). */
  959. static struct atrdef pka_recattr[2] =
  960. { { sizeof(pka_rattr), ATR$C_RECATTR, GVTC &pka_rattr}, /* RECATTR. */
  961. { 0, 0, 0 } /* List terminator. */
  962. };
  963. static struct dsc$descriptor pka_fibdsc =
  964. { sizeof(pka_fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (void *) &pka_fib };
  965. static struct dsc$descriptor_s pka_devdsc =
  966. { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &nam.NAM_DVI[1] };
  967. static struct dsc$descriptor_s pka_fnam =
  968. { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };
  969. /* Expanded and resultant name storage. */
  970. static char exp_nam[NAM_MAXRSS];
  971. static char res_nam[NAM_MAXRSS];
  972. /* Special ODS5-QIO-compatible name storage. */
  973. #ifdef NAML$C_MAXRSS
  974. static char sys_nam[NAML$C_MAXRSS]; /* Probably need less here. */
  975. #endif /* NAML$C_MAXRSS */
  976. #define PK_PRINTABLE_RECTYP(x) ( (x) == FAT$C_VARIABLE \
  977. || (x) == FAT$C_STREAMLF \
  978. || (x) == FAT$C_STREAMCR \
  979. || (x) == FAT$C_STREAM )
  980. /* The following return codes are supported:
  981. * OPENOUT_OK a file has been opened normally
  982. * OPENOUT_FAILED the file open process failed
  983. * OPENOUT_SKIPOK file open skipped at user request, err level OK
  984. * OPENOUT_SKIPWARN file open skipped at user request, err level WARN
  985. */
  986. static int create_qio_output(__GPRO)
  987. {
  988. int status;
  989. int i;
  990. int text_output;
  991. /* extract the file in text (variable-length) format, when
  992. * piping to SYS$OUTPUT, unless "binary" piping was requested
  993. * by the user (through the -b option); the "-a" option is
  994. * ignored when extracting zip entries with VMS attributes saved
  995. */
  996. text_output = uO.cflag &&
  997. (!uO.bflag || (!(uO.bflag - 1) && G.pInfo->textfile));
  998. if ( uO.cflag )
  999. {
  1000. int rtype;
  1001. if (text_output)
  1002. {
  1003. rtype = pka_rattr.fat$v_rtype;
  1004. if (!PK_PRINTABLE_RECTYP(rtype))
  1005. {
  1006. Info(slide, 1, ((char *)slide,
  1007. "[ File %s has illegal record format to put to screen ]\n",
  1008. FnFilter1(G.filename)));
  1009. return OPENOUT_FAILED;
  1010. }
  1011. }
  1012. else
  1013. /* force "block I/O" for binary piping mode */
  1014. rtype = FAT$C_UNDEFINED;
  1015. init_buf_ring();
  1016. switch (rtype)
  1017. {
  1018. case FAT$C_VARIABLE:
  1019. _flush_routine = _flush_varlen;
  1020. break;
  1021. case FAT$C_STREAM:
  1022. case FAT$C_STREAMCR:
  1023. case FAT$C_STREAMLF:
  1024. _flush_routine = _flush_stream;
  1025. got_eol = 0;
  1026. break;
  1027. default:
  1028. _flush_routine = _flush_blocks;
  1029. break;
  1030. }
  1031. _close_routine = _close_rms;
  1032. }
  1033. else /* !(uO.cflag) : redirect output */
  1034. {
  1035. fileblk = cc$rms_fab; /* Initialize FAB. */
  1036. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  1037. fileblk.FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  1038. #ifdef NAML$C_MAXRSS
  1039. fileblk.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  1040. fileblk.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  1041. /* Special ODS5-QIO-compatible name storage. */
  1042. nam.naml$l_filesys_name = sys_nam;
  1043. nam.naml$l_filesys_name_alloc = sizeof(sys_nam);
  1044. #endif /* NAML$C_MAXRSS */
  1045. /* VMS-format file name, derived from archive. */
  1046. FAB_OR_NAML(fileblk, nam).FAB_OR_NAML_FNA = G.filename;
  1047. FAB_OR_NAML(fileblk, nam).FAB_OR_NAML_FNS = strlen(G.filename);
  1048. /* Expanded and resultant name storage. */
  1049. nam.NAM_ESA = exp_nam;
  1050. nam.NAM_ESS = sizeof(exp_nam);
  1051. nam.NAM_RSA = res_nam;
  1052. nam.NAM_RSS = sizeof(res_nam);
  1053. if ( ERR(status = sys$parse(&fileblk)) )
  1054. {
  1055. vms_msg(__G__ "create_qio_output: sys$parse failed.\n", status);
  1056. return OPENOUT_FAILED;
  1057. }
  1058. pka_devdsc.dsc$w_length = (unsigned short)nam.NAM_DVI[0];
  1059. if ( ERR(status = sys$assign(&pka_devdsc, &pka_devchn, 0, 0)) )
  1060. {
  1061. vms_msg(__G__ "create_qio_output: sys$assign failed.\n", status);
  1062. return OPENOUT_FAILED;
  1063. }
  1064. #ifdef NAML$C_MAXRSS
  1065. /* Enable fancy name characters. Note that "fancy" here does
  1066. not include Unicode, for which there's no support elsewhere.
  1067. */
  1068. pka_fib.fib$v_names_8bit = 1;
  1069. pka_fib.fib$b_name_format_in = FIB$C_ISL1;
  1070. /* ODS5 Extended names used as input to QIO have peculiar
  1071. encoding (perhaps to minimize storage?), so the special
  1072. filesys_name result (typically containing fewer carets) must
  1073. be used here.
  1074. */
  1075. pka_fnam.dsc$a_pointer = nam.naml$l_filesys_name;
  1076. pka_fnam.dsc$w_length = nam.naml$l_filesys_name_size;
  1077. #else /* !NAML$C_MAXRSS */
  1078. /* Extract only the name.type;version.
  1079. 2005-02-14 SMS.
  1080. Note: In old code, the version in the name here was retained
  1081. only if -V (uO.V_flag, so that there might be an explicit
  1082. version number in the archive (or perhaps not)), but the
  1083. version should already have been stripped before this in
  1084. adj_file_name_odsX(), and sys$parse() here should always
  1085. return a good version number which may be used as-is. If
  1086. not, here's where to fix the (new) problem. Note that the
  1087. ODS5-compatible code uses the whole thing in filesys_name,
  1088. too, and that's critical for proper interpretation of funny
  1089. names. (Omitting the ";" can cause trouble, so it should
  1090. certainly be kept, even if the version digits are removed
  1091. here.)
  1092. */
  1093. pka_fnam.dsc$a_pointer = nam.NAM_L_NAME;
  1094. pka_fnam.dsc$w_length =
  1095. nam.NAM_B_NAME + nam.NAM_B_TYPE + nam.NAM_B_VER;
  1096. #if 0
  1097. pka_fnam.dsc$w_length = nam.NAM_B_NAME + nam.NAM_B_TYPE;
  1098. if ( uO.V_flag /* keep versions */ )
  1099. pka_fnam.dsc$w_length += nam.NAM_B_VER;
  1100. #endif /* 0 */
  1101. #endif /* ?NAML$C_MAXRSS */
  1102. /* Move the directory ID from the NAM[L] to the FIB.
  1103. Clear the FID in the FIB, as we're using the name.
  1104. */
  1105. for (i = 0; i < 3; i++)
  1106. {
  1107. pka_fib.FIB$W_DID[i] = nam.NAM_DID[i];
  1108. pka_fib.FIB$W_FID[i] = 0;
  1109. }
  1110. /* 2004-11-23 SMS.
  1111. * Set the "sequential access only" flag, as otherwise, on a
  1112. * file system with highwater marking enabled, allocating space
  1113. * for a large file may lock the disk for a long time (minutes).
  1114. * (The "no other readers" flag is also required, if you want
  1115. * the "sequential access only" flag to have any effect.)
  1116. */
  1117. pka_fib.FIB$L_ACCTL = FIB$M_WRITE | FIB$M_SEQONLY | FIB$M_NOREAD;
  1118. /* Allocate space for the file */
  1119. pka_fib.FIB$W_EXCTL = FIB$M_EXTEND;
  1120. if ( pka_uchar & FCH$M_CONTIG )
  1121. pka_fib.FIB$W_EXCTL |= FIB$M_ALCON | FIB$M_FILCON;
  1122. if ( pka_uchar & FCH$M_CONTIGB )
  1123. pka_fib.FIB$W_EXCTL |= FIB$M_ALCONB;
  1124. #define SWAPW(x) ( (((x)>>16)&0xFFFF) + ((x)<<16) )
  1125. pka_fib.fib$l_exsz = SWAPW(pka_rattr.fat$l_hiblk);
  1126. status = sys$qiow(0, /* event flag */
  1127. pka_devchn, /* channel */
  1128. IO$_CREATE|IO$M_CREATE|IO$M_ACCESS, /* funct */
  1129. &pka_acp_iosb, /* IOSB */
  1130. 0, /* AST address */
  1131. 0, /* AST parameter */
  1132. &pka_fibdsc, /* P1 = File Info Block */
  1133. &pka_fnam, /* P2 = File name (descr) */
  1134. 0, /* P3 (= Resulting name len) */
  1135. 0, /* P4 (= Resulting name descr) */
  1136. pka_atr, /* P5 = Attribute descr */
  1137. 0); /* P6 (not used) */
  1138. if ( !ERR(status) )
  1139. status = pka_acp_iosb.status;
  1140. if ( status == SS$_DUPFILENAME )
  1141. {
  1142. /* File exists. Prepare to ask user what to do. */
  1143. /* Arrange to store the resultant file spec (with new
  1144. * version?) where the message code will find it.
  1145. */
  1146. short res_nam_len;
  1147. struct dsc$descriptor_s res_nam_dscr =
  1148. { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };
  1149. res_nam_dscr.dsc$a_pointer = G.filename;
  1150. res_nam_dscr.dsc$w_length = sizeof(G.filename);
  1151. /* File exists.
  1152. * Consider command-line options, or ask the user what to do.
  1153. */
  1154. status = replace(__G);
  1155. switch (status & REPL_TASKMASK)
  1156. {
  1157. case REPL_NO_EXTRACT: /* No extract. */
  1158. free_up();
  1159. return ((status & REPL_ERRLV_WARN)
  1160. ? OPENOUT_SKIPWARN : OPENOUT_SKIPOK);
  1161. case REPL_NEW_VERSION: /* Create a new version. */
  1162. pka_fib.FIB$W_NMCTL |= FIB$M_NEWVER;
  1163. break;
  1164. case REPL_OVERWRITE: /* Overwrite the existing file. */
  1165. pka_fib.FIB$W_NMCTL |= FIB$M_SUPERSEDE;
  1166. break;
  1167. }
  1168. /* Retry file creation with new (user-specified) policy. */
  1169. status = sys$qiow(0, /* event flag */
  1170. pka_devchn, /* channel */
  1171. IO$_CREATE|IO$M_CREATE|IO$M_ACCESS, /* funct */
  1172. &pka_acp_iosb, /* IOSB */
  1173. 0, /* AST address */
  1174. 0, /* AST parameter */
  1175. &pka_fibdsc, /* P1 = File Info Block */
  1176. &pka_fnam, /* P2 = File name (descr) */
  1177. &res_nam_len, /* P3 = Resulting name len */
  1178. &res_nam_dscr, /* P4 = Resulting name descr */
  1179. pka_atr, /* P5 = Attribute descr */
  1180. 0); /* P6 (not used) */
  1181. if ( !ERR(status) )
  1182. status = pka_acp_iosb.status;
  1183. if (res_nam_len > 0)
  1184. {
  1185. /* NUL-terminate the resulting file spec. */
  1186. G.filename[res_nam_len] = '\0';
  1187. }
  1188. /* Clear any user-specified version policy flags
  1189. * (for the next file to be processed).
  1190. */
  1191. pka_fib.FIB$W_NMCTL &= (~(FIB$M_NEWVER| FIB$M_SUPERSEDE));
  1192. }
  1193. if ( ERR(status) )
  1194. {
  1195. char buf[NAM_MAXRSS + 128]; /* Name length + message length. */
  1196. sprintf(buf, "[ Cannot create (QIO) output file %s ]\n",
  1197. G.filename);
  1198. vms_msg(__G__ buf, status);
  1199. sys$dassgn(pka_devchn);
  1200. return OPENOUT_FAILED;
  1201. }
  1202. #ifdef ASYNCH_QIO
  1203. init_buf_ring();
  1204. pka_io_pending = FALSE;
  1205. #else
  1206. locptr = locbuf;
  1207. loccnt = 0;
  1208. #endif
  1209. pka_vbn = 1;
  1210. _flush_routine = _flush_qio;
  1211. _close_routine = _close_qio;
  1212. } /* end if (!uO.cflag) */
  1213. return OPENOUT_OK;
  1214. }
  1215. /* 2008-07-23 SMS.
  1216. * Segregated user query function from file re-open functions/code.
  1217. *
  1218. * There was no code in create_qio_output() to deal with an
  1219. * SS$_DUPFILENAME condition, leading to ugly run-time failures, and its
  1220. * requirements differ from those of the RMS (non-QIO) functions,
  1221. * create_default_output() and create_rms_output().
  1222. *
  1223. * Whether it makes sense to have a second layer of VMS-specific
  1224. * querying after the generic UnZip query in extract.c:
  1225. * extract_or_test_entrylist() is another question, but changing that
  1226. * looks more scary than just getting the VMS-specific stuff to work
  1227. * right (better?).
  1228. */
  1229. /* "File exists" handler(s). Ask user about further action. */
  1230. /* RMS create new version. */
  1231. static int replace_rms_newversion(__GPRO)
  1232. {
  1233. int ierr;
  1234. struct NAM_STRUCT nam;
  1235. nam = CC_RMS_NAM; /* Initialize local NAM[L] block. */
  1236. outfab->FAB_NAM = &nam; /* Point FAB to local NAM[L]. */
  1237. /* Arrange to store the resultant file spec (with new version), so
  1238. * that we can extract the actual file version from it, for later
  1239. * use in the "extracting:/inflating:/..." message (G.filename).
  1240. */
  1241. nam.NAM_RSA = res_nam;
  1242. nam.NAM_RSS = sizeof(res_nam);
  1243. #ifdef NAML$C_MAXRSS
  1244. outfab->fab$l_dna = (char *) -1; /* Using NAML for default name. */
  1245. outfab->fab$l_fna = (char *) -1; /* Using NAML for file name. */
  1246. #endif /* NAML$C_MAXRSS */
  1247. FAB_OR_NAML(*outfab, nam).FAB_OR_NAML_FNA = G.filename;
  1248. FAB_OR_NAML(*outfab, nam).FAB_OR_NAML_FNS = strlen(G.filename);
  1249. /* Maximize version number. */
  1250. outfab->fab$l_fop |= FAB$M_MXV;
  1251. /* Create the new-version file. */
  1252. ierr = sys$create(outfab);
  1253. if (nam.NAM_RSL > 0)
  1254. {
  1255. /* File spec version pointers.
  1256. * Versions must exist, so a simple right-to-left search for ";"
  1257. * should work, even on ODS5 extended file specs.
  1258. */
  1259. char *semi_col_orig;
  1260. char *semi_col_res;
  1261. /* NUL-terminate the (complete) resultant file spec. */
  1262. res_nam[nam.NAM_RSL] = '\0';
  1263. /* Find the versions (";") in the original and resultant file specs. */
  1264. semi_col_orig = strrchr(G.filename, ';');
  1265. semi_col_res = strrchr(res_nam, ';');
  1266. if ((semi_col_orig != NULL) && (semi_col_res != NULL))
  1267. {
  1268. /* Transfer the resultant version to the original file spec. */
  1269. strcpy((semi_col_orig + 1), (semi_col_res + 1));
  1270. }
  1271. }
  1272. return ierr;
  1273. }
  1274. /* RMS overwrite original version. */
  1275. static int replace_rms_overwrite(__GPRO)
  1276. {
  1277. /* Supersede existing file. */
  1278. outfab->fab$l_fop |= FAB$M_SUP;
  1279. /* Create (overwrite) the original-version file. */
  1280. return sys$create(outfab);
  1281. }
  1282. /* Main query function to ask user how to handle an existing file
  1283. * (unless command-line options already specify what to do).
  1284. */
  1285. static int replace(__GPRO)
  1286. {
  1287. char answ[10];
  1288. int replace_code;
  1289. if (replace_code_all >= 0)
  1290. {
  1291. /* Use the previous all-file response. */
  1292. replace_code = replace_code_all;
  1293. }
  1294. else if (uO.overwrite_none)
  1295. {
  1296. /* "-n". Do not extract this (or any) file. */
  1297. replace_code = replace_code_all = REPL_NO_EXTRACT;
  1298. }
  1299. else if (uO.overwrite_all == 1)
  1300. {
  1301. /* "-o". Create a new version of this (or any) file. */
  1302. replace_code = replace_code_all = REPL_NEW_VERSION;
  1303. }
  1304. else if (uO.overwrite_all > 1)
  1305. {
  1306. /* "-oo". Overwrite (supersede) this (or any) existing file. */
  1307. replace_code = replace_code_all = REPL_OVERWRITE;
  1308. }
  1309. else
  1310. {
  1311. replace_code = -1;
  1312. do
  1313. {
  1314. /* Request, accept, and decode a response. */
  1315. Info(slide, 0x81, ((char *)slide,
  1316. "%s exists: new [v]ersion, [o]verwrite, or [n]o extract?\n\
  1317. (Uppercase response [V,O,N] => Do same for all files): ",
  1318. FnFilter1(G.filename)));
  1319. fflush(stderr);
  1320. if (fgets(answ, sizeof(answ), stdin) == (char *)NULL)
  1321. {
  1322. Info(slide, 1, ((char *)slide, AssumeNo));
  1323. /* Handle the NULL answer as "N",
  1324. * do not extract any existing files. */
  1325. replace_code_all = REPL_NO_EXTRACT;
  1326. /* Set a warning indicator. */
  1327. replace_code = REPL_NO_EXTRACT | REPL_ERRLV_WARN;
  1328. /* We are finished, break out of the query loop. */
  1329. break;
  1330. }
  1331. /* Strip off a trailing newline, to avoid corrupt
  1332. * complaints when displaying the answer.
  1333. */
  1334. if (answ[strlen(answ) - 1] == '\n')
  1335. answ[strlen(answ) - 1] = '\0';
  1336. /* Extra newline to avoid having the extracting:/inflating:/...:
  1337. * message overwritten by the next query.
  1338. */
  1339. Info(slide, 1, ((char *)slide, "\n"));
  1340. /* Interpret response. Store upper-case answer for future use. */
  1341. switch (answ[0])
  1342. {
  1343. case 'N':
  1344. replace_code_all = REPL_NO_EXTRACT;
  1345. case 'n':
  1346. /* Do not extract this file. */
  1347. replace_code = REPL_NO_EXTRACT;
  1348. break;
  1349. case 'O':
  1350. replace_code_all = REPL_OVERWRITE;
  1351. case 'o':
  1352. /* Overwrite (supersede) this existing file. */
  1353. replace_code = REPL_OVERWRITE;
  1354. break;
  1355. case 'V':
  1356. replace_code_all = REPL_NEW_VERSION;
  1357. case 'v':
  1358. /* Create a new version of this file. */
  1359. replace_code = REPL_NEW_VERSION;
  1360. break;
  1361. default:
  1362. /* Invalid response. Try again. */
  1363. Info(slide, 1, ((char *)slide, InvalidResponse, answ));
  1364. }
  1365. } while (replace_code < 0);
  1366. }
  1367. return replace_code;
  1368. }
  1369. #define W(p) (*(unsigned short*)(p))
  1370. #define L(p) (*(unsigned long*)(p))
  1371. #define EQL_L(a, b) ( L(a) == L(b) )
  1372. #define EQL_W(a, b) ( W(a) == W(b) )
  1373. /*
  1374. * Function find_vms_attrs() scans the ZIP entry extra field, if any,
  1375. * and looks for VMS attribute records. Various date-time attributes
  1376. * are ignored if set_date_time is FALSE (typically for a directory).
  1377. *
  1378. * For a set of IZ records, a FAB and various XABs are created and
  1379. * chained together.
  1380. *
  1381. * For a PK record, the pka_atr[] attribute descriptor array is
  1382. * populated.
  1383. *
  1384. * The return value is a VAT_* value, according to the type of extra
  1385. * field attribute data found.
  1386. */
  1387. static int find_vms_attrs(__GPRO__ int set_date_time)
  1388. {
  1389. uch *scan = G.extra_field;
  1390. struct EB_header *hdr;
  1391. int len;
  1392. int type=VAT_NONE;
  1393. outfab = NULL;
  1394. xabfhc = NULL;
  1395. xabdat = NULL;
  1396. xabrdt = NULL;
  1397. xabpro = NULL;
  1398. first_xab = last_xab = NULL;
  1399. if (scan == NULL)
  1400. return VAT_NONE;
  1401. len = G.lrec.extra_field_length;
  1402. #define LINK(p) {/* Link xaballs and xabkeys into chain */ \
  1403. if ( first_xab == NULL ) \
  1404. first_xab = (void *) p; \
  1405. if ( last_xab != NULL ) \
  1406. last_xab->xab$l_nxt = (void *) p; \
  1407. last_xab = (void *) p; \
  1408. p->xab$l_nxt = NULL; \
  1409. }
  1410. /* End of macro LINK */
  1411. while (len > 0)
  1412. {
  1413. hdr = (struct EB_header *)scan;
  1414. if (EQL_W(&hdr->tag, IZ_SIGNATURE))
  1415. {
  1416. /*
  1417. * Info-ZIP-style extra block decoding.
  1418. */
  1419. uch *blk;
  1420. unsigned siz;
  1421. uch *block_id;
  1422. type = VAT_IZ;
  1423. siz = hdr->size;
  1424. blk = (uch *)(&hdr->data[0]);
  1425. block_id = (uch *)(&((struct IZ_block *)hdr)->bid);
  1426. if (EQL_L(block_id, FABSIG)) {
  1427. outfab = (struct FAB *)extract_izvms_block(__G__ blk,
  1428. siz, NULL, (uch *)&cc$rms_fab, FABL);
  1429. } else if (EQL_L(block_id, XALLSIG)) {
  1430. xaball = (struct XABALL *)extract_izvms_block(__G__ blk,
  1431. siz, NULL, (uch *)&cc$rms_xaball, XALLL);
  1432. LINK(xaball);
  1433. } else if (EQL_L(block_id, XKEYSIG)) {
  1434. xabkey = (struct XABKEY *)extract_izvms_block(__G__ blk,
  1435. siz, NULL, (uch *)&cc$rms_xabkey, XKEYL);
  1436. LINK(xabkey);
  1437. } else if (EQL_L(block_id, XFHCSIG)) {
  1438. xabfhc = (struct XABFHC *) extract_izvms_block(__G__ blk,
  1439. siz, NULL, (uch *)&cc$rms_xabfhc, XFHCL);
  1440. } else if (EQL_L(block_id, XDATSIG)) {
  1441. if (set_date_time) {
  1442. xabdat = (struct XABDAT *) extract_izvms_block(__G__ blk,
  1443. siz, NULL, (uch *)&cc$rms_xabdat, XDATL);
  1444. }
  1445. } else if (EQL_L(block_id, XRDTSIG)) {
  1446. if (set_date_time) {
  1447. xabrdt = (struct XABRDT *) extract_izvms_block(__G__ blk,
  1448. siz, NULL, (uch *)&cc$rms_xabrdt, XRDTL);
  1449. }
  1450. } else if (EQL_L(block_id, XPROSIG)) {
  1451. xabpro = (struct XABPRO *) extract_izvms_block(__G__ blk,
  1452. siz, NULL, (uch *)&cc$rms_xabpro, XPROL);
  1453. } else if (EQL_L(block_id, VERSIG)) {
  1454. #ifdef CHECK_VERSIONS
  1455. char verbuf[80];
  1456. unsigned verlen = 0;
  1457. uch *vers;
  1458. char *m;
  1459. get_vms_version(verbuf, sizeof(verbuf));
  1460. vers = extract_izvms_block(__G__ blk, siz,
  1461. &verlen, NULL, 0);
  1462. if ((m = strrchr((char *) vers, '-')) != NULL)
  1463. *m = '\0'; /* Cut out release number */
  1464. if (strcmp(verbuf, (char *) vers) && uO.qflag < 2)
  1465. {
  1466. Info(slide, 0, ((char *)slide,
  1467. "[ Warning: VMS version mismatch."));
  1468. Info(slide, 0, ((char *)slide,
  1469. " This version %s --", verbuf));
  1470. strncpy(verbuf, (char *) vers, verlen);
  1471. verbuf[verlen] = '\0';
  1472. Info(slide, 0, ((char *)slide,
  1473. " version made by %s ]\n", verbuf));
  1474. }
  1475. free(vers);
  1476. #endif /* CHECK_VERSIONS */
  1477. } else {
  1478. Info(slide, 1, ((char *)slide,
  1479. "[ Warning: Unknown block signature %s ]\n",
  1480. block_id));
  1481. }
  1482. }
  1483. else if (hdr->tag == PK_SIGNATURE)
  1484. {
  1485. /*
  1486. * PKWARE-style extra block decoding.
  1487. */
  1488. struct PK_header *blk;
  1489. register byte *scn;
  1490. register int len;
  1491. type = VAT_PK;
  1492. blk = (struct PK_header *)hdr;
  1493. len = blk->size - (PK_HEADER_SIZE - EB_HEADSIZE);
  1494. scn = (byte *)(&blk->data);
  1495. pka_idx = 0;
  1496. if (blk->crc32 != crc32(CRCVAL_INITIAL, scn, (extent)len))
  1497. {
  1498. Info(slide, 1, ((char *)slide,
  1499. "[ Warning: CRC error, discarding PKWARE extra field ]\n"));
  1500. len = 0;
  1501. type = VAT_NONE;
  1502. }
  1503. while (len > PK_FLDHDR_SIZE)
  1504. {
  1505. register struct PK_field *fld;
  1506. int skip=0;
  1507. fld = (struct PK_field *)scn;
  1508. switch(fld->tag)
  1509. {
  1510. case ATR$C_UCHAR:
  1511. pka_uchar = L(&fld->value);
  1512. break;
  1513. case ATR$C_RECATTR:
  1514. pka_rattr = *(struct fatdef *)(&fld->value);
  1515. break;
  1516. case ATR$C_UIC:
  1517. case ATR$C_ADDACLENT:
  1518. skip = !uO.X_flag;
  1519. break;
  1520. case ATR$C_CREDATE:
  1521. case ATR$C_REVDATE:
  1522. case ATR$C_EXPDATE:
  1523. case ATR$C_BAKDATE:
  1524. case ATR$C_ASCDATES:
  1525. skip = (set_date_time == FALSE);
  1526. break;
  1527. }
  1528. if ( !skip )
  1529. {
  1530. pka_atr[pka_idx].atr$w_size = fld->size;
  1531. pka_atr[pka_idx].atr$w_type = fld->tag;
  1532. pka_atr[pka_idx].atr$l_addr = GVTC &fld->value;
  1533. ++pka_idx;
  1534. }
  1535. len -= fld->size + PK_FLDHDR_SIZE;
  1536. scn += fld->size + PK_FLDHDR_SIZE;
  1537. }
  1538. pka_atr[pka_idx].atr$w_size = 0; /* End of list */
  1539. pka_atr[pka_idx].atr$w_type = 0;
  1540. pka_atr[pka_idx].atr$l_addr = 0; /* NULL when DECC VAX gets fixed */
  1541. }
  1542. len -= hdr->size + EB_HEADSIZE;
  1543. scan += hdr->size + EB_HEADSIZE;
  1544. }
  1545. if ( type == VAT_IZ )
  1546. {
  1547. if (outfab != NULL)
  1548. {
  1549. /* Do not link XABPRO or XABRDT now.
  1550. * Leave them for sys$close() resp. set_direc_attribs().
  1551. */
  1552. outfab->fab$l_xab = NULL;
  1553. if (xabfhc != NULL)
  1554. {
  1555. xabfhc->xab$l_nxt = outfab->fab$l_xab;
  1556. outfab->fab$l_xab = (void *) xabfhc;
  1557. }
  1558. if (xabdat != NULL)
  1559. {
  1560. xabdat->xab$l_nxt = outfab->fab$l_xab;
  1561. outfab->fab$l_xab = (void *) xabdat;
  1562. }
  1563. if (first_xab != NULL) /* Link xaball,xabkey subchain */
  1564. {
  1565. last_xab->xab$l_nxt = outfab->fab$l_xab;
  1566. outfab->fab$l_xab = (void *) first_xab;
  1567. }
  1568. }
  1569. else
  1570. type = VAT_NONE;
  1571. }
  1572. return type;
  1573. }
  1574. static void free_up()
  1575. {
  1576. /*
  1577. * Free up all allocated XABs.
  1578. */
  1579. if (xabdat != NULL) free(xabdat);
  1580. if (xabpro != NULL) free(xabpro);
  1581. if (xabrdt != NULL) free(xabrdt);
  1582. if (xabfhc != NULL) free(xabfhc);
  1583. while (first_xab != NULL)
  1584. {
  1585. struct XAB *x;
  1586. x = (struct XAB *) first_xab->xab$l_nxt;
  1587. free(first_xab);
  1588. first_xab = x;
  1589. }
  1590. /* Free FAB storage, if not the static one. */
  1591. if (outfab != NULL && outfab != &fileblk)
  1592. free(outfab);
  1593. }
  1594. #ifdef CHECK_VERSIONS
  1595. static int get_vms_version(verbuf, len)
  1596. char *verbuf;
  1597. int len;
  1598. {
  1599. int i = SYI$_VERSION;
  1600. int verlen = 0;
  1601. struct dsc$descriptor version;
  1602. char *m;
  1603. version.dsc$a_pointer = verbuf;
  1604. version.dsc$w_length = len - 1;
  1605. version.dsc$b_dtype = DSC$K_DTYPE_B;
  1606. version.dsc$b_class = DSC$K_CLASS_S;
  1607. if (ERR(lib$getsyi(&i, 0, &version, &verlen, 0, 0)) || verlen == 0)
  1608. return 0;
  1609. /* Cut out trailing spaces "V5.4-3 " -> "V5.4-3" */
  1610. for (m = verbuf + verlen, i = verlen - 1; i > 0 && verbuf[i] == ' '; --i)
  1611. --m;
  1612. *m = '\0';
  1613. /* Cut out release number "V5.4-3" -> "V5.4" */
  1614. if ((m = strrchr(verbuf, '-')) != NULL)
  1615. *m = '\0';
  1616. return strlen(verbuf) + 1; /* Transmit ending '\0' too */
  1617. }
  1618. #endif /* CHECK_VERSIONS */
  1619. /* flush contents of output buffer */
  1620. int flush(__G__ rawbuf, size, unshrink) /* return PK-type error code */
  1621. __GDEF
  1622. uch *rawbuf;
  1623. ulg size;
  1624. int unshrink;
  1625. {
  1626. G.crc32val = crc32(G.crc32val, rawbuf, (extent)size);
  1627. if (uO.tflag)
  1628. return PK_COOL; /* Do not output. Update CRC only */
  1629. else
  1630. return (*_flush_routine)(__G__ rawbuf, size, 0);
  1631. }
  1632. static int _flush_blocks(__G__ rawbuf, size, final_flag)
  1633. /* Asynchronous version */
  1634. __GDEF
  1635. uch *rawbuf;
  1636. unsigned size;
  1637. int final_flag; /* 1 if this is the final flushout */
  1638. {
  1639. int status;
  1640. unsigned off = 0;
  1641. while (size > 0)
  1642. {
  1643. if (curbuf->bufcnt < BUFS512)
  1644. {
  1645. unsigned ncpy;
  1646. ncpy = size > (BUFS512 - curbuf->bufcnt) ?
  1647. (BUFS512 - curbuf->bufcnt) : size;
  1648. memcpy(curbuf->buf + curbuf->bufcnt, rawbuf + off, ncpy);
  1649. size -= ncpy;
  1650. curbuf->bufcnt += ncpy;
  1651. off += ncpy;
  1652. }
  1653. if (curbuf->bufcnt == BUFS512)
  1654. {
  1655. status = WriteBuffer(__G__ curbuf->buf, curbuf->bufcnt);
  1656. if (status)
  1657. return status;
  1658. curbuf = curbuf->next;
  1659. curbuf->bufcnt = 0;
  1660. }
  1661. }
  1662. return (final_flag && (curbuf->bufcnt > 0)) ?
  1663. WriteBuffer(__G__ curbuf->buf, curbuf->bufcnt) :
  1664. PK_COOL;
  1665. }
  1666. #ifdef ASYNCH_QIO
  1667. static int WriteQIO(__G__ buf, len)
  1668. __GDEF
  1669. uch *buf;
  1670. unsigned len;
  1671. {
  1672. int status;
  1673. if (pka_io_pending) {
  1674. status = sys$synch(0, &pka_io_iosb);
  1675. if (!ERR(status))
  1676. status = pka_io_iosb.status;
  1677. if (ERR(status))
  1678. {
  1679. vms_msg(__G__ "[ WriteQIO: sys$synch found I/O failure ]\n",
  1680. status);
  1681. return PK_DISK;
  1682. }
  1683. pka_io_pending = FALSE;
  1684. }
  1685. /*
  1686. * Put content of buffer as a single VB
  1687. */
  1688. status = sys$qio(0, pka_devchn, IO$_WRITEVBLK,
  1689. &pka_io_iosb, 0, 0,
  1690. buf, len, pka_vbn,
  1691. 0, 0, 0);
  1692. if (ERR(status))
  1693. {
  1694. vms_msg(__G__ "[ WriteQIO: sys$qio failed ]\n", status);
  1695. return PK_DISK;
  1696. }
  1697. pka_io_pending = TRUE;
  1698. pka_vbn += (len>>9);
  1699. return PK_COOL;
  1700. }
  1701. /*
  1702. 2004-10-01 SMS. Changed to clear the extra byte written out by qio()
  1703. and sys$write() when an odd byte count is incremented to the next
  1704. even value, either explicitly (qio), or implicitly (sys$write), on
  1705. the theory that a reliable NUL beats left-over garbage. Alpha and
  1706. VAX object files seem frequently to have even more than one byte of
  1707. extra junk past EOF, so this may not help them.
  1708. */
  1709. static int _flush_qio(__G__ rawbuf, size, final_flag)
  1710. /* Asynchronous version */
  1711. __GDEF
  1712. uch *rawbuf;
  1713. unsigned size;
  1714. int final_flag; /* 1 if this is the final flushout */
  1715. {
  1716. int status;
  1717. unsigned off = 0;
  1718. while (size > 0)
  1719. {
  1720. if (curbuf->bufcnt < BUFS512)
  1721. {
  1722. unsigned ncpy;
  1723. ncpy = size > (BUFS512 - curbuf->bufcnt) ?
  1724. (BUFS512 - curbuf->bufcnt) : size;
  1725. memcpy(curbuf->buf + curbuf->bufcnt, rawbuf + off, ncpy);
  1726. size -= ncpy;
  1727. curbuf->bufcnt += ncpy;
  1728. off += ncpy;
  1729. }
  1730. if (curbuf->bufcnt == BUFS512)
  1731. {
  1732. status = WriteQIO(__G__ curbuf->buf, curbuf->bufcnt);
  1733. if (status)
  1734. return status;
  1735. curbuf = curbuf->next;
  1736. curbuf->bufcnt = 0;
  1737. }
  1738. }
  1739. if (final_flag && (curbuf->bufcnt > 0))
  1740. {
  1741. unsigned bufcnt_even;
  1742. /* Round up to an even byte count. */
  1743. bufcnt_even = (curbuf->bufcnt+1) & (~1);
  1744. /* If there is one, clear the extra byte. */
  1745. if (bufcnt_even > curbuf->bufcnt)
  1746. curbuf->buf[curbuf->bufcnt] = '\0';
  1747. return WriteQIO(curbuf->buf, bufcnt_even);
  1748. }
  1749. else
  1750. {
  1751. return PK_COOL;
  1752. }
  1753. }
  1754. #else /* !ASYNCH_QIO */
  1755. static int _flush_qio(__G__ rawbuf, size, final_flag)
  1756. __GDEF
  1757. uch *rawbuf;
  1758. unsigned size;
  1759. int final_flag; /* 1 if this is the final flushout */
  1760. {
  1761. int status;
  1762. uch *out_ptr=rawbuf;
  1763. if ( final_flag )
  1764. {
  1765. if ( loccnt > 0 )
  1766. {
  1767. unsigned loccnt_even;
  1768. /* Round up to an even byte count. */
  1769. loccnt_even = (loccnt+1) & (~1);
  1770. /* If there is one, clear the extra byte. */
  1771. if (loccnt_even > loccnt)
  1772. locbuf[loccnt] = '\0';
  1773. status = sys$qiow(0, pka_devchn, IO$_WRITEVBLK,
  1774. &pka_io_iosb, 0, 0,
  1775. locbuf,
  1776. loccnt_even,
  1777. pka_vbn,
  1778. 0, 0, 0);
  1779. if (!ERR(status))
  1780. status = pka_io_iosb.status;
  1781. if (ERR(status))
  1782. {
  1783. vms_msg(__G__ "[ Write QIO failed ]\n", status);
  1784. return PK_DISK;
  1785. }
  1786. }
  1787. return PK_COOL;
  1788. }
  1789. if ( loccnt > 0 )
  1790. {
  1791. /*
  1792. * Fill local buffer upto 512 bytes then put it out
  1793. */
  1794. unsigned ncpy;
  1795. ncpy = 512-loccnt;
  1796. if ( ncpy > size )
  1797. ncpy = size;
  1798. memcpy(locptr, out_ptr, ncpy);
  1799. locptr += ncpy;
  1800. loccnt += ncpy;
  1801. size -= ncpy;
  1802. out_ptr += ncpy;
  1803. if ( loccnt == 512 )
  1804. {
  1805. status = sys$qiow(0, pka_devchn, IO$_WRITEVBLK,
  1806. &pka_io_iosb, 0, 0,
  1807. locbuf, loccnt, pka_vbn,
  1808. 0, 0, 0);
  1809. if (!ERR(status))
  1810. status = pka_io_iosb.status;
  1811. if (ERR(status))
  1812. {
  1813. vms_msg(__G__ "[ Write QIO failed ]\n", status);
  1814. return PK_DISK;
  1815. }
  1816. pka_vbn++;
  1817. loccnt = 0;
  1818. locptr = locbuf;
  1819. }
  1820. }
  1821. if ( size >= 512 )
  1822. {
  1823. unsigned nblk, put_cnt;
  1824. /*
  1825. * Put rest of buffer as a single VB
  1826. */
  1827. put_cnt = (nblk = size>>9)<<9;
  1828. status = sys$qiow(0, pka_devchn, IO$_WRITEVBLK,
  1829. &pka_io_iosb, 0, 0,
  1830. out_ptr, put_cnt, pka_vbn,
  1831. 0, 0, 0);
  1832. if (!ERR(status))
  1833. status = pka_io_iosb.status;
  1834. if (ERR(status))
  1835. {
  1836. vms_msg(__G__ "[ Write QIO failed ]\n", status);
  1837. return PK_DISK;
  1838. }
  1839. pka_vbn += nblk;
  1840. out_ptr += put_cnt;
  1841. size -= put_cnt;
  1842. }
  1843. if ( size > 0 )
  1844. {
  1845. memcpy(locptr, out_ptr, size);
  1846. loccnt += size;
  1847. locptr += size;
  1848. }
  1849. return PK_COOL;
  1850. }
  1851. #endif /* ?ASYNCH_QIO */
  1852. /*
  1853. * The routine _flush_varlen() requires: "(size & 1) == 0"
  1854. * (The variable-length record algorithm assumes an even byte-count!)
  1855. */
  1856. static int _flush_varlen(__G__ rawbuf, size, final_flag)
  1857. __GDEF
  1858. uch *rawbuf;
  1859. unsigned size;
  1860. int final_flag;
  1861. {
  1862. unsigned nneed;
  1863. unsigned reclen;
  1864. uch *inptr=rawbuf;
  1865. /*
  1866. * Flush local buffer
  1867. */
  1868. if ( loccnt > 0 ) /* incomplete record left from previous call */
  1869. {
  1870. reclen = *(ush*)locbuf;
  1871. nneed = reclen + 2 - loccnt;
  1872. if ( nneed > size )
  1873. {
  1874. if ( size+loccnt > BUFSMAXREC )
  1875. {
  1876. char buf[80];
  1877. Info(buf, 1, (buf,
  1878. "[ Record too long (%u bytes) ]\n", reclen));
  1879. return PK_DISK;
  1880. }
  1881. memcpy(locbuf+loccnt, inptr, size);
  1882. loccnt += size;
  1883. size = 0;
  1884. }
  1885. else
  1886. {
  1887. memcpy(locbuf+loccnt, inptr, nneed);
  1888. loccnt += nneed;
  1889. size -= nneed;
  1890. inptr += nneed;
  1891. if ( reclen & 1 )
  1892. {
  1893. size--;
  1894. inptr++;
  1895. }
  1896. if ( WriteRecord(__G__ locbuf+2, reclen) )
  1897. return PK_DISK;
  1898. loccnt = 0;
  1899. }
  1900. }
  1901. /*
  1902. * Flush incoming records
  1903. */
  1904. while (size > 0)
  1905. {
  1906. reclen = *(ush*)inptr;
  1907. if ( reclen+2 <= size )
  1908. {
  1909. if (WriteRecord(__G__ inptr+2, reclen))
  1910. return PK_DISK;
  1911. size -= 2+reclen;
  1912. inptr += 2+reclen;
  1913. if ( reclen & 1 )
  1914. {
  1915. --size;
  1916. ++inptr;
  1917. }
  1918. }
  1919. else
  1920. {
  1921. memcpy(locbuf, inptr, size);
  1922. loccnt = size;
  1923. size = 0;
  1924. }
  1925. }
  1926. /*
  1927. * Final flush rest of local buffer
  1928. */
  1929. if ( final_flag && loccnt > 0 )
  1930. {
  1931. char buf[80];
  1932. Info(buf, 1, (buf,
  1933. "[ Warning, incomplete record of length %u ]\n",
  1934. (unsigned)*(ush*)locbuf));
  1935. if ( WriteRecord(__G__ locbuf+2, loccnt-2) )
  1936. return PK_DISK;
  1937. }
  1938. return PK_COOL;
  1939. }
  1940. /*
  1941. * Routine _flush_stream breaks decompressed stream into records
  1942. * depending on format of the stream (fab->rfm, G.pInfo->textmode, etc.)
  1943. * and puts out these records. It also handles CR LF sequences.
  1944. * Should be used when extracting *text* files.
  1945. */
  1946. #define VT 0x0B
  1947. #define FF 0x0C
  1948. /* The file is from MSDOS/OS2/NT -> handle CRLF as record end, throw out ^Z */
  1949. /* GRR NOTES: cannot depend on hostnum! May have "flip'd" file or re-zipped
  1950. * a Unix file, etc. */
  1951. #ifdef USE_ORIG_DOS
  1952. # define ORG_DOS \
  1953. (G.pInfo->hostnum==FS_FAT_ \
  1954. || G.pInfo->hostnum==FS_HPFS_ \
  1955. || G.pInfo->hostnum==FS_NTFS_)
  1956. #else
  1957. # define ORG_DOS 1
  1958. #endif
  1959. /* Record delimiters */
  1960. #ifdef undef
  1961. #define RECORD_END(c, f) \
  1962. ( ( ORG_DOS || G.pInfo->textmode ) && c==CTRLZ \
  1963. || ( f == FAB$C_STMLF && c==LF ) \
  1964. || ( f == FAB$C_STMCR || ORG_DOS || G.pInfo->textmode ) && c==CR \
  1965. || ( f == FAB$C_STM && (c==CR || c==LF || c==FF || c==VT) ) \
  1966. )
  1967. #else
  1968. # define RECORD_END(c, f) ((c) == LF || (c) == (CR))
  1969. #endif
  1970. static unsigned find_eol(p, n, l)
  1971. /*
  1972. * Find first CR, LF, CR/LF or LF/CR in string 'p' of length 'n'.
  1973. * Return offset of the sequence found or 'n' if not found.
  1974. * If found, return in '*l' length of the sequence (1 or 2) or
  1975. * zero if sequence end not seen, i.e. CR or LF is last char
  1976. * in the buffer.
  1977. */
  1978. ZCONST uch *p;
  1979. unsigned n;
  1980. unsigned *l;
  1981. {
  1982. unsigned off = n;
  1983. ZCONST uch *q;
  1984. *l = 0;
  1985. for (q=p ; n > 0 ; --n, ++q)
  1986. if ( RECORD_END(*q, rfm) )
  1987. {
  1988. off = q-p;
  1989. break;
  1990. }
  1991. if ( n > 1 )
  1992. {
  1993. *l = 1;
  1994. if ( ( q[0] == CR && q[1] == LF ) || ( q[0] == LF && q[1] == CR ) )
  1995. *l = 2;
  1996. }
  1997. return off;
  1998. }
  1999. /* Record delimiters that must be put out */
  2000. #define PRINT_SPEC(c) ( (c)==FF || (c)==VT )
  2001. static int _flush_stream(__G__ rawbuf, size, final_flag)
  2002. __GDEF
  2003. uch *rawbuf;
  2004. unsigned size;
  2005. int final_flag; /* 1 if this is the final flushout */
  2006. {
  2007. int rest;
  2008. unsigned end = 0, start = 0;
  2009. if (size == 0 && loccnt == 0)
  2010. return PK_COOL; /* Nothing to do ... */
  2011. if ( final_flag )
  2012. {
  2013. unsigned recsize;
  2014. /*
  2015. * This is flush only call. size must be zero now.
  2016. * Just eject everything we have in locbuf.
  2017. */
  2018. recsize = loccnt - (got_eol ? 1 : 0);
  2019. /*
  2020. * If the last char of file was ^Z ( end-of-file in MSDOS ),
  2021. * we will see it now.
  2022. */
  2023. if ( recsize==1 && locbuf[0] == CTRLZ )
  2024. return PK_COOL;
  2025. return WriteRecord(__G__ locbuf, recsize);
  2026. }
  2027. if ( loccnt > 0 )
  2028. {
  2029. /* Find end of record partially saved in locbuf */
  2030. unsigned recsize;
  2031. int complete=0;
  2032. if ( got_eol )
  2033. {
  2034. recsize = loccnt - 1;
  2035. complete = 1;
  2036. if ( (got_eol == CR && rawbuf[0] == LF) ||
  2037. (got_eol == LF && rawbuf[0] == CR) )
  2038. end = 1;
  2039. got_eol = 0;
  2040. }
  2041. else
  2042. {
  2043. unsigned eol_len;
  2044. unsigned eol_off;
  2045. eol_off = find_eol(rawbuf, size, &eol_len);
  2046. if ( loccnt+eol_off > BUFSMAXREC )
  2047. {
  2048. /*
  2049. * No room in locbuf. Dump it and clear
  2050. */
  2051. char buf[80]; /* CANNOT use slide for Info() */
  2052. recsize = loccnt;
  2053. start = 0;
  2054. Info(buf, 1, (buf,
  2055. "[ Warning: Record too long (%u) ]\n", loccnt+eol_off));
  2056. complete = 1;
  2057. end = 0;
  2058. }
  2059. else
  2060. {
  2061. if ( eol_off >= size )
  2062. {
  2063. end = size;
  2064. complete = 0;
  2065. }
  2066. else if ( eol_len == 0 )
  2067. {
  2068. got_eol = rawbuf[eol_off];
  2069. end = size;
  2070. complete = 0;
  2071. }
  2072. else
  2073. {
  2074. memcpy(locptr, rawbuf, eol_off);
  2075. recsize = loccnt + eol_off;
  2076. locptr += eol_off;
  2077. loccnt += eol_off;
  2078. end = eol_off + eol_len;
  2079. complete = 1;
  2080. }
  2081. }
  2082. }
  2083. if ( complete )
  2084. {
  2085. if (WriteRecord(__G__ locbuf, recsize))
  2086. return PK_DISK;
  2087. loccnt = 0;
  2088. locptr = locbuf;
  2089. }
  2090. } /* end if ( loccnt ) */
  2091. for (start = end; start < size && end < size; )
  2092. {
  2093. unsigned eol_off, eol_len;
  2094. got_eol = 0;
  2095. #ifdef undef
  2096. if (uO.cflag)
  2097. /* skip CR's at the beginning of record */
  2098. while (start < size && rawbuf[start] == CR)
  2099. ++start;
  2100. #endif
  2101. if ( start >= size )
  2102. continue;
  2103. /* Find record end */
  2104. end = start+(eol_off = find_eol(rawbuf+start, size-start, &eol_len));
  2105. if ( end >= size )
  2106. continue;
  2107. if ( eol_len > 0 )
  2108. {
  2109. if ( WriteRecord(__G__ rawbuf+start, end-start) )
  2110. return PK_DISK;
  2111. start = end + eol_len;
  2112. }
  2113. else
  2114. {
  2115. got_eol = rawbuf[end];
  2116. end = size;
  2117. continue;
  2118. }
  2119. }
  2120. rest = size - start;
  2121. if (rest > 0)
  2122. {
  2123. if ( rest > BUFSMAXREC )
  2124. {
  2125. unsigned recsize;
  2126. char buf[80]; /* CANNOT use slide for Info() */
  2127. recsize = rest - (got_eol ? 1 : 0 );
  2128. Info(buf, 1, (buf,
  2129. "[ Warning: Record too long (%u) ]\n", recsize));
  2130. got_eol = 0;
  2131. return WriteRecord(__G__ rawbuf+start, recsize);
  2132. }
  2133. else
  2134. {
  2135. memcpy(locptr, rawbuf + start, rest);
  2136. locptr += rest;
  2137. loccnt += rest;
  2138. }
  2139. }
  2140. return PK_COOL;
  2141. }
  2142. static int WriteBuffer(__G__ buf, len)
  2143. __GDEF
  2144. uch *buf;
  2145. unsigned len;
  2146. {
  2147. int status;
  2148. if (uO.cflag)
  2149. {
  2150. (void)(*G.message)((zvoid *)&G, buf, len, 0);
  2151. }
  2152. else
  2153. {
  2154. status = sys$wait(outrab);
  2155. if (ERR(status))
  2156. {
  2157. vms_msg(__G__ "[ WriteBuffer: sys$wait failed ]\n", status);
  2158. if (outrab->rab$l_stv != 0)
  2159. {
  2160. vms_msg(__G__ "", outrab->rab$l_stv);
  2161. }
  2162. }
  2163. /* If odd byte count, then this must be the final record.
  2164. Clear the extra byte past EOF to help keep the file clean.
  2165. */
  2166. if (len & 1)
  2167. buf[len] = '\0';
  2168. outrab->rab$w_rsz = len;
  2169. outrab->rab$l_rbf = (char *) buf;
  2170. if (ERR(status = sys$write(outrab)))
  2171. {
  2172. vms_msg(__G__ "[ WriteBuffer: sys$write failed ]\n", status);
  2173. if (outrab->rab$l_stv != 0)
  2174. {
  2175. vms_msg(__G__ "", outrab->rab$l_stv);
  2176. }
  2177. return PK_DISK;
  2178. }
  2179. }
  2180. return PK_COOL;
  2181. }
  2182. static int WriteRecord(__G__ rec, len)
  2183. __GDEF
  2184. uch *rec;
  2185. unsigned len;
  2186. {
  2187. int status;
  2188. if (uO.cflag)
  2189. {
  2190. (void)(*G.message)((zvoid *)&G, rec, len, 0);
  2191. (void)(*G.message)((zvoid *)&G, (uch *) ("\n"), 1, 0);
  2192. }
  2193. else
  2194. {
  2195. if (ERR(status = sys$wait(outrab)))
  2196. {
  2197. vms_msg(__G__ "[ WriteRecord: sys$wait failed ]\n", status);
  2198. if (outrab->rab$l_stv != 0)
  2199. {
  2200. vms_msg(__G__ "", outrab->rab$l_stv);
  2201. }
  2202. }
  2203. outrab->rab$w_rsz = len;
  2204. outrab->rab$l_rbf = (char *) rec;
  2205. if (ERR(status = sys$put(outrab)))
  2206. {
  2207. vms_msg(__G__ "[ WriteRecord: sys$put failed ]\n", status);
  2208. if (outrab->rab$l_stv != 0)
  2209. {
  2210. vms_msg(__G__ "", outrab->rab$l_stv);
  2211. }
  2212. return PK_DISK;
  2213. }
  2214. }
  2215. return PK_COOL;
  2216. }
  2217. #ifdef SYMLINKS
  2218. /* Read symlink text from a still-open rms file. */
  2219. static int _read_link_rms(int byte_count, char *link_text_buf)
  2220. {
  2221. /* Use RMS to read the link text into the user's buffer.
  2222. * Rewind, then read byte count = byte_count.
  2223. * NUL-terminate the link text.
  2224. *
  2225. * $WAIT may be pointless if not async, but $WAIT elsewhere seems
  2226. * to be used unconditionally, so what do I know?
  2227. */
  2228. int sts;
  2229. int bytes_read;
  2230. /* Clear the bytes-read count. */
  2231. bytes_read = 0;
  2232. /* Wait for anything pending. */
  2233. sts = sys$wait(outrab);
  2234. {
  2235. /* Rewind. */
  2236. sts = sys$rewind(outrab);
  2237. if (!ERR(sts))
  2238. {
  2239. /* Wait for $REWIND. */
  2240. sts = sys$wait(outrab);
  2241. if (!ERR(sts))
  2242. {
  2243. /* Read the link text. */
  2244. outrab->rab$w_usz = byte_count;
  2245. outrab->rab$l_ubf = link_text_buf;
  2246. sts = sys$read(outrab);
  2247. if (!ERR(sts))
  2248. {
  2249. /* Wait for $READ. */
  2250. sts = sys$wait(outrab);
  2251. if (!ERR(sts))
  2252. /* Set the resultant byte count. */
  2253. bytes_read = outrab->rab$w_rsz;
  2254. }
  2255. }
  2256. }
  2257. }
  2258. /* NUL-terminate the link text. */
  2259. link_text_buf[bytes_read] = '\0';
  2260. return sts;
  2261. }
  2262. #endif /* SYMLINKS */
  2263. void close_outfile(__G)
  2264. __GDEF
  2265. {
  2266. int status;
  2267. status = (*_flush_routine)(__G__ NULL, 0, 1);
  2268. if (status)
  2269. return /* PK_DISK */;
  2270. if (uO.cflag)
  2271. return /* PK_COOL */; /* Don't close stdout */
  2272. /* return */ (*_close_routine)(__G);
  2273. }
  2274. static int _close_rms(__GPRO)
  2275. {
  2276. int status;
  2277. struct XABPRO pro;
  2278. int retcode = PK_OK;
  2279. #ifdef SYMLINKS
  2280. /*----------------------------------------------------------------------
  2281. UNIX description:
  2282. If symbolic links are supported, allocate storage for a symlink
  2283. control structure, put the uncompressed "data" and other required
  2284. info in it, and add the structure to the "deferred symlinks" chain.
  2285. Since we know it's a symbolic link to start with, we shouldn't have
  2286. to worry about overflowing unsigned ints with unsigned longs.
  2287. ----------------------------------------------------------------------*/
  2288. if (G.symlnk) {
  2289. extent ucsize = (extent)G.lrec.ucsize;
  2290. /* 2007-03-03 SMS.
  2291. * If the symlink is already a symlink (restored with VMS/RMS
  2292. * symlink attributes), then read the link text from the file,
  2293. * and close the file (using the appropriate methods), and then
  2294. * return.
  2295. */
  2296. if (G.pInfo->symlink == 0)
  2297. {
  2298. if (QCOND2)
  2299. {
  2300. /* Link text storage. */
  2301. char* link_target = malloc(ucsize + 1);
  2302. if (link_target == NULL)
  2303. {
  2304. Info(slide, 0x201, ((char *)slide,
  2305. "warning: cannot show symlink (%s) target, no mem\n",
  2306. FnFilter1(G.filename)));
  2307. retcode = PK_MEM;
  2308. }
  2309. else
  2310. {
  2311. /* Read the link text. */
  2312. status = _read_link_rms(ucsize, link_target);
  2313. if (ERR(status))
  2314. {
  2315. Info(slide, 0x201, ((char *)slide,
  2316. "warning: error reading symlink text: %s\n",
  2317. strerror(EVMSERR, status)));
  2318. retcode = PK_DISK;
  2319. }
  2320. else
  2321. {
  2322. Info(slide, 0, ((char *)slide, "-> %s ",
  2323. FnFilter1(link_target)));
  2324. }
  2325. free(link_target);
  2326. }
  2327. }
  2328. }
  2329. else
  2330. {
  2331. extent slnk_entrysize;
  2332. slinkentry *slnk_entry;
  2333. /* It's a symlink in need of post-processing. */
  2334. /* Size of the symlink entry is the sum of
  2335. * (struct size (includes 1st '\0') + 1 additional trailing '\0'),
  2336. * system specific attribute data size (might be 0),
  2337. * and the lengths of name and link target.
  2338. */
  2339. slnk_entrysize = (sizeof(slinkentry) + 1) +
  2340. ucsize + strlen(G.filename);
  2341. if (slnk_entrysize < ucsize) {
  2342. Info(slide, 0x201, ((char *)slide,
  2343. "warning: symbolic link (%s) failed: mem alloc overflow\n",
  2344. FnFilter1(G.filename)));
  2345. retcode = PK_ERR;
  2346. }
  2347. else
  2348. {
  2349. if ((slnk_entry = (slinkentry *)malloc(slnk_entrysize))
  2350. == NULL) {
  2351. Info(slide, 0x201, ((char *)slide,
  2352. "warning: symbolic link (%s) failed, no mem\n",
  2353. FnFilter1(G.filename)));
  2354. retcode = PK_MEM;
  2355. }
  2356. else
  2357. {
  2358. slnk_entry->next = NULL;
  2359. slnk_entry->targetlen = ucsize;
  2360. /* don't set attributes for symlinks */
  2361. slnk_entry->attriblen = 0;
  2362. slnk_entry->target = slnk_entry->buf;
  2363. slnk_entry->fname = slnk_entry->target + ucsize + 1;
  2364. strcpy(slnk_entry->fname, G.filename);
  2365. /* Read the link text using the appropriate method. */
  2366. status = _read_link_rms(ucsize, slnk_entry->target);
  2367. if (ERR(status))
  2368. {
  2369. Info(slide, 0x201, ((char *)slide,
  2370. "warning: error reading symlink text (rms): %s\n",
  2371. strerror(EVMSERR, status)));
  2372. free(slnk_entry);
  2373. retcode = PK_DISK;
  2374. }
  2375. else
  2376. {
  2377. if (QCOND2)
  2378. Info(slide, 0, ((char *)slide, "-> %s ",
  2379. FnFilter1(slnk_entry->target)));
  2380. /* Add this symlink record to the list of
  2381. deferred symlinks. */
  2382. if (G.slink_last != NULL)
  2383. G.slink_last->next = slnk_entry;
  2384. else
  2385. G.slink_head = slnk_entry;
  2386. G.slink_last = slnk_entry;
  2387. }
  2388. }
  2389. }
  2390. }
  2391. }
  2392. #endif /* SYMLINKS */
  2393. /* Link XABRDT, XABDAT, and (optionally) XABPRO. */
  2394. if (xabrdt != NULL)
  2395. {
  2396. xabrdt->xab$l_nxt = NULL;
  2397. outfab->fab$l_xab = (void *) xabrdt;
  2398. }
  2399. else
  2400. {
  2401. rdt.xab$l_nxt = NULL;
  2402. outfab->fab$l_xab = (void *) &rdt;
  2403. }
  2404. if (xabdat != NULL)
  2405. {
  2406. xabdat->xab$l_nxt = outfab->fab$l_xab;
  2407. outfab->fab$l_xab = (void *)xabdat;
  2408. }
  2409. if (xabpro != NULL)
  2410. {
  2411. if ( !uO.X_flag )
  2412. xabpro->xab$l_uic = 0; /* Use default (user's) uic */
  2413. xabpro->xab$l_nxt = outfab->fab$l_xab;
  2414. outfab->fab$l_xab = (void *) xabpro;
  2415. }
  2416. else
  2417. {
  2418. pro = cc$rms_xabpro;
  2419. pro.xab$w_pro = G.pInfo->file_attr;
  2420. pro.xab$l_nxt = outfab->fab$l_xab;
  2421. outfab->fab$l_xab = (void *) &pro;
  2422. }
  2423. status = sys$wait(outrab);
  2424. if (ERR(status))
  2425. {
  2426. vms_msg(__G__ "[ _close_rms: sys$wait failed ]\n", status);
  2427. if (outrab->rab$l_stv != 0)
  2428. {
  2429. vms_msg(__G__ "", outrab->rab$l_stv);
  2430. }
  2431. }
  2432. status = sys$close(outfab);
  2433. #ifdef DEBUG
  2434. if (ERR(status))
  2435. {
  2436. vms_msg(__G__
  2437. "\r[ Warning: cannot set owner/protection/time attributes ]\n",
  2438. status);
  2439. if (outfab->fab$l_stv != 0)
  2440. {
  2441. vms_msg(__G__ "", outfab->fab$l_stv);
  2442. }
  2443. retcode = PK_WARN;
  2444. }
  2445. #endif
  2446. free_up();
  2447. return retcode;
  2448. }
  2449. static int _close_qio(__GPRO)
  2450. {
  2451. int status;
  2452. pka_fib.FIB$L_ACCTL =
  2453. FIB$M_WRITE | FIB$M_NOTRUNC ;
  2454. pka_fib.FIB$W_EXCTL = 0;
  2455. pka_fib.FIB$W_FID[0] =
  2456. pka_fib.FIB$W_FID[1] =
  2457. pka_fib.FIB$W_FID[2] =
  2458. pka_fib.FIB$W_DID[0] =
  2459. pka_fib.FIB$W_DID[1] =
  2460. pka_fib.FIB$W_DID[2] = 0;
  2461. #ifdef ASYNCH_QIO
  2462. if (pka_io_pending) {
  2463. status = sys$synch(0, &pka_io_iosb);
  2464. if (!ERR(status))
  2465. status = pka_io_iosb.status;
  2466. if (ERR(status))
  2467. {
  2468. vms_msg(__G__ "[ _close_qio: sys$synch found I/O failure ]\n",
  2469. status);
  2470. }
  2471. pka_io_pending = FALSE;
  2472. }
  2473. #endif /* ASYNCH_QIO */
  2474. #ifdef SYMLINKS
  2475. if (G.symlnk && QCOND2)
  2476. {
  2477. /* Read back the symlink target specification for display purpose. */
  2478. extent ucsize = (extent)G.lrec.ucsize;
  2479. char *link_target; /* Link text storage. */
  2480. if ((link_target = malloc(ucsize + 1)) == NULL)
  2481. {
  2482. Info(slide, 0x201, ((char *)slide,
  2483. "warning: cannot show symlink (%s) target, no mem\n",
  2484. FnFilter1(G.filename)));
  2485. }
  2486. else
  2487. {
  2488. unsigned bytes_read = 0;
  2489. status = sys$qiow(0, /* event flag */
  2490. pka_devchn, /* channel */
  2491. IO$_READVBLK, /* function */
  2492. &pka_io_iosb, /* IOSB */
  2493. 0, /* AST address */
  2494. 0, /* AST parameter */
  2495. link_target, /* P1 = buffer address */
  2496. ucsize, /* P2 = requested byte count */
  2497. 1, /* P3 = VBN (1 = first) */
  2498. 0, /* P4 (not used) */
  2499. 0, /* P5 (not used) */
  2500. 0); /* P6 (not used) */
  2501. if (!ERR(status))
  2502. /* Final status. */
  2503. status = pka_io_iosb.status;
  2504. /* Set the resultant byte count. */
  2505. if (!ERR(status))
  2506. bytes_read = pka_io_iosb.count;
  2507. /* NUL-terminate the link text. */
  2508. link_target[bytes_read] = '\0';
  2509. if (ERR(status))
  2510. {
  2511. Info(slide, 0x201, ((char *)slide,
  2512. "warning: error reading symlink text (qio): %s\n",
  2513. strerror(EVMSERR, status)));
  2514. }
  2515. else
  2516. {
  2517. Info(slide, 0, ((char *)slide, "-> %s ",
  2518. FnFilter1(link_target)));
  2519. }
  2520. free(link_target);
  2521. }
  2522. }
  2523. #endif /* SYMLINKS */
  2524. status = sys$qiow(0, pka_devchn, IO$_DEACCESS, &pka_acp_iosb,
  2525. 0, 0,
  2526. &pka_fibdsc, 0, 0, 0,
  2527. pka_atr, 0);
  2528. sys$dassgn(pka_devchn);
  2529. if ( !ERR(status) )
  2530. status = pka_acp_iosb.status;
  2531. if ( ERR(status) )
  2532. {
  2533. vms_msg(__G__ "[ Deaccess QIO failed ]\n", status);
  2534. return PK_DISK;
  2535. }
  2536. return PK_COOL;
  2537. }
  2538. #ifdef SET_DIR_ATTRIB
  2539. /*
  2540. * 2006-10-04 SMS.
  2541. * vms_path_fixdown().
  2542. *
  2543. * Convert VMS directory spec to VMS directory file name. That is,
  2544. * change "dev:[a.b.c.e]" to "dev:[a.b.c]e.DIR;1". The result (always
  2545. * larger than the source) is returned in the user's buffer.
  2546. */
  2547. #define DIR_TYPE_VER ".DIR;1"
  2548. static char *vms_path_fixdown(ZCONST char *dir_spec, char *dir_file)
  2549. {
  2550. char dir_close;
  2551. char dir_open;
  2552. unsigned i;
  2553. unsigned dir_spec_len;
  2554. dir_spec_len = strlen(dir_spec);
  2555. if (dir_spec_len == 0) return NULL;
  2556. i = dir_spec_len - 1;
  2557. dir_close = dir_spec[i];
  2558. /* Identify the directory delimiters (which must exist). */
  2559. if (dir_close == ']')
  2560. {
  2561. dir_open = '[';
  2562. }
  2563. else if (dir_close == '>')
  2564. {
  2565. dir_open = '<';
  2566. }
  2567. else
  2568. {
  2569. return NULL;
  2570. }
  2571. /* Find the beginning of the last directory name segment. */
  2572. while ((i > 0) && ((dir_spec[i - 1] == '^') ||
  2573. ((dir_spec[i] != '.') && (dir_spec[i] != dir_open))))
  2574. {
  2575. i--;
  2576. }
  2577. /* Form the directory file name from the pieces. */
  2578. if (dir_spec[i] == dir_open)
  2579. {
  2580. /* Top-level directory. */
  2581. sprintf(dir_file, "%.*s000000%c%.*s%s",
  2582. /* "dev:[" "000000" "]" */
  2583. (i + 1), dir_spec, dir_close,
  2584. /* "a" ".DIR;1" */
  2585. (dir_spec_len - i - 2), (dir_spec + i + 1), DIR_TYPE_VER);
  2586. }
  2587. else
  2588. {
  2589. /* Non-top-level directory. */
  2590. sprintf(dir_file, "%.*s%c%.*s%s",
  2591. /* "dev:[a.b.c" "]" */
  2592. i, dir_spec, dir_close,
  2593. /* "e" ".DIR;1" */
  2594. (dir_spec_len - i - 2), (dir_spec + i + 1), DIR_TYPE_VER);
  2595. }
  2596. return dir_file;
  2597. } /* end function vms_path_fixdown(). */
  2598. /* Save directory attributes (as the archive's extra field). */
  2599. /* 2006-12-13 SMS.
  2600. * This could probably be made more efficient by analyzing the data
  2601. * here, extracting the important data, and saving only what's needed.
  2602. * Given the existing code, it seemed simpler to save them all here, and
  2603. * deal with what's important in set_direc_attribs().
  2604. */
  2605. int defer_dir_attribs(__G__ pd)
  2606. __GDEF
  2607. direntry **pd;
  2608. {
  2609. vmsdirattr *d_entry;
  2610. unsigned fnlen;
  2611. unsigned xlen;
  2612. /* Allocate space to save the file (directory) name, the extra
  2613. * block, and all the other data needed by the extra-block data
  2614. * scanner functions. If that works, save the data.
  2615. */
  2616. fnlen = strlen(G.filename);
  2617. xlen = G.lrec.extra_field_length;
  2618. d_entry = (vmsdirattr *) malloc(sizeof(vmsdirattr) + fnlen + xlen);
  2619. *pd = (direntry *) d_entry;
  2620. if (d_entry == (vmsdirattr *) NULL)
  2621. {
  2622. return PK_MEM;
  2623. }
  2624. /* Save extra block length and data. */
  2625. d_entry->xlen = xlen;
  2626. memcpy(d_entry->buf, G.extra_field, xlen);
  2627. /* Set pointer to file (directory) name. */
  2628. d_entry->fn = d_entry->buf + xlen;
  2629. /* Save file (directory) name. */
  2630. strcpy(d_entry->fn, G.filename);
  2631. /* Strip the closing ']' char, to allow proper sorting. */
  2632. d_entry->fn[fnlen - 1] = '\0';
  2633. /* Save generic permission data from mapattr(). */
  2634. d_entry->perms = G.pInfo->file_attr;
  2635. /* Save G.lrec.last_mod_dos_datetime. */
  2636. d_entry->mod_dos_datetime = G.lrec.last_mod_dos_datetime;
  2637. return PK_OK;
  2638. } /* end function defer_dir_attribs() */
  2639. int set_direc_attribs(__G__ d)
  2640. __GDEF
  2641. direntry *d;
  2642. {
  2643. uch *sav_ef_ptr;
  2644. int i;
  2645. int status;
  2646. int type;
  2647. ush attr;
  2648. struct XABPRO pro;
  2649. char dir_name[NAM_MAXRSS + 1];
  2650. char warnmsg[NAM_MAXRSS + 128]; /* Name length + message length. */
  2651. int retcode = PK_OK;
  2652. /* Re-append the closing ']' character which has been stripped in
  2653. * defer_dir_attribs() for compatibility with generic sorting code.
  2654. */
  2655. strcat(VmsAtt(d)->fn, "]");
  2656. /* Convert "[a.b.c]" form into "[a.b]c.DIR;1" */
  2657. vms_path_fixdown(VmsAtt(d)->fn, dir_name);
  2658. /* Dummy up critical global (G) data from the preserved directory
  2659. * attribute data.
  2660. */
  2661. sav_ef_ptr = G.extra_field;
  2662. G.extra_field = (uch *)((VmsAtt(d)->xlen > 0) ? VmsAtt(d)->buf : NULL);
  2663. G.lrec.extra_field_length = VmsAtt(d)->xlen;
  2664. /* Extract the VMS file attributes from the preserved attribute
  2665. * data, if they exist, and restore the date-time stamps.
  2666. */
  2667. type = find_vms_attrs(__G__ (uO.D_flag <= 0));
  2668. if (outfab == NULL)
  2669. {
  2670. /* Default and PK schemes need a FAB. (IZ supplies one.)
  2671. * In a degenerate case, this could be the first use of fileblk,
  2672. * so we assume that we need to initialize it.
  2673. */
  2674. fileblk = cc$rms_fab; /* Initialize FAB. */
  2675. outfab = &fileblk; /* Set pointer used elsewhere. */
  2676. }
  2677. /* Arrange FAB-NAM[L] for file (directory) access. */
  2678. if (type != VAT_NONE)
  2679. {
  2680. if (type == VAT_IZ)
  2681. {
  2682. /* Make an attribute descriptor list for the VMS creation and
  2683. * revision dates (which were stored in the IZ XABs by
  2684. * find_vms_attrs()).
  2685. */
  2686. pka_idx = 0;
  2687. if (xabrdt != NULL)
  2688. {
  2689. /* Revision date-time from XABRDT. */
  2690. pka_atr[pka_idx].atr$w_size = 8;
  2691. pka_atr[pka_idx].atr$w_type = ATR$C_REVDATE;
  2692. pka_atr[pka_idx].atr$l_addr = GVTC &xabrdt->xab$q_rdt;
  2693. ++pka_idx;
  2694. }
  2695. if (xabdat != NULL)
  2696. {
  2697. /* Trust the XABRDT value for revision date. */
  2698. if (xabrdt == NULL)
  2699. {
  2700. /* Revision date-time from XABDAT. */
  2701. pka_atr[pka_idx].atr$w_size = 8;
  2702. pka_atr[pka_idx].atr$w_type = ATR$C_REVDATE;
  2703. pka_atr[pka_idx].atr$l_addr = GVTC &xabdat->xab$q_rdt;
  2704. ++pka_idx;
  2705. }
  2706. /* Creation date-time from XABDAT. */
  2707. pka_atr[pka_idx].atr$w_size = 8;
  2708. pka_atr[pka_idx].atr$w_type = ATR$C_CREDATE;
  2709. pka_atr[pka_idx].atr$l_addr = GVTC &xabdat->xab$q_cdt;
  2710. ++pka_idx;
  2711. }
  2712. if (xabpro != NULL)
  2713. {
  2714. if ( uO.X_flag ) {
  2715. pka_atr[pka_idx].atr$w_size = 4;
  2716. pka_atr[pka_idx].atr$w_type = ATR$C_UIC;
  2717. pka_atr[pka_idx].atr$l_addr = GVTC &xabpro->xab$l_uic;
  2718. ++pka_idx;
  2719. }
  2720. attr = xabpro->xab$w_pro;
  2721. }
  2722. else
  2723. {
  2724. /* Revoke directory Delete permission for all. */
  2725. attr = VmsAtt(d)->perms
  2726. | (((1<< XAB$V_NODEL)<< XAB$V_SYS)|
  2727. ((1<< XAB$V_NODEL)<< XAB$V_OWN)|
  2728. ((1<< XAB$V_NODEL)<< XAB$V_GRP)|
  2729. ((1<< XAB$V_NODEL)<< XAB$V_WLD));
  2730. }
  2731. pka_atr[pka_idx].atr$w_size = 2;
  2732. pka_atr[pka_idx].atr$w_type = ATR$C_FPRO;
  2733. pka_atr[pka_idx].atr$l_addr = GVTC &attr;
  2734. ++pka_idx;
  2735. }
  2736. }
  2737. else
  2738. {
  2739. /* No VMS attribute data were found. Prepare to assemble
  2740. * non-VMS attribute data.
  2741. */
  2742. pka_idx = 0;
  2743. /* Get the (already converted) non-VMS permissions. */
  2744. attr = VmsAtt(d)->perms; /* Use right-sized prot storage. */
  2745. /* Revoke directory Delete permission for all. */
  2746. attr |= (((1<< XAB$V_NODEL)<< XAB$V_SYS)|
  2747. ((1<< XAB$V_NODEL)<< XAB$V_OWN)|
  2748. ((1<< XAB$V_NODEL)<< XAB$V_GRP)|
  2749. ((1<< XAB$V_NODEL)<< XAB$V_WLD));
  2750. pka_atr[pka_idx].atr$w_size = 2;
  2751. pka_atr[pka_idx].atr$w_type = ATR$C_FPRO;
  2752. pka_atr[pka_idx].atr$l_addr = GVTC &attr;
  2753. ++pka_idx;
  2754. /* Restore directory date-time if user requests it (-D). */
  2755. if (uO.D_flag <= 0)
  2756. {
  2757. /* Set the directory date-time from the non-VMS data.
  2758. * Dummy up the DOS-style modification date into global (G)
  2759. * data from the preserved directory attribute data.
  2760. */
  2761. G.lrec.last_mod_dos_datetime = VmsAtt(d)->mod_dos_datetime;
  2762. /* Extract date-time data from the normal attribute data. */
  2763. set_default_datetime_XABs(__G);
  2764. /* Make an attribute descriptor list for the VMS creation
  2765. * and revision dates (which were stored in the XABs by
  2766. * set_default_datetime_XABs()).
  2767. */
  2768. pka_atr[pka_idx].atr$w_size = 8;
  2769. pka_atr[pka_idx].atr$w_type = ATR$C_CREDATE;
  2770. pka_atr[pka_idx].atr$l_addr = GVTC &dattim.xab$q_cdt;
  2771. ++pka_idx;
  2772. pka_atr[pka_idx].atr$w_size = 8;
  2773. pka_atr[pka_idx].atr$w_type = ATR$C_REVDATE;
  2774. pka_atr[pka_idx].atr$l_addr = GVTC &rdt.xab$q_rdt;
  2775. ++pka_idx;
  2776. }
  2777. /* Set the directory protection from the non-VMS data. */
  2778. /* Terminate the attribute descriptor list. */
  2779. pka_atr[pka_idx].atr$w_size = 0; /* End of list */
  2780. pka_atr[pka_idx].atr$w_type = 0;
  2781. pka_atr[pka_idx].atr$l_addr = 0; /* NULL when DECC VAX gets fixed. */
  2782. }
  2783. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  2784. outfab->FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  2785. /* Point the FAB-NAM[L] to the VMS-format directory file name. */
  2786. #ifdef NAML$C_MAXRSS
  2787. outfab->fab$l_dna = (char *) -1; /* Using NAML for default name. */
  2788. outfab->fab$l_fna = (char *) -1; /* Using NAML for file name. */
  2789. /* Special ODS5-QIO-compatible name storage. */
  2790. nam.naml$l_filesys_name = sys_nam;
  2791. nam.naml$l_filesys_name_alloc = sizeof(sys_nam);
  2792. #endif /* NAML$C_MAXRSS */
  2793. FAB_OR_NAML(*outfab, nam).FAB_OR_NAML_FNA = dir_name;
  2794. FAB_OR_NAML(*outfab, nam).FAB_OR_NAML_FNS = strlen(dir_name);
  2795. /* Expanded and resultant name storage. */
  2796. nam.NAM_ESA = exp_nam;
  2797. nam.NAM_ESS = sizeof(exp_nam);
  2798. nam.NAM_RSA = res_nam;
  2799. nam.NAM_RSS = sizeof(res_nam);
  2800. status = sys$parse(outfab);
  2801. if ( ERR(status) )
  2802. {
  2803. sprintf(warnmsg,
  2804. "warning: set-dir-attributes failed ($parse) for %s.\n",
  2805. dir_name);
  2806. vms_msg(__G__ warnmsg, status);
  2807. retcode = PK_WARN;
  2808. goto cleanup_exit;
  2809. }
  2810. /* Set the length in the device name descriptor. */
  2811. pka_devdsc.dsc$w_length = (unsigned short) nam.NAM_DVI[0];
  2812. /* Open a channel to the disk device. */
  2813. status = sys$assign(&pka_devdsc, &pka_devchn, 0, 0);
  2814. if ( ERR(status) )
  2815. {
  2816. sprintf(warnmsg,
  2817. "warning: set-dir-attributes failed ($assign) for %s.\n",
  2818. dir_name);
  2819. vms_msg(__G__ warnmsg, status);
  2820. retcode = PK_WARN;
  2821. goto cleanup_exit;
  2822. }
  2823. /* Move the directory ID from the NAM[L] to the FIB.
  2824. Clear the FID in the FIB, as we're using the name.
  2825. */
  2826. for (i = 0; i < 3; i++)
  2827. {
  2828. pka_fib.FIB$W_DID[i] = nam.NAM_DID[i];
  2829. pka_fib.FIB$W_FID[i] = 0;
  2830. }
  2831. #ifdef NAML$C_MAXRSS
  2832. /* Enable fancy name characters. Note that "fancy" here does
  2833. not include Unicode, for which there's no support elsewhere.
  2834. */
  2835. pka_fib.fib$v_names_8bit = 1;
  2836. pka_fib.fib$b_name_format_in = FIB$C_ISL1;
  2837. /* ODS5 Extended names used as input to QIO have peculiar
  2838. encoding (perhaps to minimize storage?), so the special
  2839. filesys_name result (typically containing fewer carets) must
  2840. be used here.
  2841. */
  2842. pka_fnam.dsc$a_pointer = nam.naml$l_filesys_name;
  2843. pka_fnam.dsc$w_length = nam.naml$l_filesys_name_size;
  2844. #else /* !NAML$C_MAXRSS */
  2845. /* ODS2-only: Use the whole name. */
  2846. pka_fnam.dsc$a_pointer = nam.NAM_L_NAME;
  2847. pka_fnam.dsc$w_length = nam.NAM_B_NAME + nam.NAM_B_TYPE + nam.NAM_B_VER;
  2848. #endif /* ?NAML$C_MAXRSS */
  2849. /* 2007-07-13 SMS.
  2850. * Our freshly created directory can easily contain fewer files than
  2851. * the original archived directory (for example, if not all the
  2852. * files in the original directory were included in the archive), so
  2853. * its size may differ from that of the archived directory. Thus,
  2854. * simply restoring the original RECATTR attributes structure, which
  2855. * includes EFBLK (and so on) can cause "SYSTEM-W-BADIRECTORY, bad
  2856. * directory file format" complaints. Instead, we overwrite
  2857. * selected archived attributes with current attributes, to avoid
  2858. * setting obsolete/inappropriate attributes on the newly created
  2859. * directory file.
  2860. *
  2861. * First, see if there is a RECATTR structure about which we need to
  2862. * worry.
  2863. */
  2864. for (i = 0; pka_atr[i].atr$w_type != 0; i++)
  2865. {
  2866. if (pka_atr[i].atr$w_type == ATR$C_RECATTR)
  2867. {
  2868. /* We found a RECATTR structure which (we must assume) needs
  2869. * adjustment. Retrieve the RECATTR data for the existing
  2870. * (newly created) directory file.
  2871. */
  2872. status = sys$qiow(0, /* event flag */
  2873. pka_devchn, /* channel */
  2874. IO$_ACCESS, /* function code */
  2875. &pka_acp_iosb, /* IOSB */
  2876. 0, /* AST address */
  2877. 0, /* AST parameter */
  2878. &pka_fibdsc, /* P1 = File Info Block */
  2879. &pka_fnam, /* P2 = File name */
  2880. 0, /* P3 = Rslt nm len */
  2881. 0, /* P4 = Rslt nm str */
  2882. pka_recattr, /* P5 = Attributes */
  2883. 0); /* P6 (not used) */
  2884. /* If initial success, then get the final status from the IOSB. */
  2885. if ( !ERR(status) )
  2886. status = pka_acp_iosb.status;
  2887. if ( ERR(status) )
  2888. {
  2889. sprintf(warnmsg,
  2890. "warning: set-dir-attributes failed ($qiow acc) for %s.\n",
  2891. dir_name);
  2892. vms_msg(__G__ warnmsg, status);
  2893. retcode = PK_WARN;
  2894. }
  2895. else
  2896. {
  2897. /* We should have valid RECATTR data. Overwrite the
  2898. * critical bits of the archive RECATTR structure with
  2899. * the current bits. The book says that an attempt to
  2900. * modify HIBLK will be ignored, and FFBYTE should
  2901. * always be zero, but safety is cheap.
  2902. */
  2903. struct fatdef *ptr_recattr;
  2904. ptr_recattr = (struct fatdef *) pka_atr[i].atr$l_addr;
  2905. ptr_recattr->fat$l_hiblk = pka_rattr.fat$l_hiblk;
  2906. ptr_recattr->fat$l_efblk = pka_rattr.fat$l_efblk;
  2907. ptr_recattr->fat$w_ffbyte = pka_rattr.fat$w_ffbyte;
  2908. }
  2909. /* There should be only one RECATTR structure in the list, so
  2910. * escape from the loop after the first/only one has been
  2911. * processed.
  2912. */
  2913. break;
  2914. }
  2915. }
  2916. /* Modify the file (directory) attributes. */
  2917. status = sys$qiow(0, /* event flag */
  2918. pka_devchn, /* channel */
  2919. IO$_MODIFY, /* function code */
  2920. &pka_acp_iosb, /* IOSB */
  2921. 0, /* AST address */
  2922. 0, /* AST parameter */
  2923. &pka_fibdsc, /* P1 = File Info Block */
  2924. &pka_fnam, /* P2 = File name */
  2925. 0, /* P3 = Rslt nm len */
  2926. 0, /* P4 = Rslt nm str */
  2927. pka_atr, /* P5 = Attributes */
  2928. 0); /* P6 (not used) */
  2929. /* If initial success, then get the final status from the IOSB. */
  2930. if ( !ERR(status) )
  2931. status = pka_acp_iosb.status;
  2932. if ( ERR(status) )
  2933. {
  2934. sprintf(warnmsg,
  2935. "warning: set-dir-attributes failed ($qiow mod) for %s.\n",
  2936. dir_name);
  2937. vms_msg(__G__ warnmsg, status);
  2938. retcode = PK_WARN;
  2939. }
  2940. sys$dassgn(pka_devchn);
  2941. cleanup_exit:
  2942. free_up(); /* Free FAB, XAB storage. */
  2943. free(d); /* Free directory attribute storage. */
  2944. G.extra_field = sav_ef_ptr; /* Restore original pointer. */
  2945. return retcode;
  2946. } /* end function set_direc_attribs() */
  2947. #endif /* SET_DIR_ATTRIB */
  2948. #ifdef TIMESTAMP
  2949. /* Nonzero if `y' is a leap year, else zero. */
  2950. #define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)
  2951. /* Number of leap years from 1970 to `y' (not including `y' itself). */
  2952. #define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)
  2953. /* Accumulated number of days from 01-Jan up to start of current month. */
  2954. static ZCONST short ydays[] = {
  2955. 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
  2956. };
  2957. /***********************/
  2958. /* Function mkgmtime() */
  2959. /***********************/
  2960. static time_t mkgmtime(tm)
  2961. struct tm *tm;
  2962. {
  2963. time_t m_time;
  2964. int yr, mo, dy, hh, mm, ss;
  2965. unsigned days;
  2966. yr = tm->tm_year - 70;
  2967. mo = tm->tm_mon;
  2968. dy = tm->tm_mday - 1;
  2969. hh = tm->tm_hour;
  2970. mm = tm->tm_min;
  2971. ss = tm->tm_sec;
  2972. /* calculate days from BASE to this year and add expired days this year */
  2973. dy = (unsigned)dy + ((unsigned)yr * 365) + (unsigned)nleap(yr+1970) +
  2974. (unsigned)ydays[mo] + ((mo > 1) && leap(yr+1970));
  2975. /* convert date & time to seconds relative to 00:00:00, 01/01/1970 */
  2976. return (time_t)((unsigned long)(unsigned)dy * 86400L +
  2977. (unsigned long)hh * 3600L +
  2978. (unsigned long)(mm * 60 + ss));
  2979. } /* end function mkgmtime() */
  2980. /*******************************/
  2981. /* Function dos_to_unix_time() */ /* only used for timestamping of archives */
  2982. /*******************************/
  2983. time_t dos_to_unix_time(dosdatetime)
  2984. ulg dosdatetime;
  2985. {
  2986. struct tm *ltm; /* Local time. */
  2987. time_t loctime; /* The time_t value of local time. */
  2988. time_t then; /* The time to return. */
  2989. long tzoffset_adj; /* timezone-adjustment `remainder' */
  2990. int bailout_cnt; /* counter of tries for tz correction */
  2991. then = time(NULL);
  2992. ltm = localtime(&then);
  2993. /* dissect date */
  2994. ltm->tm_year = ((int)(dosdatetime >> 25) & 0x7f) + 80;
  2995. ltm->tm_mon = ((int)(dosdatetime >> 21) & 0x0f) - 1;
  2996. ltm->tm_mday = ((int)(dosdatetime >> 16) & 0x1f);
  2997. /* dissect time */
  2998. ltm->tm_hour = (int)(dosdatetime >> 11) & 0x1f;
  2999. ltm->tm_min = (int)(dosdatetime >> 5) & 0x3f;
  3000. ltm->tm_sec = (int)(dosdatetime << 1) & 0x3e;
  3001. loctime = mkgmtime(ltm);
  3002. /* Correct for the timezone and any daylight savings time.
  3003. The correction is verified and repeated when not correct, to
  3004. take into account the rare case that a change to or from daylight
  3005. savings time occurs between when it is the time in `tm' locally
  3006. and when it is that time in Greenwich. After the second correction,
  3007. the "timezone & daylight" offset should be correct in all cases. To
  3008. be sure, we allow a third try, but then the loop is stopped. */
  3009. bailout_cnt = 3;
  3010. then = loctime;
  3011. do {
  3012. ltm = localtime(&then);
  3013. tzoffset_adj = (ltm != NULL) ? (loctime - mkgmtime(ltm)) : 0L;
  3014. if (tzoffset_adj == 0L)
  3015. break;
  3016. then += tzoffset_adj;
  3017. } while (--bailout_cnt > 0);
  3018. if ( (dosdatetime >= DOSTIME_2038_01_18) &&
  3019. (then < (time_t)0x70000000L) )
  3020. then = U_TIME_T_MAX; /* saturate in case of (unsigned) overflow */
  3021. if (then < (time_t)0L) /* a converted DOS time cannot be negative */
  3022. then = S_TIME_T_MAX; /* -> saturate at max signed time_t value */
  3023. return then;
  3024. } /* end function dos_to_unix_time() */
  3025. /*******************************/
  3026. /* Function uxtime2vmstime() */
  3027. /*******************************/
  3028. static void uxtime2vmstime( /* convert time_t value into 64 bit VMS bintime */
  3029. time_t utimeval,
  3030. long int binval[2] )
  3031. {
  3032. time_t m_time = utimeval;
  3033. struct tm *t = localtime(&m_time);
  3034. if (t == (struct tm *)NULL) {
  3035. /* time conversion error; use current time instead, hoping
  3036. that localtime() does not reject it as well! */
  3037. m_time = time(NULL);
  3038. t = localtime(&m_time);
  3039. }
  3040. sprintf(timbuf, "%02d-%3s-%04d %02d:%02d:%02d.00",
  3041. t->tm_mday, month[t->tm_mon], t->tm_year + 1900,
  3042. t->tm_hour, t->tm_min, t->tm_sec);
  3043. sys$bintim(&date_str, binval);
  3044. } /* end function uxtime2vmstime() */
  3045. /***************************/
  3046. /* Function stamp_file() */ /* adapted from VMSmunch...it just won't die! */
  3047. /***************************/
  3048. int stamp_file(fname, modtime)
  3049. ZCONST char *fname;
  3050. time_t modtime;
  3051. {
  3052. int status;
  3053. int i;
  3054. static long int Cdate[2], Rdate[2], Edate[2], Bdate[2];
  3055. static short int revisions;
  3056. #if defined(__DECC) || defined(__DECCXX)
  3057. #pragma __member_alignment __save
  3058. #pragma __nomember_alignment
  3059. #endif /* __DECC || __DECCXX */
  3060. static union {
  3061. unsigned short int value;
  3062. struct {
  3063. unsigned system : 4;
  3064. unsigned owner : 4;
  3065. unsigned group : 4;
  3066. unsigned world : 4;
  3067. } bits;
  3068. } prot;
  3069. #if defined(__DECC) || defined(__DECCXX)
  3070. #pragma __member_alignment __restore
  3071. #endif /* __DECC || __DECCXX */
  3072. static unsigned long uic;
  3073. static struct fjndef jnl;
  3074. static struct atrdef Atr[] = {
  3075. {sizeof(pka_rattr), ATR$C_RECATTR, GVTC &pka_rattr},
  3076. {sizeof(pka_uchar), ATR$C_UCHAR, GVTC &pka_uchar},
  3077. {sizeof(Cdate), ATR$C_CREDATE, GVTC &Cdate[0]},
  3078. {sizeof(Rdate), ATR$C_REVDATE, GVTC &Rdate[0]},
  3079. {sizeof(Edate), ATR$C_EXPDATE, GVTC &Edate[0]},
  3080. {sizeof(Bdate), ATR$C_BAKDATE, GVTC &Bdate[0]},
  3081. {sizeof(revisions), ATR$C_ASCDATES, GVTC &revisions},
  3082. {sizeof(prot), ATR$C_FPRO, GVTC &prot},
  3083. {sizeof(uic), ATR$C_UIC, GVTC &uic},
  3084. {sizeof(jnl), ATR$C_JOURNAL, GVTC &jnl},
  3085. {0, 0, 0}
  3086. };
  3087. fileblk = cc$rms_fab; /* Initialize FAB. */
  3088. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  3089. fileblk.FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  3090. #ifdef NAML$C_MAXRSS
  3091. fileblk.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  3092. fileblk.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  3093. /* Special ODS5-QIO-compatible name storage. */
  3094. nam.naml$l_filesys_name = sys_nam;
  3095. nam.naml$l_filesys_name_alloc = sizeof(sys_nam);
  3096. #endif /* NAML$C_MAXRSS */
  3097. FAB_OR_NAML(fileblk, nam).FAB_OR_NAML_FNA = (char *)fname;
  3098. FAB_OR_NAML(fileblk, nam).FAB_OR_NAML_FNS = strlen(fname);
  3099. nam.NAM_ESA = exp_nam;
  3100. nam.NAM_ESS = sizeof(exp_nam);
  3101. nam.NAM_RSA = res_nam;
  3102. nam.NAM_RSS = sizeof(res_nam);
  3103. if ( ERR(status = sys$parse(&fileblk)) )
  3104. {
  3105. vms_msg(__G__ "stamp_file: sys$parse failed.\n", status);
  3106. return -1;
  3107. }
  3108. pka_devdsc.dsc$w_length = (unsigned short)nam.NAM_DVI[0];
  3109. if ( ERR(status = sys$assign(&pka_devdsc, &pka_devchn, 0, 0)) )
  3110. {
  3111. vms_msg(__G__ "stamp_file: sys$assign failed.\n", status);
  3112. return -1;
  3113. }
  3114. /* Load the descriptor with the appropriate name data: */
  3115. #ifdef NAML$C_MAXRSS
  3116. /* Enable fancy name characters. Note that "fancy" here does
  3117. not include Unicode, for which there's no support elsewhere.
  3118. */
  3119. pka_fib.fib$v_names_8bit = 1;
  3120. pka_fib.fib$b_name_format_in = FIB$C_ISL1;
  3121. /* ODS5 Extended names used as input to QIO have peculiar
  3122. encoding (perhaps to minimize storage?), so the special
  3123. filesys_name result (typically containing fewer carets) must
  3124. be used here.
  3125. */
  3126. pka_fnam.dsc$a_pointer = nam.naml$l_filesys_name;
  3127. pka_fnam.dsc$w_length = nam.naml$l_filesys_name_size;
  3128. #else /* !NAML$C_MAXRSS */
  3129. /* Extract only the name.type;version. */
  3130. pka_fnam.dsc$a_pointer = nam.NAM_L_NAME;
  3131. pka_fnam.dsc$w_length = nam.NAM_B_NAME + nam.NAM_B_TYPE + nam.NAM_B_VER;
  3132. #endif /* ?NAML$C_MAXRSS */
  3133. /* Move the directory ID from the NAM[L] to the FIB.
  3134. Clear the FID in the FIB, as we're using the name.
  3135. */
  3136. for (i = 0; i < 3; i++)
  3137. {
  3138. pka_fib.FIB$W_DID[i] = nam.NAM_DID[i];
  3139. pka_fib.FIB$W_FID[i] = 0;
  3140. }
  3141. /* Use the IO$_ACCESS function to return info about the file.
  3142. This way, the file is not opened, and the expiration and
  3143. revision dates are not modified.
  3144. */
  3145. status = sys$qiow(0, pka_devchn, IO$_ACCESS,
  3146. &pka_acp_iosb, 0, 0,
  3147. &pka_fibdsc, &pka_fnam, 0, 0, Atr, 0);
  3148. if ( !ERR(status) )
  3149. status = pka_acp_iosb.status;
  3150. if ( ERR(status) )
  3151. {
  3152. vms_msg(__G__ "[ Access file QIO failed. ]\n", status);
  3153. sys$dassgn(pka_devchn);
  3154. return -1;
  3155. }
  3156. uxtime2vmstime(modtime, Cdate);
  3157. memcpy(Rdate, Cdate, sizeof(Cdate));
  3158. /* Note: Part of the FIB was cleared by earlier QIOW, so reset it. */
  3159. pka_fib.FIB$L_ACCTL = FIB$M_NORECORD;
  3160. /* Move the directory ID from the NAM[L] to the FIB.
  3161. Clear the FID in the FIB, as we're using the name.
  3162. */
  3163. for (i = 0; i < 3; i++)
  3164. {
  3165. pka_fib.FIB$W_DID[i] = nam.NAM_DID[i];
  3166. pka_fib.FIB$W_FID[i] = 0;
  3167. }
  3168. /* Use the IO$_MODIFY function to change info about the file */
  3169. /* Note, used this way, the file is not opened, however this would */
  3170. /* normally cause the expiration and revision dates to be modified. */
  3171. /* Using FIB$M_NORECORD prohibits this from happening. */
  3172. status = sys$qiow(0, pka_devchn, IO$_MODIFY,
  3173. &pka_acp_iosb, 0, 0,
  3174. &pka_fibdsc, &pka_fnam, 0, 0, Atr, 0);
  3175. if ( !ERR(status) )
  3176. status = pka_acp_iosb.status;
  3177. if ( ERR(status) )
  3178. {
  3179. vms_msg(__G__ "[ Modify file QIO failed. ]\n", status);
  3180. sys$dassgn(pka_devchn);
  3181. return -1;
  3182. }
  3183. if ( ERR(status = sys$dassgn(pka_devchn)) )
  3184. {
  3185. vms_msg(__G__ "stamp_file: sys$dassgn failed.\n", status);
  3186. return -1;
  3187. }
  3188. return 0;
  3189. } /* end function stamp_file() */
  3190. #endif /* TIMESTAMP */
  3191. #ifdef DEBUG
  3192. #if 0 /* currently not used anywhere ! */
  3193. void dump_rms_block(p)
  3194. unsigned char *p;
  3195. {
  3196. unsigned char bid, len;
  3197. int err;
  3198. char *type;
  3199. char buf[132];
  3200. int i;
  3201. err = 0;
  3202. bid = p[0];
  3203. len = p[1];
  3204. switch (bid)
  3205. {
  3206. case FAB$C_BID:
  3207. type = "FAB";
  3208. break;
  3209. case XAB$C_ALL:
  3210. type = "xabALL";
  3211. break;
  3212. case XAB$C_KEY:
  3213. type = "xabKEY";
  3214. break;
  3215. case XAB$C_DAT:
  3216. type = "xabDAT";
  3217. break;
  3218. case XAB$C_RDT:
  3219. type = "xabRDT";
  3220. break;
  3221. case XAB$C_FHC:
  3222. type = "xabFHC";
  3223. break;
  3224. case XAB$C_PRO:
  3225. type = "xabPRO";
  3226. break;
  3227. default:
  3228. type = "Unknown";
  3229. err = 1;
  3230. break;
  3231. }
  3232. printf("Block @%08X of type %s (%d).", p, type, bid);
  3233. if (err)
  3234. {
  3235. printf("\n");
  3236. return;
  3237. }
  3238. printf(" Size = %d\n", len);
  3239. printf(" Offset - Hex - Dec\n");
  3240. for (i = 0; i < len; i += 8)
  3241. {
  3242. int j;
  3243. printf("%3d - ", i);
  3244. for (j = 0; j < 8; j++)
  3245. if (i + j < len)
  3246. printf("%02X ", p[i + j]);
  3247. else
  3248. printf(" ");
  3249. printf(" - ");
  3250. for (j = 0; j < 8; j++)
  3251. if (i + j < len)
  3252. printf("%03d ", p[i + j]);
  3253. else
  3254. printf(" ");
  3255. printf("\n");
  3256. }
  3257. }
  3258. #endif /* never */
  3259. #endif /* DEBUG */
  3260. static char vms_msgbuf[256]; /* VMS-specific error message. */
  3261. static $DESCRIPTOR(vms_msgbuf_dscr, vms_msgbuf);
  3262. char *vms_msg_text(void)
  3263. {
  3264. return vms_msgbuf;
  3265. }
  3266. static int vms_msg_fetch(int status)
  3267. {
  3268. int msglen = 0;
  3269. int sts;
  3270. sts = lib$sys_getmsg(&status, &msglen, &vms_msgbuf_dscr, 0, 0);
  3271. vms_msgbuf[msglen] = '\0';
  3272. return sts;
  3273. }
  3274. static void vms_msg(__GPRO__ ZCONST char *string, int status)
  3275. {
  3276. if (ERR(vms_msg_fetch(status)))
  3277. Info(slide, 1, ((char *)slide,
  3278. "%s[ VMS status = %d ]\n", string, status));
  3279. else
  3280. Info(slide, 1, ((char *)slide,
  3281. "%s[ %s ]\n", string, vms_msgbuf));
  3282. }
  3283. #ifndef SFX
  3284. /* 2004-11-23 SMS.
  3285. * Changed to return the resulting file name even when sys$search()
  3286. * fails. Before, if the user specified "fred.zip;4" and there was
  3287. * none, the error message would complain:
  3288. * cannot find either fred.zip;4 or fred.zip;4.zip.
  3289. * when it wasn't really looking for "fred.zip;4.zip".
  3290. */
  3291. /* 2005-08-11 SPC.
  3292. * The calling interface for the VMS version of do_wild() differs from all
  3293. * other implementations in the way it returns status info.
  3294. * There are three return states:
  3295. * a) pointer to buffer with non-zero-length string
  3296. * - canonical full filespec of existing file (search succeeded).
  3297. * b) pointer to buffer with zero-length string
  3298. * - initial file search has failed, extended VMS error info is available
  3299. * through call to vms_msg_text().
  3300. * c) NULL pointer
  3301. * - repeated file search has failed, because
  3302. * i) the list of matches for the pattern has been exhausted after at
  3303. * least one successful attempt.
  3304. * ii) a second attempt for a failed initial pattern (where do_wild()
  3305. * has returned a zero-length string) was tried and failed again.
  3306. */
  3307. char *do_wild( __G__ wld )
  3308. __GDEF
  3309. ZCONST char *wld;
  3310. {
  3311. int status;
  3312. static char filenam[NAM_MAXRSS + 1];
  3313. static char efn[NAM_MAXRSS];
  3314. static char last_wild[NAM_MAXRSS + 1];
  3315. static struct FAB fab;
  3316. static struct NAM_STRUCT nam;
  3317. static int first_call = 1;
  3318. static ZCONST char deflt[] = "[]*.ZIP";
  3319. if ( first_call || strcmp(wld, last_wild) )
  3320. { /* (Re)Initialize everything */
  3321. strcpy( last_wild, wld );
  3322. fab = cc$rms_fab; /* Initialize FAB. */
  3323. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  3324. fab.FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  3325. #ifdef NAML$C_MAXRSS
  3326. fab.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  3327. fab.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  3328. #endif /* NAML$C_MAXRSS */
  3329. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNA = (char *) deflt;
  3330. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNS = sizeof(deflt) - 1;
  3331. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNA = last_wild;
  3332. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNS = strlen(last_wild);
  3333. nam.NAM_ESA = efn;
  3334. nam.NAM_ESS = sizeof(efn)-1;
  3335. nam.NAM_RSA = filenam;
  3336. nam.NAM_RSS = sizeof(filenam)-1;
  3337. first_call = 0;
  3338. /* 2005-08-08 SMS.
  3339. * Parse the file spec. If sys$parse() fails, save the VMS
  3340. * error message for later use, and return an empty string.
  3341. */
  3342. nam.NAM_NOP = NAM_M_SYNCHK; /* Syntax-only analysis. */
  3343. if ( !OK(status = sys$parse(&fab)) )
  3344. {
  3345. vms_msg_fetch(status);
  3346. filenam[0] = '\0'; /* Initialization failed */
  3347. return filenam;
  3348. }
  3349. /* 2005-11-16 SMS.
  3350. * If syntax-only parse worked, re-parse normally so that
  3351. * sys$search() will work properly. Regardless of parse error,
  3352. * leave filenam[] as-was.
  3353. */
  3354. nam.NAM_NOP = 0; /* Normal analysis. */
  3355. if ( OK(status = sys$parse(&fab)) )
  3356. {
  3357. status = sys$search(&fab);
  3358. }
  3359. if ( !OK(status) )
  3360. {
  3361. /* Save the VMS error message for later use. */
  3362. vms_msg_fetch(status);
  3363. }
  3364. }
  3365. else
  3366. {
  3367. if ( !OK(sys$search(&fab)) )
  3368. {
  3369. first_call = 1; /* Reinitialize next time */
  3370. return (char *)NULL;
  3371. }
  3372. }
  3373. filenam[nam.NAM_RSL] = '\0'; /* Add the NUL terminator. */
  3374. return filenam;
  3375. } /* end function do_wild() */
  3376. #endif /* !SFX */
  3377. static ulg unix_to_vms[8]={ /* Map from UNIX rwx to VMS rwed */
  3378. /* Note that unix w bit is mapped to VMS wd bits */
  3379. /* no access */
  3380. XAB$M_NOREAD | XAB$M_NOWRITE | XAB$M_NODEL | XAB$M_NOEXE, /* --- */
  3381. XAB$M_NOREAD | XAB$M_NOWRITE | XAB$M_NODEL, /* --x */
  3382. XAB$M_NOREAD | XAB$M_NOEXE, /* -w- */
  3383. XAB$M_NOREAD, /* -wx */
  3384. XAB$M_NOWRITE | XAB$M_NODEL | XAB$M_NOEXE, /* r-- */
  3385. XAB$M_NOWRITE | XAB$M_NODEL, /* r-x */
  3386. XAB$M_NOEXE, /* rw- */
  3387. 0 /* rwx */
  3388. /* full access */
  3389. };
  3390. #define SETDFPROT /* We are using undocumented VMS System Service */
  3391. /* SYS$SETDFPROT here. If your version of VMS does */
  3392. /* not have that service, undef SETDFPROT. */
  3393. /* IM: Maybe it's better to put this to Makefile */
  3394. /* and DESCRIP.MMS */
  3395. #ifdef SETDFPROT
  3396. extern int sys$setdfprot();
  3397. #endif
  3398. int mapattr(__G)
  3399. __GDEF
  3400. {
  3401. ulg tmp = G.crec.external_file_attributes;
  3402. ulg theprot;
  3403. static ulg defprot = (ulg)-1L,
  3404. sysdef, owndef, grpdef, wlddef; /* Default protection fields */
  3405. /* IM: The only field of XABPRO we need to set here is */
  3406. /* file protection, so we need not to change type */
  3407. /* of G.pInfo->file_attr. WORD is quite enough. */
  3408. if ( defprot == (ulg)-1L )
  3409. {
  3410. /*
  3411. * First time here -- Get user default settings
  3412. */
  3413. #ifdef SETDFPROT /* Undef this if linker cat't resolve SYS$SETDFPROT */
  3414. defprot = (ulg)0L;
  3415. if ( !ERR(sys$setdfprot(0, &defprot)) )
  3416. {
  3417. sysdef = defprot & ( (1L<<XAB$S_SYS)-1 ) << XAB$V_SYS;
  3418. owndef = defprot & ( (1L<<XAB$S_OWN)-1 ) << XAB$V_OWN;
  3419. grpdef = defprot & ( (1L<<XAB$S_GRP)-1 ) << XAB$V_GRP;
  3420. wlddef = defprot & ( (1L<<XAB$S_WLD)-1 ) << XAB$V_WLD;
  3421. }
  3422. else
  3423. #endif /* SETDFPROT */
  3424. {
  3425. umask(defprot = umask(0));
  3426. defprot = ~defprot;
  3427. wlddef = unix_to_vms[defprot & 07] << XAB$V_WLD;
  3428. grpdef = unix_to_vms[(defprot>>3) & 07] << XAB$V_GRP;
  3429. owndef = unix_to_vms[(defprot>>6) & 07] << XAB$V_OWN;
  3430. sysdef = owndef >> (XAB$V_OWN - XAB$V_SYS);
  3431. defprot = sysdef | owndef | grpdef | wlddef;
  3432. }
  3433. }
  3434. switch (G.pInfo->hostnum) {
  3435. case AMIGA_:
  3436. tmp = (unsigned)(tmp>>16 & 0x0f); /* Amiga RWED bits */
  3437. G.pInfo->file_attr = (tmp << XAB$V_OWN) |
  3438. grpdef | sysdef | wlddef;
  3439. break;
  3440. case THEOS_:
  3441. tmp &= 0xF1FFFFFFL;
  3442. if ((tmp & 0xF0000000L) != 0x40000000L)
  3443. tmp &= 0x01FFFFFFL; /* not a dir, mask all ftype bits */
  3444. else
  3445. tmp &= 0x41FFFFFFL; /* leave directory bit as set */
  3446. /* fall through! */
  3447. case UNIX_:
  3448. case VMS_: /*IM: ??? Does VMS Zip store protection in UNIX format ?*/
  3449. /* GRR: Yup. Bad decision on my part... */
  3450. case ACORN_:
  3451. case ATARI_:
  3452. case ATHEOS_:
  3453. case BEOS_:
  3454. case QDOS_:
  3455. case TANDEM_:
  3456. {
  3457. int r = FALSE;
  3458. unsigned uxattr = (unsigned)(tmp >> 16); /* drwxrwxrwx */
  3459. if (uxattr == 0 && G.extra_field) {
  3460. /* Some (non-Info-ZIP) implementations of Zip for Unix and
  3461. * VMS (and probably others ??) leave 0 in the upper 16-bit
  3462. * part of the external_file_attributes field. Instead, they
  3463. * store file permission attributes in some e.f. block.
  3464. * As a work-around, we search for the presence of one of
  3465. * these extra fields and fall back to the MSDOS compatible
  3466. * part of external_file_attributes if one of the known
  3467. * e.f. types has been detected.
  3468. * Later, we might implement extraction of the permission
  3469. * bits from the VMS extra field. But for now, the work-around
  3470. * should be sufficient to provide "readable" extracted files.
  3471. * (For ASI Unix e.f., an experimental remap of the e.f.
  3472. * mode value IS already provided!)
  3473. */
  3474. ush ebID;
  3475. unsigned ebLen;
  3476. uch *ef = G.extra_field;
  3477. unsigned ef_len = G.crec.extra_field_length;
  3478. while (!r && ef_len >= EB_HEADSIZE) {
  3479. ebID = makeword(ef);
  3480. ebLen = (unsigned)makeword(ef+EB_LEN);
  3481. if (ebLen > (ef_len - EB_HEADSIZE))
  3482. /* discoverd some e.f. inconsistency! */
  3483. break;
  3484. switch (ebID) {
  3485. case EF_ASIUNIX:
  3486. if (ebLen >= (EB_ASI_MODE+2)) {
  3487. uxattr =
  3488. (unsigned)makeword(ef+(EB_HEADSIZE+EB_ASI_MODE));
  3489. /* force stop of loop: */
  3490. ef_len = (ebLen + EB_HEADSIZE);
  3491. break;
  3492. }
  3493. /* else: fall through! */
  3494. case EF_PKVMS:
  3495. /* "found nondecypherable e.f. with perm. attr" */
  3496. r = TRUE;
  3497. default:
  3498. break;
  3499. }
  3500. ef_len -= (ebLen + EB_HEADSIZE);
  3501. ef += (ebLen + EB_HEADSIZE);
  3502. }
  3503. }
  3504. if (!r) {
  3505. #ifdef SYMLINKS
  3506. /* Check if the file is a (POSIX-compatible) symbolic link.
  3507. * We restrict symlink support to those "made-by" hosts that
  3508. * are known to support symbolic links.
  3509. */
  3510. G.pInfo->symlink = S_ISLNK(uxattr) &&
  3511. SYMLINK_HOST(G.pInfo->hostnum);
  3512. #endif
  3513. theprot = (unix_to_vms[uxattr & 07] << XAB$V_WLD)
  3514. | (unix_to_vms[(uxattr>>3) & 07] << XAB$V_GRP)
  3515. | (unix_to_vms[(uxattr>>6) & 07] << XAB$V_OWN);
  3516. if ( uxattr & 0x4000 )
  3517. /* Directory -- set D bits */
  3518. theprot |= (XAB$M_NODEL << XAB$V_SYS)
  3519. | (XAB$M_NODEL << XAB$V_OWN)
  3520. | (XAB$M_NODEL << XAB$V_GRP)
  3521. | (XAB$M_NODEL << XAB$V_WLD);
  3522. G.pInfo->file_attr = theprot;
  3523. break;
  3524. }
  3525. }
  3526. /* fall through! */
  3527. /* all remaining cases: expand MSDOS read-only bit into write perms */
  3528. case FS_FAT_:
  3529. case FS_HPFS_:
  3530. case FS_NTFS_:
  3531. case MAC_:
  3532. case TOPS20_:
  3533. default:
  3534. theprot = defprot;
  3535. if ( tmp & 1 ) /* Test read-only bit */
  3536. { /* Bit is set -- set bits in all fields */
  3537. tmp = XAB$M_NOWRITE | XAB$M_NODEL;
  3538. theprot |= (tmp << XAB$V_SYS) | (tmp << XAB$V_OWN) |
  3539. (tmp << XAB$V_GRP) | (tmp << XAB$V_WLD);
  3540. }
  3541. G.pInfo->file_attr = theprot;
  3542. break;
  3543. } /* end switch (host-OS-created-by) */
  3544. return 0;
  3545. } /* end function mapattr() */
  3546. #define PATH_DEFAULT "SYS$DISK:[]"
  3547. /* dest_struct_level()
  3548. Returns file system structure level for argument, negative on
  3549. error.
  3550. */
  3551. int dest_struct_level(char *path)
  3552. {
  3553. int acp_code;
  3554. #ifdef DVI$C_ACP_F11V5
  3555. /* Should know about ODS5 file system. Do actual check.
  3556. (This should be non-VAX with __CRTL_VER >= 70200000.)
  3557. */
  3558. int sts;
  3559. struct FAB fab;
  3560. struct NAM_STRUCT nam;
  3561. char e_name[NAM_MAXRSS + 1];
  3562. struct dsc$descriptor_s dev_descr =
  3563. { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
  3564. fab = cc$rms_fab; /* Initialize FAB. */
  3565. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  3566. fab.FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  3567. #ifdef NAML$C_MAXRSS
  3568. fab.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  3569. fab.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  3570. #endif /* NAML$C_MAXRSS */
  3571. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNA = PATH_DEFAULT;
  3572. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNS = strlen(PATH_DEFAULT);
  3573. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNA = path;
  3574. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNS = strlen(path);
  3575. nam.NAM_ESA = e_name;
  3576. nam.NAM_ESS = sizeof(e_name) - 1;
  3577. nam.NAM_NOP = NAM_M_SYNCHK; /* Syntax-only analysis. */
  3578. sts = sys$parse(&fab);
  3579. if ((sts & STS$M_SUCCESS) == STS$K_SUCCESS)
  3580. {
  3581. /* Load resultant device name into device descriptor. */
  3582. dev_descr.dsc$a_pointer = nam.NAM_L_DEV;
  3583. dev_descr.dsc$w_length = nam.NAM_B_DEV;
  3584. /* Get filesystem type code.
  3585. (Text results for this item code have been unreliable.)
  3586. */
  3587. sts = lib$getdvi(&((int) DVI$_ACPTYPE),
  3588. 0,
  3589. &dev_descr,
  3590. &acp_code,
  3591. 0,
  3592. 0);
  3593. if ((sts & STS$M_SUCCESS) != STS$K_SUCCESS)
  3594. {
  3595. acp_code = -2;
  3596. }
  3597. }
  3598. else
  3599. {
  3600. acp_code = -1;
  3601. }
  3602. #else /* !DVI$C_ACP_F11V5 */
  3603. /* Too old for ODS5 file system. Return level 2. */
  3604. acp_code = DVI$C_ACP_F11V2;
  3605. #endif /* ?DVI$C_ACP_F11V5 */
  3606. return acp_code;
  3607. }
  3608. /* 2005-02-12 SMS.
  3609. Note that these name conversion functions do no length checking.
  3610. Buffer overflows are possible.
  3611. */
  3612. static void adj_dir_name_ods2(char *dest, char *src, int src_len)
  3613. {
  3614. /* The source string (src) typically extends beyond the directory
  3615. segment of interest, hence the confining src_len argument.
  3616. */
  3617. unsigned char uchr;
  3618. unsigned char prop;
  3619. char * src_last;
  3620. for (src_last = src + src_len; src < src_last; src++)
  3621. {
  3622. prop = char_prop[uchr = *src]; /* Get source char, properties. */
  3623. if ((prop & 2) != 0) /* Up-case lower case. */
  3624. {
  3625. uchr -= ('a' - 'A'); /* (Simple-fast is adequate.) */
  3626. }
  3627. else if ((prop & 1) == 0) /* Replace invalid char */
  3628. {
  3629. uchr = '_'; /* with "_". */
  3630. }
  3631. *dest++ = uchr; /* Store good char. */
  3632. }
  3633. *dest = '\0'; /* Terminate destination. */
  3634. }
  3635. static void adj_dir_name_ods5(char *dest, char *src, int src_len)
  3636. {
  3637. /* The source string (src) typically extends beyond the directory
  3638. segment of interest, hence the confining src_len argument.
  3639. */
  3640. unsigned char uchr;
  3641. unsigned char prop;
  3642. char * src_last;
  3643. for (src_last = src + src_len; src < src_last; src++)
  3644. {
  3645. prop = char_prop[uchr = *src]; /* Get source char, props. */
  3646. prop = char_prop[uchr]; /* Get source char props. */
  3647. if ((prop & (32+8+4)) != 0) /* Escape 1-char, including */
  3648. { /* SP and dot. */
  3649. *dest++ = '^'; /* Insert caret. */
  3650. if ((prop & 8) != 0) /* Replace SP with "_". */
  3651. {
  3652. uchr = '_';
  3653. }
  3654. else if (uchr == '?')
  3655. {
  3656. uchr = '/'; /* Replace "?" with "/". */
  3657. }
  3658. }
  3659. else if ((prop & 64) != 0) /* Escape hex-hex. */
  3660. {
  3661. *dest++ = '^'; /* Insert caret. */
  3662. *dest++ = hex_digit[uchr >> 4]; /* First hex digit. */
  3663. uchr = hex_digit[uchr & 15]; /* Second hex digit. */
  3664. }
  3665. else if ((prop & 16) == 0) /* Replace invalid with "_". */
  3666. {
  3667. uchr = '_';
  3668. }
  3669. *dest++ = uchr; /* Put good (or last) char. */
  3670. }
  3671. *dest = '\0'; /* Terminate destination. */
  3672. }
  3673. static void adj_file_name_ods2(char *dest, char *src)
  3674. {
  3675. unsigned char uchr;
  3676. unsigned char prop;
  3677. char *endp;
  3678. char *versionp;
  3679. char *last_dot;
  3680. endp = src + strlen(src); /* Pointer to the NUL-terminator of src. */
  3681. /* Starting at the end, find the last non-decimal-digit. */
  3682. versionp = endp;
  3683. while ((--versionp >= src) && isdigit(*versionp));
  3684. /* Left-most non-digit of a valid version is ";" (or perhaps "."). */
  3685. if ((*versionp != ';') && ((uO.Y_flag == 0) || (*versionp != '.')))
  3686. {
  3687. /* No valid version. The last dot is the last dot. */
  3688. versionp = endp;
  3689. }
  3690. else
  3691. { /* Some kind of valid version. */
  3692. if (!uO.V_flag) /* Not -V, so cut off version. */
  3693. {
  3694. *versionp = '\0';
  3695. }
  3696. else if (*versionp == '.')
  3697. {
  3698. *versionp = ';'; /* Replace version dot with ";". */
  3699. }
  3700. }
  3701. /* 2008-11-04 SMS.
  3702. * Simplified the scheme here to escape all non-last dots. This
  3703. * should work when Zip works correctly (Zip 3.1).
  3704. * Note that if no last dot is found, the non-last-dot test below
  3705. * will always fail, but that's not a problem.
  3706. */
  3707. /* Find the last dot (if any). */
  3708. last_dot = versionp;
  3709. while ((--last_dot >= src) && (*last_dot != '.'));
  3710. /* Critical features having been located, transform the name. */
  3711. while ((uchr = *src++) != '\0') /* Get source character. */
  3712. {
  3713. /* Note that "src" has been incremented, affecting "src <=". */
  3714. prop = char_prop[uchr]; /* Get source char properties. */
  3715. if ((prop & 2) != 0) /* Up-case lower case. */
  3716. {
  3717. uchr -= ('a' - 'A'); /* (Simple-fast is adequate.) */
  3718. }
  3719. else if ((prop & 4) != 0) /* Dot. */
  3720. {
  3721. if (src <= last_dot) /* Replace non-last dot */
  3722. {
  3723. uchr = '_'; /* with "_". */
  3724. }
  3725. }
  3726. else if ((prop & 1) == 0) /* Replace SP or invalid char, */
  3727. {
  3728. if (src <= versionp) /* if not in version, */
  3729. {
  3730. uchr = '_'; /* with "_". */
  3731. }
  3732. }
  3733. *dest++ = uchr; /* Store good char. */
  3734. }
  3735. *dest = '\0'; /* Terminate destination. */
  3736. }
  3737. static void adj_file_name_ods5(char *dest, char *src)
  3738. {
  3739. unsigned char uchr;
  3740. unsigned char prop;
  3741. char *endp;
  3742. char *versionp;
  3743. char *last_dot;
  3744. endp = src + strlen(src); /* Pointer to the NUL-terminator of src. */
  3745. /* Starting at the end, find the last non-decimal-digit. */
  3746. versionp = endp;
  3747. while ((--versionp >= src) && isdigit(*versionp));
  3748. /* Left-most non-digit of a valid version is ";" (or perhaps "."). */
  3749. if ((*versionp != ';') && ((uO.Y_flag == 0) || (*versionp != '.')))
  3750. {
  3751. /* No valid version. The last dot is the last dot. */
  3752. versionp = endp;
  3753. }
  3754. else
  3755. { /* Some kind of valid version. */
  3756. if (!uO.V_flag) /* Not -V, so cut off version. */
  3757. {
  3758. *versionp = '\0';
  3759. }
  3760. else if (*versionp == '.')
  3761. {
  3762. *versionp = ';'; /* Replace version dot with ";". */
  3763. }
  3764. }
  3765. /* 2008-11-04 SMS.
  3766. * Simplified the scheme here to escape all non-last dots. This
  3767. * should work when Zip works correctly (Zip 3.1).
  3768. * Note that if no last dot is found, the non-last-dot test below
  3769. * will always fail, but that's not a problem.
  3770. */
  3771. /* Find the last dot (if any). */
  3772. last_dot = versionp;
  3773. while ((--last_dot >= src) && (*last_dot != '.'));
  3774. /* Critical features having been located, transform the name. */
  3775. while ((uchr = *src++) != '\0') /* Get source character. */
  3776. {
  3777. /* Note that "src" has been incremented, affecting "src <=". */
  3778. prop = char_prop[uchr]; /* Get source char props. */
  3779. if ((prop & (32+8)) != 0) /* Escape 1-char, including */
  3780. { /* SP (but not dot). */
  3781. if (src <= versionp) /* No escapes for version. */
  3782. {
  3783. *dest++ = '^'; /* Insert caret. */
  3784. if ((prop & 8) != 0) /* Replace SP with "_". */
  3785. {
  3786. uchr = '_';
  3787. }
  3788. else if (uchr == '?')
  3789. {
  3790. uchr = '/'; /* Replace "?" with "/". */
  3791. }
  3792. }
  3793. }
  3794. else if ((prop & 4) != 0) /* Dot. */
  3795. {
  3796. if (src <= last_dot) /* Escape non-last dot */
  3797. {
  3798. *dest++ = '^'; /* Insert caret. */
  3799. }
  3800. }
  3801. else if ((prop & 64) != 0) /* Escape hex-hex. */
  3802. {
  3803. *dest++ = '^'; /* Insert caret. */
  3804. *dest++ = hex_digit[uchr >> 4]; /* First hex digit. */
  3805. uchr = hex_digit[uchr & 15]; /* Second hex digit. */
  3806. }
  3807. else if ((prop & 16) == 0) /* Replace invalid with "_". */
  3808. {
  3809. uchr = '_';
  3810. }
  3811. *dest++ = uchr; /* Put good (or last) char. */
  3812. }
  3813. *dest = '\0'; /* Terminate destination. */
  3814. }
  3815. # define FN_MASK 7
  3816. # define USE_DEFAULT (FN_MASK+1)
  3817. /*
  3818. * Checkdir function codes:
  3819. * ROOT - set root path from unzip qq d:[dir]
  3820. * INIT - get ready for "filename"
  3821. * APPEND_DIR - append pathcomp
  3822. * APPEND_NAME - append filename
  3823. * APPEND_NAME | USE_DEFAULT - expand filename using collected path
  3824. * GETPATH - return resulting filespec
  3825. * END - free dynamically allocated space prior to program exit
  3826. */
  3827. static int created_dir;
  3828. static int dest_file_sys_level;
  3829. static int ods2_names = -1;
  3830. int mapname(__G__ renamed)
  3831. /* returns: */
  3832. /* MPN_OK if no error, */
  3833. /* MPN_INF_TRUNC if caution (filename trunc), */
  3834. /* MPN_INF_SKIP if warning (skip file, dir doesn't exist), */
  3835. /* MPN_ERR_SKIP if error (skip file), */
  3836. /* MPN_CREATED_DIR if has created directory, */
  3837. /* MPN_VOL_LABEL if path was volume label (skip it) */
  3838. /* MPN_NOMEM if no memory (skip file) */
  3839. __GDEF
  3840. int renamed;
  3841. {
  3842. char pathcomp[FILNAMSIZ]; /* Path-component buffer. */
  3843. char *last_slash; /* Last slash in path. */
  3844. char *next_slash; /* Next slash in path. */
  3845. int dir_len; /* Length of a directory segment. */
  3846. char *cp = (char *)NULL; /* character pointer */
  3847. int killed_ddot = FALSE; /* Set when skipping "../" pathcomp. */
  3848. int error = MPN_OK;
  3849. if ( renamed )
  3850. {
  3851. if ( !(error = checkdir(__G__ pathcomp, APPEND_NAME | USE_DEFAULT)) )
  3852. strcpy(G.filename, pathcomp);
  3853. return error;
  3854. }
  3855. /*---------------------------------------------------------------------------
  3856. Initialize various pointers and counters and stuff.
  3857. ---------------------------------------------------------------------------*/
  3858. if (G.pInfo->vollabel)
  3859. return MPN_VOL_LABEL; /* can't set disk volume labels on VMS */
  3860. /* can create path as long as not just freshening, or if user told us */
  3861. G.create_dirs = !uO.fflag;
  3862. created_dir = FALSE; /* not yet */
  3863. /* If not yet known, determine the destination file system type
  3864. (ODS2 or ODS5). (If the user specified a destination, we should
  3865. already have this, so use the default destination.)
  3866. */
  3867. if (ods2_names < 0)
  3868. {
  3869. /* If user doesn't force ODS2, set flag according to destination. */
  3870. if (uO.ods2_flag == 0)
  3871. {
  3872. ods2_names =
  3873. (dest_struct_level(PATH_DEFAULT) <= DVI$C_ACP_F11V2);
  3874. }
  3875. else
  3876. {
  3877. ods2_names = 1; /* User demands ODS2 names. */
  3878. }
  3879. }
  3880. /* GRR: for VMS, convert to internal format now or later? or never? */
  3881. if (checkdir(__G__ pathcomp, INIT) == 10)
  3882. return MPN_NOMEM; /* Initialize path buffer, unless no memory. */
  3883. /* Locate and treat directory segments one at a time.
  3884. When pointer exceeds last_slash, then directory segments are
  3885. done, and only the name (with version?) remains.
  3886. */
  3887. *pathcomp = '\0'; /* Initialize translation buffer. */
  3888. last_slash = strrchr(G.filename, '/'); /* Find last slash. */
  3889. if (uO.jflag) /* If junking directories, */
  3890. cp = last_slash; /* start at (will be after) the last slash. */
  3891. if (cp == NULL) /* If no '/', or keeping directories, */
  3892. cp = G.filename; /* start at the front of the pathname. */
  3893. else /* Else, with directories to junk, */
  3894. ++cp; /* start after the last slash. */
  3895. /* Loop through the directory segments. */
  3896. while (cp < last_slash)
  3897. {
  3898. next_slash = strchr(cp, '/'); /* Find the next slash. */
  3899. dir_len = next_slash- cp;
  3900. /* Filter out unacceptable directories. */
  3901. if ((dir_len == 2) && (strncmp(cp, "..", 2) == 0))
  3902. { /* Double dot. */
  3903. if (!uO.ddotflag) /* Not allowed. Skip it. */
  3904. {
  3905. dir_len = 0;
  3906. killed_ddot = TRUE; /* Record skipping double-dot. */
  3907. }
  3908. }
  3909. else if ((dir_len == 1) && (strncmp(cp, ".", 1) == 0))
  3910. { /* Single dot. No-op. Skip it. */
  3911. dir_len = 0;
  3912. }
  3913. /* If non-null, acceptable directory, then process it. */
  3914. if (dir_len > 0)
  3915. {
  3916. if (ods2_names) /* Make directory name ODS2-compliant. */
  3917. {
  3918. adj_dir_name_ods2(pathcomp, cp, dir_len);
  3919. }
  3920. else /* Make directory name ODS5-compliant. */
  3921. {
  3922. adj_dir_name_ods5(pathcomp, cp, dir_len);
  3923. }
  3924. if (((error = checkdir(__G__ pathcomp, APPEND_DIR))
  3925. & MPN_MASK) > MPN_INF_TRUNC)
  3926. return error;
  3927. }
  3928. cp = next_slash+ 1; /* Continue at the next name segment. */
  3929. } /* end while loop */
  3930. /* Show warning when stripping insecure "parent dir" path components */
  3931. if (killed_ddot && QCOND2) {
  3932. Info(slide, 0, ((char *)slide,
  3933. "warning: skipped \"../\" path component(s) in %s\n",
  3934. FnFilter1(G.filename)));
  3935. if (!(error & ~MPN_MASK))
  3936. error = (error & MPN_MASK) | PK_WARN;
  3937. }
  3938. /* If there is one, adjust the name.type;version segment. */
  3939. if (strlen(cp) == 0)
  3940. {
  3941. /* Directory only, no file name. Create the directory, as needed.
  3942. Report directory creation to user.
  3943. */
  3944. checkdir(__G__ "", APPEND_NAME); /* create directory, if not found */
  3945. checkdir(__G__ G.filename, GETPATH);
  3946. if (created_dir) {
  3947. if (QCOND2) {
  3948. Info(slide, 0, ((char *)slide, " creating: %s\n",
  3949. FnFilter1(G.filename)));
  3950. }
  3951. /* set dir time (note trailing '/') */
  3952. return (error & ~MPN_MASK) | MPN_CREATED_DIR;
  3953. }
  3954. /* dir existed already; don't look for data to extract */
  3955. return (error & ~MPN_MASK) | MPN_INF_SKIP;
  3956. }
  3957. /* Process the file name. */
  3958. if (ods2_names) /* Make file name ODS2-compliant. */
  3959. {
  3960. adj_file_name_ods2(pathcomp, cp);
  3961. }
  3962. else /* Make file name ODS5-compliant. */
  3963. {
  3964. adj_file_name_ods5(pathcomp, cp);
  3965. }
  3966. checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
  3967. checkdir(__G__ G.filename, GETPATH);
  3968. return error;
  3969. } /* end function mapname() */
  3970. int checkdir(__G__ pathcomp, fcn)
  3971. /*
  3972. * returns:
  3973. * MPN_OK - no problem detected
  3974. * MPN_INF_TRUNC - (on APPEND_NAME) truncated filename
  3975. * MPN_INF_SKIP - path doesn't exist, not allowed to create
  3976. * MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path
  3977. * exists and is not a directory, but is supposed to be
  3978. * MPN_ERR_TOOLONG - path is too long
  3979. * MPN_NOMEM - can't allocate memory for filename buffers
  3980. */
  3981. __GDEF
  3982. char *pathcomp;
  3983. int fcn;
  3984. {
  3985. int function=fcn & FN_MASK;
  3986. static char pathbuf[FILNAMSIZ];
  3987. /* previously created directory (initialized to impossible dir. spec.) */
  3988. static char lastdir[FILNAMSIZ] = "\t";
  3989. static char *pathptr = pathbuf; /* For debugger */
  3990. static char *devptr, *dirptr;
  3991. static int devlen, dirlen;
  3992. static int root_dirlen;
  3993. static char *end;
  3994. static int first_comp, root_has_dir;
  3995. static int rootlen=0;
  3996. static char *rootend;
  3997. static int mkdir_failed=0;
  3998. int status;
  3999. struct FAB fab;
  4000. struct NAM_STRUCT nam;
  4001. /************
  4002. *** ROOT ***
  4003. ************/
  4004. #if (!defined(SFX) || defined(SFX_EXDIR))
  4005. if (function == ROOT)
  4006. { /* Assume VMS root spec */
  4007. /* 2006-01-20 SMS.
  4008. Changed to use sys$parse() instead of sys$filescan() for analysis
  4009. of the user-specified destination directory. Previously, various
  4010. values behaved badly, without complaint, e.g. "-d sys$scratch".
  4011. */
  4012. char *root_dest;
  4013. /* If the root path has already been set, return immediately. */
  4014. if (rootlen > 0)
  4015. return MPN_OK;
  4016. /* Initialization. */
  4017. root_dest = PATH_DEFAULT; /* Default destination for ODSx sensing. */
  4018. root_has_dir = 0; /* Root includes a directory. */
  4019. fab = cc$rms_fab; /* Initialize FAB. */
  4020. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  4021. fab.FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  4022. #ifdef NAML$C_MAXRSS
  4023. fab.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  4024. fab.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  4025. #endif /* NAML$C_MAXRSS */
  4026. /* Specified file spec. */
  4027. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNA = pathcomp;
  4028. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNS = strlen(pathcomp);
  4029. /* Default file spec. */
  4030. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNA = PATH_DEFAULT;
  4031. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNS = strlen(PATH_DEFAULT);
  4032. /* Expanded file spec. */
  4033. nam.NAM_ESA = pathbuf;
  4034. nam.NAM_ESS = NAM_MAXRSS;
  4035. status = sys$parse(&fab);
  4036. /* OK so far, if OK or if directory not found. */
  4037. if (((status & STS$M_SEVERITY) != STS$K_SUCCESS) &&
  4038. (status != RMS$_DNF))
  4039. {
  4040. /* Invalid destination directory specified. */
  4041. Info(slide, 1, ((char *)slide,
  4042. "Invalid destination directory (parse error): %s\n",
  4043. FnFilter1(pathcomp)));
  4044. return MPN_ERR_SKIP;
  4045. }
  4046. /* Should be only a device:[directory], so name+type+version
  4047. should have length 2 (".;").
  4048. */
  4049. if (nam.NAM_B_NAME + nam.NAM_B_TYPE + nam.NAM_B_VER > 2)
  4050. {
  4051. Info(slide, 1, ((char *)slide,
  4052. "Invalid destination directory (includes file name): %s\n",
  4053. FnFilter1(nam.NAM_ESA)));
  4054. return MPN_ERR_SKIP;
  4055. }
  4056. /* Truncate at name, leaving only "dev:[dir]". */
  4057. *nam.NAM_L_NAME = '\0';
  4058. rootlen = nam.NAM_L_NAME - nam.NAM_ESA;
  4059. /* Remove any trailing dots in directory. */
  4060. if ((nam.NAM_ESA[rootlen-1] == ']') &&
  4061. (nam.NAM_ESA[rootlen-2] != '^'))
  4062. {
  4063. root_has_dir = 1;
  4064. rootlen -= 2;
  4065. while ((nam.NAM_ESA[rootlen] == '.') &&
  4066. (nam.NAM_ESA[rootlen-1] != '^'))
  4067. {
  4068. rootlen--;
  4069. }
  4070. nam.NAM_ESA[++rootlen] = ']';
  4071. nam.NAM_ESA[++rootlen] = '\0';
  4072. }
  4073. devlen = nam.NAM_L_DIR - nam.NAM_ESA;
  4074. /* If directory not found, then create it. */
  4075. if (status == RMS$_DNF)
  4076. {
  4077. if (status = mkdir(nam.NAM_ESA, 0))
  4078. {
  4079. Info(slide, 1, ((char *)slide,
  4080. "Can not create destination directory: %s\n",
  4081. FnFilter1(nam.NAM_ESA)));
  4082. /* path didn't exist, tried to create, and failed. */
  4083. return MPN_ERR_SKIP;
  4084. }
  4085. }
  4086. /* Save the (valid) device:[directory] spec. */
  4087. strcpy(pathbuf, nam.NAM_ESA);
  4088. root_dest = pathbuf;
  4089. /* At this point, the true destination is known. If the user
  4090. supplied an invalid destination directory, the default
  4091. directory will be used. (This may be pointless, but should
  4092. be safe.)
  4093. */
  4094. /* If not yet known, determine the destination (root_dest) file
  4095. system type (ODS2 or ODS5).
  4096. */
  4097. if (ods2_names < 0)
  4098. {
  4099. /* If user doesn't force ODS2, set flag according to dest. */
  4100. if (uO.ods2_flag == 0)
  4101. {
  4102. ods2_names = (dest_struct_level(root_dest) <= DVI$C_ACP_F11V2);
  4103. }
  4104. else
  4105. {
  4106. ods2_names = 1; /* User demands ODS2 names. */
  4107. }
  4108. }
  4109. /* Replace trailing "]" with ".", for later appending. */
  4110. if ((pathbuf[rootlen-1] == ']') || (pathbuf[rootlen-1] == '>'))
  4111. {
  4112. pathbuf[rootlen-1] = '.';
  4113. }
  4114. /* Set various pointers and lengths. */
  4115. devptr = pathbuf;
  4116. dirptr = pathbuf + (nam.NAM_L_DIR - nam.NAM_ESA);
  4117. rootend = pathbuf + rootlen;
  4118. *(end = rootend) = '\0';
  4119. root_dirlen = dirlen = rootlen - devlen;
  4120. first_comp = !root_has_dir;
  4121. return MPN_OK;
  4122. }
  4123. #endif /* !SFX || SFX_EXDIR */
  4124. /************
  4125. *** INIT ***
  4126. ************/
  4127. if ( function == INIT )
  4128. {
  4129. if ( strlen(G.filename) + rootlen + 13 > NAM_MAXRSS )
  4130. return MPN_ERR_TOOLONG;
  4131. if ( rootlen == 0 ) /* No root given, reset everything. */
  4132. {
  4133. devptr = dirptr = rootend = pathbuf;
  4134. devlen = dirlen = 0;
  4135. }
  4136. end = rootend;
  4137. first_comp = !root_has_dir;
  4138. if ( dirlen = root_dirlen )
  4139. end[-1] = '.';
  4140. *end = '\0';
  4141. return MPN_OK;
  4142. }
  4143. /******************
  4144. *** APPEND_DIR ***
  4145. ******************/
  4146. if ( function == APPEND_DIR )
  4147. {
  4148. int cmplen;
  4149. cmplen = strlen(pathcomp);
  4150. if ( first_comp )
  4151. {
  4152. *end++ = '[';
  4153. if ( cmplen )
  4154. *end++ = '.'; /* "dir/..." --> "[.dir...]" */
  4155. /* else "/dir..." --> "[dir...]" */
  4156. first_comp = 0;
  4157. }
  4158. if ( cmplen == 1 && *pathcomp == '.' )
  4159. ; /* "..././..." -- ignore */
  4160. else if ( cmplen == 2 && pathcomp[0] == '.' && pathcomp[1] == '.' )
  4161. { /* ".../../..." -- convert to "...-..." */
  4162. *end++ = '-';
  4163. *end++ = '.';
  4164. }
  4165. else if ( cmplen + (end-pathptr) > NAM_MAXRSS )
  4166. return MPN_ERR_TOOLONG;
  4167. else
  4168. {
  4169. strcpy(end, pathcomp);
  4170. *(end+=cmplen) = '.';
  4171. ++end;
  4172. }
  4173. dirlen = end - dirptr;
  4174. *end = '\0';
  4175. return MPN_OK;
  4176. }
  4177. /*******************
  4178. *** APPEND_NAME ***
  4179. *******************/
  4180. if ( function == APPEND_NAME )
  4181. {
  4182. if ( fcn & USE_DEFAULT )
  4183. { /* Expand renamed filename using collected path, return
  4184. * at pathcomp */
  4185. fab = cc$rms_fab; /* Initialize FAB. */
  4186. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  4187. fab.FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  4188. #ifdef NAML$C_MAXRSS
  4189. fab.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  4190. fab.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  4191. #endif /* NAML$C_MAXRSS */
  4192. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNA = pathptr;
  4193. FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNS = end - pathptr;
  4194. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNA = G.filename;
  4195. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNS = strlen(G.filename);
  4196. nam.NAM_ESA = pathcomp; /* (Great design. ---v. SMS.) */
  4197. nam.NAM_ESS = NAM_MAXRSS; /* Assume large enough. */
  4198. if (!OK(status = sys$parse(&fab)) && status == RMS$_DNF )
  4199. /* Directory not found: */
  4200. { /* ... try to create it */
  4201. char save;
  4202. char *dirend;
  4203. int mkdir_failed;
  4204. dirend = (char*)nam.NAM_L_DIR + nam.NAM_B_DIR;
  4205. save = *dirend;
  4206. *dirend = '\0';
  4207. if ( (mkdir_failed = mkdir(nam.NAM_L_DEV, 0)) &&
  4208. errno == EEXIST )
  4209. mkdir_failed = 0;
  4210. *dirend = save;
  4211. if ( mkdir_failed )
  4212. return 3;
  4213. created_dir = TRUE;
  4214. } /* if (sys$parse... */
  4215. pathcomp[nam.NAM_ESL] = '\0';
  4216. return MPN_OK;
  4217. } /* if (USE_DEFAULT) */
  4218. else
  4219. {
  4220. *end = '\0';
  4221. if ( dirlen )
  4222. {
  4223. dirptr[dirlen-1] = ']'; /* Close directory */
  4224. /*
  4225. * Try to create the target directory.
  4226. * Don't waste time creating directory that was created
  4227. * last time.
  4228. */
  4229. if ( STRICMP(lastdir, pathbuf) )
  4230. {
  4231. mkdir_failed = 0;
  4232. if ( mkdir(pathbuf, 0) )
  4233. {
  4234. if ( errno != EEXIST )
  4235. mkdir_failed = 1; /* Mine for GETPATH */
  4236. }
  4237. else
  4238. created_dir = TRUE;
  4239. strcpy(lastdir, pathbuf);
  4240. }
  4241. }
  4242. else
  4243. { /*
  4244. * Target directory unspecified.
  4245. * Try to create "SYS$DISK:[]"
  4246. */
  4247. if ( strcmp(lastdir, PATH_DEFAULT) )
  4248. {
  4249. strcpy(lastdir, PATH_DEFAULT);
  4250. mkdir_failed = 0;
  4251. if ( mkdir(lastdir, 0) && errno != EEXIST )
  4252. mkdir_failed = 1; /* Mine for GETPATH */
  4253. }
  4254. }
  4255. if ( strlen(pathcomp) + (end-pathbuf) > 255 )
  4256. return MPN_INF_TRUNC;
  4257. strcpy(end, pathcomp);
  4258. end += strlen(pathcomp);
  4259. return MPN_OK;
  4260. }
  4261. }
  4262. /***************
  4263. *** GETPATH ***
  4264. ***************/
  4265. if ( function == GETPATH )
  4266. {
  4267. if ( mkdir_failed )
  4268. return MPN_ERR_SKIP;
  4269. *end = '\0'; /* To be safe */
  4270. strcpy( pathcomp, pathbuf );
  4271. return MPN_OK;
  4272. }
  4273. /***********
  4274. *** END ***
  4275. ***********/
  4276. if ( function == END )
  4277. {
  4278. Trace((stderr, "checkdir(): nothing to free...\n"));
  4279. rootlen = 0;
  4280. return MPN_OK;
  4281. }
  4282. return MPN_INVALID; /* should never reach */
  4283. }
  4284. int check_for_newer(__G__ filenam) /* return 1 if existing file newer or */
  4285. __GDEF /* equal; 0 if older; -1 if doesn't */
  4286. char *filenam; /* exist yet */
  4287. {
  4288. #ifdef USE_EF_UT_TIME
  4289. iztimes z_utime;
  4290. struct tm *t;
  4291. #endif
  4292. char *filenam_stat;
  4293. unsigned short timbuf[7];
  4294. unsigned dy, mo, yr, hh, mm, ss, dy2, mo2, yr2, hh2, mm2, ss2;
  4295. struct FAB fab;
  4296. struct XABDAT xdat;
  4297. #ifdef NAML$C_MAXRSS
  4298. struct NAM_STRUCT nam;
  4299. #endif
  4300. /* 2008-07-12 SMS.
  4301. * Special case for "." as a file name, not as the current directory.
  4302. * Substitute ".;" to keep stat() from seeing a plain ".".
  4303. */
  4304. if (strcmp(filenam, ".") == 0)
  4305. filenam_stat = ".;";
  4306. else
  4307. filenam_stat = filenam;
  4308. if (stat(filenam_stat, &G.statbuf))
  4309. return DOES_NOT_EXIST;
  4310. fab = cc$rms_fab; /* Initialize FAB. */
  4311. xdat = cc$rms_xabdat; /* Initialize XAB. */
  4312. #ifdef NAML$C_MAXRSS
  4313. nam = CC_RMS_NAM; /* Initialize NAM[L]. */
  4314. fab.FAB_NAM = &nam; /* Point FAB to NAM[L]. */
  4315. fab.fab$l_dna = (char *) -1; /* Using NAML for default name. */
  4316. fab.fab$l_fna = (char *) -1; /* Using NAML for file name. */
  4317. #endif /* NAML$C_MAXRSS */
  4318. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNA = filenam;
  4319. FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNS = strlen(filenam);
  4320. fab.fab$l_xab = (char *) &xdat;
  4321. fab.fab$l_fop = FAB$M_GET | FAB$M_UFO;
  4322. if (ERR(sys$open(&fab))) /* open failure: report exists and */
  4323. return EXISTS_AND_OLDER; /* older so new copy will be made */
  4324. sys$numtim(&timbuf, &xdat.xab$q_cdt);
  4325. fab.fab$l_xab = NULL;
  4326. sys$dassgn(fab.fab$l_stv);
  4327. sys$close(&fab); /* be sure file is closed and RMS knows about it */
  4328. #ifdef USE_EF_UT_TIME
  4329. if (G.extra_field &&
  4330. #ifdef IZ_CHECK_TZ
  4331. G.tz_is_valid &&
  4332. #endif
  4333. (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
  4334. G.lrec.last_mod_dos_datetime, &z_utime, NULL)
  4335. & EB_UT_FL_MTIME))
  4336. t = localtime(&(z_utime.mtime));
  4337. else
  4338. t = (struct tm *)NULL;
  4339. if (t != (struct tm *)NULL)
  4340. {
  4341. yr2 = (unsigned)(t->tm_year) + 1900;
  4342. mo2 = (unsigned)(t->tm_mon) + 1;
  4343. dy2 = (unsigned)(t->tm_mday);
  4344. hh2 = (unsigned)(t->tm_hour);
  4345. mm2 = (unsigned)(t->tm_min);
  4346. ss2 = (unsigned)(t->tm_sec);
  4347. /* round to nearest sec--may become 60,
  4348. but doesn't matter for compare */
  4349. ss = (unsigned)((float)timbuf[5] + (float)timbuf[6]*.01 + 0.5);
  4350. TTrace((stderr, "check_for_newer: using Unix extra field mtime\n"));
  4351. }
  4352. else
  4353. #endif /* USE_EF_UT_TIME */
  4354. {
  4355. yr2 = ((G.lrec.last_mod_dos_datetime >> 25) & 0x7f) + 1980;
  4356. mo2 = (G.lrec.last_mod_dos_datetime >> 21) & 0x0f;
  4357. dy2 = (G.lrec.last_mod_dos_datetime >> 16) & 0x1f;
  4358. hh2 = (G.lrec.last_mod_dos_datetime >> 11) & 0x1f;
  4359. mm2 = (G.lrec.last_mod_dos_datetime >> 5) & 0x3f;
  4360. ss2 = (G.lrec.last_mod_dos_datetime << 1) & 0x1f;
  4361. /* round to nearest 2 secs--may become 60,
  4362. but doesn't matter for compare */
  4363. ss = (unsigned)((float)timbuf[5] + (float)timbuf[6]*.01 + 1.) & (~1);
  4364. }
  4365. yr = timbuf[0];
  4366. mo = timbuf[1];
  4367. dy = timbuf[2];
  4368. hh = timbuf[3];
  4369. mm = timbuf[4];
  4370. if (yr > yr2)
  4371. return EXISTS_AND_NEWER;
  4372. else if (yr < yr2)
  4373. return EXISTS_AND_OLDER;
  4374. if (mo > mo2)
  4375. return EXISTS_AND_NEWER;
  4376. else if (mo < mo2)
  4377. return EXISTS_AND_OLDER;
  4378. if (dy > dy2)
  4379. return EXISTS_AND_NEWER;
  4380. else if (dy < dy2)
  4381. return EXISTS_AND_OLDER;
  4382. if (hh > hh2)
  4383. return EXISTS_AND_NEWER;
  4384. else if (hh < hh2)
  4385. return EXISTS_AND_OLDER;
  4386. if (mm > mm2)
  4387. return EXISTS_AND_NEWER;
  4388. else if (mm < mm2)
  4389. return EXISTS_AND_OLDER;
  4390. if (ss >= ss2)
  4391. return EXISTS_AND_NEWER;
  4392. return EXISTS_AND_OLDER;
  4393. }
  4394. #ifdef RETURN_CODES
  4395. void return_VMS(__G__ err)
  4396. __GDEF
  4397. #else
  4398. void return_VMS(err)
  4399. #endif
  4400. int err;
  4401. {
  4402. int severity;
  4403. #ifdef RETURN_CODES
  4404. /*---------------------------------------------------------------------------
  4405. Do our own, explicit processing of error codes and print message, since
  4406. VMS misinterprets return codes as rather obnoxious system errors ("access
  4407. violation," for example).
  4408. ---------------------------------------------------------------------------*/
  4409. switch (err) {
  4410. case PK_COOL:
  4411. break; /* life is fine... */
  4412. case PK_WARN:
  4413. Info(slide, 1, ((char *)slide, "\n\
  4414. [return-code %d: warning error \
  4415. (e.g., failed CRC or unknown compression method)]\n", err));
  4416. break;
  4417. case PK_ERR:
  4418. case PK_BADERR:
  4419. Info(slide, 1, ((char *)slide, "\n\
  4420. [return-code %d: error in zipfile \
  4421. (e.g., cannot find local file header sig)]\n", err));
  4422. break;
  4423. case PK_MEM:
  4424. case PK_MEM2:
  4425. case PK_MEM3:
  4426. case PK_MEM4:
  4427. case PK_MEM5:
  4428. Info(slide, 1, ((char *)slide,
  4429. "\n[return-code %d: insufficient memory]\n", err));
  4430. break;
  4431. case PK_NOZIP:
  4432. Info(slide, 1, ((char *)slide,
  4433. "\n[return-code %d: zipfile not found]\n", err));
  4434. break;
  4435. case PK_PARAM: /* exit(PK_PARAM); gives "access violation" */
  4436. Info(slide, 1, ((char *)slide, "\n\
  4437. [return-code %d: bad or illegal parameters specified on command line]\n",
  4438. err));
  4439. break;
  4440. case PK_FIND:
  4441. Info(slide, 1, ((char *)slide,
  4442. "\n[return-code %d: no files found to extract/view/etc.]\n",
  4443. err));
  4444. break;
  4445. case PK_DISK:
  4446. Info(slide, 1, ((char *)slide,
  4447. "\n[return-code %d: disk full or other I/O error]\n", err));
  4448. break;
  4449. case PK_EOF:
  4450. Info(slide, 1, ((char *)slide, "\n\
  4451. [return-code %d: unexpected EOF in zipfile (i.e., truncated)]\n", err));
  4452. break;
  4453. case IZ_CTRLC:
  4454. Info(slide, 1, ((char *)slide,
  4455. "\n[return-code %d: you hit ctrl-C to terminate]\n", err));
  4456. break;
  4457. case IZ_UNSUP:
  4458. Info(slide, 1, ((char *)slide, "\n\
  4459. [return-code %d: unsupported compression or encryption for all files]\n",
  4460. err));
  4461. break;
  4462. case IZ_BADPWD:
  4463. Info(slide, 1, ((char *)slide,
  4464. "\n[return-code %d: bad decryption password for all files]\n",
  4465. err));
  4466. break;
  4467. #ifdef DO_SAFECHECK_2GB
  4468. case IZ_ERRBF:
  4469. Info(slide, 1, ((char *)slide,
  4470. "\n[return-code %d: big-file archive, small-file program]\n",
  4471. err));
  4472. break;
  4473. #endif /* DO_SAFECHECK_2GB */
  4474. default:
  4475. Info(slide, 1, ((char *)slide,
  4476. "\n[return-code %d: unknown return-code (screw-up)]\n", err));
  4477. break;
  4478. }
  4479. #endif /* RETURN_CODES */
  4480. /*---------------------------------------------------------------------------
  4481. * Return an intelligent status/severity level:
  4482. *
  4483. * 2007-01-29 SMS.
  4484. *
  4485. * VMS Status Code Summary (See STSDEF.H for details.)
  4486. *
  4487. * Bits: 31:28 27:16 15:3 2 1 0
  4488. * Field: Control Facility Message Severity
  4489. * -----
  4490. * 0 0 0 0 Warning
  4491. * 0 0 1 1 Success
  4492. * 0 1 0 2 Error
  4493. * 0 1 1 3 Information
  4494. * 1 0 0 4 Severe (fatal) error
  4495. *
  4496. * In the Control field, bits 31:29 are reserved. Bit 28 inhibits
  4497. * printing the message. In the Facility field, bit 27 means
  4498. * customer-defined (not HP-assigned, like us). In the Message field,
  4499. * bit 15 means facility-specific (which our messages are).
  4500. *
  4501. * Note that the C library translates exit(0) to a $STATUS value of 1
  4502. * (i.e., exit is both silent and has a $SEVERITY of "success").
  4503. *
  4504. * Previous versions of Info-ZIP programs used a generic ("chosen (by
  4505. * experimentation)") Control+Facility code of 0x7FFF, which included
  4506. * some reserved control bits, the inhibit-printing bit, and the
  4507. * customer-defined bit.
  4508. *
  4509. * HP has now assigned official Facility names and corresponding
  4510. * Facility codes for the Info-ZIP products:
  4511. *
  4512. * Facility Name Facility Code
  4513. * IZ_UNZIP 1954 = 0x7A2
  4514. * IZ_ZIP 1955 = 0x7A3
  4515. *
  4516. * Now, unless the CTL_FAC_IZ_UZP macro is defined at build-time, we
  4517. * will use the official Facility code.
  4518. *
  4519. ---------------------------------------------------------------------------*/
  4520. /* Official HP-assigned Info-ZIP UnZip Facility code. */
  4521. #define FAC_IZ_UZP 1954 /* 0x7A2 */
  4522. #ifndef CTL_FAC_IZ_UZP
  4523. /*
  4524. * Default is inhibit-printing with the official Facility code.
  4525. */
  4526. # define CTL_FAC_IZ_UZP ((0x1 << 12) | FAC_IZ_UZP)
  4527. # define MSG_FAC_SPEC 0x8000 /* Facility-specific code. */
  4528. #else /* CTL_FAC_IZ_UZP */
  4529. /* Use the user-supplied Control+Facility code for err or warn. */
  4530. # ifndef MSG_FAC_SPEC /* Old default is not Facility-specific. */
  4531. # define MSG_FAC_SPEC 0x0 /* Facility-specific code. Or 0x8000. */
  4532. # endif /* !MSG_FAC_SPEC */
  4533. #endif /* ?CTL_FAC_IZ_ZIP */
  4534. #define VMS_UZ_FAC_BITS ((CTL_FAC_IZ_UZP << 16) | MSG_FAC_SPEC)
  4535. severity = (err == PK_WARN) ? 0 : /* warn */
  4536. (err == PK_ERR || /* error */
  4537. (err >= PK_NOZIP && err <= PK_FIND) || /* ... */
  4538. (err >= IZ_CTRLC && err <= IZ_BADPWD)) ? 2 : /* ... */
  4539. 4; /* fatal */
  4540. exit( /* $SEVERITY: */
  4541. (err == PK_COOL) ? SS$_NORMAL : /* success */
  4542. (VMS_UZ_FAC_BITS | (err << 4) | severity) /* warning, error, fatal */
  4543. );
  4544. } /* end function return_VMS() */
  4545. #ifdef MORE
  4546. static int scrnlines = -1;
  4547. static int scrncolumns = -1;
  4548. static int scrnwrap = -1;
  4549. static int getscreeninfo(int *tt_rows, int *tt_cols, int *tt_wrap)
  4550. {
  4551. /*
  4552. * For VMS v5.x:
  4553. * IO$_SENSEMODE/SETMODE info: Programming, Vol. 7A, System Programming,
  4554. * I/O User's: Part I, sec. 8.4.1.1, 8.4.3, 8.4.5, 8.6
  4555. * sys$assign(), sys$qio() info: Programming, Vol. 4B, System Services,
  4556. * System Services Reference Manual, pp. sys-23, sys-379
  4557. * fixed-length descriptor info: Programming, Vol. 3, System Services,
  4558. * Intro to System Routines, sec. 2.9.2
  4559. * GRR, 15 Aug 91 / SPC, 07 Aug 1995, 14 Nov 1999
  4560. */
  4561. #ifndef OUTDEVICE_NAME
  4562. #define OUTDEVICE_NAME "SYS$OUTPUT"
  4563. #endif
  4564. static ZCONST struct dsc$descriptor_s OutDevDesc =
  4565. {(sizeof(OUTDEVICE_NAME) - 1), DSC$K_DTYPE_T, DSC$K_CLASS_S,
  4566. OUTDEVICE_NAME};
  4567. /* {dsc$w_length, dsc$b_dtype, dsc$b_class, dsc$a_pointer}; */
  4568. short OutDevChan, iosb[4];
  4569. long status;
  4570. struct tt_characts
  4571. {
  4572. uch class, type;
  4573. ush pagewidth;
  4574. union {
  4575. struct {
  4576. uch ttcharsbits[3];
  4577. uch pagelength;
  4578. } ttdef_bits;
  4579. unsigned ttcharflags;
  4580. } ttdef_area;
  4581. } ttmode; /* total length = 8 bytes */
  4582. /* assign a channel to standard output */
  4583. status = sys$assign(&OutDevDesc, &OutDevChan, 0, 0);
  4584. if (OK(status))
  4585. {
  4586. /* use sys$qiow and the IO$_SENSEMODE function to determine
  4587. * the current tty status.
  4588. */
  4589. status = sys$qiow(0, OutDevChan, IO$_SENSEMODE, &iosb, 0, 0,
  4590. &ttmode, sizeof(ttmode), 0, 0, 0, 0);
  4591. /* deassign the output channel by way of clean-up */
  4592. (void) sys$dassgn(OutDevChan);
  4593. }
  4594. if ( OK(status) && OK(status = iosb[0]) ) {
  4595. if (tt_rows != NULL)
  4596. *tt_rows = ( (ttmode.ttdef_area.ttdef_bits.pagelength >= 5)
  4597. ? (int) (ttmode.ttdef_area.ttdef_bits.pagelength)
  4598. /* TT device value */
  4599. : (24) ); /* VT 100 default */
  4600. if (tt_cols != NULL)
  4601. *tt_cols = ( (ttmode.pagewidth >= 10)
  4602. ? (int) (ttmode.pagewidth) /* TT device value */
  4603. : (80) ); /* VT 100 default */
  4604. if (tt_wrap != NULL)
  4605. *tt_wrap = ((ttmode.ttdef_area.ttcharflags & TT$M_WRAP) != 0);
  4606. } else {
  4607. /* VT 100 defaults */
  4608. if (tt_rows != NULL)
  4609. *tt_rows = 24;
  4610. if (tt_cols != NULL)
  4611. *tt_cols = 80;
  4612. if (tt_wrap != NULL)
  4613. *tt_wrap = FALSE;
  4614. }
  4615. return (OK(status));
  4616. }
  4617. int screensize(int *tt_rows, int *tt_cols)
  4618. {
  4619. if (scrnlines < 0 || scrncolumns < 0)
  4620. getscreeninfo(&scrnlines, &scrncolumns, &scrnwrap);
  4621. if (tt_rows != NULL) *tt_rows = scrnlines;
  4622. if (tt_cols != NULL) *tt_cols = scrncolumns;
  4623. return !(scrnlines > 0 && scrncolumns > 0);
  4624. }
  4625. int screenlinewrap()
  4626. {
  4627. if (scrnwrap == -1)
  4628. getscreeninfo(&scrnlines, &scrncolumns, &scrnwrap);
  4629. return (scrnwrap);
  4630. }
  4631. #endif /* MORE */
  4632. #ifndef SFX
  4633. /************************/
  4634. /* Function version() */
  4635. /************************/
  4636. /* 2004-11-23 SMS.
  4637. * Changed to include the "-x" part of the VMS version.
  4638. * Added the IA64 system type name.
  4639. * Prepared for VMS versions after 9. (We should live so long.)
  4640. */
  4641. void version(__G)
  4642. __GDEF
  4643. {
  4644. int len;
  4645. #ifdef VMS_VERSION
  4646. char *chrp1;
  4647. char *chrp2;
  4648. char buf[40];
  4649. char vms_vers[16];
  4650. int ver_maj;
  4651. #endif
  4652. #ifdef __DECC_VER
  4653. char buf2[40];
  4654. int vtyp;
  4655. #endif
  4656. #ifdef VMS_VERSION
  4657. /* Truncate the version string at the first (trailing) space. */
  4658. strncpy(vms_vers, VMS_VERSION, sizeof(vms_vers));
  4659. vms_vers[sizeof(vms_vers)-1] = '\0';
  4660. chrp1 = strchr(vms_vers, ' ');
  4661. if (chrp1 != NULL)
  4662. *chrp1 = '\0';
  4663. /* Determine the major version number. */
  4664. ver_maj = 0;
  4665. chrp1 = strchr(&vms_vers[1], '.');
  4666. for (chrp2 = &vms_vers[1];
  4667. chrp2 < chrp1;
  4668. ver_maj = ver_maj * 10 + *(chrp2++) - '0');
  4669. #endif /* VMS_VERSION */
  4670. /* DEC C in ANSI mode does not like "#ifdef MACRO" inside another
  4671. macro when MACRO is equated to a value (by "#define MACRO 1"). */
  4672. len = sprintf((char *)slide, LoadFarString(CompiledWith),
  4673. #ifdef __GNUC__
  4674. "gcc ", __VERSION__,
  4675. #else
  4676. # if defined(DECC) || defined(__DECC) || defined (__DECC__)
  4677. "DEC C",
  4678. # ifdef __DECC_VER
  4679. (sprintf(buf2, " %c%d.%d-%03d",
  4680. ((vtyp = (__DECC_VER / 10000) % 10) == 6 ? 'T' :
  4681. (vtyp == 8 ? 'S' : 'V')),
  4682. __DECC_VER / 10000000,
  4683. (__DECC_VER % 10000000) / 100000, __DECC_VER % 1000), buf2),
  4684. # else
  4685. "",
  4686. # endif
  4687. # else
  4688. # ifdef VAXC
  4689. "VAX C", "",
  4690. # else
  4691. "unknown compiler", "",
  4692. # endif
  4693. # endif
  4694. #endif
  4695. #ifdef VMS_VERSION
  4696. # if defined(__alpha)
  4697. "OpenVMS",
  4698. (sprintf(buf, " (%s Alpha)", vms_vers), buf),
  4699. # elif defined(__ia64)
  4700. "OpenVMS",
  4701. (sprintf(buf, " (%s IA64)", vms_vers), buf),
  4702. # else /* VAX */
  4703. (ver_maj >= 6) ? "OpenVMS" : "VMS",
  4704. (sprintf(buf, " (%s VAX)", vms_vers), buf),
  4705. # endif
  4706. #else
  4707. "VMS",
  4708. "",
  4709. #endif /* ?VMS_VERSION */
  4710. #ifdef __DATE__
  4711. " on ", __DATE__
  4712. #else
  4713. "", ""
  4714. #endif
  4715. );
  4716. (*G.message)((zvoid *)&G, slide, (ulg)len, 0);
  4717. } /* end function version() */
  4718. #endif /* !SFX */
  4719. #ifdef __DECC
  4720. /* 2004-11-20 SMS.
  4721. *
  4722. * acc_cb(), access callback function for DEC C open().
  4723. *
  4724. * Set some RMS FAB/RAB items, with consideration of user-specified
  4725. * values from (DCL) SET RMS_DEFAULT. Items of particular interest are:
  4726. *
  4727. * fab$w_deq default extension quantity (blocks) (write).
  4728. * rab$b_mbc multi-block count.
  4729. * rab$b_mbf multi-buffer count (used with rah and wbh).
  4730. *
  4731. * See also the OPEN* macros in VMSCFG.H. Currently, no notice is
  4732. * taken of the caller-ID value, but options could be set differently
  4733. * for read versus write access. (I assume that specifying fab$w_deq,
  4734. * for example, for a read-only file has no ill effects.)
  4735. */
  4736. /* Global storage. */
  4737. int openr_id = OPENR_ID; /* Callback id storage, read. */
  4738. /* acc_cb() */
  4739. int acc_cb(int *id_arg, struct FAB *fab, struct RAB *rab)
  4740. {
  4741. int sts;
  4742. /* Get process RMS_DEFAULT values, if not already done. */
  4743. if (rms_defaults_known == 0)
  4744. {
  4745. get_rms_defaults();
  4746. }
  4747. /* If RMS_DEFAULT (and adjusted active) values are available, then set
  4748. * the FAB/RAB parameters. If RMS_DEFAULT values are not available,
  4749. * suffer with the default parameters.
  4750. */
  4751. if (rms_defaults_known > 0)
  4752. {
  4753. /* Set the FAB/RAB parameters accordingly. */
  4754. fab-> fab$w_deq = rms_ext_active;
  4755. rab-> rab$b_mbc = rms_mbc_active;
  4756. rab-> rab$b_mbf = rms_mbf_active;
  4757. /* Truncate at EOF on close, as we'll probably over-extend. */
  4758. fab-> fab$v_tef = 1;
  4759. /* If using multiple buffers, enable read-ahead and write-behind. */
  4760. if (rms_mbf_active > 1)
  4761. {
  4762. rab-> rab$v_rah = 1;
  4763. rab-> rab$v_wbh = 1;
  4764. }
  4765. if (DIAG_FLAG)
  4766. {
  4767. fprintf(stderr,
  4768. "Open callback. ID = %d, deq = %6d, mbc = %3d, mbf = %3d.\n",
  4769. *id_arg, fab-> fab$w_deq, rab-> rab$b_mbc, rab-> rab$b_mbf);
  4770. }
  4771. }
  4772. /* Declare success. */
  4773. return 0;
  4774. }
  4775. /*
  4776. * 2004-09-19 SMS.
  4777. *
  4778. *----------------------------------------------------------------------
  4779. *
  4780. * decc_init()
  4781. *
  4782. * On non-VAX systems, uses LIB$INITIALIZE to set a collection of C
  4783. * RTL features without using the DECC$* logical name method.
  4784. *
  4785. *----------------------------------------------------------------------
  4786. */
  4787. #ifdef __CRTL_VER
  4788. #if !defined(__VAX) && (__CRTL_VER >= 70301000)
  4789. #include <unixlib.h>
  4790. /*--------------------------------------------------------------------*/
  4791. /* Global storage. */
  4792. /* Flag to sense if decc_init() was called. */
  4793. static int decc_init_done = -1;
  4794. /*--------------------------------------------------------------------*/
  4795. /* decc_init()
  4796. Uses LIB$INITIALIZE to set a collection of C RTL features without
  4797. requiring the user to define the corresponding logical names.
  4798. */
  4799. /* Structure to hold a DECC$* feature name and its desired value. */
  4800. typedef struct
  4801. {
  4802. char *name;
  4803. int value;
  4804. } decc_feat_t;
  4805. /* Array of DECC$* feature names and their desired values. */
  4806. decc_feat_t decc_feat_array[] = {
  4807. /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
  4808. { "DECC$ARGV_PARSE_STYLE", 1 },
  4809. /* Preserve case for file names on ODS5 disks. */
  4810. { "DECC$EFS_CASE_PRESERVE", 1 },
  4811. /* Enable multiple dots (and most characters) in ODS5 file names,
  4812. while preserving VMS-ness of ";version". */
  4813. { "DECC$EFS_CHARSET", 1 },
  4814. /* List terminator. */
  4815. { (char *)NULL, 0 } };
  4816. /* LIB$INITIALIZE initialization function. */
  4817. static void decc_init(void)
  4818. {
  4819. int feat_index;
  4820. int feat_value;
  4821. int feat_value_max;
  4822. int feat_value_min;
  4823. int i;
  4824. int sts;
  4825. /* Set the global flag to indicate that LIB$INITIALIZE worked. */
  4826. decc_init_done = 1;
  4827. /* Loop through all items in the decc_feat_array[]. */
  4828. for (i = 0; decc_feat_array[i].name != NULL; i++)
  4829. {
  4830. /* Get the feature index. */
  4831. feat_index = decc$feature_get_index(decc_feat_array[i].name);
  4832. if (feat_index >= 0)
  4833. {
  4834. /* Valid item. Collect its properties. */
  4835. feat_value = decc$feature_get_value(feat_index, 1);
  4836. feat_value_min = decc$feature_get_value(feat_index, 2);
  4837. feat_value_max = decc$feature_get_value(feat_index, 3);
  4838. if ((decc_feat_array[i].value >= feat_value_min) &&
  4839. (decc_feat_array[i].value <= feat_value_max))
  4840. {
  4841. /* Valid value. Set it if necessary. */
  4842. if (feat_value != decc_feat_array[i].value)
  4843. {
  4844. sts = decc$feature_set_value(
  4845. feat_index,
  4846. 1,
  4847. decc_feat_array[i].value);
  4848. }
  4849. }
  4850. else
  4851. {
  4852. /* Invalid DECC feature value. */
  4853. printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n",
  4854. feat_value,
  4855. feat_value_min, decc_feat_array[i].name, feat_value_max);
  4856. }
  4857. }
  4858. else
  4859. {
  4860. /* Invalid DECC feature name. */
  4861. printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name);
  4862. }
  4863. }
  4864. }
  4865. /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
  4866. #pragma nostandard
  4867. /* Establish the LIB$INITIALIZE PSECT, with proper alignment and
  4868. attributes.
  4869. */
  4870. globaldef {"LIB$INITIALIZ"} readonly _align (LONGWORD)
  4871. int spare[8] = { 0 };
  4872. globaldef {"LIB$INITIALIZE"} readonly _align (LONGWORD)
  4873. void (*x_decc_init)() = decc_init;
  4874. /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
  4875. #pragma extern_model save
  4876. /* The declaration for LIB$INITIALIZE() is missing in the VMS system header
  4877. files. Addionally, the lowercase name "lib$initialize" is defined as a
  4878. macro, so that this system routine can be reference in code using the
  4879. traditional C-style lowercase convention of function names for readability.
  4880. (VMS system functions declared in the VMS system headers are defined in a
  4881. similar way to allow using lowercase names within the C code, whereas the
  4882. "externally" visible names in the created object files are uppercase.)
  4883. */
  4884. #ifndef lib$initialize
  4885. # define lib$initialize LIB$INITIALIZE
  4886. #endif
  4887. int lib$initialize(void);
  4888. #pragma extern_model strict_refdef
  4889. int dmy_lib$initialize = (int)lib$initialize;
  4890. #pragma extern_model restore
  4891. #pragma standard
  4892. #endif /* !defined(__VAX) && (__CRTL_VER >= 70301000) */
  4893. #endif /* __CRTL_VER */
  4894. #endif /* __DECC */
  4895. #endif /* VMS */