ckuus4.c 512 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915
  1. #include "ckcsym.h"
  2. /* C K U U S 4 -- "User Interface" for C-Kermit, part 4 */
  3. /*
  4. Authors:
  5. Frank da Cruz <fdc@columbia.edu>,
  6. The Kermit Project, New York City
  7. Jeffrey E Altman <jaltman@secure-endpoints.com>
  8. Secure Endpoints Inc., New York City
  9. Copyright (C) 1985, 2020,
  10. Trustees of Columbia University in the City of New York.
  11. All rights reserved. See the C-Kermit COPYING.TXT file or the
  12. copyright text in the ckcmai.c module for disclaimer and permissions.
  13. Last update:
  14. Fri Sep 18 14:54:00 2020
  15. */
  16. /*
  17. File ckuus4.c -- Functions moved from other ckuus*.c modules to even
  18. out their sizes.
  19. */
  20. #include "ckcdeb.h"
  21. #include "ckcasc.h"
  22. #include "ckcker.h"
  23. #include "ckcnet.h" /* Network symbols */
  24. #include "ckuusr.h"
  25. #include "ckuver.h"
  26. #include "ckcxla.h" /* Character sets */
  27. #ifdef HAVE_LOCALE
  28. #include <locale.h>
  29. #endif /* HAVE_LOCALE */
  30. #ifdef CK_AUTHENTICATION
  31. #include "ckuath.h"
  32. #endif /* CK_AUTHENTICATION */
  33. #ifdef CK_SSL
  34. #include "ck_ssl.h"
  35. #endif /* CK_SSL */
  36. #ifdef VMS
  37. #include <errno.h> /* For \v(errno) */
  38. extern char * ckvmserrstr(unsigned long);
  39. #ifndef OLD_VMS
  40. #include <lib$routines.h> /* Not for VAX C 2.4 */
  41. #else
  42. #include <libdef.h>
  43. #endif /* OLD_VMS */
  44. _PROTOTYP(int vmsttyfd, (void) );
  45. #endif /* VMS */
  46. #ifdef OS2
  47. #ifndef NT
  48. #define INCL_NOPM
  49. #define INCL_VIO /* Needed for ckocon.h */
  50. #include <os2.h>
  51. #undef COMMENT
  52. #else
  53. #include <windows.h>
  54. #include <tapi.h>
  55. #include "ckntap.h"
  56. #define APIRET ULONG
  57. #endif /* NT */
  58. #include "ckocon.h"
  59. #include "ckodir.h" /* [jt] 2013/11/21 - for MAXPATHLEN */
  60. #include "ckoetc.h"
  61. int StartedFromDialer = 0;
  62. HWND hwndDialer = 0;
  63. LONG KermitDialerID = 0;
  64. #ifdef putchar
  65. #undef putchar
  66. #endif /* putchar */
  67. #define putchar(x) conoc(x)
  68. #ifdef CK_PID
  69. #include <process.h>
  70. #endif /* CK_PID */
  71. #endif /* OS2 */
  72. #ifdef KUI
  73. extern struct keytab * term_font;
  74. extern int ntermfont, tt_font, tt_font_size;
  75. #endif /* KUI */
  76. extern xx_strp xxstring;
  77. #ifdef DEC_TCPIP
  78. #include <descrip>
  79. #include <dvidef>
  80. #include <dcdef>
  81. #endif /* DEC_TCPIP */
  82. #ifndef NOICP
  83. extern char *tfnam[];
  84. extern int tlevel;
  85. #endif /* NOICP */
  86. #ifdef FNFLOAT
  87. #include <math.h> /* Floating-point functions */
  88. #endif /* FNFLOAT */
  89. int fp_rounding = 0; /* Nonzero if printf("%f") rounds */
  90. int fp_digits = 0; /* Digits of floating point precision */
  91. extern int quiet, network, xitsta, escape, nopush, xferstat,
  92. exitonclose, tn_exit, ttnproto, autodl, flow, byteorder, what, lastxfer;
  93. extern int filepeek, nscanfile, makestrlen;
  94. extern char * k_info_dir;
  95. #ifndef MAC
  96. #ifndef AMIGA
  97. extern int ttyfd;
  98. #endif /* MAC */
  99. #endif /* AMIGA */
  100. #ifdef TNCODE
  101. extern int tn_nlm, tn_b_nlm, tn_b_xfer, tn_sb_bug;
  102. extern int tn_rem_echo;
  103. extern int tn_b_meu, tn_b_ume, tn_auth_krb5_des_bug;
  104. #endif /* TNCODE */
  105. static char * lastkwval = NULL;
  106. char * xferfile = NULL;
  107. int xferlog = 0;
  108. extern int local, xargc, stayflg, rcflag, bgset, backgrd, cfilef,
  109. inserver, srvcdmsg, success;
  110. #ifdef VMS
  111. extern int batch;
  112. #endif /* VMS */
  113. extern char cmdfil[], *versio, *ckxsys, **xargv;
  114. extern char lasttakeline[];
  115. #ifdef DEBUG
  116. extern char debfil[]; /* Debug log file name */
  117. extern int debtim;
  118. #endif /* DEBUG */
  119. extern int noinit;
  120. static char ndatbuf[10];
  121. char *months[] = {
  122. "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  123. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  124. };
  125. char *
  126. zzndate() { /* Returns today's date as yyyymmdd */
  127. char * p = NULL;
  128. int x;
  129. /* WARNING - This will fail if asctime() returns non-English month names */
  130. ztime(&p); /* Get "asctime" string */
  131. if (p == NULL || *p == NUL) return("");
  132. for (x = 20; x < 24; x++) /* yyyy */
  133. ndatbuf[x - 20] = p[x];
  134. ndatbuf[6] = (char) ((p[8] == ' ') ? '0' : p[8]);
  135. ndatbuf[7] = p[9]; /* dd */
  136. for (x = 0; x < 12; x++) /* mm */
  137. if (!strncmp(p+4,months[x],3)) break;
  138. if (x == 12) {
  139. ndatbuf[4] = ndatbuf[5] = '?';
  140. } else {
  141. x++;
  142. ndatbuf[4] = (char) ((x < 10) ? '0' : '1');
  143. ndatbuf[5] = (char) ((x % 10) + 48);
  144. }
  145. ndatbuf[8] = NUL;
  146. debug(F110,"zzndate return",ndatbuf,0);
  147. return((char *)ndatbuf);
  148. }
  149. #ifdef DCMDBUF
  150. extern struct cmdptr *cmdstk;
  151. extern char *line, *tmpbuf;
  152. #else
  153. extern struct cmdptr cmdstk[];
  154. extern char line[], tmpbuf[];
  155. #endif /* DCMDBUF */
  156. #ifdef OS2
  157. extern char exedir[];
  158. #else
  159. extern char * exedir;
  160. #endif /* OS2 */
  161. extern int nettype;
  162. #ifndef NOICP /* Most of this file... */
  163. #ifdef CKLOGDIAL
  164. extern char diafil[];
  165. #endif /* CKLOGDIAL */
  166. #ifndef AMIGA
  167. #ifndef MAC
  168. #include <signal.h>
  169. #endif /* MAC */
  170. #endif /* AMIGA */
  171. #ifdef SV68 /* July 2006 believe it or not */
  172. #ifndef SEEK_CUR
  173. #include <unistd.h>
  174. #endif /* SEEK_CUR */
  175. #endif /* SV68 */
  176. #ifdef SCO32 /* June 2011 believe it or not... */
  177. #ifdef XENIX
  178. #ifndef SEEK_CUR
  179. #include <unistd.h>
  180. #endif /* SEEK_CUR */
  181. #endif /* XENIX */
  182. #endif /* SCO32 */
  183. #ifdef STRATUS /* Stratus Computer, Inc. VOS */
  184. #ifdef putchar
  185. #undef putchar
  186. #endif /* putchar */
  187. #define putchar(x) conoc(x)
  188. #ifdef getchar
  189. #undef getchar
  190. #endif /* getchar */
  191. #define getchar(x) coninc(0)
  192. #endif /* STRATUS */
  193. #ifdef ANYX25
  194. extern int revcall, closgr, cudata;
  195. int x25ver;
  196. extern char udata[];
  197. #ifndef IBMX25
  198. extern int npadx3;
  199. extern CHAR padparms[];
  200. extern struct keytab padx3tab[];
  201. #endif /* !IBMX25 */
  202. #ifdef IBMX25
  203. /* global variables only available for IBM X.25 - possibly interesting for
  204. * other implementations
  205. */
  206. extern x25addr_t local_nua;
  207. extern x25addr_t remote_nua;
  208. #endif /* IBMX25 */
  209. #endif /* ANYX25 */
  210. #ifdef NETCONN
  211. #ifndef NODIAL
  212. extern int nnetdir;
  213. extern char *netdir[];
  214. #endif /* NODIAL */
  215. extern char ipaddr[];
  216. #ifdef CK_NETBIOS
  217. extern unsigned short netbiosAvail;
  218. extern unsigned long NetbeuiAPI;
  219. extern unsigned char NetBiosName[];
  220. extern unsigned char NetBiosAdapter;
  221. extern unsigned char NetBiosLSN;
  222. #endif /* CK_NETBIOS */
  223. #ifdef TCPSOCKET
  224. extern char myipaddr[];
  225. extern int tcp_rdns;
  226. #ifdef CK_DNS_SRV
  227. extern int tcp_dns_srv;
  228. #endif /* CK_DNS_SRV */
  229. extern char * tcp_address;
  230. #ifndef NOHTTP
  231. extern char * tcp_http_proxy;
  232. #endif /* NOHTTP */
  233. #ifdef NT
  234. #ifdef CK_SOCKS
  235. extern char * tcp_socks_svr;
  236. #ifdef CK_SOCKS_NS
  237. extern char * tcp_socks_ns;
  238. #endif /* CK_SOCKS_NS */
  239. #endif /* CK_SOCKS */
  240. #endif /* NT */
  241. #ifndef NOTCPOPTS
  242. #ifdef SOL_SOCKET
  243. #ifdef SO_LINGER
  244. extern int tcp_linger;
  245. extern int tcp_linger_tmo;
  246. #endif /* SO_LINGER */
  247. #ifdef SO_DONTROUTE
  248. extern int tcp_dontroute;
  249. #endif /* SO_DONTROUTE */
  250. #ifdef TCP_NODELAY
  251. extern int tcp_nodelay;
  252. #endif /* TCP_NODELAY */
  253. #ifdef SO_SNDBUF
  254. extern int tcp_sendbuf;
  255. #endif /* SO_SNDBUF */
  256. #ifdef SO_RCVBUF
  257. extern int tcp_recvbuf;
  258. #endif /* SO_RCVBUF */
  259. #ifdef SO_KEEPALIVE
  260. extern int tcp_keepalive;
  261. #endif /* SO_KEEPALIVE */
  262. #endif /* SOL_SOCKET */
  263. #endif /* NOTCPOPTS */
  264. #endif /* TCPSOCKET */
  265. #endif /* NETCONN */
  266. extern char * floname[];
  267. #ifndef NOSPL
  268. extern int vareval; /* Variable evaluation method */
  269. extern int fndiags; /* Function diagnostics on/off */
  270. extern int divbyzero;
  271. int itsapattern = 0;
  272. int isinbuflen = 0;
  273. int isjoin = 0;
  274. #ifdef CK_APC
  275. extern int apcactive; /* Nonzero = APC command was rec'd */
  276. extern int apcstatus; /* Are APC commands being processed? */
  277. #ifdef DCMDBUF
  278. extern char *apcbuf; /* APC command buffer */
  279. #else
  280. extern char apcbuf[];
  281. #endif /* DCMDBUF */
  282. #endif /* CK_APC */
  283. extern char evalbuf[]; /* EVALUATE result */
  284. extern char uidbuf[], pwbuf[], prmbuf[];
  285. _PROTOTYP( static char * fneval, (char *, char * [], int, char * ) );
  286. _PROTOTYP( static VOID myflsh, (void) );
  287. _PROTOTYP( static char * getip, (char *) );
  288. _PROTOTYP( int delta2sec, (char *, long *) );
  289. #ifdef NEWFTP
  290. _PROTOTYP( char * ftp_cpl_mode, (void) );
  291. _PROTOTYP( char * ftp_dpl_mode, (void) );
  292. _PROTOTYP( char * ftp_authtype, (void) );
  293. #endif /* NEWFTP */
  294. #ifndef NOHTTP
  295. _PROTOTYP( char * http_host, (void) );
  296. _PROTOTYP( int http_isconnected, (void) );
  297. _PROTOTYP( char * http_security, (void) );
  298. #endif /* NOHTTP */
  299. #ifndef NOSEXP
  300. _PROTOTYP( char * dosexp, (char *) );
  301. int fsexpflag = 0;
  302. #endif /* NOSEXP */
  303. static char hexdigits[16] = {
  304. '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  305. };
  306. extern char * tempdir;
  307. #ifdef CK_REXX
  308. extern char rexxbuf[];
  309. #endif /* CK_REXX */
  310. extern int tfline[];
  311. char *wkdays[] = {
  312. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  313. };
  314. #endif /* NOSPL */
  315. #ifdef OS2
  316. extern char startupdir[], inidir[];
  317. #else
  318. #ifdef VMSORUNIX
  319. extern char startupdir[];
  320. #endif /* VMSORUNIX */
  321. #endif /* OS2 */
  322. #ifdef OS2
  323. _PROTOTYP (int os2getcp, (void) );
  324. #ifdef TCPSOCKET
  325. extern char tcpname[];
  326. #endif /* TCPSOCKET */
  327. extern int tcp_avail;
  328. #ifdef DECNET
  329. extern int dnet_avail;
  330. #endif /* DECNET */
  331. #ifdef SUPERLAT
  332. extern int slat_avail;
  333. #endif /* SUPERLAT */
  334. #ifndef NOTERM
  335. extern int tt_type, max_tt;
  336. extern struct tt_info_rec tt_info[];
  337. #endif /* NOTERM */
  338. extern int tt_rows[], tt_cols[];
  339. #else /* OS2 */
  340. extern int tt_rows, tt_cols;
  341. #endif /* OS2 */
  342. #ifdef CK_TAPI
  343. extern int tttapi;
  344. extern int tapipass;
  345. extern struct keytab * tapilinetab;
  346. extern struct keytab * _tapilinetab;
  347. extern int ntapiline;
  348. #endif /* CK_TAPI */
  349. extern struct keytab colxtab[];
  350. extern int ncolx;
  351. extern char ttname[], *zinptr, *kermrc;
  352. extern char inidir[];
  353. extern int activecmd, remonly, cmd_rows, cmd_cols, parity, seslog,
  354. sessft, sosi, hwparity, tsecs, xargs, zincnt, tlevel, insilence, cmdmsk,
  355. timint, timef, inbufsize, dialog, binary, carrier, cdtimo, cmask, duplex,
  356. fmask, inecho, nmac, turnch, turn, kbchar;
  357. #ifndef NOXFER
  358. extern CHAR eol, mypadc, mystch, padch, seol, stchr, * epktmsg, feol;
  359. extern char *cksysid;
  360. extern struct ck_p ptab[];
  361. extern int
  362. protocol, prefixing, xfrbel, xfrcan, xfrint, xfrchr, xfrnum, pktpaus,
  363. lscapr, lscapu, xfermode, dest, slostart, maxrps, maxsps, maxtry, mypadn,
  364. npad, pkttim, bigrbsiz, bigsbsiz, keep, atcapr, autopar, bctr, bctu,
  365. crunched, ckdelay, ebq, ebqflg, pktlog, retrans, rpackets, rptflg, rptq,
  366. rtimo, spackets, spsiz, spsizf, spsizr, timeouts, fncact, fncnv, urpsiz,
  367. wmax, wslotn, wslotr, fdispla, spmax, fnrpath, fnspath, crc16;
  368. #endif /* NOXFER */
  369. #ifdef OS2
  370. extern int zxpn;
  371. extern int viewonly;
  372. #endif /* OS2 */
  373. #ifndef NOXFER
  374. #ifdef GFTIMER
  375. extern CKFLOAT fptsecs, fpxfsecs;
  376. #endif /* GFTIMER */
  377. extern long xfsecs, tfcps;
  378. #ifdef CK_TMPDIR
  379. extern char *dldir;
  380. #endif /* CK_TMPDIR */
  381. #endif /* NOXFER */
  382. #ifdef RECURSIVE
  383. extern int recursive;
  384. #endif /* RECURSIVE */
  385. #ifdef VMS
  386. extern int frecl;
  387. #endif /* VMS */
  388. extern CK_OFF_T ffc, tfc, tlci, tlco;
  389. extern long filcnt, rptn, speed, ccu, ccp, vernum, xvernum;
  390. #ifndef NOSPL
  391. extern char fspec[], myhost[];
  392. #endif /* NOSPL */
  393. extern char *tfnam[]; /* Command file names */
  394. extern char pktfil[], /* Packet log file name */
  395. #ifdef TLOG
  396. trafil[], /* Transaction log file name */
  397. #endif /* TLOG */
  398. sesfil[]; /* Session log file name */
  399. #ifndef NOXMIT /* TRANSMIT command variables */
  400. extern char xmitbuf[];
  401. extern int xmitf, xmitl, xmitx, xmits, xmitw, xmitt;
  402. #endif /* NOXMIT */
  403. extern int cmdlvl;
  404. #ifndef NOSPL
  405. /* Script programming language items */
  406. extern char **a_ptr[]; /* Arrays */
  407. extern int a_dim[];
  408. static char * inpmatch = NULL;
  409. #ifdef CKFLOAT
  410. char * inpscale = NULL;
  411. #endif /* CKFLOAT */
  412. extern char * inpbuf, inchar[]; /* Buffers for INPUT and REINPUT */
  413. extern char *inpbp; /* And pointer to same */
  414. static char *r3 = (char *)0;
  415. extern int incount; /* INPUT character count */
  416. extern int m_found; /* MINPUT result */
  417. extern int maclvl; /* Macro invocation level */
  418. extern struct mtab *mactab; /* Macro table */
  419. extern char *mrval[];
  420. extern int macargc[], topargc;
  421. #ifdef COMMENT
  422. extern char *m_line[];
  423. extern char *topline;
  424. #endif /* COMMENT */
  425. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  426. extern char *g_var[GVARS]; /* for external 2-dimensional arrays. */
  427. #ifdef DCMDBUF
  428. extern int *count, *inpcas;
  429. #else
  430. extern int count[], inpcas[];
  431. #endif /* DCMDBUF */
  432. #endif /* NOSPL */
  433. #ifdef UNIX
  434. extern int haslock; /* For UUCP locks */
  435. extern char flfnam[];
  436. #ifndef USETTYLOCK
  437. extern char lock2[];
  438. #endif /* USETTYLOCK */
  439. #endif /* UNIX */
  440. #ifdef OS2ORUNIX
  441. extern int maxnam, maxpath; /* Longest name, path length */
  442. #endif /* OS2ORUNIX */
  443. extern int mdmtyp, mdmsav;
  444. #ifndef NODIAL
  445. /* DIAL-related variables */
  446. extern char modemmsg[];
  447. extern MDMINF *modemp[]; /* Pointers to modem info structs */
  448. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialsrt, dialsta;
  449. extern int dialrtr, dialint, dialrstr, dialcon, dialcq, dialfld;
  450. extern int mdmspd, dialec, dialdc, dialmth, dialmauto, dialesc;
  451. extern char *dialnum, *dialini, *dialdir[], *dialcmd, *dialnpr,
  452. *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd, *diallac,
  453. *dialhwfc, *dialswfc, *dialnofc, *dialpulse, *dialtone, *dialname,
  454. *dialaaon, *dialaaoff, *dialmac;
  455. extern char *diallcc, *dialixp, *dialixs, *dialldp, *diallds,
  456. *dialpxi, *dialpxo, *dialsfx, *dialtfp;
  457. extern char *diallcp, *diallcs;
  458. extern int ntollfree, ndialpxx, nlocalac;
  459. extern char *dialtfc[], *diallcac[], *dialpxx[], *matchpxx;
  460. extern int ndialpucc, ndialtocc;
  461. extern char *dialtocc[], *dialpucc[];
  462. extern int ndialdir, dialcnf, dialcvt, dialidt, dialpace;
  463. extern long dialmax, dialcapas;
  464. extern struct keytab mdmtab[];
  465. #ifdef BIGBUFOK
  466. #define ARGBUFSIZ 8191
  467. #else
  468. #define ARGBUFSIZ 1023
  469. #endif /* BIGBUFOK */
  470. #ifdef BIGBUFOK
  471. extern char * dialmsg[];
  472. #endif /* BIGBUFOK */
  473. #endif /* NODIAL */
  474. #ifndef NOCSETS
  475. /* Translation stuff */
  476. extern int nfilc;
  477. extern struct keytab fcstab[];
  478. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  479. extern int dcset7, dcset8;
  480. extern struct keytab lngtab[];
  481. extern struct csinfo fcsinfo[], tcsinfo[];
  482. extern struct langinfo langs[];
  483. #ifdef CK_ANSIC
  484. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  485. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  486. #else
  487. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  488. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  489. #endif /* CK_ANSIC */
  490. #ifdef UNICODE
  491. extern int ucsbom, ucsorder;
  492. #endif /* UNICODE */
  493. #endif /* NOCSETS */
  494. #ifndef NOSPL
  495. /* Built-in variable names, maximum length VNAML (20 characters) */
  496. struct keytab vartab[] = {
  497. { "_line", VN_TFLN, CM_INV}, /* 192 */
  498. { "apcactive", VN_APC, CM_INV}, /* 192 */
  499. #ifdef NT
  500. { "appdata", VN_APPDATA, 0}, /* 201 */
  501. #endif /* NT */
  502. { "argc", VN_ARGC, 0},
  503. { "args", VN_ARGS, 0},
  504. { "authname", VN_AUTHN, 0}, /* 196 */
  505. { "authstate", VN_AUTHS, 0}, /* 195 */
  506. { "authtype", VN_AUTHT, 0}, /* 195 */
  507. { "bits", VN_BITS, 0}, /* 212 */
  508. { "blockcheck",VN_BLK, 0}, /* 195 */
  509. #ifdef BROWSER
  510. { "browser", VN_BROWSR,0}, /* 193 */
  511. { "browsopts", VN_BROPT, 0}, /* 193 */
  512. { "browsurl", VN_URL, 0}, /* 193 */
  513. { "buildid", VN_BUILD, 0}, /* 199 */
  514. #endif /* BROWSER */
  515. { "byteorder", VN_BYTE, 0}, /* 195 */
  516. #ifndef NOCSETS
  517. { "charset", VN_CSET, 0}, /* 192 */
  518. #endif /* NOCSETS */
  519. { "cmdbufsize",VN_CMDBL, 0}, /* 195 */
  520. { "cmdfile", VN_CMDF, 0},
  521. { "cmdlevel", VN_CMDL, 0},
  522. { "cmdsource", VN_CMDS, 0},
  523. { "cols", VN_COLS, 0}, /* 190 */
  524. #ifdef NT
  525. { "common", VN_COMMON, 0}, /* 201 */
  526. #endif /* NT */
  527. { "connection",VN_CONN, 0}, /* 190 */
  528. { "count", VN_COUN, 0},
  529. #ifndef NOXFER
  530. { "cps", VN_CPS, 0}, /* 190 */
  531. #endif /* NOXFER */
  532. { "cpu", VN_CPU, 0},
  533. #ifndef NOXFER
  534. { "crc16", VN_CRC16, 0}, /* 192 */
  535. { "ctty", VN_TTYNAM,0}, /* 196 */
  536. #endif /* NOXFER */
  537. #ifndef NOLOGDIAL
  538. #ifndef NOLOCAL
  539. { "cx_time", VN_CXTIME,0}, /* 195 */
  540. { "cx_status", VN_CX_STA,0}, /* 199 */
  541. #endif /* NOLOCAL */
  542. #endif /* NOLOGDIAL */
  543. #ifndef NODIAL
  544. { "d$ac", VN_D_AC, 0}, /* 192 */
  545. { "d$cc", VN_D_CC, 0}, /* 192 */
  546. { "d$ip", VN_D_IP, 0}, /* 192 */
  547. { "d$lc", VN_D_LCP, 0}, /* 193 */
  548. { "d$lcp", VN_D_LCP, CM_INV}, /* 193 */
  549. { "d$lp", VN_D_LP, 0}, /* 192 */
  550. { "d$px", VN_D_PXX, 0}, /* 195 */
  551. { "d$pxx", VN_D_PXX, CM_INV}, /* 195 */
  552. #endif /* NODIAL */
  553. { "date", VN_DATE, 0},
  554. { "day", VN_DAY, 0},
  555. #ifdef NT
  556. { "desktop", VN_DESKTOP, 0}, /* 201 */
  557. #endif /* NT */
  558. #ifndef NODIAL
  559. { "dialcount", VN_DRTR, 0}, /* 195 */
  560. { "dialmessage",VN_DMSG, 0}, /* 212 */
  561. { "dialnumber",VN_DNUM, 0}, /* 192 */
  562. { "dialresult",VN_MDMSG, 0}, /* 192 */
  563. { "dialstatus",VN_DIAL, 0}, /* 190 */
  564. { "dialsuffix",VN_PDSFX, 0}, /* 193 */
  565. { "dialtype", VN_DTYPE, 0}, /* 193 */
  566. #endif /* NODIAL */
  567. { "directory", VN_DIRE, 0},
  568. #ifndef NODIAL
  569. { "dm_hf", VN_DM_HF, 0}, /* 199 */
  570. { "dm_lp", VN_DM_LP, 0}, /* 195 */
  571. { "dm_sp", VN_DM_SP, 0}, /* 195 */
  572. { "dm_pd", VN_DM_PD, 0}, /* 195 */
  573. { "dm_td", VN_DM_TD, 0}, /* 195 */
  574. { "dm_wa", VN_DM_WA, 0}, /* 195 */
  575. { "dm_wb", VN_DM_WB, 0}, /* 199 */
  576. { "dm_wd", VN_DM_WD, 0}, /* 195 */
  577. { "dm_rc", VN_DM_RC, 0}, /* 195 */
  578. #endif /* NODIAL */
  579. #ifndef NOXFER
  580. { "download", VN_DLDIR, 0}, /* 192 */
  581. #endif /* NOXFER */
  582. { "editor", VN_EDITOR,0},
  583. { "editfile", VN_EDFILE,0},
  584. { "editopts", VN_EDOPT, 0},
  585. { "errno", VN_ERRNO, 0}, /* 192 */
  586. { "errstring", VN_ERSTR, 0}, /* 192 */
  587. { "escape", VN_ESC, 0}, /* 193 */
  588. { "evaluate", VN_EVAL, 0}, /* 190 */
  589. #ifdef OS2ORUNIX
  590. { "exedir", VN_EXEDIR,0}, /* 192 */
  591. #endif /* OS2ORUNIX */
  592. { "exitstatus",VN_EXIT, 0},
  593. #ifdef CKCHANNELIO
  594. { "f_count", VN_FCOU, 0}, /* 195 */
  595. { "f_error", VN_FERR, 0}, /* 195 */
  596. { "f_max", VN_FMAX, 0}, /* 195 */
  597. { "fileerror", VN_FERR, CM_INV}, /* 195 */
  598. { "filemax", VN_FERR, CM_INV}, /* 195 */
  599. #endif /* CKCHANNELIO */
  600. { "filename", VN_FNAM, 0}, /* 193 */
  601. { "filenumber",VN_FNUM, 0}, /* 193 */
  602. { "filespec", VN_FILE, 0},
  603. { "fsize", VN_FFC, 0}, /* 190 */
  604. #ifdef GFTIMER
  605. { "ftime", VN_FTIME, 0}, /* 199 */
  606. #else
  607. { "ftime", VN_NTIM, CM_INV},
  608. #endif /* GFTIMER */
  609. #ifndef NOFTP
  610. #ifndef SYSFTP
  611. { "ftp_code", VN_FTP_C, 0}, /* 199 */
  612. { "ftp_cpl", VN_FTP_B, 0}, /* 199 */
  613. { "ftp_connected", VN_FTP_X, 0}, /* 199 */
  614. { "ftp_dpl", VN_FTP_D, 0}, /* 199 */
  615. { "ftp_getputremote", VN_FTP_G, 0}, /* 199 */
  616. { "ftp_host", VN_FTP_H, 0}, /* 199 */
  617. { "ftp_loggedin", VN_FTP_L, 0}, /* 199 */
  618. { "ftp_message", VN_FTP_M, 0}, /* 199 */
  619. { "ftp_msg", VN_FTP_M, CM_INV}, /* 199 */
  620. { "ftp_security", VN_FTP_Z, 0}, /* 199 */
  621. { "ftp_server", VN_FTP_S, 0}, /* 199 */
  622. #endif /* SYSFTP */
  623. #endif /* NOFTP */
  624. { "ftype", VN_MODE, 0}, /* 190 */
  625. #ifdef KUI
  626. { "gui_fontname", VN_GUI_FNM, 0}, /* 205 */
  627. { "gui_fontsize", VN_GUI_FSZ, 0}, /* 205 */
  628. { "gui_runmode", VN_GUI_RUN, 0}, /* 205 */
  629. { "gui_xpos", VN_GUI_XP, 0}, /* 205 */
  630. { "gui_xres", VN_GUI_XR, 0}, /* 205 */
  631. { "gui_ypos", VN_GUI_YP, 0}, /* 205 */
  632. { "gui_yres", VN_GUI_YR, 0}, /* 205 */
  633. #endif /* KUI */
  634. { "herald", VN_HERALD, 0},
  635. { "home", VN_HOME, 0},
  636. { "host", VN_HOST, 0},
  637. { "hour", VN_HOUR, 0}, /* 200 */
  638. #ifndef NOHTTP
  639. { "http_code", VN_HTTP_C, 0}, /* 199 */
  640. { "http_connected", VN_HTTP_N, 0}, /* 199 */
  641. { "http_host", VN_HTTP_H, 0}, /* 199 */
  642. { "http_message", VN_HTTP_M, 0}, /* 199 */
  643. { "http_security", VN_HTTP_S, 0}, /* 199 */
  644. #endif /* NOHTTP */
  645. { "hwparity", VN_HWPAR, 0}, /* 195 */
  646. { "input", VN_IBUF, 0},
  647. { "inchar", VN_ICHR, 0},
  648. { "incount", VN_ICNT, 0},
  649. { "inidir", VN_INI, 0}, /* 192 */
  650. { "inmatch", VN_MATCH, 0}, /* 196 */
  651. { "inmessage", VN_INPMSG,0}, /* 212 */
  652. { "inscale", VN_ISCALE,0}, /* 210 */
  653. { "instatus", VN_ISTAT, 0}, /* 192 */
  654. { "intime", VN_INTIME,0}, /* 193 */
  655. { "inwait", VN_INTMO, 0}, /* 195 */
  656. { "ip", VN_IPADDR, CM_ABR|CM_INV},
  657. { "ipaddress", VN_IPADDR,0}, /* 192 */
  658. { "iprompt", VN_PROMPT,0}, /* 199 */
  659. { "kbchar", VN_KBCHAR,0}, /* 196 */
  660. #ifndef NOLOCAL
  661. #ifdef OS2
  662. { "keyboard", VN_KEYB, 0},
  663. #endif /* OS2 */
  664. #endif /* NOLOCAL */
  665. #ifdef CK_KERBEROS
  666. { "krb4errmsg", VN_K4EMSG,0},
  667. { "krb4errno", VN_K4ENO, 0},
  668. { "krb4principal", VN_K4PRN, 0},
  669. { "krb4realm", VN_K4RLM, 0},
  670. { "krb4service", VN_K4SRV, 0},
  671. { "krb5cc", VN_K5CC, 0},
  672. { "krb5errmsg", VN_K5EMSG,0},
  673. { "krb5errno", VN_K5ENO, 0},
  674. { "krb5principal", VN_K5PRN, 0},
  675. { "krb5realm", VN_K5RLM, 0},
  676. { "krb5service", VN_K5SRV, 0},
  677. #endif /* CK_KERBEROS */
  678. { "lastcommand", VN_PREVCMD, 0}, /* 299 */
  679. #ifndef NOLASTFILE
  680. { "lastfilespec", VN_LASTFIL, 0}, /* 212 */
  681. #endif /* NOLASTFILE */
  682. { "lastkeywordvalue", VN_LASTKWV, 0}, /* 212 */
  683. { "lastkwvalue", VN_LASTKWV, CM_ABR|CM_INV}, /* 212 */
  684. { "line", VN_LINE, 0},
  685. { "local", VN_LCL, 0},
  686. #ifdef UNIX
  687. { "lockdir", VN_LCKDIR,0}, /* 195 */
  688. { "lockpid", VN_LCKPID,0}, /* 195 */
  689. #endif /* UNIX */
  690. { "log_connection", VN_LOG_CON, 0}, /* 206 */
  691. { "log_debug", VN_LOG_DEB, 0}, /* 206 */
  692. { "log_packet", VN_LOG_PKT, 0}, /* 206 */
  693. { "log_session", VN_LOG_SES, 0}, /* 206 */
  694. { "log_transaction", VN_LOG_TRA, 0},/* 206 */
  695. { "maclevel", VN_MACLVL,0}, /* 195 */
  696. { "macro", VN_MAC, 0},
  697. #ifdef FNFLOAT
  698. { "math_e", VN_MA_E, 0}, /* 195 */
  699. { "math_pi", VN_MA_PI, 0}, /* 195 */
  700. { "math_precision", VN_MA_PR, 0}, /* 195 */
  701. #endif /* FNFLOAT */
  702. { "minput", VN_MINP, 0}, /* 192 */
  703. { "model", VN_MODL, 0}, /* 193 */
  704. { "modem", VN_MDM, 0},
  705. { "month", VN_MONTH, 0}, /* 304 */
  706. #ifndef NOLOCAL
  707. #ifdef OS2
  708. { "mousecurx", VN_MOU_X, 0}, /* K95 1.1.14 */
  709. { "mousecury", VN_MOU_Y, 0}, /* K95 1.1.14 */
  710. #endif /* OS2 */
  711. #endif /* NOLOCAL */
  712. #ifndef NODIAL
  713. { "m_aa_off", VN_M_AAX, 0}, /* all 192... */
  714. { "m_aa_on", VN_M_AAO, 0},
  715. { "m_dc_off", VN_M_DCX, 0},
  716. { "m_dc_on", VN_M_DCO, 0},
  717. { "m_dial", VN_M_DCM, 0},
  718. { "m_ec_off", VN_M_ECX, 0},
  719. { "m_ec_on", VN_M_ECO, 0},
  720. { "m_fc_hw", VN_M_HWF, 0},
  721. { "m_fc_no", VN_M_NFC, 0},
  722. { "m_fc_sw", VN_M_SWF, 0},
  723. { "m_hup", VN_M_HUP, 0},
  724. { "m_init", VN_M_INI, 0},
  725. { "m_name", VN_M_NAM, 0}, /* 195 */
  726. { "m_pulse", VN_M_PDM, 0},
  727. { "m_sig_cd", VN_MS_CD, 0}, /* 195 */
  728. { "m_sig_cts", VN_MS_CTS,0}, /* 195 */
  729. { "m_sig_dsr", VN_MS_DSR,0}, /* 195 */
  730. { "m_sig_dtr", VN_MS_DTR,0}, /* 195 */
  731. { "m_sig_ri", VN_MS_RI, 0}, /* 195 */
  732. { "m_sig_rts", VN_MS_RTS,0}, /* 195 */
  733. { "m_tone", VN_M_TDM, 0},
  734. #endif /* NODIAL */
  735. { "name", VN_NAME, 0},
  736. { "ndate", VN_NDAT, 0},
  737. { "nday", VN_NDAY, 0},
  738. { "newline", VN_NEWL, 0},
  739. { "nmonth", VN_NMONTH,0}, /* 304 */
  740. { "ntime", VN_NTIM, 0},
  741. { "osname", VN_OSNAM, 0}, /* 193 */
  742. { "osrelease", VN_OSREL, 0}, /* 193 */
  743. { "osversion", VN_OSVER, 0}, /* 193 */
  744. #ifndef NOXFER
  745. { "packetlen", VN_RPSIZ, 0}, /* 192 */
  746. #endif /* NOXFER */
  747. { "parity", VN_PRTY, 0}, /* 190 */
  748. { "password", VN_PWD, CM_INV}, /* 192 */
  749. #ifdef NT
  750. { "personal", VN_PERSONAL, 0}, /* 201 */
  751. #endif /* NT */
  752. #ifdef PEXITSTAT
  753. { "pexitstat", VN_PEXIT, 0}, /* 193 */
  754. #endif /* PEXITSTAT */
  755. #ifdef CK_PID
  756. { "pid", VN_PID, 0}, /* 193 */
  757. #endif /* CK_PID */
  758. { "platform", VN_SYSV, 0},
  759. { "printer", VN_PRINT, 0}, /* 193 */
  760. { "program", VN_PROG, 0},
  761. { "prompt", VN_PRM, CM_INV}, /* 192 */
  762. #ifndef NOXFER
  763. { "protocol", VN_PROTO, 0}, /* 192 */
  764. { "p_8bit", VN_P_8BIT,0}, /* 193 */
  765. { "p_ctl", VN_P_CTL, 0}, /* 193 */
  766. { "p_rpt", VN_P_RPT, 0}, /* 193 */
  767. { "query", VN_QUE, 0}, /* 190 */
  768. #endif /* NOXFER */
  769. { "remoteip", VN_HOSTIP,0}, /* 212 */
  770. { "return", VN_RET, 0},
  771. #ifdef CK_REXX
  772. { "rexx", VN_REXX, 0}, /* 190 */
  773. #endif /* CK_REXX */
  774. #ifdef TN_COMPORT
  775. { "rfc2217_signature", VN_TNC_SIG, 0}, /* 201 */
  776. { "rfc2717_signature", VN_TNC_SIG, CM_INV}, /* 202 */
  777. #endif /* TN_COMPORT */
  778. { "rows", VN_ROWS, 0}, /* 190 */
  779. #ifndef NOSEXP
  780. { "sdepth", VN_LSEXP,0}, /* 199 */
  781. #endif /* NOSEXP */
  782. { "secure", VN_SECURE, 0}, /* 199 */
  783. #ifndef NOLOCAL
  784. #ifdef OS2
  785. { "select", VN_SELCT, 0}, /* 192 */
  786. #endif /* OS2 */
  787. #endif /* NOLOCAL */
  788. { "sendlist", VN_SNDL, 0},
  789. { "serial", VN_SERIAL,0}, /* 195 */
  790. { "setlinemsg",VN_SLMSG, 0}, /* 195 */
  791. #ifndef NOSEXP
  792. { "sexpression",VN_SEXP, 0}, /* 199 */
  793. #endif /* NOSEXP */
  794. { "speed", VN_SPEE, 0},
  795. #ifdef OS2
  796. { "space", VN_SPA, 0},
  797. { "startup", VN_STAR, 0}, /* 190 */
  798. #else
  799. #ifdef UNIX
  800. { "startup", VN_STAR, 0}, /* 193 */
  801. #else
  802. #ifdef VMS
  803. { "startup", VN_STAR, 0}, /* 193 */
  804. #endif /* VMS */
  805. #endif /* UNIX */
  806. #endif /* OS2 */
  807. { "status", VN_SUCC, 0},
  808. #ifndef NOSEXP
  809. { "svalue", VN_VSEXP, 0}, /* 199 */
  810. #endif /* NOSEXP */
  811. #ifndef NOXFER
  812. { "sysid", VN_SYSI, 0},
  813. #endif /* NOXFER */
  814. { "system", VN_SYST, 0},
  815. { "terminal", VN_TTYP, 0},
  816. #ifdef OS2
  817. #ifndef NOKVERBS
  818. { "termkey", VN_TRMK, CM_INV}, /* 192 */
  819. #endif /* NOKVERBS */
  820. #endif /* OS2 */
  821. { "test", VN_TEST, 0}, /* 193 */
  822. { "textdir", VN_TXTDIR,0}, /* 195 */
  823. #ifndef NOXFER
  824. { "tfsize", VN_TFC, 0},
  825. { "tftime", VN_TFTIM, 0}, /* 195 */
  826. #endif /* NOXFER */
  827. { "time", VN_TIME, 0},
  828. { "timestamp", VN_NOW, 0}, /* 200 */
  829. { "tmpdir", VN_TEMP, 0}, /* 192 */
  830. #ifdef CK_TRIGGER
  831. { "trigger", VN_TRIG, 0}, /* 193 */
  832. #endif /* CK_TRIGGER */
  833. #ifdef CK_TTYFD
  834. { "ttyfd", VN_TTYF, 0},
  835. #endif /* CK_TTYFD */
  836. { "ty_ln", VN_TY_LN, 0}, /* 195 */
  837. { "ty_lc", VN_TY_LC, 0}, /* 195 */
  838. { "ty_lm", VN_TY_LM, 0}, /* 195 */
  839. #ifdef BROWSER
  840. { "url", VN_URL, CM_INV}, /* 193 */
  841. #endif /* BROWSER */
  842. { "userid", VN_UID, 0}, /* 192 */
  843. { "vareval", VN_VAREVAL, 0}, /* 212 */
  844. { "version", VN_VERS, 0},
  845. #ifndef NOXFER
  846. { "window", VN_WINDO, 0}, /* 192 */
  847. #endif /* NOXFER */
  848. #ifdef IBMX25
  849. { "x25local_nua", VN_X25LA, 0}, /* 193 */
  850. { "x25remote_nua", VN_X25RA, 0}, /* 193 */
  851. #endif /* IBMX25 */
  852. #ifdef CK_SSL
  853. { "x509_issuer", VN_X509_I, 0},
  854. { "x509_subject", VN_X509_S, 0},
  855. #endif /* CK_SSL */
  856. #ifndef NOXFER
  857. { "xferstatus",VN_XFSTAT,0}, /* 193 */
  858. { "xfermsg", VN_XFMSG, 0}, /* 193 */
  859. { "xfer_badpackets", VN_XF_BC, 0}, /* 195 */
  860. { "xfer_timeouts", VN_XF_TM, 0}, /* 195 */
  861. { "xfer_retransmits",VN_XF_RX, 0}, /* 195 */
  862. #endif /* NOXFER */
  863. { "xprogram", VN_XPROG, 0}, /* 193 */
  864. { "xversion", VN_XVNUM, 0}, /* 192 */
  865. { "year", VN_YEAR, 0} /* 304 */
  866. };
  867. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  868. #endif /* NOSPL */
  869. #ifndef NOSPL
  870. struct keytab fnctab[] = { /* Function names */
  871. #ifdef OS2
  872. { ".oox", FN_OOX, CM_INV}, /* ... */
  873. #endif /* OS2 */
  874. #ifdef CKCHANNELIO
  875. { "_eof", FN_FEOF, 0},
  876. { "_errmsg", FN_FERMSG, 0},
  877. { "_getblock", FN_FGBLK, 0},
  878. { "_getchar", FN_FGCHAR, 0},
  879. { "_getline", FN_FGLINE, 0},
  880. { "_handle", FN_FILNO, 0},
  881. { "_line", FN_NLINE, 0},
  882. { "_pos", FN_FPOS, 0},
  883. { "_putblock", FN_FPBLK, 0},
  884. { "_putchar", FN_FPCHAR, 0},
  885. { "_putline", FN_FPLINE, 0},
  886. { "_status", FN_FSTAT, 0},
  887. #endif /* CKCHANNELIO */
  888. { "aaconvert", FN_AADUMP, 0}, /* Associative Array conversion */
  889. { "absolute", FN_ABS, 0}, /* Absolute value */
  890. #ifdef TCPSOCKET
  891. { "addr2name", FN_HSTADD,CM_INV}, /* IP Address to Hostname */
  892. { "addrtoname", FN_HSTADD,CM_INV}, /* IP Address to Hostname */
  893. #endif /* TCPSOCKET */
  894. { "arraylook", FN_ALOOK,0}, /* Array lookup */
  895. { "b64decode", FN_FMB64,0}, /* Base-64 conversion */
  896. { "b64encode", FN_TOB64,0}, /* ... */
  897. { "basename", FN_BSN, 0}, /* Basename */
  898. { "break", FN_BRK, 0}, /* Break (as in Snobol) */
  899. { "ca", FN_CAP, CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  900. { "cap", FN_CAP, CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  901. { "capitalize", FN_CAP, 0}, /* First Letter -> uppercase */
  902. { "caps", FN_CAP, CM_INV}, /* ditto */
  903. { "character", FN_CHR, 0}, /* Character from code */
  904. { "checksum", FN_CHK, 0}, /* Checksum */
  905. { "cmdstack", FN_CMDSTK,0}, /* Command stack */
  906. { "cmpdates", FN_CMPDATE,0}, /* Compare dates */
  907. { "code", FN_COD, 0}, /* Code from character */
  908. #ifndef NOPUSH
  909. { "command", FN_CMD, 0}, /* Output from a command */
  910. #endif /* NOPUSH */
  911. { "contents", FN_CON, 0}, /* Definition (contents) of variable */
  912. { "count", FN_COUNT, 0}, /* Occurrences of string in string */
  913. { "crc16", FN_CRC, 0}, /* CRC-16 */
  914. #ifdef OS2
  915. { "crypt", FN_CRY, CM_INV},
  916. #endif /* OS2 */
  917. { "cvtcset", FN_XLATE, 0}, /* Convert character set */
  918. { "cvtdate", FN_DTIM, 0}, /* Convert free date/time to std */
  919. #ifdef ZFCDAT
  920. { "date", FN_FD, 0}, /* File modification/creation date */
  921. #endif /* ZFCDAT */
  922. { "day", FN_DAY, 0}, /* Day of week */
  923. { "dayname", FN_DAYNAME,0}, /* Name of day of week */
  924. { "dayofyear", FN_JDATE, 0}, /* Date to Day of Year */
  925. { "decodehex", FN_UNPCT, 0}, /* Decode string with hex escapes */
  926. { "definition", FN_DEF, 0}, /* Return definition of given macro */
  927. { "delta2secs", FN_DELSEC, 0}, /* Delta time to seconds */
  928. { "deltatosecs", FN_DELSEC, CM_INV}, /* Delta time to seconds */
  929. #ifndef NODIAL
  930. { "dialconvert",FN_PNCVT,0}, /* Convert portable phone number */
  931. #endif /* NODIAL */
  932. { "diffdates", FN_DIFDATE,0}, /* Difference of two date-times */
  933. { "dimension", FN_DIM, 0}, /* Dimension of array */
  934. { "dir", FN_DIR, CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  935. { "dire", FN_DIR, CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  936. { "direc", FN_DIR, CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  937. { "direct", FN_DIR, CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  938. { "directo", FN_DIR, CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  939. { "director", FN_DIR, CM_INV|CM_ABR}, /* Abbreviation for direct.. */
  940. { "directories",FN_DIR, 0}, /* List of directories */
  941. { "directory", FN_DIR, CM_INV}, /* List of directories */
  942. { "dirname", FN_DNAM, 0}, /* Directory part of filename */
  943. { "dos2unixpath",FN_PC_DU, CM_INV}, /* DOS to UNIX path */
  944. { "dostounixpath",FN_PC_DU, 0}, /* DOS to UNIX path */
  945. { "doy", FN_JDATE,CM_INV}, /* Date to Day of Year */
  946. { "doy2date", FN_DATEJ,0}, /* Day of Year to date */
  947. { "doytodate", FN_DATEJ,CM_INV}, /* Day of Year to date */
  948. { "emailaddress",FN_EMAIL, 0}, /* Email address */
  949. #ifdef FN_ERRMSG
  950. { "errstring", FN_ERRMSG,0}, /* Error code to message */
  951. #endif /* FN_ERRMSG */
  952. { "evaluate", FN_EVA, 0}, /* Evaluate given arith expression */
  953. { "execute", FN_EXE, 0}, /* Execute given macro */
  954. { "filecompare",FN_FILECMP, 0}, /* File compare */
  955. { "fileinfo", FN_FILEINF, 0}, /* File information */
  956. { "files", FN_FC, 0}, /* File count */
  957. #ifdef FNFLOAT
  958. { "fpabsolute", FN_FPABS, 0}, /* Floating-point absolute value */
  959. { "fpadd", FN_FPADD, 0}, /* FP add */
  960. { "fpcosine", FN_FPCOS, 0}, /* FP cosine */
  961. { "fpdivide", FN_FPDIV, 0}, /* FP divide */
  962. { "fpexp", FN_FPEXP, 0}, /* FP e to the x */
  963. { "fpint", FN_FPINT, 0}, /* FP to integer */
  964. { "fplog10", FN_FPLOG, 0}, /* FP base-10 logarithm */
  965. { "fplogn", FN_FPLN, 0}, /* FP natural logarithm */
  966. { "fpmaximum", FN_FPMAX, 0}, /* FP maxinum */
  967. { "fpminimum", FN_FPMIN, 0}, /* FP mininum */
  968. { "fpmodulus", FN_FPMOD, 0}, /* FP modulus */
  969. { "fpmultiply", FN_FPMUL, 0}, /* FP multiply */
  970. { "fpraise", FN_FPPOW, 0}, /* FP raise to a power */
  971. { "fpround", FN_FPROU, 0}, /* FP round */
  972. { "fpsine", FN_FPSIN, 0}, /* FP sine */
  973. { "fpsqrt", FN_FPSQR, 0}, /* FP square root */
  974. { "fpsubtract", FN_FPSUB, 0}, /* FP subtract */
  975. { "fptangent", FN_FPTAN, 0}, /* FP tangent */
  976. #endif /* FNFLOAT */
  977. { "function", FN_FUNC, 0 }, /* Test for existence of a function */
  978. { "getpidinfo", FN_PID, CM_INV }, /* Get PID info (synonym for pidnfo) */
  979. { "hex2ip", FN_HEX2IP,0}, /* Hex to IP address */
  980. { "hextoip", FN_HEX2IP,CM_INV}, /* Hex to IP address */
  981. { "hex2n", FN_HEX2N, CM_INV}, /* Hex to decimal number */
  982. { "hexify", FN_HEX, 0}, /* Hexify (string) */
  983. { "index", FN_IND, 0}, /* Index (string search) */
  984. { "ip2hex", FN_IP2HEX,0}, /* IP address to hex */
  985. { "iptohex", FN_IP2HEX,CM_INV}, /* IP address to hex */
  986. { "ipaddress", FN_IPA, 0}, /* Find and return IP address */
  987. { "jdate", FN_JDATE, CM_INV}, /* Date to Day of Year */
  988. { "join", FN_JOIN, 0}, /* Join array elements */
  989. { "keywordvalue", FN_KWVAL, 0}, /* Keyword=Value */
  990. #ifdef CK_KERBEROS
  991. { "krbflags", FN_KRB_FG, 0}, /* Kerberos functions */
  992. { "krbisvalid", FN_KRB_IV, 0},
  993. { "krbnextticket", FN_KRB_NX, 0},
  994. { "krbtickets", FN_KRB_TK, 0},
  995. { "krbtimeleft", FN_KRB_TT, 0},
  996. #endif /* CK_KERBEROS */
  997. { "kwvalue", FN_KWVAL, CM_INV}, /* Keyword=Value */
  998. { "left", FN_LEF, 0}, /* Leftmost n characters of string */
  999. { "length", FN_LEN, 0}, /* Return length of argument */
  1000. { "literal", FN_LIT, 0}, /* Return argument literally */
  1001. #ifdef NT
  1002. { "longpathname",FN_LNAME,0}, /* GetLongPathName() */
  1003. #else
  1004. { "longpathname",FN_FFN,CM_INV},
  1005. #endif /* NT */
  1006. { "lop", FN_STL, 0}, /* Lop */
  1007. { "lopx", FN_LOPX, 0}, /* Lopx */
  1008. { "lower", FN_LOW, 0}, /* Return lowercased argument */
  1009. { "lpad", FN_LPA, 0}, /* Return left-padded argument */
  1010. { "ltrim", FN_LTR, 0}, /* Left-Trim */
  1011. { "maximum", FN_MAX, 0}, /* Return maximum of two arguments */
  1012. { "minimum", FN_MIN, 0}, /* Return minimum of two arguments */
  1013. { "mjd", FN_MJD, 0}, /* Date to Modified Julian Date */
  1014. { "mjd2date", FN_MJD2, CM_INV}, /* MJD to Date */
  1015. { "mjdtodate", FN_MJD2, 0}, /* MJD to Date */
  1016. { "modulus", FN_MOD, 0}, /* Return modulus of two arguments */
  1017. { "monthname", FN_MONNAME,0}, /* Name of month of year */
  1018. #ifdef COMMENT
  1019. { "msleep", FN_MSLEEP,0}, /* Sleep for n milliseconds */
  1020. #endif /* COMMENT */
  1021. { "n2hex", FN_2HEX, CM_INV}, /* Number to hex */
  1022. { "n2octal", FN_2OCT, CM_INV}, /* Number to octal */
  1023. { "n2time", FN_N2TIM,0}, /* Number to hh:mm:ss */
  1024. #ifdef TCPSOCKET
  1025. { "name2addr", FN_HSTNAM,CM_INV}, /* Hostname to IP Address */
  1026. #endif /* TCPSOCKET */
  1027. { "nday", FN_NDAY, 0}, /* Numeric day of week */
  1028. { "nextfile", FN_FIL, 0}, /* Next file in list */
  1029. { "ntime", FN_NTIM, 0}, /* Time to seconds since midnight */
  1030. { "ntohex", FN_2HEX, CM_INV}, /* Number to hex */
  1031. { "ntooctal", FN_2OCT, CM_INV}, /* Number to octal */
  1032. { "ntotime", FN_N2TIM,CM_INV}, /* Number to hh:mm:ss */
  1033. { "oct2n", FN_OCT2N,CM_INV}, /* Octal to decimal number */
  1034. { "octton", FN_OCT2N,CM_INV}, /* Octal to decimal number */
  1035. { "pathname", FN_FFN, 0}, /* Full file name */
  1036. { "pattern", FN_PATTERN, 0}, /* Pattern (for INPUT) */
  1037. #ifdef CK_PERMS
  1038. { "permissions",FN_PERM, 0}, /* Permissions of file */
  1039. #else
  1040. { "permissions",FN_PERM, CM_INV}, /* Permissions of file */
  1041. #endif /* CK_PERMS */
  1042. #ifdef SEEK_CUR
  1043. { "pictureinfo",FN_PICTURE, 0 }, /* Picture orientation/dimensions */
  1044. #endif /* SEEK_CUR */
  1045. { "pidinfo", FN_PID, 0 }, /* Get PID info */
  1046. { "radix", FN_RADIX, 0 }, /* Radix conversion */
  1047. #ifndef NORANDOM
  1048. { "random", FN_RAND, 0}, /* Random number */
  1049. #endif /* NORANDOM */
  1050. #ifndef NOPUSH
  1051. { "rawcommand", FN_RAW, 0}, /* Output from a command (raw) */
  1052. #endif /* NOPUSH */
  1053. #ifdef RECURSIVE
  1054. { "rdirectories", FN_RDIR, 0}, /* Recursive directory list */
  1055. #endif /* RECURSIVE */
  1056. { "recurse", FN_RECURSE, 0}, /* Recursive variable evaluation */
  1057. #ifdef RECURSIVE
  1058. { "rfiles", FN_RFIL, 0}, /* Recursive file list */
  1059. #endif /* RECURSIVE */
  1060. { "rep", FN_REP, CM_INV|CM_ABR},
  1061. { "repeat", FN_REP, 0}, /* Repeat argument given # of times */
  1062. { "replace", FN_RPL, 0}, /* Replace characters in string */
  1063. { "reverse", FN_REV, 0}, /* Reverse the argument string */
  1064. { "right", FN_RIG, 0}, /* Rightmost n characters of string */
  1065. { "rindex", FN_RIX, 0}, /* Right index */
  1066. { "rpad", FN_RPA, 0}, /* Right-pad the argument */
  1067. { "rsearch", FN_RSEARCH, 0}, /* R-L Search for pattern in string */
  1068. #ifdef OS2
  1069. { "scrncurx", FN_SCRN_CX, 0}, /* Screen Cursor X Pos */
  1070. { "scrncury", FN_SCRN_CY, 0}, /* Screen Cursor Y Pos */
  1071. { "scrnstr", FN_SCRN_STR, 0}, /* Screen String */
  1072. #endif /* OS2 */
  1073. { "search", FN_SEARCH, 0}, /* L-R Search for pattern in string */
  1074. #ifndef NOSEXP
  1075. { "sexpression",FN_SEXP, 0}, /* S-Expression */
  1076. #endif /* NOSEXP */
  1077. #ifdef NT
  1078. { "shortpathname",FN_SNAME,0}, /* GetShortPathName() */
  1079. #else
  1080. { "shortpathname",FN_FFN,CM_INV},
  1081. #endif /* NT */
  1082. { "size", FN_FS, 0}, /* File size */
  1083. #ifdef COMMENT
  1084. { "sleep", FN_SLEEP,0}, /* Sleep for n seconds */
  1085. #endif /* COMMENT */
  1086. { "span", FN_SPN, 0}, /* Span - like Snobol */
  1087. { "split", FN_SPLIT,0}, /* Split string into words */
  1088. { "squeeze", FN_SQUEEZE,0}, /* Squeeze whitespace in string */
  1089. { "strcmp", FN_STRCMP,0}, /* String comparison */
  1090. { "stringtype", FN_STRINGT,0}, /* String type (7-bit, 8-bit, UTF-8) */
  1091. { "stripb", FN_STB, 0}, /* Strip enclosing braces/brackets */
  1092. { "stripn", FN_STN, 0}, /* Strip n chars */
  1093. { "stripx", FN_STX, 0}, /* Strip suffix */
  1094. { "su", FN_SUB, CM_INV|CM_ABR},
  1095. { "sub", FN_SUB, CM_INV|CM_ABR},
  1096. { "subs", FN_SUB, CM_INV|CM_ABR},
  1097. { "subst", FN_SUB, CM_INV|CM_ABR},
  1098. { "substitute", FN_SUBST,0}, /* Substitute chars */
  1099. { "substring", FN_SUB, 0}, /* Extract substring from argument */
  1100. { "tablelook", FN_TLOOK,0}, /* Table lookup */
  1101. { "time", FN_TIME, 0}, /* Free-format time to hh:mm:ss */
  1102. { "tod2secs", FN_NTIM, CM_INV}, /* Time-of-day-to-secs-since-midnite */
  1103. { "todtosecs", FN_NTIM, CM_INV}, /* Time-of-day-to-secs-since-midnite */
  1104. { "trim", FN_TRM, 0}, /* Trim */
  1105. { "unhexify", FN_UNH, 0}, /* Unhexify */
  1106. { "unix2dospath",FN_PC_UD, CM_INV}, /* UNIX to DOS path */
  1107. { "unixtodospath",FN_PC_UD, 0}, /* UNIX to DOS path */
  1108. { "untabify", FN_UNTAB,0}, /* Untabify */
  1109. { "upper", FN_UPP, 0}, /* Return uppercased argument */
  1110. { "utcdate", FN_TOGMT,0}, /* Date-time to UTC (GMT) */
  1111. { "verify", FN_VER, 0}, /* Verify */
  1112. { "word", FN_WORD, 0}, /* Extract a word */
  1113. { "", 0, 0}
  1114. };
  1115. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab)) - 1;
  1116. #endif /* NOSPL */
  1117. #ifndef NOSPL /* Buffer for expansion of */
  1118. #ifdef BIGBUFOK /* built-in variables. */
  1119. #define VVBUFL 1024
  1120. #else
  1121. #define VVBUFL 256
  1122. #endif /* BIGBUFOK */
  1123. char vvbuf[VVBUFL+1];
  1124. #endif /* NOSPL */
  1125. struct keytab disptb[] = { /* Log file disposition */
  1126. { "append", 1, 0},
  1127. { "new", 0, 0}
  1128. };
  1129. #ifdef CKFLOAT
  1130. /* I N I T F L O A T -- Deduce floating-point precision by inspection */
  1131. #ifdef COMMENT
  1132. /* For looking at internal floating-point representations */
  1133. static char fp_xbuf[128];
  1134. static char *
  1135. tohex(s, n) CHAR * s; int n; {
  1136. int x;
  1137. char * p = fp_xbuf;
  1138. while (n-- > 0) {
  1139. x = (*s >> 4) & 0x0f;
  1140. *p++ = hexdigits[x];
  1141. x = *s++ & 0x0f;
  1142. *p++ = hexdigits[x];
  1143. }
  1144. *p = NUL;
  1145. return((char *)fp_xbuf);
  1146. }
  1147. #endif /* COMMENT */
  1148. char math_pi[] = "3.1415926535897932384626433832795";
  1149. char math_e[] = "2.7182818284590452353602874713527";
  1150. VOID
  1151. initfloat() {
  1152. char * buf = NULL;
  1153. int i, x, y;
  1154. /*
  1155. We malloc a big temporary buffer for sprintf() to minimize likelihood of
  1156. (and damage from) sprintf buffer overflows. In any case, the only way this
  1157. could happen would be if sprintf() itself had bugs, since the format
  1158. descriptor says to cut it off at 250 decimal places.
  1159. */
  1160. if ((buf = (char *)malloc(4096))) {
  1161. sprintf(buf,"%0.250f",(10.0 / 3.0));
  1162. for (i = 2; i < 250 && buf[i] == '3'; i++) ;
  1163. x = i - 1;
  1164. debug(F111,"initfloat 10.0/3.0",buf,x);
  1165. sprintf(buf,"%0.250f",(4.0 / 9.0));
  1166. for (i = 2; i < 250 && buf[i] == '4'; i++) ;
  1167. y = i - 1;
  1168. debug(F111,"initfloat 4.0/9.0",buf,y);
  1169. fp_digits = (x < y) ? x : y;
  1170. if (fp_digits < sizeof(math_pi) - 1) {
  1171. math_pi[fp_digits+1] = NUL;
  1172. math_e[fp_digits+1] = NUL;
  1173. }
  1174. sprintf(buf,"%0.6f",(7.0 / 9.0));
  1175. if (buf[7] == '8') fp_rounding = 1;
  1176. debug(F111,"initfloat 7.0/9.0",buf,fp_rounding);
  1177. debug(F101,"initfloat precision","",fp_digits);
  1178. free(buf);
  1179. }
  1180. }
  1181. #endif /* CKFLOAT */
  1182. /*
  1183. P R E S C A N -- A quick look through the command-line options for
  1184. items that must be handled before the initialization file is executed.
  1185. */
  1186. #ifdef NT
  1187. extern int StartedFromDialer;
  1188. #endif /* NT */
  1189. #ifdef OS2
  1190. extern int k95stdio;
  1191. unsigned long startflags = 0L;
  1192. #endif /* OS2 */
  1193. static char *
  1194. findinpath(arg) char * arg; {
  1195. #ifdef OS2
  1196. char * scriptenv, * keymapenv;
  1197. int len;
  1198. #endif /* OS2 */
  1199. #ifdef DCMDBUF
  1200. extern char * cmdbuf;
  1201. #else
  1202. extern char cmdbuf[];
  1203. #endif /* DCMDBUF */
  1204. char takepath[4096];
  1205. char * s;
  1206. int x, z;
  1207. /* Set up search path... */
  1208. #ifdef OS2
  1209. char * appdata0 = NULL, *appdata1 = NULL;
  1210. #ifdef NT
  1211. scriptenv = getenv("K95SCRIPTS");
  1212. keymapenv = getenv("K95KEYMAPS");
  1213. makestr(&appdata0,(char *)GetAppData(0));
  1214. makestr(&appdata1,(char *)GetAppData(1));
  1215. #else /* NT */
  1216. scriptenv = getenv("K2SCRIPTS");
  1217. keymapenv = getenv("K2KEYMAPS");
  1218. #endif /* NT */
  1219. if (!scriptenv)
  1220. scriptenv = getenv("CK_SCRIPTS");
  1221. if (!scriptenv)
  1222. scriptenv = "";
  1223. if (!keymapenv)
  1224. keymapenv = getenv("CK_KEYMAPS");
  1225. if (!keymapenv)
  1226. keymapenv = "";
  1227. debug(F110,"startupdir",startupdir,0);
  1228. debug(F110,"common appdata directory",appdata1,0);
  1229. debug(F110,"appdata directory",appdata0,0);
  1230. debug(F110,"inidir",inidir,0);
  1231. debug(F110,"home",zhome(),0);
  1232. debug(F110,"exedir",exedir,0);
  1233. len = strlen(scriptenv) + strlen(keymapenv) + 3*strlen(startupdir)
  1234. + 3*strlen(inidir) + 3*strlen(zhome()) + 3*strlen(exedir)
  1235. + (appdata0 ? 3*strlen(appdata0) : 0)
  1236. + (appdata1 ? 3*strlen(appdata1) : 0)
  1237. + 6*strlen("SCRIPTS/") + 6*strlen("KEYMAPS/") + 16;
  1238. if (len >= 4096) { /* SAFE (length is checked) */
  1239. takepath[0] = '\0';
  1240. debug(F111,"findinpath error - path length too long","len",len);
  1241. } else
  1242. sprintf(takepath,
  1243. /* semicolon-separated path list */
  1244. "%s%s%s%s%s;%s%s;%s%s;%s%s%s%s%s%s%s%s%s%s%s%s%s;%s%s;%s%s;%s;%s%s;%s%s",
  1245. scriptenv,
  1246. (scriptenv[0] && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  1247. keymapenv,
  1248. (keymapenv[0] && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  1249. startupdir,
  1250. startupdir, "SCRIPTS/",
  1251. startupdir, "KEYMAPS/",
  1252. appdata1 ? appdata1 : "",
  1253. appdata1 ? "Kermit 95;" : "",
  1254. appdata1 ? appdata1 : "",
  1255. appdata1 ? "Kermit 95/SCRIPTS/;" : "",
  1256. appdata1 ? appdata1 : "",
  1257. appdata1 ? "Kermit 95/KEYMAPS/;" : "",
  1258. appdata0 ? appdata0 : "",
  1259. appdata0 ? "Kermit 95;" : "",
  1260. appdata0 ? appdata0 : "",
  1261. appdata0 ? "Kermit 95/SCRIPTS/;" : "",
  1262. appdata0 ? appdata0 : "",
  1263. appdata0 ? "Kermit 95/KEYMAPS/;" : "",
  1264. inidir,
  1265. inidir, "SCRIPTS/",
  1266. inidir, "KEYMAPS/",
  1267. zhome(),
  1268. zhome(), "SCRIPTS/",
  1269. zhome(), "KEYMAPS/",
  1270. exedir,
  1271. exedir, "SCRIPTS/",
  1272. exedir, "KEYMAPS/"
  1273. );
  1274. debug(F110,"findinpath takepath",takepath,0);
  1275. #ifdef NT
  1276. makestr(&appdata0,NULL);
  1277. makestr(&appdata1,NULL);
  1278. #endif /* NT */
  1279. #else /* not OS2 */
  1280. #ifndef NOSPL
  1281. z = 1024; /* Look in home directory */
  1282. s = takepath;
  1283. zzstring("\\v(home)",&s,&z);
  1284. #else
  1285. takepath[0] = '\0';
  1286. #endif /* NOSPL */
  1287. #endif /* OS2 */
  1288. /*
  1289. All the logic for searching the take path is in the command parser.
  1290. So even though we aren't parsing commands, we initialize and call the
  1291. parser from here, with the purported filename stuffed into the command
  1292. buffer, followed by some carriage returns to make the parser return.
  1293. If the file is not found, or otherwise not accessible, the parser prints
  1294. an appropriate message, and then we just exit.
  1295. */
  1296. cmdini(); /* Allocate command buffers etc */
  1297. cmini(0); /* Initialize them */
  1298. /* Stuff filename into command buf with braces in case of spaces */
  1299. ckmakmsg(cmdbuf,CMDBL,"{",arg,"}",NULL);
  1300. debug(F110,"findinpath cmdbuf",cmdbuf,0);
  1301. ckstrncat(cmdbuf,"\r\r",CMDBL); /* And some carriage returns */
  1302. if (cmifip("","",&s,&x,0,takepath,xxstring) < 0)
  1303. return(NULL);
  1304. cmres();
  1305. return(s);
  1306. }
  1307. static int tr_int; /* Flag if TRANSMIT interrupted */
  1308. #ifndef MAC
  1309. SIGTYP
  1310. #ifdef CK_ANSIC
  1311. trtrap(int foo) /* TRANSMIT interrupt trap */
  1312. #else
  1313. trtrap(foo) int foo; /* TRANSMIT interrupt trap */
  1314. #endif /* CK_ANSIC */
  1315. /* trtrap */ {
  1316. #ifdef __EMX__
  1317. signal(SIGINT, SIG_ACK);
  1318. #endif
  1319. tr_int = 1; /* (Need arg for ANSI C) */
  1320. SIGRETURN;
  1321. }
  1322. #endif /* MAC */
  1323. #endif /* NOICP */
  1324. #ifdef UNIX
  1325. VOID
  1326. getexedir() {
  1327. extern char * xarg0;
  1328. long xx;
  1329. /*
  1330. Unix provides no standard service for this. We look in argv[0], and if
  1331. we're lucky there's a full pathname. If not we do a PATH search.
  1332. */
  1333. if (ckstrchr(xarg0,'/')) { /* Global copy of argv[0] */
  1334. int i, k;
  1335. char * p = NULL;
  1336. if ((k = ckstrncpy(tmpbuf,xarg0,TMPBUFSIZ-2)) > 0) {
  1337. p = tmpbuf;
  1338. /* Convert to fully qualified pathname */
  1339. if (tmpbuf[0]) if (tmpbuf[0] != '/') {
  1340. line[0] = NUL;
  1341. zfnqfp(tmpbuf,LINBUFSIZ-2,(char *)line);
  1342. if (line[0])
  1343. p = line;
  1344. }
  1345. xx = zchki(p);
  1346. if (xx > -1) { /* Is the result an existing file? */
  1347. k = strlen(p);
  1348. for (i = k-1; i > 0; i--) { /* Yes, strip name part */
  1349. if (p[i] == '/') {
  1350. if (i < k-1)
  1351. p[i+1] = NUL;
  1352. break;
  1353. }
  1354. }
  1355. }
  1356. makestr(&exedir,p); /* Save the result */
  1357. }
  1358. }
  1359. if (!exedir && xarg0) { /* Not found? */
  1360. char * p;
  1361. p = getenv("PATH"); /* Search the PATH */
  1362. if (p) { /* If there is one... */
  1363. char * q, * PATH = NULL;
  1364. int k;
  1365. makestr(&PATH,p); /* Pokeable copy of PATH string */
  1366. if (PATH) { /* If malloc succeeded... */
  1367. p = PATH;
  1368. while (p && *p) { /* Loop through segments */
  1369. q = ckstrchr(p,':'); /* End of this segment */
  1370. if (q == p) { /* Null PATH segment */
  1371. p++; /* Skip over colon */
  1372. continue;
  1373. }
  1374. if (q) /* If not at end of PATH string */
  1375. *q++ = NUL; /* zero out the colon */
  1376. if ((k = ckstrncpy(tmpbuf,p,TMPBUFSIZ)) > 0) {
  1377. if (tmpbuf[k-1] != '/') { /* Copy this PATH segment */
  1378. tmpbuf[k++] = '/'; /* Append '/' if needed */
  1379. tmpbuf[k] = NUL;
  1380. }
  1381. /* Append the argv[0] value */
  1382. if (ckstrncpy(&tmpbuf[k],xarg0,TMPBUFSIZ) > 0) {
  1383. if (zchki(tmpbuf) > -1) { /* File exists? */
  1384. tmpbuf[k] = NUL; /* Yes, we're done */
  1385. zfnqfp(tmpbuf,LINBUFSIZ,(char *)line);
  1386. makestr(&exedir,line);
  1387. break;
  1388. }
  1389. } else break;
  1390. } else break;
  1391. p = q; /* Not found, go to next segment */
  1392. } /* while */
  1393. free(PATH); /* Free PATH copy */
  1394. }
  1395. }
  1396. if (!exedir) { /* Still nothing? */
  1397. if (zchki(xarg0) > -1) { /* Maybe it's in the current dir */
  1398. zfnqfp(zgtdir(),LINBUFSIZ,(char *)line);
  1399. makestr(&exedir,line);
  1400. }
  1401. }
  1402. }
  1403. if (!exedir) { /* Still nothing? */
  1404. makestr(&exedir,"/"); /* Fake it with with root. */
  1405. }
  1406. }
  1407. #endif /* UNIX */
  1408. int arg_x = 0;
  1409. static int x_prescan = 0;
  1410. /*
  1411. The argument y once meant something but I can't imagine what so now
  1412. it's ignored. (Prior to 22 Aug 98, prescan() was called twice by main(),
  1413. and the arg differentiated the two calls. But this caused all sorts of
  1414. problems & confusion, so I commented out the second call. This issue might
  1415. need to be revisited.)
  1416. */
  1417. VOID
  1418. prescan(dummy) int dummy; { /* Arg is ignored. */
  1419. extern int howcalled;
  1420. int yargc; char **yargv;
  1421. char x;
  1422. char *yp, *yy;
  1423. #ifdef DEBUG
  1424. int debcount = 0;
  1425. #endif /* DEBUG */
  1426. int z;
  1427. if (x_prescan) /* Only run once */
  1428. return;
  1429. x_prescan = 1;
  1430. yargc = xargc; /* Make copy of arg vector */
  1431. yargv = xargv;
  1432. #ifndef NOICP
  1433. #ifdef DCMDBUF
  1434. if (!kermrc)
  1435. if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1436. fatal("prescan: no memory for kermrc");
  1437. #endif /* DCMDBUF */
  1438. ckstrncpy(kermrc,KERMRC,KERMRCL); /* Default init file name */
  1439. #endif /* NOICP */
  1440. #ifdef OS2
  1441. yp = getenv("K95STARTFLAGS");
  1442. if (yp) {
  1443. startflags = atoi(yp);
  1444. }
  1445. #endif /* OS2 */
  1446. #ifdef IKSD
  1447. if (howcalled == I_AM_IKSD) /* Internet Kermit Service daemon */
  1448. inserver = 1; /* (See inserver section of ckcmai) */
  1449. #endif /* IKSD */
  1450. /* Command line options for Kermit */
  1451. #ifndef NOCMDL
  1452. if (yargc > 1
  1453. && *yargv[1] != '-'
  1454. && (yargv[1][0] != '=')
  1455. #ifdef KERBANG
  1456. && (yargv[1][0] != '+')
  1457. #endif /* KERBANG */
  1458. #ifdef IKSD
  1459. && (howcalled != I_AM_IKSD)
  1460. #endif /* IKSD */
  1461. ) { /* Filename as 1st argument */
  1462. #ifndef NOICP
  1463. char *s;
  1464. #endif /* NOICP */
  1465. #ifndef NOURL
  1466. extern int haveurl;
  1467. extern struct urldata g_url;
  1468. if (urlparse(yargv[1],&g_url)) {
  1469. if (!ckstrcmp(g_url.svc,"ftp",-1,0) ||
  1470. !ckstrcmp(g_url.svc,"ftps",-1,0)) {
  1471. haveurl = 1;
  1472. howcalled = I_AM_FTP;
  1473. } else if (!ckstrcmp(g_url.svc,"telnet",-1,0) ||
  1474. !ckstrcmp(g_url.svc,"telnets",-1,0)) {
  1475. haveurl = 1;
  1476. howcalled = I_AM_TELNET;
  1477. } else if (!ckstrcmp(g_url.svc,"ssh",-1,0)) {
  1478. haveurl = 1;
  1479. howcalled = I_AM_SSH;
  1480. } else if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  1481. !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  1482. haveurl = 1;
  1483. howcalled = I_AM_KERMIT;
  1484. } else if (!ckstrcmp(g_url.svc,"http",-1,0) ||
  1485. !ckstrcmp(g_url.svc,"https",-1,0)) {
  1486. haveurl = 1;
  1487. howcalled = I_AM_HTTP;
  1488. }
  1489. if (haveurl) {
  1490. while (--yargc > 0) { /* Go through command-line args */
  1491. yargv++; /* looking for -Y and -d */
  1492. yp = *yargv+1;
  1493. if (**yargv == '-') {
  1494. x = *(*yargv+1);
  1495. while (x) {
  1496. switch (x) {
  1497. #ifndef NOICP
  1498. case '+':
  1499. case '-':
  1500. if (doxarg(yargv,1) < 0) {
  1501. fatal("Extended argument error");
  1502. }
  1503. yp = "";
  1504. break;
  1505. #endif /* NOICP */
  1506. case 'Y':
  1507. noinit++;
  1508. break;
  1509. case 'q':
  1510. quiet = 1;
  1511. break;
  1512. case 'h':
  1513. noinit = 1;
  1514. #ifdef OS2
  1515. startflags |= 2; /* No network DLLs */
  1516. startflags |= 4; /* No TAPI DLLs */
  1517. startflags |= 8; /* No Security DLLs */
  1518. startflags |= 16; /* No Zmodem DLLs */
  1519. startflags |= 32; /* Stdin */
  1520. startflags |= 64; /* Stdout */
  1521. #endif /* OS2 */
  1522. break;
  1523. case 'd': /* = SET DEBUG ON */
  1524. #ifdef DEBUG
  1525. if (debcount++ > 0)
  1526. debtim = 1;
  1527. if (!deblog)
  1528. deblog = debopn("debug.log",0);
  1529. #endif /* DEBUG */
  1530. break;
  1531. #ifdef OS2
  1532. case 'W':
  1533. if (*(yp+1))
  1534. fatal("invalid argument bundling after -W");
  1535. yargv++, yargc--;
  1536. if (yargc < 1)
  1537. fatal("Window handle missing");
  1538. hwndDialer = (HWND) atol(*yargv);
  1539. StartedFromDialer = 1;
  1540. yargv++, yargc--;
  1541. KermitDialerID = atol(*yargv) ;
  1542. break;
  1543. case '#': /* K95 initialization options */
  1544. if (*(yp+1)) {
  1545. fatal("invalid argument bundling");
  1546. }
  1547. yargv++, yargc--;
  1548. if (yargc < 1)
  1549. fatal("-# argument missing");
  1550. startflags |= atol(*yargv);
  1551. break;
  1552. #endif /* OS2 */
  1553. }
  1554. if (!yp)
  1555. break;
  1556. x = *++yp;
  1557. }
  1558. }
  1559. }
  1560. return;
  1561. }
  1562. }
  1563. /* after this point non-Kermit personalities must return */
  1564. switch (howcalled) {
  1565. case I_AM_KERMIT:
  1566. case I_AM_IKSD:
  1567. case I_AM_SSHSUB:
  1568. break;
  1569. default:
  1570. return;
  1571. }
  1572. #endif /* NOURL */
  1573. #ifndef NOICP
  1574. /* If it is not a URL that we recognize, try to treat it as a file */
  1575. if (!isabsolute(yargv[1])) /* If not absolute */
  1576. s = findinpath(yargv[1]); /* Look in PATH */
  1577. else
  1578. s = yargv[1];
  1579. if (!s)
  1580. doexit(BAD_EXIT,xitsta);
  1581. zfnqfp(s,CKMAXPATH,cmdfil); /* In case of CD in file */
  1582. yargc -= 1; /* Skip past the filename */
  1583. yargv += 1; /* Otherwise we'll get an error */
  1584. #endif /* NOICP */
  1585. }
  1586. #ifndef NOCMDL
  1587. #ifdef NEWFTP
  1588. if (howcalled == I_AM_FTP) { /* Kermit's FTP client personality */
  1589. while (--yargc > 0) { /* Go through command-line args */
  1590. yargv++; /* looking for -Y and -d */
  1591. yp = *yargv+1;
  1592. if (**yargv == '-') {
  1593. x = *(*yargv+1);
  1594. while (x) {
  1595. switch (x) {
  1596. #ifndef NOICP
  1597. case '+':
  1598. case '-':
  1599. if (doxarg(yargv,1) < 0) {
  1600. fatal("Extended argument error");
  1601. }
  1602. yp = "";
  1603. break;
  1604. #endif /* NOICP */
  1605. case 'Y':
  1606. noinit++;
  1607. break;
  1608. case 'q':
  1609. quiet = 1;
  1610. break;
  1611. case 'h':
  1612. noinit = 1;
  1613. #ifdef OS2
  1614. startflags |= 2; /* No network DLLs */
  1615. startflags |= 4; /* No TAPI DLLs */
  1616. startflags |= 8; /* No Security DLLs */
  1617. startflags |= 16; /* No Zmodem DLLs */
  1618. startflags |= 32; /* Stdin */
  1619. startflags |= 64; /* Stdout */
  1620. #endif /* OS2 */
  1621. break;
  1622. case 'd': /* = SET DEBUG ON */
  1623. #ifdef DEBUG
  1624. if (debcount++ > 0)
  1625. debtim = 1;
  1626. if (!deblog)
  1627. deblog = debopn("debug.log",0);
  1628. #endif /* DEBUG */
  1629. break;
  1630. #ifdef OS2
  1631. case 'W':
  1632. if (*(yp+1))
  1633. fatal("invalid argument bundling after -W");
  1634. yargv++, yargc--;
  1635. if (yargc < 1)
  1636. fatal("Window handle missing");
  1637. hwndDialer = (HWND) atol(*yargv);
  1638. StartedFromDialer = 1;
  1639. yargv++, yargc--;
  1640. KermitDialerID = atol(*yargv) ;
  1641. break;
  1642. case '#': /* K95 initialization options */
  1643. if (*(yp+1)) {
  1644. fatal("invalid argument bundling");
  1645. }
  1646. yargv++, yargc--;
  1647. if (yargc < 1)
  1648. fatal("-# argument missing");
  1649. startflags |= atol(*yargv);
  1650. break;
  1651. #endif /* OS2 */
  1652. }
  1653. if (!yp)
  1654. break;
  1655. x = *++yp;
  1656. }
  1657. }
  1658. }
  1659. return;
  1660. }
  1661. #endif /* NEWFTP */
  1662. #endif /* NOCMDL */
  1663. while (--yargc > 0) { /* Go through command-line args */
  1664. yargv++;
  1665. yp = *yargv+1; /* Pointer for bundled args */
  1666. if (**yargv == '=') /* Same rules as cmdlin()... */
  1667. return;
  1668. debug(F110,"prescan *yargv",*yargv,0);
  1669. #ifndef NOICP
  1670. #ifdef KERBANG
  1671. yy = *yargv;
  1672. if (!strcmp(yy,"+") || (*yy == '+' && *(yy+1) < (char)33)) {
  1673. char * s;
  1674. yargv++;
  1675. noinit = 1;
  1676. if (!*yargv)
  1677. return;
  1678. cfilef = 1;
  1679. s = findinpath(*yargv);
  1680. if (s) {
  1681. zfnqfp(s,CKMAXPATH,cmdfil);
  1682. return;
  1683. } else
  1684. doexit(BAD_EXIT,xitsta);
  1685. }
  1686. #endif /* KERBANG */
  1687. #endif /* NOICP */
  1688. if (!strcmp(*yargv,"--")) /* getopt() conformance */
  1689. return;
  1690. #ifdef VMS
  1691. else if (**yargv == '/')
  1692. continue;
  1693. #endif /* VMS */
  1694. else if (**yargv == '-') { /* Got an option (begins with dash) */
  1695. x = *(*yargv+1); /* Get option letter */
  1696. while (x) { /* Allow for bundled options */
  1697. debug(F000,"prescan arg","",x);
  1698. switch (x) {
  1699. #ifndef NOICP
  1700. case '+':
  1701. case '-':
  1702. if (doxarg(yargv,1) < 0) {
  1703. fatal("Extended argument error");
  1704. }
  1705. #ifndef COMMENT /* Jeff 28 Apr 2003 */
  1706. yp = NULL; /* (not "") */
  1707. #else
  1708. yargv++, yargc--;
  1709. yp = *yargv;
  1710. #endif /* COMMENT */
  1711. break;
  1712. #endif /* NOICP */
  1713. case '7': /* Undocumented... */
  1714. sstelnet = 1; /* (because it doesn't work) */
  1715. break;
  1716. #ifdef IKSD
  1717. case 'A': {
  1718. char * p;
  1719. inserver = 1; /* Flag that we are doing this */
  1720. srvcdmsg = 2; /* Preset this */
  1721. /* See inserver section of ckcmai.c for more settings */
  1722. #ifdef OS2
  1723. if (*(yp+1)) {
  1724. fatal("invalid argument bundling after -A");
  1725. }
  1726. #ifdef NT
  1727. /* Support for Pragma Systems Telnet/Terminal Servers */
  1728. p = getenv("PRAGMASYS_INETD_SOCK");
  1729. if (p && atoi(p) != 0) {
  1730. ttname[0] = '$';
  1731. ckstrncpy(&ttname[1],p,TTNAMLEN-1);
  1732. break;
  1733. }
  1734. #endif /* NT */
  1735. yargv++, yargc--;
  1736. if (yargc < 1 || **yargv == '-') {
  1737. fatal("-A argument missing");
  1738. } else {
  1739. ttname[0] = '$';
  1740. ckstrncpy(&ttname[1],*yargv,TTNAMLEN-1);
  1741. }
  1742. #endif /* OS2 */
  1743. break;
  1744. }
  1745. #endif /* IKSD */
  1746. #ifdef OS2
  1747. case 'W':
  1748. if (*(yp+1))
  1749. fatal("invalid argument bundling after -W");
  1750. yargv++, yargc--;
  1751. if (yargc < 1)
  1752. fatal("Window handle missing");
  1753. #ifdef COMMENT
  1754. if (dummy) {
  1755. yargv++, yargc--;
  1756. break;
  1757. } else {
  1758. #endif /* COMMENT */
  1759. hwndDialer = (HWND) atol(*yargv);
  1760. StartedFromDialer = 1;
  1761. yargv++, yargc--;
  1762. KermitDialerID = atol(*yargv) ;
  1763. #ifdef COMMENT
  1764. }
  1765. #endif /* COMMENT */
  1766. break;
  1767. case '#': /* K95 initialization options */
  1768. if (*(yp+1)) {
  1769. fatal("invalid argument bundling");
  1770. }
  1771. yargv++, yargc--;
  1772. if (yargc < 1)
  1773. fatal("-# argument missing");
  1774. startflags |= atol(*yargv);
  1775. break;
  1776. #endif /* OS2 */
  1777. #ifndef NOSPL
  1778. case 'M': /* My User Name */
  1779. if (*(yp+1)) {
  1780. fatal("invalid argument bundling");
  1781. }
  1782. yargv++, yargc--;
  1783. if ((yargc < 1) || (**yargv == '-')) {
  1784. fatal("missing username");
  1785. }
  1786. if ((int)strlen(*yargv) > UIDBUFLEN) {
  1787. fatal("username too long");
  1788. }
  1789. #ifdef COMMENT
  1790. /*
  1791. This can't work. uidbuf is overwritten in sysinit() which has yet to be
  1792. called. This cannot be set in prescan().
  1793. */
  1794. #ifdef IKSD
  1795. if (!inserver)
  1796. #endif /* IKSD */
  1797. ckstrncpy(uidbuf,*yargv,UIDBUFLEN);
  1798. #endif /* COMMENT */
  1799. break;
  1800. #endif /* NOSPL */
  1801. case 'R': /* Remote-only advisory */
  1802. #ifdef CK_IFRO
  1803. remonly = 1;
  1804. #endif /* CK_IFRO */
  1805. break;
  1806. case 'S': /* STAY */
  1807. stayflg = 1;
  1808. break;
  1809. case 'h':
  1810. noinit = 1;
  1811. #ifdef OS2
  1812. startflags |= 2; /* No network DLLs */
  1813. startflags |= 4; /* No TAPI DLLs */
  1814. startflags |= 8; /* No Security DLLs */
  1815. startflags |= 16; /* No Zmodem DLLs */
  1816. startflags |= 32; /* Stdin */
  1817. startflags |= 64; /* Stdout */
  1818. #endif /* OS2 */
  1819. break;
  1820. #ifndef NOICP
  1821. case 'Y': /* No init file */
  1822. noinit = 1;
  1823. break;
  1824. #endif /* NOICP */
  1825. case 'q':
  1826. quiet = 1;
  1827. break;
  1828. case 'd': /* = SET DEBUG ON */
  1829. #ifdef DEBUG
  1830. if (debcount++ > 0)
  1831. debtim = 1;
  1832. if (!deblog)
  1833. deblog = debopn("debug.log",0);
  1834. #endif /* DEBUG */
  1835. break;
  1836. case 'x': /* Server */
  1837. arg_x = 1; /* Note in advance */
  1838. break;
  1839. #ifndef NOICP
  1840. case 'y': /* Alternative init file */
  1841. noinit = 0;
  1842. yargv++, yargc--;
  1843. if (yargc < 1) fatal("missing name in -y");
  1844. /* Replace init file name */
  1845. ckstrncpy(kermrc,*yargv,KERMRCL);
  1846. rcflag = 1; /* Flag that this has been done */
  1847. debug(F111,"prescan kermrc",kermrc,rcflag);
  1848. break;
  1849. #endif /* NOICP */
  1850. case 'z': /* = SET BACKGROUND OFF */
  1851. bgset = 0;
  1852. backgrd = 0;
  1853. #ifdef VMS
  1854. batch = 0;
  1855. #endif /* VMS */
  1856. break;
  1857. case 'B': /* Force background (batch) */
  1858. bgset = 1;
  1859. backgrd = 1;
  1860. #ifdef VMS
  1861. batch = 1;
  1862. #endif /* VMS */
  1863. break;
  1864. #ifdef CK_NETBIOS
  1865. case 'N':
  1866. {
  1867. int n ;
  1868. yargv++, yargc--;
  1869. #ifdef COMMENT
  1870. if (y)
  1871. break;
  1872. #endif /* COMMENT */
  1873. if (strlen(*yargv) != 1 || (*yargv)[0] == 'X') {
  1874. NetBiosAdapter = -1;
  1875. } else {
  1876. n = atoi(*yargv);
  1877. if (n >= 0 && n <= 9)
  1878. NetBiosAdapter = n;
  1879. else
  1880. NetBiosAdapter = -1;
  1881. }
  1882. }
  1883. break;
  1884. #endif /* CK_NETBIOS */
  1885. default:
  1886. break;
  1887. }
  1888. if (!yp)
  1889. break;
  1890. x = *++yp; /* See if options are bundled */
  1891. }
  1892. }
  1893. }
  1894. #endif /* NOCMDL */
  1895. }
  1896. /* G E T T C S -- Get Transfer (Intermediate) Character Set */
  1897. /*
  1898. Given two file character sets, this routine picks out the appropriate
  1899. "transfer" character set to use for translating between them.
  1900. The transfer character set number is returned.
  1901. At present this routine is somewhat overloaded. It's fine for file
  1902. transfer because it does not assume the Kermit partner understands UTF8.
  1903. However, for terminal emulation it *should* use UTF8 as the intermediate
  1904. character set whenever possible so as not to lose characters it might
  1905. have been able to display; for example on a terminal connection from
  1906. the Linux console (UTF8) to a BBS that uses CP437 box-drawing characters.
  1907. This is handled in the CONNECT command code in ckucns.c, which avoids
  1908. calling this routine if the character-set on either end is UTF8.
  1909. Translation between different Kanji character sets is not yet supported.
  1910. */
  1911. int
  1912. gettcs(cs1,cs2) int cs1, cs2; {
  1913. #ifdef NOCSETS /* No character-set support */
  1914. return(0); /* so no translation */
  1915. #else
  1916. int tcs = TC_TRANSP;
  1917. #ifdef KANJI
  1918. /* Kanji not supported yet */
  1919. if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  1920. fcsinfo[cs2].alphabet == AL_JAPAN )
  1921. tcs = TC_TRANSP;
  1922. else
  1923. #endif /* KANJI */
  1924. #ifdef CYRILLIC
  1925. /*
  1926. I can't remember why we don't test both sets here, but I think there
  1927. must have been a reason...
  1928. */
  1929. if (fcsinfo[cs2].alphabet == AL_CYRIL)
  1930. tcs = TC_CYRILL;
  1931. else
  1932. #endif /* CYRILLIC */
  1933. #ifdef HEBREW
  1934. if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  1935. fcsinfo[cs2].alphabet == AL_HEBREW )
  1936. tcs = TC_HEBREW;
  1937. else
  1938. #endif /* HEBREW */
  1939. #ifdef GREEK
  1940. if (fcsinfo[cs1].alphabet == AL_GREEK ||
  1941. fcsinfo[cs2].alphabet == AL_GREEK )
  1942. tcs = TC_GREEK;
  1943. else
  1944. #endif /* GREEK */
  1945. /* Roman sets ... */
  1946. #ifdef LATIN2 /* East European */
  1947. if (cs1 == FC_2LATIN || cs2 == FC_2LATIN || /* Latin-2 */
  1948. cs1 == FC_CP852 || cs2 == FC_CP852 || /* CP852 */
  1949. cs1 == FC_CP1250 || cs2 == FC_CP1250 || /* Windows Latin-2 */
  1950. cs1 == FC_MAZOVIA || cs2 == FC_MAZOVIA) /* Polish Mazovia */
  1951. tcs = TC_2LATIN;
  1952. else
  1953. #endif /* LATIN2 */
  1954. /* West European Euro-aware */
  1955. if (cs1 == FC_CP858 || cs1 == FC_9LATIN ||
  1956. cs2 == FC_CP858 || cs2 == FC_9LATIN)
  1957. tcs = TC_9LATIN;
  1958. else /* Traditional West European */
  1959. tcs = TC_1LATIN;
  1960. return(tcs);
  1961. #endif /* NOCSETS */
  1962. }
  1963. #ifndef NOLOCAL
  1964. /* D O C O N E C T -- Do the connect command */
  1965. /*
  1966. q = 0 means issue normal informational message about how to get back, etc.
  1967. q != 0 means to skip the message.
  1968. */
  1969. int
  1970. doconect(q,async) int q, async; {
  1971. int x; /* Return code */
  1972. #ifdef CK_AUTODL
  1973. extern CHAR ksbuf[];
  1974. #endif /* CK_AUTODL */
  1975. #ifndef NOKVERBS /* Keyboard macro material */
  1976. extern int keymac, keymacx;
  1977. #endif /* NOKVERBS */
  1978. extern int justone, adl_err;
  1979. int qsave; /* For remembering "quiet" value */
  1980. #ifdef OS2
  1981. extern int term_io;
  1982. int term_io_save;
  1983. #ifdef KUI
  1984. extern int kui_async;
  1985. #endif /* KUI */
  1986. #endif /* OS2 */
  1987. int is_tn = 0;
  1988. #ifdef IKSD
  1989. if (inserver) {
  1990. if (!quiet)
  1991. printf("\r\n?Sorry, IKSD cannot CONNECT.\r\n");
  1992. return(success = 0);
  1993. }
  1994. #endif /* IKSD */
  1995. is_tn =
  1996. #ifdef TNCODE
  1997. (local && network && IS_TELNET()) || (!local && sstelnet)
  1998. #else
  1999. 0
  2000. #endif /* TNCODE */
  2001. ;
  2002. /*
  2003. Saving, changing, and restoring the global "quiet" variable around calls
  2004. to conect() to control whether the verbose CONNECT message is printed is
  2005. obviously less elegant than passing a parameter to conect(), but we do it
  2006. this way to avoid the need to change all of the ck?con.c modules. NOTE:
  2007. it is important to restore the value immediately upon return in case there
  2008. is an autodownload or APC.
  2009. */
  2010. qsave = quiet; /* Save it */
  2011. if (!quiet && q > -1)
  2012. quiet = q; /* Use argument temporarily */
  2013. conres(); /* Put console back to normal */
  2014. debug(F101,"doconect justone 1","",justone);
  2015. #ifdef CK_AUTODL
  2016. ksbuf[0] = NUL; /* Autodownload packet buffer */
  2017. #endif /* CK_AUTODL */
  2018. #ifdef OS2
  2019. display_demo = 1; /* Remember to display demo */
  2020. #endif /* OS2 */
  2021. #ifdef IKS_OPTION
  2022. if (is_tn && TELOPT_U(TELOPT_KERMIT) && ttchk() >= 0
  2023. #ifdef OS2
  2024. && !viewonly
  2025. #endif /* OS2 */
  2026. ) {
  2027. /* If the remote side is in a state of IKS START-SERVER */
  2028. /* we request that the state be changed. We will detect */
  2029. /* a failure to adhere to the request when we call ttinc() */
  2030. if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  2031. if (!quiet) {
  2032. printf("\r\nEnter Client/Server Mode... Use:\r\n\r\n");
  2033. printf(
  2034. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2035. printf(" SEND and GET for file transfer.\r\n");
  2036. printf(" REMOTE commands for file management.\r\n");
  2037. printf(" FINISH to terminate Client/Server mode.\r\n");
  2038. printf(" BYE to terminate and close connection.\r\n");
  2039. printf(" REMOTE HELP for additional information.\r\n\r\n");
  2040. }
  2041. quiet = qsave;
  2042. return(0); /* Failure */
  2043. }
  2044. }
  2045. /* Let our peer know our state. */
  2046. #ifdef CK_AUTODL
  2047. if (is_tn && TELOPT_ME(TELOPT_KERMIT)
  2048. #ifdef OS2
  2049. && !viewonly
  2050. #endif /* OS2 */
  2051. ) {
  2052. if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2053. tn_siks(KERMIT_START); /* Send Kermit-Server Start */
  2054. } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2055. tn_siks(KERMIT_STOP);
  2056. }
  2057. }
  2058. #else /* CK_AUTODL */
  2059. if (is_tn && TELOPT_ME(TELOPT_KERMIT) &&
  2060. TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2061. tn_siks(KERMIT_STOP);
  2062. #endif /* CK_AUTODL */
  2063. #endif /* IKS_OPTION */
  2064. debug(F101,"doconect flow","",flow);
  2065. #ifdef OS2
  2066. debug(F101,"doconect async","",async);
  2067. #ifdef KUI
  2068. if (kui_async)
  2069. async = 1;;
  2070. #endif /* KUI */
  2071. x = conect(async); /* Connect the first time */
  2072. #else /* OS2 */
  2073. x = conect();
  2074. #endif /* OS2 */
  2075. debok = 1;
  2076. #ifdef IKS_OPTION
  2077. if (TELOPT_U(TELOPT_KERMIT) &&
  2078. TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  2079. !tcp_incoming && !quiet && ttchk() >= 0
  2080. ) {
  2081. printf("\r\nEnter Client/Server Mode... Use:\r\n\r\n");
  2082. printf(
  2083. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2084. printf(" SEND and GET for file transfer.\r\n");
  2085. printf(" REMOTE commands for file management.\r\n");
  2086. printf(" FINISH to terminate Client/Server mode.\r\n");
  2087. printf(" BYE to terminate and close connection.\r\n");
  2088. printf(" REMOTE HELP for additional information.\r\n\r\n");
  2089. }
  2090. #endif /* IKS_OPTION */
  2091. quiet = qsave; /* Restore "quiet" value */
  2092. debug(F101,"doconect justone 2","",justone);
  2093. #ifdef NETCONN
  2094. if (network && tn_exit && ttchk() < 0)
  2095. doexit(GOOD_EXIT,xitsta); /* Exit with good status */
  2096. #endif /* NETCONN */
  2097. #ifdef OS2ORUNIX
  2098. /* Exit on disconnect if the port is not open or carrier detect */
  2099. if (exitonclose && (ttchk() < 0))
  2100. doexit(GOOD_EXIT,xitsta);
  2101. #endif /* OS2ORUNIX */
  2102. #ifdef CKCONINTB4CB
  2103. /* The order makes a difference in HP-UX 8.00. */
  2104. /* The other order makes it think it's in the background when it */
  2105. /* returns from CONNECT (Apr 1999). */
  2106. setint();
  2107. concb((char)escape); /* Restore console for commands */
  2108. #else
  2109. /* This is how it has always been so better leave it */
  2110. /* this way for all non-HP-UX-8.00 builds. */
  2111. concb((char)escape); /* Restore console for commands */
  2112. setint();
  2113. #endif /* CKCONINTB4CB */
  2114. #ifdef OS2
  2115. if (!async) {
  2116. term_io_save = term_io; /* Disable I/O by emulator */
  2117. term_io = 0;
  2118. #endif /* OS2 */
  2119. #ifdef CK_APC
  2120. /*
  2121. If an APC command was received during CONNECT mode, we define it now
  2122. as a macro, execute the macro, and then return to CONNECT mode.
  2123. We do this in a WHILE loop in case additional APCs come during subsequent
  2124. CONNECT sessions.
  2125. */
  2126. debug(F101,"doconect apcactive","",apcactive);
  2127. debug(F101,"doconect success","",success);
  2128. while (x > 0 && (apcactive == APC_LOCAL ||
  2129. (apcactive == APC_REMOTE && apcstatus != APC_OFF))) {
  2130. debug(F101,"doconect justone 3","",justone);
  2131. if (mlook(mactab,"_apc_commands",nmac) == -1) {
  2132. debug(F110,"doconect about to execute APC",apcbuf,0);
  2133. domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  2134. delmac("_apc_commands",1);
  2135. #ifdef DEBUG
  2136. } else {
  2137. debug(F100,"doconect APC in progress","",0);
  2138. #endif /* DEBUG */
  2139. }
  2140. debug(F101,"doconect apcactive after domac","",apcactive);
  2141. if (!apcactive) { /* In case CLEAR APC was in APC */
  2142. debug(F101,"doconect quit APC loop: apcactive","",apcactive);
  2143. break;
  2144. }
  2145. /* Also don't reconnect if autodownload failed - very confusing! */
  2146. /* Let them view the local screen to see what happened. - fdc */
  2147. /* This should be conditional. If someone is relying on the */
  2148. /* connect mode autodownload for the kermit server to use with */
  2149. /* a remotely executed script we should be able to return to */
  2150. /* connect mode on the failure. What we really need to do is */
  2151. /* report the status of the transfer and then return to CONNECT. */
  2152. /* In unix this would simply be a printf(), but in K95 it could */
  2153. /* use a popup dialog to report the status. - Jeff */
  2154. #ifndef NOXFER
  2155. debug(F101,"doconect xferstat","",xferstat);
  2156. if (apcactive == APC_LOCAL && !xferstat && adl_err != 0) {
  2157. debug(F101,"doconect quit APC loop: xferstat","",xferstat);
  2158. apcactive = APC_INACTIVE;
  2159. break;
  2160. }
  2161. #endif /* NOXFER */
  2162. #ifdef OS2
  2163. msleep(250);
  2164. #endif /* OS2 */
  2165. debug(F101,"doconect justone 4","",justone);
  2166. qsave = quiet; /* Do this again... */
  2167. if (!quiet && q > -1)
  2168. quiet = q;
  2169. #ifdef CK_AUTODL
  2170. ksbuf[0] = NUL;
  2171. #endif /* CK_AUTODL */
  2172. #ifdef IKS_OPTION
  2173. #ifdef CK_AUTODL
  2174. if (is_tn &&
  2175. TELOPT_ME(TELOPT_KERMIT) &&
  2176. !TELOPT_SB(TELOPT_KERMIT).kermit.me_start &&
  2177. autodl
  2178. #ifdef CK_APC
  2179. && !apcactive
  2180. #endif /* CK_APC */
  2181. #ifdef OS2
  2182. && !viewonly
  2183. #endif /* OS2 */
  2184. ) {
  2185. tn_siks(KERMIT_START); /* Send Kermit-Server Start */
  2186. }
  2187. #endif /* CK_AUTODL */
  2188. #endif /* IKS_OPTION */
  2189. #ifndef OS2
  2190. x = conect(); /* Re-CONNECT. */
  2191. #else /* OS2 */
  2192. x = conect(0);
  2193. term_io = term_io_save;
  2194. #endif /* OS2 */
  2195. debok = 1;
  2196. quiet = qsave;
  2197. debug(F101,"doconect justone 5","",justone);
  2198. #ifdef NETCONN
  2199. if (network && ttchk() < 0) {
  2200. if (tn_exit || exitonclose)
  2201. doexit(GOOD_EXIT,xitsta);
  2202. else
  2203. break;
  2204. }
  2205. #endif /* NETCONN */
  2206. #ifdef OS2ORUNIX
  2207. /* If connection dropped */
  2208. if (ttchk() < 0) {
  2209. concb((char)escape); /* Restore console. */
  2210. if (exitonclose)
  2211. doexit(GOOD_EXIT,xitsta);
  2212. else
  2213. break;
  2214. }
  2215. #endif /* OS2ORUNIX */
  2216. } /* Loop back for more. */
  2217. #endif /* CK_APC */
  2218. #ifndef NOKVERBS
  2219. if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  2220. /* Set up the macro and return */
  2221. /* Do not clear the keymac flag */
  2222. #ifdef OS2
  2223. term_io = term_io_save;
  2224. #endif /* OS2 */
  2225. return(dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs));
  2226. }
  2227. #endif /* NOKVERBS */
  2228. #ifdef OS2
  2229. term_io = term_io_save;
  2230. } /* if (!async) */
  2231. #endif /* OS2 */
  2232. #ifdef CKCONINTB4CB
  2233. /* The order makes a difference in HP-UX 8.00. */
  2234. /* The other order makes it think it's in the background when it */
  2235. /* returns from CONNECT (Apr 1999). */
  2236. setint();
  2237. concb((char)escape); /* Restore console for commands */
  2238. #else
  2239. /* This is how it has always been so better leave it */
  2240. /* this way for all non-HP-UX-8.00 builds. */
  2241. concb((char)escape); /* Restore console for commands */
  2242. setint();
  2243. #endif /* CKCONINTB4CB */
  2244. #ifdef OS2
  2245. if (!async)
  2246. #endif /* OS2 */
  2247. what = W_COMMAND; /* Back in command mode. */
  2248. return(x); /* Done. */
  2249. }
  2250. #endif /* NOLOCAL */
  2251. #ifndef NOICP
  2252. #ifdef COMMENT
  2253. /*
  2254. It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  2255. file-oriented variables or functions can return filenames containing
  2256. backslashes, which are subsequently interpreted as quotes rather than
  2257. directory separators (e.g. see commented section for VN_CMDF below).
  2258. But the problem can't be cured at this level. Example:
  2259. type \v(cmdfile)
  2260. Without doubling, the filename is parsed correctly, but then when passed
  2261. to UNIX 'cat' through the shell, the backslash is removed, and then cat
  2262. can't open the file. With doubling, the filename is not parsed correctly
  2263. and the TYPE command fails immediately with a "file not found" error.
  2264. */
  2265. /*
  2266. Utility routine to double all backslashes in a string.
  2267. s1 is pointer to source string, s2 is pointer to destination string,
  2268. n is length of destination string, both NUL-terminated.
  2269. Returns 0 if OK, -1 if not OK (destination string too short).
  2270. */
  2271. int
  2272. dblbs(s1,s2,n) char *s1, *s2; int n; {
  2273. int i = 0;
  2274. while (*s1) {
  2275. if (*s1 == '\\') {
  2276. if (++i > n) return(-1);
  2277. *s2++ = '\\';
  2278. }
  2279. if (++i > n) return(-1);
  2280. *s2++ = *s1++;
  2281. }
  2282. *s2 = NUL;
  2283. return(0);
  2284. }
  2285. #endif /* COMMENT */
  2286. char *
  2287. gmdmtyp() { /* Get modem type */
  2288. #ifndef NODIAL
  2289. int i, x;
  2290. debug(F111,"gmdmtyp","mdmtyp",mdmtyp);
  2291. debug(F111,"gmdmtyp","mdmsav",mdmsav);
  2292. x = mdmtyp;
  2293. if (x < 0) /* In case of network dialing */
  2294. x = mdmsav;
  2295. if (x < 1)
  2296. return("none");
  2297. else
  2298. for (i = 0; i < nmdm; i++)
  2299. if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0))
  2300. return(mdmtab[i].kwd);
  2301. #endif /* NODIAL */
  2302. return("none");
  2303. }
  2304. #ifndef NOXMIT
  2305. #ifndef NOLOCAL
  2306. /* T R A N S M I T -- Raw upload */
  2307. /* Obey current line, duplex, parity, flow, text/binary settings. */
  2308. /* Returns 0 upon apparent success, 1 on obvious failure. */
  2309. /***
  2310. Things to add:
  2311. . Make both text and binary mode obey set file bytesize.
  2312. . Maybe allow user to specify terminators other than CR?
  2313. . Maybe allow user to specify prompts other than single characters?
  2314. . Make STATISTICS also work for TRANSMIT.
  2315. . If TRANSMIT is done without echo, make some kind of (optional) display.
  2316. . Make the same optimization for binary-mode transmit that was done for
  2317. text-mode (in the no-echo / no-prompt / no-pause case).
  2318. ***/
  2319. /* T R A N S M I T -- Raw upload */
  2320. /* s is the filename, t is the turnaround (prompt) character */
  2321. /*
  2322. Maximum number of characters to buffer.
  2323. Must be less than LINBUFSIZ
  2324. */
  2325. #ifdef OS2
  2326. #define XMBUFS 4096 /* For compatibility with XYZmodem */
  2327. #else /* OS2 */
  2328. #define XMBUFS 1024
  2329. #endif /* OS2 */
  2330. #ifdef TNCODE
  2331. #ifndef IAC
  2332. #define IAC 255
  2333. #endif /* IAC */
  2334. #endif /* TNCODE */
  2335. #define OUTXBUFSIZ 15
  2336. static CHAR inxbuf[OUTXBUFSIZ+1]; /* Host-to-screen expansion buffer */
  2337. static int inxcount = 0; /* and count */
  2338. static CHAR outxbuf[OUTXBUFSIZ+1]; /* Keyboard-to-host expansion buf */
  2339. static int outxcount = 0; /* and count */
  2340. /* T R A N S M I T -- Unguarded non-protocol file transmission */
  2341. /*
  2342. Call with:
  2343. char * s: Name of file to transmit.
  2344. char t: Turnaround char for text-mode transmission (normally LF).
  2345. int xlate: nonzero = charset translation for text-mode xfer, 0 = skip.
  2346. int binary: nonzero = transmit in binary mode, 0 = in text mode.
  2347. */
  2348. #define XBBUFSIZ 508 /* For binary blasting */
  2349. static CHAR xbbuf[XBBUFSIZ+4];
  2350. int
  2351. #ifdef CK_ANSIC
  2352. transmit(char * s, char t, int xlate, int binary, int xxecho)
  2353. #else
  2354. transmit(s,t,xlate,binary,xxecho) char *s; char t; int xlate, binary, xxecho;
  2355. #endif /* CK_ANSIC */
  2356. /* transmit */ {
  2357. #ifdef MAC
  2358. extern char sstate;
  2359. int count = 100;
  2360. #else
  2361. int count = 0;
  2362. #ifdef OS2
  2363. #ifdef NT
  2364. SIGTYP (* oldsig)(int); /* For saving old interrupt trap. */
  2365. #else /* NT */
  2366. SIGTYP (* volatile oldsig)(int);
  2367. #endif /* NT */
  2368. #else /* OS2 */
  2369. SIGTYP (* oldsig)();
  2370. #endif /* OS2 */
  2371. #endif /* MAC */
  2372. int eof = 0; /* End of File flag */
  2373. int eol = 0; /* End of Line flag */
  2374. int rc = 1; /* Return code. 0=fail, 1=succeed. */
  2375. int myflow; /* Local copy of global flow... */
  2376. int is_tn = 0; /* Do Telnet negotiations */
  2377. int xbufsiz = XMBUFS; /* Size of TRANSMIT buffer */
  2378. int x, y, c, i; /* Int workers... */
  2379. int control = 0; /* Echo loop control */
  2380. long nbytes = 0; /* File byte count */
  2381. long zz; /* Long worker */
  2382. char *p; /* Char * worker */
  2383. #ifdef PIPESEND
  2384. extern int pipesend;
  2385. #endif /* PIPESEND */
  2386. #ifndef NOCSETS
  2387. int tcs = TC_TRANSP; /* Intermediate (xfer) char set */
  2388. int langsv = L_USASCII; /* Save current language */
  2389. int unicode = 0;
  2390. int tcssize = 0;
  2391. #ifdef CK_ANSIC /* ANSI C prototypes... */
  2392. CHAR (*sxo)(CHAR);
  2393. CHAR (*rxo)(CHAR);
  2394. CHAR (*sxi)(CHAR);
  2395. CHAR (*rxi)(CHAR);
  2396. #else /* Not ANSI C... */
  2397. CHAR (*sxo)();
  2398. CHAR (*rxo)();
  2399. CHAR (*sxi)();
  2400. CHAR (*rxi)();
  2401. #endif /* CK_ANSIC */
  2402. #ifdef UNICODE
  2403. union ck_short uc;
  2404. int bomorder = 0;
  2405. #ifdef CK_ANSIC
  2406. extern int (*xl_ufc[MAXFCSETS+1])(USHORT); /* Unicode to FCS */
  2407. extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  2408. extern int (*xuf)(USHORT);
  2409. extern USHORT (*xfu)(CHAR);
  2410. #else
  2411. extern int (*xl_ufc[MAXFCSETS+1])();
  2412. extern USHORT (*xl_fcu[MAXFCSETS+1])();
  2413. extern int (*xuf)();
  2414. extern USHORT (*xfu)();
  2415. #endif /* CK_ANSIC */
  2416. #endif /* UNICODE */
  2417. #endif /* NOCSETS */
  2418. debug(F101,"xmit t","",t);
  2419. debug(F101,"xmit xlate","",xlate);
  2420. debug(F101,"xmit binary","",binary);
  2421. #ifdef PIPESEND
  2422. if (pipesend) {
  2423. if (nopush) return(-2);
  2424. if (zxcmd(ZIFILE,s) < 1) {
  2425. printf("\r\n?Can't start command: %s\n",s);
  2426. return(0);
  2427. }
  2428. } else
  2429. #endif /* PIPESEND */
  2430. if (zopeni(ZIFILE,s) == 0) { /* Open the file to be transmitted */
  2431. printf("\r\n?Can't open file %s\n",s);
  2432. return(0);
  2433. }
  2434. x = -1; /* Open the communication channel */
  2435. if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) { /* (no harm if already open) */
  2436. printf("\r\nCan't open device %s\n",ttname);
  2437. return(0);
  2438. }
  2439. zz = x ? speed : -1L;
  2440. if (binary) { /* Binary file transmission */
  2441. myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  2442. if (ttvt(zz,myflow) < 0) { /* So no Xon/Xoff! */
  2443. printf("\r\nCan't condition line\n");
  2444. return(0);
  2445. }
  2446. } else {
  2447. if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  2448. printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  2449. return(0);
  2450. }
  2451. }
  2452. is_tn =
  2453. #ifdef TNCODE
  2454. (local && network && IS_TELNET()) || (!local && sstelnet)
  2455. #else
  2456. 0
  2457. #endif /* TNCODE */
  2458. ;
  2459. #ifndef NOCSETS
  2460. /* Set up character set translations */
  2461. tcs = 0; /* "Transfer" or "Other" charset */
  2462. sxo = rxo = NULL; /* Initialize byte-to-byte functions */
  2463. sxi = rxi = NULL;
  2464. unicode = 0; /* Assume Unicode won't be involved */
  2465. if (!binary && xlate) { /* Set up charset translations */
  2466. /*
  2467. In the SENDING direction, we are converting from the local file's
  2468. character-set (fcharset) to the remote terminal charset (tcsr). In the
  2469. RECEIVING direction (echoing) we are converting from the remote end of the
  2470. terminal charset (tcsr) to its local end (tcsl), which is not necessarily
  2471. the same as the file character-set. Especially when the file character
  2472. set is UCS-2, which is not a valid terminal character set. The various
  2473. combinations are represented in this table:
  2474. FCS = File Character Set
  2475. RCS = Remote Terminal Character Set
  2476. CCS = Console (Local Terminal) Character Set
  2477. 8 4 2 1
  2478. FCS FCS RCS CCS
  2479. UCS UTF UTF UTF
  2480. 0 0 0 0 = 0 = No translation
  2481. 0 0 0 1 = 1 = FCS -> RCS, Echo RCS -> UTF
  2482. 0 0 1 0 = 2 = FCS -> UTF, Echo UTF -> CCS
  2483. 0 0 1 1 = 3 = FCS -> UTF, Echo no translation
  2484. 0 1 0 0 = 4 = UTF -> RCS, Echo RCS -> CCS
  2485. 0 1 0 1 = 5 = UTF -> RCS, Echo RCS -> UTF
  2486. 0 1 1 0 = 6 = UTF -> UTF, Echo UTF -> CCS
  2487. 0 1 1 1 = 7 = No translation
  2488. 1 0 0 0 = 8 = UCS -> RCS, Echo RCS -> CCS
  2489. 1 0 0 1 = 9 = UCS -> RCS, Echo RCS -> UTF
  2490. 1 0 1 0 = 10 = UCS -> UTF, Echo UTF -> CCS
  2491. 1 0 1 1 = 11 = UCS -> UTF, Echo no translation
  2492. */
  2493. #ifdef UNICODE
  2494. xfu = NULL; /* Unicode translation functions */
  2495. xuf = NULL;
  2496. bomorder = ucsorder; /* UCS-2 byte order */
  2497. if (fcharset == FC_UCS2) /* File charset is UCS-2 */
  2498. unicode |= 8;
  2499. else if (fcharset == FC_UTF8) /* File charset is UTF-8 */
  2500. unicode |= 4;
  2501. if (tcsr == FC_UTF8) /* Remote term charset is UTF-8 */
  2502. unicode |= 2;
  2503. if (tcsl == FC_UTF8) /* Local term charset is UTF-8 */
  2504. unicode |= 1;
  2505. #endif /* UNICODE */
  2506. /*
  2507. When Unicode not involved -- TCS is the intermediate (xfer) set, and:
  2508. sxo = File-to-Intermediate charset function
  2509. rxo = Intermediate-to-Remote-Terminal charset function
  2510. sxi = Remote-Terminal-to-Intermediate
  2511. rxi = Intermediate-to-Local-Terminal
  2512. */
  2513. tcs = gettcs(tcsr,fcharset); /* Get intermediate set. */
  2514. sxo = xls[tcs][fcharset]; /* translation function */
  2515. rxo = xlr[tcs][tcsr]; /* pointers for output functions */
  2516. sxi = xls[tcs][tcsr]; /* and for input functions. */
  2517. rxi = xlr[tcs][tcsl];
  2518. /*
  2519. At this point we have unicode nonzero if Unicode is involved in the
  2520. conversion, and to 0 if it is not.
  2521. The following is to prevent use of zmstuff() and zdstuff() by translation
  2522. functions (stuffing works with file i/o, not with communication i/o).
  2523. */
  2524. langsv = language; /* Save current SET LANGUAGE */
  2525. language = L_USASCII; /* No language-specific translations */
  2526. }
  2527. #endif /* NOCSETS */
  2528. i = 0; /* Beginning of buffer. */
  2529. #ifndef MAC
  2530. #ifndef AMIGA
  2531. oldsig = signal(SIGINT, trtrap); /* Save current interrupt trap. */
  2532. #endif /* AMIGA */
  2533. #endif /* MAC */
  2534. tr_int = 0; /* Have not been interrupted (yet). */
  2535. rc = 1; /* Return code presumed good. */
  2536. #ifdef VMS
  2537. conres();
  2538. #endif /* VMS */
  2539. #ifndef NOCSETS
  2540. debug(F101,"XMIT unicode","",unicode);
  2541. #ifdef UNICODE
  2542. debug(F101,"XMIT bomorder","",bomorder);
  2543. #endif /* UNICODE */
  2544. #endif /* NOCSETS */
  2545. c = 0; /* Initial condition */
  2546. while (c > -1 && !eof) { /* Loop for all characters in file */
  2547. eol = 0;
  2548. #ifdef MAC
  2549. /*
  2550. * It is expensive to run the miniparser so don't do it for
  2551. * every character.
  2552. */
  2553. if (--count < 0) {
  2554. count = 100;
  2555. miniparser(1);
  2556. if (sstate == 'a') {
  2557. sstate = '\0';
  2558. goto xmitfail;
  2559. }
  2560. }
  2561. #else /* Not MAC */
  2562. if (tr_int) { /* Interrupted? */
  2563. printf("^C...\n"); /* Print message */
  2564. goto xmitfail;
  2565. }
  2566. #endif /* MAC */
  2567. c = zminchar(); /* Get a file character */
  2568. #ifdef COMMENT
  2569. /* too much */
  2570. #ifdef DEBUG
  2571. if (deblog) {
  2572. if (c < 0)
  2573. debug(F101,"XMIT zminchar","",c);
  2574. else
  2575. debug(F000,"XMIT zminchar","",c);
  2576. }
  2577. #endif /* DEBUG */
  2578. #endif /* COMMENT */
  2579. if (c < -1) { /* Other error */
  2580. printf("\r\n?TRANSMIT file read error: %s\n",ck_errstr());
  2581. goto xmitfail;
  2582. } else if (c > -1) {
  2583. nbytes++;
  2584. c &= fmask; /* Apply SET FILE BYTESIZE mask */
  2585. } else if (c == -1) {
  2586. eof = 1;
  2587. debug(F101,"XMIT eof","",eof);
  2588. }
  2589. if (binary) { /* Binary... */
  2590. if (c == -1) { /* If EOF */
  2591. rc = 1; /* Success */
  2592. eof = 1;
  2593. goto xmitexit; /* Done */
  2594. }
  2595. if (!xmitw && !xxecho) { /* Special "blast" mode */
  2596. if (count == XBBUFSIZ) { /* File input buffer full... */
  2597. while (count > 0) {
  2598. errno = 0;
  2599. y = ttol(xbbuf,count);
  2600. if (y < 0) { /* try to send it. */
  2601. printf("\r\n?TRANSMIT output error: %s\n",
  2602. ck_errstr());
  2603. debug(F111,"XMIT binary ttol error",
  2604. ck_errstr(),errno);
  2605. rc = 0;
  2606. break;
  2607. }
  2608. if (y < 0) break;
  2609. count -= y;
  2610. }
  2611. count = 0;
  2612. }
  2613. xbbuf[count++] = c;
  2614. #ifdef TNCODE
  2615. if (c == IAC && is_tn) /* Telnet IAC */
  2616. xbbuf[count++] = IAC; /* must be doubled */
  2617. #endif /* TNCODE */
  2618. continue;
  2619. }
  2620. if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  2621. printf("\r\n?Can't transmit character\n");
  2622. goto xmitfail;
  2623. }
  2624. #ifdef TNCODE
  2625. if (c == IAC && is_tn) /* Quote Telnet IAC */
  2626. ttoc((char)IAC);
  2627. #endif /* TNCODE */
  2628. if (xmitw) /* Pause if requested */
  2629. msleep(xmitw);
  2630. if (xxecho) { /* SET TRANSMIT ECHO ON? */
  2631. if (duplex) { /* Yes, for half duplex */
  2632. #ifndef NOLOCAL
  2633. #ifdef OS2
  2634. /* Echo to emulator */
  2635. scriptwrtbuf((USHORT)(c & cmdmsk));
  2636. #endif /* OS2 */
  2637. #endif /* NOLOCAL */
  2638. if (conoc((char)(c & cmdmsk)) < 0) /* echo locally. */
  2639. goto xmitfail;
  2640. } else { /* For full duplex, */
  2641. int i, n; /* display whatever is there. */
  2642. n = ttchk(); /* See how many chars are waiting */
  2643. if (n < 0) { /* Connection dropped? */
  2644. printf("\r\n?Connection lost\n");
  2645. goto xmitfail;
  2646. }
  2647. for (i = 0; i < n; i++) { /* Read and echo that many. */
  2648. x = ttinc(xmitt); /* Timed read just in case. */
  2649. if (x > -1) { /* If no timeout */
  2650. if (parity) x &= 0x7f; /* display the char, */
  2651. #ifndef NOLOCAL
  2652. #ifdef OS2
  2653. /* Echo to emulator */
  2654. scriptwrtbuf((USHORT)x);
  2655. #endif /* OS2 */
  2656. #endif /* NOLOCAL */
  2657. if (conoc((char)(x & cmdmsk)) < 0) {
  2658. printf("\r\n?Output error\n");
  2659. goto xmitfail;
  2660. }
  2661. } else if (x == -2) {
  2662. printf("\r\nConnection closed.\n");
  2663. ttclos(1);
  2664. goto xmitfail;
  2665. } else if (x == -3) {
  2666. printf(
  2667. "\r\nSession Limit exceeded - closing connection.\n"
  2668. );
  2669. ttclos(1);
  2670. goto xmitfail;
  2671. } else {
  2672. printf("\r\n?Communications error\n");
  2673. goto xmitfail;
  2674. }
  2675. }
  2676. }
  2677. } else ttflui(); /* Not echoing, just flush input. */
  2678. } else { /* Text mode, line at a time. */
  2679. #ifdef UNICODE
  2680. if (fcharset == FC_UCS2 && xlate) { /* Special for UCS-2 */
  2681. char xbuf[8];
  2682. x = 1 - (nbytes & 1); /* Odd or even byte */
  2683. if (x == 0) /* Note: 1 = the 1st, 0 = 2nd, etc */
  2684. uc.x_short = 0;
  2685. if (bomorder) /* Little Endian */
  2686. x = 1 - x; /* Save byte in appropriate half */
  2687. debug(F101,"XMIT UCS2 x","",x);
  2688. uc.x_char[x] = (CHAR) (c & 0xff);
  2689. if (nbytes & 1) /* First byte, go back for next */
  2690. continue;
  2691. if (nbytes == 2) { /* UCS-2 Byte Order Mark */
  2692. if (uc.x_short == (USHORT) 0xfeff) {
  2693. debug(F100,"XMIT UCS2 BOM FEFF","",bomorder);
  2694. continue;
  2695. } else if (uc.x_short == (USHORT) 0xfffe) {
  2696. bomorder = 1 - bomorder;
  2697. debug(F100,"XMIT UCS2 BOM FFFE (swap)","",bomorder);
  2698. continue;
  2699. }
  2700. }
  2701. sprintf(xbuf,"%04X",uc.x_short); /* SAFE */
  2702. debug(F111,"XMIT UCS2",xbuf,uc.x_short);
  2703. if (nbytes & 1) /* Special eol test for UCS-2 */
  2704. if (uc.x_short == '\n')
  2705. eol = 1;
  2706. #ifdef COMMENT
  2707. if (uc.x_short == 0x2028 || uc.x_short == 0x2029)
  2708. eol = 1;
  2709. #endif /* COMMENT */
  2710. } else
  2711. #endif /* UNICODE */
  2712. if (c == '\n') { /* Normal eol test otherwise */
  2713. eol = 1;
  2714. }
  2715. if (eol) { /* End of line? */
  2716. int stuff = -1;
  2717. debug(F101,"XMIT eol length","",i);
  2718. if (i == 0) { /* Blank line? */
  2719. if (xmitf) /* Yes, insert fill if asked. */
  2720. line[i++] = dopar((char) xmitf);
  2721. }
  2722. if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR)))
  2723. line[i++] = dopar(CR); /* Terminate it with CR */
  2724. if (xmitl) {
  2725. stuff = LF;
  2726. #ifdef TNCODE
  2727. } else if (is_tn && (tn_nlm != TNL_CR)) {
  2728. /* TELNET NEWLINE ON/OFF/RAW */
  2729. stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  2730. #endif /* TNCODE */
  2731. }
  2732. if (stuff > -1)
  2733. line[i++] = dopar((char)stuff);
  2734. line[i] = NUL;
  2735. debug(F111,"XMIT eol line",line,i);
  2736. } else if (c != -1) { /* Not a newline, regular character */
  2737. int k, x;
  2738. outxbuf[0] = c; /* In case of no translation */
  2739. outxcount = 1; /* Assume result is one byte */
  2740. #ifndef NOCSETS
  2741. switch (unicode) {
  2742. case 0: /* No Unicode involved */
  2743. case 1:
  2744. if (xlate) { /* If not /TRANSPARENT */
  2745. /* Local-to-intermediate */
  2746. if (sxo) c = (*sxo)((char)c);
  2747. /* Intermediate-to-remote */
  2748. if (rxo) c = (*rxo)((char)c);
  2749. outxbuf[0] = c;
  2750. }
  2751. break;
  2752. #ifdef UNICODE
  2753. case 2: /* Local byte to UTF-8 */
  2754. case 3:
  2755. xfu = xl_fcu[fcharset];
  2756. tcssize = fcsinfo[fcharset].size;
  2757. outxcount =
  2758. b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize);
  2759. break;
  2760. case 4: /* Local UTF-8 to remote byte */
  2761. case 5:
  2762. xuf = xl_ufc[tcsr];
  2763. x = u_to_b((CHAR)c); /* Convert to byte */
  2764. if (x == -1) { /* If more input bytes needed */
  2765. continue; /* go back and get them */
  2766. } else if (x == -2) { /* LS or PS (shouldn't happen) */
  2767. outxbuf[0] = CR;
  2768. } else if (x == -9) { /* UTF-8 error */
  2769. outxbuf[0] = '?'; /* Insert error char */
  2770. outxbuf[1] = u_to_b2(); /* Insert next char */
  2771. outxcount = 2;
  2772. } else {
  2773. outxbuf[0] = /* Otherwise store result */
  2774. (unsigned)(x & 0xff);
  2775. }
  2776. break;
  2777. case 6: /* UTF-8 to UTF-8 */
  2778. case 7:
  2779. break;
  2780. case 8: /* UCS-2 to byte */
  2781. case 9:
  2782. xuf = xl_ufc[tcsr];
  2783. outxbuf[0] = (*xuf)(uc.x_short);
  2784. break;
  2785. case 10:
  2786. case 11: { /* UCS-2 to UTF-8 */
  2787. int j;
  2788. CHAR * buf = NULL;
  2789. x = ucs2_to_utf8(uc.x_short,&buf);
  2790. if (x < 0) {
  2791. outxbuf[0] = 0xff; /* (= U+FFFD) */
  2792. outxbuf[1] = 0xbd;
  2793. x = 2;
  2794. }
  2795. for (j = 0; j < x; j++)
  2796. outxbuf[j] = buf[j];
  2797. outxcount = x;
  2798. break;
  2799. }
  2800. #endif /* UNICODE */
  2801. }
  2802. #endif /* NOCSETS */
  2803. outxbuf[outxcount] = NUL;
  2804. debug(F111,"XMIT outxbuf",outxbuf,outxcount);
  2805. /*
  2806. Now the input character (1 or more bytes) is translated into the output
  2807. expansion buffer (1 or more bytes); outxcount = number of bytes to add to
  2808. the TRANSMIT line buffer, which we do here, taking care of parity, SI/SO
  2809. processing, and quoting Telnet IACs.
  2810. */
  2811. for (k = 0; k < outxcount; k++) {
  2812. c = outxbuf[k];
  2813. if (xmits && parity && (c & 0200)) { /* If shifting */
  2814. line[i++] = dopar(SO); /* needs to be done, */
  2815. line[i++] = dopar((char)c); /* do it here, */
  2816. line[i++] = dopar(SI); /* crudely. */
  2817. } else {
  2818. line[i++] = dopar((char)c);
  2819. #ifdef TNCODE
  2820. if (c == (CHAR)IAC && is_tn)
  2821. line[i++] = (CHAR)IAC;
  2822. #endif /* TNCODE */
  2823. }
  2824. }
  2825. }
  2826. /*
  2827. Send characters if buffer full, or at end of line, or at end of file.
  2828. (End of line only if echoing, waiting for a prompt, or pausing.)
  2829. */
  2830. debug(F000,"XMIT c",ckitoa(i),c);
  2831. if (i >= xbufsiz || eof || (eol && (xxecho || xmitw || t))) {
  2832. p = line;
  2833. line[i] = '\0';
  2834. debug(F111,"transmit buf",p,i);
  2835. if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  2836. printf("?TRANSMIT output error: %s\n",ck_errstr());
  2837. rc = 0;
  2838. break;
  2839. }
  2840. i = 0; /* Reset buffer pointer. */
  2841. /*
  2842. Now we handle the echo. If the user wants to see it, or if we have to
  2843. wait for the turnaround character, t. If the echo is being displayed,
  2844. and terminal character-set translation is required, we do it here.
  2845. */
  2846. if (duplex && xxecho) { /* If local echo, echo it */
  2847. if (parity || cmdmsk == 0x7f) { /* Strip hi bits */
  2848. char *ss = line; /* if necessary */
  2849. while (*ss) {
  2850. *ss &= 0x7f;
  2851. ss++;
  2852. }
  2853. }
  2854. #ifndef NOLOCAL
  2855. #ifdef OS2
  2856. { /* Echo to emulator */
  2857. char *ss = p;
  2858. while (*ss) {
  2859. scriptwrtbuf((USHORT)*ss);
  2860. ss++;
  2861. }
  2862. }
  2863. #endif /* OS2 */
  2864. #endif /* NOLOCAL */
  2865. if (conoll(p) < 0)
  2866. goto xmitfail;
  2867. }
  2868. if (xmitw) /* Sleep TRANSMIT PAUSE interval */
  2869. msleep(xmitw);
  2870. control = 0; /* Readback loop control */
  2871. if (t != 0 && eol) /* TRANSMIT PROMPT given and at EOL */
  2872. control |= 1;
  2873. if (xxecho && !duplex) /* Echo desired and is remote */
  2874. control |= 2;
  2875. if (control) { /* Do this if reading back the echo */
  2876. int n;
  2877. x = 0;
  2878. while (1) {
  2879. if (control & 1) { /* Termination criterion */
  2880. if (x == t) /* for turnaround */
  2881. break;
  2882. } else if (control & 2) { /* And for echoing */
  2883. if ((n = ttchk()) < 1)
  2884. break;
  2885. }
  2886. if ((x = ttinc(xmitt)) < 0) { /* Read with timeout */
  2887. switch (x) {
  2888. case -2:
  2889. printf("Connection closed.\n");
  2890. ttclos(1);
  2891. goto xmitfail;
  2892. case -3:
  2893. printf(
  2894. "Session Limit exceeded - closing connection.\n"
  2895. );
  2896. ttclos(1); /* full thru... */
  2897. goto xmitfail;
  2898. default:
  2899. printf("?Timeout\n");
  2900. goto xmitfail;
  2901. }
  2902. }
  2903. if (x > -1 && (control & 2)) { /* Echo any echoes */
  2904. if (parity)
  2905. x &= 0x7f;
  2906. c = x;
  2907. #ifndef NOLOCAL
  2908. #ifdef OS2
  2909. scriptwrtbuf((USHORT)x);
  2910. #endif /* OS2 */
  2911. #endif /* NOLOCAL */
  2912. inxbuf[0] = c;
  2913. inxcount = 1;
  2914. #ifndef NOCSETS
  2915. switch (unicode & 3) { /* Remote bits */
  2916. case 0:
  2917. if (xlate) {
  2918. if (sxi) c = (*sxi)((CHAR)c);
  2919. if (rxi) c = (*rxi)((CHAR)c);
  2920. inxbuf[0] = c;
  2921. }
  2922. break;
  2923. #ifdef UNICODE
  2924. case 1: /* Remote Byte to local UTF-8 */
  2925. xfu = xl_fcu[tcsr];
  2926. tcssize = fcsinfo[tcsr].size;
  2927. inxcount =
  2928. b_to_u((CHAR)c,
  2929. inxbuf,
  2930. OUTXBUFSIZ,
  2931. tcssize
  2932. );
  2933. break;
  2934. case 2: /* Remote UTF-8 to local Byte */
  2935. xuf = xl_ufc[tcsl];
  2936. x = u_to_b((CHAR)c);
  2937. if (x < 0)
  2938. continue;
  2939. inxbuf[0] = (unsigned)(x & 0xff);
  2940. break;
  2941. case 3: /* UTF-8 to UTF-8 */
  2942. break;
  2943. #endif /* UNICODE */
  2944. }
  2945. #endif /* NOCSETS */
  2946. inxbuf[inxcount] = NUL;
  2947. if (conxo(inxcount,(char *)inxbuf) < 0)
  2948. goto xmitfail;
  2949. }
  2950. }
  2951. } else /* Not echoing */
  2952. ttflui(); /* Just flush input buffer */
  2953. } /* End of buffer-dumping block */
  2954. } /* End of text mode */
  2955. if (eof) {
  2956. rc = 1;
  2957. goto xmitexit;
  2958. }
  2959. } /* End of character-reading loop */
  2960. xmitfail: /* Failure exit point */
  2961. rc = 0;
  2962. xmitexit: /* General exit point */
  2963. if (rc > 0) {
  2964. if (binary && !xmitw && !xxecho) { /* "blasting"? */
  2965. while (count > 0) { /* Partial buffer still to go? */
  2966. errno = 0;
  2967. y = ttol(xbbuf,count);
  2968. if (y < 0) {
  2969. printf("?TRANSMIT output error: %s\n",
  2970. ck_errstr());
  2971. debug(F111,"XMIT binary eof ttol error",
  2972. ck_errstr(),errno);
  2973. rc = 0;
  2974. break;
  2975. }
  2976. count -= y;
  2977. }
  2978. } else if (!binary && *xmitbuf) { /* Anything to send at EOF? */
  2979. p = xmitbuf; /* Yes, point to string. */
  2980. while (*p) /* Send it. */
  2981. ttoc(dopar(*p++)); /* Don't worry about echo here. */
  2982. }
  2983. }
  2984. #ifndef AMIGA
  2985. #ifndef MAC
  2986. signal(SIGINT,oldsig); /* Put old signal action back. */
  2987. #endif /* MAC */
  2988. #endif /* AMIGA */
  2989. #ifdef VMS
  2990. concb(escape); /* Put terminal back, */
  2991. #endif /* VMS */
  2992. zclose(ZIFILE); /* Close file, */
  2993. #ifndef NOCSETS
  2994. language = langsv; /* restore language, */
  2995. #endif /* NOCSETS */
  2996. ttres(); /* and terminal modes, */
  2997. return(rc); /* and return successfully. */
  2998. }
  2999. #endif /* NOLOCAL */
  3000. #endif /* NOXMIT */
  3001. #ifndef NOCSETS
  3002. _PROTOTYP( CHAR (*sxx), (CHAR) ); /* Local translation function */
  3003. _PROTOTYP( CHAR (*rxx), (CHAR) ); /* Local translation function */
  3004. _PROTOTYP( CHAR zl1as, (CHAR) ); /* Latin-1 to ascii */
  3005. _PROTOTYP( CHAR xl1as, (CHAR) ); /* ditto */
  3006. /* X L A T E -- Translate a local file from one character set to another */
  3007. /*
  3008. Translates input file (fin) from character set csin to character set csout
  3009. and puts the result in the output file (fout). The two character sets are
  3010. file character sets from fcstab.
  3011. */
  3012. int
  3013. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  3014. #ifndef MAC
  3015. #ifdef OS2
  3016. extern int k95stdout;
  3017. extern int wherex[], wherey[];
  3018. extern unsigned char colorcmd;
  3019. #ifdef NT
  3020. SIGTYP (* oldsig)(int); /* For saving old interrupt trap. */
  3021. #else /* NT */
  3022. SIGTYP (* volatile oldsig)(int); /* For saving old interrupt trap. */
  3023. #endif /* NT */
  3024. #else /* OS2 */
  3025. SIGTYP (* oldsig)();
  3026. #endif /* OS2 */
  3027. #endif /* MAC */
  3028. #ifdef CK_ANSIC
  3029. int (*fn)(char); /* Output function pointer */
  3030. #else
  3031. int (*fn)();
  3032. #endif /* CK_ANSIC */
  3033. extern int xlatype;
  3034. int filecode; /* Code for output file */
  3035. int scrnflg = 0;
  3036. int z = 1; /* Return code. */
  3037. int x, c, c2; /* Workers */
  3038. #ifndef UNICODE
  3039. int tcs;
  3040. #endif /* UNICODE */
  3041. ffc = 0L;
  3042. if (zopeni(ZIFILE,fin) == 0) { /* Open the file to be translated */
  3043. #ifdef COMMENT
  3044. /* An error message was already printed by zopeni() */
  3045. printf("?Can't open input file %s\n",fin);
  3046. #endif /* COMMENT */
  3047. return(0);
  3048. }
  3049. #ifdef MAC
  3050. /*
  3051. If user specified no output file, it goes to the screen. For the Mac,
  3052. this must be done a special way (result goes to a new window); the Mac
  3053. doesn't have a "controlling terminal" device name.
  3054. */
  3055. filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  3056. #else
  3057. #ifdef VMS
  3058. filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  3059. #else
  3060. #ifdef OS2
  3061. filecode = (!stricmp(fout,"con") || !stricmp(fout,"con:")) ?
  3062. ZCTERM : ZMFILE;
  3063. if ((filecode == ZCTERM) && !k95stdout && !inserver)
  3064. csout = FC_UCS2;
  3065. #else /* OS2 */
  3066. filecode = ZOFILE;
  3067. #endif /* OS2 */
  3068. #endif /* VMS */
  3069. #endif /* MAC */
  3070. if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  3071. printf("?Can't open output file %s\n",fout);
  3072. return(0);
  3073. }
  3074. #ifndef AMIGA
  3075. #ifndef MAC
  3076. oldsig = signal(SIGINT, trtrap); /* Save current interrupt trap. */
  3077. #endif /* MAC */
  3078. #endif /* AMIGA */
  3079. scrnflg = (filecode == ZCTERM); /* Set output function */
  3080. if (scrnflg)
  3081. fn = NULL;
  3082. else if (filecode == ZMFILE)
  3083. fn = putmfil;
  3084. else
  3085. fn = putfil;
  3086. tr_int = 0; /* Have not been interrupted (yet). */
  3087. z = 1; /* Return code presumed good. */
  3088. if (!scrnflg && !quiet)
  3089. printf(" %s (%s) => %s (%s)\n", /* Say what we're doing. */
  3090. fin, fcsinfo[csin].keyword,
  3091. fout,fcsinfo[csout].keyword
  3092. );
  3093. #ifndef UNICODE
  3094. /*
  3095. Non-Unicode picks the "most appropriate" transfer character set as the
  3096. intermediate set, which results in loss of any characters that the source
  3097. and target sets have in common, but are lacking from the intermediate set.
  3098. */
  3099. #ifdef KANJI
  3100. /* Special handling for Japanese... */
  3101. if (fcsinfo[csin].alphabet == AL_JAPAN ||
  3102. fcsinfo[csout].alphabet == AL_JAPAN) {
  3103. USHORT eu;
  3104. int c, x, y;
  3105. xpnbyte(-1,0,0,NULL); /* Reset output machine */
  3106. xlatype = XLA_JAPAN;
  3107. while ((c = xgnbyte(FC_JEUC,csin,NULL)) > -1) { /* Get an EUC byte */
  3108. if (tr_int) { /* Interrupted? */
  3109. printf("^C...\n"); /* Print message */
  3110. z = 0;
  3111. break;
  3112. }
  3113. /* Send EUC byte to output machine */
  3114. if ((x = xpnbyte(c,TC_JEUC,csout,fn)) < 0) {
  3115. z = -1;
  3116. break;
  3117. }
  3118. }
  3119. goto xxlate;
  3120. }
  3121. #endif /* KANJI */
  3122. /* Regular bytewise conversion... */
  3123. tcs = gettcs(csin,csout); /* Get intermediate set. */
  3124. if (csin == csout) { /* Input and output sets the same? */
  3125. sxx = rxx = NULL; /* If so, no translation. */
  3126. } else { /* Otherwise, set up */
  3127. if (tcs < 0 || tcs > MAXTCSETS ||
  3128. csin < 0 || csin > MAXFCSETS ||
  3129. csout < 0 || csout > MAXFCSETS) {
  3130. debug(F100,"XLATE csets out of range","",0);
  3131. sxx = rxx = NULL;
  3132. } else {
  3133. sxx = xls[tcs][csin]; /* translation function */
  3134. rxx = xlr[tcs][csout]; /* pointers. */
  3135. if (rxx == zl1as) rxx = xl1as;
  3136. }
  3137. }
  3138. while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3139. if (tr_int) { /* Interrupted? */
  3140. printf("^C...\n"); /* Print message */
  3141. z = 0;
  3142. break;
  3143. }
  3144. if (sxx) c = (*sxx)((CHAR)c); /* From fcs1 to tcs */
  3145. if (rxx) c = (*rxx)((CHAR)c); /* from tcs to fcs2 */
  3146. if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3147. z = -1;
  3148. break;
  3149. }
  3150. }
  3151. goto xxlate; /* Done. */
  3152. #else /* UNICODE */
  3153. /*
  3154. Use Unicode as the intermediate character set. It's simple and gives
  3155. little or no loss, but the overhead is a bit higher.
  3156. */
  3157. initxlate(csin,csout); /* Set up translation functions */
  3158. if (xlatype == XLA_NONE) {
  3159. while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3160. if (tr_int) { /* Interrupted? */
  3161. printf("^C...\n"); /* Print message */
  3162. z = 0;
  3163. break;
  3164. }
  3165. if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3166. z = -1;
  3167. break;
  3168. }
  3169. }
  3170. goto xxlate; /* Done. */
  3171. }
  3172. #ifndef NOLOCAL
  3173. #ifdef OS2
  3174. if (csout == FC_UCS2 && /* we're translating to UCS-2 */
  3175. filecode == ZCTERM && /* for the real screen... */
  3176. !k95stdout && !inserver
  3177. ) {
  3178. union {
  3179. USHORT ucs2;
  3180. UCHAR bytes[2];
  3181. } output;
  3182. while (1) { /* In this case we go two-by-two. */
  3183. if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3184. break;
  3185. output.bytes[0] = c;
  3186. if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3187. break;
  3188. output.bytes[1] = c;
  3189. if (tr_int) { /* Interrupted? */
  3190. printf("^C...\n"); /* Print message */
  3191. z = 0;
  3192. break;
  3193. }
  3194. VscrnWrtUCS2StrAtt(VCMD,
  3195. &output.ucs2,
  3196. 1,
  3197. wherey[VCMD],
  3198. wherex[VCMD],
  3199. &colorcmd
  3200. );
  3201. }
  3202. } else
  3203. #endif /* OS2 */
  3204. #endif /* NOLOCAL */
  3205. /* General case: Get next byte translated from fcs to UCS-2 */
  3206. #ifdef COMMENT
  3207. while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1 &&
  3208. (c2 = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3209. extern int fileorder;
  3210. if (tr_int) { /* Interrupted? */
  3211. printf("^C...\n"); /* Print message */
  3212. z = 0;
  3213. break;
  3214. }
  3215. debug(F001,"XLATE c","",c);
  3216. debug(F001,"XLATE c2","",c2);
  3217. /* And then send UCS-2 byte to translate-and-output machine */
  3218. if ((x = xpnbyte(fileorder?c2:c,TC_UCS2,csout,fn)) < 0) {
  3219. z = -1;
  3220. break;
  3221. }
  3222. if ((x = xpnbyte(fileorder?c:c2,TC_UCS2,csout,fn)) < 0) {
  3223. z = -1;
  3224. break;
  3225. }
  3226. }
  3227. #else
  3228. while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3229. if (tr_int) { /* Interrupted? */
  3230. printf("^C...\n"); /* Print message */
  3231. z = 0;
  3232. break;
  3233. }
  3234. if ((x = xpnbyte(c,TC_UCS2,csout,fn)) < 0) {
  3235. z = -1;
  3236. break;
  3237. }
  3238. }
  3239. #endif /* COMMENT */
  3240. #endif /* UNICODE */
  3241. xxlate: /* Common exit point */
  3242. #ifndef AMIGA
  3243. #ifndef MAC
  3244. signal(SIGINT,oldsig); /* Put old signal action back. */
  3245. #endif /* MAC */
  3246. #endif /* AMIGA */
  3247. tr_int = 0;
  3248. if (z < 0) {
  3249. if (z == -1)
  3250. printf("?File output error: %s\n",ck_errstr());
  3251. z = 0;
  3252. }
  3253. zclose(ZIFILE); /* Close files */
  3254. zclose(filecode); /* ... */
  3255. return(success = z); /* and return status. */
  3256. }
  3257. int
  3258. doxlate() {
  3259. #ifdef OS2ONLY
  3260. extern int tt_font;
  3261. #endif /* OS2ONLY */
  3262. #ifdef UNIX
  3263. extern char ** mtchs; /* zxpand() file list */
  3264. #endif /* UNIX */
  3265. int x, y, incs, outcs, multiple = 0, wild = 0, fc = 0, len = 0;
  3266. int ofisdir = 0;
  3267. char * s, * tocs = "";
  3268. if ((x = cmifi("File(s) to translate","",&s,&wild,xxstring)) < 0) {
  3269. if (x == -3) {
  3270. printf("?Name of an existing file\n");
  3271. return(-9);
  3272. } else
  3273. return(x);
  3274. }
  3275. ckstrncpy(line,s,LINBUFSIZ); /* Save copy of string just parsed. */
  3276. if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
  3277. return(incs);
  3278. #ifdef OS2
  3279. if (isunicode())
  3280. tocs = "ucs2";
  3281. else
  3282. #endif /* OS2 */
  3283. tocs = getdcset();
  3284. if ((outcs = cmkey(fcstab,nfilc,"to character-set",tocs,xxstring)) < 0)
  3285. return(outcs);
  3286. if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
  3287. if (x > 1)
  3288. ofisdir = 1;
  3289. len = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3290. if ((y = cmcfm()) < 0) return(y); /* Confirm the command */
  3291. if (len < 1)
  3292. return(-2);
  3293. if (ofisdir)
  3294. multiple = 2;
  3295. else if (wild) {
  3296. if (isdir(tmpbuf))
  3297. multiple = 2;
  3298. else if (!strcmp(tmpbuf,CTTNAM))
  3299. multiple = 1;
  3300. #ifdef OS2
  3301. else if (!stricmp(tmpbuf,"con") || !stricmp(tmpbuf,"con:"))
  3302. multiple = 1;
  3303. #else
  3304. #ifdef UNIXOROSK
  3305. else if (!strncmp(tmpbuf,"/dev/",4))
  3306. multiple = 1;
  3307. #endif /* UNIXOROSK */
  3308. #endif /* OS2 */
  3309. if (!multiple) {
  3310. printf("?A single file please\n");
  3311. return(-9);
  3312. }
  3313. }
  3314. if (!multiple) { /* Just one file */
  3315. return(success = xlate(line,tmpbuf,incs,outcs));
  3316. } else { /* Translate multiple files */
  3317. char dirbuf[CKMAXPATH+4];
  3318. int k;
  3319. #ifndef ZXREWIND
  3320. int flags = ZX_FILONLY;
  3321. #endif /* ZXREWIND */
  3322. if (multiple == 2) { /* Target is a directory */
  3323. k = ckstrncpy(dirbuf,tmpbuf,CKMAXPATH+1) - 1;
  3324. if (k < 0)
  3325. return(-2);
  3326. #ifdef OS2ORUNIX
  3327. if (dirbuf[k] != '/') {
  3328. dirbuf[k+1] = '/';
  3329. dirbuf[k+2] = NUL;
  3330. }
  3331. #else
  3332. #ifdef OSK
  3333. if (dirbuf[k] != '/') {
  3334. dirbuf[k+1] = '/';
  3335. dirbuf[k+2] = NUL;
  3336. }
  3337. #else
  3338. #ifdef VMS
  3339. if (ckmatch("*.DIR;1",s,0,0))
  3340. k = cvtdir(tmpbuf,dirbuf,TMPBUFSIZ);
  3341. if (dirbuf[k] != ']' &&
  3342. dirbuf[k] != '>' &&
  3343. dirbuf[k] != ':')
  3344. return(-2);
  3345. #else
  3346. #ifdef datageneral
  3347. if (dirbuf[k] != ':') {
  3348. dirbuf[k+1] = ':';
  3349. dirbuf[k+2] = NUL;
  3350. }
  3351. #else
  3352. #ifdef STRATUS
  3353. if (dirbuf[k] != '>') {
  3354. dirbuf[k+1] = '>';
  3355. dirbuf[k+2] = NUL;
  3356. }
  3357. #endif /* STRATUS */
  3358. #endif /* datageneral */
  3359. #endif /* VMS */
  3360. #endif /* OSK */
  3361. #endif /* OS2ORUNIX */
  3362. }
  3363. #ifdef ZXREWIND
  3364. fc = zxrewind(); /* Rewind the file list */
  3365. #else
  3366. if (matchdot) flags |= ZX_MATCHDOT;
  3367. fc = nzxpand(line,flags);
  3368. #endif /* ZXREWIND */
  3369. if (fc < 1) {
  3370. printf("?Wildcard expansion error\n");
  3371. return(-9);
  3372. }
  3373. #ifdef UNIX
  3374. sh_sort(mtchs,NULL,fc,0,0,filecase); /* Sort the file list */
  3375. #endif /* UNIX */
  3376. while (1) { /* Loop through the files */
  3377. znext(line);
  3378. if (!line[0])
  3379. break;
  3380. if (multiple == 2)
  3381. ckmakmsg(tmpbuf,TMPBUFSIZ,dirbuf,line,NULL,NULL);
  3382. if (xlate(line,tmpbuf,incs,outcs) < 1)
  3383. return(success = 0);
  3384. }
  3385. }
  3386. return(success = 1);
  3387. }
  3388. #endif /* NOCSETS */
  3389. /*
  3390. Returns path of user's actual home directory (or, if specified, SET CD HOME
  3391. directory), properly terminated to allow filenames or sub-paths to be
  3392. appended.
  3393. */
  3394. static char hompthbuf[CKMAXPATH+1] = { NUL, NUL }; /* Home directory path */
  3395. char *
  3396. homepath() {
  3397. int x;
  3398. extern char hompthbuf[];
  3399. extern char * myhome;
  3400. char * h;
  3401. /* myhome = SET CD HOME; zhome() uses API to get home directory */
  3402. h = myhome ? myhome : zhome();
  3403. hompthbuf[0] = NUL;
  3404. /* Ensure it is terminated with appropriate directory or device separator. */
  3405. #ifdef UNIXOROSK
  3406. x = ckstrncpy(hompthbuf,h,CKMAXPATH+1);
  3407. if (x <= 0) {
  3408. hompthbuf[0] = '/';
  3409. hompthbuf[1] = NUL;
  3410. } else if (x < CKMAXPATH - 2 && hompthbuf[x-1] != '/') {
  3411. hompthbuf[x] = '/';
  3412. hompthbuf[x+1] = NUL;
  3413. }
  3414. return(hompthbuf);
  3415. #else
  3416. #ifdef STRATUS
  3417. if (strlen(h) < CKMAXPATH)
  3418. sprintf(hompthbuf,"%s>",h); /* SAFE */
  3419. return(hompthbuf);
  3420. #else
  3421. return(h);
  3422. #endif /* STRATUS */
  3423. #endif /* UNIXOROSK */
  3424. }
  3425. /* D O L O G -- Do the log command */
  3426. int
  3427. dolog(x) int x; {
  3428. int y, disp; char *s = NULL, * p = NULL, * q = NULL;
  3429. extern int isguest;
  3430. #ifdef ZFNQFP
  3431. struct zfnfp * fnp;
  3432. #endif /* ZFNQFP */
  3433. if (isguest) {
  3434. printf("?Anonymous log creation not allowed\n");
  3435. return(-9);
  3436. }
  3437. switch (x) { /* Which log... */
  3438. #ifdef DEBUG
  3439. case LOGD:
  3440. q = "debug.log";
  3441. y = cmofi("Name of debugging log file",q,&s,xxstring);
  3442. break;
  3443. #endif /* DEBUG */
  3444. case LOGP:
  3445. q = "packet.log";
  3446. y = cmofi("Name of packet log file",q,&s,xxstring);
  3447. break;
  3448. #ifndef NOLOCAL
  3449. case LOGS:
  3450. q = "session.log";
  3451. y = cmofi("Name of session log file",q,&s,xxstring);
  3452. break;
  3453. #endif /* NOLOCAL */
  3454. #ifdef TLOG
  3455. case LOGT:
  3456. q = "transact.log";
  3457. y = cmofi("Name of transaction log file",q,&s,xxstring);
  3458. break;
  3459. #endif /* TLOG */
  3460. #ifdef CKLOGDIAL
  3461. case LOGM: {
  3462. int m, n;
  3463. char mypath[CKMAXPATH+1];
  3464. q = CXLOGFILE;
  3465. m = ckstrncpy(mypath,homepath(),CKMAXPATH);
  3466. n = strlen(CXLOGFILE);
  3467. if (m + n < CKMAXPATH)
  3468. ckstrncat(mypath,CXLOGFILE,CKMAXPATH);
  3469. else
  3470. ckstrncpy(mypath,CXLOGFILE,CKMAXPATH);
  3471. y = cmofi("Name of connection log file",mypath,&s,xxstring);
  3472. break;
  3473. }
  3474. #endif /* CKLOGDIAL */
  3475. default:
  3476. printf("\n?Unknown log designator - %d\n",x);
  3477. return(-2);
  3478. }
  3479. if (y < 0) return(y);
  3480. if (y == 2) { /* If they gave a directory name */
  3481. int k;
  3482. char * ds = "/";
  3483. k = strlen(s);
  3484. if (k > 0 && s[k-1] == '/') ds = "";
  3485. ckmakmsg(tmpbuf,TMPBUFSIZ,s,ds,q,NULL);
  3486. s = tmpbuf;
  3487. }
  3488. #ifdef ZFNQFP
  3489. #ifdef OS2ORUNIX
  3490. if (*s != '|') /* Allow for pipes */
  3491. #else
  3492. #ifdef OSK
  3493. if (*s != '|')
  3494. #endif /* OSK */
  3495. #endif /* OS2ORUNIX */
  3496. if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3497. if (fnp->fpath)
  3498. if ((int) strlen(fnp->fpath) > 0)
  3499. s = fnp->fpath;
  3500. } /* else if error keep original string */
  3501. #endif /* ZFNQFP */
  3502. ckstrncpy(line,s,LINBUFSIZ);
  3503. s = line;
  3504. #ifdef MAC
  3505. y = 0;
  3506. #else
  3507. p = "new";
  3508. #ifdef TLOG
  3509. if ((x == LOGT && tlogfmt == 2) || x == LOGM)
  3510. p = "append";
  3511. #endif /* TLOG */
  3512. if ((y = cmkey(disptb,2,"Disposition",p,xxstring)) < 0)
  3513. return(y);
  3514. #endif /* MAC */
  3515. disp = y;
  3516. if ((y = cmcfm()) < 0) return(y);
  3517. switch (x) {
  3518. #ifdef DEBUG
  3519. case LOGD:
  3520. return(deblog = debopn(s,disp));
  3521. #endif /* DEBUG */
  3522. #ifndef NOXFER
  3523. case LOGP:
  3524. return(pktlog = pktopn(s,disp));
  3525. #endif /* NOXFER */
  3526. #ifndef NOLOCAL
  3527. case LOGS:
  3528. setseslog(sesopn(s,disp));
  3529. return(seslog);
  3530. #endif /* NOLOCAL */
  3531. #ifdef TLOG
  3532. case LOGT:
  3533. return(tralog = traopn(s,disp));
  3534. #endif /* TLOG */
  3535. #ifdef CKLOGDIAL
  3536. case LOGM:
  3537. return(dialog = diaopn(s,disp,0));
  3538. #endif /* CKLOGDIAL */
  3539. default:
  3540. return(-2);
  3541. }
  3542. }
  3543. #ifndef NOXFER
  3544. int
  3545. pktopn(s,disp) char *s; int disp; {
  3546. static struct filinfo xx;
  3547. if (!s)
  3548. s = "";
  3549. if (!*s)
  3550. return(0);
  3551. debug(F111,"pktopn",s,disp);
  3552. zclose(ZPFILE);
  3553. #ifdef OS2ORUNIX
  3554. if (s[0] == '|') { /* Pipe */
  3555. char * p = s + 1;
  3556. debug(F110,"pktopn p",p,0);
  3557. while (*p) {
  3558. if (*p != ' ')
  3559. break;
  3560. else
  3561. p++;
  3562. }
  3563. debug(F110,"pktopn pipe",p,0);
  3564. pktlog = zxcmd(ZPFILE,p);
  3565. debug(F101,"pktopn seslog","",seslog);
  3566. } else { /* File */
  3567. #endif /* OS2ORUNIX */
  3568. if (disp) {
  3569. xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3570. xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3571. xx.lblopts = 0;
  3572. pktlog = zopeno(ZPFILE,s,NULL,&xx);
  3573. } else pktlog = zopeno(ZPFILE,s,NULL,NULL);
  3574. if (!pktlog && !quiet)
  3575. printf("?%s - %s\n",s,ck_errstr());
  3576. #ifdef OS2ORUNIX
  3577. }
  3578. #endif /* OS2ORUNIX */
  3579. if (pktlog > 0)
  3580. ckstrncpy(pktfil,s,CKMAXPATH+1);
  3581. else
  3582. *pktfil = '\0';
  3583. return(pktlog);
  3584. }
  3585. #endif /* NOXFER */
  3586. int
  3587. traopn(s,disp) char *s; int disp; {
  3588. #ifdef TLOG
  3589. static struct filinfo xx;
  3590. if (!s)
  3591. s = "";
  3592. if (!*s)
  3593. return(0);
  3594. debug(F111,"traopn",s,disp);
  3595. debug(F101,"traopn tlogfmt","",tlogfmt);
  3596. zclose(ZTFILE);
  3597. #ifdef OS2ORUNIX
  3598. if (tlogfmt == 2) { /* FTP format is special... */
  3599. VOID doiklog();
  3600. if (!disp) /* Append? */
  3601. if (zchki(s) > -1) /* No - does file exist? */
  3602. (VOID) zdelet(s); /* Yes - delete it. */
  3603. xferlog = 1;
  3604. ckstrncpy(trafil,s,CKMAXPATH);
  3605. makestr(&xferfile,s);
  3606. doiklog();
  3607. return(1);
  3608. }
  3609. if (s[0] == '|') { /* Pipe */
  3610. char * p = s + 1;
  3611. debug(F110,"traopn p",p,0);
  3612. while (*p) {
  3613. if (*p != ' ')
  3614. break;
  3615. else
  3616. p++;
  3617. }
  3618. debug(F110,"traopn pipe",p,0);
  3619. tralog = zxcmd(ZTFILE,p);
  3620. debug(F101,"traopn tralog","",tralog);
  3621. }
  3622. #endif /* OS2ORUNIX */
  3623. if (s[0] != '|') { /* File */
  3624. if (disp) {
  3625. xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3626. xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3627. xx.lblopts = 0;
  3628. tralog = zopeno(ZTFILE,s,NULL,&xx);
  3629. } else tralog = zopeno(ZTFILE,s,NULL,NULL);
  3630. }
  3631. if (!tralog && !quiet)
  3632. printf("?%s - %s\n",s,ck_errstr());
  3633. if (tralog > 0 && tlogfmt > 0) {
  3634. ckstrncpy(trafil,s,CKMAXPATH);
  3635. tlog(F110,"Transaction Log:",versio,0L);
  3636. #ifndef MAC
  3637. tlog(F100,ckxsys,"",0L);
  3638. #endif /* MAC */
  3639. ztime(&s);
  3640. tlog(F100,s,"",0L);
  3641. } else
  3642. *trafil = '\0';
  3643. return(tralog);
  3644. #else
  3645. return(0);
  3646. #endif /* TLOG */
  3647. }
  3648. #ifndef NOLOCAL
  3649. int
  3650. sesopn(s,disp) char * s; int disp; {
  3651. static struct filinfo xx;
  3652. extern int tsstate;
  3653. tsstate = 0; /* Session log timestamp state */
  3654. if (!s)
  3655. s = "";
  3656. if (!*s)
  3657. return(0);
  3658. debug(F111,"sesopn",s,disp);
  3659. zclose(ZSFILE);
  3660. #ifdef OS2ORUNIX
  3661. if (s[0] == '|') { /* Pipe */
  3662. char * p = s + 1;
  3663. debug(F110,"sesopn p",p,0);
  3664. while (*p) {
  3665. if (*p != ' ')
  3666. break;
  3667. else
  3668. p++;
  3669. }
  3670. debug(F110,"sesopn pipe",p,0);
  3671. setseslog(zxcmd(ZSFILE,p));
  3672. debug(F101,"sesopn seslog","",seslog);
  3673. } else { /* File */
  3674. #endif /* OS2ORUNIX */
  3675. if (disp) {
  3676. xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3677. xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3678. xx.lblopts = 0;
  3679. setseslog(zopeno(ZSFILE,s,NULL,&xx));
  3680. } else
  3681. setseslog(zopeno(ZSFILE,s,NULL,NULL));
  3682. if (!seslog && !quiet)
  3683. printf("?%s - %s\n",s,ck_errstr());
  3684. #ifdef OS2ORUNIX
  3685. }
  3686. #endif /* OS2ORUNIX */
  3687. if (seslog > 0)
  3688. ckstrncpy(sesfil,s,CKMAXPATH+1);
  3689. else
  3690. *sesfil = '\0';
  3691. return(seslog);
  3692. }
  3693. #endif /* NOLOCAL */
  3694. #endif /* NOICP */
  3695. int
  3696. debopn(s,disp) char *s; int disp; {
  3697. #ifdef DEBUG
  3698. #ifdef CK_UTSNAME
  3699. extern char unm_mch[], unm_nam[], unm_rel[], unm_ver[], unm_mod[];
  3700. #endif /* CK_UTSNAME */
  3701. #ifdef OS2
  3702. extern char ckxsystem[];
  3703. #endif /* OS2 */
  3704. char *tp;
  3705. static struct filinfo xx;
  3706. if (!s)
  3707. s = "";
  3708. if (!*s)
  3709. return(0);
  3710. zclose(ZDFILE);
  3711. #ifdef OS2ORUNIX
  3712. if (s[0] == '|') { /* Pipe */
  3713. char * p = s + 1;
  3714. debug(F110,"debopn p",p,0);
  3715. while (*p) {
  3716. if (*p != ' ')
  3717. break;
  3718. else
  3719. p++;
  3720. }
  3721. debug(F110,"debopn pipe",p,0);
  3722. deblog = zxcmd(ZDFILE,p);
  3723. debug(F101,"debopn deblog","",deblog);
  3724. } else { /* File */
  3725. #endif /* OS2ORUNIX */
  3726. if (disp) {
  3727. xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3728. xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3729. xx.lblopts = 0;
  3730. deblog = zopeno(ZDFILE,s,NULL,&xx);
  3731. } else
  3732. deblog = zopeno(ZDFILE,s,NULL,NULL);
  3733. if (!deblog && !quiet)
  3734. printf("?%s - %s\n",s,ck_errstr());
  3735. #ifdef OS2ORUNIX
  3736. }
  3737. #endif /* OS2ORUNIX */
  3738. if (deblog > 0) {
  3739. ckstrncpy(debfil,s,CKMAXPATH+1);
  3740. debug(F110,"Debug Log ",versio,0);
  3741. #ifndef MAC
  3742. #ifdef OS2
  3743. debug(F110,ckxsys,ckxsystem,0);
  3744. #else /* OS2 */
  3745. debug(F100,ckxsys,"",0);
  3746. #endif /* OS2 */
  3747. #endif /* MAC */
  3748. #ifdef CK_UTSNAME
  3749. if (unm_mch[0]) {
  3750. debug(F110,"uname machine",unm_mch,0);
  3751. if (unm_mod[0])
  3752. debug(F110,"uname model ",unm_mod,0);
  3753. debug(F110,"uname sysname",unm_nam,0);
  3754. debug(F110,"uname release",unm_rel,0);
  3755. debug(F110,"uname version",unm_ver,0);
  3756. }
  3757. #ifdef KTARGET
  3758. {
  3759. char * s; /* Makefile target */
  3760. s = KTARGET;
  3761. if (!s) s = "";
  3762. if (!*s) s = "(unknown)";
  3763. debug(F110,"build target",s,0);
  3764. }
  3765. #endif /* KTARGET */
  3766. deblog = 0;
  3767. ztime(&tp);
  3768. deblog = 1;
  3769. debug(F100,tp,"",0);
  3770. #endif /* UTSNAME */
  3771. debug(F101,"byteorder","",byteorder);
  3772. #ifndef NOICP
  3773. #ifndef NOLOCAL
  3774. if (local) {
  3775. debug(F110,"Active connection: ",ttname,0);
  3776. if (!network) {
  3777. debug(F101,"Speed","",speed);
  3778. if (hwparity)
  3779. debug(F110,"Parity[hardware]",parnam((char)hwparity),0);
  3780. else
  3781. debug(F110,"Parity",parnam((char)parity),0);
  3782. deblog = 0;
  3783. debug(F110,"Modem",gmdmtyp(),0);
  3784. deblog = 1;
  3785. }
  3786. } else {
  3787. debug(F110,"Active connection: ","none",0);
  3788. }
  3789. #endif /* NOLOCAL */
  3790. #endif /* NOICP */
  3791. } else *debfil = '\0';
  3792. return(deblog);
  3793. #else
  3794. return(0);
  3795. #endif /* MAC */
  3796. }
  3797. /* C K D A T E -- Returns current date/time in standard format */
  3798. static char nowbuf[18];
  3799. char *
  3800. ckdate() {
  3801. extern struct keytab cmonths[];
  3802. int x;
  3803. char * t; /* Substitute today's date */
  3804. char dbuf[32];
  3805. ztime(&t);
  3806. /* 012345678901234567890123 */
  3807. /* Sat Jul 4 12:16:43 1998 */
  3808. ckstrncpy(dbuf,t,32);
  3809. t = dbuf;
  3810. debug(F110,"ckdate dbuf",dbuf,0);
  3811. nowbuf[0] = t[20];
  3812. nowbuf[1] = t[21];
  3813. nowbuf[2] = t[22];
  3814. nowbuf[3] = t[23];
  3815. nowbuf[4] = NUL;
  3816. debug(F110,"ckdate nowbuf",nowbuf,0);
  3817. t[7] = NUL;
  3818. if ((x = lookup(cmonths,t+4,12,NULL)) < 0) {
  3819. debug(F110,"ckdate bad month",t,0);
  3820. return("<BAD_MONTH>");
  3821. }
  3822. sprintf(nowbuf+4,"%02d",x); /* SAFE */
  3823. nowbuf[6] = (t[8] == SP) ? '0' : t[8];
  3824. nowbuf[7] = t[9];
  3825. nowbuf[8] = ' ';
  3826. nowbuf[9] = NUL;
  3827. debug(F110,"ckdate nowbuf",nowbuf,0);
  3828. for (x = 11; x < 19; x++) nowbuf[x-2] = t[x];
  3829. nowbuf[17] = NUL;
  3830. debug(F110,"ckdate nowbuf",nowbuf,0);
  3831. return((char *)nowbuf);
  3832. }
  3833. #ifndef NOICP
  3834. #ifdef CKLOGDIAL
  3835. /*
  3836. fc = 0 for initial open, meaning open, then close immediately.
  3837. fc > 0 for subsequent opens, meaning open for use, leave open.
  3838. */
  3839. int
  3840. diaopn(s,disp,fc) char *s; int disp, fc; {
  3841. static struct filinfo xx;
  3842. if (!s)
  3843. s = "";
  3844. if (!*s)
  3845. return(0);
  3846. debug(F110,"diaopn log",s,0);
  3847. debug(F101,"diaopn fc",s,fc);
  3848. debug(F101,"diaopn disp 1",s,disp);
  3849. if (fc) disp = 1; /* Force append if open for use */
  3850. debug(F101,"diaopn disp 2",s,disp);
  3851. zclose(ZDIFIL); /* In case a log was already open */
  3852. #ifdef OS2ORUNIX
  3853. if (s[0] == '|') { /* Pipe */
  3854. char * p = s + 1;
  3855. debug(F110,"diaopn p",p,0);
  3856. while (*p) {
  3857. if (*p != ' ')
  3858. break;
  3859. else
  3860. p++;
  3861. }
  3862. debug(F110,"diaopn pipe",p,0);
  3863. dialog = zxcmd(ZDIFIL,p);
  3864. debug(F101,"diaopn dialog","",dialog);
  3865. } else { /* File */
  3866. #endif /* OS2ORUNIX */
  3867. if (disp) {
  3868. xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3869. xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3870. xx.lblopts = 0;
  3871. dialog = zopeno(ZDIFIL,s,NULL,&xx);
  3872. } else dialog = zopeno(ZDIFIL,s,NULL,NULL);
  3873. if (!dialog)
  3874. printf("?%s - %s\n",s,ck_errstr());
  3875. #ifdef OS2ORUNIX
  3876. }
  3877. #endif /* OS2ORUNIX */
  3878. if (dialog > 0)
  3879. ckstrncpy(diafil,s,CKMAXPATH+1);
  3880. else
  3881. *diafil = '\0';
  3882. if (fc == 0) /* Initial open */
  3883. zclose(ZDIFIL); /* close it */
  3884. return(dialog);
  3885. }
  3886. #endif /* CKLOGDIAL */
  3887. #ifndef NOSHOW
  3888. /* SHOW command routines */
  3889. char *
  3890. shoxm() {
  3891. char * s;
  3892. switch (binary) {
  3893. case XYFT_T: s = "text"; break;
  3894. #ifdef VMS
  3895. case XYFT_B: s = "binary fixed"; break;
  3896. case XYFT_I: s = "image"; break;
  3897. case XYFT_L: s = "labeled"; break;
  3898. case XYFT_U: s = "binary undef"; break;
  3899. #else
  3900. #ifdef MAC
  3901. case XYFT_B: s = "binary"; break;
  3902. case XYFT_M: s = "macbinary"; break;
  3903. #else
  3904. case XYFT_B: s = "binary"; break;
  3905. #ifdef CK_LABELED
  3906. case XYFT_L: s = "labeled"; break;
  3907. #endif /* CK_LABELED */
  3908. #endif /* MAC */
  3909. #endif /* VMS */
  3910. default: s = "unknown"; break;
  3911. }
  3912. return(s);
  3913. }
  3914. #ifndef NOXFER
  3915. VOID /* SHOW TRANSFER */
  3916. shoxfer() {
  3917. extern int docrc, usepipes, xfrxla, whereflg;
  3918. extern char * xfrmsg;
  3919. printf("\n");
  3920. printf(" Transfer Bell: %s\n",showoff(xfrbel));
  3921. printf(" Transfer Interruption: %s\n",showoff(xfrint));
  3922. printf(" Transfer Cancellation: %s\n",showoff(xfrcan));
  3923. #ifndef NOCSETS
  3924. printf(" Transfer Translation: %s\n",showoff(xfrxla));
  3925. printf(" Transfer Character-set: ");
  3926. if (tcharset == TC_TRANSP)
  3927. printf("Transparent\n");
  3928. else
  3929. printf("%s\n",tcsinfo[tcharset].keyword);
  3930. #endif /* NOCSETS */
  3931. printf(" Transfer CRC-calculation: %s\n",showoff(docrc));
  3932. printf(" Transfer Display: ");
  3933. switch (fdispla) {
  3934. case XYFD_N: printf("%s\n","none"); break;
  3935. case XYFD_R: printf("%s\n","serial"); break;
  3936. case XYFD_C: printf("%s\n","fullscreen"); break;
  3937. case XYFD_S: printf("%s\n","crt"); break;
  3938. case XYFD_B: printf("%s\n","brief"); break;
  3939. case XYFD_G: printf("%s\n","gui"); break;
  3940. }
  3941. printf(" Transfer Message: %s\n", xfrmsg ? xfrmsg : "(none)");
  3942. printf(" Transfer Locking-shift: ");
  3943. if (lscapu == 2) {
  3944. printf("forced");
  3945. } else {
  3946. printf("%s", (lscapr ? "enabled" : "disabled"));
  3947. if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  3948. }
  3949. printf("\n Transfer Mode: %s\n",
  3950. xfermode == XMODE_A ?
  3951. "automatic" :
  3952. "manual"
  3953. );
  3954. printf(" Transfer Pipes: %s\n", showoff(usepipes));
  3955. printf(" Transfer Protocol: %s\n",ptab[protocol].p_name);
  3956. printf(" Transfer Report: %s\n",showoff(whereflg));
  3957. printf(" Transfer Slow-start: %s\n",showoff(slostart));
  3958. printf("\n");
  3959. }
  3960. #endif /* NOXFER */
  3961. VOID
  3962. shoflow() {
  3963. int i, x;
  3964. extern int cxflow[], cxtype, ncxname, nfloname, autoflow;
  3965. extern char * cxname[];
  3966. printf("\nConnection type: %s\n",cxname[cxtype]);
  3967. if (autoflow) {
  3968. printf("Current flow-control: %s\n", floname[cxflow[cxtype]]);
  3969. printf("Switches automatically: yes\n");
  3970. } else {
  3971. printf("Current flow-control: %s\n", floname[flow]);
  3972. printf("Switches automatically: no\n");
  3973. }
  3974. printf("\nDefaults by connection type:\n");
  3975. debug(F111,"shoflow cxtype",cxname[cxtype],cxtype);
  3976. debug(F101,"shoflow flow","",flow);
  3977. for (i = 0; i < ncxname; i++) {
  3978. #ifdef NOLOCAL
  3979. if (i > 0) break;
  3980. #endif /* NOLOCAL */
  3981. #ifndef NETCONN
  3982. if (i > 2) break;
  3983. #endif /* NETCONN */
  3984. #ifndef DECNET
  3985. if (i == CXT_DECNET) continue;
  3986. #endif /* DECNET */
  3987. #ifndef DECNET
  3988. #ifndef SUPERLAT
  3989. if (i == CXT_LAT) continue;
  3990. #endif /* SUPERLAT */
  3991. #endif /* DECNET */
  3992. #ifndef CK_NETBIOS
  3993. if (i == CXT_NETBIOS) continue;
  3994. #endif /* CK_NETBIOS */
  3995. #ifndef NPIPE
  3996. if (i == CXT_NPIPE) continue;
  3997. #endif /* NPIPE */
  3998. #ifndef NETCMD
  3999. if (i == CXT_PIPE) continue;
  4000. #endif /* NETCMD */
  4001. #ifndef ANYX25
  4002. if (i == CXT_X25) continue;
  4003. #endif /* ANYX25 */
  4004. x = cxflow[i];
  4005. debug(F101,"shoflow x","",x);
  4006. if (x < nfloname)
  4007. printf(" %-14s: %s\n",cxname[i],floname[x]);
  4008. else
  4009. printf(" %-14s: (%d)\n",cxname[i],x);
  4010. }
  4011. printf("\n");
  4012. }
  4013. #ifndef NOLOCAL
  4014. #ifdef ANYX25
  4015. int
  4016. shox25(n) int n; {
  4017. if (nettype == NET_SX25) {
  4018. printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  4019. if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4020. printf("\n");
  4021. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4022. printf(" Reverse charge call %s",
  4023. revcall ? "selected" : "not selected");
  4024. printf (", Closed user group ");
  4025. if (closgr > -1)
  4026. printf ("%d",closgr);
  4027. else
  4028. printf ("not selected");
  4029. printf("\n");
  4030. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4031. printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4032. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4033. } else if (nettype == NET_VX25) {
  4034. if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4035. printf("\n");
  4036. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4037. printf(" Reverse charge call %s",
  4038. revcall ? "selected" : "not selected");
  4039. printf (", Closed user group [unsupported]");
  4040. if (closgr > -1)
  4041. printf ("%d",closgr);
  4042. else
  4043. printf ("not selected");
  4044. printf (",");
  4045. printf("\n");
  4046. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4047. printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4048. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4049. } else if (nettype == NET_IX25) {
  4050. printf("AIX NPI X.25\n");
  4051. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4052. printf("\n Reverse charge call %s",
  4053. revcall ? "selected" : "not selected");
  4054. printf (", Closed user group [unsupported]");
  4055. if (closgr > -1)
  4056. printf ("%d",closgr);
  4057. else
  4058. printf ("not selected");
  4059. printf (",");
  4060. printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  4061. }
  4062. return(n);
  4063. }
  4064. #ifndef IBMX25
  4065. int
  4066. shopad(n) int n; {
  4067. int i;
  4068. printf("\nX.3 PAD Parameters:\n");
  4069. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4070. for (i = 0; i < npadx3; i++) {
  4071. printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  4072. padparms[padx3tab[i].kwval]);
  4073. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4074. }
  4075. return(n);
  4076. }
  4077. #endif /* IBMX25 */
  4078. #endif /* ANYX25 */
  4079. VOID
  4080. shoparc() {
  4081. extern int reliable, stopbits, clsondisc;
  4082. int i; char *s;
  4083. long zz;
  4084. #ifdef NEWFTP
  4085. if (ftpisconnected()) {
  4086. shoftp(1);
  4087. printf("\n");
  4088. }
  4089. #endif /* NEWFTP */
  4090. printf("Communications Parameters:\n");
  4091. if (network
  4092. #ifdef IKSD
  4093. || inserver
  4094. #endif /* IKSD */
  4095. ) {
  4096. printf(" Network Host: %s%s",ttname,
  4097. (reliable == SET_ON || (reliable == SET_AUTO && !local)
  4098. #ifdef TN_COMPORT
  4099. && !istncomport()
  4100. #endif /* TN_COMPORT */
  4101. #ifdef IKSD
  4102. || inserver
  4103. #endif /* IKSD */
  4104. ) ? " (reliable)" : "");
  4105. #ifdef TN_COMPORT
  4106. if (istncomport()) {
  4107. int modemstate;
  4108. char * oflow, * iflow = "", * parity, * stopsize, * signature;
  4109. int baud = tnc_get_baud();
  4110. switch (tnc_get_oflow()) {
  4111. case TNC_CTL_OFLOW_NONE:
  4112. oflow = "none";
  4113. break;
  4114. case TNC_CTL_OFLOW_XON_XOFF:
  4115. oflow = "xon/xoff";
  4116. break;
  4117. case TNC_CTL_OFLOW_RTS_CTS:
  4118. oflow = "rts/cts";
  4119. break;
  4120. case TNC_CTL_OFLOW_DCD:
  4121. oflow = "dcd";
  4122. break;
  4123. case TNC_CTL_OFLOW_DSR:
  4124. oflow = "dsr";
  4125. break;
  4126. default:
  4127. oflow = "(unknown)";
  4128. }
  4129. switch (tnc_get_iflow()) {
  4130. case TNC_CTL_IFLOW_NONE:
  4131. iflow = "none";
  4132. break;
  4133. case TNC_CTL_IFLOW_XON_XOFF:
  4134. iflow = "xon/xoff";
  4135. break;
  4136. case TNC_CTL_IFLOW_RTS_CTS:
  4137. iflow = "rts/cts";
  4138. break;
  4139. case TNC_CTL_IFLOW_DTR:
  4140. break;
  4141. default:
  4142. iflow = oflow;
  4143. }
  4144. switch (tnc_get_parity()) {
  4145. case TNC_PAR_NONE:
  4146. parity = "none";
  4147. break;
  4148. case TNC_PAR_ODD:
  4149. parity = "odd";
  4150. break;
  4151. case TNC_PAR_EVEN:
  4152. parity = "even";
  4153. break;
  4154. case TNC_PAR_MARK:
  4155. parity = "mark";
  4156. break;
  4157. case TNC_PAR_SPACE:
  4158. parity = "space";
  4159. break;
  4160. default:
  4161. parity = "(unknown)";
  4162. }
  4163. switch (tnc_get_stopsize()) {
  4164. case TNC_SB_1:
  4165. stopsize = "1";
  4166. break;
  4167. case TNC_SB_1_5:
  4168. stopsize = "1.5";
  4169. break;
  4170. case TNC_SB_2:
  4171. stopsize = "2";
  4172. break;
  4173. default:
  4174. stopsize = "(unknown)";
  4175. }
  4176. signature = (char *)tnc_get_signature();
  4177. printf("\n Signature : %s\n",signature?signature:"");
  4178. if (baud <= 0)
  4179. printf(" Speed : (unknown)\n");
  4180. else
  4181. printf(" Speed : %d\n", baud);
  4182. printf(" Outbound Flow Control: %s\n", oflow);
  4183. printf(" Inbound Flow Control : %s\n", iflow);
  4184. printf(" Parity : %s\n", parity);
  4185. printf(" Data Size : %d\n", tnc_get_datasize());
  4186. printf(" Stop Bits : %s\n", stopsize);
  4187. printf(" DTR Signal : %d\n", tnc_get_dtr_state());
  4188. printf(" RTS Signal : %d\n", tnc_get_rts_state());
  4189. printf(" Modem State:\n");
  4190. modemstate = tnc_get_ms();
  4191. if (modemstate & TNC_MS_EDGE_RING)
  4192. printf(" Trailing Edge Ring Detector On\n");
  4193. else
  4194. printf(" Trailing Edge Ring Detector Off\n");
  4195. if (modemstate & TNC_MS_CTS_SIG)
  4196. printf(" CTS Signal On\n");
  4197. else
  4198. printf(" CTS Signal Off\n");
  4199. if (modemstate & TNC_MS_DSR_SIG)
  4200. printf(" DSR Signal On\n");
  4201. else
  4202. printf(" DSR Signal Off\n");
  4203. if (modemstate & TNC_MS_RI_SIG)
  4204. printf(" Ring Indicator On\n");
  4205. else
  4206. printf(" Ring Indicator Off\n");
  4207. if (modemstate & TNC_MS_RLSD_SIG)
  4208. printf(" RLSD (CD) Signal On\n");
  4209. else
  4210. printf(" RLSD (CD) Signal Off\n");
  4211. printf("\n");
  4212. }
  4213. #endif /* TN_COMPORT */
  4214. } else {
  4215. printf(" %s: %s%s, speed: ",
  4216. #ifdef OS2
  4217. "Port",
  4218. #else
  4219. "Line",
  4220. #endif /* OS2 */
  4221. ttname,
  4222. #ifdef CK_TTYFD
  4223. (local &&
  4224. #ifdef VMS
  4225. vmsttyfd() < 0
  4226. #else
  4227. ttyfd == -1
  4228. #endif /* VMS */
  4229. ) ?
  4230. " (closed)" :
  4231. (reliable == SET_ON ? " (reliable)" : "")
  4232. #else
  4233. ""
  4234. #endif /* CK_TTYFD */
  4235. );
  4236. if (
  4237. #ifdef CK_TTYFD
  4238. #ifdef VMS
  4239. vmsttyfd() < 0
  4240. #else
  4241. ttyfd == -1
  4242. #endif /* VMS */
  4243. ||
  4244. #endif /* CK_TTYFD */
  4245. (zz = ttgspd()) < 0) {
  4246. printf("unknown");
  4247. } else {
  4248. if (speed == 8880) printf("75/1200");
  4249. else if (speed == 134) printf("134.5");
  4250. else printf("%ld",zz);
  4251. }
  4252. }
  4253. if (network
  4254. #ifdef IKSD
  4255. || inserver
  4256. #endif /* IKSD */
  4257. )
  4258. printf("\n Mode: ");
  4259. else
  4260. printf(", mode: ");
  4261. if (local) printf("local"); else printf("remote");
  4262. if (network == 0
  4263. #ifdef IKSD
  4264. && !inserver
  4265. #endif/* IKSD */
  4266. ) {
  4267. #ifdef CK_TAPI
  4268. if (tttapi && !tapipass )
  4269. printf(", modem: %s","TAPI");
  4270. else
  4271. #endif /* CK_TAPI */
  4272. printf(", modem: %s",gmdmtyp());
  4273. } else {
  4274. #ifdef NETCONN
  4275. if (nettype == NET_TCPA) printf(", TCP/IP");
  4276. if (nettype == NET_TCPB) printf(", TCP/IP");
  4277. if (nettype == NET_DEC) {
  4278. if (ttnproto == NP_LAT) printf(", DECnet LAT");
  4279. else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  4280. else printf(", DECnet");
  4281. }
  4282. if (nettype == NET_SLAT) printf(", Meridian Technologies' SuperLAT");
  4283. #ifdef NETFILE
  4284. if (nettype == NET_FILE) printf(", local file");
  4285. #endif /* NETFILE */
  4286. #ifdef NETCMD
  4287. if (nettype == NET_CMD) printf(", pipe");
  4288. #endif /* NETCMD */
  4289. #ifdef NETPTY
  4290. if (nettype == NET_PTY) printf(", pseudoterminal");
  4291. #endif /* NETPTY */
  4292. #ifdef NETDLL
  4293. if (nettype == NET_DLL) printf(", dynamic load library");
  4294. #endif /* NETDLL */
  4295. if (nettype == NET_PIPE) printf(", Named Pipes");
  4296. #ifdef SSHBUILTIN
  4297. if (nettype == NET_SSH)
  4298. printf(", Secure Shell protocol (SECURE)");
  4299. #endif /* SSHBUILTIN */
  4300. #ifdef ANYX25
  4301. if (shox25(0) < 0) return;
  4302. #endif /* ANYX25 */
  4303. if (IS_TELNET()) {
  4304. printf(", telnet protocol");
  4305. if (0
  4306. #ifdef CK_ENCRYPTION
  4307. || ck_tn_encrypting() && ck_tn_decrypting()
  4308. #endif /* CK_ENCRYPTION */
  4309. #ifdef CK_SSL
  4310. || tls_active_flag || ssl_active_flag
  4311. #endif /* CK_SSL */
  4312. )
  4313. printf(" (SECURE)");
  4314. }
  4315. #ifdef RLOGCODE
  4316. else if (ttnproto == NP_RLOGIN || ttnproto == NP_K4LOGIN ||
  4317. ttnproto == NP_K5LOGIN)
  4318. printf(", rlogin protocol");
  4319. else if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN)
  4320. printf(", rlogin protocol (SECURE)");
  4321. #endif /* RLOGCODE */
  4322. #ifdef CK_KERBEROS
  4323. #ifdef KRB5
  4324. else if (ttnproto == NP_K5U2U)
  4325. printf(", Kerberos 5 User to User protocol (SECURE)");
  4326. #endif /* KRB5 */
  4327. #endif /* CK_KERBEROS */
  4328. #endif /* NETCONN */
  4329. }
  4330. printf("\n");
  4331. if (hwparity && local && !network)
  4332. s = parnam((char)hwparity);
  4333. else
  4334. s = parnam((char)parity);
  4335. printf(" Parity: %s%s",hwparity ? "hardware " : "", s);
  4336. #ifndef NOLOCAL
  4337. if (local && !network) {
  4338. int sb;
  4339. char c;
  4340. c = s[0];
  4341. if (islower(c)) c = toupper(c);
  4342. sb = stopbits;
  4343. if (sb < 1) {
  4344. sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  4345. printf(", stop-bits: (default)");
  4346. } else {
  4347. printf(", stop-bits: %d",sb);
  4348. }
  4349. if (hwparity)
  4350. printf(" (8%c%d)",c,sb);
  4351. else if (parity)
  4352. printf(" (7%c%d)",c,sb);
  4353. else
  4354. printf(" (8N%d)",sb);
  4355. printf("\n D");
  4356. } else
  4357. printf(", d");
  4358. #endif /* NOLOCAL */
  4359. printf("uplex: %s, ", duplex ? "half" : "full");
  4360. debug(F101,"shoparp flow","",flow);
  4361. printf("flow: %s", floname[flow]);
  4362. printf(", handshake: ");
  4363. if (turn) printf("%d\n",turnch); else printf("none\n");
  4364. #ifdef COMMENT
  4365. if (local && !network) { /* SET CARRIER-WATCH */
  4366. #endif /* COMMENT */
  4367. if (carrier == CAR_OFF) s = "off";
  4368. else if (carrier == CAR_ON) s = "on";
  4369. else if (carrier == CAR_AUT) s = "auto";
  4370. else s = "unknown";
  4371. printf(" Carrier-watch: %s", s);
  4372. if (carrier == CAR_ON) {
  4373. if (cdtimo) printf(", timeout: %d sec", cdtimo);
  4374. else printf(", timeout: none");
  4375. }
  4376. #ifdef COMMENT
  4377. }
  4378. #endif /* COMMENT */
  4379. printf(", close-on-disconnect: %s\n",showoff(clsondisc));
  4380. #ifdef UNIX /* UUCP lockfile, UNIX only */
  4381. if (local) {
  4382. #ifndef NOUUCP
  4383. if (!network && haslock && *flfnam)
  4384. printf(" Lockfile: %s",flfnam);
  4385. #ifndef USETTYLOCK
  4386. if (!network && haslock && lock2[0])
  4387. printf("\n Secondary lockfile: %s",lock2);
  4388. #endif /* USETTYLOCK */
  4389. #else
  4390. #ifdef QNX
  4391. {
  4392. extern int qnxportlock, qnxopencount();
  4393. if (local)
  4394. printf(" Qnx-port-lock: %s, Open count: %d",
  4395. showoff(qnxportlock),
  4396. qnxopencount()
  4397. );
  4398. else
  4399. printf(" Qnx-port-lock: %s", showoff(qnxportlock));
  4400. }
  4401. #endif /* QNX */
  4402. #endif /* NOUUCP */
  4403. printf("\n");
  4404. } else {
  4405. char * s;
  4406. s = ttglckdir();
  4407. if (!s) s = "";
  4408. printf(" Lockfile directory: %s\n", *s ? s : "(none)");
  4409. }
  4410. #endif /* UNIX */
  4411. #ifndef MACOSX
  4412. if (!local) {
  4413. printf(" Typical port device name: %s\n",ttgtpn());
  4414. }
  4415. #endif /* MACOSX */
  4416. if (local) {
  4417. int i;
  4418. i = parity ? 7 : 8;
  4419. if (i == 8) i = (cmask == 0177) ? 7 : 8;
  4420. printf(" Terminal bytesize: %d,",i);
  4421. printf(" escape character: %d (^%c)\n",escape,ctl(escape));
  4422. }
  4423. }
  4424. int
  4425. shotcp(n) int n; {
  4426. #ifdef TCPSOCKET
  4427. if (nettype == NET_TCPA || nettype == NET_TCPB) {
  4428. printf("SET TCP parameters:\n");
  4429. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4430. printf(" Reverse DNS lookup: %s\n", showooa(tcp_rdns));
  4431. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4432. #ifdef CK_DNS_SRV
  4433. printf(" DNS Service Records lookup: %s\n", showooa(tcp_dns_srv));
  4434. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4435. #endif /* CK_DNS_SRV */
  4436. #ifndef NOTCPOPTS
  4437. #ifdef SOL_SOCKET
  4438. #ifdef SO_KEEPALIVE
  4439. printf(" Keepalive: %s\n", showoff(tcp_keepalive));
  4440. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4441. #endif /* SO_KEEPALIVE */
  4442. #ifdef SO_LINGER
  4443. printf(" Linger: %s", tcp_linger ? "on, " : "off\n" );
  4444. if (tcp_linger) {
  4445. if (tcp_linger_tmo)
  4446. printf("%d x 10 milliseconds\n",tcp_linger_tmo);
  4447. else
  4448. printf("no timeout\n");
  4449. }
  4450. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4451. #endif /* SO_LINGER */
  4452. #ifdef SO_DONTROUTE
  4453. printf(" DontRoute: %s\n", tcp_dontroute ? "on" : "off" );
  4454. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4455. #endif /* SO_DONTROUTE */
  4456. #ifdef TCP_NODELAY
  4457. printf(" Nodelay: %s\n", showoff(tcp_nodelay));
  4458. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4459. #endif /* TCP_NODELAY */
  4460. #ifdef SO_SNDBUF
  4461. if (tcp_sendbuf <= 0)
  4462. printf(" Send buffer: (default size)\n");
  4463. else
  4464. printf(" Send buffer: %d bytes\n", tcp_sendbuf);
  4465. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4466. #endif /* SO_SNDBUF */
  4467. #ifdef SO_RCVBUF
  4468. if (tcp_recvbuf <= 0)
  4469. printf(" Receive buffer: (default size)\n");
  4470. else
  4471. printf(" Receive buffer: %d bytes\n", tcp_recvbuf);
  4472. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4473. #endif /* SO_RCVBUF */
  4474. #endif /* SOL_SOCKET */
  4475. #endif /* NOTCPOPTS */
  4476. printf(" address: %s\n",tcp_address ? tcp_address : "(none)");
  4477. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4478. #ifndef NOHTTP
  4479. printf(" http-proxy: %s\n",tcp_http_proxy ? tcp_http_proxy : "(none)");
  4480. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4481. #endif /* NOHTTP */
  4482. #ifdef NT
  4483. #ifdef CK_SOCKS
  4484. printf(" socks-server: %s\n",tcp_socks_svr ? tcp_socks_svr : "(none)");
  4485. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4486. #ifdef CK_SOCKS_NS
  4487. printf(" socks-name-server: %s\n",
  4488. tcp_socks_ns ? tcp_socks_ns : "(none)");
  4489. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4490. #endif /* CK_SOCKS_NS */
  4491. #endif /* CK_SOCKS */
  4492. #endif /* NT */
  4493. }
  4494. #endif /* TCPSOCKET */
  4495. return(n);
  4496. }
  4497. #ifdef TNCODE
  4498. int
  4499. shotopt(n) int n; {
  4500. int opt;
  4501. printf("%-21s %12s %12s %12s %12s\n\n",
  4502. "Telnet Option","Me (client)","U (client)",
  4503. "Me (server)","U (server)");
  4504. n += 2;
  4505. if (n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4506. for ( opt = TELOPT_FIRST; opt <= TELOPT_LAST; opt++) {
  4507. switch (opt) {
  4508. case TELOPT_AUTHENTICATION:
  4509. case TELOPT_ENCRYPTION:
  4510. case TELOPT_TTYPE:
  4511. case TELOPT_NAWS:
  4512. case TELOPT_BINARY:
  4513. case TELOPT_NEWENVIRON:
  4514. case TELOPT_SNDLOC:
  4515. case TELOPT_XDISPLOC:
  4516. case TELOPT_SGA:
  4517. case TELOPT_ECHO:
  4518. case TELOPT_KERMIT:
  4519. case TELOPT_START_TLS:
  4520. case TELOPT_FORWARD_X:
  4521. case TELOPT_COMPORT:
  4522. break;
  4523. default:
  4524. continue;
  4525. }
  4526. printf("%03d %-17s ",
  4527. opt, TELOPT(opt)
  4528. );
  4529. printf("%12s %12s ",
  4530. TELOPT_MODE(TELOPT_DEF_C_ME_MODE(opt)),
  4531. TELOPT_MODE(TELOPT_DEF_C_U_MODE(opt))
  4532. );
  4533. printf("%12s %12s\n",
  4534. TELOPT_MODE(TELOPT_DEF_S_ME_MODE(opt)),
  4535. TELOPT_MODE(TELOPT_DEF_S_U_MODE(opt))
  4536. );
  4537. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4538. if (sstelnet)
  4539. printf("%21s %12s %12s %12s %12s\n",
  4540. "",
  4541. "",
  4542. "",
  4543. (TELOPT_ME(opt)?"WILL":"WONT"),
  4544. (TELOPT_U(opt)?"DO":"DONT")
  4545. );
  4546. else
  4547. printf("%21s %12s %12s %12s %12s\n",
  4548. "",
  4549. (TELOPT_ME(opt)?"WILL":"WONT"),
  4550. (TELOPT_U(opt)?"DO":"DONT"),
  4551. "",
  4552. ""
  4553. );
  4554. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4555. }
  4556. return(n);
  4557. }
  4558. int
  4559. shotel(n) int n; {
  4560. extern int tn_duplex;
  4561. #ifdef CK_ENVIRONMENT
  4562. extern int tn_env_flg;
  4563. extern char tn_env_acct[];
  4564. extern char tn_env_job[];
  4565. extern char tn_env_prnt[];
  4566. extern char tn_env_sys[];
  4567. extern char * tn_env_uservar[8][2];
  4568. int x;
  4569. #endif /* CK_ENVIRONMENT */
  4570. #ifdef CK_SNDLOC
  4571. extern char * tn_loc;
  4572. #endif /* CK_SNDLOC */
  4573. printf("SET TELNET parameters:\n echo: %s\n NVT newline-mode: ",
  4574. tn_duplex ? "local" : "remote");
  4575. switch (tn_nlm) {
  4576. case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4577. case TNL_CRLF: printf("%s\n","on (cr-lf)"); break;
  4578. case TNL_CR: printf("%s\n","raw (cr)"); break;
  4579. case TNL_LF: printf("%s\n","(lf)"); break;
  4580. }
  4581. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4582. #ifdef CK_AUTHENTICATION
  4583. {
  4584. int type = ck_tn_authenticated();
  4585. printf(" authentication: ");
  4586. switch (sstelnet ?
  4587. TELOPT_U_MODE(TELOPT_AUTHENTICATION) :
  4588. TELOPT_ME_MODE(TELOPT_AUTHENTICATION)
  4589. ) {
  4590. case TN_NG_AC: printf( "accepted " ); break;
  4591. case TN_NG_RF: printf( "refused " ); break;
  4592. case TN_NG_RQ: printf( "requested"); break;
  4593. case TN_NG_MU: printf( "required "); break;
  4594. }
  4595. #ifdef CK_SSL
  4596. if ((ssl_active_flag || tls_active_flag) &&
  4597. ck_tn_auth_valid() == AUTH_VALID &&
  4598. (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  4599. type == AUTHTYPE_NULL ||
  4600. type == AUTHTYPE_AUTO))
  4601. printf(" in use: X.509 certificate\n");
  4602. else
  4603. #endif /* CK_SSL */
  4604. printf(" in use: %s\n",AUTHTYPE_NAME(type));
  4605. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4606. if (forward_flag)
  4607. printf(" credentials forwarding requested %s\n",
  4608. forwarded_tickets ? "and completed" :
  4609. "but not completed");
  4610. else
  4611. printf(" credentials forwarding disabled\n");
  4612. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4613. }
  4614. #endif /* CK_AUTHENTICATION */
  4615. #ifdef CK_ENCRYPTION
  4616. {
  4617. int i,x;
  4618. int e_type = ck_tn_encrypting();
  4619. int d_type = ck_tn_decrypting();
  4620. char * e_str = NULL, * d_str = NULL;
  4621. static struct keytab * tnetbl = NULL;
  4622. static int ntnetbl = 0;
  4623. x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  4624. for (i = 0; i < ntnetbl; i++) {
  4625. if (e_type == tnetbl[i].kwval)
  4626. e_str = tnetbl[i].kwd;
  4627. if (d_type == tnetbl[i].kwval)
  4628. d_str = tnetbl[i].kwd;
  4629. }
  4630. printf(" encryption: ");
  4631. switch (TELOPT_ME_MODE(TELOPT_ENCRYPTION)) {
  4632. /* This should be changed to report both ME and U modes */
  4633. case TN_NG_AC: printf( "accepted " ); break;
  4634. case TN_NG_RF: printf( "refused " ); break;
  4635. case TN_NG_RQ: printf( "requested"); break;
  4636. case TN_NG_MU: printf( "required "); break;
  4637. }
  4638. printf(" in use: ");
  4639. switch ((e_type ? 1 : 0) | (d_type ? 2 : 0)) {
  4640. case 0:
  4641. printf("plain text in both directions");
  4642. break;
  4643. case 1:
  4644. printf("%s output, plain text input",e_str);
  4645. break;
  4646. case 2:
  4647. printf("plain text output, %s input",d_str);
  4648. break;
  4649. case 3:
  4650. printf("%s output, %s input",e_str,d_str);
  4651. break;
  4652. }
  4653. printf("\n");
  4654. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4655. }
  4656. #endif /* CK_ENCRYPTION */
  4657. #ifdef IKS_OPTION
  4658. printf(" kermit: ");
  4659. switch (TELOPT_U_MODE(TELOPT_KERMIT)) {
  4660. case TN_NG_AC: printf( "u, accepted; " ); break;
  4661. case TN_NG_RF: printf( "u, refused; " ); break;
  4662. case TN_NG_RQ: printf( "u, requested; "); break;
  4663. case TN_NG_MU: printf( "u, required; "); break;
  4664. }
  4665. switch (TELOPT_ME_MODE(TELOPT_KERMIT)) {
  4666. case TN_NG_AC: printf( "me, accepted; " ); break;
  4667. case TN_NG_RF: printf( "me, refused; " ); break;
  4668. case TN_NG_RQ: printf( "me, requested; "); break;
  4669. case TN_NG_MU: printf( "me, required; "); break;
  4670. }
  4671. if (TELOPT_U(TELOPT_KERMIT))
  4672. printf(" u, %s",
  4673. TELOPT_SB(TELOPT_KERMIT).kermit.u_start ?
  4674. "started" :
  4675. "stopped"
  4676. );
  4677. else
  4678. printf(" u, n/a");
  4679. if (TELOPT_ME(TELOPT_KERMIT))
  4680. printf(" me, %s;",
  4681. TELOPT_SB(TELOPT_KERMIT).kermit.me_start ?
  4682. "started" :
  4683. "stopped"
  4684. );
  4685. else
  4686. printf(" me, n/a;");
  4687. printf("\n");
  4688. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4689. #endif /* IKS_OPTION */
  4690. printf(" BINARY newline-mode: ");
  4691. switch (tn_b_nlm) {
  4692. case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4693. case TNL_CRLF: printf("%s\n","on (cr-lf)"); break;
  4694. case TNL_CR: printf("%s\n","raw (cr)"); break;
  4695. case TNL_LF: printf("%s\n","(lf)"); break;
  4696. }
  4697. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4698. printf(" binary-mode: ");
  4699. switch (TELOPT_U_MODE(TELOPT_BINARY)) {
  4700. case TN_NG_AC: printf( "u, accepted; " ); break;
  4701. case TN_NG_RF: printf( "u, refused; " ); break;
  4702. case TN_NG_RQ: printf( "u, requested; "); break;
  4703. case TN_NG_MU: printf( "u, required; "); break;
  4704. }
  4705. switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
  4706. case TN_NG_AC: printf( "me, accepted; " ); break ;
  4707. case TN_NG_RF: printf( "me, refused; " ); break;
  4708. case TN_NG_RQ: printf( "me, requested; "); break;
  4709. case TN_NG_MU: printf( "me, required; "); break;
  4710. }
  4711. printf("u, %s; me, %s\n",
  4712. TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
  4713. TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
  4714. );
  4715. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4716. printf(" binary-transfer-mode: %s\n",showoff(tn_b_xfer));
  4717. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4718. printf(" bug binary-me-means-u-too: %s\n",showoff(tn_b_meu));
  4719. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4720. printf(" bug binary-u-means-me-too: %s\n",showoff(tn_b_ume));
  4721. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4722. printf(" bug sb-implies-will-do: %s\n",showoff(tn_sb_bug));
  4723. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4724. printf(" bug auth-krb5-des: %s\n",showoff(tn_auth_krb5_des_bug));
  4725. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4726. printf(" terminal-type: ");
  4727. if (tn_term) {
  4728. printf("%s\n",tn_term);
  4729. } else {
  4730. char *p;
  4731. #ifdef OS2
  4732. p = (tt_type >= 0 && tt_type <= max_tt) ?
  4733. tt_info[tt_type].x_name :
  4734. "UNKNOWN";
  4735. #else
  4736. p = getenv("TERM");
  4737. #endif /* OS2 */
  4738. if (p)
  4739. printf("none (%s will be used)\n",p);
  4740. else printf("none\n");
  4741. }
  4742. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4743. #ifdef CK_ENVIRONMENT
  4744. printf(" environment: %s\n", showoff(tn_env_flg));
  4745. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4746. printf(" ACCOUNT: %s\n",tn_env_acct);
  4747. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4748. printf(" DISPLAY: %s\n",(char *)tn_get_display() ?
  4749. (char *)tn_get_display() : "");
  4750. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4751. printf(" JOB : %s\n",tn_env_job);
  4752. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4753. printf(" PRINTER: %s\n",tn_env_prnt);
  4754. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4755. #ifndef NOSPL
  4756. printf(" USER : %s\n",uidbuf);
  4757. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4758. #endif /* NOSPL */
  4759. printf(" SYSTEM : %s\n",tn_env_sys);
  4760. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4761. for (x = 0; x < 8; x++) {
  4762. if (tn_env_uservar[x][0] && tn_env_uservar[x][1]) {
  4763. printf(" %-7s: %s\n",tn_env_uservar[x][0],
  4764. tn_env_uservar[x][1]);
  4765. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4766. }
  4767. }
  4768. #endif /* CK_ENVIRONMENT */
  4769. #ifdef CK_SNDLOC
  4770. printf(" LOCATION: %s\n", tn_loc ? tn_loc : "");
  4771. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4772. #endif /* CK_SNDLOC */
  4773. #ifdef CK_FORWARD_X
  4774. printf(" .Xauthority-file: %s\n", (char *)XauFileName() ?
  4775. (char *)XauFileName() : "(none)");
  4776. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4777. #endif /* CK_FORWARD_X */
  4778. return(n);
  4779. }
  4780. #endif /* TNCODE */
  4781. #ifdef CK_NETBIOS
  4782. static int
  4783. shonb(n) int n; {
  4784. printf("NETBIOS parameters:\n");
  4785. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4786. printf(" API : %s\n",
  4787. NetbeuiAPI ?
  4788. "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
  4789. : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
  4790. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4791. printf(" Local Name: [%s]\n", NetBiosName);
  4792. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4793. printf(" Adapter : %d\n", NetBiosAdapter);
  4794. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4795. if (NetBiosLSN > 0xFF) {
  4796. printf(" Session : %d\n", NetBiosLSN);
  4797. } else {
  4798. printf(" Session : none active\n");
  4799. }
  4800. if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4801. return(n);
  4802. }
  4803. #endif /* CK_NETBIOS */
  4804. #ifndef NONET
  4805. int
  4806. shonet() {
  4807. #ifndef NETCONN
  4808. printf("\nNo networks are supported in this version of C-Kermit\n");
  4809. #else
  4810. #ifdef NOLOCAL
  4811. printf("\nNo networks are supported in this version of C-Kermit\n");
  4812. #else /* rest of this routine */
  4813. int i, n = 4;
  4814. #ifndef NODIAL
  4815. if (nnetdir <= 1) {
  4816. printf("\nNetwork directory: %s\n",netdir[0] ? netdir[0] : "(none)");
  4817. n++;
  4818. } else {
  4819. int i;
  4820. printf("\nNetwork directories:\n");
  4821. for (i = 0; i < nnetdir; i++) {
  4822. printf("%2d. %s\n",i,netdir[i]);
  4823. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4824. }
  4825. }
  4826. #endif /* NODIAL */
  4827. #ifdef SSHCMD
  4828. {
  4829. extern char * sshcmd;
  4830. printf("SSH COMMAND: %s\n",sshcmd ? sshcmd : "ssh -e none");
  4831. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4832. }
  4833. #endif /* SSHCMD */
  4834. #ifdef OS2
  4835. printf("\nNetwork availability:\n");
  4836. #else
  4837. printf("\nSupported networks:\n");
  4838. #endif /* OS2 */
  4839. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4840. #ifdef VMS
  4841. #ifdef TCPWARE
  4842. printf(" Process Software Corporation TCPware for OpenVMS");
  4843. #else
  4844. #ifdef MULTINET
  4845. printf(" TGV MultiNet TCP/IP");
  4846. #else
  4847. #ifdef WINTCP
  4848. printf(" WOLLONGONG WIN/TCP");
  4849. #else
  4850. #ifdef DEC_TCPIP
  4851. {
  4852. static $DESCRIPTOR(tcp_desc,"_TCP0:");
  4853. int status;
  4854. long devclass;
  4855. static int itmcod = DVI$_DEVCLASS;
  4856. #ifdef COMMENT
  4857. status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
  4858. #else
  4859. /* Martin Zinser 9/96 */
  4860. status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
  4861. #endif /* COMMENT */
  4862. if ((status & 1) && (devclass == DC$_SCOM))
  4863. printf(" Process Software Corporation TCPware for OpenVMS");
  4864. else
  4865. #ifdef UCX50
  4866. printf(" DEC TCP/IP Services for (Open)VMS 5.0");
  4867. #else
  4868. printf(" DEC TCP/IP Services for (Open)VMS");
  4869. #endif /* UCX50 */
  4870. }
  4871. #else
  4872. #ifdef CMU_TCPIP
  4873. printf(" CMU-OpenVMS/IP");
  4874. #else
  4875. printf(" None");
  4876. #endif /* CMU_TCPIP */
  4877. #endif /* DEC_TCPIP */
  4878. #endif /* WINTCP */
  4879. #endif /* MULTINET */
  4880. #endif /* TCPWARE */
  4881. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4882. #ifdef TNCODE
  4883. printf(", TELNET protocol\n\n");
  4884. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4885. n = shotel(n);
  4886. if (n < 0) return(0);
  4887. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4888. #endif /* TNCODE */
  4889. printf("\n");
  4890. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4891. printf("\n");
  4892. n = shotcp(++n);
  4893. if (n < 0) return(0);
  4894. #else /* Not VMS */
  4895. #ifdef SUNX25
  4896. printf(" SunLink X.25\n");
  4897. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4898. #endif /* SUNX25 */
  4899. #ifdef STRATUSX25
  4900. printf(" Stratus VOS X.25\n");
  4901. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4902. #endif /* STRATUSX25 */
  4903. #ifdef IBMX25
  4904. printf(" IBM AIX X.25\n");
  4905. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4906. #endif /* IBMX25 */
  4907. #ifdef HPX25
  4908. printf(" HP-UX X.25\n");
  4909. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4910. #endif /* HPX25 */
  4911. #ifdef SSHBUILTIN
  4912. if (ck_ssleay_is_installed())
  4913. printf(" SSH V1 and V2 protocols\n");
  4914. else
  4915. printf(" SSH V1 and V2 protocols - not available\n");
  4916. #endif /* SSHBUILTIN */
  4917. #ifdef DECNET
  4918. #ifdef OS2
  4919. #ifdef NT
  4920. if (dnet_avail)
  4921. printf(" DECnet, LAT and CTERM protocols\n");
  4922. else
  4923. printf(" DECnet, LAT and CTERM protocols - not available\n");
  4924. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4925. #else /* NT */
  4926. if (dnet_avail)
  4927. printf(" DECnet, LAT protocol\n");
  4928. else
  4929. printf(" DECnet, LAT protocol - not available\n");
  4930. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4931. #endif /* NT */
  4932. #else
  4933. printf(" DECnet\n");
  4934. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4935. #endif /* OS2 */
  4936. #endif /* DECNET */
  4937. #ifdef NPIPE
  4938. printf(" Named Pipes\n");
  4939. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4940. #endif /* NPIPE */
  4941. #ifdef CK_NETBIOS
  4942. if (netbiosAvail)
  4943. printf(" NETBIOS\n");
  4944. else
  4945. printf(" NETBIOS - not available\n");
  4946. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4947. #endif /* CK_NETBIOS */
  4948. #ifdef SUPERLAT
  4949. if (slat_avail)
  4950. printf(" SuperLAT\n");
  4951. else
  4952. printf(" SuperLAT - not available\n") ;
  4953. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4954. #endif /* SUPERLAT */
  4955. #ifdef TCPSOCKET
  4956. if (
  4957. #ifdef OS2
  4958. tcp_avail
  4959. #else
  4960. 1
  4961. #endif /* OS2 */
  4962. ) {
  4963. char ipaddr[16];
  4964. if (getlocalipaddrs(ipaddr,16,0) < 0) {
  4965. #ifdef OS2ONLY
  4966. printf(" TCP/IP via %s\n", tcpname);
  4967. #else
  4968. printf(" TCP/IP\n");
  4969. #endif /* OS2ONLY */
  4970. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4971. } else {
  4972. int i = 1;
  4973. #ifdef OS2ONLY
  4974. printf(" TCP/IP [%16s] via %s\n", ipaddr, tcpname);
  4975. #else
  4976. printf(" TCP/IP [%16s]\n",ipaddr);
  4977. #endif /* OS2ONLY */
  4978. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4979. while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
  4980. printf(" [%16s]\n",ipaddr);
  4981. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4982. }
  4983. }
  4984. if (nettype == NET_TCPB) {
  4985. printf("\n");
  4986. n = shotcp(++n);
  4987. if (n < 0) return(0);
  4988. #ifdef TNCODE
  4989. printf("\n");
  4990. n = shotel(++n);
  4991. if (n < 0) return(0);
  4992. #endif /* TNCODE */
  4993. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4994. }
  4995. #ifdef OS2
  4996. } else {
  4997. printf(" TCP/IP - not available%s\n",tcpname[0] ? tcpname : "" );
  4998. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4999. #endif /* OS2 */
  5000. }
  5001. #endif /* TCPSOCKET */
  5002. #ifdef CK_NETBIOS
  5003. if (netbiosAvail && nettype == NET_BIOS) {
  5004. printf("\n") ;
  5005. if ((n = shonb(++n)) < 0) return(0);
  5006. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5007. }
  5008. #endif /* CK_NETBIOS */
  5009. #endif /* VMS */
  5010. printf("\nActive network connection:\n");
  5011. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5012. if (network) {
  5013. printf(" Host: %s",ttname);
  5014. if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
  5015. printf(" [%s]",ipaddr);
  5016. } else
  5017. printf(" Host: none");
  5018. printf(", via: ");
  5019. if (nettype == NET_TCPA || nettype == NET_TCPB)
  5020. printf("tcp/ip\n");
  5021. else if (nettype == NET_SX25)
  5022. printf("SunLink X.25\n");
  5023. else if (nettype == NET_VX25)
  5024. printf("Stratus VOS X.25\n");
  5025. else if (nettype == NET_IX25)
  5026. printf("IBM AIX X.25\n");
  5027. else if (nettype == NET_HX25)
  5028. printf("HP-UX X.25\n");
  5029. else if (nettype == NET_DEC) {
  5030. if ( ttnproto == NP_LAT )
  5031. printf("DECnet LAT\n");
  5032. else if ( ttnproto == NP_CTERM )
  5033. printf("DECnet CTERM\n");
  5034. else
  5035. printf("DECnet\n");
  5036. } else if (nettype == NET_PIPE)
  5037. printf("Named Pipes\n");
  5038. else if (nettype == NET_BIOS)
  5039. printf("NetBIOS\n");
  5040. else if (nettype == NET_SLAT)
  5041. printf("SuperLAT\n");
  5042. #ifdef NETFILE
  5043. else if ( nettype == NET_FILE )
  5044. printf("local file\n");
  5045. #endif /* NETFILE */
  5046. #ifdef NETCMD
  5047. else if ( nettype == NET_CMD )
  5048. printf("pipe\n");
  5049. #endif /* NETCMD */
  5050. #ifdef NETPTY
  5051. else if ( nettype == NET_PTY )
  5052. printf("pseudoterminal\n");
  5053. #endif /* NETPTY */
  5054. #ifdef NETDLL
  5055. else if ( nettype == NET_DLL )
  5056. printf("dynamic link library\n");
  5057. #endif /* NETDLL */
  5058. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5059. #ifdef ANYX25
  5060. if ((nettype == NET_SX25) ||
  5061. (nettype == NET_VX25) ||
  5062. (nettype == NET_IX25))
  5063. if ((n = shox25(n)) < 0) return(0);
  5064. #endif /* ANYX25 */
  5065. #ifdef SSHBUILTIN
  5066. if (nettype == NET_SSH) {
  5067. printf("Secure Shell protocol\n");
  5068. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5069. }
  5070. #endif /* SSHBUILTIN */
  5071. if (nettype == NET_TCPA || nettype == NET_TCPB) {
  5072. #ifdef RLOGCODE
  5073. if (ttnproto == NP_RLOGIN) {
  5074. printf(" LOGIN (rlogin) protocol\n");
  5075. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5076. }
  5077. #ifdef CK_KERBEROS
  5078. else if (ttnproto == NP_K4LOGIN) {
  5079. printf(" Kerberos 4 LOGIN (klogin) protocol\n");
  5080. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5081. }
  5082. else if (ttnproto == NP_EK4LOGIN) {
  5083. printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocol\n");
  5084. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5085. }
  5086. else if (ttnproto == NP_K5LOGIN) {
  5087. printf(" Kerberos 5 LOGIN (klogin) protocol\n");
  5088. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5089. }
  5090. else if (ttnproto == NP_EK5LOGIN) {
  5091. printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocol\n");
  5092. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5093. }
  5094. #endif /* CK_KERBEROS */
  5095. #endif /* RLOGCODE */
  5096. #ifdef CK_KERBEROS
  5097. if (ttnproto == NP_K5U2U) {
  5098. printf(" Kerberos 5 User to User protocol\n");
  5099. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5100. }
  5101. #endif /* CK_KERBEROS */
  5102. #ifdef TNCODE
  5103. if (IS_TELNET()) {
  5104. printf(" TELNET protocol\n");
  5105. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5106. printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  5107. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5108. }
  5109. #endif /* TNCODE */
  5110. if (ttnproto == NP_TCPRAW) {
  5111. printf(" Raw TCP socket\n");
  5112. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5113. }
  5114. }
  5115. printf("\n");
  5116. #endif /* NOLOCAL */
  5117. #endif /* NETCONN */
  5118. return(0);
  5119. }
  5120. #endif /* NONET */
  5121. #ifndef NODIAL
  5122. VOID
  5123. shodial() {
  5124. if (mdmtyp >= 0 || local != 0) doshodial();
  5125. }
  5126. VOID
  5127. shods(s) char *s; { /* Show a dial-related string */
  5128. char c;
  5129. if (s == NULL || !(*s)) { /* Empty? */
  5130. printf("(none)\n");
  5131. } else { /* Not empty. */
  5132. while ((c = *s++)) /* Can contain controls */
  5133. if (c == '\\') /* a backslash */
  5134. printf("\\\\");
  5135. else if (c > 31 && c < 127) {
  5136. putchar(c);
  5137. } else
  5138. printf("\\{%d}",c);
  5139. printf("\n");
  5140. }
  5141. }
  5142. int
  5143. doshodial() {
  5144. int i, n = 2;
  5145. printf(" Dial status: %d", dialsta);
  5146. #ifdef BIGBUFOK
  5147. if (dialsta > 90)
  5148. printf(" = Unknown error");
  5149. else if (dialsta < 0)
  5150. printf(" = (none)");
  5151. else if (dialsta < 35 && dialmsg[dialsta])
  5152. printf(" = %s", dialmsg[dialsta]);
  5153. #endif /* BIGBUFOK */
  5154. n++;
  5155. if (ndialdir <= 1) {
  5156. printf("\n Dial directory: %s\n",dialdir[0] ? dialdir[0] : "(none)");
  5157. } else {
  5158. int i;
  5159. printf("\n Dial directories:\n");
  5160. for (i = 0; i < ndialdir; i++)
  5161. printf("%2d. %s\n",i+1,dialdir[i]);
  5162. n += ndialdir;
  5163. }
  5164. printf(" Dial method: ");
  5165. if (dialmauto) printf("auto ");
  5166. else if (dialmth == XYDM_D) printf("default");
  5167. else if (dialmth == XYDM_P) printf("pulse ");
  5168. else if (dialmth == XYDM_T) printf("tone ");
  5169. printf(" Dial sort: %s\n",dialsrt ? "on" : "off");
  5170. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5171. printf(" Dial hangup: %s Dial display: %s\n",
  5172. dialhng ? "on " : "off", dialdpy ? "on" : "off");
  5173. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5174. if (dialrtr > 0) {
  5175. printf(" Dial retries: %-12d Dial interval: %d\n",
  5176. dialrtr, dialint);
  5177. } else {
  5178. printf(" Dial retries: (auto) Dial interval: %d\n", dialint);
  5179. }
  5180. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5181. printf(" Dial timeout: ");
  5182. #ifdef CK_TAPI
  5183. if (tttapi && !tapipass)
  5184. printf("(tapi)");
  5185. else
  5186. #endif /* CK_TAPI */
  5187. if (dialtmo > 0)
  5188. printf("%4d sec", dialtmo);
  5189. else
  5190. printf("0 (auto)");
  5191. printf(" Redial number: %s\n",dialnum ? dialnum : "(none)");
  5192. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5193. printf(" Dial confirmation: %s Dial convert-directory: %s\n",
  5194. dialcnf ? "on " : "off",
  5195. dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
  5196. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5197. printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
  5198. printf(" Dial pacing: %d\n",dialpace);
  5199. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5200. printf(
  5201. " Dial prefix: %s\n", dialnpr ? dialnpr : "(none)");
  5202. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5203. printf(
  5204. " Dial suffix: %s\n", dialsfx ? dialsfx : "(none)");
  5205. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5206. printf(
  5207. " Dial country-code: %-12s", diallcc ? diallcc : "(none)");
  5208. printf("Dial connect: %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
  5209. : "off");
  5210. if (dialcon != CAR_OFF)
  5211. printf(" %s", dialcq ? "quiet" : "verbose");
  5212. printf(
  5213. "\n Dial area-code: %-12s", diallac ? diallac : "(none)");
  5214. n++;
  5215. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5216. printf("Dial restrict: ");
  5217. if (dialrstr == 5) printf("international\n");
  5218. else if (dialrstr == 4) printf("long-distance\n");
  5219. else if (dialrstr == 2) printf("local\n");
  5220. else if (dialrstr == 6) printf("none\n");
  5221. else printf("?\n");
  5222. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5223. printf(" Dial lc-area-codes: ");
  5224. if (nlocalac == 0)
  5225. printf("(none)");
  5226. else
  5227. for (i = 0; i < nlocalac; i++)
  5228. printf("%s ", diallcac[i]);
  5229. printf(
  5230. "\n Dial lc-prefix: %s\n", diallcp ? diallcp : "(none)");
  5231. n++;
  5232. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5233. printf(
  5234. " Dial lc-suffix: %s\n", diallcs ? diallcs : "(none)");
  5235. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5236. printf(
  5237. " Dial ld-prefix: %s\n", dialldp ? dialldp : "(none)");
  5238. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5239. printf(
  5240. " Dial ld-suffix: %s\n", diallds ? diallds : "(none)");
  5241. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5242. printf(
  5243. " Dial force-long-distance %s\n", showoff(dialfld));
  5244. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5245. printf(
  5246. " Dial intl-prefix: %s\n", dialixp ? dialixp : "(none)");
  5247. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5248. printf(
  5249. " Dial intl-suffix: %s\n", dialixs ? dialixs : "(none)");
  5250. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5251. printf(
  5252. " Dial toll-free-area-code: ");
  5253. if (ntollfree == 0)
  5254. printf("(none)");
  5255. else
  5256. for (i = 0; i < ntollfree; i++)
  5257. printf("%s ", dialtfc[i]);
  5258. printf("\n");
  5259. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5260. printf(
  5261. " Dial pulse-countries: ");
  5262. if (ndialpucc == 0)
  5263. printf("(none)");
  5264. else
  5265. for (i = 0; i < ndialpucc; i++)
  5266. printf("%s ", dialpucc[i]);
  5267. printf("\n");
  5268. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5269. printf(
  5270. " Dial tone-countries: ");
  5271. if (ndialtocc == 0)
  5272. printf("(none)");
  5273. else
  5274. for (i = 0; i < ndialtocc; i++)
  5275. printf("%s ", dialtocc[i]);
  5276. printf("\n");
  5277. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5278. printf(
  5279. " Dial toll-free-prefix: %s\n",
  5280. dialtfp ? dialtfp :
  5281. (dialldp ? dialldp : "(none)")
  5282. );
  5283. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5284. printf(" Dial pbx-exchange: ");
  5285. if (ndialpxx == 0)
  5286. printf("(none)");
  5287. else
  5288. for (i = 0; i < ndialpxx; i++)
  5289. printf("%s ", dialpxx[i]);
  5290. printf("\n");
  5291. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5292. printf(
  5293. " Dial pbx-inside-prefix: %s\n", dialpxi ? dialpxi : "(none)");
  5294. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5295. printf(
  5296. " Dial pbx-outside-prefix: %s\n", dialpxo ? dialpxo : "(none)");
  5297. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5298. printf(
  5299. " Dial macro: %s\n", dialmac ? dialmac : "(none)");
  5300. return(0);
  5301. }
  5302. #endif /* NODIAL */
  5303. #endif /* NOLOCAL */
  5304. /* Show File Parameters */
  5305. static char *
  5306. pathval(x) int x; {
  5307. switch (x) {
  5308. case PATH_OFF: return("off");
  5309. case PATH_ABS: return("absolute");
  5310. case PATH_REL: return("relative");
  5311. case PATH_AUTO: return("auto");
  5312. default: return("unknown");
  5313. }
  5314. }
  5315. VOID
  5316. shofil() {
  5317. char *s; int i = 0, n = 1;
  5318. extern char * ifdnam[];
  5319. extern int wildena;
  5320. #ifdef UNIX
  5321. extern int wildxpand;
  5322. #endif /* UNIX */
  5323. extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
  5324. #ifdef PATTERNS
  5325. extern int patterns;
  5326. #endif /* PATTERNS */
  5327. extern char * rfspec, * sfspec;
  5328. #ifdef UNIX
  5329. extern int zobufsize, zofbuffer, zofblock;
  5330. #endif /* UNIX */
  5331. #ifdef CK_CTRLZ
  5332. extern int eofmethod;
  5333. #endif /* CK_CTRLZ */
  5334. printf("\n");
  5335. #ifdef VMS
  5336. printf(" File record-Length: %5d\n",frecl);
  5337. n++;
  5338. #endif /* VMS */
  5339. #ifndef NOXFER
  5340. printf(" Transfer mode: %s\n",
  5341. xfermode == XMODE_A ?
  5342. "automatic" :
  5343. "manual"
  5344. );
  5345. n++;
  5346. #ifdef PATTERNS
  5347. printf(" File patterns: %s", showooa(patterns));
  5348. if (xfermode == XMODE_M && patterns)
  5349. printf(" (but disabled by TRANSFER-MODE MANUAL)");
  5350. else if (patterns)
  5351. printf(" (SHOW PATTERNS for list)");
  5352. printf("\n");
  5353. n++;
  5354. #endif /* PATTERNS */
  5355. if (filepeek)
  5356. printf(" File scan: on %d\n", nscanfile);
  5357. else
  5358. printf(" File scan: off\n");
  5359. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5360. if (xfermode == XMODE_A)
  5361. printf(" Default file type: %s\n",shoxm());
  5362. else
  5363. printf(" File type: %s\n",shoxm());
  5364. n++;
  5365. if (fncnv == XYFN_L)
  5366. s = "literal";
  5367. else if (fncnv == XYFN_C)
  5368. s = "converted";
  5369. else
  5370. s = "(unknown)";
  5371. printf(" File names: %s\n",s);
  5372. n++;
  5373. printf(" Send pathnames: %s\n", pathval(fnspath));
  5374. n++;
  5375. printf(" Receive pathnames: %s\n", pathval(fnrpath));
  5376. n++;
  5377. #ifdef UNIXOROSK
  5378. printf(" Match dot files: %s\n", matchdot ? "yes" : "no");
  5379. n++;
  5380. #ifdef UNIX
  5381. printf(" Wildcard-expansion: %s (%s)\n", showoff(wildena),
  5382. wildxpand ? "shell" : "kermit");
  5383. n++;
  5384. #endif /* UNIX */
  5385. #endif /* UNIXOROSK */
  5386. printf(" File collision: ");
  5387. for (i = 0; i < ncolx; i++)
  5388. if (colxtab[i].kwval == fncact) break;
  5389. printf("%s\n", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5390. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5391. printf(" File destination: %s\n",
  5392. (dest == DEST_D) ? "disk" :
  5393. ((dest == DEST_S) ? "screen" :
  5394. ((dest == DEST_N) ? "nowhere" :
  5395. "printer"))
  5396. );
  5397. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5398. s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
  5399. printf(" File incomplete: %s\n",s);
  5400. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5401. printf(" File bytesize: %d\n",(fmask == 0177) ? 7 : 8);
  5402. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5403. #ifndef NOCSETS
  5404. printf(" File character-set: %s\n",fcsinfo[fcharset].keyword);
  5405. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5406. printf(" File default 7-bit: %s\n",fcsinfo[dcset7].keyword);
  5407. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5408. printf(" File default 8-bit: %s\n",fcsinfo[dcset8].keyword);
  5409. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5410. #ifdef UNICODE
  5411. printf(" File UCS bom: %s\n",showoff(ucsbom));
  5412. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5413. printf(" File UCS byte-order: %s-endian\n",
  5414. ucsorder ? "little" : "big");
  5415. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5416. printf(" Computer byteorder: %s-endian\n",
  5417. byteorder ? "little" : "big");
  5418. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5419. #endif /* UNICODE */
  5420. #endif /* NOCSETS */
  5421. printf(" File end-of-line: ");
  5422. i = feol;
  5423. switch (feol) {
  5424. case XYFA_C: printf("%s\n","cr"); break;
  5425. case XYFA_L: printf("%s\n","lf"); break;
  5426. case XYFA_2: printf("%s\n","crlf"); break;
  5427. default: printf("%d\n",i);
  5428. }
  5429. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5430. #endif /* NOXFER */
  5431. #ifdef CK_CTRLZ
  5432. printf(" File eof: %s\n", eofmethod ? "ctrl-z" : "length");
  5433. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5434. #endif /* CK_CTRLZ */
  5435. #ifndef NOXFER
  5436. #ifdef CK_TMPDIR
  5437. printf(" File download-directory: %s\n", dldir ? dldir : "(none)");
  5438. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5439. #ifdef COMMENT
  5440. i = 256;
  5441. s = line;
  5442. zzstring("\\v(tmpdir)",&s,&i);
  5443. printf(" Temporary directory: %s\n", line);
  5444. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5445. #endif /* COMMENT */
  5446. #endif /* CK_TMPDIR */
  5447. #ifdef VMS
  5448. {
  5449. extern int vmssversions, vmsrversions;
  5450. printf(" Send version-numbers: %s\n",showoff(vmssversions));
  5451. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5452. printf(" Receive version-numbers: %s\n",showoff(vmsrversions));
  5453. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5454. }
  5455. #endif /* VMS */
  5456. printf(" Send move-to: %s\n",
  5457. snd_move ? snd_move : "(none)");
  5458. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5459. printf(" Send rename-to: %s\n",
  5460. snd_rename ? snd_rename : "(none)");
  5461. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5462. printf(" Receive move-to: %s\n",
  5463. rcv_move ? rcv_move : "(none)");
  5464. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5465. printf(" Receive rename-to: %s\n",
  5466. rcv_rename ? rcv_rename : "(none)");
  5467. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5468. #endif /* NOXFER */
  5469. #ifdef KERMRC
  5470. printf(" Initialization file: %s\n", noinit ? "(none)" :
  5471. #ifdef CK_SYSINI
  5472. CK_SYSINI
  5473. #else
  5474. kermrc
  5475. #endif /* CK_SYSINI */
  5476. );
  5477. #endif /* KERMRC */
  5478. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5479. if (k_info_dir) {
  5480. printf(" Kermit doc files: %s\n", k_info_dir);
  5481. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5482. }
  5483. #ifdef CKROOT
  5484. s = zgetroot();
  5485. printf(" Root set: %s\n", s ? s : "(none)");
  5486. #endif /* CKROOT */
  5487. #ifdef UNIX
  5488. printf(" Disk output buffer: %d (writes are %s, %s)\n",
  5489. zobufsize,
  5490. zofbuffer ? "buffered" : "unbuffered",
  5491. zofblock ? "blocking" : "nonblocking"
  5492. );
  5493. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5494. #ifdef DYNAMIC
  5495. printf(" Stringspace: %d\n", zsetfil(0,2));
  5496. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5497. printf(" Listsize: %d\n", zsetfil(0,4));
  5498. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5499. #endif /* DYNAMIC */
  5500. #endif /* UNIX */
  5501. #ifdef OS2ORUNIX
  5502. printf(" Longest filename: %d\n", maxnam);
  5503. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5504. printf(" Longest pathname: %d\n", maxpath);
  5505. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5506. #endif /* OS2ORUNIX */
  5507. printf(" Last file sent: %s\n", sfspec ? sfspec : "(none)");
  5508. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5509. printf(" Last file received: %s\n", rfspec ? rfspec : "(none)");
  5510. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5511. printf("\n Also see:\n");
  5512. n++;
  5513. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5514. printf(" SHOW PROTOCOL, SHOW XFER");
  5515. #ifdef CK_LABELED
  5516. printf(", SHOW LABELED");
  5517. #endif /* CK_LABELED */
  5518. #ifdef PATTERNS
  5519. printf(", SHOW PATTERNS");
  5520. #endif /* PATTERNS */
  5521. #ifdef STREAMING
  5522. printf(", SHOW STREAMING");
  5523. #endif /* STREAMING */
  5524. #ifndef NOCSETS
  5525. printf(", SHOW CHARACTER-SETS");
  5526. #endif /* NOCSETS */
  5527. printf("\n\n");
  5528. }
  5529. #ifndef NOXFER
  5530. VOID
  5531. shoparp() { /* Protocol */
  5532. extern int docrc, skipbup;
  5533. char *s;
  5534. #ifdef CK_TIMERS
  5535. extern int rttflg;
  5536. #endif /* CK_TIMERS */
  5537. printf("Protocol: %s\n",ptab[protocol].p_name);
  5538. if (protocol == PROTO_K) {
  5539. printf("\nProtocol Parameters: Send Receive");
  5540. if (timef)
  5541. printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  5542. else
  5543. printf("\n Timeout (used=%2d):%7d%9d ", timint, rtimo, pkttim);
  5544. #ifdef XFRCAN
  5545. printf(" Cancellation: %s",showoff(xfrcan));
  5546. if (xfrcan)
  5547. printf(" %d %d", xfrchr, xfrnum);
  5548. #endif /* XFRCAN */
  5549. printf("\n Padding: %11d%9d", npad, mypadn);
  5550. if (bctr == 4)
  5551. printf(" Block Check: blank-free-2\n");
  5552. else
  5553. printf(" Block Check: %6d\n",bctr);
  5554. printf( " Pad Character:%11d%9d", padch, mypadc);
  5555. printf(" Delay: %6d\n",ckdelay);
  5556. printf( " Pause: %11d%9d", pktpaus, pktpaus);
  5557. printf(" Attributes: %s\n",showoff(atcapr));
  5558. printf( " Packet Start: %11d%9d", mystch, stchr);
  5559. printf(" Max Retries: %6d%s\n",
  5560. maxtry,
  5561. (maxtry == 0) ? " (unlimited)" : ""
  5562. );
  5563. printf( " Packet End: %11d%9d", seol, eol);
  5564. if (ebqflg)
  5565. printf(" 8th-Bit Prefix: '%c'",ebq);
  5566. else
  5567. printf(" 8th-Bit Prefix: ('%c' but not used)",ebq);
  5568. printf( "\n Packet Length:%11d ", spmax);
  5569. printf("%8d ", urpsiz);
  5570. if (rptflg)
  5571. printf(" Repeat Prefix: '%c'",rptq);
  5572. else
  5573. printf(" Repeat Prefix: ('%c' but not used)",rptq);
  5574. printf( "\n Maximum Length: %9d%9d", maxsps, maxrps);
  5575. printf(" Window Size:%7d set, %d used\n",wslotr,wmax);
  5576. printf( " Buffer Size: %11d%9d", bigsbsiz, bigrbsiz);
  5577. printf(" Locking-Shift: ");
  5578. if (lscapu == 2) {
  5579. printf("forced");
  5580. } else {
  5581. printf("%s", (lscapr ? "enabled" : "disabled"));
  5582. if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  5583. }
  5584. printf("\n\n");
  5585. if (!(s = ptab[protocol].h_b_init)) s = "";
  5586. printf(" Auto-upload command (binary): ");
  5587. if (*s) {
  5588. shostrdef((CHAR *)s);
  5589. printf("\n");
  5590. } else {
  5591. printf("(none)\n");
  5592. }
  5593. if (!(s = ptab[protocol].h_t_init)) s = "";
  5594. printf(" Auto-upload command (text): ");
  5595. if (*s) {
  5596. shostrdef((CHAR *)s);
  5597. printf("\n");
  5598. } else {
  5599. printf("(none)\n");
  5600. }
  5601. if (!(s = ptab[protocol].h_x_init)) s = "";
  5602. printf(" Auto-server command: ");
  5603. if (*s) {
  5604. shostrdef((CHAR *)s);
  5605. printf("\n");
  5606. } else {
  5607. printf("(none)\n");
  5608. }
  5609. tmpbuf[0] = NUL;
  5610. #ifdef CK_TIMERS
  5611. if (rttflg) {
  5612. extern int mintime, maxtime;
  5613. sprintf(tmpbuf," Packet timeouts: dynamic %d:%d", /* SAFE */
  5614. mintime,
  5615. maxtime);
  5616. } else {
  5617. sprintf(tmpbuf," Packet timeouts: fixed"); /* SAFE */
  5618. }
  5619. #endif /* CK_TIMERS */
  5620. if (tmpbuf[0])
  5621. printf("%-31s",tmpbuf);
  5622. printf("Send backup: %s\n",showoff(!skipbup));
  5623. printf(" Transfer mode: %s", xfermode == XMODE_A ?
  5624. "automatic " :
  5625. "manual "
  5626. );
  5627. printf(" Transfer slow-start: %s, crc: %s\n",
  5628. showoff(slostart),
  5629. showoff(docrc)
  5630. );
  5631. #ifdef PIPESEND
  5632. {
  5633. extern int usepipes;
  5634. printf(" Transfer pipes: %s ",usepipes ? "on " : "off");
  5635. }
  5636. #endif /* PIPESEND */
  5637. #ifndef NOCSETS
  5638. printf(" Transfer character-set: ");
  5639. if (tcharset == TC_TRANSP)
  5640. printf("transparent\n");
  5641. else
  5642. printf("%s\n", tcsinfo[tcharset].keyword );
  5643. #endif /* NOCSETS */
  5644. #ifdef PIPESEND
  5645. {
  5646. extern char * sndfilter, * rcvfilter;
  5647. printf(" Send filter: %s\n", sndfilter ? sndfilter : "(none)");
  5648. printf(" Receive filter: %s\n", rcvfilter ? rcvfilter : "(none)");
  5649. }
  5650. #endif /* PIPESEND */
  5651. printf("\nAlso see:\n");
  5652. printf(" SHOW FILE, SHOW XFER");
  5653. #ifdef CK_LABELED
  5654. printf(", SHOW LABELED");
  5655. #endif /* CK_LABELED */
  5656. #ifdef PATTERNS
  5657. printf(", SHOW PATTERNS");
  5658. #endif /* PATTERNS */
  5659. #ifdef STREAMING
  5660. printf(", SHOW STREAMING");
  5661. #endif /* STREAMING */
  5662. #ifndef NOCSETS
  5663. printf(", SHOW CHARACTER-SETS");
  5664. #endif /* NOCSETS */
  5665. }
  5666. #ifdef CK_XYZ
  5667. #ifdef XYZ_INTERNAL
  5668. if (protocol != PROTO_K) {
  5669. int i;
  5670. int x;
  5671. printf(" File type: %s\n", binary ? "binary" : "text");
  5672. if (protocol == PROTO_Z) { /* Zmodem */
  5673. printf(" Window size: ");
  5674. if (ptab[protocol].winsize < 1)
  5675. printf("none\n");
  5676. else
  5677. printf("%d\n",wslotr);
  5678. #ifdef COMMENT
  5679. printf(" Packet (frame) length: ");
  5680. if (ptab[protocol].spktlen < 0)
  5681. printf("none\n");
  5682. else
  5683. printf("%d\n",spmax);
  5684. #endif /* COMMENT */
  5685. } else {
  5686. if (ptab[protocol].spktlen >= 1000)
  5687. printf(" 1K packets\n");
  5688. else
  5689. printf(" 128-byte packets\n");
  5690. }
  5691. printf(" Pathname stripping when sending: %s\n",
  5692. showoff(ptab[protocol].fnsp)
  5693. );
  5694. printf(" Pathname stripping when receiving: %s\n",
  5695. showoff(ptab[protocol].fnrp)
  5696. );
  5697. printf(" Filename collision action: ");
  5698. for (i = 0; i < ncolx; i++)
  5699. if (colxtab[i].kwval == fncact) break;
  5700. printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5701. printf("\n Escape control characters: ");
  5702. x = ptab[protocol].prefix;
  5703. if (x == PX_ALL)
  5704. printf("all\n");
  5705. else if (x == PX_CAU || x==PX_WIL)
  5706. printf("minimal\n");
  5707. else
  5708. printf("none\n");
  5709. if (!(s = ptab[protocol].h_b_init))
  5710. s = "";
  5711. printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5712. if (!(s = ptab[protocol].h_t_init))
  5713. s = "";
  5714. printf(" Autoreceive command (text): %s\n", *s ? s : "(none)");
  5715. }
  5716. #else
  5717. #ifndef NOPUSH
  5718. if (protocol != PROTO_K) {
  5719. _PROTOTYP( VOID shoextern, (void) );
  5720. printf("\nExecuted by external commands:\n\n");
  5721. s = ptab[protocol].p_b_scmd;
  5722. if (!s) s = "";
  5723. printf(" SEND command (binary): %s\n", *s ? s : "(none)");
  5724. s = ptab[protocol].p_t_scmd;
  5725. if (!s) s = "";
  5726. printf(" SEND command (text): %s\n", *s ? s : "(none)");
  5727. s = ptab[protocol].p_b_rcmd;
  5728. if (!s) s = "";
  5729. printf(" RECEIVE command (binary): %s\n", *s ? s : "(none)");
  5730. s = ptab[protocol].p_t_rcmd;
  5731. if (!s) s = "";
  5732. printf(" RECEIVE command (text): %s\n", *s ? s : "(none)");
  5733. s = ptab[protocol].h_b_init;
  5734. if (!s) s = "";
  5735. printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5736. s = ptab[protocol].h_t_init;
  5737. if (!s) s = "";
  5738. printf(" Autoreceive command (text): %s\n", *s ? s : "(none)");
  5739. (VOID) shoextern();
  5740. }
  5741. #endif /* NOPUSH */
  5742. #endif /* XYZ_INTERNAL */
  5743. #endif /* CK_XYZ */
  5744. }
  5745. #endif /* NOXFER */
  5746. #ifndef NOCSETS
  5747. /* Character-set items */
  5748. extern int s_cset, r_cset, axcset[], afcset[];
  5749. extern struct keytab xfrmtab[];
  5750. VOID
  5751. shoparl() {
  5752. #ifdef COMMENT
  5753. int i;
  5754. /* Misleading... */
  5755. printf("\nAvailable Languages:\n");
  5756. for (i = 0; i < MAXLANG; i++) {
  5757. printf(" %s\n",langs[i].description);
  5758. }
  5759. #else
  5760. printf("\nLanguage-specific translation rules: %s\n",
  5761. language == L_USASCII ? "none" : langs[language].description);
  5762. shocharset();
  5763. printf("\n\n");
  5764. #endif /* COMMENT */
  5765. }
  5766. VOID
  5767. shocharset() {
  5768. int x;
  5769. #ifdef COMMENT
  5770. char * s = "Unknown";
  5771. extern int xlatype;
  5772. #endif /* COMMENT */
  5773. #ifndef NOXFER
  5774. extern int xfrxla;
  5775. #endif /* NOXFER */
  5776. debug(F101,"SHOW FILE CHAR","",fcharset);
  5777. printf("\n");
  5778. #ifndef NOXFER
  5779. printf(" Transfer Translation: %s\n", showoff(xfrxla));
  5780. if (!xfrxla) {
  5781. printf(
  5782. " Because transfer translation is off, the following are ignored:\n\n");
  5783. }
  5784. #endif /* NOXFER */
  5785. printf(" File Character-Set: %s (%s), ",
  5786. fcsinfo[fcharset].keyword,
  5787. fcsinfo[fcharset].name
  5788. );
  5789. if ((x = fcsinfo[fcharset].size) == 128)
  5790. printf("7-bit");
  5791. else if (x == 256)
  5792. printf("8-bit");
  5793. else
  5794. printf("multibyte");
  5795. printf("\n");
  5796. printf(" File Scan: %s\n",showoff(filepeek));
  5797. printf(" Default 7bit-Character-Set: %s\n",fcsinfo[dcset7].keyword);
  5798. printf(" Default 8bit-Character-Set: %s\n",fcsinfo[dcset8].keyword);
  5799. printf(" Transfer Character-Set");
  5800. #ifdef COMMENT
  5801. if (tslevel == TS_L2)
  5802. printf(": (international)");
  5803. else
  5804. #endif /* COMMENT */
  5805. if (tcharset == TC_TRANSP)
  5806. printf(": Transparent");
  5807. else
  5808. printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
  5809. printf("\n");
  5810. #ifdef COMMENT
  5811. switch (xlatype) {
  5812. case XLA_NONE: s = "None"; break;
  5813. case XLA_BYTE: s = "Byte"; break;
  5814. case XLA_JAPAN: s = "Japanese"; break;
  5815. case XLA_UNICODE: s = "Unicode"; break;
  5816. }
  5817. printf("\n Translation type: %s\n",s);
  5818. #endif /* COMMENT */
  5819. printf(" SEND character-set-selection: %s\n",xfrmtab[s_cset].kwd);
  5820. printf(" RECEIVE character-set-selection: %s\n",xfrmtab[r_cset].kwd);
  5821. if (s_cset == XMODE_A || r_cset == XMODE_A)
  5822. printf(
  5823. " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)\n"
  5824. );
  5825. }
  5826. VOID
  5827. showassoc() {
  5828. int i, k, n = 4;
  5829. char * s;
  5830. printf("\nFor incoming files:\n\n");
  5831. printf("Transfer Character-Set File Character-Set\n");
  5832. for (i = 1; i <= MAXTCSETS; i++) {
  5833. k = axcset[i];
  5834. if (k < 0 || k > MAXFCSETS)
  5835. s = "(none)";
  5836. else
  5837. s = fcsinfo[k].keyword;
  5838. if (!s) s = "";
  5839. if (!*s) s = "(none)";
  5840. printf(" %-25s%s\n",tcsinfo[i].keyword,s);
  5841. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5842. }
  5843. printf("\nFor outbound files:\n\n");
  5844. n += 2;
  5845. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5846. printf("File Character-Set Transfer Character-Set\n");
  5847. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5848. for (i = 0; i <= MAXFCSETS; i++) {
  5849. k = afcset[i];
  5850. if (k < 0 || k > MAXTCSETS)
  5851. s = "(none)";
  5852. else
  5853. s = tcsinfo[k].keyword;
  5854. if (!s) s = "";
  5855. if (!*s) s = "(none)";
  5856. printf(" %-25s%s\n",fcsinfo[i].keyword,s);
  5857. if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5858. }
  5859. }
  5860. #endif /* NOCSETS */
  5861. VOID
  5862. shopar() {
  5863. printf("Show what? (Type \"show ?\" for a list of possibilities.)\n");
  5864. }
  5865. #endif /* NOSHOW */
  5866. #ifndef NOXFER
  5867. /* D O S T A T -- Display file transfer statistics. */
  5868. int
  5869. dostat(brief) int brief; {
  5870. extern long filrej, peakcps;
  5871. extern int lastspmax, streamed, cleared, streamok;
  5872. extern char whoareu[];
  5873. int n = 0, ftp = 0;
  5874. extern int docrc, interrupted, fatalio;
  5875. ftp = lastxfer & W_FTP;
  5876. #ifdef CK_TTGWSIZ
  5877. #ifdef OS2
  5878. if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  5879. ttgwsiz();
  5880. #else /* OS2 */
  5881. if (ttgwsiz() > 0) {
  5882. if (tt_rows > 0 && tt_cols > 0) {
  5883. cmd_rows = tt_rows;
  5884. cmd_cols = tt_cols;
  5885. }
  5886. }
  5887. #endif /* OS2 */
  5888. #endif /* CK_TTGWSIZ */
  5889. debug(F101,"dostat xferstat","",xferstat);
  5890. if (xferstat < 0) {
  5891. printf(" No file transfers yet.\n");
  5892. return(1);
  5893. }
  5894. n = 0;
  5895. if (brief) { printf("\n"); n++; };
  5896. printf(" protocol : %s\n",
  5897. ftp ? "ftp" : ptab[protocol].p_name);
  5898. n++;
  5899. printf(" status : ");
  5900. if (xferstat) printf("SUCCESS\n");
  5901. else if (interrupted) printf("FAILURE (interrupted)\n");
  5902. else if (fatalio) printf("FAILURE (i/o error)\n");
  5903. else printf("FAILURE\n");
  5904. #ifndef XYZ_INTERNAL
  5905. if (!ftp && protocol != PROTO_K) {
  5906. printf("\n external protocol statistics not available\n");
  5907. return(1);
  5908. }
  5909. #endif /* XYZ_INTERNAL */
  5910. n++;
  5911. if (!ftp) {
  5912. if (!xferstat > 0) {
  5913. if (docrc)
  5914. printf(" crc-16 of file(s) : %ld\n", crc16);
  5915. else
  5916. printf(" crc-16 of file(s) : (disabled)\n");
  5917. n++;
  5918. }
  5919. if (!xferstat && *epktmsg) {
  5920. printf(" reason : %s\n", epktmsg);
  5921. n++;
  5922. }
  5923. }
  5924. if (!brief) {
  5925. #ifdef NEWFTP
  5926. if (ftp) {
  5927. extern char ftp_srvtyp[];
  5928. printf(" remote system type : %s\n",ftp_srvtyp);
  5929. } else
  5930. #endif /* NEWFTP */
  5931. if (whoareu[0]) {
  5932. printf(" remote system type : %s\n",
  5933. getsysid((char *)whoareu));
  5934. n++;
  5935. }
  5936. printf(" files transferred : %ld\n",filcnt - filrej);
  5937. if (!ftp)
  5938. printf(" files not transferred : %ld\n",filrej);
  5939. printf(" characters last file : %s\n",ckfstoa(ffc));
  5940. printf(" total file characters : %s\n",ckfstoa(tfc));
  5941. n += ftp ? 3 : 4;
  5942. if (!ftp) {
  5943. printf(" communication line in : %s\n",ckfstoa(tlci));
  5944. printf(" communication line out : %s\n",ckfstoa(tlco));
  5945. printf(" packets sent : %d\n", spackets);
  5946. printf(" packets received : %d\n", rpackets);
  5947. n += 4;
  5948. }
  5949. }
  5950. if (ftp) goto dotimes;
  5951. printf(" damaged packets rec'd : %d\n", crunched);
  5952. printf(" timeouts : %d\n", timeouts);
  5953. printf(" retransmissions : %d\n", retrans);
  5954. n += 3;
  5955. if (!brief) {
  5956. if (filcnt > 0) {
  5957. printf(" parity : %s",parnam((char)parity));
  5958. n++;
  5959. if (autopar) { printf(" (detected automatically)"); n++; }
  5960. printf(
  5961. "\n control characters : %ld prefixed, %ld unprefixed\n",
  5962. ccp, ccu);
  5963. n++;
  5964. printf(" 8th bit prefixing : ");
  5965. n++;
  5966. if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  5967. n++;
  5968. printf(" locking shifts : %s\n", lscapu ? "yes" : "no");
  5969. n++;
  5970. }
  5971. }
  5972. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  5973. if (streamed > 0)
  5974. printf(" window slots used : (streaming)\n");
  5975. else
  5976. printf(" window slots used : %d of %d\n", wmax, wslotr);
  5977. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  5978. printf(" reliable: : %s%s\n",
  5979. streamok ? "" : "not ", "negotiated");
  5980. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  5981. printf(" clearchannel: : %s%s\n",
  5982. cleared ? "" : "not ", "negotiated");
  5983. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  5984. if (!brief) {
  5985. printf(" packet length : %d (send), %d (receive)\n",
  5986. lastspmax, urpsiz);
  5987. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  5988. printf(" compression : ");
  5989. if (rptflg)
  5990. printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  5991. else
  5992. printf("no\n");
  5993. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  5994. if (bctu == 4)
  5995. printf(" block check type used : blank-free-2\n");
  5996. else
  5997. printf(" block check type used : %d\n",bctu);
  5998. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  5999. }
  6000. dotimes:
  6001. #ifdef GFTIMER
  6002. #ifdef COMMENT
  6003. printf(" elapsed time : %0.3f sec, %s\n", fptsecs,hhmmss(tsecs));
  6004. #endif /* COMMENT */
  6005. printf(" elapsed time : %s (%0.3f sec)\n",
  6006. hhmmss((long)(fptsecs + 0.5)),fptsecs);
  6007. #else
  6008. #ifdef COMMENT
  6009. printf(" elapsed time : %s (%d sec)\n",hhmmss(tsecs),tsecs);
  6010. #endif /* COMMENT */
  6011. printf(" elapsed time : %d sec, %s\n",tsecs,hhmmss(tsecs));
  6012. #endif /* GFTIMER */
  6013. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6014. if (!ftp && local && !network && !brief) {
  6015. if (speed <= 0L) speed = ttgspd();
  6016. if (speed > 0L) {
  6017. if (speed == 8880)
  6018. printf(" transmission rate : 75/1200 bps\n");
  6019. else
  6020. printf(" transmission rate : %ld bps\n",speed);
  6021. if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6022. }
  6023. }
  6024. if (!ftp && local && !network && /* Only makes sense for */
  6025. mdmtyp == 0 && /* direct serial connections */
  6026. speed > 99L && /* when we really know the speed */
  6027. speed != 8880L
  6028. ) {
  6029. int eff;
  6030. eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
  6031. printf(" effective data rate : %ld cps (%d%%)\n",tfcps,eff);
  6032. } else
  6033. printf(" effective data rate : %ld cps\n", tfcps);
  6034. if (!ftp && peakcps > 0L && peakcps > tfcps)
  6035. printf(" peak data rate : %ld cps\n", peakcps);
  6036. if (brief)
  6037. printf("\nUse STATISTICS /VERBOSE for greater detail.\n\n");
  6038. return(1);
  6039. }
  6040. #endif /* NOXFER */
  6041. #ifndef NOSPL
  6042. /* The INPUT command */
  6043. /*
  6044. NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
  6045. material that has already arrived and is waiting to be read, and perform
  6046. matches against it, without doing any further reads. It should succeed
  6047. or fail instantaneously.
  6048. */
  6049. /* Output buffering for "doinput" */
  6050. #ifdef pdp11
  6051. #define MAXBURST 16 /* Maximum size of input burst */
  6052. #else
  6053. #define MAXBURST 1024
  6054. #endif /* pdp11 */
  6055. #ifdef OSK
  6056. static CHAR *conbuf; /* Buffer to hold output for console */
  6057. #else
  6058. static CHAR conbuf[MAXBURST]; /* Buffer to hold output for console */
  6059. #endif /* OSK */
  6060. static int concnt = 0; /* Number of characters buffered */
  6061. #ifdef OSK
  6062. static CHAR *sesbuf; /* Buffer to hold output for session log */
  6063. #else
  6064. static CHAR sesbuf[MAXBURST]; /* Buffer to hold output for session log */
  6065. #endif /* OSK */
  6066. static int sescnt = 0; /* Number of characters buffered */
  6067. extern int debses; /* TERMINAL DEBUG ON/OFF */
  6068. static VOID /* Flush INPUT echoing */
  6069. myflsh() { /* and session log output. */
  6070. if (concnt > 0) {
  6071. if (debses) { /* Terminal debugging? */
  6072. int i;
  6073. for (i = 0; i < concnt; i++)
  6074. conol(dbchr(conbuf[i]));
  6075. } else
  6076. conxo(concnt, (char *) conbuf);
  6077. concnt = 0;
  6078. }
  6079. if (sescnt > 0) {
  6080. logstr((char *) sesbuf, sescnt);
  6081. sescnt = 0;
  6082. }
  6083. }
  6084. /* Execute the INPUT and MINPUT commands */
  6085. int instatus = -1;
  6086. long inetime = -1L;
  6087. int inwait = 0;
  6088. int nowrap = 0;
  6089. /* For returning the input sequence that matched */
  6090. #ifdef BIGBUFOK
  6091. #define MATCHBUFSIZ 8191
  6092. #else
  6093. #define MATCHBUFSIZ 1023
  6094. #endif /* BIGBUFOK */
  6095. static char * matchbuf = NULL;
  6096. static int matchindex = 0;
  6097. static int burst = 0; /* Chars remaining in input burst */
  6098. /*
  6099. timo = How long to wait:
  6100. < 0 = Wait forever
  6101. 0 = Don't wait at all - material must already have arrived
  6102. > 0 = Wait this many seconds
  6103. ms = Array of strings to wait for.
  6104. mp = Array of flags.
  6105. If mp[i] == 0, ms[i] is literal, else it's a pattern.
  6106. flags = bit mask
  6107. INPSW_NOM = /NOMATCH = 1
  6108. INPSW_CLR = /CLEAR = 2
  6109. INPSW_NOW = /NOWRAP = 4
  6110. INPSW_COU = /COUNT = 8
  6111. count = /COUNT: value if a /COUNT switch was given.
  6112. Returns:
  6113. 0 on failure, 1 on success.
  6114. */
  6115. #ifndef ES_NORMAL
  6116. #define ES_NORMAL 0
  6117. #endif /* ES_NORMAL */
  6118. extern int inesc[], oldesc[];
  6119. int
  6120. doinput(timo,ms,mp,flags,count)
  6121. int timo; char *ms[]; int mp[]; int flags; int count; {
  6122. extern int inintr;
  6123. #ifdef CK_AUTODL
  6124. extern int inautodl;
  6125. #endif /* CK_AUTODL */
  6126. int x, y, i, t, rt, icn, anychar = 0, mi[MINPMAX];
  6127. #ifdef GFTIMER
  6128. CKFLOAT fpt = 0.0;
  6129. #endif /* GFTIMER */
  6130. int savecount = 0;
  6131. int nomatch = 0;
  6132. int clearfirst = 0;
  6133. int lastchar = 0;
  6134. int waiting = 0;
  6135. int imask = 0;
  6136. char ch, *xp, *s;
  6137. CHAR c;
  6138. #ifndef NOLOCAL
  6139. #ifdef OS2
  6140. extern int term_io;
  6141. int term_io_save;
  6142. #endif /* OS2 */
  6143. #endif /* NOLOCAL */
  6144. #ifdef TNCODE
  6145. static int cr = 0;
  6146. #endif /* TNCODE */
  6147. int is_tn = 0;
  6148. #ifdef SSHBUILTIN
  6149. extern int ssh_cas;
  6150. extern char * ssh_cmd;
  6151. #endif /* SSHBUILTIN */
  6152. int noescseq = 0; /* Filter escape sequences */
  6153. debug(F101,"input count","",count);
  6154. debug(F101,"input flags","",flags);
  6155. /*
  6156. CK_BURST enables the INPUT speedup code, which depends on ttchk() returning
  6157. accurate information. If INPUT fails with this code enabled, change the
  6158. above "#define" to "#undef".
  6159. */
  6160. #define CK_BURST
  6161. /***** CHANGE THIS TO A SET INPUT PARAMETER *****/
  6162. noescseq = (sessft == XYFT_T); /* Filter escape sequences */
  6163. imask = cmask;
  6164. if (parity) imask = 0x7f;
  6165. inwait = timo; /* For \v(inwait) */
  6166. /* Options from command switches */
  6167. nowrap = flags & INPSW_NOW; /* 4 = /NOWRAP */
  6168. nomatch = flags & INPSW_NOM; /* 1 = /NOMATCH */
  6169. clearfirst = flags & INPSW_CLR; /* 2 = /CLEAR */
  6170. savecount = count;
  6171. makestr(&inpmatch,NULL);
  6172. if (!matchbuf) {
  6173. matchbuf = malloc(MATCHBUFSIZ+1);
  6174. matchbuf[0] = NUL;
  6175. }
  6176. matchindex = 0;
  6177. /* If last time through we returned because of /NOWRAP and buffer full */
  6178. /* now we have to clear the buffer to make room for another load. */
  6179. if (nowrap && instatus == INP_BF)
  6180. clearfirst = 1;
  6181. if (clearfirst) { /* INPUT /CLEAR */
  6182. int i;
  6183. myflsh(); /* Flush screen and log buffers */
  6184. for (i = 0; i < inbufsize; i++)
  6185. inpbuf[i] = NUL;
  6186. inpbp = inpbuf;
  6187. }
  6188. is_tn =
  6189. #ifdef TNCODE
  6190. (local && network && IS_TELNET()) || (!local && sstelnet)
  6191. #else
  6192. 0
  6193. #endif /* TNCODE */
  6194. ;
  6195. #ifdef CK_SSL
  6196. if (is_tn) if (ssl_raw_flag || tls_raw_flag) is_tn = 0;
  6197. #endif /* CK_SSL */
  6198. instatus = INP_IE; /* 3 = internal error */
  6199. kbchar = 0;
  6200. #ifdef OSK
  6201. if (conbuf == NULL) {
  6202. if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
  6203. return(0);
  6204. }
  6205. sesbuf = conbuf + MAXBURST;
  6206. }
  6207. #endif /* OSK */
  6208. #ifndef NOLOCAL
  6209. if (local) { /* In local mode... */
  6210. if ((waiting = ttchk()) < 0) { /* check that connection is open */
  6211. if (!quiet) {
  6212. if ((!network
  6213. #ifdef TN_COMPORT
  6214. || istncomport()
  6215. #endif /* TN_COMPORT */
  6216. ) && carrier != CAR_OFF)
  6217. printf("?Carrier detect failure on %s.\n", ttname);
  6218. else
  6219. printf("?Connection %s %s is not open.\n",
  6220. network ? "to" : "on",
  6221. ttname
  6222. );
  6223. }
  6224. instatus = INP_IO;
  6225. return(0);
  6226. }
  6227. debug(F101,"doinput waiting","",waiting);
  6228. y = ttvt(speed,flow); /* Put line in "ttvt" mode */
  6229. if (y < 0) {
  6230. printf("?INPUT initialization error\n");
  6231. instatus = INP_IO;
  6232. return(0); /* Watch out for failure. */
  6233. }
  6234. }
  6235. #endif /* NOLOCAL */
  6236. #ifdef SSHBUILTIN
  6237. if ( network && nettype == NET_SSH && ssh_cas && ssh_cmd &&
  6238. !(strcmp(ssh_cmd,"kermit") && strcmp(ssh_cmd,"sftp"))) {
  6239. if (!quiet)
  6240. printf("?SSH Subsystem active: %s\n", ssh_cmd);
  6241. instatus = INP_IKS;
  6242. return(0);
  6243. }
  6244. #endif /* SSHBUILTIN */
  6245. debug(F111,"doinput ms[0]",ms[0],waiting);
  6246. if (!ms[0] || isemptystring(ms[0])) { /* No search string was given nor */
  6247. if (count < 2) /* a /COUNT: switch so we just */
  6248. anychar = 1; /* wait for the first character */
  6249. }
  6250. if (nomatch) anychar = 0; /* Don't match anything */
  6251. if (!anychar && waiting == 0 && timo == 0)
  6252. return(0);
  6253. #ifndef NODEBUG
  6254. if (deblog) {
  6255. char xbuf[100];
  6256. debug(F101,"doinput anychar","",anychar);
  6257. debug(F101,"doinput timo","",timo);
  6258. debug(F101,"doinput echo","",inecho);
  6259. #ifdef CK_BURST
  6260. debug(F101,"doinput burst","",burst);
  6261. #endif /* CK_BURST */
  6262. y = -1;
  6263. while (ms[++y]) {
  6264. sprintf(xbuf,"doinput string %2d",y); /* SAFE (24) */
  6265. debug(F111,xbuf,ms[y],mp[y]);
  6266. }
  6267. }
  6268. #endif /* NODEBUG */
  6269. #ifdef IKS_OPTION
  6270. if (is_tn) {
  6271. /* If the remote side is in a state of IKS START-SERVER */
  6272. /* we request that the state be changed. We will detect */
  6273. /* a failure to adhere to the request when we call ttinc() */
  6274. if (TELOPT_U(TELOPT_KERMIT) &&
  6275. TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  6276. iks_wait(KERMIT_REQ_STOP,0); /* Send Request-Stop */
  6277. #ifdef CK_AUTODL
  6278. /* If we are processing packets during INPUT and we have not */
  6279. /* sent a START message, do so now. */
  6280. if (inautodl && TELOPT_ME(TELOPT_KERMIT) &&
  6281. !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  6282. tn_siks(KERMIT_START); /* Send Kermit-Server Start */
  6283. }
  6284. #endif /* CK_AUTODL */
  6285. }
  6286. #endif /* IKS_OPTION */
  6287. x = 0; /* Return code, assume failure */
  6288. instatus = INP_TO; /* Status, assume timeout */
  6289. for (y = 0; y < MINPMAX; y++) /* Initialize... */
  6290. mi[y] = 0; /* ..string pattern match position */
  6291. if (!inpcas[cmdlvl]) { /* INPUT CASE = IGNORE? */
  6292. y = -1;
  6293. while ((xp = ms[++y])) { /* Convert each target to lowercase */
  6294. while (*xp) {
  6295. if (isupper(*xp)) *xp = (char) tolower(*xp);
  6296. xp++;
  6297. }
  6298. }
  6299. }
  6300. rtimer(); /* Reset timer. */
  6301. #ifdef GFTIMER
  6302. rftimer(); /* Floating-point timer too. */
  6303. #endif /* GFTIMER */
  6304. inetime = -1L; /* Initialize elapsed time. */
  6305. t = 0; /* Time now is 0. */
  6306. m_found = 0; /* Default to timed-out */
  6307. incount = 0; /* Character counter */
  6308. rt = (timo == 0) ? 0 : 1; /* Character-read timeout interval */
  6309. #ifndef NOLOCAL
  6310. #ifdef OS2
  6311. term_io_save = term_io; /* Disable I/O by emulator */
  6312. term_io = 0;
  6313. #endif /* OS2 */
  6314. #endif /* NOLOCAL */
  6315. while (1) { /* Character-getting loop */
  6316. #ifdef CK_APC
  6317. /* Check to see if there is an Autodown or other APC command */
  6318. if (apcactive == APC_LOCAL ||
  6319. (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
  6320. if (mlook(mactab,"_apc_commands",nmac) == -1) {
  6321. debug(F110,"doinput about to execute APC",apcbuf,0);
  6322. domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  6323. delmac("_apc_commands",1);
  6324. apcactive = APC_INACTIVE;
  6325. #ifdef DEBUG
  6326. } else {
  6327. debug(F100,"doinput APC in progress","",0);
  6328. #endif /* DEBUG */
  6329. }
  6330. }
  6331. #endif /* CK_APC */
  6332. if (timo == 0 && waiting < 1) { /* Special exit criterion */
  6333. instatus = INP_TO; /* for timeout == 0 */
  6334. break;
  6335. }
  6336. if (local) { /* One case for local */
  6337. y = ttinc(rt); /* Get character from comm device */
  6338. debug(F101,"doinput ttinc(rt) returns","",y);
  6339. if (y < -1) { /* Connection failed. */
  6340. instatus = INP_IO; /* Status = i/o error */
  6341. #ifndef NOLOCAL
  6342. #ifdef OS2
  6343. term_io = term_io_save;
  6344. #endif /* OS2 */
  6345. #endif /* NOLOCAL */
  6346. switch (y) {
  6347. case -2: /* Connection lost */
  6348. if (local && !network && carrier != CAR_OFF) {
  6349. dologend();
  6350. printf("Connection closed.\n");
  6351. ttclos(1);
  6352. }
  6353. break;
  6354. case -3:
  6355. dologend();
  6356. printf("Session Limit exceeded - closing connection.\n");
  6357. ttclos(1);
  6358. default:
  6359. break;
  6360. }
  6361. debug(F111,"doinput Connection failed","returning 0",y);
  6362. return(0);
  6363. }
  6364. if (inintr) {
  6365. debug(F111,"doinput","inintr",inintr);
  6366. if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
  6367. debug(F101,"input interrupted from keyboard","",icn);
  6368. kbchar = coninc(0);
  6369. if (kbchar >= 0) {
  6370. while (--icn > 0) {
  6371. debug(F110,"doinput","absorbing",0);
  6372. coninc(0); /* Yes, absorb what was typed. */
  6373. }
  6374. instatus = INP_UI; /* Fail and remember why. */
  6375. break;
  6376. }
  6377. }
  6378. }
  6379. } else { /* Another for remote */
  6380. y = coninc(rt);
  6381. debug(F101,"doinput coninc(rt) returns","",y);
  6382. }
  6383. if (y > -1) { /* A character arrived */
  6384. debug(F111,"doinput","a character arrived",y);
  6385. if (timo == 0)
  6386. waiting--;
  6387. #ifndef OS2
  6388. #define TN_NOLO
  6389. #endif /* OS2 */
  6390. #ifdef NOLOCAL
  6391. #define TN_NOLO
  6392. #endif /* NOLOCAL */
  6393. #ifdef TN_NOLO
  6394. debug(F100,"doinput TN_NOLO","",0);
  6395. #ifdef TNCODE
  6396. /* Check for telnet protocol negotiation */
  6397. if (is_tn) {
  6398. switch (y & 0xff) {
  6399. case IAC:
  6400. cr = 0;
  6401. myflsh(); /* Break from input burst for tn_doop() */
  6402. #ifdef CK_BURST
  6403. burst = 0;
  6404. #endif /* CK_BURST */
  6405. waiting -= 2; /* (not necessarily...) */
  6406. switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  6407. case 2: duplex = 0; continue;
  6408. case 1: duplex = 1; continue;
  6409. #ifdef IKS_OPTION
  6410. case 4:
  6411. if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6412. !tcp_incoming) {
  6413. instatus = INP_IKS;
  6414. printf(
  6415. " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6416. );
  6417. break;
  6418. }
  6419. continue;
  6420. #endif /* IKS_OPTION */
  6421. case 6: /* TELNET DO LOGOUT received */
  6422. continue;
  6423. case 7:
  6424. case 3: /* A quoted IAC */
  6425. break;
  6426. default:
  6427. continue;
  6428. }
  6429. case CR:
  6430. cr = 1;
  6431. break;
  6432. case NUL:
  6433. if (!TELOPT_U(TELOPT_BINARY) && cr) {
  6434. cr = 0;
  6435. continue;
  6436. }
  6437. cr = 0;
  6438. break;
  6439. default:
  6440. cr = 0;
  6441. }
  6442. /* I'm echoing remote chars */
  6443. if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6444. ttoc((char)y);
  6445. }
  6446. #endif /* TNCODE */
  6447. #ifdef CK_AUTODL
  6448. /* Check for file transfer packets */
  6449. if (inautodl) autodown(y);
  6450. #endif /* CK_AUTODL */
  6451. #else /* TN_NOLO */
  6452. debug(F100,"doinput !TN_NOLO","",0);
  6453. #ifdef TNCODE
  6454. /* Check for telnet protocol negotiation */
  6455. if (is_tn) {
  6456. int tx;
  6457. switch (y & 0xff) {
  6458. case IAC:
  6459. myflsh(); /* Break from input burst for tn_doop() */
  6460. #ifdef CK_BURST
  6461. burst = 0;
  6462. #endif /* CK_BURST */
  6463. #ifdef IKS_OPTION
  6464. tx = scriptwrtbuf((USHORT)y);
  6465. if (tx == 4) {
  6466. if (TELOPT_U(TELOPT_KERMIT) &&
  6467. TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6468. !tcp_incoming
  6469. ) {
  6470. instatus = INP_IKS;
  6471. printf(
  6472. " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6473. );
  6474. break;
  6475. }
  6476. } else if (tx == 6) {
  6477. /* TELNET DO LOGOUT received */
  6478. }
  6479. #else /* IKS_OPTION */
  6480. /* Handles Telnet negotiations */
  6481. tx = scriptwrtbuf((USHORT)y);
  6482. if (tx == 6) {
  6483. /* TELNET DO LOGOUT received */
  6484. }
  6485. #endif /* IKS_OPTION */
  6486. waiting -= 2; /* (not necessarily...) */
  6487. cr = 0;
  6488. continue; /* and autodownload check */
  6489. case CR:
  6490. cr = 1;
  6491. tx = scriptwrtbuf((USHORT)y);
  6492. if (tx == 6) {
  6493. /* TELNET DO LOGOUT received */
  6494. }
  6495. break;
  6496. case NUL:
  6497. cr = 0;
  6498. if (!TELOPT_U(TELOPT_BINARY) && cr)
  6499. continue;
  6500. tx = scriptwrtbuf((USHORT)y);
  6501. if (tx == 6) {
  6502. /* TELNET DO LOGOUT received */
  6503. }
  6504. break;
  6505. default:
  6506. cr = 0;
  6507. tx = scriptwrtbuf((USHORT)y);
  6508. if (tx == 6) {
  6509. /* TELNET DO LOGOUT received */
  6510. }
  6511. }
  6512. /* I'm echoing remote chars */
  6513. if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6514. ttoc((CHAR)y);
  6515. } else
  6516. #endif /* TNCODE */
  6517. /* Handles terminal emulation responses */
  6518. scriptwrtbuf((USHORT)y);
  6519. #endif /* TN_NOLO */
  6520. /* Real input character to be checked */
  6521. #ifdef CK_BURST
  6522. burst--; /* One less character waiting */
  6523. debug(F101,"doinput burst","",burst);
  6524. #endif /* CK_BURST */
  6525. c = (CHAR) (imask & (CHAR) y); /* Mask off any parity */
  6526. inchar[0] = c; /* Remember character for \v(inchar) */
  6527. #ifdef COMMENT
  6528. #ifdef CK_BURST
  6529. /* Update "lastchar" time only once during input burst */
  6530. if (burst <= 0)
  6531. #endif /* CK_BURST */
  6532. #endif /* COMMENT */
  6533. lastchar = gtimer(); /* Remember when it came */
  6534. if (c == '\0') { /* NUL, we can't use it */
  6535. if (anychar) { /* Except if any character will do? */
  6536. x = 1; /* Yes, done. */
  6537. instatus = INP_OK;
  6538. incount = 1; /* This must be the first and only. */
  6539. break;
  6540. } else goto refill; /* Otherwise continue INPUTting */
  6541. }
  6542. *inpbp++ = c; /* Store char in circular buffer */
  6543. incount++; /* Count it for \v(incount) */
  6544. if (flags & INPSW_COU) { /* INPUT /COUNT */
  6545. if (--count < 1) {
  6546. x = 1;
  6547. instatus = INP_OK;
  6548. incount = savecount;
  6549. break;
  6550. }
  6551. }
  6552. if (matchbuf) {
  6553. if (matchindex < MATCHBUFSIZ) {
  6554. matchbuf[matchindex++] = c;
  6555. matchbuf[matchindex] = NUL;
  6556. }
  6557. }
  6558. #ifdef MAC
  6559. {
  6560. extern char *ttermw; /* fake pointer cast */
  6561. if (inecho) {
  6562. outchar(ttermw, c); /* echo to terminal window */
  6563. /* this might be too much overhead to do here ? */
  6564. updatecommand(ttermw);
  6565. }
  6566. }
  6567. #else /* Not MAC */
  6568. if (inecho) { /* Buffer console output */
  6569. conbuf[concnt++] = c;
  6570. }
  6571. #endif /* MAC */
  6572. #ifndef OS2
  6573. if (seslog) {
  6574. int dummy = 0, skip = 0;
  6575. #ifndef NOLOCAL
  6576. if (noescseq) {
  6577. dummy = chkaes(c,0);
  6578. if (inesc[0] != ES_NORMAL || oldesc[0] != ES_NORMAL)
  6579. skip = 1;
  6580. }
  6581. #endif /* NOLOCAL */
  6582. #ifdef UNIXOROSK
  6583. if (sessft == XYFT_T) {
  6584. #ifdef UNIX
  6585. if (c == '\r')
  6586. #else
  6587. #ifdef OSK
  6588. if (c == '\012')
  6589. #endif /* OSK */
  6590. #endif /* UNIX */
  6591. skip = 1;
  6592. }
  6593. #endif /* UNIXOROSK */
  6594. if (!skip)
  6595. sesbuf[sescnt++] = c; /* Buffer session log output */
  6596. }
  6597. #endif /* OS2 */
  6598. if (anychar) { /* Any character will do? */
  6599. x = 1;
  6600. instatus = INP_OK;
  6601. break;
  6602. }
  6603. if (!inpcas[cmdlvl]) { /* Ignore alphabetic case? */
  6604. if (isupper(c)) /* Yes, convert input char to lower */
  6605. c = (CHAR) tolower(c);
  6606. }
  6607. debug(F000,"doinput char","",c);
  6608. /* Here is the matching section */
  6609. y = -1; /* Loop thru search strings */
  6610. while (!nomatch && (s = ms[++y])) { /* ...as many as we have. */
  6611. if (mp[y]) { /* Pattern match? */
  6612. #ifdef COMMENT
  6613. int j;
  6614. /* This is gross but it works... */
  6615. /* We could just as easily have prepended '*' to the */
  6616. /* pattern and skipped the loop, except then we would */
  6617. /* not have any way to identify the matching string. */
  6618. for (j = 0; j < matchindex; j++) {
  6619. if (ckmatch(s,&matchbuf[j],1,1)) {
  6620. matchindex = j;
  6621. instatus = INP_OK;
  6622. x = 1;
  6623. break;
  6624. }
  6625. }
  6626. if (x > 0)
  6627. break;
  6628. #else
  6629. /* July 2001 - ckmatch() returns match position. */
  6630. /* It works and it's not gross. */
  6631. /* (4 = floating pattern) */
  6632. x = ckmatch(s,matchbuf,inpcas[cmdlvl],1+4);
  6633. if (x > 0) {
  6634. matchindex = x - 1;
  6635. instatus = INP_OK;
  6636. x = 1;
  6637. break;
  6638. }
  6639. #endif /* COMMENT */
  6640. continue;
  6641. } /* Literal match. */
  6642. i = mi[y]; /* Match-position in search string. */
  6643. debug(F000,"compare char","",(CHAR)s[i]);
  6644. if (c == (CHAR) s[i]) { /* Check for match */
  6645. i++; /* Got one, go to next character */
  6646. } else { /* Don't have a match */
  6647. int j;
  6648. for (j = i; i > 0; ) { /* Back up in search string */
  6649. i--; /* (Do this here to prevent compiler foulup) */
  6650. /* j is the length of the substring that matched */
  6651. if (c == (CHAR) s[i]) {
  6652. if (!strncmp(s,&s[j-i],i)) {
  6653. i++; /* c actually matches -- cfk */
  6654. break;
  6655. }
  6656. }
  6657. }
  6658. }
  6659. if ((CHAR) s[i] == (CHAR) '\0') { /* Matched to end? */
  6660. ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
  6661. matchindex = 0;
  6662. instatus = INP_OK; /* Yes, */
  6663. x = 1;
  6664. break; /* done. */
  6665. }
  6666. mi[y] = i; /* No, remember match-position */
  6667. }
  6668. if (x == 1) { /* Set \v(minput) result */
  6669. instatus = INP_OK;
  6670. m_found = y + 1;
  6671. break;
  6672. }
  6673. if (inpbp >= inpbuf + inbufsize) { /* Reached end of buffer? */
  6674. if (nowrap) { /* If /NOWRAP...*/
  6675. instatus = INP_BF; /* ...return indicating buffer full. */
  6676. *inpbp = NUL;
  6677. goto xinput;
  6678. }
  6679. *inpbp = NUL; /* Make it null-terminated */
  6680. inpbp = inpbuf; /* Yes. */
  6681. }
  6682. }
  6683. #ifdef CK_BURST
  6684. else if (y <= -1 && burst > 0) {
  6685. debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
  6686. /* A timeout occurred so there can't */
  6687. burst = 0; /* be data waiting; must check timo */
  6688. }
  6689. refill:
  6690. if (burst <= 0) { /* No buffered chars remaining... */
  6691. myflsh(); /* Flush buffered output */
  6692. if (local) { /* Get size of next input burst */
  6693. burst = ttchk();
  6694. if (burst < 0) { /* ttchk() says connection is closed */
  6695. instatus = INP_IO; /* Status = i/o error */
  6696. #ifndef NOLOCAL
  6697. #ifdef OS2
  6698. term_io = term_io_save;
  6699. #endif /* OS2 */
  6700. #endif /* NOLOCAL */
  6701. if ((!network
  6702. #ifdef TN_COMPORT
  6703. || istncomport()
  6704. #endif /* TN_COMPORT */
  6705. ) && carrier != CAR_OFF) {
  6706. /* The test is written this way because the Microsoft compiler
  6707. * is producing bad code if written:
  6708. *
  6709. * if (network && (!istncomport() || carrier == CAR_OFF) )
  6710. */
  6711. break;
  6712. } else {
  6713. printf("Fatal error - disconnected.\n");
  6714. ttclos(1);
  6715. break;
  6716. }
  6717. }
  6718. if (inintr) {
  6719. if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
  6720. kbchar = coninc(0);
  6721. debug(F101,"input interrupted from keyboard","",icn);
  6722. while (--icn > 0) coninc(0); /* Yes, absorb chars. */
  6723. break; /* And fail. */
  6724. }
  6725. }
  6726. } else {
  6727. burst = conchk();
  6728. }
  6729. debug(F101,"doinput burst","",burst);
  6730. /* Prevent overflow of "conbuf" and "sesbuf" */
  6731. if (burst > MAXBURST)
  6732. burst = MAXBURST;
  6733. /* Did not match, timer exceeded? */
  6734. t = gtimer();
  6735. debug(F111,"doinput gtimer","burst",t);
  6736. debug(F101,"doinput timo","",timo);
  6737. if ((t >= timo) && (timo > 0))
  6738. break;
  6739. else if (insilence > 0 && (t - lastchar) > insilence)
  6740. break;
  6741. } else {
  6742. debug(F111,"doinput (burst > 0)","burst",burst);
  6743. }
  6744. #else /* CK_BURST */
  6745. refill:
  6746. myflsh(); /* Flush buffered output */
  6747. /* Did not match, timer exceeded? */
  6748. t = gtimer();
  6749. debug(F111,"doinput gtimer","no burst",t);
  6750. debug(F101,"doinput timo","",timo);
  6751. if ((t >= timo) && (timo > -1))
  6752. break;
  6753. else if (insilence > 0 && (t - lastchar) > insilence)
  6754. break;
  6755. #endif /* CK_BURST */
  6756. } /* Still have time left, continue. */
  6757. xinput:
  6758. myflsh(); /* Flush buffered output */
  6759. if (instatus == INP_BF) { /* Buffer full and /NOWAIT */
  6760. x = 0; /* Must not succeed */
  6761. } else { /* Buffer full and /NOWAIT */
  6762. if (nomatch) x = 1; /* Succeed if nomatch and timed out */
  6763. if (x > 0 && !nomatch)
  6764. instatus = 0;
  6765. }
  6766. #ifndef NOLOCAL
  6767. #ifdef OS2
  6768. term_io = term_io_save;
  6769. #endif /* OS2 */
  6770. #endif /* NOLOCAL */
  6771. #ifdef COMMENT
  6772. #ifdef IKS_OPTION
  6773. #ifdef CK_AUTODL
  6774. if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
  6775. tn_siks(KERMIT_STOP); /* Send Kermit-Server Stop */
  6776. }
  6777. #endif /* CK_AUTODL */
  6778. #endif /* IKS_OPTION */
  6779. #endif /* COMMENT */
  6780. #ifdef GFTIMER
  6781. fpt = gftimer(); /* Get elapsed time */
  6782. /* If a long is 32 bits, it would take about 50 days for this to overflow. */
  6783. inetime = (int)(fpt * (CKFLOAT)1000.0);
  6784. #else
  6785. inetime = (int)(gtimer() * 1000);
  6786. #endif /* GFTIMER */
  6787. if (x > 0)
  6788. makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  6789. return(x); /* Return the return code. */
  6790. }
  6791. #endif /* NOSPL */
  6792. #ifndef NOSPL
  6793. /* REINPUT Command */
  6794. /*
  6795. Note, the timeout parameter is required, but ignored. Syntax is compatible
  6796. with MS-DOS Kermit except timeout can't be omitted. This function only
  6797. looks at the characters already received and does not read any new
  6798. characters from the connection.
  6799. */
  6800. int
  6801. doreinp(timo,s,pat) int timo; char *s; int pat; {
  6802. int x, y, i;
  6803. char *xx, *xp, *xq = (char *)0;
  6804. CHAR c;
  6805. if (!s) s = "";
  6806. debug(F101,"doreinput pat","",pat);
  6807. y = (int)strlen(s);
  6808. debug(F111,"doreinput search",s,y);
  6809. if (y > inbufsize) { /* If search string longer than */
  6810. debug(F101,"doreinput inbufsize","",inbufsize);
  6811. return(0); /* input buffer, fail. */
  6812. }
  6813. makestr(&inpmatch,NULL);
  6814. if (!matchbuf)
  6815. matchbuf = malloc(MATCHBUFSIZ+1);
  6816. matchindex = 0;
  6817. x = 0; /* Return code, assume failure */
  6818. i = 0; /* String pattern match position */
  6819. if (!inpcas[cmdlvl]) { /* INPUT CASE = IGNORE? */
  6820. xp = malloc(y+2); /* Make a separate copy of the */
  6821. if (!xp) { /* search string. */
  6822. printf("?malloc error 6\n");
  6823. return(x);
  6824. } else xq = xp; /* Keep pointer to beginning. */
  6825. while (*s) { /* Yes, convert to lowercase */
  6826. *xp = *s;
  6827. if (isupper(*xp)) *xp = (char) tolower(*xp);
  6828. xp++; s++;
  6829. }
  6830. *xp = NUL; /* Terminate it! */
  6831. s = xq; /* Move search pointer to it. */
  6832. }
  6833. xx = *inpbp ? inpbp : inpbuf; /* Current INPUT buffer pointer */
  6834. do {
  6835. c = *xx++; /* Get next character */
  6836. if (!c) break;
  6837. if (xx >= inpbuf + inbufsize) /* Wrap around if necessary */
  6838. xx = inpbuf;
  6839. if (!inpcas[cmdlvl]) { /* Ignore alphabetic case? */
  6840. if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
  6841. }
  6842. if (pat) {
  6843. int j;
  6844. if (matchbuf) {
  6845. if (matchindex < MATCHBUFSIZ) {
  6846. matchbuf[matchindex++] = c;
  6847. matchbuf[matchindex] = NUL;
  6848. }
  6849. for (j = 0; j < matchindex; j++) { /* Gross but effective */
  6850. if (ckmatch(s,&matchbuf[j],1,1)) {
  6851. debug(F101,"GOT IT","",j);
  6852. matchindex = j;
  6853. x = 1;
  6854. break;
  6855. }
  6856. }
  6857. }
  6858. if (x > 0)
  6859. break;
  6860. continue;
  6861. }
  6862. debug(F000,"doreinp char","",c);
  6863. debug(F000,"compare char","",(CHAR) s[i]);
  6864. if (((char) c) == ((char) s[i])) { /* Check for match */
  6865. i++; /* Got one, go to next character */
  6866. } else { /* Don't have a match */
  6867. int j;
  6868. for (j = i; i > 0; ) { /* [jrs] search backwards for it */
  6869. i--;
  6870. if (((char) c) == ((char) s[i])) {
  6871. if (!strncmp(s,&s[j-i],i)) {
  6872. i++;
  6873. break;
  6874. }
  6875. }
  6876. }
  6877. } /* [jrs] or return to zero from -1 */
  6878. if (s[i] == '\0') { /* Matched all the way to end? */
  6879. ckstrncpy(matchbuf,s,MATCHBUFSIZ);
  6880. matchindex = 0;
  6881. x = 1; /* Yes, */
  6882. break; /* done. */
  6883. }
  6884. } while (xx != inpbp && x < 1); /* Until back where we started. */
  6885. if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  6886. makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  6887. return(x); /* Return search result. */
  6888. }
  6889. /* X X S T R I N G -- Interpret strings containing backslash escapes */
  6890. /* Z Z S T R I N G -- (new name...) */
  6891. /*
  6892. Copies result to new string.
  6893. strips enclosing braces or doublequotes.
  6894. interprets backslash escapes.
  6895. returns 0 on success, nonzero on failure.
  6896. tries to be compatible with MS-DOS Kermit.
  6897. Syntax of input string:
  6898. string = chars | "chars" | {chars}
  6899. chars = (c*e*)*
  6900. where c = any printable character, ascii 32-126
  6901. and e = a backslash escape
  6902. and * means 0 or more repetitions of preceding quantity
  6903. backslash escape = \operand
  6904. operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  6905. number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  6906. radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
  6907. */
  6908. #ifndef NOFRILLS
  6909. int
  6910. yystring(s,s2) char *s; char **s2; { /* Reverse a string */
  6911. int x;
  6912. static char *new;
  6913. new = *s2;
  6914. if (!s || !new) return(-1); /* Watch out for null pointers. */
  6915. if ((x = (int)strlen(s)) == 0) { /* Recursion done. */
  6916. *new = '\0';
  6917. return(0);
  6918. }
  6919. x--; /* Otherwise, call self */
  6920. *new++ = s[x]; /* to reverse rest of string. */
  6921. s[x] = 0;
  6922. return(yystring(s,&new));
  6923. }
  6924. #endif /* NOFRILLS */
  6925. static char ipabuf[16] = { NUL }; /* IP address buffer */
  6926. static char *
  6927. getip(s) char *s; {
  6928. char c=NUL; /* Workers... */
  6929. int i=0, p=0, d=0;
  6930. int state = 0; /* State of 2-state FSA */
  6931. while ((c = *s++)) {
  6932. switch(state) {
  6933. case 0: /* Find first digit */
  6934. i = 0; /* Output buffer index */
  6935. ipabuf[i] = NUL; /* Initialize output buffer */
  6936. p = 0; /* Period counter */
  6937. d = 0; /* Digit counter */
  6938. if (isdigit(c)) { /* Have first digit */
  6939. d = 1; /* Count it */
  6940. ipabuf[i++] = c; /* Copy it */
  6941. state = 1; /* Change state */
  6942. }
  6943. break;
  6944. case 1: /* In numeric field */
  6945. if (isdigit(c)) { /* Have digit */
  6946. if (++d > 3) /* Too many */
  6947. state = 0; /* Start over */
  6948. else /* Not too many */
  6949. ipabuf[i++] = c; /* Keep it */
  6950. } else if (c == '.' && p < 3) { /* Have a period */
  6951. p++; /* Count it */
  6952. if (d == 0) /* Not preceded by a digit */
  6953. state = 0; /* Start over */
  6954. else /* OK */
  6955. ipabuf[i++] = c; /* Keep it */
  6956. d = 0; /* Reset digit counter */
  6957. } else if (p == 3 && d > 0) { /* Not part of address */
  6958. ipabuf[i] = NUL; /* If we have full IP address */
  6959. return((char *)ipabuf); /* Return it */
  6960. } else { /* Otherwise */
  6961. state = 0; /* Start over */
  6962. ipabuf[0] = NUL; /* (in case no more chars left) */
  6963. }
  6964. }
  6965. } /* Fall thru at end of string */
  6966. ipabuf[i] = NUL; /* Maybe we have one */
  6967. return((p == 3 && d > 0) ? (char *)ipabuf : "");
  6968. }
  6969. #endif /* NOSPL */
  6970. /* Date Routines */
  6971. /* Z J D A T E -- Convert yyyymmdd date to Day of Year */
  6972. static int jdays[12] = { 0,31,59,90,120,151,181,212,243,273,304,334 };
  6973. static int ldays[12] = { 0,31,60,91,121,152,182,213,244,274,305,335 };
  6974. static char zjdbuf[12] = { NUL, NUL };
  6975. /*
  6976. Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
  6977. statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
  6978. praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
  6979. fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
  6980. consequentur centesimi non omnes bissextiles sint, sed in quadringentis
  6981. quibusque annis primi quique tres centesimi sine bissexto transigantur,
  6982. quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
  6983. MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
  6984. intercaletur, februario dies XXIX continente, idemque ordo intermittendi
  6985. intercalandique bissextum diem in quadringentis quibusque annis perpetuo
  6986. conservetur. - Gregorius XIII, Anno Domini MDLXXXII.
  6987. */
  6988. char *
  6989. zjdate(date) char * date; { /* date = yyyymmdd */
  6990. char year[5];
  6991. char month[3];
  6992. char day[3];
  6993. int d, m, x, y;
  6994. int leapday, j;
  6995. char * time = NULL;
  6996. if (!date) date = ""; /* Validate arg */
  6997. x = strlen(date);
  6998. if (x < 1) return("0");
  6999. if (x < 8) return("-1");
  7000. for (x = 0; x < 8; x++)
  7001. if (!isdigit(date[x]))
  7002. return("-1");
  7003. if (date[8]) if (date[9])
  7004. time = date + 9;
  7005. year[0] = date[0]; /* Isolate year */
  7006. year[1] = date[1];
  7007. year[2] = date[2];
  7008. year[3] = date[3];
  7009. year[4] = '\0';
  7010. month[0] = date[4]; /* Month */
  7011. month[1] = date[5];
  7012. month[2] = '\0';;
  7013. day[0] = date[6]; /* And day */
  7014. day[1] = date[7];
  7015. day[2] = '\0';
  7016. leapday = 0; /* Assume no leap day */
  7017. y = atoi(year);
  7018. m = atoi(month);
  7019. d = atoi(day);
  7020. if (m > 2) { /* No Leap day before March */
  7021. if (y % 4 == 0) { /* If year is divisible by 4 */
  7022. leapday = 1; /* It's a Leap year */
  7023. if (y % 100 == 0) { /* Except if divisible by 100 */
  7024. if (y % 400 != 0) /* but not by 400 */
  7025. leapday = 0;
  7026. }
  7027. }
  7028. }
  7029. j = jdays[m - 1] + d + leapday; /* Day of year */
  7030. if (time)
  7031. sprintf(zjdbuf,"%04d%03d %s",y,j,time); /* SAFE */
  7032. else
  7033. sprintf(zjdbuf,"%04d%03d",y,j); /* SAFE */
  7034. return((char *)zjdbuf);
  7035. }
  7036. static char jzdbuf[32];
  7037. /* J Z D A T E -- Convert Day of Year to yyyyddmm date */
  7038. char *
  7039. jzdate(date) char * date; { /* date = yyyyddd */
  7040. char year[5]; /* with optional time */
  7041. char day[4];
  7042. char * time = NULL, * p;
  7043. int d, m, x, y;
  7044. int leapday, j;
  7045. int * zz;
  7046. if (!date) date = ""; /* Validate arg */
  7047. x = strlen(date);
  7048. debug(F111,"jzdate len",date,x);
  7049. if (x < 1) return("0");
  7050. if (x < 7) return("-1");
  7051. if (x > 8) time = date + 8;
  7052. for (x = 0; x < 7; x++)
  7053. if (!isdigit(date[x]))
  7054. return("-1");
  7055. year[0] = date[0]; /* Isolate year */
  7056. year[1] = date[1];
  7057. year[2] = date[2];
  7058. year[3] = date[3];
  7059. year[4] = '\0';
  7060. debug(F110,"jzdate year",year,0);
  7061. day[0] = date[4]; /* And day */
  7062. day[1] = date[5];
  7063. day[2] = date[6];
  7064. day[3] = '\0';
  7065. debug(F110,"jzdate day",day,0);
  7066. j = atoi(day);
  7067. if (j > 366)
  7068. return("-1");
  7069. leapday = 0; /* Assume no leap day */
  7070. y = atoi(year);
  7071. if (y % 4 == 0) { /* If year is divisible by 4 */
  7072. leapday = 1; /* It's a Leap year */
  7073. if (y % 100 == 0) { /* Except if divisible by 100 */
  7074. if (y % 400 != 0) /* but not by 400 */
  7075. leapday = 0;
  7076. }
  7077. }
  7078. debug(F101,"jzdate leapday","",leapday);
  7079. zz = leapday ? ldays : jdays;
  7080. for (x = 0; x < 11; x++)
  7081. if (j > zz[x] && j <= zz[x+1])
  7082. break;
  7083. m = x + 1;
  7084. debug(F101,"jzdate m","",m);
  7085. d = j - zz[x];
  7086. debug(F101,"jzdate d","",d);
  7087. if (time)
  7088. sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time); /* SAFE */
  7089. else
  7090. sprintf(jzdbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7091. debug(F101,"jzdate jzdbuf",jzdbuf,0);
  7092. p = ckcvtdate((char *)jzdbuf, 0); /* Convert to standard form */
  7093. ckstrncpy(jzdbuf,p,32);
  7094. if (!time) jzdbuf[8] = NUL; /* Remove time if not wanted */
  7095. return((char *)jzdbuf);
  7096. }
  7097. /* M J D -- Modified Julian Date */
  7098. /*
  7099. Call with:
  7100. Standard-format date-time string: yyyymmdd[ hh:mm:ss].
  7101. The time, if any, is ignored.
  7102. Returns:
  7103. -1L on error, otherwise:
  7104. The number of days since 17 Nov 1858 as a whole number:
  7105. 16 Nov 1858 = -1, 17 Nov 1858 = 0, 18 Nov 1858 = 1, 19 Nov 1858 = 2, ...
  7106. The Modified Julian Date is defined by the International Astronomical
  7107. Union as the true Julian date minus 2400000.5 days. The true Julian
  7108. date is the number days since since noon of 1 January 4713 BCE of the
  7109. Julian proleptic calendar. Conversions between calendar dates and
  7110. Julian dates, however, assume Gregorian dating. The day of the week
  7111. is MJD mod 7: 0=We, 1=Th, 2=Fr, 3=Sa, 4=Su, 5=Mo, 6=Tu.
  7112. */
  7113. long
  7114. mjd(date) char * date; {
  7115. char year[5];
  7116. char month[3];
  7117. char day[3];
  7118. int x, a, d, m, y;
  7119. long z;
  7120. if (!date) date = ""; /* Validate arg */
  7121. x = strlen(date);
  7122. if (x < 1) return(0L);
  7123. if (x < 8) return(-1L);
  7124. for (x = 0; x < 8; x++)
  7125. if (!isdigit(date[x]))
  7126. return(-1L);
  7127. year[0] = date[0]; /* Isolate year */
  7128. year[1] = date[1];
  7129. year[2] = date[2];
  7130. year[3] = date[3];
  7131. year[4] = '\0';
  7132. month[0] = date[4]; /* Month */
  7133. month[1] = date[5];
  7134. month[2] = '\0';;
  7135. m = atoi(month);
  7136. day[0] = date[6]; /* And day */
  7137. day[1] = date[7];
  7138. day[2] = '\0';
  7139. d = atoi(day);
  7140. a = (14-m)/12; /* Calculate true Julian date */
  7141. y = atoi(year) + 4800 - a;
  7142. m = m + 12 * a - 3;
  7143. z = d + (long)(306*m+5)/10 + (long)(y*365) + y/4 - y/100 + y/400 - 32045L;
  7144. z -= 2400001L; /* Convert JD to MJD */
  7145. return(z);
  7146. }
  7147. static char mjd2dbuf[32];
  7148. /* M J D 2 D A T E -- Converts MJD to yyyymmdd */
  7149. char *
  7150. #ifdef CK_ANSIC
  7151. mjd2date(long mjd)
  7152. #else
  7153. mjd2date(mjd) long mjd;
  7154. #endif /* CK_ANSIC */
  7155. /* mjd2date */ {
  7156. long jd, l, n;
  7157. int d, m, y;
  7158. jd = (long)(mjd + 2400001L);
  7159. l = jd + 68569;
  7160. n = 4 * l / 146097L;
  7161. l = l - (146097 * n + 3) / 4;
  7162. y = 4000 * (l + 1) / 1461001L;
  7163. l = l - 1461 * y / 4 + 31;
  7164. m = 80 * l / 2447;
  7165. d = l - 2447 * m / 80;
  7166. l = m / 11;
  7167. m = m + 2 - 12 * l;
  7168. y = 100 * (n - 49) + y + l;
  7169. sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7170. return((char *)mjd2dbuf);
  7171. }
  7172. #ifndef NOSPL
  7173. static char ** flist = (char **) NULL; /* File list for \fnextfile() */
  7174. static int flistn = 0; /* Number of items in file list */
  7175. /*
  7176. The function return-value buffer must be global, since fneval() returns a
  7177. pointer to it. fneval() is called only by zzstring(), which always copies
  7178. the result out of this buffer to somewhere else, so it's OK to have only
  7179. one buffer for this in most cases. However, since function calls can be
  7180. nested -- e.g. functions whose arguments are functions, or recursive
  7181. functions, at some point we should convert this to an array of buffers,
  7182. indexed by function depth (which might or might not be the same as the
  7183. "depth" variable). Also, since function results are potentially quite big,
  7184. we'd need to allocate and deallocate dynamically as we descend and ascend
  7185. function depth. Left for a future release...
  7186. */
  7187. char fnval[FNVALL+2]; /* Function return value */
  7188. static int fndepth = 0; /* (we don't actually use this yet) */
  7189. int fnsuccess = 1;
  7190. extern int fnerror;
  7191. /* f p f o r m a t -- Floating-point number nicely formatted. */
  7192. /*
  7193. Returns results from a circular 1K buffer.
  7194. Don't count on too many results remaining available at once; it could
  7195. be anywhere from 5 to maybe 100, depending on the sizes of the results.
  7196. */
  7197. #ifdef CKFLOAT
  7198. #define FPFMTSIZ 1024
  7199. static char fpfmtbuf[FPFMTSIZ] = { NUL, NUL };
  7200. static int fpfbufpos = 0; /* (why was this char before?) */
  7201. char *
  7202. fpformat(fpresult,places,round) CKFLOAT fpresult; int places, round; {
  7203. char fbuf[16]; /* For creating printf format */
  7204. int nines = 0, sign = 0, x, y, i, j, size = 0;
  7205. char * buf;
  7206. CKFLOAT ftmp;
  7207. x = places ? places : (fp_digits ? fp_digits : 6);
  7208. debug(F101,"fpformat fpresult","",fpresult);
  7209. debug(F101,"fpformat places","",places);
  7210. debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7211. ftmp = fpresult;
  7212. if (ftmp < 0.0) ftmp = 0.0 - fpresult;
  7213. #ifdef FNFLOAT
  7214. if (!fp_rounding && /* If printf doesn't round, */
  7215. (places > 0 || /* round result to decimal places. */
  7216. (places == 0 && round)))
  7217. fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  7218. y = (ftmp == 0.0) ? 1 : (int)log10(ftmp);
  7219. size = y + x + 3; /* Estimated length of result */
  7220. if (fpresult < 0.0) size++;
  7221. #else
  7222. size = 200; /* No way to estimate, be generous */
  7223. #endif /* FNFLOAT */
  7224. debug(F101,"fpformat size","",size);
  7225. if (fpfbufpos > (FPFMTSIZ - size)) /* Wrap around if necessary */
  7226. fpfbufpos = 0;
  7227. debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7228. buf = &fpfmtbuf[fpfbufpos];
  7229. if (places > 0) { /* If places specified */
  7230. /* use specified places to write given number of digits */
  7231. sprintf(fbuf,"%%0.%df",places); /* SAFE */
  7232. sprintf(buf,fbuf,fpresult); /* SAFE */
  7233. } else { /* Otherwise... */
  7234. /* Go for max precision */
  7235. sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  7236. sprintf(buf,fbuf,fpresult); /* SAFE */
  7237. }
  7238. if (buf[0] == '-') sign = 1;
  7239. debug(F111,"fpresult 1 errno",buf,errno); /* Check for over/underflow */
  7240. debug(F111,"fpresult 1 fpfbufpos",buf,fpfbufpos);
  7241. /* Give requested decimal places */
  7242. for (i = sign; i < FPFMTSIZ && buf[i]; i++) {
  7243. if (buf[i] == '.') /* First find the decimal point */
  7244. break;
  7245. else if (i > fp_digits + sign - 1) /* replacing garbage */
  7246. buf[i] = '0'; /* digits with 0... */
  7247. }
  7248. if (buf[i] == '.') { /* Have decimal point */
  7249. int gotend = 0;
  7250. /* places < 0 so truncate fraction */
  7251. if (places < 0 || (places == 0 && round)) {
  7252. buf[i] = NUL;
  7253. } else if (places > 0) { /* d > 0 so this many decimal places */
  7254. i++; /* First digit after decimal */
  7255. for (j = 0; j < places; j++) { /* Truncate after d decimal */
  7256. if (!buf[j+i]) /* places or extend to d */
  7257. gotend = 1; /* decimal places. */
  7258. if (gotend || j+i+sign > fp_digits)
  7259. buf[j+i] = '0';
  7260. }
  7261. buf[j+i] = NUL;
  7262. } else { /* places == 0 so Do The Right Thing */
  7263. for (j = (int)strlen(buf) - 1; j > i+1; j--) {
  7264. if ((j - sign) > fp_digits)
  7265. buf[j] = '0';
  7266. if (buf[j] == '0')
  7267. buf[j] = NUL; /* Strip useless trailing 0's. */
  7268. else
  7269. break;
  7270. }
  7271. }
  7272. }
  7273. fpfmtbuf[FPFMTSIZ-1] = NUL;
  7274. j = strlen(buf);
  7275. sign = 0;
  7276. for (i = j-1; i >= 0; i--) {
  7277. if (buf[i] == '9')
  7278. nines++;
  7279. else
  7280. break;
  7281. }
  7282. /* Do something about xx.xx99999999... */
  7283. if (nines > 5) {
  7284. if (isdigit(buf[i]) && i < FPFMTSIZ - 2) {
  7285. buf[i] = buf[i] + 1;
  7286. buf[i+1] = '0';
  7287. buf[i+2] = '\0';
  7288. }
  7289. }
  7290. if (!strncmp(buf,"-0.0",FPFMTSIZ))
  7291. ckstrncpy(buf,"0.0",FPFMTSIZ);
  7292. fpfbufpos += (int)strlen(buf) + 1;
  7293. return((char *)buf);
  7294. }
  7295. #endif /* CKFLOAT */
  7296. static VOID
  7297. evalerr(fn) char * fn; {
  7298. if (fndiags) {
  7299. if (divbyzero)
  7300. ckmakmsg(fnval,FNVALL,"<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  7301. else
  7302. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  7303. }
  7304. }
  7305. static int
  7306. ckcindex(c,s) char c, *s; {
  7307. int rc;
  7308. if (!c || !s) return(0);
  7309. for (rc = 0; s[rc]; rc++) {
  7310. if (c == s[rc]) return(rc+1);
  7311. }
  7312. return(0);
  7313. }
  7314. static char *
  7315. dokwval(s,sep) char * s, * sep; {
  7316. char c = '\0', * p, * kw = NULL, * vp = NULL;
  7317. char * rc = "0"; /* Return code */
  7318. int x = 0;
  7319. if (!s) return(rc);
  7320. if (!*s) return(rc);
  7321. debug(F110,"kwval arg",s,0);
  7322. debug(F110,"kwval sep",sep,0);
  7323. p = (char *)malloc((int)strlen(s)+1);
  7324. if (!p) goto xdokwval;
  7325. strcpy(p,s); /* SAFE */
  7326. s = p;
  7327. while (*s < '!' && *s > '\0') /* Get first nonblank */
  7328. s++;
  7329. if (!*s) goto xdokwval;
  7330. if (ckcindex(*s,sep)) /* Separator but no keyword */
  7331. goto xdokwval;
  7332. kw = s; /* Keyword */
  7333. while (*s > ' ') {
  7334. if (ckcindex(*s,sep)) { /* keyword=... */
  7335. c = *s;
  7336. break;
  7337. }
  7338. s++;
  7339. }
  7340. if (*kw) rc = "1"; /* Have keyword, promote return code */
  7341. *s++ = NUL; /* Terminate keyword */
  7342. while (*s < '!' && *s > '\0') /* Skip blanks */
  7343. s++;
  7344. if (!c && ckcindex(*s,sep)) {
  7345. c = *s++; /* Have separator */
  7346. while (*s < '!' && *s > '\0') /* Skip blanks */
  7347. s++;
  7348. }
  7349. if (c) {
  7350. vp = s;
  7351. if (*vp) rc = "2"; /* Have value, another promotion */
  7352. #ifdef COMMENT
  7353. while (*s > ' ') /* Skip to end */
  7354. s++;
  7355. *s = NUL; /* Terminate value */
  7356. #endif /* COMMENT */
  7357. }
  7358. debug(F110,"kwval c",ckctoa(c),0);
  7359. debug(F110,"kwval keyword",kw,0);
  7360. debug(F110,"kwval value",vp,0);
  7361. makestr(&lastkwval,kw);
  7362. vp = brstrip(vp);
  7363. debug(F110,"kwval value",vp,0);
  7364. x = addmac(kw,vp);
  7365. debug(F111,"kwval addmac",kw,x);
  7366. xdokwval:
  7367. if (p) free(p);
  7368. return((x < 0) ? "-1" : rc);
  7369. }
  7370. static int
  7371. isaarray(s) char * s; { /* Is s an associative array element */
  7372. int state = 0;
  7373. CHAR c;
  7374. if (!s) return(0);
  7375. while ((c = *s++)) {
  7376. if (!isprint(c)) {
  7377. return(0);
  7378. } else if (c == '<') {
  7379. if (state != 0)
  7380. return(0);
  7381. state = 1;
  7382. } else if (c == '>') {
  7383. return((state != 1 || *s) ? 0 : 1);
  7384. }
  7385. }
  7386. return(0);
  7387. }
  7388. /* J P G D A T E -- Get "date taken" from JPG file Exif data */
  7389. /*
  7390. This routine doesn't follow the Exif spec, it just hunts for
  7391. date-time strings in the first 8K of the JPG and keeps the earliest one.
  7392. Call with file pointer, returns Exif date-time string "yyyy:mm:dd hh:mm:ss"
  7393. or an empty string if none found.
  7394. */
  7395. #define JPGYEAR 1
  7396. #define JPGMONTH 2
  7397. #define JPGDAY 3
  7398. #define JPGHOUR 4
  7399. #define JPGMIN 5
  7400. #define JPGSEC 6
  7401. #define JPGDATEBUF 8192 /* Should be more than enough bytes to find date */
  7402. static char *
  7403. jpgdate(fp) FILE * fp; {
  7404. static char datebuf[20];
  7405. char tmpbuf[20];
  7406. CHAR buf[JPGDATEBUF+1];
  7407. CHAR * p;
  7408. CHAR * z;
  7409. CHAR c;
  7410. int i;
  7411. int k = 0;
  7412. int n = 0;
  7413. int count = 0;
  7414. int state = 0;
  7415. if (fp == NULL)
  7416. return("");
  7417. rewind(fp);
  7418. for (i = 0; i < 20; i++) { datebuf[i] = NUL; tmpbuf[i] = NUL; }
  7419. datebuf[0] = NUL;
  7420. tmpbuf[0] = NUL;
  7421. count = fread(buf,1,JPGDATEBUF,fp); /* Read a buffer */
  7422. if (count == EOF || count == 0) {
  7423. return("");
  7424. }
  7425. p = (CHAR *) buf;
  7426. z = p + JPGDATEBUF;
  7427. while (p < z) {
  7428. c = *p++;
  7429. n++;
  7430. if (c != ' ' && c != ':' && !isdigit(c)) {
  7431. state = 0;
  7432. k = 0;
  7433. continue;
  7434. }
  7435. switch (state) {
  7436. case 0:
  7437. if (c == '1' && *p == '9') state = JPGYEAR;
  7438. else if (c == '2' && *p == '0') state = JPGYEAR;
  7439. if (state == JPGYEAR) {
  7440. k = 0;
  7441. tmpbuf[k++] = c;
  7442. }
  7443. continue;
  7444. case JPGYEAR:
  7445. if (c == ':' && k == 4) {
  7446. tmpbuf[k++] = c;
  7447. state = JPGMONTH;
  7448. continue;
  7449. }
  7450. if (k > 3 || !isdigit(c))
  7451. state = k = 0;
  7452. else
  7453. tmpbuf[k++] = c;
  7454. continue;
  7455. case JPGMONTH:
  7456. if (c == ':' && k == 7) {
  7457. tmpbuf[k++] = c;
  7458. state = JPGDAY;
  7459. continue;
  7460. }
  7461. if (k > 6 || !isdigit(c))
  7462. state = k = 0;
  7463. else
  7464. tmpbuf[k++] = c;
  7465. continue;
  7466. case JPGDAY:
  7467. if (c == ' ' && k == 10) {
  7468. tmpbuf[k++] = c;
  7469. state = JPGHOUR;
  7470. continue;
  7471. }
  7472. if (k > 9 || !isdigit(c))
  7473. state = k = 0;
  7474. else
  7475. tmpbuf[k++] = c;
  7476. continue;
  7477. case JPGHOUR:
  7478. if (c == ':' && k == 13) {
  7479. tmpbuf[k++] = c;
  7480. state = JPGMIN;
  7481. continue;
  7482. }
  7483. if (k > 12 || !isdigit(c))
  7484. state = k = 0;
  7485. else
  7486. tmpbuf[k++] = c;
  7487. continue;
  7488. case JPGMIN:
  7489. if (c == ':' && k == 16) {
  7490. tmpbuf[k++] = c;
  7491. state = JPGSEC;
  7492. continue;
  7493. }
  7494. if (k > 15 || !isdigit(c))
  7495. state = k = 0;
  7496. else
  7497. tmpbuf[k++] = c;
  7498. continue;
  7499. case JPGSEC:
  7500. if (!isdigit(c) || !isdigit(*p)) {
  7501. state = k = 0;
  7502. continue;
  7503. }
  7504. tmpbuf[k++] = c;
  7505. tmpbuf[k++] = *p;
  7506. tmpbuf[k] = NUL;
  7507. }
  7508. if (!datebuf[0]) { /* First date */
  7509. strncpy(datebuf,tmpbuf,19);
  7510. } else if (strncmp(tmpbuf,datebuf,19) < 0) { /* Earlier date */
  7511. strncpy(datebuf,tmpbuf,19);
  7512. }
  7513. }
  7514. return((char *) datebuf);
  7515. }
  7516. int /* Is character alphnumeric? */
  7517. cisalphanum(ch) CHAR ch; { /* i.e. a letter, digit, @, $, or _ */
  7518. /* All 8-bit characters are counted as alphanumeric */
  7519. int c;
  7520. c = (int)ch; /* Avoid C-language character syntax */
  7521. if (c == 36) return(1); /* '$' is alphanumeric */
  7522. if (c == 95) return(1); /* '_' is alphanumeric */
  7523. if (c < 48) return(0); /* Space, punctuation, math */
  7524. if (c > 57 && c < 64) return(0); /* Between '9' and '@' */
  7525. if (c > 90 && c < 97) return(0); /* Between 'Z' and 'a' */
  7526. if (c > 122 && c < 127) return(0); /* Between 'z' and DEL */
  7527. return(1);
  7528. }
  7529. int /* Is character non-alphanumeric */
  7530. cnonalphanum(ch) CHAR ch; { /* i.e. not letter, digit, [$@_] */
  7531. int c;
  7532. c = (int)ch; /* Avoid C-language character syntax */
  7533. if (c == 36) return(0); /* '$' is alphanumeric */
  7534. if (c == 95) return(0); /* '_' is alphanumeric */
  7535. if (c < 48) return(1); /* Space, punctuation, math */
  7536. if (c > 57 && c < 64) return(1); /* Between '9' and '@' */
  7537. if (c > 90 && c < 97) return(1); /* Between 'Z' and 'a' */
  7538. if (c > 122 && c < 127) return(1); /* Between 'z' and DEL */
  7539. return(0);
  7540. }
  7541. /* Tell if a string contains only alphanumeric characters */
  7542. int
  7543. isalphanum(s) char *s; {
  7544. CHAR c;
  7545. while ((c = (int)(*s++))) {
  7546. if (!cisalphanum(c)) return(0);
  7547. }
  7548. return(1);
  7549. }
  7550. /* Tell if a string contains only non-alphanumeric characters */
  7551. int
  7552. nonalphanum(s) char *s; {
  7553. CHAR c;
  7554. while ((c = (int)(*s++))) {
  7555. if (!cnonalphanum(c)) return(0);
  7556. }
  7557. return(1);
  7558. }
  7559. static char * /* Evaluate builtin functions */
  7560. fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
  7561. int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
  7562. int cx, failed = 0; /* Return code, 0 = ok */
  7563. long z = 0L;
  7564. char *bp[FNARGS + 1]; /* Pointers to malloc'd strings */
  7565. char c = NUL;
  7566. char *p = NULL, *s = NULL;
  7567. char *val1 = NULL, *val2 = NULL; /* Pointers to numeric string values */
  7568. #ifdef RECURSIVE
  7569. int rsave = recursive;
  7570. #endif /* RECURSIVE */
  7571. #ifdef OS2
  7572. int zsave = zxpn;
  7573. #endif /* OS2 */
  7574. if (!fn) fn = ""; /* Protect against null pointers */
  7575. if (!*fn) return("");
  7576. for (i = 0; i < FNARGS; i++) /* Initialize argument pointers */
  7577. bp[i] = NULL;
  7578. /*
  7579. IMPORTANT: Note that argn is not an accurate count of the number of
  7580. arguments. We can't really tell if an argument is null until after we
  7581. execute the code below. So argn is really the maximum number of arguments
  7582. we might have. Argn should always be at least 1, even if the function is
  7583. called with empty parentheses (but don't count on it).
  7584. */
  7585. debug(F111,"fneval",fn,argn);
  7586. debug(F110,"fneval",argp[0],0);
  7587. if (argn > FNARGS) /* Discard excess arguments */
  7588. argn = FNARGS;
  7589. fndepth++;
  7590. debug(F101,"fneval fndepth","",fndepth);
  7591. p = fnval;
  7592. fnval[0] = NUL;
  7593. y = lookup(fnctab,fn,nfuncs,&x); /* Look up the function name */
  7594. cx = y; /* Because y is too generic... */
  7595. if (cx < 0) { /* Not found */
  7596. failed = 1;
  7597. if (fndiags) { /* FUNCTION DIAGNOSTIC ON */
  7598. int x;
  7599. x = strlen(fn);
  7600. /* The following sprintf's are safe */
  7601. switch (cx) {
  7602. case -1:
  7603. if (x + 32 < FNVALL)
  7604. sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\\f%s()>",fn);
  7605. else
  7606. sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
  7607. break;
  7608. case -2:
  7609. if (x + 26 < FNVALL)
  7610. sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\\f%s()>",fn);
  7611. else
  7612. sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
  7613. break;
  7614. case -3:
  7615. sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\\f()>");
  7616. break;
  7617. default:
  7618. if (x + 26 < FNVALL)
  7619. sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\\f%s()>",fn);
  7620. else
  7621. sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
  7622. break;
  7623. }
  7624. }
  7625. goto fnend; /* Always leave via common exit */
  7626. }
  7627. fn = fnctab[x].kwd; /* Full name of function */
  7628. if (argn < 0) {
  7629. failed = 1;
  7630. p = fnval;
  7631. if (fndiags)
  7632. sprintf(fnval,"<ERROR:MISSING_ARG:\\f%s()>",fn);
  7633. goto fnend;
  7634. }
  7635. if (cx == FN_LIT) { /* literal(arg1) */
  7636. debug(F010,"flit",xp,0);
  7637. p = xp ? xp : ""; /* Return a pointer to arg itself */
  7638. goto fnend;
  7639. }
  7640. #ifdef DEBUG
  7641. if (deblog) {
  7642. int j;
  7643. for (j = 0; j < argn; j++)
  7644. debug(F111,"fneval arg",argp[j],j);
  7645. }
  7646. #endif /* DEBUG */
  7647. for (j = argn-1; j >= 0; j--) { /* Uncount empty trailing args */
  7648. if (!argp[j])
  7649. argn--;
  7650. else if (!*(argp[j]))
  7651. argn--;
  7652. else break;
  7653. }
  7654. debug(F111,"fneval argn",fn,argn);
  7655. /*
  7656. \fliteral() and \fcontents() are special functions that do not evaluate
  7657. their arguments, and are treated specially here. After these come the
  7658. functions whose arguments are evaluated in the normal way.
  7659. */
  7660. #ifdef COMMENT
  7661. /* (moved up) */
  7662. if (cx == FN_LIT) { /* literal(arg1) */
  7663. debug(F110,"flit",xp,0);
  7664. p = xp ? xp : ""; /* Return a pointer to arg itself */
  7665. goto fnend;
  7666. }
  7667. #endif /* COMMENT */
  7668. if (cx == FN_CON) { /* Contents of variable, unexpanded. */
  7669. char c;
  7670. int subscript = 0;
  7671. if (!(p = argp[0]) || !*p) {
  7672. failed = 1;
  7673. p = fnval;
  7674. if (fndiags)
  7675. sprintf(fnval,"<ERROR:MISSING_ARG:\\fcontents()>");
  7676. goto fnend;
  7677. }
  7678. p = brstrip(p);
  7679. if (*p == CMDQ) p++;
  7680. if ((c = *p) == '%') { /* Scalar variable. */
  7681. c = *++p; /* Get ID character. */
  7682. p = ""; /* Assume definition is empty */
  7683. if (!c) { /* Double paranoia */
  7684. failed = 1;
  7685. p = fnval;
  7686. if (fndiags)
  7687. sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\\fcontents()>");
  7688. goto fnend;
  7689. }
  7690. if (c >= '0' && c <= '9') { /* Digit for macro arg */
  7691. if (maclvl < 0) /* Digit variables are global */
  7692. p = g_var[c]; /* if no macro is active */
  7693. else /* otherwise */
  7694. p = m_arg[maclvl][c - '0']; /* they're on the stack */
  7695. } else if (c == '*') {
  7696. #ifdef COMMENT
  7697. p = (maclvl > -1) ? m_line[maclvl] : topline;
  7698. if (!p) p = "";
  7699. #else
  7700. int nx = FNVALL;
  7701. char * sx = fnval;
  7702. p = fnval;
  7703. #ifdef COMMENT
  7704. if (cmdsrc() == 0 && topline)
  7705. p = topline;
  7706. else
  7707. #endif /* COMMENT */
  7708. if (zzstring("\\fjoin(&_[],{ },1)",&sx,&nx) < 0) {
  7709. failed = 1;
  7710. p = fnval;
  7711. if (fndiags)
  7712. sprintf(fnval,"<ERROR:OVERFLOW:\\fcontents()>");
  7713. debug(F110,"zzstring fcontents(\\%*)",p,0);
  7714. }
  7715. #endif /* COMMENT */
  7716. } else {
  7717. if (isupper(c)) c -= ('a'-'A');
  7718. p = g_var[c]; /* Letter for global variable */
  7719. }
  7720. if (!p) p = "";
  7721. goto fnend;
  7722. } else if (c == '&') { /* Array reference. */
  7723. int vbi, d;
  7724. if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
  7725. failed = 1;
  7726. p = fnval;
  7727. if (fndiags)
  7728. sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\\fcontents()>");
  7729. goto fnend;
  7730. }
  7731. subscript = chkarray(vbi,d); /* Check the array */
  7732. if (subscript >= 0) { /* Array is declared? */
  7733. vbi -= ARRAYBASE; /* Convert name to index */
  7734. if (a_dim[vbi] >= d) { /* If subscript in range */
  7735. char **ap;
  7736. ap = a_ptr[vbi]; /* get data pointer */
  7737. if (ap) { /* and if there is one */
  7738. p = ap[d]; /* return it */
  7739. goto fnend;
  7740. }
  7741. }
  7742. } else { /* Array not declared or element */
  7743. fnval[0] = NUL; /* out of range - return null string */
  7744. p = fnval; /* fdc 2010-12-30 */
  7745. goto fnend;
  7746. }
  7747. } else {
  7748. failed = 1;
  7749. p = fnval;
  7750. if (fndiags)
  7751. sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\\fcontents()>");
  7752. goto fnend;
  7753. }
  7754. }
  7755. p = fnval; /* Default result pointer */
  7756. fnval[0] = NUL; /* Default result = empty string */
  7757. for (i = 0; i < argn; i++) { /* Loop to expand each argument */
  7758. n = MAXARGLEN; /* Allow plenty of space */
  7759. bp[i] = s = malloc(n+1); /* Allocate space for this argument */
  7760. if (bp[i] == NULL) { /* Handle failure to get space */
  7761. failed = 1;
  7762. if (fndiags)
  7763. ckmakmsg(fnval,FNVALL,"<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  7764. goto fnend;
  7765. }
  7766. p = argp[i] ? argp[i] : ""; /* Point to this argument */
  7767. /*
  7768. Trim leading and trailing spaces from the original argument, before
  7769. evaluation. This code new to edit 184. Fixed in edit 199 to trim
  7770. blanks BEFORE stripping braces.
  7771. */
  7772. {
  7773. int x, j;
  7774. x = strlen(p);
  7775. j = x - 1; /* Trim trailing whitespace */
  7776. while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  7777. *(p + j--) = NUL;
  7778. while (*p == SP || *p == HT) /* Strip leading whitespace */
  7779. p++;
  7780. x = strlen(p);
  7781. if (*p == '{' && *(p+x-1) == '}') { /* NOW strip braces */
  7782. p[x-1] = NUL;
  7783. p++;
  7784. x -= 2;
  7785. }
  7786. }
  7787. /* Now evaluate the argument */
  7788. debug(F111,"fneval calling zzstring",p,n);
  7789. t = zzstring(p,&s,&n); /* Expand arg into new space */
  7790. debug(F101,"fneval zzstring","",t);
  7791. debug(F101,"fneval zzstring","",n);
  7792. if (t < 0) {
  7793. debug(F101,"fneval zzstring fails, arg","",i);
  7794. failed = 1;
  7795. if (fndiags) {
  7796. if (n == 0)
  7797. ckmakmsg(fnval,FNVALL,
  7798. "<ERROR:ARG_TOO_LONG:\\f",fn,"()>",NULL);
  7799. else
  7800. ckmakmsg(fnval,FNVALL,
  7801. "<ERROR:ARG_EVAL_FAILURE:\\f",fn,"()>",NULL);
  7802. }
  7803. goto fnend;
  7804. }
  7805. debug(F111,"fneval arg",bp[i],i);
  7806. }
  7807. #ifdef DEBUG
  7808. if (deblog) {
  7809. int j;
  7810. debug(F110,"fneval",fn,0);
  7811. for (j = 0; j < argn; j++) {
  7812. debug(F111,"fneval arg post eval",argp[j],j);
  7813. debug(F111,"fneval evaluated arg",bp[j],j);
  7814. }
  7815. }
  7816. #endif /* DEBUG */
  7817. {
  7818. /* Adjust argn for empty trailing arguments. */
  7819. /* For example when an arg is a variable name but the */
  7820. /* variable has no value. July 2006. */
  7821. int j, old; char *p;
  7822. old = argn;
  7823. for (j = argn - 1; j >= 0; j--) {
  7824. p = bp[j];
  7825. if (!p)
  7826. argn--;
  7827. else if (!*p)
  7828. argn--;
  7829. else
  7830. break;
  7831. }
  7832. #ifdef DEBUG
  7833. if (argn != old)
  7834. debug(F101,"fneval adjusted argn","",argn);
  7835. #endif /* DEBUG */
  7836. }
  7837. /*
  7838. From this point on, bp[0..argn-1] are not NULL and all must be freed
  7839. before returning. BUT NOTE: if no arguments were given, bp[0] *is* NULL.
  7840. */
  7841. if (argn < 1) { /* Catch required args missing */
  7842. switch (cx) {
  7843. case FN_DEF:
  7844. case FN_EVA:
  7845. case FN_EXE:
  7846. case FN_CHR:
  7847. /* case FN_COD: */
  7848. case FN_MAX:
  7849. case FN_MIN:
  7850. case FN_MOD:
  7851. case FN_FD:
  7852. case FN_FS:
  7853. case FN_TOD:
  7854. case FN_FFN:
  7855. case FN_BSN:
  7856. case FN_RAW:
  7857. case FN_CMD:
  7858. case FN_2HEX:
  7859. case FN_2OCT:
  7860. case FN_DNAM:
  7861. #ifdef FN_ERRMSG
  7862. case FN_ERRMSG:
  7863. #endif /* FN_ERRMSG */
  7864. #ifdef CK_KERBEROS
  7865. case FN_KRB_TK:
  7866. case FN_KRB_NX:
  7867. case FN_KRB_IV:
  7868. case FN_KRB_TT:
  7869. case FN_KRB_FG:
  7870. #endif /* CK_KERBEROS */
  7871. case FN_MJD2:
  7872. case FN_N2TIM:
  7873. case FN_DIM:
  7874. case FN_DATEJ:
  7875. case FN_PNCVT:
  7876. case FN_PERM:
  7877. case FN_ALOOK:
  7878. case FN_TLOOK:
  7879. case FN_ABS:
  7880. case FN_AADUMP:
  7881. case FN_JOIN:
  7882. #ifdef CKFLOAT
  7883. case FN_FPABS:
  7884. case FN_FPEXP:
  7885. case FN_FPLOG:
  7886. case FN_FPLN:
  7887. case FN_FPMOD:
  7888. case FN_FPSQR:
  7889. case FN_FPADD:
  7890. case FN_FPDIV:
  7891. case FN_FPMUL:
  7892. case FN_FPPOW:
  7893. case FN_FPSUB:
  7894. case FN_FPINT:
  7895. case FN_FPROU:
  7896. case FN_FPSIN:
  7897. case FN_FPCOS:
  7898. case FN_FPTAN:
  7899. #endif /* CKFLOAT */
  7900. #ifdef TCPSOCKET
  7901. case FN_HSTADD:
  7902. case FN_HSTNAM:
  7903. #endif /* TCPSOCKET */
  7904. case FN_DELSEC:
  7905. #ifdef COMMENT
  7906. case FN_KWVAL:
  7907. case FN_SLEEP:
  7908. case FN_MSLEEP:
  7909. #endif /* COMMENT */
  7910. #ifdef NT
  7911. case FN_SNAME:
  7912. case FN_LNAME:
  7913. #endif /* NT */
  7914. case FN_FILEINF:
  7915. case FN_FILECMP:
  7916. failed = 1;
  7917. p = fnval;
  7918. if (fndiags)
  7919. ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  7920. goto fnend;
  7921. }
  7922. }
  7923. p = fnval; /* Reset these again. */
  7924. fnval[0] = NUL;
  7925. switch (cx) { /* Do function on expanded args. */
  7926. #ifdef TCPSOCKET
  7927. case FN_HSTADD:
  7928. p = ckaddr2name(bp[0]);
  7929. goto fnend;
  7930. case FN_HSTNAM:
  7931. p = ckname2addr(bp[0]);
  7932. goto fnend;
  7933. #endif /* TCPSOCKET */
  7934. case FN_DEF: /* \fdefinition(arg1) */
  7935. k = isaarray(bp[0]) ?
  7936. mxxlook(mactab,bp[0],nmac) :
  7937. mxlook(mactab,bp[0],nmac);
  7938. p = (k > -1) ? mactab[k].mval : "";
  7939. goto fnend;
  7940. case FN_EVA: /* \fevaluate(arg1) */
  7941. p = *(bp[0]) ? evalx(bp[0]) : "";
  7942. if (!*p && fndiags) {
  7943. failed = 1;
  7944. p = fnval;
  7945. evalerr(fn);
  7946. }
  7947. goto fnend;
  7948. case FN_EXE: /* \fexecute(arg1) */
  7949. j = (int)strlen(s = bp[0]); /* Length of macro invocation */
  7950. p = ""; /* Initialize return value to null */
  7951. if (j) { /* If there is a macro to execute */
  7952. while (*s == SP) s++,j--; /* strip leading spaces */
  7953. p = s; /* remember beginning of macro name */
  7954. for (i = 0; i < j; i++) { /* find end of macro name */
  7955. if (*s == SP)
  7956. break;
  7957. s++;
  7958. }
  7959. if (*s == SP) { /* if there was a space after */
  7960. *s++ = NUL; /* terminate the macro name */
  7961. while (*s == SP) s++; /* skip past any extra spaces */
  7962. } else
  7963. s = ""; /* maybe there are no arguments */
  7964. if (p && *p) {
  7965. k = mlook(mactab,p,nmac); /* Look up the macro name */
  7966. debug(F111,"fexec mlook",p,k);
  7967. } else
  7968. k = -1;
  7969. if (k < 0) {
  7970. char * p2 = p;
  7971. failed = 1;
  7972. p = fnval;
  7973. if (fndiags)
  7974. ckmakxmsg(fnval,FNVALL,
  7975. "<ERROR:NO_SUCH_MACRO:\\f",fn,"(",p2,")>",
  7976. NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  7977. goto fnend;
  7978. }
  7979. /*
  7980. This is just a WEE bit dangerous because we are copying up to 9 arguments
  7981. into the space reserved for one. It won't overrun the buffer, but if there
  7982. are lots of long arguments we might lose some. The other problem is that if
  7983. the macro has more than 3 arguments, the 4th through last are all
  7984. concatenated onto the third. (The workaround is to use spaces rather than
  7985. commas to separate them.) Leaving it like this to avoid having to allocate
  7986. tons more buffers.
  7987. */
  7988. if (argn > 1) { /* Commas used instead of spaces */
  7989. int i;
  7990. char *p = bp[0]; /* Reuse this space */
  7991. *p = NUL; /* Make into dodo() arg list */
  7992. for (i = 1; i < argn; i++) {
  7993. ckstrncat(p,bp[i],MAXARGLEN);
  7994. ckstrncat(p," ",MAXARGLEN);
  7995. }
  7996. s = bp[0]; /* Point to new list */
  7997. }
  7998. p = ""; /* Initialize return value */
  7999. if (k >= 0) { /* If macro found in table */
  8000. /* Go set it up (like DO cmd) */
  8001. if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
  8002. if (cmpush() > -1) { /* Push command parser state */
  8003. extern int ifc;
  8004. int ifcsav = ifc; /* Push IF condition on stack */
  8005. k = parser(1); /* Call parser to execute the macro */
  8006. cmpop(); /* Pop command parser */
  8007. ifc = ifcsav; /* Restore IF condition */
  8008. if (k == 0) { /* No errors, ignore action cmds. */
  8009. p = mrval[maclvl+1]; /* If OK, set return value. */
  8010. if (p == NULL) p = "";
  8011. }
  8012. } else { /* Can't push any more */
  8013. debug(F100,"zzstring fneval fexec failure","",0);
  8014. printf("\n?\\fexec() too deeply nested\n");
  8015. while (cmpop() > -1) ;
  8016. p = "";
  8017. }
  8018. }
  8019. }
  8020. }
  8021. debug(F110,"zzstring fneval fexecute final p",p,0);
  8022. goto fnend;
  8023. #ifdef RECURSIVE
  8024. case FN_RDIR: /* \frdir..() - Recursive dir count */
  8025. case FN_RFIL: /* \frfiles() - Recursive file count */
  8026. /* recursive = 2; */ /* fall thru... */
  8027. #endif /* RECURSIVE */
  8028. case FN_FC: /* \ffiles() - File count. */
  8029. case FN_DIR: { /* \ffdir.() - Directory count. */
  8030. char abuf[16], *s;
  8031. char ** ap = NULL;
  8032. int x, xflags = 0;
  8033. if (matchdot)
  8034. xflags |= ZX_MATCHDOT;
  8035. if (cx == FN_RDIR || cx == FN_RFIL) {
  8036. xflags |= ZX_RECURSE;
  8037. #ifdef CKSYMLINK
  8038. /* Recursive - don't follow symlinks */
  8039. xflags |= ZX_NOLINKS;
  8040. #endif /* CKSYMLINK */
  8041. }
  8042. failed = 0;
  8043. if (argn < 1) {
  8044. p = "0";
  8045. goto fnend;
  8046. }
  8047. if (cx == FN_DIR || cx == FN_RDIR) { /* Only list directories */
  8048. debug(F100,"FN_DIR or FN_RDIR","",0);
  8049. xflags |= ZX_DIRONLY;
  8050. #ifdef OS2
  8051. zxpn = 1; /* Use the alternate list */
  8052. #endif /* OS2 */
  8053. } else { /* List only files */
  8054. debug(F100,"Not FN_DIR or FN_RDIR","",0);
  8055. xflags |= ZX_FILONLY;
  8056. #ifdef OS2
  8057. zxpn = 1; /* Use the alternate list */
  8058. #endif /* OS2 */
  8059. }
  8060. if (*(bp[0])) {
  8061. k = nzxpand(bp[0],xflags);
  8062. if (k < 0) k = 0;
  8063. sprintf(fnval,"%d",k); /* SAFE */
  8064. p = fnval;
  8065. } else
  8066. p = "0";
  8067. if (argn > 1) { /* Assign list to array */
  8068. fnval[0] = NUL; /* Initial return value */
  8069. ckstrncpy(abuf,bp[1],16); /* Get array reference */
  8070. s = abuf;
  8071. if (*s == CMDQ) s++;
  8072. failed = 1; /* Assume it's bad */
  8073. p = fnval; /* Point to result */
  8074. if (fndiags) /* Default is this error message */
  8075. ckmakmsg(fnval,FNVALL,
  8076. "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  8077. if (s[0] != '&') /* "Address" of array */
  8078. goto fnend;
  8079. if (s[2])
  8080. if (s[2] != '[' || s[3] != ']')
  8081. goto fnend;
  8082. if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  8083. s[1] += 32;
  8084. if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
  8085. goto fnend;
  8086. failed = 0; /* Unset failure flag */
  8087. ap = a_ptr[x]; /* Point to array we just declared */
  8088. sprintf(fnval,"%d",k); /* SAFE */
  8089. }
  8090. #ifdef OS2
  8091. if (ap) { /* We are making an array */
  8092. int i;
  8093. char tmp[16];
  8094. ap[0] = NULL; /* Containing number of files */
  8095. makestr(&(ap[0]),ckitoa(k));
  8096. ckstrncpy(tmp,fnval,16); /* Save return value */
  8097. for (i = 1; i <= k; i++) { /* Fill it */
  8098. ap[i] = NULL;
  8099. znext(fnval); /* Next filename */
  8100. if (!*fnval) /* No more, done */
  8101. break; /* In case a premature end */
  8102. makestr(&(ap[i]),fnval);
  8103. }
  8104. #ifdef ZXREWIND
  8105. k = zxrewind(); /* Reset the file expansion */
  8106. #else
  8107. k = nzxpand(bp[0],xflags);
  8108. #endif /* ZXREWIND */
  8109. ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8110. }
  8111. #else /* OS2 */
  8112. { /* Make copies of the list */
  8113. int i; char tmp[16];
  8114. if (flist) { /* Free old file list, if any */
  8115. for (i = 0; flist[i]; i++) { /* and each string */
  8116. free(flist[i]);
  8117. flist[i] = NULL;
  8118. }
  8119. free((char *)flist);
  8120. }
  8121. ckstrncpy(tmp,fnval,16); /* Save our return value */
  8122. flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
  8123. if (flist) {
  8124. for (i = 0; i <= k; i++) { /* Fill it */
  8125. flist[i] = NULL;
  8126. znext(fnval); /* Next filename */
  8127. if (!*fnval) /* No more, done */
  8128. break;
  8129. makestr(&(flist[i]),fnval);
  8130. }
  8131. if (ap) { /* If array pointer given */
  8132. ap[0] = NULL;
  8133. makestr(&(ap[0]),ckitoa(k));
  8134. for (i = 0; i < k; i++) { /* Copy file list to array */
  8135. ap[i+1] = NULL;
  8136. makestr(&(ap[i+1]),flist[i]);
  8137. }
  8138. }
  8139. }
  8140. ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8141. flistn = 0; /* Reset global list pointer */
  8142. }
  8143. #endif /* OS2 */
  8144. #ifdef RECURSIVE
  8145. recursive = rsave;
  8146. #endif /* RECURSIVE */
  8147. #ifdef OS2
  8148. zxpn = zsave;
  8149. #endif /* OS2 */
  8150. }
  8151. goto fnend;
  8152. case FN_FIL: /* \fnextfile() - Next file in list. */
  8153. p = fnval; /* (no args) */
  8154. *p = NUL;
  8155. #ifdef OS2
  8156. zxpn = 1; /* OS/2 - use the alternate list */
  8157. znext(p); /* Call system-dependent function */
  8158. zxpn = zsave; /* Restore original list */
  8159. #else
  8160. if (flist) /* Others, use our own list. */
  8161. if (flist[flistn])
  8162. p = flist[flistn++];
  8163. #endif /* OS2 */
  8164. goto fnend;
  8165. } /* Break up big switch... */
  8166. switch (cx) {
  8167. case FN_IND: /* \findex(s1,s2,start,occurrence) */
  8168. case FN_RIX: /* \frindex(s1,s2,start,occurrence) */
  8169. case FN_SEARCH: /* \fsearch(pat,string,start,occ) */
  8170. case FN_RSEARCH: /* \frsearch(pat,string,start,occ) */
  8171. case FN_COUNT: { /* \fcount(s1,s2,start) */
  8172. int i = 0, right = 0, search = 0, count = 0;
  8173. int desired = 1;
  8174. right = (cx == FN_RIX || cx == FN_RSEARCH);
  8175. search = (cx == FN_SEARCH || cx == FN_RSEARCH);
  8176. count = (cx == FN_COUNT);
  8177. p = "0";
  8178. if (argn > 1) { /* Only works if we have 2 or 3 args */
  8179. int start = 0;
  8180. char * pat = NULL;
  8181. len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
  8182. len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  8183. if (len1 < 1 || len2 < 1) /* Watch out for empty strings */
  8184. goto fnend;
  8185. start = right ? -1 : 0; /* Default starting position */
  8186. if (argn > 2) {
  8187. val1 = *(bp[2]) ? evalx(bp[2]) : "1";
  8188. if (argn > 3) { /* Occurrence */
  8189. val2 = *(bp[3]) ? evalx(bp[3]) : "1";
  8190. if (chknum(val2)) desired = atoi(val2);
  8191. if (desired * len1 > len2) goto fnend;
  8192. }
  8193. if (chknum(val1)) {
  8194. int t;
  8195. t = atoi(val1);
  8196. if (!search) { /* Index or Rindex */
  8197. j = len2 - len1; /* Length difference */
  8198. t--; /* Convert position to 0-based */
  8199. if (t < 0) t = 0;
  8200. start = t;
  8201. if (!right && start < 0) start = 0;
  8202. } else { /* Search or Rsearch */
  8203. int x;
  8204. if (t < 0) t = 0;
  8205. if (right) { /* Right to left */
  8206. if (t > len2) t = len2;
  8207. start = len2 - t - 1;
  8208. if (start < 0)
  8209. goto fnend;
  8210. x = len2 - t;
  8211. s[x] = NUL;
  8212. } else { /* Left to right */
  8213. start = t - 1;
  8214. if (start < 0) start = 0;
  8215. if (start >= len2)
  8216. goto fnend;
  8217. }
  8218. }
  8219. } else {
  8220. failed = 1;
  8221. evalerr(fn);
  8222. p = fnval;
  8223. goto fnend;
  8224. }
  8225. }
  8226. if (count) { /* \fcount() */
  8227. int j;
  8228. for (i = 0; start < len2; i++) {
  8229. j = ckindex(pat,bp[1],start,0,inpcas[cmdlvl]);
  8230. if (j == 0) break;
  8231. start = j;
  8232. }
  8233. } else if (search) { /* \fsearch() or \frsearch() */
  8234. if (right && pat[0] == '^') {
  8235. right = 0;
  8236. start = 0;
  8237. }
  8238. if (right) { /* From right */
  8239. int k, j = 1;
  8240. if (start < 0)
  8241. start = len2 - 1;
  8242. i = 0;
  8243. while (start >= 0 && j <= desired) {
  8244. for (i = start;
  8245. (i >= 0) &&
  8246. !(k = ckmatch(pat,s+i,inpcas[cmdlvl],1+4));
  8247. i--) ;
  8248. if (k < 1) { /* No match */
  8249. i = 0;
  8250. break;
  8251. }
  8252. if (j == desired) { /* The match we want? */
  8253. i += k; /* Yes, return string index */
  8254. break;
  8255. }
  8256. j++; /* No, count this match */
  8257. s[i] = NUL; /* null it out */
  8258. start = i-1; /* move left and look again */
  8259. }
  8260. } else { /* From left */
  8261. int j;
  8262. i = 0;
  8263. for (j = 1; j <= desired && start < len2; j++) {
  8264. i = ckmatch(pat,&s[start],inpcas[cmdlvl],1+4);
  8265. if (i == 0 || j == desired) break;
  8266. start += i + 1;
  8267. }
  8268. if (j == desired && i != 0)
  8269. i += start;
  8270. else
  8271. i = 0;
  8272. }
  8273. } else { /* index or rindex */
  8274. int j = 0;
  8275. i = 0;
  8276. for (j = 1; j <= desired && start < len2; j++) {
  8277. i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
  8278. if (i == 0 || j == desired) break;
  8279. start = (right) ? len2 - i + 1 : i;
  8280. }
  8281. if (j != desired)
  8282. i = 0;
  8283. }
  8284. sprintf(fnval,"%d",i); /* SAFE */
  8285. p = fnval;
  8286. }
  8287. goto fnend;
  8288. }
  8289. case FN_RPL: /* \freplace(s1,s2,s3) */
  8290. /*
  8291. s = bp[0] = source string (len1)
  8292. bp[1] = match string (len2)
  8293. bp[2] = replacement string (len3)
  8294. bp[3] = which occurrence (default = all);
  8295. bp[4] = context sensitive ("word mode") 20171005
  8296. fnval = p = destination (result) string
  8297. */
  8298. if (argn < 1) /* Nothing */
  8299. goto fnend;
  8300. if (argn < 2) { /* Need at least two args */
  8301. ckstrncpy(p,bp[0],FNVALL);
  8302. } else {
  8303. int occur = 0, xx = 0, context = 0, j2;
  8304. int left = 0, right = 0, ok = 0;
  8305. len1 = (int)strlen(bp[0]); /* length of string to look in */
  8306. len2 = (int)strlen(bp[1]); /* length of string to look for */
  8307. len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  8308. j = len1 - len2 + 1; /* source - match + 1 */
  8309. j2 = j;
  8310. if (argn > 3) {
  8311. if (chknum(bp[3])) {
  8312. occur = atoi(bp[3]);
  8313. } else {
  8314. failed = 1;
  8315. if (fndiags)
  8316. ckmakmsg(fnval,FNVALL,
  8317. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8318. goto fnend;
  8319. }
  8320. }
  8321. /*
  8322. Context-sensitive "word mode" replace, new for C-Kermit 9.0.304 Dev.23,
  8323. October 2017. Can be removed by defining NORPLWORDMODE.
  8324. */
  8325. #ifdef RPLWORDMODE
  8326. if (argn > 4) {
  8327. if (chknum(bp[4])) {
  8328. context = atoi(bp[4]);
  8329. } else {
  8330. failed = 1;
  8331. if (fndiags)
  8332. ckmakmsg(fnval,FNVALL,
  8333. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8334. goto fnend;
  8335. }
  8336. }
  8337. #endif /* RPLWORDMODE */
  8338. /* If args out of whack... */
  8339. if (j < 1 || len1 == 0 || len2 == 0) {
  8340. ckstrncpy(p,bp[0],FNVALL); /* just return original string */
  8341. p[FNVALL] = NUL;
  8342. } else {
  8343. ragain:
  8344. s = bp[0]; /* Point to beginning of source string */
  8345. xx = 0; /* Match counter */
  8346. while (*s) { /* For each character in it...*/
  8347. /* Compare current segment with target string */
  8348. if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl])) {
  8349. ok = 1; /* Assume OK to replace */
  8350. #ifdef RPLWORDMODE
  8351. if (context) { /* New 2017-10-05 */
  8352. CHAR c;
  8353. left = 0;
  8354. right = 0;
  8355. ok = 0; /* Mustcheck context before replacing */
  8356. if (!strncmp(bp[1],"...",len2)) {
  8357. /* Special case for ellipsis */
  8358. if (s > bp[0]) { /* Can't begin a line */
  8359. c = *(s-1); /* Check preceding char */
  8360. if (c != 32 && c != '.')
  8361. left = 1;
  8362. }
  8363. c = *(s+len2); /* Check following char */
  8364. if (c != '.' && (c == SP || c == '\0'))
  8365. right = 1;
  8366. } else if (isalphanum(bp[1])) {
  8367. /* Target string is alphanumeric... */
  8368. if (s == bp[0]) { /* At beginning of string */
  8369. left = 1; /* So left boundary ok */
  8370. } else { /* Otherwise */
  8371. c = *(s-1); /* Check preceding char */
  8372. if (cnonalphanum(c)) /* If not alphamum */
  8373. left = 2; /* left boundary ok */
  8374. }
  8375. c = *(s+len2); /* Check following character */
  8376. if (c == '\0') /* If end of string */
  8377. right = 1; /* Right boundary OK */
  8378. else if (cnonalphanum(c))
  8379. right = 2; /* Right boundary OK */
  8380. } else if (nonalphanum(bp[1])) {
  8381. /* Target is non-salphanumeric */
  8382. if (s == bp[0]) { /* At beginning of line */
  8383. left = 1; /* Left OK */
  8384. } else { /* Otherwise */
  8385. c = *(s-1); /* Check preceding char */
  8386. if (cisalphanum(c) || c == SP)
  8387. left = 2; /* Left OK */
  8388. }
  8389. c = *(s+len2); /* Check char after target */
  8390. if (c == '\0') { /* At end of string */
  8391. right = 1; /* Right OK */
  8392. } else { /* Otherwise */
  8393. if (cisalphanum(c) || c <= SP)
  8394. right = 2; /* Right ok */
  8395. }
  8396. }
  8397. /* If none of the above nothing is replaced */
  8398. if (left && right) { /* Match accepted */
  8399. ok = 1; /* OK to replace */
  8400. xx++; /* Count this match */
  8401. }
  8402. } else
  8403. #endif /* RPLWORDMODE */
  8404. xx++; /* Straight replace - count every match */
  8405. if (ok && (occur == 0 || occur == xx)) {
  8406. if (len3) {
  8407. ckstrncpy(p,bp[2],FNVALL);
  8408. p += len3;
  8409. }
  8410. s += len2; /* and skip past it. */
  8411. } else { /* matched but not selected */
  8412. *p++ = *s++; /* Just copy this character */
  8413. }
  8414. } else { /* Didn't match */
  8415. *p++ = *s++; /* just copy this character */
  8416. }
  8417. }
  8418. *p = NUL;
  8419. while ((*p++ = *s++)); /* Append the rest */
  8420. if (occur < 0) { /* cheap... */
  8421. occur = xx + occur + 1;
  8422. xx = 0;
  8423. p = fnval;
  8424. j = j2;
  8425. if (occur > 0)
  8426. goto ragain;
  8427. }
  8428. }
  8429. }
  8430. p = fnval;
  8431. goto fnend;
  8432. case FN_CHR: /* \fcharacter(arg1) */
  8433. val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8434. if (chknum(val1)) { /* Must be numeric */
  8435. i = atoi(val1);
  8436. if (i >= 0 && i < 256) { /* Must be an 8-bit value */
  8437. p = fnval;
  8438. *p++ = (char) i;
  8439. *p = NUL;
  8440. p = fnval;
  8441. } else {
  8442. failed = 1;
  8443. if (fndiags)
  8444. ckmakmsg(fnval,FNVALL,
  8445. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  8446. }
  8447. } else {
  8448. failed = 1;
  8449. evalerr(fn);
  8450. }
  8451. goto fnend;
  8452. case FN_COD: /* \fcode(string) */
  8453. /*
  8454. returns decimal character value of first char in string.
  8455. or 0 if string empty or no string given.
  8456. */
  8457. p = "0";
  8458. if (!bp[0]) goto fnend; /* No argument given */
  8459. if ((int)strlen(bp[0]) < 1) /* Empty argument */
  8460. goto fnend;
  8461. i = (int) bp[0][0];
  8462. debug(F111,"FN_CODE",bp[0],i);
  8463. p = fnval;
  8464. sprintf(p,"%d",(i & 0xff)); /* SAFE */
  8465. debug(F111,"FN_CODE fnval",fnval,i);
  8466. goto fnend;
  8467. case FN_LEN: /* \flength(arg1) */
  8468. if (argn > 0) {
  8469. p = fnval;
  8470. sprintf(p,"%d",(int)strlen(bp[0])); /* SAFE */
  8471. } else p = "0";
  8472. goto fnend;
  8473. case FN_LOW: /* \flower(arg1) */
  8474. s = bp[0] ? bp[0] : "";
  8475. p = fnval;
  8476. while (*s) {
  8477. if (isupper(*s))
  8478. *p = (char) tolower(*s);
  8479. else
  8480. *p = *s;
  8481. p++; s++;
  8482. }
  8483. *p = NUL;
  8484. p = fnval;
  8485. goto fnend;
  8486. case FN_MAX: /* \fmax(arg1,arg2) */
  8487. case FN_MIN: /* \fmin(arg1,arg2) */
  8488. case FN_MOD: /* \fmod(arg1,arg2) */
  8489. val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8490. #ifdef COMMENT
  8491. /* No longer necessary because evalx() no longer overwrites its */
  8492. /* result every time it's called (2000/09/23). */
  8493. free(bp[0]);
  8494. bp[0] = NULL;
  8495. #endif /* COMMENT */
  8496. if (argn > 1) {
  8497. #ifdef COMMENT
  8498. /* Ditto... */
  8499. bp[0] = malloc((int)strlen(val1)+1);
  8500. if (bp[0])
  8501. strcpy(bp[0],val1); /* safe */
  8502. val1 = bp[0];
  8503. #endif /* COMMENT */
  8504. val2 = *(bp[1]) ? evalx(bp[1]) : "";
  8505. if (chknum(val1) && chknum(val2)) {
  8506. i = atoi(val1);
  8507. j = atoi(val2);
  8508. switch (y) {
  8509. case FN_MAX:
  8510. if (j < i) j = i;
  8511. break;
  8512. case FN_MIN:
  8513. if (j > i) j = i;
  8514. break;
  8515. case FN_MOD:
  8516. if (j == 0) {
  8517. failed = 1;
  8518. if (fndiags)
  8519. ckmakmsg(fnval,FNVALL,
  8520. "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  8521. else
  8522. fnval[0] = NUL;
  8523. goto fnend;
  8524. } else
  8525. j = i % j;
  8526. }
  8527. p = fnval;
  8528. sprintf(p,"%d",j); /* SAFE */
  8529. } else {
  8530. failed = 1;
  8531. evalerr(fn);
  8532. }
  8533. } else p = val1;
  8534. goto fnend;
  8535. } /* Break up big switch... */
  8536. switch (y) {
  8537. case FN_SUB: /* \fsubstr(arg1,arg2,arg3) */
  8538. case FN_RIG: /* \fright(arg1,arg2) */
  8539. case FN_LEF: /* \fleft(arg1,arg2) */
  8540. if (argn < 1)
  8541. goto fnend;
  8542. val1 = "";
  8543. if (argn > 1)
  8544. if (*(bp[1]))
  8545. val1 = evalx(bp[1]);
  8546. #ifdef COMMENT
  8547. if (bp[1]) free(bp[1]); /* Have to copy this */
  8548. bp[1] = malloc((int)strlen(val1)+1);
  8549. if (!bp[1]) {
  8550. failed = 1;
  8551. if (fndiags) {
  8552. p = fnval;
  8553. ckmakmsg(fnval,FNVALL,
  8554. "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8555. }
  8556. goto fnend;
  8557. }
  8558. strcpy(bp[1],val1); /* safe */
  8559. val1 = bp[1];
  8560. #endif /* COMMENT */
  8561. val2 = "";
  8562. if (argn > 2)
  8563. if (*(bp[2]))
  8564. val2 = evalx(bp[2]);
  8565. if (
  8566. ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
  8567. ((cx == FN_SUB) &&
  8568. ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
  8569. ) {
  8570. failed = 1;
  8571. evalerr(fn);
  8572. } else {
  8573. int lx;
  8574. p = fnval; /* pointer to result */
  8575. lx = strlen(bp[0]); /* length of arg1 */
  8576. if (cx == FN_SUB) { /* substring */
  8577. k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
  8578. j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
  8579. } else if (cx == FN_LEF) { /* left */
  8580. k = (argn > 1) ? atoi(val1) : lx;
  8581. j = 1;
  8582. } else { /* right */
  8583. k = (argn > 1) ? atoi(val1) : lx; /* length */
  8584. j = lx - k + 1; /* start pos for right */
  8585. if (j < 1) j = 1;
  8586. }
  8587. if (k > 0 && j <= lx) { /* if start pos in range */
  8588. s = bp[0]+j-1; /* point to source string */
  8589. for (i = 0; (i < k) && (*p++ = *s++); i++) ; /* copy */
  8590. }
  8591. *p = NUL; /* terminate the result */
  8592. p = fnval; /* and point to it. */
  8593. }
  8594. goto fnend;
  8595. case FN_UPP: /* \fupper(arg1) */
  8596. s = bp[0] ? bp[0] : "";
  8597. p = fnval;
  8598. while (*s) {
  8599. if (islower(*s))
  8600. *p = (char) toupper(*s);
  8601. else
  8602. *p = *s;
  8603. p++; s++;
  8604. }
  8605. *p = NUL;
  8606. p = fnval;
  8607. goto fnend;
  8608. case FN_REP: /* \frepeat(text,number) */
  8609. if (argn < 1)
  8610. goto fnend;
  8611. val1 = "1";
  8612. if (argn > 1)
  8613. if (*(bp[1]))
  8614. val1 = evalx(bp[1]);
  8615. if (chknum(val1)) { /* Repeat count */
  8616. n = atoi(val1);
  8617. debug(F111,"SUNDAY frepeat n",val1,n);
  8618. if (n > 0) { /* Make n copies */
  8619. p = fnval;
  8620. *p = '\0';
  8621. k = (int)strlen(bp[0]); /* Make sure string has some length */
  8622. debug(F111,"SUNDAY frepeat k","",k);
  8623. debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
  8624. if (k * n >= FNVALL) { /* But not too much... */
  8625. failed = 1;
  8626. if (fndiags)
  8627. ckmakmsg(fnval,FNVALL,
  8628. "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  8629. else
  8630. fnval[0] = NUL;
  8631. p = fnval;
  8632. goto fnend;
  8633. }
  8634. if (k > 0) { /* If there is something to copy */
  8635. for (i = 0; i < n; i++) { /* Copy loop */
  8636. s = bp[0];
  8637. for (j = 0; j < k; j++) {
  8638. if ((p - fnval) >= FNVALL)
  8639. break; /* shouldn't happen... */
  8640. else
  8641. *p++ = *s++;
  8642. }
  8643. }
  8644. *p = NUL;
  8645. }
  8646. }
  8647. } else {
  8648. failed = 1;
  8649. evalerr(fn);
  8650. }
  8651. p = fnval;
  8652. goto fnend;
  8653. #ifndef NOFRILLS
  8654. case FN_REV: /* \freverse() */
  8655. if (argn < 1)
  8656. goto fnend;
  8657. yystring(bp[0],&p);
  8658. goto fnend;
  8659. #endif /* NOFRILLS */
  8660. case FN_RPA: /* \frpad() and \flpad() */
  8661. case FN_LPA:
  8662. if (argn < 1)
  8663. goto fnend;
  8664. val1 = "";
  8665. if (argn > 1)
  8666. if (*(bp[1]))
  8667. val1 = evalx(bp[1]);
  8668. if (argn == 1) { /* If a number wasn't given */
  8669. p = fnval; /* just return the original string */
  8670. ckstrncpy(p,bp[0],FNVALL);
  8671. } else if (argn > 1 && !*val1) {
  8672. failed = 1;
  8673. evalerr(fn);
  8674. } else /* if (chknum(val1)) */ { /* Repeat count */
  8675. char pc;
  8676. n = atoi(val1);
  8677. if (n >= 0) {
  8678. p = fnval;
  8679. k = (int)strlen(bp[0]); /* Length of string to be padded */
  8680. if (k >= n) { /* It's already long enough */
  8681. ckstrncpy(p,bp[0],FNVALL);
  8682. } else {
  8683. if (n + k <= FNVALL) {
  8684. pc = (char) ((argn < 3) ? SP : *bp[2]);
  8685. if (!pc) pc = SP;
  8686. if (cx == FN_RPA) { /* RPAD */
  8687. strncpy(p,bp[0],k); /* (leave it like this) */
  8688. p[k] = NUL;
  8689. p += k;
  8690. for (i = k; i < n; i++)
  8691. *p++ = pc;
  8692. } else { /* LPAD */
  8693. n -= k;
  8694. for (i = 0; i < n; i++)
  8695. *p++ = pc;
  8696. strncpy(p,bp[0],k); /* (leave it like this) */
  8697. p[k] = NUL;
  8698. p += k;
  8699. }
  8700. }
  8701. *p = NUL;
  8702. }
  8703. }
  8704. }
  8705. p = fnval;
  8706. goto fnend;
  8707. #ifdef ZFCDAT
  8708. case FN_FD: /* \fdate(filename) */
  8709. p = fnval;
  8710. s = zfcdat(bp[0]);
  8711. if (!s) s = "";
  8712. if (!*s) {
  8713. failed = 1;
  8714. if (fndiags)
  8715. ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8716. goto fnend;
  8717. }
  8718. ckstrncpy(fnval,s,FNVALL);
  8719. #endif /* ZFCDAT */
  8720. goto fnend;
  8721. } /* Break up big switch... */
  8722. switch (y) {
  8723. case FN_FS: { /* \fsize(filename) */
  8724. CK_OFF_T z;
  8725. p = fnval;
  8726. z = zchki(bp[0]);
  8727. if (z < (CK_OFF_T)0) {
  8728. failed = 1;
  8729. if (fndiags) {
  8730. if (z == (CK_OFF_T)-1)
  8731. ckmakmsg(fnval,FNVALL,
  8732. "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8733. else if (z == (CK_OFF_T)-2)
  8734. ckmakmsg(fnval,FNVALL,
  8735. "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  8736. else if (z == (CK_OFF_T)-3)
  8737. ckmakmsg(fnval,FNVALL,
  8738. "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  8739. else
  8740. ckmakmsg(fnval,FNVALL,
  8741. "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  8742. }
  8743. goto fnend;
  8744. }
  8745. ckstrncpy(fnval,ckfstoa(z),FNVALL);
  8746. goto fnend;
  8747. }
  8748. case FN_VER: /* \fverify() */
  8749. p = "-1";
  8750. if (argn == 1) /* No second arg */
  8751. goto fnend;
  8752. else if (!bp[1]) /* Or second arg null */
  8753. goto fnend;
  8754. else if (!*(bp[1])) /* or empty. */
  8755. goto fnend;
  8756. p = "0";
  8757. if (argn > 1) { /* Only works if we have 2 or 3 args */
  8758. int start;
  8759. char *s2, ch1, ch2;
  8760. start = 0;
  8761. if (argn > 2) { /* Starting position specified */
  8762. val1 = *(bp[2]) ? evalx(bp[2]) : "0";
  8763. if (chknum(val1)) {
  8764. start = atoi(val1) /* - 1 */;
  8765. if (start < 0) start = 0;
  8766. if (start > (int)strlen(bp[1]))
  8767. goto verfin;
  8768. } else {
  8769. failed = 1;
  8770. evalerr(fn);
  8771. goto fnend;
  8772. }
  8773. }
  8774. i = start;
  8775. p = "0";
  8776. for (s = bp[1] + start; *s; s++,i++) {
  8777. ch1 = *s;
  8778. if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
  8779. j = 0;
  8780. for (s2 = bp[0]; *s2; s2++) {
  8781. ch2 = *s2;
  8782. if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
  8783. if (ch1 == ch2) {
  8784. j = 1;
  8785. break;
  8786. }
  8787. }
  8788. if (j == 0) {
  8789. sprintf(fnval,"%d",i+1); /* SAFE */
  8790. p = fnval;
  8791. break;
  8792. }
  8793. }
  8794. }
  8795. verfin:
  8796. goto fnend;
  8797. case FN_IPA: /* Find and return IP address */
  8798. if (argn > 0) { /* in argument string. */
  8799. int start = 0;
  8800. if (argn > 1) { /* Starting position specified */
  8801. if (chknum(bp[1])) {
  8802. start = atoi(bp[1]) - 1;
  8803. if (start < 0) start = 0;
  8804. } else {
  8805. failed = 1;
  8806. if (fndiags)
  8807. ckmakmsg(fnval,FNVALL,
  8808. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8809. goto fnend;
  8810. }
  8811. }
  8812. p = getip(bp[0]+start);
  8813. } else p = "";
  8814. goto fnend;
  8815. #ifdef OS2
  8816. case FN_CRY:
  8817. p = "";
  8818. if (argn > 0) {
  8819. p = fnval;
  8820. ckstrncpy(p,bp[0],FNVALL);
  8821. ck_encrypt(p);
  8822. }
  8823. goto fnend;
  8824. case FN_OOX:
  8825. p = "";
  8826. if (argn > 0)
  8827. p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
  8828. goto fnend;
  8829. #endif /* OS2 */
  8830. case FN_HEX: /* \fhexify(arg1) */
  8831. if (argn < 1)
  8832. goto fnend;
  8833. if ((int)strlen(bp[0]) < (FNVALL / 2)) {
  8834. s = bp[0];
  8835. p = fnval;
  8836. while (*s) {
  8837. x = (*s >> 4) & 0x0f;
  8838. *p++ = hexdigits[x];
  8839. x = *s++ & 0x0f;
  8840. *p++ = hexdigits[x];
  8841. }
  8842. *p = NUL;
  8843. p = fnval;
  8844. }
  8845. goto fnend;
  8846. case FN_UNTAB: /* \funtab(arg1) */
  8847. if (argn < 1)
  8848. goto fnend;
  8849. if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8850. s = bp[0];
  8851. p = fnval;
  8852. if (untabify(bp[0],p,FNVALL) < 0) {
  8853. failed = 1;
  8854. if (fndiags)
  8855. ckmakmsg(fnval,FNVALL,
  8856. "<ERROR:OVERFLOW:\\f",fn,"()>",NULL);
  8857. }
  8858. goto fnend;
  8859. }
  8860. case FN_UNH: { /* \funhex(arg1) */
  8861. int c[2], i;
  8862. if (argn < 1)
  8863. goto fnend;
  8864. if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8865. s = bp[0];
  8866. p = fnval;
  8867. while (*s) {
  8868. for (i = 0; i < 2; i++) {
  8869. c[i] = *s++;
  8870. if (!c[i]) { p = ""; goto unhexfin; }
  8871. if (islower(c[i])) c[i] = toupper(c[i]);
  8872. if (c[i] >= '0' && c[i] <= '9') {
  8873. c[i] -= 0x30;
  8874. } else if (c[i] >= 'A' && c[i] <= 'F') {
  8875. c[i] -= 0x37;
  8876. } else {
  8877. failed = 1;
  8878. if (fndiags)
  8879. ckmakmsg(fnval,
  8880. FNVALL,
  8881. "<ERROR:ARG_OUT_OF_RANGE:\\f",
  8882. fn,
  8883. "()>",
  8884. NULL
  8885. );
  8886. goto fnend;
  8887. }
  8888. }
  8889. *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
  8890. }
  8891. *p = NUL;
  8892. p = fnval;
  8893. }
  8894. unhexfin:
  8895. goto fnend;
  8896. }
  8897. case FN_BRK: { /* \fbreak() */
  8898. char * c; /* Characters to break on */
  8899. char c2, s2;
  8900. int start = 0;
  8901. int done = 0;
  8902. if (argn < 1)
  8903. goto fnend;
  8904. if (argn > 2) {
  8905. s = bp[2] ? bp[2] : "0";
  8906. if (chknum(s)) {
  8907. start = atoi(s);
  8908. if (start < 0) start = 0;
  8909. if (start > (int)strlen(bp[0]))
  8910. goto brkfin;
  8911. } else {
  8912. failed = 1;
  8913. if (fndiags)
  8914. ckmakmsg(fnval,FNVALL,
  8915. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8916. goto fnend;
  8917. }
  8918. }
  8919. s = bp[0] + start; /* Source pointer */
  8920. while (*s && !done) {
  8921. s2 = *s;
  8922. if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
  8923. c = bp[1] ? bp[1] : ""; /* Character to break on */
  8924. while (*c) {
  8925. c2 = *c;
  8926. if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
  8927. if (c2 == s2) {
  8928. done = 1;
  8929. break;
  8930. }
  8931. c++;
  8932. }
  8933. if (done) break;
  8934. *p++ = *s++;
  8935. }
  8936. *p = NUL; /* terminate the result */
  8937. p = fnval; /* and point to it. */
  8938. brkfin:
  8939. goto fnend;
  8940. }
  8941. case FN_SPN: { /* \fspan() */
  8942. char *q;
  8943. char c1, c2;
  8944. int start = 0;
  8945. if (argn < 1)
  8946. goto fnend;
  8947. if (argn > 2) { /* Starting position */
  8948. s = bp[2] ? bp[2] : "0";
  8949. if (chknum(s)) {
  8950. start = atoi(s);
  8951. if (start < 0) start = 0;
  8952. } else {
  8953. failed = 1;
  8954. if (fndiags)
  8955. ckmakmsg(fnval,FNVALL,
  8956. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8957. goto fnend;
  8958. }
  8959. }
  8960. s = bp[0] + start; /* Source pointer */
  8961. if (argn > 1 &&
  8962. (int)strlen(bp[1]) > 0 &&
  8963. start <= (int)strlen(bp[0])) {
  8964. while (*s) { /* Loop thru source string */
  8965. q = bp[1]; /* Span string */
  8966. c1 = *s;
  8967. if (!inpcas[cmdlvl])
  8968. if (islower(c1)) c1 = toupper(c1);
  8969. x = 0;
  8970. while ((c2 = *q++)) {
  8971. if (!inpcas[cmdlvl])
  8972. if (islower(c2)) c2 = toupper(c2);
  8973. if (c1 == c2) { x = 1; break; }
  8974. }
  8975. if (!x) break;
  8976. *p++ = *s++;
  8977. }
  8978. *p = NUL; /* Terminate and return the result */
  8979. p = fnval;
  8980. }
  8981. goto fnend;
  8982. }
  8983. } /* Break up big switch... */
  8984. switch (y) {
  8985. case FN_TRM: /* \ftrim(s1[,s2]) */
  8986. case FN_LTR: /* \fltrim(s1[,s2]) */
  8987. if (argn < 1)
  8988. goto fnend;
  8989. if ((len1 = (int)strlen(bp[0])) > 0) {
  8990. if (len1 > FNVALL)
  8991. len1 = FNVALL;
  8992. s = " \t\r\n";
  8993. if (argn > 1) /* Trim list given */
  8994. s = bp[1];
  8995. len2 = (int)strlen(s);
  8996. if (len2 < 1) { /* or not... */
  8997. s = " \t\r\n"; /* Default is to trim whitespace */
  8998. len2 = 2;
  8999. }
  9000. if (cx == FN_TRM) { /* Trim from right */
  9001. char * q, p2, q2;
  9002. ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
  9003. p = fnval + len1 - 1; /* Point to last character */
  9004. while (p >= (char *)fnval) { /* Go backwards */
  9005. q = s; /* Point to trim list */
  9006. p2 = *p;
  9007. if (!inpcas[cmdlvl])
  9008. if (islower(p2)) p2 = toupper(p2);
  9009. while (*q) { /* Is this char in trim list? */
  9010. q2 = *q;
  9011. if (!inpcas[cmdlvl])
  9012. if (islower(q2)) q2 = toupper(q2);
  9013. if (p2 == q2) { /* Yes, null it out */
  9014. *p = NUL;
  9015. break;
  9016. }
  9017. q++;
  9018. }
  9019. if (!*q) /* Trim list exhausted */
  9020. break; /* So we're done. */
  9021. p--; /* Else keep trimming */
  9022. }
  9023. } else { /* Trim from left */
  9024. char * q, p2, q2;
  9025. p = bp[0]; /* Source */
  9026. while (*p) {
  9027. p2 = *p;
  9028. if (!inpcas[cmdlvl])
  9029. if (islower(p2)) p2 = toupper(p2);
  9030. q = s;
  9031. while (*q) { /* Is this char in trim list? */
  9032. q2 = *q;
  9033. if (!inpcas[cmdlvl])
  9034. if (islower(q2)) q2 = toupper(q2);
  9035. if (p2 == q2) { /* Yes, point past it */
  9036. p++; /* and try next source character */
  9037. break;
  9038. }
  9039. q++; /* No, try next trim character */
  9040. }
  9041. if (!*q) /* Trim list exhausted */
  9042. break; /* So we're done. */
  9043. }
  9044. ckstrncpy(fnval,p,FNVALL);
  9045. }
  9046. p = fnval;
  9047. } else p = "";
  9048. goto fnend;
  9049. case FN_CAP: /* \fcapitalize(arg1) */
  9050. if (argn < 1)
  9051. goto fnend;
  9052. s = bp[0];
  9053. p = fnval;
  9054. x = 0;
  9055. while ((c = *s++)) {
  9056. if (isalpha(c)) {
  9057. if (x == 0) {
  9058. x = 1;
  9059. if (islower(c))
  9060. c = toupper(c);
  9061. } else if (isupper(c))
  9062. c = tolower(c);
  9063. }
  9064. *p++ = c;
  9065. }
  9066. *p = NUL;
  9067. p = fnval;
  9068. goto fnend;
  9069. #ifdef COMMENT
  9070. case FN_TOD: /* Time of day to secs since midnite */
  9071. sprintf(fnval,"%ld",tod2sec(bp[0])); /* SAFE */
  9072. goto fnend;
  9073. #endif /* COMMENT */
  9074. case FN_FFN: /* Full pathname of file */
  9075. zfnqfp(bp[0],FNVALL,p);
  9076. if (!p) p = "";
  9077. goto fnend;
  9078. case FN_CHK: { /* \fchecksum() */
  9079. long chk = 0;
  9080. p = (argn > 0) ? bp[0] : "";
  9081. while (*p) chk += *p++;
  9082. sprintf(fnval,"%lu",chk); /* SAFE */
  9083. p = fnval;
  9084. goto fnend;
  9085. }
  9086. #ifndef NOXFER
  9087. case FN_CRC: /* \fcrc16() */
  9088. if (argn > 0)
  9089. sprintf(fnval,"%u", /* SAFE */
  9090. chk3((CHAR *)bp[0],(int)strlen(bp[0])));
  9091. else
  9092. p = "0";
  9093. goto fnend;
  9094. #endif /* NOXFER */
  9095. case FN_BSN: /* \fbasename() */
  9096. zstrip(bp[0],&p);
  9097. goto fnend;
  9098. #ifndef NOLOCAL
  9099. #ifdef OS2
  9100. case FN_SCRN_CX: /* \fscrncurx() */
  9101. p = fnval;
  9102. sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x); /* SAFE */
  9103. goto fnend;
  9104. case FN_SCRN_CY: /* \fscrncury() */
  9105. p = fnval;
  9106. sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y); /* SAFE */
  9107. goto fnend;
  9108. case FN_SCRN_STR: { /* \fscrnstr() */
  9109. videoline * line = NULL;
  9110. viocell * cells = NULL;
  9111. int row = 0, col = 0, len = 0;
  9112. /* NOTE: On Unicode systems, the screen contents are stored in */
  9113. /* in Unicode. Therefore, we should really be performing a */
  9114. /* conversion to the local character set. */
  9115. /* 6/18/2000 - added the translation to lcs */
  9116. if (bp[0] == NULL || bp[0][0] == '\0') {
  9117. row = 0;
  9118. } else {
  9119. if (chknum(bp[0])) {
  9120. row = atoi(bp[0]);
  9121. if (row < 0)
  9122. row = 0;
  9123. } else {
  9124. failed = 1;
  9125. if (fndiags)
  9126. ckmakmsg(fnval,FNVALL,
  9127. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9128. goto fnend;
  9129. }
  9130. }
  9131. line = VscrnGetLineFromTop( VTERM, (USHORT) row );
  9132. if (line != NULL) {
  9133. if (bp[1] == NULL || bp[1][0] == '\0')
  9134. col = 0;
  9135. else {
  9136. if (chknum(bp[0])) {
  9137. col = atoi(bp[1]);
  9138. if (col < 0 || col >= line->width)
  9139. col = 0;
  9140. } else {
  9141. failed = 1;
  9142. if (fndiags)
  9143. ckmakmsg(fnval,FNVALL,
  9144. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9145. goto fnend;
  9146. }
  9147. }
  9148. if (bp[2] == NULL || bp[2][0] == '\0') {
  9149. len = line->width - (col+1);
  9150. } else {
  9151. if (!chknum(bp[2])) {
  9152. failed = 1;
  9153. if (fndiags)
  9154. ckmakmsg(fnval,FNVALL,
  9155. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9156. goto fnend;
  9157. }
  9158. len = atoi(bp[2]);
  9159. if (len < 0 || len > line->width)
  9160. len = line->width;
  9161. }
  9162. cells = line->cells;
  9163. for (i = 0; i < len; i++) {
  9164. int pos = i + col;
  9165. if (pos < line->width) {
  9166. if (isunicode())
  9167. fnval[i] = (CHAR) utolxlat(cells[pos].c);
  9168. else
  9169. fnval[i] = (CHAR) (cells[pos].c & 0xFF);
  9170. if (fnval[i] == 0)
  9171. fnval[i] = SP;
  9172. } else
  9173. fnval[i] = SP;
  9174. }
  9175. fnval[i] = '\0';
  9176. } else {
  9177. fnval[0] = '\0';
  9178. }
  9179. p = fnval;
  9180. goto fnend;
  9181. }
  9182. #endif /* OS2 */
  9183. #endif /* NOLOCAL */
  9184. #ifndef NOPUSH
  9185. case FN_RAW: /* \frawcommand() */
  9186. case FN_CMD: { /* \fcommand() */
  9187. int x, c, n = FNVALL;
  9188. x = 0; /* Completion flag */
  9189. /*
  9190. ZIFILE can be safely used because we can't possibly be transferring a file
  9191. while executing this function.
  9192. */
  9193. if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
  9194. while (n-- > -1) { /* Read from it */
  9195. if ((c = zminchar()) < 0) {
  9196. x = 1; /* EOF - set completion flag */
  9197. if (cx == FN_CMD) { /* If not "rawcommand" */
  9198. p--; /* remove trailing newlines */
  9199. while (*p == CR || *p == LF)
  9200. p--;
  9201. p++;
  9202. }
  9203. *p = NUL; /* Terminate the string */
  9204. break;
  9205. } else /* Command still running */
  9206. *p++ = c; /* Copy the bytes */
  9207. }
  9208. zclose(ZIFILE); /* Close the command */
  9209. }
  9210. /* Return null string if command's output was too long. */
  9211. p = fnval;
  9212. if (!x) {
  9213. failed = 1;
  9214. if (fndiags)
  9215. ckmakmsg(fnval,FNVALL,
  9216. "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  9217. }
  9218. goto fnend;
  9219. }
  9220. #endif /* NOPUSH */
  9221. } /* Break up big switch... */
  9222. switch (y) {
  9223. case FN_STX: /* \fstripx(string,c) */
  9224. if (!(s = bp[0])) /* Make sure there is a string */
  9225. goto fnend;
  9226. c = '.'; /* Character to strip from */
  9227. if (argn > 1) if (*bp[1]) c = *bp[1];
  9228. n = ckstrncpy(fnval,bp[0],FNVALL);
  9229. while (--n >= 0) {
  9230. if (fnval[n] == c) {
  9231. fnval[n] = NUL;
  9232. break;
  9233. }
  9234. }
  9235. p = fnval;
  9236. goto fnend;
  9237. case FN_STL: /* \flop(string,c) */
  9238. case FN_LOPX: { /* \flopx(string,c) */
  9239. int n = 1;
  9240. if (!(s = bp[0])) /* Make sure there is a string */
  9241. goto fnend;
  9242. c = '.'; /* Character to strip to */
  9243. if (argn > 1) if (*bp[1]) c = *bp[1];
  9244. if (argn > 2) if (*bp[2]) {
  9245. #ifndef NOFLOAT
  9246. n = 0;
  9247. if (isfloat(bp[2],0)) {
  9248. n = (int)floatval;
  9249. if (n < 0) n = 0;
  9250. } else
  9251. #endif /* NOFLOAT */
  9252. n = atoi(bp[2]);
  9253. }
  9254. x = 0;
  9255. if (cx == FN_LOPX) { /* Lopx (from right) */
  9256. if (n == 0)
  9257. goto fnend;
  9258. s += strlen(s) - 1; /* We already know it's > 0 */
  9259. while (s-- >= bp[0]) {
  9260. if (*s == c) {
  9261. n--;
  9262. if (n == 0) {
  9263. s++;
  9264. x = 1;
  9265. break;
  9266. }
  9267. }
  9268. }
  9269. if (!x) s = "";
  9270. } else { /* Lop (from left) */
  9271. if (n == 0) {
  9272. p = bp[0];
  9273. goto fnend;
  9274. }
  9275. while (*s++) {
  9276. if (*(s-1) == c) {
  9277. if (--n == 0) {
  9278. x = 1;
  9279. break;
  9280. }
  9281. }
  9282. }
  9283. if (!x) s = bp[0];
  9284. }
  9285. ckstrncpy(fnval,s,FNVALL);
  9286. p = fnval;
  9287. goto fnend;
  9288. }
  9289. case FN_STN: /* \fstripn(string,n) */
  9290. if (argn < 1) /* Remove n chars from right */
  9291. goto fnend;
  9292. val1 = "0";
  9293. if (argn > 1)
  9294. if (*(bp[1]))
  9295. val1 = evalx(bp[1]);
  9296. if (!chknum(val1)) {
  9297. failed = 1;
  9298. evalerr(fn);
  9299. goto fnend;
  9300. }
  9301. n = atoi(val1);
  9302. if (n < 0) n = 0;
  9303. k = (int)strlen(s = bp[0]) - n;
  9304. if (k < 0) k = 0;
  9305. p = fnval;
  9306. while (k-- > 0)
  9307. *p++ = *s++;
  9308. *p = NUL;
  9309. p = fnval;
  9310. goto fnend;
  9311. case FN_STB: { /* \fstripb(string,c) */
  9312. char c2 = NUL;
  9313. int i, k = 0;
  9314. char * gr_opn = "\"{'([<"; /* Group open brackets */
  9315. char * gr_cls = "\"}')]>"; /* Group close brackets */
  9316. p = fnval;
  9317. *p = NUL;
  9318. if (!(s = bp[0])) /* Make sure there is a string */
  9319. goto fnend;
  9320. if ((x = strlen(s)) < 1)
  9321. goto fnend;
  9322. c = NUL; /* Brace/bracket kind */
  9323. if (argn > 1) {
  9324. if (*bp[1]) {
  9325. if (chknum(bp[1])) {
  9326. k = atoi(bp[1]);
  9327. if (k < 0) k = 63;
  9328. for (i = 0; i < 6; i++) {
  9329. if (k & (1<<i)) {
  9330. if (s[0] == gr_opn[i] && s[x-1] == gr_cls[i]) {
  9331. ckstrncpy(fnval,s+1,FNVALL);
  9332. fnval[x-2] = NUL;
  9333. goto fnend;
  9334. }
  9335. }
  9336. }
  9337. ckstrncpy(fnval,s,FNVALL); /* No match */
  9338. goto fnend;
  9339. }
  9340. }
  9341. }
  9342. c = !bp[1] ? 0 : *bp[1];
  9343. if (!c) c = s[0];
  9344. if (argn > 2) if (*bp[2]) c2 = *bp[2];
  9345. if (*s == c) {
  9346. if (!c2) {
  9347. switch (c) {
  9348. case '(': c2 = ')'; break;
  9349. case '[': c2 = ']'; break;
  9350. case '{': c2 = '}'; break;
  9351. case '<': c2 = '>'; break;
  9352. case '"': c2 = '"'; break;
  9353. case 39: c2 = 39; break;
  9354. case 96: c2 = 39; break;
  9355. default:
  9356. if (argn == 2) {
  9357. c2 = c;
  9358. } else {
  9359. strncpy(fnval,s,x); /* Leave it like this */
  9360. fnval[x] = NUL;
  9361. goto fnend;
  9362. }
  9363. }
  9364. }
  9365. if (s[x-1] == c2) {
  9366. strncpy(fnval,s+1,x-2); /* Leave it like this */
  9367. fnval[x-2] = NUL;
  9368. goto fnend;
  9369. }
  9370. }
  9371. strncpy(fnval,s,x);
  9372. fnval[x] = NUL;
  9373. goto fnend;
  9374. }
  9375. case FN_2HEX: /* Number to hex */
  9376. case FN_2OCT: /* Number to octal */
  9377. val1 = evalx(bp[0]);
  9378. if (!*val1) {
  9379. failed = 1;
  9380. evalerr(fn);
  9381. goto fnend;
  9382. }
  9383. sprintf(fnval, cx == FN_2HEX ? "%lx" : "%lo", atol(val1)); /* SAFE */
  9384. if (cx == FN_2HEX && (int)(strlen(fnval)&1))
  9385. sprintf(fnval,"0%lx",atol(val1)); /* SAFE */
  9386. p = fnval;
  9387. goto fnend;
  9388. case FN_DNAM: { /* Directory part of file name */
  9389. char *s;
  9390. zfnqfp(bp[0],FNVALL,p); /* Get full name */
  9391. if (!isdir(p)) { /* Is it already a directory? */
  9392. zstrip(p,&s); /* No get basename */
  9393. if (*s) {
  9394. x = ckindex(s,p,0,0,0); /* Pos of latter in former */
  9395. if (x > 0) p[x-1] = NUL;
  9396. }
  9397. }
  9398. if (!p) p = "";
  9399. goto fnend;
  9400. }
  9401. #ifndef NORANDOM
  9402. case FN_RAND: /* Random number */
  9403. #ifdef CK_SSL
  9404. if (RAND_bytes((unsigned char *)&k,sizeof(k)) < 0)
  9405. #endif /* CK_SSL */
  9406. k = rand();
  9407. x = 0;
  9408. if (argn > 0) {
  9409. if (!chknum(bp[0])) {
  9410. failed = 1;
  9411. if (fndiags)
  9412. ckmakmsg(fnval,FNVALL,
  9413. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9414. goto fnend;
  9415. }
  9416. x = atoi(bp[0]);
  9417. }
  9418. #ifdef COMMENT
  9419. sprintf(fnval,"%d", (x > 0 && k > 0) || (x < 0 && k < 0) ? k % x :
  9420. (x == 0 ? 0 : (0 - (k % (-x)))));
  9421. #else
  9422. debug(F111,"rand",ckitoa(x),k);
  9423. #ifdef SUNOS4
  9424. /* This is really strange but on SunOS, if we are requesting random numbers */
  9425. /* between 0 and 4 or less, they always come out in sequence: 0 1 2 3 0 1 2 */
  9426. /* Shifting the result of rand() in this case gives a more random result. */
  9427. if (x < 5)
  9428. k = k >> 5;
  9429. #endif /* SUNOS4 */
  9430. if ((x > 0 && k > 0) || (x < 0 && k < 0))
  9431. x = k % x;
  9432. else if (x == 0)
  9433. x = 0;
  9434. else
  9435. x = 0 - (k % (-x));
  9436. debug(F101,"rand x","",x);
  9437. sprintf(fnval,"%d", x); /* SAFE */
  9438. #endif /* COMMENT */
  9439. p = fnval;
  9440. goto fnend;
  9441. #endif /* NORANDOM */
  9442. } /* Break up big switch... */
  9443. switch (y) {
  9444. case FN_SPLIT: /* \fsplit(s1,a,s2,s3,mask) */
  9445. case FN_WORD: { /* \fword(s1,n,s2,s3,mask) */
  9446. int wordnum = 0;
  9447. int splitting = 0;
  9448. int x;
  9449. int array = 0;
  9450. int grouping = 0;
  9451. int nocollapse = 0;
  9452. char * sep = "";
  9453. char * notsep = "";
  9454. char * bp0 = NULL;
  9455. char * bp1 = NULL;
  9456. char abuf[16];
  9457. struct stringarray * q = NULL;
  9458. splitting = (cx == FN_SPLIT); /* Our job */
  9459. debug(F101,"FN_SPLIT splitting","",splitting);
  9460. fnval[0] = splitting ? '0' : NUL; /* Initial return value */
  9461. fnval[1] = NUL;
  9462. p = fnval;
  9463. bp0 = bp[0]; /* Source string */
  9464. if (!bp0) bp0 = "";
  9465. debug(F111,"fsplit bp[0]",bp0,argn);
  9466. if (argn < 1 || !*bp0) /* If none, return default value */
  9467. goto fnend;
  9468. bp1 = bp[1]; /* Function-dependent arg */
  9469. if (!bp1) bp1 = ""; /* (array or number) */
  9470. debug(F110,"fsplit bp[1]",bp1,0);
  9471. if (bp[5]) {
  9472. if (!chknum(bp[5])) {
  9473. failed = 1;
  9474. ckmakmsg(fnval,FNVALL,
  9475. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9476. goto fnend;
  9477. }
  9478. x = atoi(bp[5]);
  9479. nocollapse = x;
  9480. }
  9481. if (!splitting) { /* \fword(): n = desired word number */
  9482. val1 = "1"; /* Default is first word */
  9483. if (argn > 1) /* Word number supplied */
  9484. if (*bp1)
  9485. val1 = evalx(bp1);
  9486. if (!chknum(val1)) {
  9487. failed = 1;
  9488. ckmakmsg(fnval,FNVALL,
  9489. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9490. goto fnend;
  9491. }
  9492. n = atoi(val1);
  9493. } else if (argn > 1 && *bp1) { /* \fsplit(): n = word count */
  9494. ckstrncpy(abuf,bp1,16); /* Get array reference */
  9495. debug(F110,"fsplit abuf 1",abuf,0);
  9496. failed = 1; /* Assume it's bad */
  9497. if (fndiags) /* Default is this error message */
  9498. ckmakmsg(fnval,FNVALL,
  9499. "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9500. if (abuf[0] != '&') /* "Address" of array */
  9501. goto fnend; /* It's bad */
  9502. if (abuf[2]) { /* Check for brackets */
  9503. if (abuf[2] != '[' || abuf[3] != ']') {
  9504. goto fnend; /* Bad */
  9505. }
  9506. }
  9507. debug(F110,"fsplit abuf 2",abuf,0);
  9508. if (abuf[1] > 64 && abuf[1] < 91) /* Convert upper to lower */
  9509. abuf[1] += 32;
  9510. if (abuf[1] < 97 || abuf[1] > 122) { /* Check for a-z */
  9511. goto fnend;
  9512. }
  9513. debug(F110,"fsplit abuf 3",abuf,0);
  9514. array = 1;
  9515. fnval[0] = NUL; /* No error, erase message */
  9516. failed = 0; /* Unset failure flag */
  9517. n = 0; /* Initialize word counter */
  9518. }
  9519. if (argn > 2) /* Have break set? */
  9520. sep = bp[2];
  9521. debug(F111,"fsplit sep",sep,argn);
  9522. if (argn > 3) /* Have include set? */
  9523. notsep = bp[3];
  9524. debug(F111,"fsplit notsep",notsep,argn);
  9525. if (argn > 4) { /* Have grouping set? */
  9526. char * bp4 = bp[4];
  9527. debug(F111,"fsplit bp4",bp4,argn);
  9528. if (!bp4) bp4 = "0";
  9529. if (!*bp4) bp4 = "0";
  9530. if (chknum(bp4)) {
  9531. grouping = atoi(bp4);
  9532. if (grouping == -1)
  9533. grouping = 127;
  9534. } else {
  9535. failed = 1;
  9536. if (fndiags)
  9537. ckmakmsg(fnval,FNVALL,
  9538. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9539. goto fnend;
  9540. }
  9541. }
  9542. /* Args parsed, now do the work */
  9543. debug(F111,"fsplit bp0",bp0,n);
  9544. q = cksplit(splitting,n,bp0,sep,notsep,grouping,0,nocollapse,0);
  9545. wordnum = q ? q->a_size : -1; /* Check result */
  9546. if (wordnum < 0) {
  9547. failed = 1; /* Failure */
  9548. if (fndiags)
  9549. ckmakmsg(fnval,FNVALL,
  9550. (wordnum == -1) ?
  9551. "<ERROR:MALLOC_FAILURE:\\f" :
  9552. "<ERROR:TOO_MANY_WORDS:\\f",
  9553. fn,
  9554. "()>",
  9555. NULL
  9556. );
  9557. goto fnend;
  9558. }
  9559. if (splitting) { /* \fsplit() result */
  9560. ckstrncpy(fnval,ckitoa(wordnum),FNVALL);
  9561. if (array) { /* Array was not declared. */
  9562. int i;
  9563. if ((x = dclarray(abuf[1],wordnum)) < 0) { /* Declare it. */
  9564. failed = 1;
  9565. if (fndiags)
  9566. ckmakmsg(fnval,FNVALL,
  9567. "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  9568. goto fnend;
  9569. }
  9570. for (i = 1; i <= wordnum; i++) { /* Copy results */
  9571. makestr(&(a_ptr[x][i]),q->a_head[i]);
  9572. }
  9573. a_ptr[x][0] = NULL; /* Array is 1-based */
  9574. makestr(&(a_ptr[x][0]),fnval); /* Element = size */
  9575. }
  9576. } else { /* \fword() result */
  9577. char * s;
  9578. s = q->a_head[1];
  9579. if (!s) s = "";
  9580. ckstrncpy(fnval,s,FNVALL);
  9581. }
  9582. goto fnend; /* Done */
  9583. }
  9584. } /* Break up big switch... */
  9585. switch (y) {
  9586. #ifdef CK_KERBEROS
  9587. case FN_KRB_TK: /* Kerberos tickets */
  9588. case FN_KRB_NX: /* Kerberos next ticket */
  9589. case FN_KRB_IV: /* Kerberos ticket is valid */
  9590. case FN_KRB_FG: /* Kerberos Ticket flags */
  9591. case FN_KRB_TT: { /* Kerberos ticket time */
  9592. int kv = 0; /* Kerberos version */
  9593. int n = 0;
  9594. char * s = NULL;
  9595. if (rdigits(bp[0])) {
  9596. kv = atoi(bp[0]);
  9597. } else {
  9598. failed = 1;
  9599. if (fndiags)
  9600. ckmakmsg(fnval,FNVALL,
  9601. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9602. goto fnend;
  9603. }
  9604. if (kv != 4 && kv != 5) {
  9605. failed = 1;
  9606. if (fndiags)
  9607. ckmakmsg(fnval,FNVALL,
  9608. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9609. goto fnend;
  9610. }
  9611. if ((cx == FN_KRB_IV || cx == FN_KRB_TT || cx == FN_KRB_FG) &&
  9612. argn < 2) {
  9613. failed = 1;
  9614. if (fndiags)
  9615. ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9616. goto fnend;
  9617. }
  9618. switch (y) {
  9619. case FN_KRB_TK: /* Number of Kerberos tickets */
  9620. #ifdef CK_AUTHENTICATION
  9621. switch (kv) {
  9622. case 4:
  9623. n = ck_krb4_get_tkts();
  9624. sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9625. goto fnend;
  9626. case 5: {
  9627. extern char * krb5_d_cc;
  9628. n = ck_krb5_get_tkts(krb5_d_cc);
  9629. sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9630. goto fnend;
  9631. }
  9632. }
  9633. #else
  9634. sprintf(fnval,"%d",0); /* SAFE */
  9635. #endif /* CK_AUTHENTICATION */
  9636. goto fnend;
  9637. case FN_KRB_NX: /* Kerberos next ticket */
  9638. #ifdef CK_AUTHENTICATION
  9639. switch (kv) {
  9640. case 4:
  9641. s = ck_krb4_get_next_tkt();
  9642. ckstrncpy(fnval, s ? s : "",FNVALL);
  9643. goto fnend;
  9644. case 5:
  9645. s = ck_krb5_get_next_tkt();
  9646. ckstrncpy(fnval, s ? s : "",FNVALL);
  9647. goto fnend;
  9648. }
  9649. #else
  9650. sprintf(fnval,"k%d next-ticket-string",kv); /* SAFE */
  9651. #endif /* CK_AUTHENTICATION */
  9652. goto fnend;
  9653. case FN_KRB_IV: /* Kerberos ticket is valid */
  9654. #ifdef CK_AUTHENTICATION
  9655. /* Return 1 if valid, 0 if not */
  9656. switch (kv) {
  9657. case 4:
  9658. n = ck_krb4_tkt_isvalid(bp[1]);
  9659. sprintf(fnval, "%d", n > 0 ? 1 : 0); /* SAVE */
  9660. goto fnend;
  9661. case 5: {
  9662. extern char * krb5_d_cc;
  9663. n = ck_krb5_tkt_isvalid(krb5_d_cc,bp[1]);
  9664. sprintf(fnval,"%d", n > 0 ? 1 : 0); /* SAFE */
  9665. goto fnend;
  9666. }
  9667. }
  9668. #else
  9669. sprintf(fnval,"%d",0); /* SAFE */
  9670. #endif /* CK_AUTHENTICATION */
  9671. goto fnend;
  9672. case FN_KRB_TT: /* Kerberos ticket time */
  9673. #ifdef CK_AUTHENTICATION
  9674. switch (kv) {
  9675. case 4:
  9676. n = ck_krb4_tkt_time(bp[1]);
  9677. sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9678. goto fnend;
  9679. case 5: {
  9680. extern char * krb5_d_cc;
  9681. n = ck_krb5_tkt_time(krb5_d_cc,bp[1]);
  9682. sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9683. goto fnend;
  9684. }
  9685. }
  9686. #else
  9687. ckstrncpy(fnval,"600",FNVALL); /* Some time */
  9688. #endif /* CK_AUTHENTICATION */
  9689. goto fnend;
  9690. case FN_KRB_FG: /* Kerberos ticket flags */
  9691. #ifdef CK_AUTHENTICATION
  9692. switch (kv) {
  9693. case 4:
  9694. fnval[0] = '\0';
  9695. goto fnend;
  9696. case 5: {
  9697. extern char * krb5_d_cc;
  9698. ckstrncpy(fnval,ck_krb5_tkt_flags(krb5_d_cc,bp[1]),FNVALL);
  9699. goto fnend;
  9700. }
  9701. }
  9702. #else
  9703. fnval[0] = '\0';
  9704. #endif /* CK_AUTHENTICATION */
  9705. goto fnend;
  9706. }
  9707. p = fnval;
  9708. goto fnend;
  9709. }
  9710. #endif /* CK_KERBEROS */
  9711. #ifdef FN_ERRMSG
  9712. case FN_ERRMSG:
  9713. if (rdigits(bp[0])) {
  9714. k = atoi(bp[0]);
  9715. } else {
  9716. failed = 1;
  9717. if (fndiags)
  9718. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9719. goto fnend;
  9720. }
  9721. #ifdef VMS
  9722. ckstrncpy(fnval,ckvmserrstr(k),FNVALL);
  9723. #else
  9724. x = errno;
  9725. errno = k;
  9726. ckstrncpy(fnval,ck_errstr(),FNVALL);
  9727. errno = x;
  9728. #endif /* VMS */
  9729. p = fnval;
  9730. goto fnend;
  9731. #endif /* FN_ERRMSG */
  9732. case FN_DIM: {
  9733. int max;
  9734. char abuf[16], *s;
  9735. fnval[0] = NUL; /* Initial return value */
  9736. ckstrncpy(abuf,bp[0],16); /* Get array reference */
  9737. s = abuf;
  9738. if (*s == CMDQ) s++;
  9739. failed = 1; /* Assume it's bad */
  9740. p = fnval; /* Point to result */
  9741. if (fndiags) /* Default is this error message */
  9742. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9743. if (s[0] != '&') { /* "Address" of array */
  9744. goto fnend;
  9745. }
  9746. if (s[2]) {
  9747. if (s[2] != '[' || s[3] != ']') {
  9748. goto fnend;
  9749. }
  9750. }
  9751. if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  9752. s[1] += 32;
  9753. if (s[1] < 95 || s[1] > 122) { /* Check for a-z */
  9754. goto fnend; /* Bad */
  9755. }
  9756. if ((max = chkarray(s[1],1)) < 1) /* (second arg was 1) */
  9757. max = 0;
  9758. failed = 0; /* Unset failure flag */
  9759. sprintf(fnval,"%d",max); /* SAFE */
  9760. goto fnend;
  9761. }
  9762. case FN_FILEINF: { /* File information */
  9763. #ifdef UNIX
  9764. /* from zgetfs in ckufio.c */
  9765. extern int zgfs_dir, zgfs_link;
  9766. extern char linkname[];
  9767. char * tx; /* For tilde expansion */
  9768. #else
  9769. int zgfs_dir = 0, zgfs_link = 0;
  9770. #endif /* UNIX */
  9771. char abuf[16], *s;
  9772. char ** ap = NULL;
  9773. char workbuf[MAXPATHLEN];
  9774. int attrs = 9; /* Number of attributes defined */
  9775. int k = 0; /* current attribute index */
  9776. int i,j,n;
  9777. int m; /* For scanfile() */
  9778. int dir = -1; /* 1 = arg is a directory file */
  9779. CK_OFF_T z, z2; /* For file size */
  9780. workbuf[0] = NUL;
  9781. workbuf[1] = NUL;
  9782. if (argn < 2) { /* An array designator is required */
  9783. if (fndiags)
  9784. ckmakmsg(fnval,FNVALL,"<ERROR:ARRAY_REQUIRED:\\f",fn,"()>",NULL);
  9785. goto fnend;
  9786. }
  9787. #ifdef UNIX
  9788. if (*(bp[0]) == '~') { /* Expand any tildes in filenames. */
  9789. tx = tilde_expand(bp[0]); /* We recycle bp[0] */
  9790. if (tx) if (*tx) { /* this way so they will be freed */
  9791. free(bp[0]); /* automatically later. */
  9792. bp[0] = NULL;
  9793. makestr(&(bp[0]),tx);
  9794. }
  9795. }
  9796. #endif /* UNIX */
  9797. j = ckstrncpy(workbuf,bp[0],MAXPATHLEN); /* Strip any trailing '/' */
  9798. if (workbuf[j-1] == '/') {
  9799. workbuf[j-1] = NUL;
  9800. makestr(&(bp[0]),workbuf);
  9801. }
  9802. z = zchki(bp[0]); /* Check accessibility */
  9803. if (z == -1L || z == -3L) { /* Access denied or whatever */
  9804. p = "0";
  9805. goto fnend;
  9806. /* Note: z > 0 is the file size but only of regular files */
  9807. /* Thus the zgetfs call just below */
  9808. }
  9809. #ifdef UNIX
  9810. if ((z2 = zgetfs(bp[0])) > 0) { /* Get size and some attributes */
  9811. z = z2; /* Have size */
  9812. dir = zgfs_dir; /* File is/isn't a directory */
  9813. }
  9814. #endif /* UNIX */
  9815. if (dir < 0) /* Check if file is a a directory */
  9816. dir = isdir(bp[0]); /* if previous clause didn't already */
  9817. fnval[0] = NUL; /* Initial return value */
  9818. ckstrncpy(abuf,bp[1],16); /* Get array reference */
  9819. s = abuf;
  9820. if (*s == CMDQ) s++;
  9821. failed = 1; /* Assume it's bad */
  9822. p = fnval; /* Point to result */
  9823. if (fndiags) /* Default is this error message */
  9824. ckmakmsg(fnval,FNVALL,
  9825. "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9826. if (s[0] != '&') /* "Address" of array */
  9827. goto fnend;
  9828. if (s[2])
  9829. if (s[2] != '[' || s[3] != ']')
  9830. goto fnend;
  9831. if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  9832. s[1] += 32;
  9833. if ((x = dclarray(s[1],attrs)) < 0) /* One element per attribute */
  9834. goto fnend;
  9835. failed = 0; /* Unset failure flag */
  9836. ap = a_ptr[x]; /* Point to array we just declared */
  9837. sprintf(fnval,"%d",k); /* SAFE */
  9838. /* Element 1 = filename */
  9839. s = bp[0]; /* Argument (might include path) */
  9840. n = strlen(s);
  9841. for (i = n; i > 0; i--) { /* Get filename without path */
  9842. if (ISDIRSEP(s[i-1])) { /* Platform independent way */
  9843. s += i;
  9844. break;
  9845. }
  9846. }
  9847. a_ptr[x][1] = NULL; /* Filename */
  9848. makestr(&(a_ptr[x][1]),s);
  9849. /* Element 2 - Full pathname */
  9850. s = workbuf;
  9851. zfnqfp(bp[0],FNVALL,s);
  9852. n = strlen(s);
  9853. for (i = n; i > 0; i--) { /* Get filename without path */
  9854. if (ISDIRSEP(s[i-1])) { /* Platform independent way */
  9855. s[i] = NUL;
  9856. break;
  9857. }
  9858. }
  9859. a_ptr[x][2] = NULL;
  9860. makestr(&(a_ptr[x][2]),s);
  9861. /* Element 3 - Modification date-time */
  9862. s = zfcdat(bp[0]);
  9863. a_ptr[x][3] = NULL;
  9864. makestr(&(a_ptr[x][3]),s);
  9865. /* Element 4 - Permissions string */
  9866. #ifdef UNIX
  9867. if (zgfs_link)
  9868. s = "lrwxrwxrwx";
  9869. else
  9870. #endif /* UNIX */
  9871. /* [jt] 2013/11/21:
  9872. * K-95 doesn't have ziperm. However, I have not read through this
  9873. * code thoroughly, and this needs double checked to see if there are
  9874. * any side effects of commenting this out.
  9875. */
  9876. #ifdef CK_PERMS
  9877. s = ziperm(bp[0]);
  9878. a_ptr[x][4] = NULL;
  9879. makestr(&(a_ptr[x][4]),s);
  9880. ckstrncpy(workbuf,s,32); /* Save for later */
  9881. #endif /* CK_PERMS */
  9882. /* Element 5 - Permissions numeric code */
  9883. s = zgperm(bp[0]);
  9884. a_ptr[x][5] = NULL;
  9885. makestr(&(a_ptr[x][5]),s);
  9886. /* Element 6 - Size in bytes */
  9887. #ifdef OS2 /* [jt] 2013/11/21 - K-95 doesn't have linkname */
  9888. s = ckfstoa(z);
  9889. #else
  9890. s = zgfs_link ? ckitoa((int)strlen((char *)linkname)) : ckfstoa(z);
  9891. #endif /* OS2 */
  9892. a_ptr[x][6] = NULL;
  9893. makestr(&(a_ptr[x][6]),s);
  9894. /* Element 7 - File type */
  9895. j = 0;
  9896. if (dir) j = 3;
  9897. #ifdef UNIX
  9898. else if (zgfs_link) j = 4;
  9899. else if (ckindex("x",(char *)workbuf,0,0,1)) j = 2;
  9900. else if (workbuf[1] != '-') j = 1;
  9901. #else
  9902. #ifdef VMS
  9903. else if (ckindex("E",(char *)workbuf,0,0,1)) j = 2;
  9904. else j = 1;
  9905. #endif /* VMS */
  9906. #endif /* UNIX */
  9907. a_ptr[x][7] = NULL;
  9908. switch (j) {
  9909. case 0: s = "unknown"; break;
  9910. case 1: s = "regular"; break;
  9911. case 2: s = "executable"; break;
  9912. case 3: s = "directory"; break;
  9913. case 4: s = "link"; break;
  9914. default: s = "unknown";
  9915. }
  9916. makestr(&(a_ptr[x][7]),s);
  9917. k = 7;
  9918. /* Element 8 - Name of linked-to file (if link) */
  9919. a_ptr[x][8] = NULL;
  9920. #ifdef UNIX
  9921. if (zgfs_link) {
  9922. makestr(&(a_ptr[x][8]),(char *)linkname);
  9923. k++;
  9924. }
  9925. #endif /* UNIX */
  9926. /* Element 9 - File scan result */
  9927. if (j == 1 || j == 2) { /* Regular file */
  9928. m = scanfile(bp[0],NULL,nscanfile);
  9929. if (m > -1) {
  9930. if (k < 8) k = 8; /* Insert empty element for link */
  9931. makestr(&(a_ptr[x][8]),"");
  9932. k++;
  9933. switch (m) {
  9934. case FT_7BIT: s = "text:7bit"; break;
  9935. case FT_UTF8: s = "text:utf8"; break;
  9936. case FT_UCS2: s = "text:ucs2"; break;
  9937. case FT_8BIT: s = "text:8bit"; break;
  9938. case FT_TEXT: s = "text:unknown"; break;
  9939. case FT_BIN: s = "binary"; break;
  9940. default: s = "unknown";
  9941. }
  9942. a_ptr[x][9] = NULL;
  9943. makestr(&(a_ptr[x][9]),s);
  9944. }
  9945. }
  9946. /* If adding another change attrs declaration to match */
  9947. /* Element 0 = array size */
  9948. p = ckitoa(k); /* Number of elements */
  9949. a_ptr[x][0] = NULL; /* Put number of elements in [0] */
  9950. makestr(&(a_ptr[x][0]),p);
  9951. debug(F101,"FILEINF","",attrs);
  9952. goto fnend;
  9953. }
  9954. case FN_FILECMP: { /* File comparison */
  9955. FILE *fp1 = NULL;
  9956. FILE *fp2 = NULL;
  9957. char * s, * s1 = NULL, * s2 = NULL;
  9958. #ifdef UNIX
  9959. char * tx; /* For tilde expansion */
  9960. #endif /* UNIX */
  9961. int c1, c2;
  9962. int eof1 = 0, eof2 = 0;
  9963. failed = 1; /* Assume files differ */
  9964. p[0] = '1'; /* Default return value = differ */
  9965. p[1] = NUL;
  9966. if (argn != 2) { /* Need two args */
  9967. if (fndiags)
  9968. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_COUNT:\\f",fn,"()>",NULL);
  9969. goto fnend;
  9970. }
  9971. s1 = bp[0];
  9972. s2 = bp[1];
  9973. #ifdef UNIX
  9974. if (*s1 == '~') { /* Expand any tildes in filenames. */
  9975. tx = tilde_expand(bp[0]); /* We recycle bp[0] and bp[1] */
  9976. if (tx) if (*tx) { /* this way so they will be freed */
  9977. free(bp[0]); /* automatically later. */
  9978. bp[0] = NULL;
  9979. makestr(&(bp[0]),tx);
  9980. }
  9981. s1 = bp[0];
  9982. }
  9983. if (*s2 == '~') {
  9984. tx = tilde_expand(bp[1]);
  9985. if (tx) if (*tx) {
  9986. free(bp[1]);
  9987. bp[1] = NULL;
  9988. makestr(&(bp[1]),tx);
  9989. }
  9990. s2 = bp[1];
  9991. }
  9992. #endif /* UNIX */
  9993. fp1 = fopen(s1, "r"); /* Open it first file*/
  9994. fp2 = fopen(s2, "r"); /* Open it first file*/
  9995. failed = 0; /* No failure from here down */
  9996. if (fp1 == NULL || fp2 == NULL) { /* Open failure */
  9997. p[0] = '-';
  9998. p[1] = '1';
  9999. p[2] = NUL; /* Return -1 */
  10000. if (fp1) fclose(fp1);
  10001. if (fp1) fclose(fp2);
  10002. goto fnend;
  10003. }
  10004. while (1) {
  10005. if (!eof1) {
  10006. c1 = getc(fp1);
  10007. if (c1 == (unsigned int)EOF) {
  10008. eof1++;
  10009. fclose(fp1);
  10010. }
  10011. }
  10012. if (!eof2) {
  10013. c2 = getc(fp2);
  10014. if (c2 == (unsigned int)EOF) {
  10015. eof2++;
  10016. fclose(fp2);
  10017. }
  10018. }
  10019. if (eof1 && eof2) {
  10020. p[0] = '0'; /* Success */
  10021. p[1] = NUL;
  10022. failed = 0;
  10023. goto fnend;
  10024. }
  10025. if (eof1 || eof2 || (c1 != c2)) {
  10026. if (!eof1) fclose(fp1);
  10027. if (!eof2) fclose(fp2);
  10028. goto fnend;
  10029. }
  10030. }
  10031. }
  10032. } /* Break up big switch... */
  10033. switch (y) {
  10034. case FN_JDATE:
  10035. if (argn < 1) /* Check number of args */
  10036. p = ckdate(); /* None, get today's date-time */
  10037. else /* Some */
  10038. p = bp[0]; /* Use first */
  10039. p = ckcvtdate(p,0); /* Convert to standard form */
  10040. ckstrncpy(fnval,zjdate(p),FNVALL); /* Convert to Julian */
  10041. p = fnval; /* Point to result */
  10042. failed = 0;
  10043. if (*p == '-') {
  10044. failed = 1;
  10045. if (fndiags) /* Default is this error message */
  10046. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10047. }
  10048. goto fnend;
  10049. case FN_DATEJ:
  10050. ckstrncpy(fnval,jzdate(bp[0]),FNVALL); /* Convert to yyyy<dayofyear> */
  10051. p = fnval; /* Point to result */
  10052. failed = 0;
  10053. if (*p == '-') {
  10054. failed = 1;
  10055. if (fndiags) /* Default is this error message */
  10056. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10057. }
  10058. goto fnend;
  10059. case FN_DTIM: /* \fcvtdate() */
  10060. case FN_TIME: /* Free-format time to hh:mm:ss */
  10061. case FN_NTIM: /* Time to sec since midnight */
  10062. s = (argn > 0) ? bp[0] : "";
  10063. if (!s) s = "";
  10064. if (!*s)
  10065. p = ckdate(); /* None, get today's date */
  10066. else /* Some */
  10067. p = bp[0]; /* Use first */
  10068. {
  10069. char * s;
  10070. s = p;
  10071. while (*s) { /* Strip leading spaces/ctrls */
  10072. if (*s < 32) {
  10073. *s = NUL;
  10074. break;
  10075. }
  10076. s++;
  10077. }
  10078. /* do { if (*s < '!') *s = NUL; break; } while (*s++); */
  10079. }
  10080. p = ckcvtdate(p,2); /* Convert to standard form */
  10081. if (*p == '<') {
  10082. failed = 1;
  10083. if (fndiags) /* Default is this error message */
  10084. ckmakmsg(fnval,FNVALL,
  10085. "<ERROR:ARG_BAD_DATE_OR_TIME:\\f",fn,"()>",NULL);
  10086. p = fnval;
  10087. goto fnend;
  10088. }
  10089. if (argn > 1) { /* Format code */
  10090. s = evalx(bp[1]);
  10091. if (!s) s = "";
  10092. if (!*s) s = "0";
  10093. if (!chknum(s)) {
  10094. failed = 1;
  10095. if (fndiags)
  10096. ckmakmsg(fnval,FNVALL,
  10097. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10098. p = fnval;
  10099. goto fnend;
  10100. }
  10101. x = atoi(s);
  10102. /* if (x) */ p = shuffledate(p,x);
  10103. }
  10104. if (cx == FN_TIME) {
  10105. p += 9;
  10106. } else if (cx == FN_NTIM) {
  10107. long sec = 0L;
  10108. p[11] = NUL;
  10109. p[14] = NUL;
  10110. sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  10111. sprintf(fnval,"%ld",sec); /* SAFE */
  10112. p = fnval;
  10113. }
  10114. goto fnend;
  10115. case FN_MJD: /* Modified Julian Date */
  10116. if (argn < 1) /* Check number of args */
  10117. p = zzndate(); /* None, get today's date-time */
  10118. else /* Some */
  10119. p = bp[0]; /* Use first */
  10120. p = ckcvtdate(p,0); /* Convert to standard form */
  10121. if (*p == '-') {
  10122. failed = 1;
  10123. if (fndiags) /* Default is this error message */
  10124. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10125. goto fnend;
  10126. }
  10127. /* Convert to modified Julian date */
  10128. sprintf(fnval,"%ld",mjd(p)); /* SAFE */
  10129. p = fnval; /* Point to result */
  10130. goto fnend;
  10131. case FN_MJD2: {
  10132. long k = 0L;
  10133. int n = 0;
  10134. p = evalx(bp[0]);
  10135. if (*p == '-') {
  10136. p++;
  10137. n = 1;
  10138. }
  10139. if (!rdigits(p)) {
  10140. failed = 1;
  10141. evalerr(fn);
  10142. p = fnval;
  10143. goto fnend;
  10144. } else {
  10145. k = atol(p);
  10146. if (n) k = -k;
  10147. }
  10148. ckstrncpy(fnval,mjd2date(k),FNVALL); /* Convert to Date */
  10149. p = fnval; /* Point to result */
  10150. failed = 0;
  10151. goto fnend;
  10152. }
  10153. #ifndef NODIAL
  10154. case FN_PNCVT: { /* Convert phone number */
  10155. extern char * pncvt();
  10156. failed = 0;
  10157. p = pncvt(bp[0]);
  10158. if (!p) p = "";
  10159. if (!*p) {
  10160. failed = 1;
  10161. if (fndiags) /* Default is this error message */
  10162. ckmakmsg(fnval,FNVALL,
  10163. "<ERROR:ARG_BAD_PHONENUM:\\f",fn,"()>",NULL);
  10164. }
  10165. goto fnend;
  10166. }
  10167. #endif /* NODIAL */
  10168. case FN_DAY:
  10169. case FN_NDAY:
  10170. if (argn < 1) /* Check number of args */
  10171. p = zzndate(); /* None, get today's date-time */
  10172. else /* Some */
  10173. p = bp[0]; /* Use first */
  10174. p = ckcvtdate(p,0); /* Convert to standard form */
  10175. if (*p == '-') {
  10176. failed = 1;
  10177. if (fndiags) /* Default is this error message */
  10178. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  10179. goto fnend;
  10180. }
  10181. failed = 0;
  10182. z = mjd(p); /* Convert to modified Julian date */
  10183. z = z % 7L;
  10184. if (z < 0) {
  10185. z = 0 - z;
  10186. k = 6 - ((int)z + 3) % 7;
  10187. } else {
  10188. k = ((int)z + 3) % 7; /* Day of week */
  10189. }
  10190. p = fnval; /* Point to result */
  10191. if (cx == FN_NDAY)
  10192. sprintf(fnval,"%d",k); /* SAFE */
  10193. else
  10194. ckstrncpy(fnval,wkdays[k],FNVALL);
  10195. goto fnend;
  10196. case FN_N2TIM: { /* Sec since midnight to hh:mm:ss */
  10197. long k = 0L;
  10198. int n = 0, hh, mm, ss;
  10199. char * s = bp[0];
  10200. if (argn < 1) /* If no arg substitute 0 */
  10201. s = "0";
  10202. p = evalx(s); /* Evaluate expression silently */
  10203. if (*p == '-') { /* Check result for minus sign */
  10204. p++;
  10205. n = 1;
  10206. }
  10207. if (!rdigits(p)) { /* Check for numeric */
  10208. failed = 1;
  10209. ckmakmsg(fnval,FNVALL,
  10210. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10211. p = fnval;
  10212. goto fnend;
  10213. } else {
  10214. k = atol(p);
  10215. if (n) k = -k;
  10216. }
  10217. if (k < 0) { /* Check for negative */
  10218. failed = 1;
  10219. if (fndiags)
  10220. ckmakmsg(fnval,FNVALL,
  10221. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10222. p = fnval;
  10223. goto fnend;
  10224. }
  10225. hh = k / 3600L; /* Have positive number */
  10226. mm = (k % 3600L) / 60L; /* break it down... */
  10227. ss = ((k % 3600L) % 60L);
  10228. sprintf(fnval,"%02d:%02d:%02d",hh,mm,ss); /* SAFE */
  10229. p = fnval;
  10230. failed = 0;
  10231. goto fnend;
  10232. }
  10233. case FN_PERM: { /* File permissions */
  10234. p = fnval;
  10235. z = zchki(bp[0]);
  10236. if (z < 0) {
  10237. failed = 1;
  10238. if (fndiags) {
  10239. if (z == -1)
  10240. ckmakmsg(fnval,FNVALL,
  10241. "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  10242. else if (z == -2)
  10243. ckmakmsg(fnval,FNVALL,
  10244. "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  10245. else if (z == -3)
  10246. ckmakmsg(fnval,FNVALL,
  10247. "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  10248. else
  10249. ckmakmsg(fnval,FNVALL,
  10250. "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  10251. }
  10252. goto fnend;
  10253. }
  10254. #ifdef CK_PERMS
  10255. ckstrncpy(fnval,ziperm(bp[0]),FNVALL);
  10256. #else
  10257. ckstrncpy(fnval,"(unknown)",FNVALL);
  10258. #endif /* CK_PERMS */
  10259. goto fnend;
  10260. }
  10261. case FN_TLOOK: /* tablelook() */
  10262. case FN_ALOOK: { /* arraylook() */
  10263. int i, x, hi, lo, max, cmdlen;
  10264. char abuf[16], *s, *pat;
  10265. char kwbuf[256];
  10266. char delim = ':';
  10267. failed = 1; /* Assume failure */
  10268. ckstrncpy(fnval,"-1",FNVALL);
  10269. pat = bp[0]; /* Point to search pattern */
  10270. if (!pat) pat = ""; /* Watch out for NULL pointer */
  10271. cmdlen = strlen(pat); /* Get pattern length */
  10272. if (argn < 2 /* || cmdlen < 1 */ ) { /* Need two args */
  10273. if (fndiags)
  10274. ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10275. goto fnend;
  10276. }
  10277. ckstrncpy(abuf,bp[1],16); /* Get array reference */
  10278. if (argn > 2)
  10279. delim = *(bp[2]);
  10280. s = abuf;
  10281. if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  10282. if (fndiags)
  10283. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10284. goto fnend;
  10285. }
  10286. p = fnval; /* Point to result */
  10287. max = a_dim[x]; /* Size of array */
  10288. if (lo < 0) lo = 0; /* Use given range if any */
  10289. if (lo > max) lo = max;
  10290. if (hi < 0) hi = max;
  10291. if (hi > max) hi = max;
  10292. failed = 0; /* Unset failure flag */
  10293. if (max < 1)
  10294. goto fnend;
  10295. kwbuf[255] = NUL;
  10296. for (i = lo; i <= hi; i++) {
  10297. if (!a_ptr[x][i])
  10298. continue;
  10299. if (cx == FN_ALOOK) {
  10300. if (ckmatch(pat,a_ptr[x][i],inpcas[cmdlvl],1+4)) {
  10301. sprintf(fnval,"%d",i); /* SAFE */
  10302. goto fnend;
  10303. }
  10304. } else if (cx == FN_TLOOK) {
  10305. char * aa;
  10306. int j = 0, v = 0, len;
  10307. if (i == hi)
  10308. break;
  10309. aa = a_ptr[x][i]; /* Point to this array element */
  10310. if (!aa) aa = "";
  10311. while (j < 254 && *aa) { /* Isolate keyword */
  10312. if (*aa == delim)
  10313. break;
  10314. kwbuf[j++] = *aa++;
  10315. }
  10316. kwbuf[j] = NUL;
  10317. len = j;
  10318. v = 0;
  10319. if ((len == cmdlen && !ckstrcmp(kwbuf,pat,len,0)) ||
  10320. ((v = !ckstrcmp(kwbuf,pat,cmdlen,0)) &&
  10321. ckstrcmp(a_ptr[x][i+1],pat,cmdlen,0))) {
  10322. sprintf(fnval,"%d",i); /* SAFE */
  10323. goto fnend;
  10324. }
  10325. if (v) { /* Ambiguous */
  10326. ckstrncpy(fnval,"-2",FNVALL);
  10327. goto fnend;
  10328. }
  10329. }
  10330. }
  10331. if (cx == FN_TLOOK) { /* tablelook() last element */
  10332. ckstrncpy(fnval,"-1",FNVALL);
  10333. if (!ckstrcmp(a_ptr[x][hi],pat,cmdlen,0))
  10334. sprintf(fnval,"%d",hi); /* SAFE */
  10335. }
  10336. goto fnend;
  10337. }
  10338. case FN_TOB64: /* Base-64 conversion */
  10339. case FN_FMB64:
  10340. p = fnval;
  10341. *p = NUL;
  10342. if (argn < 1)
  10343. goto fnend;
  10344. if (cx == FN_TOB64) {
  10345. x = b8tob64(bp[0],-1,fnval,FNVALL);
  10346. } else {
  10347. x = strlen(bp[0]);
  10348. if (x % 4) { /* length must be multiple of 4 */
  10349. failed = 1;
  10350. ckmakmsg(fnval,FNVALL,
  10351. "<ERROR:ARG_INCOMPLETE:\\f",fn,"()>",NULL);
  10352. goto fnend;
  10353. }
  10354. b64tob8(NULL,0,NULL,0); /* Reset */
  10355. x = b64tob8(bp[0],-1,fnval,FNVALL);
  10356. b64tob8(NULL,0,NULL,0); /* Reset again */
  10357. }
  10358. if (x < 0) {
  10359. failed = 1;
  10360. if (fndiags) {
  10361. char * m = "INTERNAL_ERROR";
  10362. switch (x) {
  10363. case -1: m = "ARG_TOO_LONG"; break;
  10364. case -2: m = "ARG_OUT_OF_RANGE"; break;
  10365. }
  10366. if (ckmakmsg(fnval,FNVALL,"<ERROR:",m,"\\f",fn) > 0)
  10367. ckstrncat(fnval,"()>",FNVALL);
  10368. }
  10369. }
  10370. goto fnend;
  10371. case FN_ABS: {
  10372. char * s;
  10373. s = bp[0];
  10374. if (*s == '-' || *s == '+')
  10375. s++;
  10376. if (!rdigits(s)) {
  10377. if (fndiags)
  10378. ckmakmsg(fnval,FNVALL,
  10379. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10380. goto fnend;
  10381. }
  10382. ckstrncpy(fnval,s,FNVALL);
  10383. goto fnend;
  10384. }
  10385. case FN_AADUMP: {
  10386. char abuf[16], *s = NULL, **ap = NULL, **vp = NULL;
  10387. char pattern[VNAML];
  10388. int slen, i, j, k, first = -1;
  10389. extern int xdelmac();
  10390. p = fnval;
  10391. if (argn < 2) {
  10392. if (fndiags)
  10393. ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG2:\\f",fn,"()>",NULL);
  10394. goto fnend;
  10395. }
  10396. debug(F101,"aaconvert argn","",argn);
  10397. s = bp[0];
  10398. slen = strlen(s);
  10399. /* Count elements so we can create the array */
  10400. ckmakmsg(pattern,VNAML,s,"<*>",NULL,NULL);
  10401. for (k = 0, i = 0; i < nmac; i++) {
  10402. if (ckmatch(pattern,mactab[i].kwd,0,1)) {
  10403. if (first < 0) /* Remember location of first match */
  10404. first = i;
  10405. k++;
  10406. }
  10407. }
  10408. debug(F101,"aaconvert matches","",k);
  10409. debug(F101,"aaconvert first","",first);
  10410. fnval[0] = NUL; /* Initial return value */
  10411. ckstrncpy(abuf,bp[1],16); /* Get array reference */
  10412. s = abuf;
  10413. if (*s == CMDQ) s++;
  10414. p = fnval; /* Point to result */
  10415. if (fndiags) /* Default is this error message */
  10416. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10417. if (s[0] != '&') /* Address of array */
  10418. goto fnend;
  10419. if (s[2])
  10420. if (s[2] != '[' || s[3] != ']')
  10421. goto fnend;
  10422. if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  10423. s[1] += 32;
  10424. if ((x = dclarray(s[1],k)) < 0) /* Declare array to size */
  10425. goto fnend;
  10426. ap = a_ptr[x]; /* Point to array we just declared */
  10427. /* debug(F111,"aaconvert array 1",abuf,ap); */
  10428. abuf[0] = NUL;
  10429. if (argn > 2) {
  10430. ckstrncpy(abuf,bp[2],16); /* Get value array reference */
  10431. s = abuf;
  10432. if (*s == CMDQ) s++;
  10433. if (s[0] != '&') /* Address of array */
  10434. goto fnend;
  10435. if (s[2])
  10436. if (s[2] != '[' || s[3] != ']')
  10437. goto fnend;
  10438. if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  10439. s[1] += 32;
  10440. if ((x = dclarray(s[1],k)) < 0)
  10441. goto fnend;
  10442. vp = a_ptr[x]; /* Point to array we just declared */
  10443. }
  10444. /* debug(F111,"aaconvert array 2",abuf,vp); */
  10445. makestr(&ap[0],ckitoa(k));
  10446. if (vp) makestr(&vp[0],ckitoa(k));
  10447. if (fndiags)
  10448. ckmakmsg(fnval,FNVALL,"<ERROR:ASSOCIATIVE_ARRAY:\\f",fn,"()>",NULL);
  10449. /* Copy macro index & value to the arrays and then remove the */
  10450. /* macro, so the 'first' pointer keeps indicating the next one. */
  10451. /* We could combine the initial counting loop with this one but */
  10452. /* then it would be harder to create the array and anyway this */
  10453. /* function is plenty fast as it is. */
  10454. for (i = 1; i <= k; ) {
  10455. if (!ckmatch(pattern,mactab[first].kwd,0,1)) {
  10456. debug(F111,"aaconvert oddball",mactab[first].kwd,first);
  10457. first++;
  10458. continue;
  10459. }
  10460. ckstrncpy(tmpbuf,mactab[first].kwd,TMPBUFSIZ); /* Macro name */
  10461. s = tmpbuf; /* Make writeable copy */
  10462. s += slen; /* Isolate "index" */
  10463. j = strlen(s) - 1;
  10464. if (*s != '<' || *(s+j) != '>') { /* Check syntax */
  10465. /* This shouldn't happen */
  10466. debug(F111,"aaconvert ERROR",mactab[first].kwd,first);
  10467. goto fnend;
  10468. }
  10469. *(s+j) = NUL; /* Remove final '>' */
  10470. debug(F111,"aaconvert",s+1,i);
  10471. makestr(&(ap[i]),s+1); /* Set first array to index */
  10472. if (vp)
  10473. makestr(&(vp[i]),mactab[first].mval); /* 2nd to value */
  10474. if (xdelmac(first) < 0)
  10475. goto fnend;
  10476. i++;
  10477. }
  10478. sprintf(fnval,"%d",k); /* SAFE */
  10479. p = fnval; /* Return size of array */
  10480. debug(F110,"aaconvert return",p,0);
  10481. failed = 0; /* Unset failure flag */
  10482. goto fnend;
  10483. }
  10484. } /* End of switch() */
  10485. #ifdef FNFLOAT
  10486. /*
  10487. Floating-point functions. To be included only if FNFLOAT is defined, which
  10488. should happen only if CKFLOAT is also defined, and if the math library is
  10489. linked in. Even then, we might have float-vs-double confusion as well as
  10490. confusion about what the final "%f" format effector is supposed to reference
  10491. (32 bits, 64 bits, etc). Expect trouble if CKFLOAT does not match the data
  10492. type of math library functions or args.
  10493. */
  10494. if (cx == FN_FPABS || /* Floating-point functions */
  10495. cx == FN_FPADD ||
  10496. cx == FN_FPDIV ||
  10497. cx == FN_FPEXP ||
  10498. cx == FN_FPLOG ||
  10499. cx == FN_FPLN ||
  10500. cx == FN_FPMOD ||
  10501. cx == FN_FPMAX ||
  10502. cx == FN_FPMIN ||
  10503. cx == FN_FPMUL ||
  10504. cx == FN_FPPOW ||
  10505. cx == FN_FPSQR ||
  10506. cx == FN_FPINT ||
  10507. cx == FN_FPSUB ||
  10508. cx == FN_FPROU ||
  10509. cx == FN_FPSIN ||
  10510. cx == FN_FPCOS ||
  10511. cx == FN_FPTAN) {
  10512. CKFLOAT farg[2], fpresult = 0.0;
  10513. char fpbuf[64], * bp0;
  10514. double dummy;
  10515. /* int sign = 0; */
  10516. int i, j, places = 0;
  10517. int argcount = 1;
  10518. failed = 1;
  10519. p = fnval;
  10520. bp0 = bp[0];
  10521. if (!bp0)
  10522. bp0 = "0";
  10523. else if (!*bp0)
  10524. bp0 = "0";
  10525. if (!isfloat(bp0,0)) {
  10526. k = mxlook(mactab,bp0,nmac);
  10527. bp0 = (k > -1) ? mactab[k].mval : NULL;
  10528. if (bp0) {
  10529. if (!isfloat(bp0,0)) {
  10530. if (fndiags)
  10531. ckmakmsg(fnval,FNVALL,
  10532. "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10533. goto fnend;
  10534. }
  10535. }
  10536. }
  10537. if (cx == FN_FPINT) { /* Float to int */
  10538. failed = 0;
  10539. ckstrncpy(fnval,bp0,FNVALL);
  10540. for (i = 0; fnval[i]; i++) {
  10541. if (fnval[i] == '.') {
  10542. fnval[i] = NUL;
  10543. break;
  10544. }
  10545. }
  10546. goto fnend;
  10547. }
  10548. switch (y) { /* These need 2 args */
  10549. case FN_FPADD:
  10550. case FN_FPDIV:
  10551. case FN_FPMOD:
  10552. case FN_FPMAX:
  10553. case FN_FPMIN:
  10554. case FN_FPMUL:
  10555. case FN_FPPOW:
  10556. case FN_FPSUB:
  10557. argcount = 2;
  10558. }
  10559. /* Missing arguments are supplied as 0.0 */
  10560. debug(F111,fn,"argcount",argcount);
  10561. for (i = 0; i < argcount; i++) { /* Get floating-point args */
  10562. #ifdef DEBUG
  10563. if (deblog) {
  10564. ckmakmsg(fpbuf,
  10565. 64,
  10566. "bp[",
  10567. ckitoa(i),
  10568. bp[i] ? bp[i] : "(null)",
  10569. "]"
  10570. );
  10571. debug(F100,fpbuf,"",0);
  10572. }
  10573. #endif /* DEBUG */
  10574. if (!bp[i]) {
  10575. farg[i] = 0.0;
  10576. } else if (!*(bp[i])) {
  10577. farg[i] = 0.0;
  10578. } else if (!isfloat(bp[i],0)) {
  10579. char * tmp;
  10580. k = mxlook(mactab,bp[i],nmac);
  10581. tmp = (k > -1) ? mactab[k].mval : NULL;
  10582. if (tmp) {
  10583. if (!isfloat(tmp,0)) {
  10584. if (fndiags)
  10585. ckmakmsg(fnval,FNVALL,
  10586. "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10587. goto fnend;
  10588. }
  10589. }
  10590. }
  10591. farg[i] = floatval;
  10592. #ifdef DEBUG
  10593. if (deblog) {
  10594. sprintf(fpbuf,"farg[%d]=%f",i,farg[i]); /* SAFE */
  10595. debug(F100,fpbuf,"",0);
  10596. }
  10597. #endif /* DEBUG */
  10598. }
  10599. if (bp[argcount]) { /* Get decimal places */
  10600. char * s;
  10601. s = bp[argcount];
  10602. if (!s) s = "";
  10603. if (!*s) s = "0";
  10604. s = evalx(s);
  10605. if (!s) s = "";
  10606. if (!*s) {
  10607. evalerr(fn);
  10608. goto fnend;
  10609. }
  10610. places = atoi(s);
  10611. }
  10612. errno = 0;
  10613. failed = 0;
  10614. switch (y) { /* Now do the requested function */
  10615. case FN_FPABS: /* Floating-point absolute value */
  10616. #ifndef COMMENT
  10617. fpresult = fabs(farg[0]);
  10618. #else
  10619. if (farg[0] < 0.0)
  10620. fpresult = 0.0 - farg[0];
  10621. #endif /* COMMENT */
  10622. break;
  10623. case FN_FPADD: /* FP add */
  10624. fpresult = farg[0] + farg[1];
  10625. break;
  10626. case FN_FPDIV: /* FP divide */
  10627. case FN_FPMOD: /* FP modulus */
  10628. if (!farg[1]) {
  10629. failed = 1;
  10630. if (fndiags)
  10631. ckmakmsg(fnval,FNVALL,
  10632. "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  10633. } else
  10634. fpresult = (cx == FN_FPDIV) ?
  10635. (farg[0] / farg[1]) :
  10636. fmod(farg[0],farg[1]);
  10637. break;
  10638. case FN_FPEXP: /* FP e to the x */
  10639. fpresult = (CKFLOAT) exp(farg[0]);
  10640. break;
  10641. case FN_FPLOG: /* FP base-10 logarithm */
  10642. case FN_FPLN: /* FP natural logarithm */
  10643. if (farg[0] < 0.0) {
  10644. failed = 1;
  10645. if (fndiags)
  10646. ckmakmsg(fnval,FNVALL,
  10647. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10648. } else
  10649. fpresult = (cx == FN_FPLOG) ? log10(farg[0]) : log(farg[0]);
  10650. break;
  10651. case FN_FPMUL: /* FP multiply */
  10652. fpresult = farg[0] * farg[1];
  10653. break;
  10654. case FN_FPPOW: /* FP raise to a power */
  10655. fpresult = modf(farg[1],&dummy);
  10656. if ((!farg[0] && farg[1] <= 0.0) ||
  10657. (farg[0] < 0.0 && fpresult)) {
  10658. failed = 1;
  10659. if (fndiags)
  10660. ckmakmsg(fnval,FNVALL,
  10661. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10662. } else
  10663. fpresult = pow(farg[0],farg[1]);
  10664. break;
  10665. case FN_FPSQR: /* FP square root */
  10666. if (farg[0] < 0.0) {
  10667. failed = 1;
  10668. if (fndiags)
  10669. ckmakmsg(fnval,FNVALL,
  10670. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10671. } else
  10672. fpresult = sqrt(farg[0]);
  10673. break;
  10674. case FN_FPSUB: /* FP subtract */
  10675. fpresult = farg[0] - farg[1];
  10676. break;
  10677. case FN_FPROU: /* FP round */
  10678. fpresult = farg[0];
  10679. break;
  10680. case FN_FPSIN: /* FP sine */
  10681. fpresult = (CKFLOAT) sin(farg[0]);
  10682. break;
  10683. case FN_FPCOS: /* FP cosine */
  10684. fpresult = (CKFLOAT) cos(farg[0]);
  10685. break;
  10686. case FN_FPTAN: /* FP tangent */
  10687. fpresult = (CKFLOAT) tan(farg[0]);
  10688. break;
  10689. case FN_FPMAX:
  10690. fpresult = (farg[0] > farg[1]) ? farg[0] : farg[1];
  10691. break;
  10692. case FN_FPMIN:
  10693. fpresult = (farg[0] < farg[1]) ? farg[0] : farg[1];
  10694. break;
  10695. }
  10696. /* Get here with fpresult = function result */
  10697. if (errno) { /* If range or domain error */
  10698. failed = 1;
  10699. if (fndiags)
  10700. ckmakmsg(fnval,FNVALL,
  10701. "<ERROR:FLOATING-POINT-OP:\\f",fn,"()>",NULL);
  10702. }
  10703. if (failed) /* and/or any other kind of error, */
  10704. goto fnend; /* fail. */
  10705. #ifndef COMMENT
  10706. /* Call routine containing code that was formerly inline */
  10707. ckstrncpy(fnval,fpformat(fpresult,places,cx == FN_FPROU),FNVALL);
  10708. #else
  10709. {
  10710. char fbuf[16]; /* For creating printf format */
  10711. if (!fp_rounding && /* If printf doesn't round, */
  10712. (places > 0 || /* round result to decimal places. */
  10713. (places == 0 && cx == FN_FPROU)))
  10714. fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  10715. if (places > 0) { /* If places specified */
  10716. /* use specified places to write given number of digits */
  10717. sprintf(fbuf,"%%0.%df",places); /* SAFE */
  10718. sprintf(fnval,fbuf,fpresult); /* SAFE */
  10719. } else { /* Otherwise... */
  10720. #ifdef COMMENT
  10721. /*
  10722. Here we want to print exactly fp_digits significant digits, no matter which
  10723. side of the decimal point they are on. That is, we want want the default
  10724. format to show the maximum number of non-garbage digits, AND we want the last
  10725. such digit to be rounded. Of course there is no way to do that, since the
  10726. digit after the last non-garbage digit is, well, garbage. So the following
  10727. clever ruse does no good.
  10728. */
  10729. int sign = 0, m = 0;
  10730. sprintf(fnval,"%f",fpresult);
  10731. if (fnval[0] == '-') sign = 1;
  10732. for (i = sign; i < FNVALL; i++) {
  10733. if (isdigit(fnval[i]))
  10734. m++;
  10735. else
  10736. break;
  10737. }
  10738. if (m > 1) {
  10739. int d = fp_digits - m;
  10740. if (d < 1) d = 1;
  10741. sprintf(fbuf,"%%%d.%df",fp_digits+sign+1,d);
  10742. } else {
  10743. sprintf(fbuf,"%%0.%df",fp_digits);
  10744. }
  10745. sprintf(fnval,fbuf,fpresult);
  10746. #else
  10747. /* Go for max precision */
  10748. sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  10749. sprintf(fnval,fbuf,fpresult); /* SAFE */
  10750. #endif /* COMMENT */
  10751. }
  10752. if (fnval[0] == '-') sign = 1;
  10753. }
  10754. debug(F111,"fpresult 1",fnval,errno); /* Check for over/underflow */
  10755. for (i = sign; fnval[i]; i++) { /* Give requested decimal places */
  10756. if (fnval[i] == '.') /* First find the decimal point */
  10757. break;
  10758. else if (i > fp_digits + sign - 1) /* replacing garbage */
  10759. fnval[i] = '0'; /* digits with 0... */
  10760. }
  10761. if (fnval[i] == '.') { /* Have decimal point */
  10762. int gotend = 0;
  10763. /* d < 0 so truncate fraction */
  10764. if (places < 0 || (places == 0 && cx == FN_FPROU)) {
  10765. fnval[i] = NUL;
  10766. } else if (places > 0) { /* d > 0 so this many decimal places */
  10767. i++; /* First digit after decimal */
  10768. for (j = 0; j < places; j++) { /* Truncate after d decimal */
  10769. if (!fnval[j+i]) /* places or extend to d */
  10770. gotend = 1; /* decimal places. */
  10771. if (gotend || j+i+sign > fp_digits)
  10772. fnval[j+i] = '0';
  10773. }
  10774. fnval[j+i] = NUL;
  10775. } else { /* d == 0 so Do The Right Thing */
  10776. for (j = (int)strlen(fnval) - 1; j > i+1; j--) {
  10777. if ((j - sign) > fp_digits)
  10778. fnval[j] = '0';
  10779. if (fnval[j] == '0')
  10780. fnval[j] = NUL; /* Strip useless trailing 0's. */
  10781. else
  10782. break;
  10783. }
  10784. }
  10785. }
  10786. #endif /* COMMENT */
  10787. debug(F111,"fpresult 2",fnval,errno);
  10788. goto fnend;
  10789. }
  10790. #endif /* FNFLOAT */
  10791. #ifdef CKCHANNELIO
  10792. if (cx == FN_FSTAT || /* File functions */
  10793. cx == FN_FPOS ||
  10794. cx == FN_FEOF ||
  10795. cx == FN_FGCHAR ||
  10796. cx == FN_FGLINE ||
  10797. cx == FN_FGBLK ||
  10798. cx == FN_FPCHAR ||
  10799. cx == FN_FPLINE ||
  10800. cx == FN_FPBLK ||
  10801. cx == FN_NLINE ||
  10802. cx == FN_FERMSG ||
  10803. cx == FN_FILNO) {
  10804. int x = 0, t = 0, channel;
  10805. long z;
  10806. extern int z_maxchan;
  10807. failed = 1; /* Assume failure */
  10808. p = fnval; /* until we validate args */
  10809. if (cx == FN_FERMSG) {
  10810. extern int z_error;
  10811. if (argn < 1) {
  10812. x = z_error;
  10813. } else if (chknum(bp[0])) {
  10814. x = atoi(bp[0]);
  10815. } else if (fndiags)
  10816. ckmakmsg(fnval,FNVALL,
  10817. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10818. failed = 0;
  10819. ckstrncpy(fnval,ckferror(x),FNVALL);
  10820. goto fnend;
  10821. }
  10822. if (argn < 1) { /* All file functions need channel */
  10823. if (cx == FN_FSTAT) { /* Except f_status(), e.g. when */
  10824. fnval[0] = '0'; /* called with a variable that */
  10825. fnval[1] = NUL; /* hasn't been defined yet. */
  10826. failed = 0;
  10827. } else {
  10828. if (fndiags)
  10829. ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10830. }
  10831. goto fnend;
  10832. }
  10833. if (rdigits(bp[0])) { /* Channel must be numeric */
  10834. channel = atoi(bp[0]);
  10835. } else { /* Fail if it isn't */
  10836. if (fndiags)
  10837. ckmakmsg(fnval,FNVALL,
  10838. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10839. goto fnend;
  10840. }
  10841. if (channel < 0 || channel > z_maxchan) { /* Check channel range */
  10842. if (fndiags)
  10843. ckmakmsg(fnval,FNVALL,
  10844. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10845. goto fnend;
  10846. }
  10847. x = z_getmode(channel); /* Find out about the channel */
  10848. failed = 0; /* Assume success from here down */
  10849. if (cx == FN_FSTAT) { /* Status / modes of channel */
  10850. if (x > -1)
  10851. x &= FM_RWB; /* Mask out irrelevant bits */
  10852. else /* In this case not open is OK */
  10853. x = 0; /* 0 if not open, 1-7 if open */
  10854. sprintf(fnval,"%d",x); /* SAFE */
  10855. goto fnend;
  10856. } else if (x < 1) { /* Not \f_status() so must be open */
  10857. failed = 1;
  10858. if (fndiags)
  10859. ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_OPEN:\\f",fn,"()>",NULL);
  10860. goto fnend;
  10861. }
  10862. switch (y) { /* Do the requested function */
  10863. case FN_FPOS: /* Get position */
  10864. z = z_getpos(channel); /* FIX THIS */
  10865. sprintf(fnval,"%ld",z); /* SAFE */
  10866. goto fnend;
  10867. case FN_NLINE: /* Get line number */
  10868. z = z_getline(channel); /* FIX THIS */
  10869. sprintf(fnval,"%ld",z); /* SAFE */
  10870. goto fnend;
  10871. case FN_FEOF: /* Check EOF */
  10872. t = 0;
  10873. if (x & FM_EOF) t = 1;
  10874. sprintf(fnval,"%d",t); /* SAFE */
  10875. goto fnend;
  10876. case FN_FILNO: /* Get file handle */
  10877. x = z_getfnum(channel);
  10878. sprintf(fnval,"%d",x); /* SAFE */
  10879. goto fnend;
  10880. case FN_FPBLK: /* Read or write block */
  10881. case FN_FGBLK:
  10882. if (argn < 2) {
  10883. if (fndiags)
  10884. ckmakmsg(fnval,FNVALL,
  10885. "<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10886. goto fnend;
  10887. }
  10888. if (rdigits(bp[1])) {
  10889. t = atoi(bp[1]);
  10890. } else {
  10891. if (fndiags)
  10892. ckmakmsg(fnval,FNVALL,
  10893. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10894. goto fnend;
  10895. }
  10896. case FN_FGCHAR: /* Read or write character or line */
  10897. case FN_FPCHAR:
  10898. case FN_FGLINE:
  10899. case FN_FPLINE:
  10900. fnval[0] = NUL;
  10901. switch (y) {
  10902. case FN_FGCHAR: t = z_in(channel,fnval,FNVALL,1,1); break;
  10903. case FN_FGLINE: t = z_in(channel,fnval,FNVALL,FNVALL-1,0); break;
  10904. case FN_FGBLK:
  10905. if (t >= FNVALL) t = FNVALL - 1;
  10906. t = z_in(channel,fnval,FNVALL,t,1);
  10907. break;
  10908. case FN_FPCHAR: t = z_out(channel,bp[1],1,1); break;
  10909. case FN_FPLINE: t = z_out(channel,bp[1],-1,0); break;
  10910. case FN_FPBLK: t = z_out(channel,bp[1],-1,1); break;
  10911. }
  10912. if (t < 0) { /* Handle read/write error */
  10913. failed = 1;
  10914. if (fndiags && t != FX_EOF)
  10915. ckmakmsg(fnval,FNVALL,
  10916. "<ERROR:FILE_ERROR_%d:\\f",fn,"()>",NULL);
  10917. goto fnend;
  10918. }
  10919. if (cx == FN_FGCHAR) /* Null terminate char */
  10920. fnval[1] = NUL;
  10921. /* Write (put) functions return numeric status code */
  10922. if (cx == FN_FPCHAR || cx == FN_FPLINE || cx == FN_FPBLK)
  10923. sprintf(fnval,"%d",t); /* SAFE */
  10924. goto fnend;
  10925. }
  10926. }
  10927. #endif /* CKCHANNELIO */
  10928. if (cx == FN_SQUEEZE) { /* String function \fsqueeze() */
  10929. /* Squeeze out whitespace */
  10930. /* Add options later for whether to trim leading and trailing blanks */
  10931. /* and what to do about control characters, 8-bit whitespace, etc */
  10932. int started = 0; /* Flag for first non-whitespace */
  10933. int n = 0; /* Blank/Tab counter */
  10934. s = bp[0] ? bp[0] : "";
  10935. p = fnval; /* Result buffer */
  10936. while (*s) { /* While there is input */
  10937. if (!started && (*s == ' ' || *s == '\011')) {
  10938. s++; /* Skip past leading whitespace */
  10939. continue;
  10940. }
  10941. started++; /* Leading whitespace was skipped */
  10942. if (*s != ' ' && *s != '\011') { /* Have a nonspace char */
  10943. n = 0; /* reset space counter */
  10944. *p++ = *s++; /* copy char to destination */
  10945. continue;
  10946. }
  10947. if (n++ > 0) { /* Have blank or tab */
  10948. s++; /* don't copy more than one */
  10949. continue;
  10950. }
  10951. *p++ = ' '; /* Deposit one space */
  10952. s++; /* and go to next source char */
  10953. }
  10954. if (*(p-1) == ' ') p--; /* Remove trailing space */
  10955. *p = NUL; /* Terminate string */
  10956. p = fnval; /* point to beginning */
  10957. goto fnend; /* Done. */
  10958. }
  10959. if (cx == FN_PATTERN) { /* \fpattern() for INPUT */
  10960. itsapattern = 1;
  10961. if (argn > 0) {
  10962. p = fnval;
  10963. ckstrncpy(fnval,bp[0],FNVALL);
  10964. } else p = "";
  10965. goto fnend;
  10966. }
  10967. if (cx == FN_HEX2N || cx == FN_OCT2N) { /* \fhex2n(), \foct2n() */
  10968. p = "0";
  10969. if (argn < 1)
  10970. goto fnend;
  10971. p = ckradix(bp[0], ((cx == FN_HEX2N) ? 16 : 8), 10);
  10972. if (!p) {
  10973. if (fndiags)
  10974. ckmakmsg(fnval,FNVALL,
  10975. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10976. goto fnend;
  10977. }
  10978. failed = 0;
  10979. ckstrncpy(fnval,p,FNVALL);
  10980. p = fnval;
  10981. goto fnend;
  10982. }
  10983. if (cx == FN_HEX2IP) {
  10984. int c[2], ip[4], i, k;
  10985. p = "0";
  10986. if (argn < 1)
  10987. goto fnend;
  10988. s = bp[0];
  10989. if ((int)strlen(s) != 8) {
  10990. failed = 1;
  10991. if (fndiags)
  10992. ckmakmsg(fnval,FNVALL,
  10993. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10994. goto fnend;
  10995. }
  10996. p = fnval;
  10997. for (k = 0; k < 8; k += 2) {
  10998. for (i = 0; i < 2; i++) {
  10999. c[i] = *s++;
  11000. if (islower(c[i])) c[i] = toupper(c[i]);
  11001. if (c[i] >= '0' && c[i] <= '9') {
  11002. c[i] -= 0x30;
  11003. } else if (c[i] >= 'A' && c[i] <= 'F') {
  11004. c[i] -= 0x37;
  11005. } else {
  11006. failed = 1;
  11007. if (fndiags)
  11008. ckmakmsg(fnval,FNVALL,
  11009. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11010. goto fnend;
  11011. }
  11012. ip[k/2] = c[0] << 4 | c[1];
  11013. }
  11014. sprintf(p,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  11015. }
  11016. goto fnend;
  11017. }
  11018. if (cx == FN_IP2HEX) {
  11019. int ip[4], i;
  11020. char * q;
  11021. p = "00000000";
  11022. if (argn < 1)
  11023. goto fnend;
  11024. s = bp[0];
  11025. p = fnval;
  11026. for (i = 0; i < 3; i++) {
  11027. q = ckstrchr(s,'.');
  11028. if (q) {
  11029. *q++ = NUL;
  11030. ip[i] = atoi(s);
  11031. s = q;
  11032. } else {
  11033. failed = 1;
  11034. if (fndiags)
  11035. ckmakmsg(fnval,FNVALL,
  11036. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11037. goto fnend;
  11038. }
  11039. }
  11040. ip[3] = atoi(s);
  11041. sprintf(p,"%02x%02x%02x%02x",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  11042. goto fnend;
  11043. }
  11044. if (cx == FN_RADIX) {
  11045. failed = 1;
  11046. p = fnval;
  11047. if (argn < 3) {
  11048. if (fndiags)
  11049. ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  11050. goto fnend;
  11051. }
  11052. if (!rdigits(bp[1]) || !rdigits(bp[2])) {
  11053. if (fndiags)
  11054. ckmakmsg(fnval,FNVALL,
  11055. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11056. goto fnend;
  11057. }
  11058. p = ckradix(bp[0],atoi(bp[1]),atoi(bp[2]));
  11059. if (!p) {
  11060. if (fndiags)
  11061. ckmakmsg(fnval,FNVALL,
  11062. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11063. goto fnend;
  11064. }
  11065. failed = 0;
  11066. ckstrncpy(fnval,p,FNVALL);
  11067. p = fnval;
  11068. goto fnend;
  11069. }
  11070. if (cx == FN_JOIN) {
  11071. int i, x, y, z, flag, flag2, hi, lo, max, seplen, grouping = 0;
  11072. char abuf[16], c, *s, *q, *sep = NULL;
  11073. char * gr_opn = "\"{'([<"; /* Group open brackets */
  11074. char * gr_cls = "\"}')]>"; /* Group close brackets */
  11075. char lb[2], rb[2]; /* Selected left and right brackets */
  11076. int csv = 0, tsv = 0; /* Function flags */
  11077. char specialchar = 0; /* Field char that triggers grouping */
  11078. char *s2 = NULL; /* Address of malloc'd storage */
  11079. failed = 1; /* Assume failure */
  11080. fnval[0] = NUL;
  11081. debug(F101,"FNJOIN ARGN","",argn);
  11082. ckstrncpy(abuf,bp[0],16); /* Get array reference */
  11083. s = abuf;
  11084. if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  11085. if (fndiags)
  11086. ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  11087. goto fnend;
  11088. }
  11089. p = fnval; /* Point to result */
  11090. max = a_dim[x]; /* Size of array */
  11091. if (lo < 0) lo = 1; /* Use given range if any */
  11092. if (lo > max) lo = max;
  11093. #ifdef COMMENT
  11094. hi = max;
  11095. #else
  11096. /*
  11097. This is a workaround for the problem in which the dimension of the \&_[]
  11098. array (but not its contents) grows upon entry to a SWITCH block. But this
  11099. code prevents the dimension from growing. Go figure.
  11100. */
  11101. if (hi < 0) { /* Bounds not given */
  11102. if (x) /* Regular array */
  11103. hi = max;
  11104. else /* Argument vector array */
  11105. for (hi = max; hi >= lo; hi--) { /* ignore any trailing */
  11106. if (!a_ptr[x][hi]) continue; /* empty elements */
  11107. if (!*(a_ptr[x][hi])) continue;
  11108. break;
  11109. }
  11110. }
  11111. #endif /* COMMENT */
  11112. if (hi > max) hi = max;
  11113. failed = 0; /* Unset failure flag */
  11114. if (max < 1)
  11115. goto fnend;
  11116. sep = " "; /* Separator */
  11117. lb[0] = NUL; /* Group start char (as string) */
  11118. rb[0] = NUL;
  11119. lb[1] = NUL; /* Group end char as string */
  11120. rb[1] = NUL;
  11121. if (argn > 1) {
  11122. if (bp[1]) if (*bp[1]) { /* If arg1 given and not empty */
  11123. if (!strcmp(bp[1],"CSV")) { /* Special "CSV" symbolic arg */
  11124. csv++; /* Make a comma separated list */
  11125. sep = ","; /* Comma */
  11126. specialchar = *sep; /* Separator is special character */
  11127. grouping = 1; /* Group with doublequotes */
  11128. lb[0] = '"'; /* and here */
  11129. rb[0] = '"'; /* they are */
  11130. } else if (!strcmp(bp[1],"TSV")) { /* "TSV" symbolic arg */
  11131. tsv++; /* Make a Tab separated list */
  11132. sep = "\011"; /* Tab */
  11133. specialchar = *sep;
  11134. grouping = 0; /* No grouping */
  11135. } else /* Normal case */
  11136. sep = bp[1]; /* use the separator char specified */
  11137. }
  11138. }
  11139. if (argn > 2 && !csv && !tsv) { /* Grouping? */
  11140. char * bp2 = bp[2];
  11141. if (!bp2) bp2 = "0";
  11142. if (!*bp2) bp2 = "0";
  11143. if (chknum(bp2)) {
  11144. grouping = atoi(bp2);
  11145. if (grouping < 0 || grouping > 63)
  11146. grouping = 1;
  11147. } else {
  11148. failed = 1;
  11149. if (fndiags)
  11150. ckmakmsg(fnval,FNVALL,
  11151. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11152. goto fnend;
  11153. }
  11154. if (grouping) { /* Take lowest-order one */
  11155. int j, k; /* and set the others to 0 */
  11156. for (k = 0; k < 6; k++) {
  11157. j = 1 << k;
  11158. if (grouping & j) {
  11159. lb[0] = gr_opn[k];
  11160. rb[0] = gr_cls[k];
  11161. break;
  11162. }
  11163. }
  11164. }
  11165. }
  11166. if (!csv && !tsv) { /* Normal case, not CSV or TSV */
  11167. specialchar = SP; /* Special character is space */
  11168. if (argn > 3) /* Nonzero 4th arg for no separator */
  11169. if (chknum(bp[3]))
  11170. if (atoi(bp[3]) > 0)
  11171. sep = NULL;
  11172. if (!sep) {
  11173. sep = "";
  11174. seplen = 0;
  11175. } else
  11176. seplen = strlen(sep);
  11177. }
  11178. for (i = lo; i <= hi; i++) { /* Loop thru selected array elements */
  11179. s = a_ptr[x][i]; /* Get next element */
  11180. if (!s)
  11181. s = "";
  11182. flag = 0; /* Flag to indicate grouping needed */
  11183. flag2 = 0; /* Flag for internal doublequotes */
  11184. if (grouping) { /* Does this element need quoting? */
  11185. q = s; /* Look for special character */
  11186. while ((c = *q++)) { /* If found */
  11187. if (c == specialchar) /* grouping is required */
  11188. flag++;
  11189. if (csv && (c == '"')) /* Character that needs doubling */
  11190. flag2++; /* in comma-separated list */
  11191. if (flag && !csv) /* Exit early if no more to do */
  11192. break;
  11193. }
  11194. }
  11195. y = strlen(s); /* Get length of this element */
  11196. if ((y > 0) && csv && !flag) { /* CSV item needs grouping */
  11197. if (s[0] == SP || s[y-1] == SP || /* if it has leading */
  11198. s[0] == HT || s[y-1] == HT) /* or trailing whitespace */
  11199. flag++; /* then it needs grouping */
  11200. }
  11201. if (flag || flag2) { /* String needs grouping or quoting */
  11202. char *ss = s;
  11203. q = (char *)malloc(y + flag2 + 3); /* Make new buffer */
  11204. if (q) {
  11205. s2 = q; /* and this is what to free */
  11206. if (flag) /* If grouping */
  11207. *q++ = lb[0]; /* put opening group quote */
  11208. while (*ss) { /* Loop through string */
  11209. if (flag2 && (*ss == '"')) /* If CSV and this a '"' */
  11210. *q++ = *ss; /* double it. */
  11211. *q++ = *ss++; /* Copy the character */
  11212. }
  11213. if (flag) /* If grouping */
  11214. *q++ = rb[0]; /* add closing group quote */
  11215. *q = NUL; /* terminate the result. */
  11216. s = s2;
  11217. y = strlen(s);
  11218. }
  11219. }
  11220. z = 0; /* Number of chars copied */
  11221. flag = 0; /* flag is now buffer-overrun flag */
  11222. if (y > 0) /* If this string is not empty */
  11223. z = ckstrncat(fnval,s,FNVALL); /* copy it. */
  11224. if (s2) free(s2); /* Free temp storage */
  11225. if (z < y) /* Now check for buffer overrun. */
  11226. flag++;
  11227. if (!flag && *sep && i < hi) { /* If buffer still has room */
  11228. z = ckstrncat(fnval,sep,FNVALL); /* copy delimiter */
  11229. if (z < seplen)
  11230. flag++;
  11231. }
  11232. if (flag) {
  11233. failed = 1;
  11234. if (fndiags)
  11235. ckmakmsg(fnval,FNVALL,
  11236. "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  11237. goto fnend;
  11238. }
  11239. }
  11240. isjoin = 1;
  11241. goto fnend;
  11242. }
  11243. if (cx == FN_SUBST) { /* \fsubstitute() */
  11244. CHAR c, * s, * r, * tp[2], buf1[256], buf2[256], buf3[256];
  11245. int len, i, j, state = 0, lo = 0, hi = 0;
  11246. failed = 0;
  11247. p = fnval; /* Result pointer */
  11248. *p = NUL;
  11249. if (!bp[0]) /* No target, no result*/
  11250. goto fnend;
  11251. len = strlen(bp[0]); /* Length of source */
  11252. if (len == 0)
  11253. goto fnend;
  11254. if (len > FNVALL) {
  11255. failed = 1;
  11256. if (fndiags)
  11257. ckmakmsg(fnval,FNVALL,
  11258. "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  11259. goto fnend;
  11260. }
  11261. if (!bp[1]) {
  11262. ckstrncpy(bp[0],fnval,FNVALL);
  11263. goto fnend;
  11264. }
  11265. tp[0] = buf1; /* For s2-s3 interpretation loop */
  11266. tp[1] = buf2;
  11267. for (i = 0; i < 256; i++) { /* Initialize working buffers */
  11268. buf1[i] = 0; /* s2 expansion buffer */
  11269. buf2[i] = 0; /* s3 expansion buffer */
  11270. buf3[i] = i; /* Translation table */
  11271. }
  11272. for (i = 0; i < 2; i++) { /* Interpret s2 and s3 */
  11273. s = (CHAR *)bp[i+1]; /* Arg pointer */
  11274. if (!s) s = (CHAR *)"";
  11275. r = tp[i]; /* To construct interpreted arg */
  11276. j = 0; /* Output buf pointer */
  11277. state = 0; /* Initial state */
  11278. while (c = *s++) { /* Loop thru arg chars */
  11279. if (j > 255) /* Output buf full */
  11280. break;
  11281. switch (state) {
  11282. case 0: /* Normal state */
  11283. switch (c) {
  11284. case '\\': /* Have quote */
  11285. state = 1;
  11286. break;
  11287. case '[': /* Have range starter */
  11288. state = 2;
  11289. break;
  11290. default: /* Anything else */
  11291. r[j++] = c;
  11292. break;
  11293. }
  11294. continue;
  11295. case 1: /* Quoted char */
  11296. r[j++] = c;
  11297. state = 0;
  11298. continue;
  11299. case 2: /* Range bottom */
  11300. lo = c;
  11301. state++;
  11302. continue;
  11303. case 3: /* Range separater */
  11304. if (c != '-') {
  11305. failed = 1;
  11306. if (fndiags)
  11307. ckmakmsg(fnval,FNVALL,
  11308. "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  11309. goto fnend;
  11310. }
  11311. state++;
  11312. continue;
  11313. case 4: /* Range top */
  11314. hi = c;
  11315. state++;
  11316. continue;
  11317. case 5: /* Range end */
  11318. if (c != ']') {
  11319. failed = 1;
  11320. if (fndiags)
  11321. ckmakmsg(fnval,FNVALL,
  11322. "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  11323. goto fnend;
  11324. }
  11325. for (k = lo; k <= hi && j < 255; k++) /* Fill in */
  11326. r[j++] = k;
  11327. lo = 0; hi = 0; /* Reset */
  11328. state = 0;
  11329. continue;
  11330. }
  11331. }
  11332. }
  11333. for (i = 0; i < 256 && buf1[i]; i++) { /* Create translation table */
  11334. k = (unsigned)buf1[i];
  11335. buf3[k] = buf2[i];
  11336. }
  11337. s = (CHAR *)bp[0]; /* Point to source string */
  11338. for (i = 0; i < len; i++) { /* Translation loop */
  11339. k = (unsigned)s[i]; /* Get next char */
  11340. if (!buf3[k]) /* Remove this char */
  11341. continue;
  11342. *p++ = buf3[k]; /* Substitute this char */
  11343. }
  11344. *p = NUL;
  11345. p = fnval;
  11346. goto fnend;
  11347. }
  11348. #ifndef NOSEXP
  11349. if (cx == FN_SEXP) { /* \fsexpression(arg1) */
  11350. char * p2;
  11351. fsexpflag++;
  11352. p = (argn > 0) ? dosexp(bp[0]) : "";
  11353. fsexpflag--;
  11354. p2 = fnval;
  11355. while ((*p2++ = *p++)) ;
  11356. p = fnval;
  11357. goto fnend;
  11358. }
  11359. #endif /* NOSEXP */
  11360. if (cx == FN_CMDSTK) { /* \fcmdstack(n1,n2) */
  11361. int i, j, k;
  11362. char * s;
  11363. if (bp[0])
  11364. val1 = *(bp[0]) ? evalx(bp[0]) : ckitoa(cmdlvl);
  11365. else
  11366. val1 = ckitoa(cmdlvl);
  11367. #ifdef COMMENT
  11368. free(bp[0]); /* (evalx() always uses same buffer) */
  11369. bp[0] = NULL; /* (not any more!) */
  11370. #endif /* COMMENT */
  11371. failed = 1;
  11372. if (argn > 1) {
  11373. #ifdef COMMENT
  11374. makestr(&(bp[0]),val1);
  11375. val1 = bp[0];
  11376. #endif /* COMMENT */
  11377. val2 = *(bp[1]) ? evalx(bp[1]) : "0";
  11378. if (!(chknum(val1) && chknum(val2))) {
  11379. if (fndiags)
  11380. ckmakmsg(fnval,FNVALL,
  11381. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11382. goto fnend;
  11383. }
  11384. } else {
  11385. val1 = ckitoa(cmdlvl);
  11386. val2 = "0";
  11387. }
  11388. i = atoi(val1); /* Level */
  11389. j = atoi(val2); /* Flags */
  11390. if (i < 0 || i > cmdlvl) {
  11391. if (fndiags)
  11392. ckmakmsg(fnval,FNVALL,
  11393. "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11394. goto fnend;
  11395. }
  11396. failed = 0;
  11397. p = fnval;
  11398. k = cmdstk[i].src; /* What (prompt, file, macro) */
  11399. if (j) {
  11400. ckstrncpy(fnval,ckitoa(k),FNVALL);
  11401. goto fnend;
  11402. }
  11403. switch (k) {
  11404. case CMD_KB:
  11405. ckstrncpy(fnval,"(prompt)",FNVALL);
  11406. break;
  11407. case CMD_TF:
  11408. s = tfnam[cmdstk[i].lvl];
  11409. if (!zfnqfp(s,FNVALL,fnval))
  11410. ckstrncpy(fnval,s,FNVALL);
  11411. break;
  11412. case CMD_MD:
  11413. ckstrncpy(fnval,m_arg[cmdstk[i].lvl][0],FNVALL);
  11414. break;
  11415. }
  11416. goto fnend;
  11417. }
  11418. #ifdef CKFLOAT
  11419. if (cx == FN_DIFDATE) { /* \fdiffdates(d1,d2) */
  11420. char * d1, * d2;
  11421. d1 = bp[0] ? bp[0] : ckdate();
  11422. d2 = bp[1] ? bp[1] : ckdate();
  11423. p = (char *)cmdiffdate(d1,d2);
  11424. if (!p) {
  11425. failed = 1;
  11426. if (fndiags) {
  11427. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11428. p = fnval;
  11429. }
  11430. }
  11431. goto fnend;
  11432. }
  11433. #endif /* CKFLOAT */
  11434. if (cx == FN_CMPDATE) { /* \fcmddates(d1,d2) */
  11435. int x = 0;
  11436. char d1[18], d2[18], * dp;
  11437. failed = 0;
  11438. d1[0] = NUL;
  11439. d2[0] = NUL;
  11440. p = fnval;
  11441. dp = cmcvtdate(bp[0],1);
  11442. if (dp) {
  11443. ckstrncpy(d1,dp,18);
  11444. if ((dp = cmcvtdate(bp[1],1))) {
  11445. ckstrncpy(d2,dp,18);
  11446. x = 1;
  11447. }
  11448. }
  11449. if (x == 0) {
  11450. failed = 1;
  11451. if (fndiags)
  11452. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11453. } else {
  11454. x = strcmp(d1,d2);
  11455. if (x > 0)
  11456. x = 1;
  11457. else if (x < 0)
  11458. x = -1;
  11459. sprintf(fnval,"%d",x);
  11460. }
  11461. goto fnend;
  11462. }
  11463. if (cx == FN_TOGMT) { /* \futcdate(d1) */
  11464. char * d1, * dp;
  11465. char datebuf[32];
  11466. char d2[32];
  11467. p = fnval;
  11468. failed = 1;
  11469. if ((dp = cmcvtdate(bp[0],1))) { /* The given date */
  11470. ckstrncpy(datebuf,dp,18);
  11471. ckstrncpy(d2,dp,18); /* local time */
  11472. ckstrncat(datebuf,"Z",19); /* Same time GMT */
  11473. if ((dp = cmcvtdate(datebuf,1))) /* converted to local time */
  11474. ckstrncpy(datebuf,dp,18);
  11475. if ((p = (char *)cmdiffdate(d2,datebuf))) { /* Get offset */
  11476. ckstrncat(d2,p,32); /* Append offset to local time */
  11477. if ((dp = cmcvtdate(d2,1))) {
  11478. failed = 0;
  11479. ckstrncpy(fnval,dp,FNVALL);
  11480. p = fnval;
  11481. }
  11482. }
  11483. }
  11484. if (failed && fndiags)
  11485. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11486. goto fnend;
  11487. }
  11488. if (cx == FN_DELSEC) { /* \fdelta2secs(delta-time) */
  11489. long secs;
  11490. p = fnval;
  11491. if ((x = delta2sec(bp[0],&secs)) < 0) {
  11492. failed = 1;
  11493. if (fndiags)
  11494. ckmakmsg(fnval,FNVALL,
  11495. (x == -1) ?
  11496. "<ERROR:BAD_DELTA_TIME:\\f" :
  11497. "<ERROR:OVERFLOW:\\f",
  11498. fn,
  11499. "()>",
  11500. NULL
  11501. );
  11502. goto fnend;
  11503. }
  11504. sprintf(p,"%ld",secs);
  11505. goto fnend;
  11506. }
  11507. if (cx == FN_PC_DU) {
  11508. char c, * s = bp[0];
  11509. if (!s) s = "";
  11510. p = fnval;
  11511. while ((c = *s++)) {
  11512. if (c == ':') {
  11513. if (*s != '\\')
  11514. *p++ = '/';
  11515. } else if (c == '\\') {
  11516. *p++ = '/';
  11517. } else {
  11518. *p++ = c;
  11519. }
  11520. }
  11521. *p = NUL;
  11522. p = fnval;
  11523. goto fnend;
  11524. }
  11525. if (cx == FN_PC_UD) { /* Unix to DOS path */
  11526. char c, * s = bp[0];
  11527. if (!s) s = "";
  11528. if (*s == '~') { /* Skip leading tilde */
  11529. s++;
  11530. if (*s == '/')
  11531. s++;
  11532. }
  11533. p = fnval;
  11534. while ((c = *s++))
  11535. *p ++ = (c == '/') ? '\\' : c;
  11536. *p = NUL;
  11537. p = fnval;
  11538. goto fnend;
  11539. }
  11540. if (cx == FN_KWVAL) { /* Keyword=Value */
  11541. p = dokwval(bp[0],bp[1]?bp[1]:"=");
  11542. goto fnend;
  11543. }
  11544. #ifdef COMMENT
  11545. /* Cute idea but doesn't work */
  11546. if (cx == FN_SLEEP || cx == FN_MSLEEP) {
  11547. p = "";
  11548. if (chknum(bp[0])) {
  11549. x = atoi(bp[0]);
  11550. } else {
  11551. failed = 1;
  11552. if (fndiags) {
  11553. ckmakmsg(fnval,FNVALL,
  11554. "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11555. p = fnval;
  11556. }
  11557. goto fnend;
  11558. }
  11559. if (cx == FN_SLEEP)
  11560. x *= 1000;
  11561. msleep(x);
  11562. goto fnend;
  11563. }
  11564. #endif /* COMMENT */
  11565. #ifdef NT
  11566. if (cx == FN_SNAME) {
  11567. GetShortPathName(bp[0],fnval,FNVALL);
  11568. goto fnend;
  11569. }
  11570. if (cx == FN_LNAME) {
  11571. ckGetLongPathName(bp[0],fnval,FNVALL);
  11572. goto fnend;
  11573. }
  11574. #endif /* NT */
  11575. /*
  11576. \femailaddress():
  11577. Picks the email address out of an RFC 2822 From: or Sender: header.
  11578. Added 26 Nov 2005. Handles all common, and some uncommon, cases but
  11579. doesn't totally bother about nested comments. Needed this for fetching
  11580. email from a POP server and then constructing the BSD "From " line.
  11581. Works with or without the "From: " or "Sender: " tag.
  11582. */
  11583. if (cx == FN_EMAIL) {
  11584. char c, * s = bp[0], * s2, * s3, * ap = "";
  11585. int k, state = 0, quote = 0, infield = 0;
  11586. int pc = 0; /* For nested comments */
  11587. if (!s) s = "";
  11588. if (!*s) goto xemail;
  11589. if (ckindex("From: ",s,0,0,0) == 1) s += 5;
  11590. if (ckindex("Sender: ",s,0,0,0) == 1) s += 7;
  11591. k = strlen(s); /* Strip junk from end */
  11592. if (k < 1) goto xemail;
  11593. k--;
  11594. while (k >= 0 && s[k] == CR || s[k] == LF)
  11595. s[k--] = NUL;
  11596. while (k >= 0 && s[k] == SP || s[k] == HT)
  11597. s[k--] = NUL;
  11598. if (k == 0)
  11599. goto xemail;
  11600. #ifndef COMMENT /* Simple method if not 100% foolproof */
  11601. k = 0;
  11602. for (s2 = s; *s2; s2++) { /* Find at-sign */
  11603. if (*s2 == '@') {
  11604. k++; /* If more than one use rightmost */
  11605. s3 = s2;
  11606. }
  11607. }
  11608. if (k < 1) /* No at-sign */
  11609. goto xemail;
  11610. for (ap = s3-1; ap >= s; ap--) { /* Back up to beginning of address */
  11611. if (isspace(*ap) || *ap == '<') {
  11612. ap++;
  11613. break;
  11614. }
  11615. if (ap == s)
  11616. break;
  11617. }
  11618. for (s2 = s3+1; *s2; s2++) { /* Find end of address */
  11619. if (isspace(*s2) || *s2 == '>')
  11620. break;
  11621. }
  11622. *s2-- = NUL;
  11623. if (*ap == '[' && *s2 == ']') { /* Handle [blah@blah.blah] */
  11624. ap++;
  11625. *s2 = NUL;
  11626. }
  11627. if (!ckstrcmp(ap,"mailto:",7,0)) /* Handle mailto: URLs */
  11628. ap += 7;
  11629. #else /* Too complicated and error-prone */
  11630. k = 0;
  11631. for (s2 = s; *s2; s2++) { /* Strip leading whitespace */
  11632. if (*s2 == SP || *s2 == HT) {
  11633. k = 1;
  11634. break;
  11635. }
  11636. }
  11637. if (!k) { /* Simple address */
  11638. ap = s;
  11639. goto xemail;
  11640. }
  11641. do { /* Not simple, have to extract it */
  11642. if (quote) {
  11643. quote = 0;
  11644. continue;
  11645. } else if (*s == '\\') {
  11646. quote = 1;
  11647. continue;
  11648. }
  11649. switch (state) {
  11650. case 0:
  11651. if (!infield && *s == '"') { /* Quoted string */
  11652. infield = 1;
  11653. c = '"';
  11654. state = 1;
  11655. } else if (!infield && *s == '(') { /* Comment in parens */
  11656. pc++;
  11657. infield = 1;
  11658. c = ')';
  11659. if (*ap) *s = NUL;
  11660. state = 1;
  11661. } else if (!infield && *s == '<') { /* Address */
  11662. infield = 1;
  11663. c = '>';
  11664. ap = s+1;
  11665. state = 2;
  11666. } else if (infield && (*s == SP || *s == HT)) {
  11667. infield = 0;
  11668. } else { /* One or more bare words */
  11669. infield = 1; /* Could be an address */
  11670. if (!*ap) ap = s; /* Could be comments */
  11671. }
  11672. continue;
  11673. case 1: /* In Quoted string or Comment */
  11674. if (infield && *s == c) { /* Look for end */
  11675. infield = 0;
  11676. *s++ = NUL;
  11677. while (*s == SP || *s == HT) s++;
  11678. if (!*ap)
  11679. ap = s;
  11680. state = 0;
  11681. }
  11682. continue;
  11683. case 2: /* In address */
  11684. if (infield && *s == c) { /* Looking for end */
  11685. infield = 0;
  11686. *s = NUL;
  11687. break;
  11688. }
  11689. }
  11690. } while (*s++);
  11691. xemail:
  11692. if (*ap) {
  11693. while (*ap == SP || *ap == HT) ap++;
  11694. }
  11695. k = strlen(ap) - 1;
  11696. while (k >= 0 && (ap[k] == SP || ap[k] == HT))
  11697. ap[k--] = NUL;
  11698. if (*ap) {
  11699. failed = 0;
  11700. if (*ap == '<') {
  11701. k = strlen(ap);
  11702. if (*(ap+k-1) == '>') {
  11703. ap[k-1] = NUL;
  11704. ap++;
  11705. }
  11706. }
  11707. } else
  11708. failed = 1;
  11709. /* Here we might also want check against "*@*.*" */
  11710. #endif /* COMMENt */
  11711. xemail:
  11712. ckstrncpy(fnval,ap,FNVALL);
  11713. goto fnend;
  11714. }
  11715. #ifdef SEEK_CUR
  11716. /*
  11717. \fpictureinfo(): Get dimensions of GIF or JPG image - fdc June 2006.
  11718. NOTE: The height and width of a JPG image do not necessarily indicate
  11719. an image's actual orientation. This is given by the Exif Orientation
  11720. tag (0x0122). But locating it in a JPG file without having a full-blown
  11721. Exif parser is probably not possible.
  11722. */
  11723. if (cx == FN_PICTURE) {
  11724. FILE *fp = NULL;
  11725. int c, x, w = 0, h = 0, eof = 0;
  11726. unsigned int i, j, k;
  11727. unsigned char buf[1024];
  11728. char abuf[16], * p, * s;
  11729. char ** ap = NULL;
  11730. #ifdef UNIX
  11731. char * tx;
  11732. #endif /* UNIX */
  11733. p = fnval; /* Point to result */
  11734. failed = 1; /* Assume failure */
  11735. s = bp[0];
  11736. #ifdef UNIX
  11737. if (*s == '~') {
  11738. tx = tilde_expand(bp[0]);
  11739. if (tx) if (*tx) {
  11740. free(bp[0]);
  11741. bp[0] = NULL;
  11742. makestr(&(bp[0]),tx);
  11743. }
  11744. s = bp[0];
  11745. }
  11746. #endif /* UNIX */
  11747. if (argn > 1) {
  11748. int xi;
  11749. ckstrncpy(abuf,bp[1],16); /* Get array reference */
  11750. s = abuf;
  11751. if (*s == CMDQ) s++;
  11752. if (fndiags) /* Default is this error message */
  11753. ckmakmsg(fnval,FNVALL,
  11754. "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  11755. if (s[0] != '&') /* "Address" of array */
  11756. goto fnend;
  11757. if (s[2])
  11758. if (s[2] != '[' || s[3] != ']')
  11759. goto fnend;
  11760. if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  11761. s[1] += 32;
  11762. if ((xi = dclarray(s[1],3)) < 0) /* three elements */
  11763. goto fnend;
  11764. ap = a_ptr[xi]; /* Point to array we just declared */
  11765. }
  11766. s = bp[0]; /* Filename */
  11767. failed = 0; /* From here on we don't fail */
  11768. p[0] = '0'; /* Default return value */
  11769. p[1] = NUL;
  11770. /* Tail anchor removed 2013-10-15 -fdc */
  11771. if (!ckmatch("*.{jpg,jpeg,gif}",s,0,1)) /* Appropriate name? */
  11772. goto fnend; /* No, fail */
  11773. fp = fopen(s, "r"); /* Open it */
  11774. if (fp == NULL) { /* Can't, fail */
  11775. p[0] = '-';
  11776. p[1] = '1';
  11777. p[2] = NUL; /* Return -1 */
  11778. goto fnend;
  11779. }
  11780. k = strlen(s);
  11781. if (!ckstrcmp(&s[k-4],".gif",4,0)) { /* GIF file */
  11782. if (fread(buf,1,10,fp) != 10) {
  11783. fclose(fp);
  11784. goto fnend;
  11785. }
  11786. /* Check signature */
  11787. if (ckstrcmp((char *)buf,"GIF87a",6,0) &&
  11788. ckstrcmp((char *)buf,"GIF89a",6,0)) {
  11789. fclose(fp);
  11790. goto fnend;
  11791. }
  11792. w = buf[6] + 256 * buf[7];
  11793. h = buf[8] + 256 * buf[9];
  11794. goto picend;
  11795. } else if (!ckstrcmp(&s[k-4],".jpg",4,0) || /* JPEG file */
  11796. !ckstrcmp(&s[k-5],".jpeg",5,0)) { /* (according to name) */
  11797. if (fread(buf,1,2,fp) != 2) { /* Read 1st bytes */
  11798. fclose(fp);
  11799. goto fnend;
  11800. }
  11801. if (buf[0] != 0xff || buf[1] != 0xd8) { /* Check signature */
  11802. fclose(fp); /* Should be FFD8 */
  11803. goto fnend;
  11804. }
  11805. eof = 0;
  11806. while (!eof) { /* Loop for each marker */
  11807. while (!eof) { /* Find next marker */
  11808. c = getc(fp);
  11809. if (c == (unsigned int)EOF) {
  11810. eof++;
  11811. break;
  11812. }
  11813. if (c == 0xff) {
  11814. buf[0] = c;
  11815. c = getc(fp);
  11816. if (c == (unsigned int)EOF) {
  11817. eof++;
  11818. break;
  11819. }
  11820. buf[1] = c;
  11821. if (c == 0xd9) /* FFD9 means End of Image */
  11822. eof++;
  11823. if (c >= 0xc0 && c <= 0xfe)
  11824. break;
  11825. }
  11826. }
  11827. if (eof) break;
  11828. x = buf[1];
  11829. if (x == 0xc0 || x == 0xc1 || x == 0xc2 || x == 0xc3 ||
  11830. x == 0xc9 || x == 0xca || x == 0xcb) {
  11831. if (fread(buf,1,7,fp) != 7) {
  11832. fclose(fp);
  11833. goto fnend;
  11834. }
  11835. h = buf[3] * 256 + buf[4];
  11836. w = buf[5] * 256 + buf[6];
  11837. goto picend;
  11838. } else { /* Not a desired field */
  11839. if (feof(fp)) {
  11840. eof++;
  11841. break;
  11842. }
  11843. if (fread(buf,1,2,fp) != 2) { /* Length of this field */
  11844. fclose(fp);
  11845. goto fnend;
  11846. }
  11847. j = 256 * buf[0] + buf[1] - 2; /* Skip next field */
  11848. if (CKFSEEK(fp,(CK_OFF_T)j,SEEK_CUR) != 0) {
  11849. fclose(fp);
  11850. goto fnend;
  11851. }
  11852. }
  11853. }
  11854. }
  11855. picend:
  11856. if (ap) {
  11857. char * s;
  11858. makestr(&(ap[0]),"2");
  11859. makestr(&(ap[1]),ckitoa(w));
  11860. makestr(&(ap[2]),ckitoa(h));
  11861. s = jpgdate(fp);
  11862. debug(F110,"jpgdate",s,0);
  11863. if (s) if (*s) makestr(&(ap[3]),s);
  11864. }
  11865. fclose(fp);
  11866. if (w > 0 && h > 0) {
  11867. if (w > h) p[0] = '1'; /* Landscape */
  11868. else if (h > w) p[0] = '2'; /* Portrait */
  11869. else p[0] = '3'; /* Square - 2013-10-05 */
  11870. }
  11871. goto fnend;
  11872. }
  11873. #endif /* SEEK_CUR */
  11874. if (cx == FN_PID) {
  11875. int x = -1;
  11876. if (chknum(bp[0])) { /* Need numeric argument */
  11877. int pid;
  11878. pid = atoi(bp[0]); /* Convert to int */
  11879. #ifdef UNIX
  11880. if (kill(pid,0) < 0) { /* Test it */
  11881. if (errno ==
  11882. #ifdef ESRCH
  11883. ESRCH /* No such process */
  11884. #else
  11885. 3
  11886. #endif /* ESRCH */
  11887. )
  11888. x = 0;
  11889. } else /* Process exists */
  11890. x = 1;
  11891. #endif /* UNIX */
  11892. }
  11893. sprintf(fnval,"%d",x); /* SAFE */
  11894. goto fnend;
  11895. }
  11896. if (cx == FN_FUNC) {
  11897. char * s = bp[0];
  11898. p = "0";
  11899. debug(F111,"ffunc",s,argn);
  11900. if (argn > 0) {
  11901. int x, y;
  11902. for (p = s; *p; p++) { /* Chop off trailing parens if any */
  11903. if (*p == '(') {
  11904. *p = NUL;
  11905. break;
  11906. }
  11907. }
  11908. /* Chop off leading "\\f" or "\f" or "f" */
  11909. p = s;
  11910. if (*p == CMDQ) /* Allow for \\f... */
  11911. p++;
  11912. if (*p == CMDQ && (*(p+1) == 'f' || *(p+1) == 'F')) { /* or \f */
  11913. p += 2;
  11914. } else if (*p == 'f' || *p == 'F') { /* or just f */
  11915. p++;
  11916. }
  11917. y = lookup(fnctab,p,nfuncs,&x); /* Look up the result */
  11918. debug(F111,"ffunc",p,y);
  11919. p = (y > -1) ? "1" : "0";
  11920. }
  11921. goto fnend;
  11922. }
  11923. if (cx == FN_RECURSE) {
  11924. int t, n;
  11925. char * s;
  11926. fnval[0] = NUL; /* Default result is empty string */
  11927. s = bp[0]; /* Check for null argument */
  11928. if (!s) s = ""; /* or empty argument */
  11929. if (!*s) goto fnend; /* in which case return empty string */
  11930. n = FNVALL; /* Not empty, max size for result */
  11931. s = fnval; /* Location of result */
  11932. {
  11933. /* Force VARIABLE-EVALUATION SIMPLE RECURSIVE */
  11934. /* NOTE: This is vulnerable to SIGINT and whatnot... */
  11935. int tmp = vareval; /* Save VARIABLE-EVALUATION setting */
  11936. vareval = 1; /* Force it to RECURSIVE */
  11937. zzstring(bp[0],&s,&n); /* Expand arg into result space */
  11938. vareval = tmp; /* Restore VARIABLE-EVALUATION */
  11939. }
  11940. goto fnend;
  11941. }
  11942. if (cx == FN_XLATE) { /* f_cvtcset() */
  11943. #ifdef NOFRILLS
  11944. ckstrncpy(fnval,bp[0],FNVALL);
  11945. #else
  11946. #ifndef NOUNICODE
  11947. _PROTOTYP( char * cvtstring, (char *, int, int) );
  11948. char * string, * cset1, * cset2;
  11949. int id1, id2;
  11950. #endif /* NOUNICODE */
  11951. fnval[0] = NUL;
  11952. #ifdef NOUNICODE
  11953. ckstrncpy(fnval,bp[0],FNVALL);
  11954. #else
  11955. string = bp[0] ? bp[0] : ""; /* String to convert */
  11956. if (!*string) goto fnend; /* It's empty */
  11957. cset1 = bp[1] ? bp[1] : "ascii"; /* Current charset of string */
  11958. cset2 = bp[2] ? bp[2] : "ascii"; /* Charset to convert to */
  11959. id1 = lookup(fcstab,cset1,nfilc,NULL); /* Lookup 'from' set */
  11960. if (id1 < 0) {
  11961. failed = 1;
  11962. ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_CHARSET:\\f",fn,"()>",NULL);
  11963. goto fnend;
  11964. }
  11965. id2 = lookup(fcstab,cset2,nfilc,NULL); /* Lookup 'to' set */
  11966. if (id2 < 0) {
  11967. failed = 1;
  11968. ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_CHARSET:\\f",fn,"()>",NULL);
  11969. goto fnend;
  11970. }
  11971. string = cvtstring(string,id1,id2);
  11972. ckstrncpy(fnval,string,FNVALL);
  11973. #endif /* NOUNICODE */
  11974. #endif /* NOFRILLS */
  11975. goto fnend;
  11976. }
  11977. /* Decode strings containing hex escapes */
  11978. if (cx == FN_UNPCT) { /* \fdecodehex() */
  11979. char *s1, *s2;
  11980. char *prefix; /* Can be 1 or 2 chars */
  11981. char buf[3];
  11982. int n = 0, k;
  11983. p = fnval;
  11984. *p = NUL;
  11985. if (argn < 1) goto fnend; /* Empty string */
  11986. s1 = bp[0] ? bp[0] : ""; /* Original string */
  11987. prefix = bp[1] ? bp[1] : "%%"; /* Hex byte prefix */
  11988. n = (int)strlen(prefix); /* Length of prefix */
  11989. if (n < 1 || n > 2) { /* must be 1 or 2 */
  11990. ckmakmsg(fnval,FNVALL,
  11991. "<ERROR:INVALID_HEX_PREFIX:\\f",fn,"()>",NULL);
  11992. goto xunpct;
  11993. }
  11994. while (*s1) {
  11995. if (!ckstrcmp(s1,prefix,n,0)) { /* Case-independent */
  11996. if (!*(s1+n)) {
  11997. ckmakmsg(fnval,FNVALL,
  11998. "<ERROR:INCOMPLETE_SEQUENCE:\\f",fn,"()>",NULL);
  11999. goto xunpct;
  12000. }
  12001. buf[0] = *(s1+n); /* First hex character */
  12002. buf[1] = *(s1+n+1); /* Second hex character */
  12003. buf[2] = NUL;
  12004. if ((k = ckhexbytetoint((char *)buf)) > -1) {
  12005. *p++ = (char) k; /* Deposit decoded result */
  12006. s1 += 2+n; /* and advance the source pointer */
  12007. } else { /* Fail on conversion error */
  12008. ckmakmsg(fnval,FNVALL,
  12009. "<ERROR:NON_HEX_CHARS:\\f",fn,"()>",NULL);
  12010. goto xunpct;
  12011. }
  12012. } else { /* Not a hex escape sequence */
  12013. *p++ = *s1++; /* Just copy the character */
  12014. }
  12015. }
  12016. *p = NUL; /* Terminate the result string */
  12017. failed = 0; /* Say we didn't fail */
  12018. p = fnval; /* Set up result pointer */
  12019. goto fnend; /* and finish */
  12020. xunpct: /* Error exit */
  12021. p = fnval;
  12022. failed = 1;
  12023. goto fnend;
  12024. }
  12025. /* Check a string for encoding family */
  12026. if (cx == FN_STRINGT) { /* \fstringtype() */
  12027. p = "UNK";
  12028. switch (scanstring(bp[0])) {
  12029. case FT_7BIT: p = "7BIT"; break;
  12030. case FT_8BIT: p = "8BIT"; break;
  12031. case FT_UTF8: p = "UTF8"; break;
  12032. case FT_UCS2: p = "UCS2"; break;
  12033. case FT_TEXT: p = "TEXT"; break;
  12034. case FT_BIN: p = "BINARY"; break;
  12035. }
  12036. ckstrncpy(fnval,p,FNVALL);
  12037. p = fnval;
  12038. goto fnend;
  12039. }
  12040. /* String compare s1, s2, [ case ], [ start ] , [ len ] */
  12041. if (cx == FN_STRCMP) {
  12042. int docase = 0; /* Case matters or not */
  12043. int start = 0; /* Start of substring */
  12044. int len = -1; /* Length of substring to compare */
  12045. int x; char * s1, * s2; /* workers */
  12046. p = "0"; /* Return value */
  12047. if (argn == 0) { /* Two null strings are equal */
  12048. ckstrncpy(fnval,p,FNVALL);
  12049. p = fnval;
  12050. goto fnend;
  12051. }
  12052. if (argn == 1) { /* Non-null string > null string */
  12053. p = "1";
  12054. ckstrncpy(fnval,p,FNVALL);
  12055. p = fnval;
  12056. goto fnend;
  12057. }
  12058. if (argn > 2) {
  12059. s = *(bp[2]) ? evalx(bp[2]) : "0"; /* 0 = caseless */
  12060. if (chknum(s)) docase = atoi(s);
  12061. if (argn > 3) {
  12062. s = *(bp[3]) ? evalx(bp[3]) : "1"; /* start is 1-based */
  12063. if (chknum(s)) start = atoi(s);
  12064. if (argn > 4) {
  12065. s = *(bp[4]) ? evalx(bp[4]) : "-1"; /* -1 = whole thing */
  12066. if (chknum(s)) len = atoi(s);
  12067. }
  12068. }
  12069. }
  12070. if (start > 0) start--; /* start is 0-based internally */
  12071. s1 = bp[0]; /* Get length of first arg */
  12072. x = (int)strlen(s1);
  12073. if (x > start) /* Point to start position of s1 */
  12074. s1 += start;
  12075. else
  12076. s1 = "";
  12077. s2 = bp[1]; /* Get length of second arg */
  12078. x = (int)strlen(s2);
  12079. if (x > start) /* Point to start position of s2 */
  12080. s2 += start;
  12081. else
  12082. s2 = "";
  12083. x = ckstrcmp(s,s2,len,docase);
  12084. p = ckitoa(x);
  12085. ckstrncpy(fnval,p,FNVALL);
  12086. p = fnval;
  12087. goto fnend;
  12088. }
  12089. #ifdef HAVE_LOCALE
  12090. /* \fdayname() - Returns locale-dependent day name string - 2013/07/23 */
  12091. if (cx == FN_DAYNAME) {
  12092. _PROTOTYP( char * locale_dayname, (int, int) );
  12093. char *s1, *s2;
  12094. char buf[3];
  12095. int fc = 0, day = 999;
  12096. s1 = bp[0];
  12097. s2 = bp[1];
  12098. p = fnval;
  12099. *p = NUL;
  12100. if (!s1) s1 = "";
  12101. if (!*s1) {
  12102. s1 = ckdate();
  12103. } else if (rdigits(s1) && (int)strlen(s1) < 8) {
  12104. day = atoi(s1);
  12105. if (day == 0) day = 7; /* In case \v(nday) used as arg */
  12106. if (day < 1 || day > 7) {
  12107. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DAYNUM\\f",fn,"()>",NULL);
  12108. goto fnend;
  12109. }
  12110. day--; /* Adjust to zero-based */
  12111. } else if (!(s1 = cmcvtdate(s1,1))) {
  12112. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE\\f",fn,"()>",NULL);
  12113. goto fnend;
  12114. }
  12115. if (!s2) s2 = ""; /* Parse function code */
  12116. if (!*s2) {
  12117. fc = 0;
  12118. } else if (rdigits(s2)) {
  12119. fc = atoi(s2);
  12120. } else {
  12121. failed = 1;
  12122. ckmakmsg(fnval,FNVALL,"<ERROR:FUNCTION_CODE:\\f",fn,"()>",NULL);
  12123. goto fnend;
  12124. }
  12125. if (day > 6) { /* Day number was not given */
  12126. day = (mjd(s1) % 7) + 2; /* Get day number */
  12127. if (day > 6) day -= 7; /* Adjust to 0=Sunday */
  12128. }
  12129. s1 = locale_dayname(day,fc); /* Get locale-based day name */
  12130. if (!s1) {
  12131. failed = 1;
  12132. ckmakmsg(fnval,FNVALL,"<ERROR:NO_RESULT:\\f",fn,"()>",NULL);
  12133. goto fnend;
  12134. }
  12135. ckstrncpy(fnval,s1,FNVALL);
  12136. goto fnend;
  12137. }
  12138. /* \fmonthname() - Returns locale-dependent month name string 2013/07/24 */
  12139. if (cx == FN_MONNAME) {
  12140. _PROTOTYP( char * locale_monthname, (int, int) );
  12141. char *s1, *s2;
  12142. char buf[3];
  12143. int fc = 0, month = 999;
  12144. s1 = bp[0];
  12145. s2 = bp[1];
  12146. p = fnval;
  12147. *p = NUL;
  12148. if (!s1) s1 = "";
  12149. if (!*s1) {
  12150. s1 = ckdate();
  12151. } else if (rdigits(s1) && (int)strlen(s1) < 8) {
  12152. month = atoi(s1);
  12153. if (month == 0) month = 12;
  12154. if (month < 1 || month > 12) {
  12155. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_MONTHNUM:\\f",fn,"()>",NULL);
  12156. goto fnend;
  12157. }
  12158. month--; /* Adjust to zero-based */
  12159. } else if (!(s1 = cmcvtdate(s1,1))) {
  12160. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE\\f",fn,"()>",NULL);
  12161. goto fnend;
  12162. }
  12163. if (month > 12) {
  12164. char mn[3];
  12165. mn[0] = s1[4];
  12166. mn[1] = s1[5];
  12167. mn[2] = NUL;
  12168. month = atoi((char *)mn) - 1;
  12169. }
  12170. if (!s2) s2 = ""; /* Parse function code */
  12171. if (!*s2) {
  12172. fc = 0;
  12173. } else if (rdigits(s2)) {
  12174. fc = atoi(s2);
  12175. } else {
  12176. failed = 1;
  12177. ckmakmsg(fnval,FNVALL,"<ERROR:FUNCTION_CODE:\\f",fn,"()>",NULL);
  12178. goto fnend;
  12179. }
  12180. s1 = locale_monthname(month,fc); /* Get locale-based month name */
  12181. if (!s1) {
  12182. failed = 1;
  12183. ckmakmsg(fnval,FNVALL,"<ERROR:NO_RESULT:\\f",fn,"()>",NULL);
  12184. goto fnend;
  12185. }
  12186. ckstrncpy(fnval,s1,FNVALL);
  12187. goto fnend;
  12188. }
  12189. #endif /* HAVE_LOCALE */
  12190. /* Note: when adding new functions remember to update dohfunc in ckuus2.c. */
  12191. failed = 1;
  12192. if (fndiags)
  12193. ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_FUNCTION:\\f",fn,"()>",NULL);
  12194. fnend:
  12195. /* Free temporary storage for aguments */
  12196. for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  12197. fndepth--;
  12198. if (failed) { /* Handle failure */
  12199. debug(F111,"fnend",fnval,errno);
  12200. if (!p) p = "";
  12201. if (p[0]) {
  12202. /* In case this wasn't caught above... */
  12203. k = strlen(p);
  12204. if (p[0] != '<' && p[k-1] != '>') {
  12205. ckmakmsg(fnval,FNVALL,"<ERROR:BAD_ARG:\\f",fn,"()>",NULL);
  12206. p = fnval;
  12207. }
  12208. } else {
  12209. ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN:\\f",fn,"()>",NULL);
  12210. p = fnval;
  12211. }
  12212. if (fnerror) /* SET FUNCTION ERROR ON */
  12213. fnsuccess = 0; /* Make command fail (see ckuus5.c) */
  12214. debug(F111,"fneval failed",p,fnsuccess);
  12215. if (fndiags) /* SET FUNCTION DIAGNOSTICS ON */
  12216. printf("?%s\n",p); /* Print error message now. */
  12217. else
  12218. return(""); /* Return nothing. */
  12219. }
  12220. return(p);
  12221. }
  12222. #endif /* NOSPL */
  12223. static char ckpidbuf[32] = "????";
  12224. #ifdef VMS
  12225. _PROTOTYP(long zgpid,(void));
  12226. #endif /* VMS */
  12227. char *
  12228. ckgetpid() { /* Return pid as string */
  12229. #ifdef CK_PID
  12230. #ifdef OS2
  12231. #define getpid _getpid
  12232. unsigned long zz;
  12233. #else
  12234. long zz;
  12235. #endif /* OS2 */
  12236. #ifdef VMS
  12237. zz = zgpid();
  12238. #else
  12239. zz = getpid();
  12240. #endif /* VMS */
  12241. sprintf(ckpidbuf,"%ld",zz); /* SAFE */
  12242. #endif /* CK_PID */
  12243. return((char *)ckpidbuf);
  12244. }
  12245. #ifndef NOSPL
  12246. #define EMBUFLEN 128 /* Error message buffer length */
  12247. static char embuf[EMBUFLEN+1];
  12248. char * /* Evaluate builtin variable */
  12249. nvlook(s) char *s; {
  12250. int x, y, cx;
  12251. long z;
  12252. char *p;
  12253. #ifndef NODIAL
  12254. MDMINF * m;
  12255. #endif /* NODIAL */
  12256. #ifndef NOKVERBS /* Keyboard macro material */
  12257. extern int keymac, keymacx;
  12258. #endif /* NOKVERBS */
  12259. #ifdef CK_LOGIN
  12260. extern int isguest;
  12261. #endif /* CK_LOGIN */
  12262. if (!s) s = "";
  12263. x = strlen(s);
  12264. if (fndiags) { /* FUNCTION DIAGNOSTIC ON */
  12265. if (x + 32 < EMBUFLEN)
  12266. sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE:\\v(%s)>",s); /* SAFE */
  12267. else
  12268. sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE>"); /* SAFE */
  12269. } else /* FUNCTION DIAGNOSTIC OFF */
  12270. embuf[0] = NUL;
  12271. x = VVBUFL;
  12272. p = vvbuf;
  12273. if (zzstring(s,&p,&x) < 0) { /* e.g. for \v(\%a) */
  12274. y = -1;
  12275. } else {
  12276. s = vvbuf;
  12277. y = lookup(vartab,s,nvars,&x);
  12278. }
  12279. cx = y; /* y is too generic */
  12280. #ifndef NODIAL
  12281. m = (mdmtyp > 0) ? modemp[mdmtyp] : NULL; /* For \v(m_xxx) variables */
  12282. #endif /* NODIAL */
  12283. debug(F101,"nvlook y","",y);
  12284. switch (y) {
  12285. case VN_ARGC: /* ARGC */
  12286. sprintf(vvbuf,"%d",maclvl < 0 ? topargc : macargc[maclvl]); /* SAFE */
  12287. return(vvbuf);
  12288. case VN_ARGS: /* ARGS */
  12289. sprintf(vvbuf,"%d",xargs); /* SAFE */
  12290. return(vvbuf);
  12291. case VN_COUN: /* COUNT */
  12292. sprintf(vvbuf,"%d",count[cmdlvl]); /* SAFE */
  12293. return(vvbuf);
  12294. case VN_DATE: /* DATE */
  12295. ztime(&p); /* Get "asctime" string */
  12296. if (p == NULL || *p == NUL) return(NULL);
  12297. vvbuf[0] = p[8]; /* dd */
  12298. vvbuf[1] = p[9];
  12299. vvbuf[2] = SP;
  12300. vvbuf[3] = p[4]; /* mmm */
  12301. vvbuf[4] = p[5];
  12302. vvbuf[5] = p[6];
  12303. vvbuf[6] = SP;
  12304. for (x = 20; x < 24; x++) /* yyyy */
  12305. vvbuf[x - 13] = p[x];
  12306. vvbuf[11] = NUL;
  12307. return(vvbuf);
  12308. case VN_NDAT: /* Numeric date */
  12309. ckstrncpy(vvbuf,zzndate(),VVBUFL);
  12310. return(vvbuf);
  12311. case VN_DIRE: /* DIRECTORY */
  12312. s = zgtdir(); /* Get current directory */
  12313. if (!s)
  12314. #ifdef UNIXOROSK
  12315. s = "./";
  12316. #else
  12317. #ifdef VMS
  12318. s = "[]";
  12319. #else
  12320. s = "";
  12321. #endif /* VMS */
  12322. #endif /* UNIXOROSK */
  12323. ckstrncpy(vvbuf,s,VVBUFL);
  12324. s = vvbuf;
  12325. #ifdef UNIXOROSK
  12326. x = strlen(s);
  12327. if (x < VVBUFL - 1) {
  12328. if (s[x-1] != '/') {
  12329. s[x] = '/';
  12330. s[x+1] = NUL;
  12331. }
  12332. }
  12333. #endif /* UNIXOROSK */
  12334. return(s);
  12335. case VN_FILE: /* filespec */
  12336. return(fspec);
  12337. case VN_HOST: /* host name */
  12338. if (*myhost) { /* If known */
  12339. return(myhost); /* return it. */
  12340. } else { /* Otherwise */
  12341. ckstrncpy(vvbuf,"unknown",VVBUFL); /* just say "unknown" */
  12342. return(vvbuf);
  12343. }
  12344. case VN_SYST: /* System type */
  12345. #ifdef UNIX
  12346. ckstrncpy(vvbuf,"UNIX",VVBUFL);
  12347. #else
  12348. #ifdef VMS
  12349. ckstrncpy(vvbuf,"VMS",VVBUFL);
  12350. #else
  12351. #ifdef OSK
  12352. ckstrncpy(vvbuf,"OS9/68K",VVBUFL);
  12353. #else
  12354. #ifdef AMIGA
  12355. ckstrncpy(vvbuf,"Amiga",VVBUFL);
  12356. #else
  12357. #ifdef MAC
  12358. ckstrncpy(vvbuf,"Macintosh",VVBUFL);
  12359. #else
  12360. #ifdef OS2
  12361. #ifdef NT
  12362. ckstrncpy(vvbuf,"WIN32",VVBUFL) ;
  12363. #else /* NT */
  12364. ckstrncpy(vvbuf,"OS/2",VVBUFL);
  12365. #endif /* NT */
  12366. #else
  12367. #ifdef datageneral
  12368. ckstrncpy(vvbuf,"AOS/VS",VVBUFL);
  12369. #else
  12370. #ifdef GEMDOS
  12371. ckstrncpy(vvbuf,"Atari_ST",VVBUFL);
  12372. #else
  12373. #ifdef STRATUS
  12374. ckstrncpy(vvbuf,"Stratus_VOS",VVBUFL);
  12375. #else
  12376. ckstrncpy(vvbuf,"unknown",VVBUFL);
  12377. #endif /* STRATUS */
  12378. #endif /* GEMDOS */
  12379. #endif /* datageneral */
  12380. #endif /* OS2 */
  12381. #endif /* MAC */
  12382. #endif /* AMIGA */
  12383. #endif /* OSK */
  12384. #endif /* VMS */
  12385. #endif /* UNIX */
  12386. return(vvbuf);
  12387. case VN_SYSV: /* System herald */
  12388. #ifdef IKSD
  12389. #ifdef CK_LOGIN
  12390. if (inserver && isguest)
  12391. return("");
  12392. #endif /* CK_LOGIN */
  12393. #endif /* IKSD */
  12394. for (x = y = 0; x < VVBUFL; x++) {
  12395. if (ckxsys[x] == SP && y == 0) continue;
  12396. vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  12397. }
  12398. vvbuf[y] = NUL;
  12399. return(vvbuf);
  12400. } /* Break up long switch statements... */
  12401. switch(y) {
  12402. case VN_TIME: /* TIME. Assumes that ztime returns */
  12403. ztime(&p); /* "Thu Feb 8 12:00:00 1990" */
  12404. if (p == NULL || *p == NUL) /* like asctime()! */
  12405. return("");
  12406. for (x = 11; x < 19; x++) /* copy hh:mm:ss */
  12407. vvbuf[x - 11] = p[x]; /* to vvbuf */
  12408. vvbuf[8] = NUL; /* terminate */
  12409. return(vvbuf); /* and return it */
  12410. case VN_NTIM: /* Numeric time */
  12411. ztime(&p); /* "Thu Feb 8 12:00:00 1990" */
  12412. if (p == NULL || *p == NUL) /* like asctime()! */
  12413. return(NULL);
  12414. z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  12415. sprintf(vvbuf,"%ld",z); /* SAFE */
  12416. return(vvbuf);
  12417. #ifdef CK_TTYFD
  12418. case VN_TTYF: /* TTY file descriptor */
  12419. sprintf(vvbuf,"%d", /* SAFE */
  12420. #ifdef VMS
  12421. vmsttyfd()
  12422. #else
  12423. ttyfd
  12424. #endif /* VMS */
  12425. );
  12426. return(vvbuf);
  12427. #endif /* CK_TTYFD */
  12428. case VN_VERS: /* Numeric Kermit version number */
  12429. sprintf(vvbuf,"%ld",vernum); /* SAFE */
  12430. return(vvbuf);
  12431. case VN_XVNUM: /* Product-specific version number */
  12432. sprintf(vvbuf,"%ld",xvernum); /* SAFE */
  12433. return(vvbuf);
  12434. case VN_HOME: /* Home directory */
  12435. return(homepath());
  12436. case VN_IBUF: /* INPUT buffer */
  12437. return((char *)inpbuf);
  12438. case VN_ICHR: /* INPUT character */
  12439. inchar[1] = NUL;
  12440. return((char *)inchar);
  12441. case VN_ICNT: /* INPUT character count */
  12442. sprintf(vvbuf,"%d",incount); /* SAFE */
  12443. return(vvbuf);
  12444. case VN_SPEE: { /* Transmission SPEED */
  12445. long t;
  12446. t = ttgspd();
  12447. if (t < 0L)
  12448. sprintf(vvbuf,"unknown"); /* SAFE */
  12449. else
  12450. sprintf(vvbuf,"%ld",t); /* SAFE */
  12451. return(vvbuf);
  12452. }
  12453. case VN_SUCC: /* SUCCESS flag */
  12454. /* Note inverted sense */
  12455. sprintf(vvbuf,"%d",(success == 0) ? 1 : 0); /* SAFE */
  12456. return(vvbuf);
  12457. case VN_LINE: { /* LINE */
  12458. #ifdef DEBUG
  12459. if (deblog) {
  12460. debug(F111,"\\v(line) local",ttname,local);
  12461. debug(F111,"\\v(line) inserver","",inserver);
  12462. #ifdef TNCODE
  12463. debug(F111,"\\v(line) tcp_incoming","",tcp_incoming);
  12464. #endif /* TNCODE */
  12465. #ifdef CK_TAPI
  12466. debug(F111,"\\v(line) tttapi","",tttapi);
  12467. #endif /* CK_TAPI */
  12468. }
  12469. #endif /* DEBUG */
  12470. #ifdef CK_TAPI
  12471. if (tttapi) { /* If I have made a TAPI connection */
  12472. int i; /* return the TAPI device name */
  12473. for (i = 0; i < ntapiline; i++) {
  12474. if (!strcmp(ttname,tapilinetab[i].kwd)) {
  12475. p = _tapilinetab[i].kwd;
  12476. return(p);
  12477. }
  12478. }
  12479. }
  12480. #endif /* CK_TAPI */
  12481. #ifndef NOXFER
  12482. if (inserver /* If I am a TCP server */
  12483. #ifdef TNCODE
  12484. || tcp_incoming
  12485. #endif /* TNCODE */
  12486. )
  12487. #ifdef TCPSOCKET
  12488. p = ckgetpeer(); /* return peer name */
  12489. else
  12490. #endif /* TCPSOCKET */
  12491. #endif /* NOXFER */
  12492. if (local) /* Otherwise if in local mode */
  12493. p = (char *) ttname; /* return SET LINE / SET HOST name */
  12494. else /* Otherwise */
  12495. p = ""; /* return empty string */
  12496. if (!p) /* In case ckgetpeer() returns */
  12497. p = ""; /* null pointer... */
  12498. debug(F110,"\\v(line) p",p,0);
  12499. if (!*p)
  12500. p = (char *) ttname;
  12501. return(p);
  12502. }
  12503. case VN_PROG: /* Program name */
  12504. return("C-Kermit");
  12505. } /* Break up long switch statements... */
  12506. switch(y) {
  12507. case VN_RET: /* Value of most recent RETURN */
  12508. debug(F111,"\\v(return)",mrval[maclvl+1],maclvl+1);
  12509. p = mrval[maclvl+1];
  12510. if (p == NULL) p = "";
  12511. return(p);
  12512. case VN_FFC: /* Size of most recent file */
  12513. sprintf(vvbuf, "%s", ckfstoa(ffc)); /* SAFE */
  12514. return(vvbuf);
  12515. case VN_TFC: /* Size of most recent file group */
  12516. sprintf(vvbuf, "%s", ckfstoa(tfc)); /* SAFE */
  12517. return(vvbuf);
  12518. case VN_CPU: /* CPU type */
  12519. #ifdef IKSD
  12520. #ifdef CK_LOGIN
  12521. if (inserver && isguest)
  12522. return("");
  12523. #endif /* CK_LOGIN */
  12524. #endif /* IKSD */
  12525. #ifdef OS2
  12526. {
  12527. char * getcpu(void) ;
  12528. return getcpu();
  12529. }
  12530. #else /* OS2 */
  12531. #ifdef CKCPU
  12532. return(CKCPU); /* Traditionally, compile-time value */
  12533. #else
  12534. #ifdef CK_UTSNAME
  12535. { /* But if none, try runtime value */
  12536. extern char unm_mch[];
  12537. return((char *)unm_mch);
  12538. }
  12539. #else
  12540. p = getenv("HOSTTYPE"); /* 20091116 */
  12541. if (p) if (*p) return(p);
  12542. return("unknown");
  12543. #endif /* CK_UTSNAME */
  12544. #endif /* CKCPU */
  12545. #endif /* OS2 */
  12546. case VN_CMDL: /* Command level */
  12547. sprintf(vvbuf, "%d", cmdlvl); /* SAFE */
  12548. return(vvbuf);
  12549. case VN_DAY: /* Current day of the week */
  12550. ztime(&p); /* three-letter abbreviation */
  12551. if (p != NULL && *p != NUL) /* ztime() succeeded. */
  12552. ckstrncpy(vvbuf,p,4);
  12553. else
  12554. vvbuf[0] = NUL; /* ztime() failed. */
  12555. return(vvbuf); /* Return what we got. */
  12556. case VN_NDAY: { /* Numeric day of week */
  12557. long k;
  12558. z = mjd(zzndate()); /* Get modified Julian date */
  12559. k = (((int)(z % 7L)) + 3) % 7; /* Get day number */
  12560. sprintf(vvbuf,"%ld",k); /* SAFE */
  12561. return(vvbuf);
  12562. case VN_MONTH:
  12563. ztime(&p); /* three-letter abbreviation */
  12564. if (p != NULL && *p != NUL) /* ztime() succeeded. */
  12565. ckstrncpy(vvbuf,p+4,5);
  12566. else
  12567. vvbuf[0] = NUL; /* ztime() failed. */
  12568. return(vvbuf); /* Return what we got. */
  12569. case VN_NMONTH: { /* Numeric month (1-12) */
  12570. int x;
  12571. ztime(&p); /* asctime three-letter abbreviation */
  12572. for (x = 0; x < 12; x++)
  12573. if (!strncmp(p+4,months[x],3)) break;
  12574. if (x == 12) {
  12575. vvbuf[0] = '?';
  12576. vvbuf[1] = '?';
  12577. } else {
  12578. x++;
  12579. vvbuf[0] = (char) ((x < 10) ? '0' : '1');
  12580. vvbuf[1] = (char) ((x % 10) + 48);
  12581. }
  12582. vvbuf[2] = NUL;
  12583. return(vvbuf); /* Return what we got. */
  12584. }
  12585. case VN_YEAR: /* Current year */
  12586. ztime(&p);
  12587. if (p != NULL && *p != NUL) /* ztime() succeeded. */
  12588. ckstrncpy(vvbuf,p+20,5);
  12589. else
  12590. vvbuf[0] = NUL; /* ztime() failed. */
  12591. return(vvbuf); /* Return what we got. */
  12592. }
  12593. case VN_LCL: /* Local (vs remote) mode */
  12594. ckstrncpy(vvbuf, local ? "1" : "0",VVBUFL);
  12595. return(vvbuf);
  12596. case VN_CMDS: /* Command source */
  12597. if (cmdstk[cmdlvl].src == CMD_KB)
  12598. ckstrncpy(vvbuf,"prompt",VVBUFL);
  12599. else if (cmdstk[cmdlvl].src == CMD_MD)
  12600. ckstrncpy(vvbuf,"macro",VVBUFL);
  12601. else if (cmdstk[cmdlvl].src == CMD_TF)
  12602. ckstrncpy(vvbuf,"file",VVBUFL);
  12603. else
  12604. ckstrncpy(vvbuf,"unknown",VVBUFL);
  12605. return(vvbuf);
  12606. case VN_CMDF: /* Current command file name */
  12607. #ifdef COMMENT /* (see comments above) */
  12608. if (tfnam[tlevel]) { /* (near dblbs declaration) */
  12609. dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  12610. return(vvbuf);
  12611. } else return("");
  12612. #else
  12613. if (tlevel < 0)
  12614. return("");
  12615. else
  12616. return(tfnam[tlevel] ? tfnam[tlevel] : "");
  12617. #endif /* COMMENT */
  12618. case VN_MAC: /* Current macro name */
  12619. return((maclvl > -1) ? m_arg[maclvl][0] : "");
  12620. case VN_EXIT:
  12621. sprintf(vvbuf,"%d",xitsta); /* SAFE */
  12622. return(vvbuf);
  12623. } /* Break up long switch statements... */
  12624. switch(y) {
  12625. case VN_PRTY: { /* Parity */
  12626. char *ss;
  12627. switch (parity) {
  12628. case 0: ss = "none"; break;
  12629. case 'e': ss = "even"; break;
  12630. case 'm': ss = "mark"; break;
  12631. case 'o': ss = "odd"; break;
  12632. case 's': ss = "space"; break;
  12633. default: ss = "unknown"; break;
  12634. }
  12635. ckstrncpy(vvbuf,ss,VVBUFL);
  12636. return(vvbuf);
  12637. }
  12638. case VN_DIAL:
  12639. sprintf(vvbuf,"%d", /* SAFE */
  12640. #ifndef NODIAL
  12641. dialsta
  12642. #else
  12643. -1
  12644. #endif /* NODIAL */
  12645. );
  12646. return(vvbuf);
  12647. #ifndef NODIAL
  12648. case VN_DMSG:
  12649. #ifdef BIGBUFOK
  12650. ckstrncpy(vvbuf,
  12651. ((dialsta < 0) ? "(none)" : dialmsg[dialsta]),
  12652. VVBUFL); /* Safe if src == NULL.. mdw 20140213 */
  12653. #endif /* BIGBUFOK */
  12654. return((char *)vvbuf);
  12655. #endif /* NODIAL */
  12656. #ifdef OS2
  12657. case VN_KEYB:
  12658. ckstrncpy(vvbuf,conkbg(),VVBUFL);
  12659. return(vvbuf);
  12660. case VN_SELCT: {
  12661. #ifndef NOLOCAL
  12662. const char * selection = GetSelection();
  12663. return( (char *) (selection ? selection : "" )) ;
  12664. #else
  12665. return("");
  12666. #endif /* NOLOCAL */
  12667. }
  12668. #endif /* OS2 */
  12669. #ifndef NOXFER
  12670. case VN_CPS:
  12671. sprintf(vvbuf,"%ld",tfcps); /* SAFE */
  12672. return(vvbuf);
  12673. #endif /* NOXFER */
  12674. case VN_MODE: /* File transfer mode */
  12675. switch (binary) {
  12676. case XYFT_T: ckstrncpy(vvbuf,"text",VVBUFL); break;
  12677. case XYFT_B:
  12678. case XYFT_U: ckstrncpy(vvbuf,"binary",VVBUFL); break;
  12679. case XYFT_I: ckstrncpy(vvbuf,"image",VVBUFL); break;
  12680. case XYFT_L: ckstrncpy(vvbuf,"labeled",VVBUFL); break;
  12681. case XYFT_M: ckstrncpy(vvbuf,"macbinary",VVBUFL); break;
  12682. default: ckstrncpy(vvbuf,"unknown",VVBUFL);
  12683. }
  12684. return(vvbuf);
  12685. #ifdef CK_REXX
  12686. case VN_REXX:
  12687. return(rexxbuf);
  12688. #endif /* CK_REXX */
  12689. case VN_NEWL: /* System newline char or sequence */
  12690. #ifdef UNIX
  12691. ckstrncpy(vvbuf,"\n",VVBUFL);
  12692. #else
  12693. #ifdef datageneral
  12694. ckstrncpy(vvbuf,"\n",VVBUFL);
  12695. #else
  12696. #ifdef OSK
  12697. ckstrncpy(vvbuf,"\15",VVBUFL); /* Remember, these are octal... */
  12698. #else
  12699. #ifdef MAC
  12700. ckstrncpy(vvbuf,"\15",VVBUFL);
  12701. #else
  12702. #ifdef OS2
  12703. ckstrncpy(vvbuf,"\15\12",VVBUFL);
  12704. #else
  12705. #ifdef STRATUS
  12706. ckstrncpy(vvbuf,"\n",VVBUFL);
  12707. #else
  12708. #ifdef VMS
  12709. ckstrncpy(vvbuf,"\15\12",VVBUFL);
  12710. #else
  12711. #ifdef AMIGA
  12712. ckstrncpy(vvbuf,"\n",VVBUFL);
  12713. #else
  12714. #ifdef GEMDOS
  12715. ckstrncpy(vvbuf,"\n",VVBUFL);
  12716. #else
  12717. ckstrncpy(vvbuf,"\n",VVBUFL);
  12718. #endif /* GEMDOS */
  12719. #endif /* AMIGA */
  12720. #endif /* VMS */
  12721. #endif /* STRATUS */
  12722. #endif /* OS2 */
  12723. #endif /* MAC */
  12724. #endif /* OSK */
  12725. #endif /* datageneral */
  12726. #endif /* UNIX */
  12727. return(vvbuf);
  12728. case VN_ROWS: /* ROWS */
  12729. case VN_COLS: /* COLS */
  12730. ckstrncpy(vvbuf,(cx == VN_ROWS) ? "24" : "80",VVBUFL); /* Default */
  12731. #ifdef CK_TTGWSIZ
  12732. #ifdef OS2
  12733. if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  12734. ttgwsiz();
  12735. sprintf(vvbuf,"%d", /* SAFE */
  12736. (cx == VN_ROWS) ? tt_rows[VTERM] : tt_cols[VTERM]);
  12737. #else /* OS2 */
  12738. if (ttgwsiz() > 0) /* Get window size */
  12739. if (tt_cols > 0 && tt_rows > 0) /* sets tt_rows, tt_cols */
  12740. sprintf(vvbuf,"%d", /* SAFE */
  12741. (cx == VN_ROWS) ? tt_rows : tt_cols);
  12742. #endif /* OS2 */
  12743. #endif /* CK_TTGWSIZ */
  12744. return(vvbuf);
  12745. case VN_TTYP:
  12746. #ifdef NOTERM
  12747. ckstrncpy(vvbuf,"unknown",VVBUFL);
  12748. #else
  12749. #ifdef OS2
  12750. sprintf(vvbuf, "%s", /* SAFE */
  12751. (tt_type >= 0 && tt_type <= max_tt) ?
  12752. tt_info[tt_type].x_name :
  12753. "unknown"
  12754. );
  12755. #else
  12756. #ifdef MAC
  12757. ckstrncpy(vvbuf,"vt320",VVBUFL);
  12758. #else
  12759. p = getenv("TERM");
  12760. ckstrncpy(vvbuf,p ? p : "unknown",VVBUFL+1);
  12761. #endif /* MAC */
  12762. #endif /* OS2 */
  12763. #endif /* NOTERM */
  12764. return(vvbuf);
  12765. case VN_MINP: /* MINPUT */
  12766. sprintf(vvbuf, "%d", m_found); /* SAFE */
  12767. return(vvbuf);
  12768. } /* Break up long switch statements... */
  12769. switch(y) {
  12770. case VN_CONN: /* CONNECTION */
  12771. if (!local) {
  12772. ckstrncpy(vvbuf,"remote",VVBUFL);
  12773. } else {
  12774. if (!network)
  12775. ckstrncpy(vvbuf,"serial",VVBUFL);
  12776. #ifdef TCPSOCKET
  12777. else if (nettype == NET_TCPB || nettype == NET_TCPA) {
  12778. if (ttnproto == NP_TELNET)
  12779. ckstrncpy(vvbuf,"tcp/ip_telnet",VVBUFL);
  12780. #ifdef CK_SSL
  12781. else if (ttnproto == NP_SSL || ttnproto == NP_SSL_RAW)
  12782. ckstrncpy(vvbuf,"tcp/ip_ssl",VVBUFL);
  12783. else if (ttnproto == NP_TLS || ttnproto == NP_SSL_RAW)
  12784. ckstrncpy(vvbuf,"tcp/ip_tls",VVBUFL);
  12785. #endif /* CK_SSL */
  12786. else
  12787. ckstrncpy(vvbuf,"tcp/ip",VVBUFL);
  12788. }
  12789. #endif /* TCPSOCKET */
  12790. #ifdef SSHBUILTIN
  12791. else if (nettype == NET_SSH)
  12792. ckstrncpy(vvbuf,"tcp/ip_ssh",VVBUFL);
  12793. #endif /* SSHBUILTIN */
  12794. #ifdef ANYX25
  12795. else if (nettype == NET_SX25 ||
  12796. nettype == NET_VX25 ||
  12797. nettype == NET_IX25
  12798. )
  12799. ckstrncpy(vvbuf,"x.25",VVBUFL);
  12800. #endif /* ANYX25 */
  12801. #ifdef DECNET
  12802. else if (nettype == NET_DEC) {
  12803. if (ttnproto == NP_LAT)
  12804. ckstrncpy(vvbuf,"decnet_lat",VVBUFL);
  12805. else if ( ttnproto == NP_CTERM )
  12806. ckstrncpy(vvbuf,"decnet_cterm",VVBUFL);
  12807. else
  12808. ckstrncpy(vvbuf,"decnet",VVBUFL);
  12809. }
  12810. #endif /* DECNET */
  12811. #ifdef SUPERLAT
  12812. else if (nettype == NET_SLAT)
  12813. ckstrncpy(vvbuf,"superlat",VVBUFL);
  12814. #endif /* SUPERLAT */
  12815. #ifdef NETFILE
  12816. else if (nettype == NET_FILE)
  12817. ckstrncpy(vvbuf,"local_file",VVBUFL);
  12818. #endif /* NETFILE */
  12819. #ifdef NETCMD
  12820. else if (nettype == NET_CMD)
  12821. ckstrncpy(vvbuf,"pipe",VVBUFL);
  12822. #endif /* NETCMD */
  12823. #ifdef NETPTY
  12824. else if (nettype == NET_PTY)
  12825. ckstrncpy(vvbuf,"pseudoterminal",VVBUFL);
  12826. #endif /* NETPTY */
  12827. #ifdef NETDLL
  12828. else if (nettype == NET_DLL)
  12829. ckstrncpy(vvbuf,"dynamic_link_library",VVBUFL);
  12830. #endif /* NETDLL */
  12831. #ifdef NPIPE
  12832. else if (nettype == NET_PIPE)
  12833. ckstrncpy(vvbuf,"named_pipe",VVBUFL);
  12834. #endif /* NPIPE */
  12835. #ifdef CK_NETBIOS
  12836. else if (nettype == NET_BIOS)
  12837. ckstrncpy(vvbuf,"netbios",VVBUFL);
  12838. #endif /* CK_NETBIOS */
  12839. else
  12840. ckstrncpy(vvbuf,"unknown",VVBUFL);
  12841. }
  12842. return(vvbuf);
  12843. #ifndef NOXFER
  12844. case VN_SYSI: /* System ID, Kermit code */
  12845. return((char *)cksysid);
  12846. #endif /* NOXFER */
  12847. #ifdef OS2
  12848. case VN_SPA: {
  12849. unsigned long space = zdskspace(0);
  12850. if (space > 0 && space < 1024)
  12851. sprintf(vvbuf,"-1");
  12852. else
  12853. sprintf(vvbuf,"%lu",space); /* SAFE */
  12854. return(vvbuf);
  12855. }
  12856. #endif /* OS2 */
  12857. #ifndef NOXFER
  12858. case VN_QUE: {
  12859. extern char querybuf[];
  12860. return(querybuf);
  12861. }
  12862. #endif /* NOXFER */
  12863. #ifndef NOCSETS
  12864. case VN_CSET:
  12865. #ifdef OS2
  12866. sprintf(vvbuf,"cp%d",os2getcp()); /* SAFE */
  12867. #else
  12868. ckstrncpy(vvbuf,fcsinfo[fcharset].keyword,VVBUFL+1);
  12869. #endif /* OS2 */
  12870. return(vvbuf);
  12871. #endif /* NOCSETS */
  12872. #ifdef OS2
  12873. case VN_EXEDIR:
  12874. return(exedir);
  12875. case VN_STAR:
  12876. return(startupdir);
  12877. #else
  12878. case VN_EXEDIR:
  12879. return(exedir ? exedir : "");
  12880. #ifdef VMSORUNIX
  12881. case VN_STAR:
  12882. return(startupdir);
  12883. #endif /* VMSORUNIX */
  12884. #endif /* OS2 */
  12885. case VN_INI:
  12886. return(inidir);
  12887. case VN_MDM:
  12888. return(gmdmtyp());
  12889. case VN_EVAL:
  12890. return(evalbuf);
  12891. #ifndef NODIAL
  12892. case VN_D_CC: /* DIAL COUNTRY-CODE */
  12893. return(diallcc ? diallcc : "");
  12894. case VN_D_AC: /* DIAL AREA-CODE */
  12895. return(diallac ? diallac : "");
  12896. case VN_D_IP: /* DIAL INTERNATIONAL-PREFIX */
  12897. return(dialixp ? dialixp : "");
  12898. case VN_D_LP: /* DIAL LD-PREFIX */
  12899. return(dialldp ? dialldp : "");
  12900. case VN_D_LCP: /* DIAL LOCAL-PREFIX */
  12901. return(diallcp ? diallcp : "");
  12902. case VN_D_PXX: /* DIAL PBX-EXCHANGE that matched */
  12903. return(matchpxx ? matchpxx : "");
  12904. #else
  12905. case VN_D_CC: /* DIAL COUNTRY-CODE */
  12906. case VN_D_AC: /* DIAL AREA-CODE */
  12907. case VN_D_IP: /* DIAL INTERNATIONAL-PREFIX */
  12908. case VN_D_LP: /* DIAL LD-PREFIX */
  12909. case VN_D_LCP: /* DIAL LOCAL-PREFIX */
  12910. case VN_D_PXX: /* DIAL PBX-EXCHANGE */
  12911. return("");
  12912. #endif /* NODIAL */
  12913. case VN_UID:
  12914. #ifdef UNIX
  12915. {
  12916. #ifdef IKSD
  12917. if (inserver)
  12918. return((char *)uidbuf);
  12919. else
  12920. #endif /* IKSD */
  12921. if (uidbuf[0])
  12922. return((char *)uidbuf);
  12923. else
  12924. return(whoami());
  12925. }
  12926. #else
  12927. return((char *)uidbuf);
  12928. #endif /* UNIX */
  12929. } /* Break up long switch statements... */
  12930. switch(y) {
  12931. case VN_PWD:
  12932. #ifdef OS2
  12933. if (activecmd == XXOUT || activecmd == XXLNOUT) {
  12934. ckstrncpy(vvbuf,pwbuf,VVBUFL);
  12935. ck_encrypt((char *)vvbuf);
  12936. return((char *)vvbuf);
  12937. } else
  12938. #endif /* OS2 */
  12939. return((char *)pwbuf);
  12940. case VN_PRM:
  12941. return((char *)prmbuf);
  12942. case VN_PROTO:
  12943. #ifdef NOXFER
  12944. return("none");
  12945. #else
  12946. #ifdef CK_XYZ
  12947. return(ptab[protocol].p_name);
  12948. #else
  12949. return("kermit");
  12950. #endif /* CK_XYZ */
  12951. #endif /* NOXFER */
  12952. #ifndef NOXFER
  12953. #ifdef CK_TMPDIR
  12954. case VN_DLDIR:
  12955. return(dldir ? dldir : "");
  12956. #endif /* CK_TMPDIR */
  12957. #endif /* NOXFER */
  12958. #ifndef NODIAL
  12959. case VN_M_INI: /* Modem init string */
  12960. return(dialini ? dialini : (m ? m->wake_str : ""));
  12961. case VN_M_DCM: /* Modem dial command */
  12962. return(dialcmd ? dialcmd : (m ? m->dial_str : ""));
  12963. case VN_M_DCO: /* Modem data compression on */
  12964. return(dialdcon ? dialdcon : (m ? m->dc_on_str : ""));
  12965. case VN_M_DCX: /* Modem data compression off */
  12966. return(dialdcoff ? dialdcoff : (m ? m->dc_off_str : ""));
  12967. case VN_M_ECO: /* Modem error correction on */
  12968. return(dialecon ? dialecon : (m ? m->ec_on_str : ""));
  12969. case VN_M_ECX: /* Modem error correction off */
  12970. return(dialecoff ? dialecoff : (m ? m->ec_off_str : ""));
  12971. case VN_M_AAO: /* Modem autoanswer on */
  12972. return(dialaaon ? dialaaon : (m ? m->aa_on_str : ""));
  12973. case VN_M_AAX: /* Modem autoanswer off */
  12974. return(dialaaoff ? dialaaoff : (m ? m->aa_off_str : ""));
  12975. case VN_M_HUP: /* Modem hangup command */
  12976. return(dialhcmd ? dialhcmd : (m ? m->hup_str : ""));
  12977. case VN_M_HWF: /* Modem hardware flow command */
  12978. return(dialhwfc ? dialhwfc : (m ? m->hwfc_str : ""));
  12979. case VN_M_SWF: /* Modem software flow command */
  12980. return(dialswfc ? dialswfc : (m ? m->swfc_str : ""));
  12981. case VN_M_NFC: /* Modem no flow-control command */
  12982. return(dialnofc ? dialnofc : (m ? m->nofc_str : ""));
  12983. case VN_M_PDM: /* Modem pulse dialing mode */
  12984. return(dialpulse ? dialpulse : (m ? m->pulse : ""));
  12985. case VN_M_TDM: /* Modem tone dialing mode */
  12986. return(dialtone ? dialtone : (m ? m->tone : ""));
  12987. case VN_M_NAM: /* Modem full name */
  12988. return(dialname ? dialname : (m ? m->name : ""));
  12989. #else
  12990. case VN_M_INI: /* Modem init string */
  12991. case VN_M_DCM: /* Modem dial command */
  12992. case VN_M_DCO: /* Modem data compression on */
  12993. case VN_M_DCX: /* Modem data compression off */
  12994. case VN_M_ECO: /* Modem error correction on */
  12995. case VN_M_ECX: /* Modem error correction off */
  12996. case VN_M_AAO: /* Modem autoanswer on */
  12997. case VN_M_AAX: /* Modem autoanswer off */
  12998. case VN_M_HUP: /* Modem hangup command */
  12999. case VN_M_HWF: /* Modem hardware flow command */
  13000. case VN_M_SWF: /* Modem software flow command */
  13001. case VN_M_NFC: /* Modem no flow-control command */
  13002. case VN_M_PDM: /* Modem pulse dialing mode */
  13003. case VN_M_TDM: /* Modem tone dialing mode */
  13004. case VN_M_NAM:
  13005. return("");
  13006. #endif /* NODIAL */
  13007. case VN_ISTAT: /* INPUT status */
  13008. sprintf(vvbuf, "%d", instatus); /* SAFE */
  13009. return(vvbuf);
  13010. case VN_TEMP: /* Temporary directory */
  13011. if (tempdir) { /* This is where SET TEMP-DIRECTORY */
  13012. p = tempdir; /* puts it -- just use what's here */
  13013. ckstrncpy(vvbuf,tempdir,VVBUFL);
  13014. } else {
  13015. char c;
  13016. /*
  13017. If tempdir was empty, we have to figure out what the temp directory should
  13018. be here and then put the result where we should have found it in the first
  13019. place. This is done by checking environment variables (or logical names
  13020. in VMS, same thing from the API point of view), and if that fails using
  13021. platform-specific conventions, like the /tmp directory in Unix.
  13022. */
  13023. #ifdef OS2
  13024. #ifdef NT
  13025. p = getenv("K95TMP");
  13026. #else
  13027. p = getenv("K2TMP");
  13028. #endif /* NT */
  13029. if ( !p )
  13030. #endif /* OS2 */
  13031. p = getenv("CK_TMP");
  13032. if (!p) p = getenv("TMPDIR");
  13033. if (!p) p = getenv("TEMP");
  13034. if (!p) p = getenv("TMP");
  13035. #ifdef OS2ORUNIX
  13036. if (p) {
  13037. int len = strlen(p);
  13038. if (p[len-1] != '/'
  13039. #ifdef OS2
  13040. && p[len-1] != '\\'
  13041. #endif /* OS2 */
  13042. ) {
  13043. ckstrncpy(vvbuf,p,VVBUFL);
  13044. if (vvbuf[0]) ckstrncat(vvbuf,"/",CKMAXPATH);
  13045. p = vvbuf;
  13046. }
  13047. }
  13048. #endif /* OS2ORUNIX */
  13049. if (!p) {
  13050. #ifdef UNIX /* Systems that have a standard */
  13051. p = "/tmp/"; /* temporary directory... */
  13052. #else
  13053. #ifdef datageneral
  13054. p = ":TMP:";
  13055. #else
  13056. p = "";
  13057. #endif /* datageneral */
  13058. #endif /* UNIX */
  13059. ckstrncpy(vvbuf,p,VVBUFL);
  13060. p = vvbuf;
  13061. }
  13062. /*
  13063. If the result does not end with a directory separator, tack on the
  13064. appropriate one. This way scripts can be written in a platform-independent
  13065. way, without having to hardwire a particlar OS's directory separator;
  13066. e.g. \v(tmpfile)foo.bar instead of \v(tmpfile)/foo.bar, which would not be
  13067. portable to (say) VMS. In a better world the following code would be in the
  13068. platform-specific modules, ck?fio.c, but it's too late to go back and redo
  13069. them all. Note: Windows and OS/2 use backslash (\) as the directory
  13070. separate in the user interface, but accept slash(/) in their APIs.
  13071. */
  13072. while (*p) { /* For Windows and OS/2 */
  13073. #ifdef OS2 /* flip the backslash */
  13074. if (*p == '\\') *p = '/';
  13075. #endif /* OS2 */
  13076. p++;
  13077. }
  13078. p = vvbuf;
  13079. #ifndef VMS
  13080. if (p > vvbuf) { /* Directory termination character */
  13081. c =
  13082. #ifdef MAC
  13083. ':'
  13084. #else
  13085. #ifdef datageneral
  13086. ':'
  13087. #else
  13088. #ifdef STRATUS
  13089. '>'
  13090. #else
  13091. '/'
  13092. #endif /* STRATUS */
  13093. #endif /* datageneral */
  13094. #endif /* MAC */
  13095. ;
  13096. if (*(p-1) != c) { /* Add it to the end of the */
  13097. *p++ = c; /* string if it was not already */
  13098. *p = NUL; /* there */
  13099. }
  13100. }
  13101. #endif /* Not VMS */
  13102. /*
  13103. But if the result is just the one character, e.g. '/' in Unix, erase it
  13104. because that's the root directory and obviously can't be used for temporary
  13105. files.
  13106. */
  13107. if (vvbuf[0] == c && vvbuf[1] == NUL) {
  13108. vvbuf[0] = NUL;
  13109. }
  13110. }
  13111. makestr(&tempdir,p); /* Save result where we can find it next time */
  13112. return(vvbuf);
  13113. }
  13114. /* Break up long switch statements... */
  13115. switch(y) {
  13116. case VN_ERRNO: /* Error number */
  13117. #ifdef VMS
  13118. {
  13119. extern int vms_lasterr;
  13120. sprintf(vvbuf, "%d", vms_lasterr); /* SAFE */
  13121. }
  13122. #else
  13123. sprintf(vvbuf, "%d", errno); /* SAFE */
  13124. #endif /* VMS */
  13125. return(vvbuf);
  13126. case VN_ERSTR: /* Error string */
  13127. ckstrncpy(vvbuf,ck_errstr(),VVBUFL);
  13128. return(vvbuf);
  13129. #ifndef NOXFER
  13130. case VN_RPSIZ: /* RECEIVE packet-length */
  13131. sprintf(vvbuf,"%d",urpsiz); /* SAFE */
  13132. return(vvbuf);
  13133. case VN_WINDO: /* WINDOW slots */
  13134. sprintf(vvbuf,"%d",wslotr); /* SAFE */
  13135. return(vvbuf);
  13136. #endif /* NOXFER */
  13137. case VN_TFLN: /* TAKE-file line number */
  13138. if (tlevel > -1) {
  13139. sprintf(vvbuf, "%d", tfline[tlevel]); /* SAFE */
  13140. return(vvbuf);
  13141. } else
  13142. return("0");
  13143. case VN_MDMSG: /* DIALRESULT */
  13144. #ifndef NODIAL
  13145. return((char *)modemmsg);
  13146. #else
  13147. return("");
  13148. #endif /* NODIAL */
  13149. case VN_DNUM: /* DIALNUMBER */
  13150. #ifndef NODIAL
  13151. return(dialnum ? (char *) dialnum : "");
  13152. #else
  13153. return("");
  13154. #endif /* NODIAL */
  13155. case VN_APC:
  13156. sprintf(vvbuf, "%d", /* SAFE */
  13157. #ifdef CK_APC
  13158. apcactive
  13159. #else
  13160. 0
  13161. #endif /* CK_APC */
  13162. );
  13163. return((char *)vvbuf);
  13164. #ifdef OS2
  13165. #ifndef NOKVERBS
  13166. case VN_TRMK:
  13167. sprintf(vvbuf, "%d", keymac); /* SAFE */
  13168. return((char *)vvbuf);
  13169. #endif /* NOKVERBS */
  13170. #endif /* OS2 */
  13171. case VN_IPADDR:
  13172. #ifdef TCPSOCKET
  13173. #ifndef OSK
  13174. /* This dumps core on OS-9 for some reason, but only if executed */
  13175. /* before we have made a TCP connection. This is obviously not */
  13176. /* the ideal fix. */
  13177. if (!myipaddr[0])
  13178. getlocalipaddr();
  13179. #endif /* OSK */
  13180. #endif /* TCPSOCKET */
  13181. ckstrncpy(vvbuf,
  13182. #ifdef TCPSOCKET
  13183. (char *)myipaddr,
  13184. #else
  13185. "",
  13186. #endif /* TCPSOCKET */
  13187. VVBUFL);
  13188. return((char *)vvbuf);
  13189. #ifndef NOXFER
  13190. case VN_CRC16: /* CRC-16 of most recent transfer */
  13191. sprintf(vvbuf,"%d",crc16); /* SAFE */
  13192. return(vvbuf);
  13193. #endif /* NOXFER */
  13194. #ifdef CK_PID
  13195. case VN_PID:
  13196. #ifdef IKSD
  13197. #ifdef CK_LOGIN
  13198. if (inserver && isguest)
  13199. return("");
  13200. #endif /* CK_LOGIN */
  13201. #endif /* IKSD */
  13202. return(ckgetpid());
  13203. #endif /* CK_PID */
  13204. #ifndef NOXFER
  13205. case VN_FNAM: { /* \v(filename) */
  13206. extern char filnam[], ofn1[], *sfspec, *rrfspec;
  13207. char * tmp;
  13208. switch (what) { /* File transfer is in progress */
  13209. #ifdef NEWFTP
  13210. case (W_FTP|W_RECV):
  13211. case (W_FTP|W_SEND):
  13212. return((char *)filnam);
  13213. #endif /* NEWFTP */
  13214. case W_RECV:
  13215. case W_REMO:
  13216. return((char *)ofn1);
  13217. default: /* Most recent file transferred */
  13218. if (filnam[0]) { /* (if any) */
  13219. return((char *)filnam);
  13220. } else if (lastxfer & W_SEND && sfspec) {
  13221. if (fnspath == PATH_OFF)
  13222. zstrip(sfspec,&tmp);
  13223. else
  13224. tmp = sfspec;
  13225. return(tmp);
  13226. } else if (lastxfer & W_RECV && rrfspec) {
  13227. if (fnrpath == PATH_OFF)
  13228. zstrip(rrfspec,&tmp);
  13229. else
  13230. tmp = rrfspec;
  13231. return(tmp);
  13232. } else
  13233. return("");
  13234. }
  13235. }
  13236. case VN_FNUM: /* \v(filenum) */
  13237. sprintf(vvbuf,"%ld",filcnt); /* SAFE */
  13238. return((char *)vvbuf);
  13239. #endif /* NOXFER */
  13240. #ifdef PEXITSTAT
  13241. case VN_PEXIT: {
  13242. extern int pexitstat;
  13243. sprintf(vvbuf,"%d",pexitstat); /* SAFE */
  13244. return((char *)vvbuf);
  13245. }
  13246. #endif /* PEXITSTAT */
  13247. #ifndef NOXFER
  13248. case VN_P_8BIT:
  13249. vvbuf[0] = parity ? ebq : NUL;
  13250. vvbuf[1] = NUL;
  13251. return((char *)vvbuf);
  13252. case VN_P_CTL: {
  13253. extern CHAR myctlq;
  13254. vvbuf[0] = myctlq;
  13255. vvbuf[1] = NUL;
  13256. return((char *)vvbuf);
  13257. }
  13258. case VN_P_RPT: {
  13259. extern int rptena;
  13260. vvbuf[0] = rptena ? rptq : NUL;
  13261. vvbuf[1] = NUL;
  13262. return((char *)vvbuf);
  13263. }
  13264. #endif /* NOXFER */
  13265. } /* Break up long switch statements... */
  13266. switch(y) {
  13267. case VN_XPROG:
  13268. #ifndef COMMENT
  13269. /* C-Kermit 9.0 and later for Windows and OS/2 is just C-Kermit */
  13270. return("C-Kermit");
  13271. #else
  13272. #ifdef OS2
  13273. #ifdef NT
  13274. #ifdef KUI
  13275. return("K-95G");
  13276. #else
  13277. return("K-95");
  13278. #endif /* KUI */
  13279. #else
  13280. return("K/2");
  13281. #endif /* NT */
  13282. #else
  13283. return("C-Kermit");
  13284. #endif /* OS2 */
  13285. #endif /* COMMENT */
  13286. case VN_EDITOR:
  13287. #ifdef NOFRILLS
  13288. return("");
  13289. #else
  13290. #ifdef NOPUSH
  13291. return("");
  13292. #else
  13293. {
  13294. extern char editor[];
  13295. char *ss;
  13296. if (!editor[0]) {
  13297. ss = getenv("EDITOR");
  13298. if (ss) {
  13299. ckstrncpy(editor,ss,CKMAXPATH);
  13300. }
  13301. }
  13302. debug(F110,"\\v(editor)",editor,0);
  13303. return(editor[0] ? (char *)editor : "");
  13304. }
  13305. #endif /* NOPUSH */
  13306. #endif /* NOFRILLS */
  13307. case VN_EDOPT:
  13308. #ifdef NOFRILLS
  13309. return("");
  13310. #else
  13311. #ifdef NOPUSH
  13312. return("");
  13313. #else
  13314. {
  13315. extern char editopts[];
  13316. return(editopts[0] ? (char *)editopts : "");
  13317. }
  13318. #endif /* NOPUSH */
  13319. #endif /* NOFRILLS */
  13320. case VN_EDFILE:
  13321. #ifdef NOFRILLS
  13322. return("");
  13323. #else
  13324. #ifdef NOPUSH
  13325. return("");
  13326. #else
  13327. {
  13328. extern char editfile[];
  13329. return(editfile[0] ? (char *)editfile : "");
  13330. }
  13331. #endif /* NOPUSH */
  13332. #endif /* NOFRILLS */
  13333. #ifdef BROWSER
  13334. case VN_BROWSR: {
  13335. extern char browser[];
  13336. if (!browser[0]) {
  13337. s = getenv("BROWSER");
  13338. if (s) ckstrncpy(browser,s,CKMAXPATH);
  13339. }
  13340. return(browser[0] ? (char *)browser : "");
  13341. }
  13342. case VN_BROPT: {
  13343. extern char browsopts[];
  13344. return(browsopts[0] ? (char *)browsopts : "");
  13345. }
  13346. case VN_URL: {
  13347. extern char browsurl[];
  13348. return(browsurl[0] ? (char *)browsurl : "");
  13349. }
  13350. #endif /* BROWSER */
  13351. case VN_HERALD:
  13352. return((char *)versio);
  13353. case VN_TEST: { /* test */
  13354. extern char * ck_s_test, * ck_s_tver;
  13355. if (!ck_s_test) ck_s_test = "";
  13356. if (!ck_s_tver) ck_s_tver = "";
  13357. if (*ck_s_test) {
  13358. ckstrncpy(vvbuf,ck_s_test,VVBUFL);
  13359. if (*ck_s_tver) {
  13360. ckstrncat(vvbuf,".",VVBUFL);
  13361. ckstrncat(vvbuf,ck_s_tver,VVBUFL);
  13362. }
  13363. } else
  13364. ckstrncpy(vvbuf,"0",VVBUFL);
  13365. return((char *)vvbuf);
  13366. }
  13367. #ifndef NOXFER
  13368. case VN_XFSTAT: /* xferstatus */
  13369. x = xferstat; /* Like success */
  13370. if (x > -1) x = (x == 0) ? 1 : 0; /* External value is reversed */
  13371. sprintf(vvbuf,"%d",x); /* SAFE */
  13372. return((char *)vvbuf);
  13373. case VN_XFMSG: /* xfermsg */
  13374. return((char *)epktmsg);
  13375. #ifndef NOMSEND
  13376. case VN_SNDL: { /* sendlist */
  13377. extern int filesinlist;
  13378. sprintf(vvbuf,"%d",filesinlist); /* SAFE */
  13379. return((char *)vvbuf);
  13380. }
  13381. #endif /* NOMSEND */
  13382. #endif /* NOXFER */
  13383. #ifdef CK_TRIGGER
  13384. case VN_TRIG: {
  13385. extern char * triggerval;
  13386. return(triggerval ? triggerval : "");
  13387. }
  13388. #endif /* CK_TRIGGER */
  13389. #ifdef OS2MOUSE
  13390. #ifdef OS2
  13391. case VN_MOU_X: {
  13392. extern int MouseCurX;
  13393. sprintf(vvbuf,"%d",MouseCurX); /* SAFE */
  13394. return((char *)vvbuf);
  13395. }
  13396. case VN_MOU_Y: {
  13397. extern int MouseCurY;
  13398. sprintf(vvbuf,"%d",MouseCurY); /* SAFE */
  13399. return((char *)vvbuf);
  13400. }
  13401. #endif /* OS2 */
  13402. #endif /* OS2MOUSE */
  13403. case VN_PRINT: {
  13404. extern int printpipe;
  13405. extern char * printername;
  13406. #ifdef PRINTSWI
  13407. extern int noprinter;
  13408. if (noprinter) return("");
  13409. #endif /* PRINTSWI */
  13410. ckmakmsg(vvbuf,VVBUFL,
  13411. printpipe ? "|" : "",
  13412. printername ? printername :
  13413. #ifdef OS2
  13414. "PRN",
  13415. #else
  13416. "(default)",
  13417. #endif /* OS2 */
  13418. NULL,
  13419. NULL
  13420. );
  13421. return((char *)vvbuf);
  13422. }
  13423. } /* Break up long switch statements... */
  13424. switch(y) {
  13425. case VN_ESC: /* Escape character */
  13426. sprintf(vvbuf,"%d",escape); /* SAFE */
  13427. return((char *)vvbuf);
  13428. case VN_INTIME:
  13429. sprintf(vvbuf,"%ld",inetime); /* SAFE */
  13430. return((char *)vvbuf);
  13431. case VN_INTMO:
  13432. sprintf(vvbuf,"%d",inwait); /* SAFE */
  13433. return((char *)vvbuf);
  13434. case VN_SECURE:
  13435. if (0
  13436. #ifdef SSHBUILTIN
  13437. || IS_SSH()
  13438. #endif /* SSHBUILTIN */
  13439. #ifdef CK_ENCRYPTION
  13440. || ck_tn_encrypting() && ck_tn_decrypting()
  13441. #endif /* CK_ENCRYPTION */
  13442. #ifdef CK_SSL
  13443. || tls_active_flag || ssl_active_flag
  13444. #endif /* CK_SSL */
  13445. )
  13446. return("1");
  13447. else
  13448. return("0");
  13449. case VN_AUTHN:
  13450. #ifdef CK_AUTHENTICATION
  13451. {
  13452. extern char szUserNameAuthenticated[];
  13453. return((char *)szUserNameAuthenticated);
  13454. }
  13455. #else /* CK_AUTHENTICATION */
  13456. return((char *)"");
  13457. #endif /* CK_AUTHENTICATION */
  13458. case VN_AUTHS:
  13459. #ifdef CK_AUTHENTICATION
  13460. switch (ck_tn_auth_valid()) {
  13461. case AUTH_UNKNOWN:
  13462. return((char *)"unknown");
  13463. case AUTH_OTHER:
  13464. return((char *)"other");
  13465. case AUTH_USER:
  13466. return((char *)"user");
  13467. case AUTH_VALID:
  13468. return((char *)"valid");
  13469. case AUTH_REJECT:
  13470. default:
  13471. return((char *)"rejected");
  13472. }
  13473. #else /* CK_AUTHENTICATION */
  13474. return((char *)"rejected");
  13475. #endif /* CK_AUTHENTICATION */
  13476. case VN_AUTHT:
  13477. #ifdef CK_AUTHENTICATION
  13478. #ifdef CK_SSL
  13479. if ((ssl_active_flag || tls_active_flag) &&
  13480. ck_tn_auth_valid() == AUTH_VALID &&
  13481. (sstelnet ? (!TELOPT_U(TELOPT_AUTHENTICATION)) :
  13482. (!TELOPT_ME(TELOPT_AUTHENTICATION))) ||
  13483. ck_tn_authenticated() == AUTHTYPE_NULL ||
  13484. ck_tn_authenticated() == AUTHTYPE_AUTO)
  13485. return("X_509_CERTIFICATE");
  13486. else
  13487. #endif /* CK_SSL */
  13488. return(AUTHTYPE_NAME(ck_tn_authenticated()));
  13489. #else /* CK_AUTHENTICATION */
  13490. return((char *)"NULL");
  13491. #endif /* CK_AUTHENTICATION */
  13492. #ifdef CK_KERBEROS
  13493. case VN_K4PRN: {
  13494. extern char * krb4_d_principal;
  13495. if (krb4_d_principal)
  13496. ckstrncpy(vvbuf,krb4_d_principal,VVBUFL+1);
  13497. else
  13498. *vvbuf = NUL;
  13499. return((char *)vvbuf);
  13500. }
  13501. case VN_K5PRN: {
  13502. extern char * krb5_d_principal;
  13503. if (krb5_d_principal)
  13504. ckstrncpy(vvbuf,krb5_d_principal,VVBUFL+1);
  13505. else
  13506. *vvbuf = NUL;
  13507. return((char *)vvbuf);
  13508. }
  13509. case VN_K4RLM: {
  13510. extern char * krb4_d_realm;
  13511. if (krb4_d_realm) {
  13512. ckstrncpy(vvbuf,krb4_d_realm,VVBUFL+1);
  13513. } else {
  13514. char * s = ck_krb4_getrealm();
  13515. ckstrncpy(vvbuf,s ? s : "",VVBUFL+1);
  13516. }
  13517. return((char *)vvbuf);
  13518. }
  13519. case VN_K4SRV: {
  13520. extern char * krb4_d_srv;
  13521. if (krb4_d_srv)
  13522. ckstrncpy(vvbuf,krb4_d_srv,VVBUFL+1);
  13523. else
  13524. ckstrncpy(vvbuf,"rcmd",VVBUFL);
  13525. return((char *)vvbuf);
  13526. }
  13527. case VN_K5RLM: {
  13528. extern char * krb5_d_realm;
  13529. extern char * krb5_d_cc;
  13530. if (krb5_d_realm) {
  13531. ckstrncpy(vvbuf,krb5_d_realm,VVBUFL+1);
  13532. } else {
  13533. char * s = ck_krb5_getrealm(krb5_d_cc);
  13534. ckstrncpy(vvbuf,s,VVBUFL+1);
  13535. }
  13536. return((char *)vvbuf);
  13537. }
  13538. case VN_K5CC: {
  13539. extern char * krb5_d_cc;
  13540. if (krb5_d_cc)
  13541. ckstrncpy(vvbuf,krb5_d_cc,VVBUFL+1);
  13542. else
  13543. ckstrncpy(vvbuf,ck_krb5_get_cc_name(),VVBUFL+1);
  13544. return((char *)vvbuf);
  13545. }
  13546. case VN_K5SRV: {
  13547. extern char * krb5_d_srv;
  13548. if (krb5_d_srv)
  13549. ckstrncpy(vvbuf,krb5_d_srv,VVBUFL+1);
  13550. else
  13551. ckstrncpy(vvbuf,"host",VVBUFL);
  13552. return((char *)vvbuf);
  13553. }
  13554. case VN_K4ENO: {
  13555. extern int krb4_errno;
  13556. sprintf(vvbuf,"%d",krb4_errno); /* SAFE */
  13557. return((char *)vvbuf);
  13558. }
  13559. case VN_K5ENO: {
  13560. extern int krb5_errno;
  13561. sprintf(vvbuf,"%d",krb5_errno); /* SAFE */
  13562. return((char *)vvbuf);
  13563. }
  13564. case VN_K4EMSG: {
  13565. extern char * krb4_errmsg;
  13566. ckstrncpy(vvbuf,krb4_errmsg?krb4_errmsg:"",VVBUFL+1);
  13567. return((char *)vvbuf);
  13568. }
  13569. case VN_K5EMSG: {
  13570. extern char * krb5_errmsg;
  13571. ckstrncpy(vvbuf,krb5_errmsg,VVBUFL+1);
  13572. return((char *)vvbuf);
  13573. }
  13574. #endif /* CK_KERBEROS */
  13575. #ifdef CK_SSL
  13576. case VN_X509_S:
  13577. if (ssl_active_flag)
  13578. ckstrncpy(vvbuf,ssl_get_subject_name(ssl_con),VVBUFL+1);
  13579. else if (tls_active_flag)
  13580. ckstrncpy(vvbuf,ssl_get_subject_name(tls_con),VVBUFL+1);
  13581. else
  13582. ckstrncpy(vvbuf,"",VVBUFL+1);
  13583. return((char *)vvbuf);
  13584. case VN_X509_I:
  13585. if (ssl_active_flag)
  13586. ckstrncpy(vvbuf,ssl_get_issuer_name(ssl_con),VVBUFL+1);
  13587. else if (tls_active_flag)
  13588. ckstrncpy(vvbuf,ssl_get_issuer_name(tls_con),VVBUFL+1);
  13589. else
  13590. ckstrncpy(vvbuf,"",VVBUFL+1);
  13591. return((char *)vvbuf);
  13592. #endif /* CK_SSL */
  13593. case VN_OSNAM:
  13594. #ifdef IKSD
  13595. #ifdef CK_LOGIN
  13596. if (inserver && isguest)
  13597. return("");
  13598. #endif /* CK_LOGIN */
  13599. #endif /* IKSD */
  13600. #ifdef CK_UTSNAME
  13601. {
  13602. extern char unm_nam[];
  13603. return((char *)unm_nam);
  13604. }
  13605. #else
  13606. for (x = y = 0; x < VVBUFL; x++) {
  13607. if (ckxsys[x] == SP && cx == 0) continue;
  13608. vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  13609. }
  13610. vvbuf[y] = NUL;
  13611. return(vvbuf);
  13612. #endif /* CK_UTSNAME */
  13613. case VN_OSVER: {
  13614. #ifdef CK_UTSNAME
  13615. extern char unm_ver[];
  13616. #ifdef IKSD
  13617. #ifdef CK_LOGIN
  13618. if (inserver && isguest)
  13619. return("");
  13620. #endif /* CK_LOGIN */
  13621. #endif /* IKSD */
  13622. return((char *)unm_ver);
  13623. #else
  13624. return("");
  13625. #endif /* CK_UTSNAME */
  13626. }
  13627. case VN_OSREL: {
  13628. #ifdef CK_UTSNAME
  13629. extern char unm_rel[];
  13630. #ifdef IKSD
  13631. #ifdef CK_LOGIN
  13632. if (inserver && isguest)
  13633. return("");
  13634. #endif /* CK_LOGIN */
  13635. #endif /* IKSD */
  13636. return((char *)unm_rel);
  13637. #else
  13638. return("");
  13639. #endif /* CK_UTSNAME */
  13640. }
  13641. } /* Break up long switch statements... */
  13642. switch(y) {
  13643. case VN_NAME: {
  13644. extern char * myname;
  13645. return(myname);
  13646. }
  13647. case VN_MODL: {
  13648. #ifdef CK_UTSNAME
  13649. extern char unm_mod[], unm_mch[];
  13650. int y = VVBUFL - 1;
  13651. char * s = unm_mod;
  13652. #endif /* CK_UTSNAME */
  13653. #ifdef IKSD
  13654. #ifdef CK_LOGIN
  13655. if (inserver && isguest)
  13656. return("");
  13657. #endif /* CK_LOGIN */
  13658. #endif /* IKSD */
  13659. #ifdef COMMENT /* was HPUX */
  13660. if (!unm_mod[0] && !nopush)
  13661. zzstring("\\fcommand(model)",&s,&y);
  13662. /*
  13663. Another possibility would be:
  13664. "\\fcommand(ksh -c 'whence model 1>&- && model || uname -m')"
  13665. But that would depend on having ksh.
  13666. */
  13667. #else
  13668. #ifdef OSF32 /* Digital UNIX 3.2 and higher... */
  13669. /* Note: Ultrix has /etc/sizer, but it is not publicly executable. */
  13670. /* sizer -c outputs 'cpu:<tab><tab>"DECxxxx"' */
  13671. if (!unm_mod[0]) {
  13672. char * p;
  13673. int flag = 0;
  13674. zzstring("\\fcommand(/usr/sbin/sizer -c)",&s,&y);
  13675. debug(F110,"DU model",unm_mod,0);
  13676. s = unm_mod;
  13677. p = unm_mod;
  13678. while (*p) { /* Extract the part in quotes */
  13679. if (*p == '"') {
  13680. if (flag)
  13681. break;
  13682. flag = 1;
  13683. p++;
  13684. continue;
  13685. }
  13686. if (flag)
  13687. *s++ = *p;
  13688. p++;
  13689. }
  13690. *s = NUL;
  13691. }
  13692. #endif /* OSF32 */
  13693. #endif /* COMMENT */
  13694. #ifdef CK_UTSNAME
  13695. if (unm_mod[0])
  13696. return((char *)unm_mod);
  13697. else
  13698. return((char *)unm_mch);
  13699. #else
  13700. return("");
  13701. #endif /* CK_UTSNAME */
  13702. }
  13703. #ifdef IBMX25
  13704. /* X.25 variables (local and remote address) */
  13705. case VN_X25LA:
  13706. if (!local_nua[0] && !x25local_nua(local_nua))
  13707. *vvbuf = NULL;
  13708. else
  13709. ckstrncpy(vvbuf,local_nua,VVBUFL+1);
  13710. return((char *)vvbuf);
  13711. case VN_X25RA:
  13712. if (!remote_nua[0])
  13713. *vvbuf = NULL;
  13714. else
  13715. ckstrncpy(vvbuf,remote_nua,VVBUFL+1);
  13716. return((char *)vvbuf);
  13717. #endif /* IBMX25 */
  13718. #ifndef NODIAL
  13719. case VN_PDSFX: {
  13720. extern char pdsfx[];
  13721. return((char *)pdsfx);
  13722. }
  13723. case VN_DTYPE: {
  13724. extern int dialtype;
  13725. sprintf(vvbuf,"%d",dialtype); /* SAFE */
  13726. return((char *)vvbuf);
  13727. }
  13728. #endif /* NODIAL */
  13729. #ifdef UNIX
  13730. case VN_LCKPID: {
  13731. extern char lockpid[];
  13732. return((char *)lockpid);
  13733. }
  13734. #endif /* UNIX */
  13735. #ifndef NOXFER
  13736. case VN_BLK:
  13737. sprintf(vvbuf,"%d",bctr); /* SAFE */
  13738. return((char *)vvbuf);
  13739. case VN_TFTIM:
  13740. sprintf(vvbuf, /* SAFE */
  13741. #ifdef GFTIMER
  13742. "%ld", (long)(fptsecs + 0.5)
  13743. #else
  13744. "%d", tsecs
  13745. #endif /* GFTIMER */
  13746. );
  13747. return((char *)vvbuf);
  13748. #endif /* NOXFER */
  13749. case VN_HWPAR:
  13750. case VN_SERIAL: {
  13751. int sb;
  13752. char c, * ss;
  13753. extern int stopbits;
  13754. vvbuf[0] = NUL;
  13755. if (hwparity && local && !network)
  13756. ss = parnam((char)hwparity);
  13757. else
  13758. ss = parnam((char)parity);
  13759. if (cx == VN_HWPAR) {
  13760. ckstrncpy(vvbuf,ss,VVBUFL);
  13761. return((char *)vvbuf);
  13762. }
  13763. c = ss[0];
  13764. if (islower(c)) c = toupper(c);
  13765. sb = stopbits;
  13766. if (sb < 1)
  13767. sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  13768. if (hwparity)
  13769. sprintf(vvbuf," 8%c%d",c,sb); /* SAFE */
  13770. else if (parity)
  13771. sprintf(vvbuf," 7%c%d",c,sb); /* SAFE */
  13772. else
  13773. sprintf(vvbuf," 8N%d",sb); /* SAFE */
  13774. return((char *)vvbuf);
  13775. }
  13776. #ifdef UNIX
  13777. case VN_LCKDIR: {
  13778. #ifndef NOUUCP
  13779. extern char * uucplockdir;
  13780. ckstrncpy(vvbuf,uucplockdir,VVBUFL);
  13781. x = strlen(vvbuf);
  13782. if (x > 0) {
  13783. if (vvbuf[x-1] != '/') {
  13784. vvbuf[x] = '/';
  13785. vvbuf[x+1] = NUL;
  13786. }
  13787. }
  13788. #else
  13789. vvbuf[0] = NUL;
  13790. #endif /* NOUUCP */
  13791. return((char *)vvbuf);
  13792. }
  13793. #endif /* UNIX */
  13794. } /* Break up long switch statements... */
  13795. switch(y) {
  13796. #ifndef NODIAL
  13797. case VN_DM_LP:
  13798. case VN_DM_SP:
  13799. case VN_DM_PD:
  13800. case VN_DM_TD:
  13801. case VN_DM_WA:
  13802. case VN_DM_WD:
  13803. case VN_DM_HF:
  13804. case VN_DM_WB:
  13805. case VN_DM_RC: {
  13806. extern char * getdm();
  13807. ckstrncpy(vvbuf,getdm(y),VVBUFL);
  13808. return((char *)vvbuf);
  13809. }
  13810. #endif /* NODIAL */
  13811. case VN_TY_LN:
  13812. case VN_TY_LC: {
  13813. extern int typ_lines;
  13814. sprintf(vvbuf,"%d",typ_lines); /* SAFE */
  13815. return((char *)vvbuf);
  13816. }
  13817. case VN_TY_LM: {
  13818. extern int typ_mtchs;
  13819. sprintf(vvbuf,"%d",typ_mtchs); /* SAFE */
  13820. return((char *)vvbuf);
  13821. }
  13822. case VN_MACLVL:
  13823. sprintf(vvbuf,"%d",maclvl); /* SAFE */
  13824. return((char *)vvbuf);
  13825. } /* Break up long switch statements... */
  13826. switch(y) {
  13827. #ifndef NOLASTFILE
  13828. case VN_LASTFIL: {
  13829. extern char * lastfile;
  13830. return(lastfile ? lastfile : "");
  13831. }
  13832. #endif /* NOLASTFILE */
  13833. #ifndef NOXFER
  13834. case VN_XF_BC:
  13835. sprintf(vvbuf,"%d",crunched); /* SAFE */
  13836. return((char *)vvbuf);
  13837. case VN_XF_TM:
  13838. sprintf(vvbuf,"%d",timeouts); /* SAFE */
  13839. return((char *)vvbuf);
  13840. case VN_XF_RX:
  13841. sprintf(vvbuf,"%d",retrans); /* SAFE */
  13842. return((char *)vvbuf);
  13843. #endif /* NOXFER */
  13844. case VN_MS_CD: /* Modem signals */
  13845. case VN_MS_CTS:
  13846. case VN_MS_DSR:
  13847. case VN_MS_DTR:
  13848. case VN_MS_RI:
  13849. case VN_MS_RTS: {
  13850. int x, z = -1;
  13851. x = ttgmdm(); /* Try to get them */
  13852. if (x > -1) {
  13853. switch (y) {
  13854. case VN_MS_CD: z = (x & BM_DCD) ? 1 : 0; break;
  13855. case VN_MS_DSR: z = (x & BM_DSR) ? 1 : 0; break;
  13856. case VN_MS_CTS: z = (x & BM_CTS) ? 1 : 0; break;
  13857. #ifdef MAC
  13858. case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  13859. #else
  13860. #ifndef STRATUS
  13861. case VN_MS_RI: z = (x & BM_RNG) ? 1 : 0; break;
  13862. #ifndef NT
  13863. case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  13864. case VN_MS_RTS: z = (x & BM_RTS) ? 1 : 0; break;
  13865. #endif /* NT */
  13866. #endif /* STRATUS */
  13867. #endif /* MAC */
  13868. }
  13869. }
  13870. sprintf(vvbuf,"%d",z); /* SAFE */
  13871. return((char *)vvbuf);
  13872. }
  13873. case VN_MATCH: /* INPUT MATCH */
  13874. return(inpmatch ? inpmatch : "");
  13875. #ifdef CKFLOAT
  13876. case VN_ISCALE: /* INPUT SCALE-FACTOR */
  13877. return(inpscale ? inpscale : "1.0");
  13878. #endif /* CKFLOAT */
  13879. case VN_SLMSG: { /* SET LINE / HOST message */
  13880. extern char * slmsg;
  13881. vvbuf[0] = NUL;
  13882. if (slmsg)
  13883. ckstrncpy(vvbuf,slmsg,VVBUFL);
  13884. return(vvbuf);
  13885. }
  13886. case VN_TXTDIR: /* TEXTDIR */
  13887. return(k_info_dir ? k_info_dir : "");
  13888. #ifdef FNFLOAT
  13889. case VN_MA_PI:
  13890. return(math_pi);
  13891. case VN_MA_E:
  13892. return(math_e);
  13893. case VN_MA_PR:
  13894. sprintf(vvbuf,"%d",fp_digits); /* SAFE */
  13895. return(vvbuf);
  13896. #endif /* FNFLOAT */
  13897. case VN_CMDBL:
  13898. sprintf(vvbuf,"%d",CMDBL); /* SAFE */
  13899. return(vvbuf);
  13900. #ifdef CKCHANNELIO
  13901. case VN_FERR: {
  13902. extern int z_error;
  13903. sprintf(vvbuf,"%d",z_error); /* SAFE */
  13904. return(vvbuf);
  13905. }
  13906. case VN_FMAX: {
  13907. extern int z_maxchan;
  13908. sprintf(vvbuf,"%d",z_maxchan); /* SAFE */
  13909. return(vvbuf);
  13910. }
  13911. case VN_FCOU: {
  13912. extern int z_filcount;
  13913. sprintf(vvbuf,"%d",z_filcount); /* SAFE */
  13914. return(vvbuf);
  13915. }
  13916. #endif /* CKCHANNELIO */
  13917. #ifndef NODIAL
  13918. case VN_DRTR: {
  13919. extern int dialcount;
  13920. sprintf(vvbuf,"%d",dialcount); /* SAFE */
  13921. return(vvbuf);
  13922. }
  13923. #endif /* NODIAL */
  13924. #ifndef NOLOGDIAL
  13925. #ifndef NOLOCAL
  13926. case VN_CXTIME:
  13927. sprintf(vvbuf,"%ld",dologshow(0)); /* SAFE */
  13928. return(vvbuf);
  13929. #endif /* NOLOCAL */
  13930. #endif /* NOLOGDIAL */
  13931. case VN_BYTE:
  13932. sprintf(vvbuf,"%d",byteorder); /* SAFE */
  13933. return(vvbuf);
  13934. case VN_KBCHAR:
  13935. vvbuf[0] = NUL;
  13936. vvbuf[1] = NUL;
  13937. if (kbchar > 0)
  13938. vvbuf[0] = (kbchar & 0xff);
  13939. return(vvbuf);
  13940. case VN_TTYNAM: {
  13941. #ifdef HAVECTTNAM
  13942. extern char cttnam[];
  13943. return((char *)cttnam);
  13944. #else
  13945. return(CTTNAM);
  13946. #endif /* HAVECTTNAM */
  13947. }
  13948. case VN_PROMPT:
  13949. return(cmgetp());
  13950. case VN_BUILD: {
  13951. extern char * buildid;
  13952. return(buildid);
  13953. }
  13954. #ifndef NOSEXP
  13955. case VN_SEXP: {
  13956. extern char * lastsexp;
  13957. return(lastsexp ? lastsexp : "");
  13958. }
  13959. case VN_VSEXP: {
  13960. extern char * sexpval;
  13961. return(sexpval ? sexpval : "");
  13962. }
  13963. case VN_LSEXP: {
  13964. extern int sexpdep;
  13965. ckstrncpy(vvbuf,ckitoa(sexpdep),VVBUFL);
  13966. return(vvbuf);
  13967. }
  13968. #endif /* NOSEXP */
  13969. #ifdef GFTIMER
  13970. case VN_FTIME: {
  13971. CKFLOAT f;
  13972. ztime(&p);
  13973. if (p == NULL || *p == NUL)
  13974. return(NULL);
  13975. z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  13976. f = (CKFLOAT)z + ((CKFLOAT)ztusec) / 1000000.0;
  13977. sprintf(vvbuf,"%f",f); /* SAFE */
  13978. return(vvbuf);
  13979. }
  13980. #endif /* GFTIMER */
  13981. #ifndef NOHTTP
  13982. case VN_HTTP_C: { /* HTTP Code */
  13983. extern int http_code;
  13984. return(ckitoa(http_code));
  13985. }
  13986. case VN_HTTP_N: /* HTTP Connected */
  13987. return( http_isconnected() ? "1" : "0");
  13988. case VN_HTTP_H: /* HTTP Host */
  13989. return( (char *)http_host() );
  13990. case VN_HTTP_M: { /* HTTP Message */
  13991. extern char http_reply_str[];
  13992. return((char *)http_reply_str);
  13993. }
  13994. case VN_HTTP_S: /* HTTP Security */
  13995. return((char *)http_security());
  13996. #endif /* NOHTTP */
  13997. #ifdef NEWFTP
  13998. case VN_FTP_B:
  13999. return((char *)ftp_cpl_mode());
  14000. case VN_FTP_D:
  14001. return((char *)ftp_dpl_mode());
  14002. case VN_FTP_Z:
  14003. return((char *)ftp_authtype());
  14004. case VN_FTP_C: {
  14005. extern int ftpcode;
  14006. return(ckitoa(ftpcode));
  14007. }
  14008. case VN_FTP_M: {
  14009. extern char ftp_reply_str[];
  14010. if (isdigit(ftp_reply_str[0]) &&
  14011. isdigit(ftp_reply_str[1]) &&
  14012. isdigit(ftp_reply_str[2]) &&
  14013. ftp_reply_str[3] == ' ')
  14014. return(&ftp_reply_str[4]);
  14015. else
  14016. return(ftp_reply_str);
  14017. }
  14018. case VN_FTP_S: {
  14019. extern char ftp_srvtyp[];
  14020. return((char *)ftp_srvtyp);
  14021. }
  14022. case VN_FTP_H: {
  14023. extern char * ftp_host;
  14024. return(ftp_host ? ftp_host : "");
  14025. }
  14026. case VN_FTP_X: { /* FTP Connected */
  14027. return(ftpisconnected() ? "1" : "0");
  14028. }
  14029. case VN_FTP_L: { /* FTP Logged in */
  14030. return(ftpisloggedin() ? "1" : "0");
  14031. }
  14032. case VN_FTP_G: { /* FTP GET-PUT-REMOTE */
  14033. extern int ftpget;
  14034. char * s = "";
  14035. switch (ftpget) {
  14036. case 0: s = "kermit"; break;
  14037. case 1: s = "ftp"; break;
  14038. case 2: s = "auto"; break;
  14039. }
  14040. return(s);
  14041. }
  14042. #endif /* NEWFTP */
  14043. #ifndef NOLOCAL
  14044. case VN_CX_STA: { /* CONNECT status */
  14045. extern int cx_status;
  14046. return(ckitoa(cx_status));
  14047. }
  14048. #endif /* NOLOCAL */
  14049. case VN_NOW: /* Timestamp */
  14050. return(ckcvtdate(p,0));
  14051. case VN_HOUR: /* Hour of the day */
  14052. ztime(&p); /* "Thu Feb 8 12:00:00 1990" */
  14053. if (!p) p = "";
  14054. if (!*p) return(p);
  14055. vvbuf[0] = p[11];
  14056. vvbuf[1] = p[12];
  14057. vvbuf[2] = NUL;
  14058. return(vvbuf); /* and return it */
  14059. case VN_BITS: /* Bits (16, 32, 64) */
  14060. if (sizeof(long) > 4)
  14061. return(ckitoa(8*sizeof(long)));
  14062. else
  14063. return(ckitoa(8*sizeof(int)));
  14064. case VN_LASTKWV: /* 212 */
  14065. return(lastkwval ? lastkwval : "");
  14066. case VN_HOSTIP: { /* 212 */
  14067. #ifdef TCPSOCKET
  14068. extern char hostipaddr[];
  14069. return((char *)hostipaddr);
  14070. #else
  14071. return("");
  14072. #endif /* TCPSOCKET */
  14073. }
  14074. case VN_INPMSG:
  14075. switch (instatus) {
  14076. case INP_OK: return("SUCCESS");
  14077. case INP_TO: return("Timed out");
  14078. case INP_UI: return("Keyboard interrupt");
  14079. case INP_IE: return("Internal error");
  14080. case INP_IO: return("I/O error or connection lost");
  14081. case INP_IKS: return("INPUT disabled");
  14082. case INP_BF: return("Buffer filled and /NOWRAP set");
  14083. default: return("Unknown");
  14084. }
  14085. case VN_VAREVAL: /* 212 */
  14086. return(vareval ? "recursive" : "simple");
  14087. case VN_LOG_CON: /* \v(...) for log files */
  14088. #ifdef CKLOGDIAL
  14089. return(diafil);
  14090. #else
  14091. return("");
  14092. #endif
  14093. case VN_LOG_PKT:
  14094. #ifndef NOXFER
  14095. return(pktfil);
  14096. #else
  14097. return("");
  14098. #endif
  14099. case VN_LOG_SES:
  14100. #ifndef NOLOCAL
  14101. return(sesfil);
  14102. #else
  14103. return("");
  14104. #endif
  14105. case VN_LOG_TRA:
  14106. #ifdef TLOG
  14107. return(trafil);
  14108. #else
  14109. return("");
  14110. #endif
  14111. case VN_LOG_DEB:
  14112. #ifdef DEBUG
  14113. return(debfil);
  14114. #else
  14115. return("");
  14116. #endif
  14117. case VN_PREVCMD: {
  14118. extern char * prevcmd;
  14119. return(prevcmd ? prevcmd : "");
  14120. }
  14121. }
  14122. #ifndef NODIAL
  14123. switch (y) { /* Caller ID values */
  14124. extern char
  14125. * callid_date, * callid_time, * callid_name,
  14126. * callid_nmbr, * callid_mesg;
  14127. case VN_CI_DA:
  14128. return(callid_date ? callid_date : "");
  14129. case VN_CI_TI:
  14130. return(callid_time ? callid_time : "");
  14131. case VN_CI_NA:
  14132. return(callid_name ? callid_name : "");
  14133. case VN_CI_NU:
  14134. return(callid_nmbr ? callid_nmbr : "");
  14135. case VN_CI_ME:
  14136. return(callid_mesg ? callid_mesg : "");
  14137. } /* End of variable-name switches */
  14138. #endif /* NODIAL */
  14139. #ifdef NT
  14140. switch (y) {
  14141. case VN_PERSONAL:
  14142. p = (char *)GetPersonal();
  14143. if (p) {
  14144. GetShortPathName(p,vvbuf,VVBUFL);
  14145. return(vvbuf);
  14146. }
  14147. return("");
  14148. case VN_DESKTOP:
  14149. p = (char *)GetDesktop();
  14150. if (p) {
  14151. GetShortPathName(p,vvbuf,VVBUFL);
  14152. return(vvbuf);
  14153. }
  14154. return("");
  14155. case VN_COMMON:
  14156. p = (char *)GetAppData(1);
  14157. if (p) {
  14158. ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  14159. GetShortPathName(vvbuf,vvbuf,VVBUFL);
  14160. return(vvbuf);
  14161. }
  14162. return("");
  14163. case VN_APPDATA:
  14164. p = (char *)GetAppData(0);
  14165. if (p) {
  14166. ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  14167. GetShortPathName(vvbuf,vvbuf,VVBUFL);
  14168. return(vvbuf);
  14169. }
  14170. return("");
  14171. }
  14172. #endif /* NT */
  14173. #ifdef TN_COMPORT
  14174. switch (y) {
  14175. case VN_TNC_SIG: {
  14176. p = (char *) tnc_get_signature();
  14177. ckstrncpy(vvbuf,p ? p : "",VVBUFL);
  14178. return(vvbuf);
  14179. }
  14180. }
  14181. #endif /* TN_COMPORT */
  14182. #ifdef KUI
  14183. switch (y) {
  14184. case VN_GUI_RUN: {
  14185. extern HWND getHwndKUI();
  14186. if ( IsIconic(getHwndKUI()) )
  14187. return("minimized");
  14188. if ( IsZoomed(getHwndKUI()) )
  14189. return("maximized");
  14190. return("restored");
  14191. }
  14192. case VN_GUI_XP:
  14193. sprintf(vvbuf,"%d",get_gui_window_pos_x()); /* SAFE */
  14194. return(vvbuf);
  14195. case VN_GUI_YP:
  14196. sprintf(vvbuf,"%d",get_gui_window_pos_y()); /* SAFE */
  14197. return(vvbuf);
  14198. case VN_GUI_XR:
  14199. sprintf(vvbuf,"%d",GetSystemMetrics(SM_CXSCREEN)); /* SAFE */
  14200. return(vvbuf);
  14201. case VN_GUI_YR:
  14202. sprintf(vvbuf,"%d",GetSystemMetrics(SM_CYSCREEN)); /* SAFE */
  14203. return(vvbuf);
  14204. case VN_GUI_FNM:
  14205. if ( ntermfont > 0 ) {
  14206. int i;
  14207. for (i = 0; i < ntermfont; i++) {
  14208. if (tt_font == term_font[i].kwval) {
  14209. ckstrncpy(vvbuf,term_font[i].kwd,VVBUFL);
  14210. return(vvbuf);
  14211. }
  14212. }
  14213. }
  14214. return("(unknown)");
  14215. case VN_GUI_FSZ:
  14216. ckstrncpy(vvbuf,ckitoa(tt_font_size/2),VVBUFL);
  14217. if ( tt_font_size % 2 )
  14218. ckstrncat(vvbuf,".5",VVBUFL);
  14219. return(vvbuf);
  14220. }
  14221. #endif /* KUI */
  14222. fnsuccess = 0;
  14223. if (fnerror) {
  14224. fnsuccess = 0;
  14225. }
  14226. if (fndiags) {
  14227. if (!embuf[0])
  14228. ckstrncpy(embuf,"<ERROR:NO_SUCH_VARIABLE>",EMBUFLEN);
  14229. printf("?%s\n",embuf);
  14230. return((char *)embuf);
  14231. } else
  14232. return("");
  14233. }
  14234. #endif /* NOSPL */
  14235. /* warning, this won't work for VMS */
  14236. char *
  14237. getbasename(s) char *s; {
  14238. int n, i;
  14239. if (!s) s = "";
  14240. if (!*s) return("");
  14241. n = (int)strlen(s);
  14242. for (i = n-2; i >= 0; i--) {
  14243. if (ISDIRSEP(s[i]))
  14244. return(s+i+1);
  14245. }
  14246. return(s);
  14247. }
  14248. /*
  14249. X X S T R I N G -- Expand variables and backslash codes.
  14250. int xxtstring(s,&s2,&n);
  14251. Expands \ escapes via recursive descent.
  14252. Argument s is a pointer to string to expand (source).
  14253. Argument s2 is the address of where to put result (destination).
  14254. Argument n is the length of the destination string (to prevent overruns).
  14255. Returns -1 on failure, 0 on success,
  14256. with destination string null-terminated and s2 pointing to the
  14257. terminating null, so that subsequent characters can be added.
  14258. Failure reasons include destination buffer is filled up.
  14259. */
  14260. #define XXDEPLIM 100 /* Recursion depth limit */
  14261. /*
  14262. In Windows the stack is limited to 256K so big character arrays like
  14263. vnambuf can't be on the stack in recursive functions like zzstring().
  14264. But that's no reason use malloc() in Unix or VMS, which don't have
  14265. this kind of restriction.
  14266. */
  14267. #ifdef DVNAMBUF /* Dynamic vnambuf[] */
  14268. #undef DVNAMBUF /* Clean slate */
  14269. #endif /* DVNAMBUF */
  14270. #ifndef NOSPL /* Only if SPL included */
  14271. #ifdef OS2 /* Only for K95 */
  14272. #define DVNAMBUF
  14273. #endif /* OS2 */
  14274. #endif /* NOSPL */
  14275. int
  14276. zzstring(s,s2,n) char *s; char **s2; int *n; {
  14277. int x, /* Current character */
  14278. xx, /* Worker */
  14279. y, /* Worker */
  14280. pp, /* Paren level */
  14281. kp, /* Brace level */
  14282. argn, /* Function argument counter */
  14283. n2, /* Local copy of n */
  14284. d, /* Array dimension */
  14285. vbi, /* Variable id (integer form) */
  14286. argl, /* String argument length */
  14287. nx, /* Save original length */
  14288. quoting = 0; /* 299 */
  14289. char vb, /* Variable id (char form) */
  14290. *vp, /* Pointer to variable definition */
  14291. *new, /* Local pointer to target string */
  14292. #ifdef COMMENT
  14293. *old, /* Save original target pointer */
  14294. #endif /* COMMENT */
  14295. *p, /* Worker */
  14296. *q, /* Worker */
  14297. *s3; /* Worker */
  14298. int x3; /* Worker */
  14299. char *r = (char *)0; /* For holding function args */
  14300. char *r2 = (char *)0;
  14301. char *r3p;
  14302. #ifndef NOSPL
  14303. #ifdef DVNAMBUF
  14304. char * vnambuf = NULL; /* Buffer for variable/function name */
  14305. #else /* DVNAMBUF */
  14306. char vnambuf[VNAML]; /* Buffer for variable/function name */
  14307. #endif /* DVNAMBUF */
  14308. char *argp[FNARGS]; /* Pointers to function args */
  14309. #endif /* NOSPL */
  14310. static int depth = 0; /* Call depth, avoid overflow */
  14311. n2 = *n; /* Make local copies of args */
  14312. nx = n2;
  14313. #ifdef COMMENT
  14314. /* This is always 32K in BIGBUFOK builds */
  14315. if (depth == 0)
  14316. debug(F101,"zzstring top-level n","",n2);
  14317. #endif /* COMMENT */
  14318. new = *s2; /* for one less level of indirection */
  14319. #ifdef COMMENT
  14320. old = new;
  14321. #endif /* COMMENT */
  14322. #ifndef NOSPL
  14323. itsapattern = 0; /* For \fpattern() */
  14324. isjoin = 0; /* For \fjoin() */
  14325. #endif /* NOSPL */
  14326. depth++; /* Sink to a new depth */
  14327. if (depth > XXDEPLIM) { /* Too deep? */
  14328. (VOID) newerrmsg("Definition is circular or too deep");
  14329. debug(F111,"zzstring","Definition is circular or too deep",XXDEPLIM);
  14330. depth = 0;
  14331. *new = NUL;
  14332. return(-1);
  14333. }
  14334. if (!s || !new) { /* Watch out for null pointers */
  14335. debug(F101,"zzstring fail 2","",depth);
  14336. if (new)
  14337. *new = NUL;
  14338. depth = 0;
  14339. return(-1);
  14340. }
  14341. s3 = s;
  14342. argl = 0;
  14343. while (*s3++) argl++; /* Get length of source string */
  14344. debug(F010,"zzstring entry",s,0);
  14345. if (argl == 0) { /* Empty string */
  14346. debug(F111,"zzstring empty arg",s,argl);
  14347. depth = 0;
  14348. *new = NUL;
  14349. return(0);
  14350. }
  14351. if (argl < 0) { /* Watch out for garbage */
  14352. debug(F101,"zzstring fail 3","",depth);
  14353. *new = NUL;
  14354. depth = 0;
  14355. return(-1);
  14356. }
  14357. #ifdef DVNAMBUF
  14358. debug(F100,"vnambuf malloc...","",0);
  14359. vnambuf = malloc(VNAML);
  14360. if (vnambuf == NULL) {
  14361. printf("?Out of memory");
  14362. return(-1);
  14363. }
  14364. debug(F100,"vnambuf malloc ok","",0);
  14365. #endif /* DVNAMBUF */
  14366. while ((x = *s)) { /* Loop for all characters */
  14367. if (x != CMDQ) { /* Is it the command-quote char? */
  14368. *new++ = *s++; /* No, normal char, just copy */
  14369. if (--n2 < 0) { /* and count it, careful of overflow */
  14370. debug(F101,"zzstring overflow 1","",depth);
  14371. depth = 0;
  14372. #ifdef DVNAMBUF
  14373. if (vnambuf) free(vnambuf);
  14374. #endif /* DVNAMBUF */
  14375. return(-1);
  14376. }
  14377. continue;
  14378. }
  14379. /* We have the command-quote character. */
  14380. x = *(s+1); /* Get the following character. */
  14381. if (isupper(x)) x = tolower(x);
  14382. switch (x) { /* Act according to variable type */
  14383. #ifndef NOSPL
  14384. case 0: /* It's a lone backslash */
  14385. *new++ = *s++;
  14386. if (--n2 < 0) {
  14387. debug(F101,"zzstring overflow 2","",0);
  14388. #ifdef DVNAMBUF
  14389. if (vnambuf) free(vnambuf);
  14390. #endif /* DVNAMBUF */
  14391. return(-1);
  14392. }
  14393. break;
  14394. case '%': /* Variable */
  14395. s += 2; /* Get the letter or digit */
  14396. vb = *s++; /* and move source pointer past it */
  14397. vp = NULL; /* Assume definition is empty */
  14398. if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  14399. if (maclvl < 0) /* Digit variables are global */
  14400. vp = g_var[vb]; /* if no macro is active */
  14401. else /* otherwise */
  14402. vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  14403. } else if (vb == '*') { /* Macro args string */
  14404. #ifdef COMMENT
  14405. /* This doesn't take changes into account */
  14406. vp = (maclvl >= 0) ? m_line[maclvl] : topline;
  14407. if (!vp) vp = "";
  14408. #else
  14409. char * ss = new;
  14410. if (zzstring("\\fjoin(&_[],,1)",&new,&n2) < 0) {
  14411. #ifdef DVNAMBUF
  14412. if (vnambuf) free(vnambuf);
  14413. #endif /* DVNAMBUF */
  14414. return(-1);
  14415. }
  14416. debug(F110,"zzstring \\%*",ss,0);
  14417. break;
  14418. #endif /* COMMENT */
  14419. } else {
  14420. if (isupper(vb)) vb += ('a'-'A');
  14421. vp = g_var[vb]; /* Letter for global variable */
  14422. }
  14423. if (!vp) vp = "";
  14424. #ifdef COMMENT
  14425. if (vp) { /* If definition not empty */
  14426. #endif /* COMMENT */
  14427. if (vareval) {
  14428. debug(F010,"zzstring %n vp",vp,0);
  14429. /* call self to evaluate it */
  14430. if (zzstring(vp,&new,&n2) < 0) {
  14431. debug(F101,"zzstring fail 6","",depth);
  14432. #ifdef DVNAMBUF
  14433. if (vnambuf) free(vnambuf);
  14434. #endif /* DVNAMBUF */
  14435. return(-1); /* Pass along failure */
  14436. }
  14437. } else {
  14438. while ((*new++ = *vp++)) /* copy it to output string. */
  14439. if (--n2 < 0) {
  14440. if (q) free(q);
  14441. debug(F101,"zzstring overflow 4.5","",depth);
  14442. #ifdef DVNAMBUF
  14443. if (vnambuf) free(vnambuf);
  14444. #endif /* DVNAMBUF */
  14445. return(-1);
  14446. }
  14447. new--; /* Back up over terminating null */
  14448. n2++; /* to allow for further deposits. */
  14449. }
  14450. #ifdef COMMENT
  14451. } else {
  14452. debug(F110,"zzstring %n vp","(NULL)",0);
  14453. n2 = nx;
  14454. new = old;
  14455. *new = NUL;
  14456. }
  14457. #endif /* COMMENT */
  14458. break;
  14459. case '&': /* An array reference */
  14460. x = arraynam(s,&vbi,&d); /* Get name and subscript */
  14461. debug(F111,"zzstring arraynam",s,x);
  14462. if (x < 0) {
  14463. debug(F101,"zzstring fail 7","",depth);
  14464. #ifdef DVNAMBUF
  14465. if (vnambuf) free(vnambuf);
  14466. #endif /* DVNAMBUF */
  14467. return(-1);
  14468. }
  14469. pp = 0; /* Bracket counter */
  14470. while (*s) { /* Advance source pointer... */
  14471. if (*s == '[') pp++;
  14472. if (*s == ']' && --pp == 0) break;
  14473. s++;
  14474. }
  14475. if (*s == ']') s++; /* ...past the closing bracket. */
  14476. xx = chkarray(vbi,d); /* Array is declared? */
  14477. debug(F101,"zzstring chkarray","",x);
  14478. if (xx > -1) {
  14479. #ifdef COMMENT
  14480. char * s1 = NULL;
  14481. #endif /* COMMENT */
  14482. vbi -= ARRAYBASE; /* Convert name to index */
  14483. if (a_dim[vbi] >= d) { /* If subscript in range */
  14484. char **ap;
  14485. ap = a_ptr[vbi]; /* get data pointer */
  14486. if (ap) { /* and if there is one */
  14487. if (ap[d]) { /* If definition not empty */
  14488. debug(F111,"zzstring ap[d]",ap[d],d);
  14489. if (vareval) {
  14490. if (zzstring(ap[d],&new,&n2) < 0) {
  14491. debug(F101,"zzstring fail 8","",depth);
  14492. #ifdef DVNAMBUF
  14493. if (vnambuf) free(vnambuf);
  14494. #endif /* DVNAMBUF */
  14495. return(-1); /* Pass along failure */
  14496. }
  14497. } else {
  14498. vp = ap[d];
  14499. while ((*new++ = *vp++)) /* copy to result */
  14500. if (--n2 < 0) {
  14501. if (q) free(q);
  14502. debug(F101,
  14503. "zzstring overflow 8.5","",depth);
  14504. #ifdef DVNAMBUF
  14505. if (vnambuf) free(vnambuf);
  14506. #endif /* DVNAMBUF */
  14507. return(-1);
  14508. }
  14509. new--; /* Back up over terminating null */
  14510. n2++; /* to allow for further deposits. */
  14511. }
  14512. }
  14513. } else {
  14514. /* old = new; */
  14515. n2 = nx;
  14516. }
  14517. }
  14518. }
  14519. break;
  14520. case 'f': /* A builtin function */
  14521. q = vnambuf; /* Copy the name */
  14522. y = 0; /* into a separate buffer */
  14523. s += 2; /* point past 'F' */
  14524. while (y++ < VNAML) {
  14525. if (*s == '(') { s++; break; } /* Look for open paren */
  14526. if ((*q = *s) == NUL) break; /* or end of string */
  14527. s++; q++;
  14528. }
  14529. *q = NUL; /* Terminate function name */
  14530. if (y >= VNAML) { /* Handle pathological case */
  14531. while (*s && (*s != '(')) /* of very long string entered */
  14532. s++; /* as function name. */
  14533. if (*s == ')') s++; /* Skip past it. */
  14534. }
  14535. r = r2 = malloc(argl+2); /* And make a place to copy args */
  14536. /* debug(F101,"zzstring r2","",r2); */
  14537. if (!r2) { /* Watch out for malloc failure */
  14538. debug(F101,"zzstring fail 9","",depth);
  14539. *new = NUL;
  14540. depth = 0;
  14541. #ifdef DVNAMBUF
  14542. if (vnambuf) free(vnambuf);
  14543. #endif /* DVNAMBUF */
  14544. return(-1);
  14545. }
  14546. if (r3) free(r3); /* And another to copy literal arg string */
  14547. r3 = malloc(argl+2);
  14548. /* debug(F101,"zzstring r3","",r3); */
  14549. if (!r3) {
  14550. debug(F101,"zzstring fail 10","",depth);
  14551. depth = 0;
  14552. *new = NUL;
  14553. if (r2) free(r2);
  14554. #ifdef DVNAMBUF
  14555. if (vnambuf) free(vnambuf);
  14556. #endif /* DVNAMBUF */
  14557. return(-1);
  14558. } else
  14559. r3p = r3;
  14560. argn = 0; /* Argument counter */
  14561. argp[argn++] = r; /* Point to first argument */
  14562. y = 0; /* Completion flag */
  14563. pp = 1; /* Paren level (already have one). */
  14564. kp = 0;
  14565. while (1) { /* Copy each argument, char by char. */
  14566. *r3p++ = *s; /* This is a literal copy for \flit */
  14567. if (!*s) break;
  14568. if (*s == '{') { /* Left brace */
  14569. kp++;
  14570. }
  14571. if (*s == '}') { /* Right brace */
  14572. kp--;
  14573. }
  14574. if (*s == '(' && kp <= 0) { /* Open paren not in brace */
  14575. pp++; /* Count it */
  14576. }
  14577. *r = *s; /* Now copy resulting byte */
  14578. if (!*r) /* If NUL, done. */
  14579. break;
  14580. if (*r == ')' && kp <= 0) { /* Closing paren, count it. */
  14581. if (--pp == 0) { /* Final one? */
  14582. *r = NUL; /* Make it a terminating null */
  14583. *(r3p - 1) = NUL;
  14584. s++; /* Point past it in source string */
  14585. y = 1; /* Flag we've got all the args */
  14586. break; /* Done with while loop */
  14587. }
  14588. }
  14589. if (*r == ',' && kp <= 0) { /* Comma */
  14590. if (pp == 1) { /* If not within ()'s, */
  14591. if (argn >= FNARGS) { /* Too many args */
  14592. s++; r++; /* Keep collecting flit() string */
  14593. continue;
  14594. }
  14595. *r = NUL; /* New arg, skip past comma */
  14596. argp[argn++] = r+1; /* In range, point to new arg */
  14597. } /* Otherwise just skip past */
  14598. }
  14599. s++; r++; /* Advance pointers */
  14600. }
  14601. if (!y) /* If we didn't find closing paren */
  14602. argn = -1;
  14603. #ifdef DEBUG
  14604. if (deblog) {
  14605. char buf[24];
  14606. debug(F111,"zzstring function name",vnambuf,y);
  14607. debug(F010,"zzstring function r3",r3,0);
  14608. for (y = 0; y < argn; y++) {
  14609. sprintf(buf,"arg %2d ",y);
  14610. debug(F010,buf,argp[y],0);
  14611. }
  14612. }
  14613. #endif /* DEBUG */
  14614. {
  14615. /* In case the function name itself is constructed */
  14616. char buf[64]; char * p = buf; int n = 64;
  14617. if (zzstring(vnambuf,&p,&n) > -1)
  14618. ckstrncpy(vnambuf,buf,64);
  14619. }
  14620. vp = fneval(vnambuf,argp,argn,r3); /* Evaluate the function. */
  14621. if (vp) { /* If definition not empty */
  14622. while ((*new++ = *vp++)) { /* copy it to output string */
  14623. if (--n2 < 0) { /* watch out for overflow */
  14624. debug(F101,"zzstring fail 12","",depth);
  14625. if (r2) { free(r2); r2 = NULL; }
  14626. if (r3) { free(r3); r3 = NULL; }
  14627. #ifdef DVNAMBUF
  14628. if (vnambuf) free(vnambuf);
  14629. #endif /* DVNAMBUF */
  14630. return(-1);
  14631. }
  14632. }
  14633. new--; /* Back up over terminating null */
  14634. n2++; /* to allow for further deposits. */
  14635. }
  14636. if (r2) { free(r2); r2 = NULL; }
  14637. if (r3) { free(r3); r3 = NULL; }
  14638. break;
  14639. case 'q': /* 299 String to be take literally */
  14640. quoting = 1; /* 299 */
  14641. case '$': /* An environment variable */
  14642. case 'v': /* Or a named builtin variable. */
  14643. case 'm': /* Or a macro /long variable */
  14644. case 's': /* 196 Macro substring */
  14645. case ':': /* 196 \-variable substring */
  14646. pp = 0;
  14647. p = s+2; /* $/V/M must be followed by (name) */
  14648. if (*p != '(') { /* as in \$(HOME) or \V(count) */
  14649. *new++ = *s++; /* If not, just copy it */
  14650. if (--n2 < 0) {
  14651. debug(F101,"zzstring overflow 3","",depth);
  14652. #ifdef DVNAMBUF
  14653. if (vnambuf) free(vnambuf);
  14654. #endif /* DVNAMBUF */
  14655. return(-1);
  14656. }
  14657. break;
  14658. }
  14659. pp++;
  14660. p++; /* Point to 1st char of name */
  14661. q = vnambuf; /* Copy the name */
  14662. y = 0; /* into a separate buffer */
  14663. debug(F110,">>>> \\q(ARG)",p,0);
  14664. while (y++ < VNAML) { /* Watch out for name too long */
  14665. if (*p == '(') { /* Parens can be nested... */
  14666. if (*(p-1) != CMDQ) /* 299 */
  14667. pp++;
  14668. } else if (*p == ')') { /* Name properly terminated with ')' */
  14669. if (*(p-1) != CMDQ) /* 299 */
  14670. pp--;
  14671. if (pp == 0) {
  14672. p++; /* Move source pointer past ')' */
  14673. break;
  14674. }
  14675. }
  14676. if ((*q = *p) == NUL) /* String ends before ')' */
  14677. break;
  14678. p++; q++; /* Advance pointers */
  14679. }
  14680. *q = NUL; /* Terminate the variable name */
  14681. if (y >= VNAML) { /* Handle pathological case */
  14682. while (*p && (*p != ')')) /* of very long string entered */
  14683. p++; /* as variable name. */
  14684. if (*p == ')') p++; /* Skip ahead to the end of it. */
  14685. }
  14686. /* At this point vnambuf contains the macro name from inside the parens */
  14687. s = p; /* Adjust global source pointer */
  14688. s3 = vnambuf;
  14689. x3 = 0;
  14690. while (*s3++) x3++; /* Length needed */
  14691. /* The following is in case the macro name itself contains variables */
  14692. p = malloc(x3 + 1); /* Make temporary space */
  14693. if (p && !quoting) { /* If we got the space */
  14694. vp = vnambuf; /* Point to original */
  14695. strcpy(p,vp); /* (safe) Make a copy of it */
  14696. y = VNAML; /* Length of name buffer */
  14697. zzstring(p,&vp,&y); /* Evaluate the copy */
  14698. free(p); /* Free the temporary space */
  14699. p = NULL;
  14700. }
  14701. /* At this point vnambuf contains the fully evaluated macro name */
  14702. debug(F110,"zzstring macro name",vnambuf,0);
  14703. q = NULL;
  14704. if (x == 'q') { /* 299 Quoting this string */
  14705. vp = vnambuf; /* 299 */
  14706. debug(F110,">>> VP",vp,0);
  14707. } else if (x == '$') { /* Look up its value */
  14708. vp = getenv(vnambuf); /* This way for environment variable */
  14709. } else if (x == 'm' || x == 's' || x == ':') { /* Macro / substr */
  14710. int k, x1 = -1, x2 = -1;
  14711. char c = NUL;
  14712. k = strlen(vnambuf);
  14713. /* \s(name[n:m]) -- Compact substring notation */
  14714. if ((x == 's' || x == ':') && (k > 1)) { /* Substring wanted */
  14715. int bprc;
  14716. if (vnambuf[k-1] == ']') {
  14717. int i;
  14718. for (i = 0; i < k-1; i++) {
  14719. if (vnambuf[i] == '[') {
  14720. bprc = boundspair(vnambuf,":_.",&x1,&x2,&c);
  14721. debug(F111,"zzstring boundspair",vnambuf,bprc);
  14722. debug(F000,"zzstring boundspair c","",c);
  14723. if (bprc > -1) {
  14724. vnambuf[i] = NUL;
  14725. if (x1 < 1)
  14726. x1 = 1;
  14727. x1--; /* Adjust to 0-base */
  14728. }
  14729. break;
  14730. }
  14731. }
  14732. }
  14733. }
  14734. if (x == ':') { /* Variable type (s or :) */
  14735. vp = vnambuf;
  14736. } else { /* Regular macro or associative array*/
  14737. y = isaarray(vnambuf) ?
  14738. mxxlook(mactab,vnambuf,nmac) : /* Assoc Array */
  14739. mxlook(mactab,vnambuf,nmac); /* Macro */
  14740. if (y > -1) { /* Got definition */
  14741. vp = mactab[y].mval;
  14742. } else {
  14743. vp = NULL;
  14744. }
  14745. }
  14746. debug(F111,"zzstring vp",vp,(vp==NULL)?0:strlen(vp));
  14747. if (vp) {
  14748. if ((x == 's' || x == ':') && (k > 1)) {
  14749. /* Compact substring notation */
  14750. if (x2 == 0) { /* Length */
  14751. vp = NULL;
  14752. } else if (x1 > -1) { /* Start */
  14753. k = strlen(vp);
  14754. debug(F101,">>> k","",k);
  14755. /* If it's off the end, result is empty */
  14756. if (x1 > k) {
  14757. vp = NULL;
  14758. } else if (k > 0) {
  14759. /* Stay in bounds */
  14760. if (c == '_' && x2 > k) /* startpos_endpos */
  14761. x2 = k;
  14762. if (c == ':' && x1 + x2 > k) /* start:length */
  14763. x2 = -1;
  14764. debug(F101,">>> x2","",x2);
  14765. debug(F000,">>> c","",c);
  14766. if ((q = malloc(k+1))) {
  14767. strcpy(q,vp); /* safe */
  14768. if (c == '.') {
  14769. q[x1+1] = NUL;
  14770. debug(F000,"XXX. q",q,c);
  14771. }
  14772. if (c == ':') { /* start:length */
  14773. if ((x2 > -1) && ((x1 + x2) <= k)) {
  14774. q[x1+x2] = NUL;
  14775. }
  14776. debug(F000,"XXX: q",q,c);
  14777. } else if (c == '_') { /* start_endpos */
  14778. if (x1 >= x2) {
  14779. q[x1 = 0] = NUL;
  14780. } else if (x2 < k && x2 > -1) {
  14781. q[x2] = NUL;
  14782. }
  14783. debug(F000,"XXX_ q",q,c);
  14784. }
  14785. vp = q+x1;
  14786. } else vp = NULL;
  14787. } else vp = NULL;
  14788. }
  14789. debug(F110,"XXX vnambuf",vnambuf,0);
  14790. debug(F000,"XXX c","",c);
  14791. debug(F101,"XXX x1","",x1);
  14792. debug(F101,"XXX x2","",x2);
  14793. debug(F110,"XXX result",vp,0);
  14794. #ifdef DEBUG
  14795. if (deblog) {
  14796. if (!vp) {
  14797. } else {
  14798. k = strlen(vp);
  14799. }
  14800. }
  14801. #endif /* DEBUG */
  14802. }
  14803. }
  14804. } else { /* or */
  14805. vp = nvlook(vnambuf); /* this way for builtin variable */
  14806. }
  14807. if (vp) { /* If definition not empty */
  14808. while ((*new++ = *vp++)) /* copy it to output string. */
  14809. if (--n2 < 0) {
  14810. if (q) free(q);
  14811. debug(F101,"zzstring overflow 4","",depth);
  14812. #ifdef DVNAMBUF
  14813. if (vnambuf) free(vnambuf);
  14814. #endif /* DVNAMBUF */
  14815. return(-1);
  14816. }
  14817. new--; /* Back up over terminating null */
  14818. n2++; /* to allow for further deposits. */
  14819. }
  14820. if (q) {
  14821. free(q);
  14822. q = NULL;
  14823. }
  14824. break;
  14825. #endif /* NOSPL */ /* Handle \nnn even if NOSPL. */
  14826. #ifndef NOKVERBS
  14827. case 'K':
  14828. case 'k': {
  14829. extern struct keytab kverbs[];
  14830. extern int nkverbs;
  14831. #define K_BUFLEN 30
  14832. char kbuf[K_BUFLEN + 1]; /* Key verb name buffer */
  14833. int x, y, z, brace = 0;
  14834. s += 2;
  14835. /*
  14836. We assume that the verb name is {braced}, or it extends to the end of the
  14837. string, s, or it ends with a space, control character, or backslash.
  14838. */
  14839. p = kbuf; /* Copy verb name into local buffer */
  14840. x = 0;
  14841. if (*s == '{') {
  14842. s++;
  14843. brace++;
  14844. }
  14845. while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  14846. if (brace && *s == '}') {
  14847. s++;
  14848. break;
  14849. }
  14850. *p++ = *s++;
  14851. }
  14852. brace = 0;
  14853. *p = NUL; /* Terminate. */
  14854. p = kbuf; /* Point back to beginning */
  14855. debug(F110,"zzstring kverb",p,0);
  14856. y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  14857. debug(F101,"zzstring lookup",0,y);
  14858. if (y > -1) {
  14859. dokverb(VCMD,y);
  14860. #ifndef NOSPL
  14861. } else { /* Is it a macro? */
  14862. y = mxlook(mactab,p,nmac);
  14863. if (y > -1) {
  14864. debug(F111,"zzstring mxlook",p,y);
  14865. if ((z = dodo(y,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  14866. if (cmpush() > -1) { /* Push command parser state */
  14867. extern int ifc;
  14868. int ifcsav = ifc; /* Push IF condition on stack */
  14869. y = parser(1); /* New parser to execute macro */
  14870. cmpop(); /* Pop command parser */
  14871. ifc = ifcsav; /* Restore IF condition */
  14872. if (y == 0) { /* No errors, ignore actions */
  14873. p = mrval[maclvl+1]; /* If OK set return val */
  14874. if (p == NULL) p = "";
  14875. }
  14876. } else { /* Can't push any more */
  14877. debug(F101,"zzstring pushed too deep","",depth);
  14878. printf(
  14879. "\n?Internal error: zzstring stack overflow\n"
  14880. );
  14881. while (cmpop() > -1);
  14882. p = "";
  14883. }
  14884. }
  14885. }
  14886. #endif /* NOSPL */
  14887. }
  14888. break;
  14889. }
  14890. #endif /* NOKVERBS */
  14891. default: /* Maybe it's a backslash code */
  14892. y = xxesc(&s); /* Go interpret it */
  14893. if (y < 0) { /* Upon failure */
  14894. *new++ = (char) x; /* Just quote the next character */
  14895. s += 2; /* Move past the pair */
  14896. n2 -= 2;
  14897. if (n2 < 0) {
  14898. debug(F101,"zzstring overflow 5","",depth);
  14899. #ifdef DVNAMBUF
  14900. if (vnambuf) free(vnambuf);
  14901. #endif /* DVNAMBUF */
  14902. return(-1);
  14903. }
  14904. continue; /* and go back for more */
  14905. } else {
  14906. *new++ = (char) y; /* else deposit interpreted value */
  14907. if (--n2 < 0) {
  14908. debug(F101,"zzstring overflow 6","",depth);
  14909. #ifdef DVNAMBUF
  14910. if (vnambuf) free(vnambuf);
  14911. #endif /* DVNAMBUF */
  14912. return(-1);
  14913. }
  14914. }
  14915. }
  14916. }
  14917. *new = NUL; /* Terminate the new string */
  14918. debug(F010,"zzstring while exit",*s2,0);
  14919. depth--; /* Adjust stack depth gauge */
  14920. *s2 = new; /* Copy results back into */
  14921. *n = n2; /* the argument addresses */
  14922. debug(F101,"zzstring ok","",depth);
  14923. #ifdef DVNAMBUF
  14924. if (vnambuf) free(vnambuf);
  14925. #endif /* DVNAMBUF */
  14926. return(0); /* and return. */
  14927. }
  14928. #endif /* NOICP */