ckuus7.c 511 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422
  1. #include "ckcsym.h"
  2. /* C K U U S 7 -- "User Interface" for C-Kermit, part 7 */
  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, 2017,
  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. */
  14. /*
  15. This file created from parts of ckuus3.c, which became too big for
  16. Mark Williams Coherent compiler to handle.
  17. */
  18. /*
  19. Definitions here supersede those from system include files.
  20. */
  21. #include "ckcdeb.h" /* Debugging & compiler things */
  22. #include "ckcasc.h" /* ASCII character symbols */
  23. #include "ckcker.h" /* Kermit application definitions */
  24. #include "ckcxla.h" /* Character set translation */
  25. #include "ckcnet.h" /* Network symbols */
  26. #include "ckuusr.h" /* User interface symbols */
  27. #include "ckucmd.h"
  28. #include "ckclib.h"
  29. #ifdef VMS
  30. #ifndef TCPSOCKET
  31. #include <errno.h>
  32. #endif /* TCPSOCKET */
  33. #endif /* VMS */
  34. #ifdef OS2
  35. #ifndef NT
  36. #define INCL_NOPM
  37. #define INCL_VIO /* Needed for ckocon.h */
  38. #define INCL_DOSMODULEMGR
  39. #include <os2.h>
  40. #undef COMMENT
  41. #else /* NT */
  42. #define APIRET ULONG
  43. #include <windows.h>
  44. #include <tapi.h>
  45. #include "cknwin.h"
  46. #include "ckntap.h"
  47. #endif /* NT */
  48. #include "ckowin.h"
  49. #include "ckocon.h"
  50. #include "ckodir.h"
  51. #ifdef OS2MOUSE
  52. #include "ckokey.h"
  53. #endif /* OS2MOUSE */
  54. #ifdef KUI
  55. #include "ikui.h"
  56. #endif /* KUI */
  57. #ifdef putchar
  58. #undef putchar
  59. #endif /* putchar */
  60. #define putchar(x) conoc(x)
  61. extern int mskkeys;
  62. extern int mskrename;
  63. #endif /* OS2 */
  64. #ifdef CK_AUTHENTICATION
  65. #include "ckuath.h"
  66. #endif /* CK_AUTHENTICATION */
  67. #ifdef CK_SSL
  68. #include "ck_ssl.h"
  69. #endif /* CK_SSL */
  70. #ifdef SSHBUILTIN
  71. #include "ckossh.h"
  72. #endif /* SSHBUILTIN */
  73. #ifdef STRATUS /* Stratus Computer, Inc. VOS */
  74. #ifdef putchar
  75. #undef putchar
  76. #endif /* putchar */
  77. #define putchar(x) conoc(x)
  78. #ifdef getchar
  79. #undef getchar
  80. #endif /* getchar */
  81. #define getchar(x) coninc(0)
  82. #endif /* STRATUS */
  83. char * slmsg = NULL;
  84. static int x, y = 0, z;
  85. static char *s;
  86. extern CHAR feol;
  87. extern int g_matchdot, hints, xcmdsrc, rcdactive;
  88. extern char * k_info_dir;
  89. #ifdef CK_LOGIN
  90. #ifdef CK_PAM
  91. int gotemptypasswd = 0; /* distinguish empty passwd from none given */
  92. #endif /* CK_PAM */
  93. #endif /* CK_LOGIN */
  94. #ifndef NOSPL
  95. extern int nmac;
  96. extern struct mtab *mactab;
  97. #endif /* NOSPL */
  98. #ifndef NOXFER
  99. #ifdef CK_SPEED
  100. extern short ctlp[]; /* Control-char prefixing table */
  101. #endif /* CK_SPEED */
  102. #ifdef PIPESEND
  103. extern char * sndfilter, * g_sfilter;
  104. extern char * rcvfilter, * g_rfilter;
  105. #endif /* PIPESEND */
  106. extern char * snd_move;
  107. extern char * snd_rename;
  108. extern char * g_snd_move;
  109. extern char * g_snd_rename;
  110. extern char * rcv_move;
  111. extern char * rcv_rename;
  112. extern char * g_rcv_move;
  113. extern char * g_rcv_rename;
  114. #ifdef PATTERNS
  115. extern char *binpatterns[], *txtpatterns[];
  116. extern int patterns;
  117. #endif /* PATTERNS */
  118. extern char * remdest;
  119. #ifdef CK_TMPDIR
  120. char * dldir = NULL;
  121. #endif /* CK_TMPDIR */
  122. extern struct ck_p ptab[];
  123. extern int protocol, remfile, rempipe, remappd, reliable, xreliable, fmask,
  124. fncnv, frecl, maxrps, wslotr, bigsbsiz, bigrbsiz, urpsiz, rpsiz, spsiz,
  125. bctr, npad, timef, timint, spsizr, spsizf, maxsps, spmax, nfils, displa,
  126. atcapr, pkttim, rtimo, fncact, mypadn, fdispla, f_save, pktpaus, setreliable,
  127. fnrpath, fnspath, atenci, atenco, atdati, atdato, atleni, atleno, atblki,
  128. atblko, attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  129. extern int stathack;
  130. extern int atfrmi, atfrmo;
  131. #ifdef STRATUS
  132. extern int atcrei, atcreo, atacti, atacto;
  133. #endif /* STRATUS */
  134. #ifdef CK_PERMS
  135. extern int atlpri, atlpro, atgpri, atgpro;
  136. #endif /* CK_PERMS */
  137. extern CHAR
  138. sstate, eol, seol, stchr, mystch, mypadc, padch, ctlq, myctlq;
  139. #ifdef IKSD
  140. extern int inserver;
  141. #ifdef IKSDCONF
  142. extern int iksdcf;
  143. #endif /* IKSDCONF */
  144. #endif /* IKSD */
  145. extern char *cmarg, *cmarg2;
  146. #ifndef NOFRILLS
  147. extern char optbuf[]; /* Buffer for MAIL or PRINT options */
  148. extern int rprintf; /* REMOTE PRINT flag */
  149. #endif /* NOFRILLS */
  150. #endif /* NOXFER */
  151. #ifdef CK_TRIGGER
  152. extern char * tt_trigger[];
  153. #endif /* CK_TRIGGER */
  154. extern int tcs_transp;
  155. #ifdef PCTERM
  156. extern int tt_pcterm;
  157. #endif /* PCTERM */
  158. #ifdef NT
  159. extern int tt_vtnt;
  160. #endif /* NT */
  161. #ifdef SSHBUILTIN
  162. int sl_ssh_xfw = 0;
  163. int sl_ssh_xfw_saved = 0;
  164. int sl_ssh_ver = 0;
  165. int sl_ssh_ver_saved = 0;
  166. #endif /* SSHBUILTIN */
  167. #ifdef CK_AUTHENTICATION
  168. extern int auth_type_user[];
  169. int sl_auth_type_user[AUTHTYPLSTSZ] = {AUTHTYPE_NULL, AUTHTYPE_NULL};
  170. int sl_auth_saved = 0;
  171. int sl_topt_a_su = 0;
  172. int sl_topt_a_s_saved = 0;
  173. int sl_topt_a_cm = 0;
  174. int sl_topt_a_c_saved = 0;
  175. #endif /* CK_AUTHENTICATION */
  176. #ifdef CK_ENCRYPTION
  177. extern int cx_type;
  178. int sl_cx_type = 0;
  179. int sl_cx_saved = 0;
  180. int sl_topt_e_su = 0;
  181. int sl_topt_e_sm = 0;
  182. int sl_topt_e_s_saved = 0;
  183. int sl_topt_e_cu = 0;
  184. int sl_topt_e_cm = 0;
  185. int sl_topt_e_c_saved = 0;
  186. #endif /* CK_ENCRYPTION */
  187. extern char uidbuf[];
  188. static int uidflag = 0;
  189. char sl_uidbuf[UIDBUFLEN] = { NUL, NUL };
  190. int sl_uid_saved = 0;
  191. #ifdef TNCODE
  192. int sl_tn_wait = 0;
  193. int sl_tn_saved = 0;
  194. #endif /* TNCODE */
  195. #ifdef TNCODE
  196. extern int tn_wait_flg;
  197. #endif /* TNCODE */
  198. VOID
  199. slrestor() {
  200. #ifdef CK_AUTHENTICATION
  201. int x;
  202. if (sl_auth_saved) {
  203. for (x = 0; x < AUTHTYPLSTSZ; x++)
  204. auth_type_user[x] = sl_auth_type_user[x];
  205. sl_auth_saved = 0;
  206. }
  207. if (sl_topt_a_s_saved) {
  208. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_su;
  209. sl_topt_a_s_saved = 0;
  210. }
  211. if (sl_topt_a_c_saved) {
  212. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_cm;
  213. sl_topt_a_c_saved = 0;
  214. }
  215. #endif /* CK_AUTHENTICATION */
  216. #ifdef CK_ENCRYPTION
  217. if (sl_cx_saved) {
  218. cx_type = sl_cx_type;
  219. sl_cx_saved = 0;
  220. }
  221. if (sl_topt_e_s_saved) {
  222. TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = sl_topt_e_su;
  223. TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_sm;
  224. sl_topt_e_s_saved = 0;
  225. }
  226. if (sl_topt_e_c_saved) {
  227. TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = sl_topt_e_cu;
  228. TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_cm;
  229. sl_topt_e_c_saved = 0;
  230. }
  231. #endif /* CK_ENCRYPTION */
  232. if (sl_uid_saved) {
  233. ckstrncpy(uidbuf,sl_uidbuf,UIDBUFLEN);
  234. sl_uid_saved = 0;
  235. }
  236. #ifdef TNCODE
  237. if (sl_tn_saved) {
  238. tn_wait_flg = sl_tn_wait;
  239. sl_tn_saved = 0;
  240. }
  241. #endif /* TNCODE */
  242. #ifdef SSHBUILTIN
  243. if (sl_ssh_xfw_saved) {
  244. ssh_xfw = sl_ssh_xfw;
  245. sl_ssh_xfw_saved = 0;
  246. }
  247. if (sl_ssh_ver_saved) {
  248. ssh_ver = sl_ssh_ver;
  249. sl_ssh_ver_saved = 0;
  250. }
  251. #endif /* SSHBUILTIN */
  252. }
  253. int oldplex = -1; /* Duplex holder around network */
  254. #ifndef NOICP
  255. #ifdef LOCUS
  256. extern int locus, autolocus;
  257. #endif /* LOCUS */
  258. #ifndef NODIAL
  259. extern int dialsta;
  260. #endif /* NODIAL */
  261. /* Note: gcc -Wall wants braces around each keyword table entry. */
  262. static struct keytab psltab[] = { /* SET LINE/PORT command options */
  263. { "/connect", SL_CNX, 0 },
  264. #ifdef OS2ORVMS
  265. { "/noshare", SL_NSH, 0 },
  266. #endif /* OS2ORVMS */
  267. { "/server", SL_SRV, 0 },
  268. #ifdef OS2ORVMS
  269. { "/share", SL_SHR, 0 },
  270. #endif /* OS2ORVMS */
  271. { "", 0, 0 }
  272. };
  273. static int npsltab = sizeof(psltab)/sizeof(struct keytab) - 1;
  274. #ifdef NETCONN
  275. static struct keytab shtab[] = { /* SET HOST command options */
  276. #ifdef NETCMD
  277. /* (COMMAND is also a network type) */
  278. { "/command", SL_CMD, CM_INV },
  279. #endif /* NETCMD */
  280. { "/connect", SL_CNX, 0 },
  281. { "/network-type", SL_NET, CM_ARG },
  282. { "/nowait", SL_NOWAIT, 0 },
  283. #ifndef NOSPL
  284. #ifdef CK_AUTHENTICATION
  285. { "/password", SL_PSW, CM_ARG },
  286. #endif /* CK_AUTHENTICATION */
  287. #endif /* NOSPL */
  288. #ifdef NETCMD
  289. { "/pipe", SL_CMD, 0 },
  290. #endif /* NETCMD */
  291. #ifdef NETPTY
  292. { "/pty", SL_PTY, 0 },
  293. #endif /* NETPTY */
  294. { "/server", SL_SRV, 0 },
  295. { "/timeout", SL_TMO, CM_ARG },
  296. { "/userid", SL_UID, CM_ARG },
  297. { "/wait", SL_WAIT, 0 },
  298. { "", 0, 0 }
  299. };
  300. static int nshtab = sizeof(shtab)/sizeof(struct keytab) - 1;
  301. static struct keytab shteltab[] = { /* TELNET command options */
  302. #ifdef CK_AUTHENTICATION
  303. { "/auth", SL_AUTH, CM_ARG },
  304. #endif /* CK_AUTHENTICATION */
  305. #ifdef CK_ENCRYPTION
  306. { "/encrypt", SL_ENC, CM_ARG },
  307. #endif /* CK_ENCRYPTION */
  308. { "/nowait", SL_NOWAIT, 0 },
  309. #ifndef NOSPL
  310. #ifdef CK_AUTHENTICATION
  311. { "/password", SL_PSW, CM_ARG },
  312. #endif /* CK_AUTHENTICATION */
  313. #endif /* NOSPL */
  314. { "/timeout", SL_TMO, CM_ARG },
  315. { "/userid", SL_UID, CM_ARG },
  316. { "/wait", SL_WAIT, 0 },
  317. { "", 0 ,0 }
  318. };
  319. static int nshteltab = sizeof(shteltab)/sizeof(struct keytab) - 1;
  320. #ifdef RLOGCODE
  321. static struct keytab shrlgtab[] = { /* SET HOST RLOGIN command options */
  322. #ifdef CK_KERBEROS
  323. #ifdef CK_ENCRYPTION
  324. { "/encrypt", SL_ENC, 0 },
  325. #endif /* CK_ENCRYPTION */
  326. { "/k4", SL_KRB4, CM_INV },
  327. { "/k5", SL_KRB5, CM_INV },
  328. { "/kerberos4", SL_KRB4, 0 },
  329. { "/kerberos5", SL_KRB5, 0 },
  330. { "/kerberos_iv", SL_KRB4, CM_INV },
  331. { "/kerberos_v", SL_KRB5, CM_INV },
  332. { "/krb4", SL_KRB4, CM_INV },
  333. { "/krb5", SL_KRB5, CM_INV },
  334. #endif /* CK_KERBEROS */
  335. { "", 0 ,0 }
  336. };
  337. static int nshrlgtab = sizeof(shrlgtab)/sizeof(struct keytab)-1;
  338. #endif /* RLOGCODE */
  339. extern struct keytab netcmd[];
  340. extern int nnets;
  341. #ifndef NODIAL
  342. extern int dirline;
  343. extern int nnetdir; /* Network services directory */
  344. extern char *netdir[];
  345. _PROTOTYP( VOID ndreset, (void) );
  346. char *nh_p[MAXDNUMS + 1]; /* Network directory entry pointers */
  347. char *nh_p2[MAXDNUMS + 1]; /* Network directory entry nettype */
  348. char *nh_px[4][MAXDNUMS + 1]; /* Network-specific stuff... */
  349. #endif /* NODIAL */
  350. int nhcount = 0;
  351. int ndinited = 0;
  352. char * n_name = NULL; /* Network name pointer */
  353. #endif /* NETCONN */
  354. _PROTOTYP(int remtxt, (char **) );
  355. _PROTOTYP(VOID rmsg, (void) );
  356. _PROTOTYP(static int remcfm, (void) );
  357. extern int nopush;
  358. int mdmsav = -1; /* Save modem type around network */
  359. extern int isguest; /* Global flag for anonymous login */
  360. extern xx_strp xxstring;
  361. extern int success, binary, b_save, ckwarn, msgflg, quiet, cmask, pflag, local,
  362. nettype, escape, mdmtyp, duplex, dfloc, network, cdtimo, autoflow, tnlm,
  363. sosi, tlevel, lf_opts, backgrd, flow, debses, parity, ttnproto, ckxech,
  364. x_ifnum, cmflgs, haveline, cxtype, cxflow[], maclvl;
  365. #ifdef DCMDBUF
  366. extern struct cmdptr *cmdstk; /* The command stack itself */
  367. #else
  368. extern struct cmdptr cmdstk[]; /* The command stack itself */
  369. #endif /* DCMDBUF */
  370. extern FILE * tfile[];
  371. extern char * macp[];
  372. extern char psave[]; /* For saving & restoring prompt */
  373. extern int sprmlen, rprmlen;
  374. #ifdef OS2
  375. static struct keytab strmkeytab[] = {
  376. { "clear", 0, 0 },
  377. { "default", 1, 0 }
  378. };
  379. static int nstrmkeytab = sizeof(strmkeytab)/sizeof(struct keytab);
  380. static struct keytab strmswitab[] = {
  381. { "/literal", 0, 0 }
  382. };
  383. static int nstrmswitab = sizeof(strmswitab)/sizeof(struct keytab);
  384. static struct keytab normrev[] = {
  385. { "dark-display", 0, 0 },
  386. { "light-display", 1, 0 },
  387. { "normal", 0, 0 },
  388. { "reverse", 1, 0 }
  389. };
  390. static struct keytab prnmtab[] = {
  391. { "auto", 1, 0 },
  392. { "copy", 2, 0 },
  393. { "off", 0, 0 },
  394. { "on", 1, CM_INV }, /* Compatibility with XPRINT version */
  395. { "user", 3, 0 },
  396. { "transparent", 3, CM_INV } /* not really transparent */
  397. };
  398. static int nprnmtab = sizeof(prnmtab)/sizeof(struct keytab);
  399. extern int tt_diff_upd;
  400. #ifdef NT
  401. #define stricmp _stricmp
  402. extern int tt_attr_bug;
  403. #endif /* NT */
  404. extern int tt_rows[], tt_cols[];
  405. extern int tt_cols_usr;
  406. extern int tt_szchng[VNUM];
  407. int tt_modechg = TVC_ENA;
  408. extern int tt_url_hilite, tt_url_hilite_attr;
  409. extern struct _vtG G[4];
  410. extern int priority;
  411. extern bool send_c1;
  412. int send_c1_usr = FALSE;
  413. extern int sgrcolors;
  414. extern int marginbell, marginbellcol;
  415. extern int autoscroll, wy_autopage;
  416. extern int tt_sac;
  417. extern int dec_nrc, dec_lang, dec_kbd;
  418. #else /* OS2 */
  419. extern int tt_rows, tt_cols;
  420. #endif /* OS2 */
  421. extern int tt_escape;
  422. extern long speed;
  423. extern char *dftty;
  424. extern char *tp, *lp; /* Temporary buffer & pointers */
  425. extern char ttname[];
  426. #ifdef CK_TAPI
  427. int tttapi = 0; /* is Line TAPI? */
  428. struct keytab * tapilinetab = NULL;
  429. struct keytab * _tapilinetab = NULL;
  430. int ntapiline = 0;
  431. #endif /* CK_TAPI */
  432. #ifdef NETCONN /* Network items */
  433. #ifdef ANYX25
  434. extern int revcall, closgr, cudata, nx25;
  435. extern char udata[];
  436. extern struct keytab x25tab[];
  437. #ifndef IBMX25
  438. extern int npadx3;
  439. extern CHAR padparms[];
  440. extern struct keytab padx3tab[];
  441. #endif /* IBMX25 */
  442. #endif /* ANYX25 */
  443. #ifdef OS2
  444. extern bool ttshare;
  445. #ifndef NT
  446. extern bool ttslip,ttppp;
  447. #endif /* NT */
  448. #endif /* OS2 */
  449. #ifdef NPIPE
  450. extern char pipename[];
  451. #endif /* NPIPE */
  452. #ifdef TCPSOCKET
  453. static struct keytab tcprawtab[] = { /* SET HOST options */
  454. { "/default", NP_DEFAULT, CM_INV },
  455. #ifdef CK_AUTHENTICATION
  456. #ifdef CK_KERBEROS
  457. #ifdef RLOGCODE
  458. { "/ek4login", NP_EK4LOGIN, 0 },
  459. { "/ek5login", NP_EK5LOGIN, 0 },
  460. { "/k4login", NP_K4LOGIN, 0 },
  461. { "/k5login", NP_K5LOGIN, 0 },
  462. #endif /* RLOGCODE */
  463. #ifdef KRB5_U2U
  464. { "/k5user2user", NP_K5U2U, 0 },
  465. #endif /* KRB5_U2U */
  466. #endif /* CK_KERBEROS */
  467. #endif /* CK_AUTHENTICATION */
  468. { "/no-telnet-init", NP_NONE, 0 },
  469. { "/none", NP_NONE, CM_INV },
  470. { "/raw-socket", NP_TCPRAW, 0 },
  471. #ifdef RLOGCODE
  472. { "/rlogin", NP_RLOGIN, 0 },
  473. #endif /* RLOGCODE */
  474. #ifdef CK_SSL
  475. { "/ssl", NP_SSL, 0 },
  476. { "/ssl-raw", NP_SSL_RAW, 0 },
  477. { "/ssl-telnet", NP_SSL_TELNET, 0 },
  478. #endif /* CK_SSL */
  479. { "/telnet", NP_TELNET, 0 },
  480. #ifdef CK_SSL
  481. { "/tls", NP_TLS, 0 },
  482. { "/tls-raw", NP_TLS_RAW, 0 },
  483. { "/tls-telnet", NP_TLS_TELNET, 0 },
  484. #endif /* CK_SSL */
  485. { "", 0, 0 }
  486. };
  487. static int ntcpraw = (sizeof(tcprawtab) / sizeof(struct keytab)) - 1;
  488. #ifdef RLOGCODE
  489. _PROTOTYP( int rlog_naws, (void) );
  490. #endif /* RLOGCODE */
  491. #endif /* TCPSOCKET */
  492. #ifdef SUPERLAT
  493. extern char slat_pwd[18];
  494. #endif /* SUPERLAT */
  495. #endif /* NETCONN */
  496. #ifdef COMMENT
  497. #ifndef NOSETKEY
  498. extern KEY *keymap;
  499. #ifndef OS2
  500. #define mapkey(x) keymap[x]
  501. #endif /* OS2 */
  502. extern MACRO *macrotab;
  503. #ifndef NOKVERBS
  504. extern struct keytab kverbs[];
  505. extern int nkverbs;
  506. #endif /* NOKVERBS */
  507. #endif /* NOSETKEY */
  508. #else
  509. #ifndef NOSETKEY
  510. extern KEY *keymap;
  511. extern MACRO *macrotab;
  512. #ifndef NOKVERBS
  513. extern struct keytab kverbs[];
  514. extern int nkverbs;
  515. #endif /* NOKVERBS */
  516. #endif /* NOSETKEY */
  517. #endif /* COMMENT */
  518. #ifdef OS2 /* AUTODOWNLOAD parameters */
  519. extern int adl_kmode, adl_zmode; /* Match Packet to signal download */
  520. extern char * adl_kstr; /* KERMIT Download String */
  521. extern char * adl_zstr; /* ZMODEM Download String */
  522. extern int adl_kc0, adl_zc0; /* Process ADL C0s in emulation */
  523. #endif /* OS2 */
  524. /* Keyword tables ... */
  525. extern struct keytab onoff[], rltab[];
  526. extern int nrlt;
  527. #ifndef NOCSETS
  528. static struct keytab fdfltab[] = {
  529. { "7bit-character-set", 7, 0 },
  530. { "8bit-character-set", 8, 0 }
  531. };
  532. static int nfdflt = (sizeof(fdfltab) / sizeof(struct keytab));
  533. #endif /* NOCSETS */
  534. /* SET FILE parameters */
  535. static struct keytab filtab[] = {
  536. #ifndef NOXFER
  537. #ifdef PATTERNS
  538. { "binary-patterns", XYFIBP, 0 },
  539. #endif /* PATTERNS */
  540. { "bytesize", XYFILS, 0 },
  541. #ifndef NOCSETS
  542. { "character-set", XYFILC, 0 },
  543. #endif /* NOCSETS */
  544. { "collision", XYFILX, 0 },
  545. { "default", XYF_DFLT, 0 },
  546. { "destination", XYFILY, 0 },
  547. { "display", XYFILD, CM_INV },
  548. #ifdef CK_TMPDIR
  549. { "download-directory", XYFILG, 0 },
  550. #endif /* CK_TMPDIR */
  551. #endif /* NOXFER */
  552. { "end-of-line", XYFILA, 0 },
  553. { "eol", XYFILA, CM_INV },
  554. #ifdef CK_CTRLZ
  555. { "eof", XYFILV, 0 },
  556. #endif /* CK_CTRLZ */
  557. #ifndef NOXFER
  558. { "fastlookups", 9997, CM_INV },
  559. { "incomplete", XYFILI, 0 },
  560. #ifndef datageneral
  561. { "inspection", XYF_INSP, CM_INV },
  562. #endif /* datageneral */
  563. #ifdef CK_LABELED
  564. { "label", XYFILL, 0 },
  565. #endif /* CK_LABELED */
  566. #ifdef UNIX
  567. #ifdef DYNAMIC
  568. { "listsize", XYF_LSIZ, 0 },
  569. #endif /* DYNAMIC */
  570. #endif /* UNIX */
  571. { "names", XYFILN, 0 },
  572. #ifdef UNIX
  573. { "output", XYFILH, 0 },
  574. #endif /* UNIX */
  575. #ifdef PATTERNS
  576. { "patterns", XYFIPA, 0 },
  577. #endif /* PATTERNS */
  578. #ifdef COMMENT /* Not implemented (but see CHMOD) */
  579. { "permissions", XYF_PRM, CM_INV },
  580. { "protection", XYF_PRM, 0 },
  581. #endif /* COMMENt */
  582. #ifdef VMS
  583. { "record-length", XYFILR, 0 },
  584. #endif /* VMS */
  585. #ifndef datageneral
  586. { "scan", XYF_INSP, 0 },
  587. #endif /* datageneral */
  588. #ifdef UNIX
  589. #ifdef DYNAMIC
  590. { "stringspace", XYF_SSPA, 0 },
  591. #endif /* DYNAMIC */
  592. #endif /* UNIX */
  593. #ifdef PATTERNS
  594. { "t", XYFILT, CM_INV|CM_ABR },
  595. { "text-patterns", XYFITP, 0 },
  596. #endif /* PATTERNS */
  597. #endif /* NOXFER */
  598. { "type", XYFILT, 0 },
  599. #ifdef UNICODE
  600. { "ucs", XYFILU, 0 },
  601. #endif /* UNICODE */
  602. #ifndef NOXFER
  603. { "warning", XYFILW, CM_INV }
  604. #endif /* NOXFER */
  605. };
  606. static int nfilp = (sizeof(filtab) / sizeof(struct keytab));
  607. struct keytab pathtab[] = {
  608. { "absolute", PATH_ABS, 0 },
  609. { "none", PATH_OFF, CM_INV },
  610. { "off", PATH_OFF, 0 },
  611. { "on", PATH_ABS, CM_INV },
  612. { "relative", PATH_REL, 0 }
  613. };
  614. int npathtab = (sizeof(pathtab) / sizeof(struct keytab));
  615. struct keytab rpathtab[] = {
  616. { "absolute", PATH_ABS, 0 },
  617. { "auto", PATH_AUTO, 0 },
  618. { "none", PATH_OFF, CM_INV },
  619. { "off", PATH_OFF, 0 },
  620. { "on", PATH_ABS, CM_INV },
  621. { "relative", PATH_REL, 0 }
  622. };
  623. int nrpathtab = (sizeof(rpathtab) / sizeof(struct keytab));
  624. #ifdef CK_CTRLZ
  625. struct keytab eoftab[] = { /* EOF detection method */
  626. { "ctrl-z", 1, 0 },
  627. { "length", 0, 0 },
  628. { "noctrl-z", 0, CM_INV }
  629. };
  630. #endif /* CK_CTRLZ */
  631. struct keytab fttab[] = { /* File types for SET FILE TYPE */
  632. { "ascii", XYFT_T, CM_INV },
  633. #ifdef VMS
  634. { "b", XYFT_B, CM_INV|CM_ABR },
  635. #endif /* VMS */
  636. { "binary", XYFT_B, 0 },
  637. #ifdef VMS
  638. { "block", XYFT_I, CM_INV },
  639. { "image", XYFT_I, 0 },
  640. #endif /* VMS */
  641. #ifdef CK_LABELED
  642. { "labeled", XYFT_L, 0 },
  643. #endif /* CK_LABELED */
  644. #ifdef MAC
  645. { "macbinary", XYFT_M, 0 },
  646. #endif /* MAC */
  647. { "text", XYFT_T, 0 }
  648. };
  649. int nfttyp = (sizeof(fttab) / sizeof(struct keytab));
  650. static struct keytab rfttab[] = { /* File types for REMOTE SET FILE */
  651. { "ascii", XYFT_T, CM_INV },
  652. { "binary", XYFT_B, 0 },
  653. #ifdef VMS
  654. { "labeled", XYFT_L, 0 },
  655. #else
  656. #ifdef OS2
  657. { "labeled", XYFT_L, 0 },
  658. #endif /* OS2 */
  659. #endif /* VMS */
  660. { "text", XYFT_T, 0 }
  661. };
  662. static int nrfttyp = (sizeof(rfttab) / sizeof(struct keytab));
  663. #ifdef OS2ORUNIX
  664. #define ZOF_BLK 0
  665. #define ZOF_NBLK 1
  666. #define ZOF_BUF 2
  667. #define ZOF_NBUF 3
  668. static struct keytab zoftab[] = {
  669. { "blocking", ZOF_BLK, 0 },
  670. { "buffered", ZOF_BUF, 0 },
  671. { "nonblocking", ZOF_NBLK, 0 },
  672. { "unbuffered", ZOF_NBUF, 0 }
  673. };
  674. static int nzoftab = (sizeof(zoftab) / sizeof(struct keytab));
  675. #endif /* OS2ORUNIX */
  676. extern int query; /* Global flag for QUERY active */
  677. #ifndef NOSPL
  678. #ifndef NOXFER
  679. static struct keytab vartyp[] = { /* Variable types for REMOTE QUERY */
  680. { "global", (int) 'G', CM_INV },
  681. { "kermit", (int) 'K', 0 },
  682. { "system", (int) 'S', 0 },
  683. { "user", (int) 'G', 0 }
  684. };
  685. static int nvartyp = (sizeof(vartyp) / sizeof(struct keytab));
  686. #endif /* NOXFER */
  687. #endif /* NOSPL */
  688. #ifdef CK_TIMERS
  689. static struct keytab timotab[] = { /* Timer types */
  690. { "dynamic", 1, 0 },
  691. { "fixed", 0, 0 }
  692. };
  693. #endif /* CK_TIMERS */
  694. #ifdef DCMDBUF
  695. extern char *atxbuf, *atmbuf; /* Atom buffer */
  696. extern char *cmdbuf; /* Command buffer */
  697. extern char *line, *tmpbuf; /* Character buffers for anything */
  698. extern int *intime; /* INPUT TIMEOUT */
  699. #else /* Not DCMDBUF ... */
  700. extern char atxbuf[], atmbuf[]; /* Atom buffer */
  701. extern char cmdbuf[]; /* Command buffer */
  702. extern char line[], tmpbuf[]; /* Character buffer for anything */
  703. extern int intime[];
  704. #endif /* DCMDBUF */
  705. #ifndef NOCSETS
  706. extern struct keytab fcstab[]; /* For SET FILE CHARACTER-SET */
  707. extern struct csinfo fcsinfo[]; /* File character set info. */
  708. extern struct keytab ttcstab[];
  709. extern int nfilc, fcharset, tcharset, ntermc, tcsr, tcsl, dcset7, dcset8;
  710. #ifdef CKOUNI
  711. extern int tt_utf8;
  712. #endif /* CKOUNI */
  713. #ifdef OS2
  714. _PROTOTYP( int os2setcp, (int) );
  715. _PROTOTYP( int os2getcp, (void) );
  716. _PROTOTYP( void os2debugoff, (void) );
  717. #endif /* OS2 */
  718. #endif /* NOCSETS */
  719. extern int cmdlvl; /* Overall command level */
  720. #ifndef NOSPL
  721. #ifdef DCMDBUF
  722. extern int *inpcas; /* INPUT CASE setting on cmd stack */
  723. #else
  724. extern int inpcas[];
  725. #endif /* DCMDBUF */
  726. #endif /* NOSPL */
  727. #ifdef CK_CURSES
  728. #ifndef VMS
  729. _PROTOTYP(int tgetent,(char *, char *));
  730. #else
  731. #ifdef __DECC
  732. _PROTOTYP(int tgetent,(char *, char *));
  733. #endif /* __DECC */
  734. #endif /* VMS */
  735. #endif /* CK_CURSES */
  736. #ifndef NOXMIT
  737. #define XMITF 0 /* SET TRANSMIT values */
  738. #define XMITL 1 /* (Local to this module) */
  739. #define XMITP 2
  740. #define XMITE 3
  741. #define XMITX 4
  742. #define XMITS 5
  743. #define XMITW 6
  744. #define XMITT 7
  745. #define XMBUFL 50
  746. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  747. char xmitbuf[XMBUFL+1] = { NUL }; /* TRANSMIT eof string */
  748. struct keytab xmitab[] = { /* SET TRANSMIT */
  749. { "echo", XMITX, 0 },
  750. { "eof", XMITE, 0 },
  751. { "fill", XMITF, 0 },
  752. { "linefeed", XMITL, 0 },
  753. { "locking-shift", XMITS, 0 },
  754. { "pause", XMITW, 0 },
  755. { "prompt", XMITP, 0 },
  756. { "timeout", XMITT, 0 }
  757. };
  758. int nxmit = (sizeof(xmitab) / sizeof(struct keytab));
  759. #endif /* NOXMIT */
  760. /* For SET FILE COLLISION */
  761. /* Some of the following may be possible for some C-Kermit implementations */
  762. /* but not others. Those that are not possible for your implementation */
  763. /* should be ifdef'd out. */
  764. struct keytab colxtab[] = { /* SET FILE COLLISION options */
  765. #ifndef MAC
  766. { "append", XYFX_A, 0 }, /* append to old file */
  767. #endif /* MAC */
  768. #ifdef COMMENT
  769. { "ask", XYFX_Q, 0 }, /* ask what to do (not implemented) */
  770. #endif
  771. { "backup", XYFX_B, 0 }, /* rename old file */
  772. #ifndef MAC
  773. /* This crashes Mac Kermit. */
  774. { "discard", XYFX_D, CM_INV }, /* don't accept new file */
  775. { "no-supersede", XYFX_D, CM_INV }, /* ditto (MSK compatibility) */
  776. #endif /* MAC */
  777. { "overwrite", XYFX_X, 0 }, /* overwrite the old file */
  778. { "reject", XYFX_D, 0 }, /* (better word than discard) */
  779. { "rename", XYFX_R, 0 }, /* rename the incoming file */
  780. #ifndef MAC /* This crashes Mac Kermit. */
  781. { "update", XYFX_U, 0 }, /* replace if newer */
  782. #endif /* MAC */
  783. { "", 0, 0 }
  784. };
  785. int ncolx = (sizeof(colxtab) / sizeof(struct keytab)) - 1;
  786. static struct keytab rfiltab[] = { /* for REMOTE SET FILE */
  787. #ifndef NOCSETS
  788. { "character-set", XYFILC, 0 },
  789. #endif /* NOCSETS */
  790. { "collision", XYFILX, 0 },
  791. { "incomplete", XYFILI, 0 },
  792. { "names", XYFILN, 0 },
  793. { "record-length", XYFILR, 0 },
  794. { "type", XYFILT, 0 }
  795. };
  796. int nrfilp = (sizeof(rfiltab) / sizeof(struct keytab));
  797. struct keytab eoltab[] = { /* File eof delimiters */
  798. { "cr", XYFA_C, 0 },
  799. { "crlf", XYFA_2, 0 },
  800. { "lf", XYFA_L, 0 }
  801. };
  802. static int neoltab = (sizeof(eoltab) / sizeof(struct keytab));
  803. struct keytab fntab[] = { /* File naming */
  804. { "converted", XYFN_C, 0 },
  805. { "literal", XYFN_L, 0 },
  806. { "standard", XYFN_C, CM_INV }
  807. };
  808. int nfntab = (sizeof(fntab) / sizeof(struct keytab));
  809. #ifndef NOLOCAL
  810. /* Terminal parameters table */
  811. static struct keytab trmtab[] = {
  812. #ifdef OS2
  813. { "answerback", XYTANS, 0 },
  814. #endif /* OS2 */
  815. #ifdef CK_APC
  816. { "apc", XYTAPC, 0 },
  817. #endif /* CK_APC */
  818. #ifdef OS2
  819. { "arrow-keys", XYTARR, 0 },
  820. #endif /* OS2 */
  821. #ifdef NT
  822. { "at", XYTATTR, CM_INV|CM_ABR },
  823. { "att", XYTATTR, CM_INV|CM_ABR },
  824. { "attr", XYTATTR, CM_INV|CM_ABR },
  825. { "attr-bug", XYTATTBUG, CM_INV },
  826. #endif /* NT */
  827. #ifdef OS2
  828. { "attribute", XYTATTR, 0 },
  829. #endif /* OS2 */
  830. #ifdef CK_APC
  831. #ifdef CK_AUTODL
  832. { "autodownload", XYTAUTODL, 0, },
  833. #endif /* CK_AUTODL */
  834. #endif /* CK_APC */
  835. #ifdef OS2
  836. { "autopage", XYTAPAGE, 0 },
  837. { "autoscroll", XYTASCRL, 0 },
  838. { "bell", XYTBEL, CM_INV },
  839. #endif /* OS2 */
  840. { "bytesize", XYTBYT, 0 },
  841. #ifndef NOCSETS
  842. { "character-set", XYTCS, 0 },
  843. #endif /* NOCSETS */
  844. #ifdef OS2
  845. { "code-page", XYTCPG, 0 },
  846. { "color", XYTCOL, 0 },
  847. { "controls", XYTCTRL, 0 },
  848. #endif /* OS2 */
  849. { "cr-display", XYTCRD, 0 },
  850. #ifdef OS2
  851. { "cursor", XYTCUR, 0 },
  852. #endif /* OS2 */
  853. { "debug", XYTDEB, 0 },
  854. #ifdef OS2
  855. { "dg-unix-mode", XYTUNX, 0 },
  856. #endif /* OS2 */
  857. { "echo", XYTEC, 0 },
  858. { "escape-character", XYTESC, 0 },
  859. #ifdef OS2
  860. #ifdef PCFONTS
  861. { "font", XYTFON, 0 },
  862. #else
  863. #ifdef KUI
  864. { "font", XYTFON, 0 },
  865. #endif /* KUI */
  866. #endif /* PCFONTS */
  867. #endif /* OS2 */
  868. { "height", XYTHIG, 0 },
  869. #ifdef CKTIDLE
  870. { "idle-action", XYTIACT, 0 },
  871. { "idle-limit", XYTITMO, CM_INV },
  872. { "idle-send", XYTIDLE, CM_INV },
  873. { "idle-timeout", XYTITMO, 0 },
  874. #endif /* CKTIDLE */
  875. #ifdef OS2
  876. #ifndef NOCSETS
  877. { "kbd-follows-gl/gr", XYTKBDGL, 0 },
  878. #endif /* NOCSETS */
  879. { "key", XYTKEY, 0 },
  880. { "keyboard-mode", XYTKBMOD, 0 },
  881. { "keypad-mode", XYTKPD, 0 },
  882. #endif /* OS2 */
  883. { "lf-display", XYTLFD, 0 },
  884. #ifndef NOCSETS
  885. #ifdef OS2
  886. #ifndef KUI
  887. { "line-spacing", XYTLSP, CM_INV },
  888. { "local-character-set", XYTLCS, 0 },
  889. #else
  890. { "line-spacing", XYTLSP, 0 },
  891. { "local-character-set", XYTLCS, CM_INV },
  892. #endif /* KUI */
  893. #else
  894. { "local-character-set", XYTLCS, CM_INV },
  895. #endif /* OS2 */
  896. #endif /* NOCSETS */
  897. { "locking-shift", XYTSO, 0 },
  898. #ifdef OS2
  899. { "margin-bell", XYTMBEL, 0 },
  900. #endif /* OS2 */
  901. #ifdef OS2MOUSE
  902. { "mouse", XYTMOU, CM_INV },
  903. #endif /* OS2MOUSE */
  904. { "newline-mode", XYTNL, 0 },
  905. #ifdef OS2
  906. { "output-pacing", XYTPAC, 0 },
  907. #ifdef PCTERM
  908. { "pcterm", XYTPCTERM, 0 },
  909. #endif /* PCTERM */
  910. #endif /* OS2 */
  911. #ifdef OS2ORUNIX
  912. { "print", XYTPRN, 0 },
  913. #endif /* OS2ORUNIX */
  914. #ifndef NOCSETS
  915. #ifdef OS2
  916. { "remote-character-set", XYTRCS, 0 },
  917. #else
  918. { "remote-character-set", XYTRCS, CM_INV },
  919. #endif /* OS2 */
  920. #endif /* NOCSETS */
  921. #ifdef OS2
  922. { "roll-mode", XYTROL, 0 },
  923. { "s", XYTUPD, CM_ABR|CM_INV },
  924. { "sc", XYTUPD, CM_ABR|CM_INV },
  925. { "scr", XYTUPD, CM_ABR|CM_INV },
  926. { "scree", XYTUPD, CM_ABR|CM_INV },
  927. { "screen", XYTUPD, CM_ABR|CM_INV },
  928. { "screen-", XYTUPD, CM_ABR|CM_INV },
  929. { "screen-mode", XYTSCNM, 0 },
  930. { "screen-optimize", XYTOPTI, 0 },
  931. { "screen-update", XYTUPD, 0 },
  932. { "scrollback", XYSCRS, 0 },
  933. { "send-data", XYTSEND, 0 },
  934. { "send-end-of-block", XYTSEOB, 0 },
  935. { "sgr-colors", XYTSGRC, 0 },
  936. { "sni-ch.code", XYTSNICC, 0 },
  937. { "sni-firmware-versions", XYTSNIFV, 0 },
  938. { "sni-language", XYTVTLNG, 0 },
  939. { "sni-pagemode", XYTSNIPM, CM_INV },
  940. { "sni-scrollmode", XYTSNISM, CM_INV },
  941. { "spacing-attribute-character", XYTSAC, CM_INV },
  942. { "statusline", XYTSTAT, 0 },
  943. { "tra", XYTCTS, CM_INV|CM_ABR },
  944. { "transmit-timeout", XYTCTS, 0 },
  945. #endif /* OS2 */
  946. #ifdef OS2ORUNIX
  947. { "transparent-print", XYTPRN, CM_INV },
  948. #endif /* OS2ORUNIX */
  949. #ifdef CK_TRIGGER
  950. { "trigger", XYTRIGGER,0 },
  951. #endif /* CK_TRIGGER */
  952. #ifdef OS2
  953. { "type", XYTTYP, 0 },
  954. #else
  955. { "type", XYTTYP, CM_INV },
  956. #endif /* OS2 */
  957. #ifndef NOCSETS
  958. #ifdef UNICODE
  959. #ifdef CKOUNI
  960. { "unicode", XYTUNI, CM_INV },
  961. #endif /* CKOUNI */
  962. #endif /* UNICODE */
  963. #endif /* NOCSETS */
  964. #ifdef OS2
  965. { "unix-mode", XYTUNX, CM_INV },
  966. { "url-highlight", XYTURLHI, 0 },
  967. #ifdef NT
  968. { "video-change", XYTVCH, 0 },
  969. #endif /* NT */
  970. { "vt-language", XYTVTLNG, 0 },
  971. { "vt-nrc-mode", XYTVTNRC, 0 },
  972. #endif /* OS2 */
  973. { "width", XYTWID, 0 },
  974. #ifdef OS2
  975. { "wrap", XYTWRP, 0 },
  976. #endif /* OS2 */
  977. { "", 0, 0 }
  978. };
  979. int ntrm = (sizeof(trmtab) / sizeof(struct keytab)) - 1;
  980. #ifdef OS2
  981. struct keytab termctrl[] = { /* SET TERM CONTROLS */
  982. { "7", 7, 0 },
  983. { "8", 8, 0 }
  984. };
  985. int ntermctrl = (sizeof(termctrl) / sizeof(struct keytab));
  986. struct keytab curontab[] = { /* SET TERM CURSOR */
  987. #ifdef KUI
  988. { "noblink", 2, 0 },
  989. #else
  990. { "noblink", 2, CM_INV },
  991. #endif /* KUI */
  992. { "off", 0, 0 },
  993. { "on", 1, 0 }
  994. };
  995. int ncuron = (sizeof(curontab) / sizeof(struct keytab));
  996. struct keytab rolltab[] = { /* Set TERM Roll Options */
  997. { "insert", TTR_INSERT, 0 },
  998. { "keystrokes",TTR_KEYS, 0 },
  999. { "off", TTR_OVER, CM_INV },
  1000. { "on", TTR_INSERT, CM_INV },
  1001. { "overwrite", TTR_OVER, 0 }
  1002. };
  1003. int nroll = (sizeof(rolltab) / sizeof(struct keytab));
  1004. struct keytab rollkeytab[] = { /* Set TERM ROLL KEYSTROKES */
  1005. { "ignore", TTRK_IGN, 0 },
  1006. { "restore-and-send", TTRK_RST, 0 },
  1007. { "send", TTRK_SND, 0 }
  1008. };
  1009. int nrollkey = (sizeof(rollkeytab) / sizeof(struct keytab));
  1010. #define TT_GR_ALL 4
  1011. #define TT_GR_G0 0
  1012. #define TT_GR_G1 1
  1013. #define TT_GR_G2 2
  1014. #define TT_GR_G3 3
  1015. #define TT_GR_KBD 4
  1016. struct keytab graphsettab[] = { /* DEC VT Graphic Sets */
  1017. { "all", TT_GR_ALL, 0 },
  1018. { "g0", TT_GR_G0, 0 },
  1019. { "g1", TT_GR_G1, 0 },
  1020. { "g2", TT_GR_G2, 0 },
  1021. { "g3", TT_GR_G3, 0 },
  1022. { "keyboard", TT_GR_KBD, 0 }
  1023. };
  1024. int ngraphset = (sizeof(graphsettab) / sizeof(struct keytab));
  1025. #endif /* OS2 */
  1026. struct keytab adltab[] = { /* Autodownload Options */
  1027. { "ask", TAD_ASK, 0 },
  1028. { "error", TAD_ERR, 0 },
  1029. #ifdef OS2
  1030. { "kermit", TAD_K, 0 },
  1031. #endif /* OS2 */
  1032. { "off", TAD_OFF, 0 },
  1033. { "on", TAD_ON, 0 },
  1034. #ifdef OS2
  1035. { "zmodem", TAD_Z, 0 },
  1036. #endif /* OS2 */
  1037. { "", 0, 0 }
  1038. };
  1039. int nadltab = (sizeof(adltab) / sizeof(struct keytab)) - 1;
  1040. struct keytab adlerrtab[] = { /* Autodownload Error Options */
  1041. { "continue", 0, 0 },
  1042. { "go", 0, CM_INV },
  1043. { "stop", 1, 0 }
  1044. };
  1045. int nadlerrtab = (sizeof(adlerrtab) / sizeof(struct keytab));
  1046. #ifdef OS2
  1047. struct keytab adlxtab[] = { /* Autodownload Options */
  1048. { "c0-conflicts", TAD_X_C0, 0 },
  1049. { "detection-method", TAD_X_DETECT, 0 },
  1050. { "string", TAD_X_STR, 0 }
  1051. };
  1052. int nadlxtab = (sizeof(adlxtab) / sizeof(struct keytab));
  1053. struct keytab adldtab[] = { /* Auto-dl Detection Methods */
  1054. { "packet", ADL_PACK, 0 },
  1055. { "string", ADL_STR, 0 }
  1056. };
  1057. int nadldtab = (sizeof(adldtab) / sizeof(struct keytab));
  1058. struct keytab adlc0tab[] = { /* Auto-dl Detection Methods */
  1059. { "ignored-by-emulator", 0, 0 },
  1060. { "processed-by-emulator", 1, 0 }
  1061. };
  1062. int nadlc0tab = (sizeof(adlc0tab) / sizeof(struct keytab));
  1063. #ifndef NOCSETS
  1064. struct keytab vtlangtab[] = {
  1065. { "belgian", VTL_BELGIAN , 0 },
  1066. { "british", VTL_BRITISH , 0 },
  1067. { "canadian", VTL_CANADIAN, 0 },
  1068. { "czech", VTL_CZECH , 0 },
  1069. { "danish", VTL_DANISH , 0 },
  1070. { "dutch", VTL_DUTCH , 0 },
  1071. { "finnish", VTL_FINNISH , 0 },
  1072. { "french", VTL_FRENCH , 0 },
  1073. { "french-canadian",VTL_FR_CAN , 0 },
  1074. { "german", VTL_GERMAN , 0 },
  1075. { "greek", VTL_GREEK , 0 },
  1076. { "hebrew", VTL_HEBREW , 0 },
  1077. { "hungarian", VTL_HUNGARIA, 0 },
  1078. { "italian", VTL_ITALIAN , 0 },
  1079. { "latin-american", VTL_LATIN_AM, 0 },
  1080. { "north-american", VTL_NORTH_AM, 0 },
  1081. { "norwegian", VTL_NORWEGIA, 0 },
  1082. { "polish", VTL_POLISH , 0 },
  1083. { "portugese", VTL_PORTUGES, 0 },
  1084. { "romanian", VTL_ROMANIAN, 0 },
  1085. { "russian", VTL_RUSSIAN , 0 },
  1086. { "scs", VTL_SCS , CM_INV },
  1087. { "slovak", VTL_SLOVAK , 0 },
  1088. { "spanish", VTL_SPANISH , 0 },
  1089. { "swedish", VTL_SWEDISH , 0 },
  1090. { "swiss-french", VTL_SW_FR , 0 },
  1091. { "swiss-german", VTL_SW_GR , 0 },
  1092. { "turkish-f", VTL_TURK_F , CM_INV },
  1093. { "turkish-q", VTL_TURK_Q , CM_INV }
  1094. };
  1095. int nvtlangtab = (sizeof(vtlangtab) / sizeof(struct keytab));
  1096. #endif /* NOCSETS */
  1097. #endif /* OS2 */
  1098. struct keytab crdtab[] = { /* Carriage-return display */
  1099. { "crlf", 1, 0 },
  1100. { "normal", 0, 0 }
  1101. };
  1102. extern int tt_crd; /* Carriage-return display variable */
  1103. extern int tt_lfd; /* Linefeed display variable */
  1104. #ifdef CK_APC
  1105. extern int apcstatus, apcactive;
  1106. static struct keytab apctab[] = { /* Terminal APC parameters */
  1107. { "no-input", APC_ON|APC_NOINP,0 },
  1108. { "off", APC_OFF, 0 },
  1109. { "on", APC_ON, 0 },
  1110. { "unchecked", APC_ON|APC_UNCH, 0 },
  1111. { "unchecked-no-input", APC_ON|APC_NOINP|APC_UNCH, 0 }
  1112. };
  1113. int napctab = (sizeof(apctab) / sizeof(struct keytab));
  1114. #endif /* CK_APC */
  1115. #endif /* NOLOCAL */
  1116. extern int autodl, adl_err, adl_ask;
  1117. struct keytab beltab[] = { /* Terminal bell mode */
  1118. #ifdef OS2
  1119. { "audible", XYB_AUD, 0 },
  1120. { "none", XYB_NONE, 0 },
  1121. #else
  1122. { "audible", XYB_AUD, CM_INV },
  1123. { "none", XYB_NONE, CM_INV },
  1124. #endif /* OS2 */
  1125. #ifdef OS2
  1126. { "off", XYB_NONE, CM_INV },
  1127. { "on", XYB_AUD, CM_INV },
  1128. #else
  1129. { "off", XYB_NONE, 0 },
  1130. { "on", XYB_AUD, 0 },
  1131. #endif /* OS2 */
  1132. #ifdef OS2
  1133. { "visible", XYB_VIS, 0 },
  1134. #endif /* OS2 */
  1135. { "", 0, 0 }
  1136. };
  1137. int nbeltab = sizeof(beltab)/sizeof(struct keytab) - 1;
  1138. int tt_unicode = 1; /* Use Unicode if possible */
  1139. #ifdef CKTIDLE
  1140. int tt_idlesnd_tmo = 0; /* Idle Send Timeout, disabled */
  1141. char * tt_idlesnd_str = NULL; /* Idle Send String, none */
  1142. char * tt_idlestr = NULL;
  1143. extern int tt_idleact, tt_idlelimit;
  1144. #endif /* CKTIDLE */
  1145. #ifdef OS2
  1146. #ifndef NOLOCAL
  1147. /*
  1148. OS/2 serial communication devices.
  1149. */
  1150. struct keytab os2devtab[] = {
  1151. { "1", 1, CM_INV }, /* Invisible synonyms, like */
  1152. { "2", 2, CM_INV }, /* "set port 1" */
  1153. { "3", 3, CM_INV },
  1154. { "4", 4, CM_INV },
  1155. { "5", 5, CM_INV },
  1156. { "6", 6, CM_INV },
  1157. { "7", 7, CM_INV },
  1158. { "8", 8, CM_INV },
  1159. { "com1", 1, 0 }, /* Real device names */
  1160. { "com2", 2, 0 },
  1161. { "com3", 3, 0 },
  1162. { "com4", 4, 0 },
  1163. { "com5", 5, 0 },
  1164. { "com6", 6, 0 },
  1165. { "com7", 7, 0 },
  1166. { "com8", 8, 0 },
  1167. #ifdef OS2ONLY
  1168. { "slipcom1", 1, 0 }, /* For use with SLIP driver */
  1169. { "slipcom2", 2, 0 }, /* shared access */
  1170. { "slipcom3", 3, 0 },
  1171. { "slipcom4", 4, 0 },
  1172. { "slipcom5", 5, 0 },
  1173. { "slipcom6", 6, 0 },
  1174. { "slipcom7", 7, 0 },
  1175. { "slipcom8", 8, 0 },
  1176. { "pppcom1", 1, 0 }, /* For use with PPP driver */
  1177. { "pppcom2", 2, 0 }, /* shared access */
  1178. { "pppcom3", 3, 0 },
  1179. { "pppcom4", 4, 0 },
  1180. { "pppcom5", 5, 0 },
  1181. { "pppcom6", 6, 0 },
  1182. { "pppcom7", 7, 0 },
  1183. { "pppcom8", 8, 0 }
  1184. #endif /* OS2ONLY */
  1185. };
  1186. int nos2dev = (sizeof(os2devtab) / sizeof(struct keytab)) - 1;
  1187. #ifdef OS2ONLY
  1188. struct keytab os2ppptab[] = {
  1189. { "0", 0, CM_INV },
  1190. { "1", 1, CM_INV }, /* Invisible synonyms, like */
  1191. { "2", 2, CM_INV }, /* "set port 1" */
  1192. { "3", 3, CM_INV },
  1193. { "4", 4, CM_INV },
  1194. { "5", 5, CM_INV },
  1195. { "6", 6, CM_INV },
  1196. { "7", 7, CM_INV },
  1197. { "8", 8, CM_INV },
  1198. { "9", 9, CM_INV },
  1199. { "ppp0", 0, 0 },
  1200. { "ppp1", 1, 0 }, /* For use with PPP driver */
  1201. { "ppp2", 2, 0 }, /* shared access */
  1202. { "ppp3", 3, 0 },
  1203. { "ppp4", 4, 0 },
  1204. { "ppp5", 5, 0 },
  1205. { "ppp6", 6, 0 },
  1206. { "ppp7", 7, 0 },
  1207. { "ppp8", 8, 0 },
  1208. { "ppp9", 9, 0 }
  1209. };
  1210. int nos2ppp = (sizeof(os2ppptab) / sizeof(struct keytab));
  1211. #endif /* OS2ONLY */
  1212. /*
  1213. Terminal parameters that can be set by SET commands.
  1214. Used by the ck?con.c terminal emulator code.
  1215. For now, only used for #ifdef OS2. Should add these for Macintosh.
  1216. */
  1217. int tt_arrow = TTK_NORM; /* Arrow key mode: normal (cursor) */
  1218. int tt_keypad = TTK_NORM; /* Keypad mode: normal (numeric) */
  1219. int tt_shift_keypad = 0; /* Keypad Shift mode: Off */
  1220. int tt_wrap = 1; /* Terminal wrap, 1 = On */
  1221. int tt_type = TT_VT220; /* Terminal type, initially VT220 */
  1222. int tt_type_mode = TT_VT220; /* Terminal type set by host command */
  1223. int tt_cursor = 0; /* Terminal cursor, 0 = Underline */
  1224. int tt_cursor_usr = 0; /* Users Terminal cursor type */
  1225. int tt_cursorena_usr = 1; /* Users Terminal cursor enabled */
  1226. int tt_cursor_blink = 1; /* Terminal Cursor Blink */
  1227. int tt_answer = 0; /* Terminal answerback (disabled) */
  1228. int tt_scrsize[VNUM] = {512,512,512,1}; /* Terminal scrollback buffer size */
  1229. int tt_roll[VNUM] = {1,1,1,1}; /* Terminal roll (on) */
  1230. int tt_rkeys[VNUM] = {1,1,1,1}; /* Terminal roll keys (send) */
  1231. int tt_pacing = 0; /* Terminal output-pacing (none) */
  1232. int tt_ctstmo = 15; /* Terminal transmit-timeout */
  1233. int tt_codepage = -1; /* Terminal code-page */
  1234. int tt_update = 100; /* Terminal screen-update interval */
  1235. int tt_updmode = TTU_FAST; /* Terminal screen-update mode FAST */
  1236. extern int updmode;
  1237. #ifndef KUI
  1238. int tt_status[VNUM] = {1,1,0,0}; /* Terminal status line displayed */
  1239. int tt_status_usr[VNUM] = {1,1,0,0};
  1240. #else /* KUI */
  1241. extern CKFLOAT floatval;
  1242. CKFLOAT tt_linespacing[VNUM] = {1.0,1.0,1.0,1.0};
  1243. #ifdef K95G
  1244. int tt_status[VNUM] = {1,1,0,0}; /* Terminal status line displayed */
  1245. int tt_status_usr[VNUM] = {1,1,0,0};
  1246. #else /* K95G */
  1247. int tt_status[VNUM] = {0,0,0,0}; /* Terminal status line displayed */
  1248. int tt_status_usr[VNUM] = {0,0,0,0};
  1249. #endif /* K95G */
  1250. #endif /* KUI */
  1251. int tt_senddata = 0; /* Let host read terminal data */
  1252. extern int wy_blockend; /* Terminal Send Data EOB type */
  1253. int tt_hidattr = 1; /* Attributes are hidden */
  1254. extern unsigned char colornormal, colorselect,
  1255. colorunderline, colorstatus, colorhelp, colorborder,
  1256. colorgraphic, colordebug, colorreverse, coloritalic;
  1257. extern int trueblink, trueunderline, truereverse, trueitalic, truedim;
  1258. extern int bgi, fgi;
  1259. extern int scrninitialized[];
  1260. struct keytab audibletab[] = { /* Terminal Bell Audible mode */
  1261. { "beep", XYB_BEEP, 0 }, /* Values ORd with bell mode */
  1262. { "system-sounds", XYB_SYS, 0 }
  1263. };
  1264. int naudibletab = sizeof(audibletab)/sizeof(struct keytab);
  1265. struct keytab akmtab[] = { /* Arrow key mode */
  1266. { "application", TTK_APPL, 0 },
  1267. { "cursor", TTK_NORM, 0 }
  1268. };
  1269. struct keytab kpmtab[] = { /* Keypad mode */
  1270. { "application", TTK_APPL, 0 },
  1271. { "numeric", TTK_NORM, 0 }
  1272. };
  1273. struct keytab ttcolmodetab[] = {
  1274. { "current-color", 0, 0 },
  1275. { "default-color", 1, 0 }
  1276. };
  1277. int ncolmode = sizeof(ttcolmodetab)/sizeof(struct keytab);
  1278. #define TTCOLNOR 0
  1279. #define TTCOLREV 1
  1280. #define TTCOLUND 2
  1281. #define TTCOLSTA 3
  1282. #define TTCOLHLP 4
  1283. #define TTCOLBOR 5
  1284. #define TTCOLSEL 6
  1285. #define TTCOLDEB 7
  1286. #define TTCOLGRP 8
  1287. #define TTCOLITA 9
  1288. #define TTCOLRES 10
  1289. #define TTCOLERA 11
  1290. struct keytab ttycoltab[] = { /* Terminal Screen coloring */
  1291. { "border", TTCOLBOR, 0 }, /* Screen border color */
  1292. { "debug-terminal", TTCOLDEB, 0 }, /* Debug color */
  1293. { "erase", TTCOLERA, 0 }, /* Erase mode */
  1294. { "graphic", TTCOLGRP, 0 }, /* Graphic Color */
  1295. { "help-text", TTCOLHLP, 0 }, /* Help screens */
  1296. { "italic", TTCOLITA, 0 }, /* Italic Color */
  1297. { "normal", TTCOLNOR, CM_INV }, /* Normal screen text */
  1298. { "reset-on-esc[0m", TTCOLRES, 0 }, /* Reset on ESC [ 0 m */
  1299. { "reverse-video", TTCOLREV, 0 }, /* Reverse video */
  1300. { "status-line", TTCOLSTA, 0 }, /* Status line */
  1301. { "selection", TTCOLSEL, 0 }, /* Selection color */
  1302. { "terminal-screen", TTCOLNOR, 0 }, /* Better name than "normal" */
  1303. { "underlined-text", TTCOLUND, 0 } /* Underlined text */
  1304. };
  1305. int ncolors = (sizeof(ttycoltab) / sizeof(struct keytab));
  1306. #define TTATTNOR 0
  1307. #define TTATTBLI 1
  1308. #define TTATTREV 2
  1309. #define TTATTUND 3
  1310. #define TTATTPRO 4
  1311. #define TTATTBLD 5
  1312. #define TTATTDIM 6
  1313. #define TTATTINV 7
  1314. #define TTATTITA 8
  1315. #define TTATTDONE 9
  1316. struct keytab ttyattrtab[] = {
  1317. { "blink", TTATTBLI, 0 },
  1318. { "dim", TTATTDIM, 0 },
  1319. { "italic", TTATTITA, 0 },
  1320. { "protected", TTATTPRO, 0 },
  1321. { "reverse", TTATTREV, 0 },
  1322. { "underline", TTATTUND, 0 }
  1323. };
  1324. int nattrib = (sizeof(ttyattrtab) / sizeof(struct keytab));
  1325. struct keytab ttyprotab[] = {
  1326. { "blink", TTATTBLI, 0 },
  1327. { "bold", TTATTBLD, 0 },
  1328. { "dim", TTATTDIM, 0 },
  1329. { "done", TTATTDONE, CM_INV },
  1330. { "invisible", TTATTINV, 0 },
  1331. { "italic", TTATTITA, 0 },
  1332. { "normal", TTATTNOR, 0 },
  1333. { "reverse", TTATTREV, 0 },
  1334. { "underlined", TTATTUND, 0 }
  1335. };
  1336. int nprotect = (sizeof(ttyprotab) / sizeof(struct keytab));
  1337. struct keytab ttyseobtab[] = {
  1338. { "crlf_etx", 1, 0 },
  1339. { "us_cr", 0, 0 }
  1340. };
  1341. struct keytab ttyclrtab[] = { /* Colors */
  1342. { "black", 0, 0 },
  1343. { "blue", 1, 0 },
  1344. { "brown", 6, 0 },
  1345. { "cyan", 3, 0 },
  1346. { "darkgray", 8, CM_INV },
  1347. { "dgray", 8, 0 },
  1348. { "green", 2, 0 },
  1349. { "lblue", 9, CM_INV },
  1350. { "lcyan", 11, CM_INV },
  1351. { "lgray", 7, CM_INV },
  1352. { "lgreen", 10, CM_INV },
  1353. { "lightblue", 9, 0 },
  1354. { "lightcyan", 11, 0 },
  1355. { "lightgray", 7, 0 },
  1356. { "lightgreen", 10, 0 },
  1357. { "lightmagenta", 13, 0 },
  1358. { "lightred", 12, 0 },
  1359. { "lmagenta", 13, CM_INV },
  1360. { "lred", 12, CM_INV },
  1361. { "magenta", 5, 0 },
  1362. { "red", 4, 0 },
  1363. { "white", 15, 0 },
  1364. { "yellow", 14, 0 }
  1365. };
  1366. int nclrs = (sizeof (ttyclrtab) / sizeof (struct keytab));
  1367. struct keytab ttycurtab[] = {
  1368. { "full", TTC_BLOCK, 0 },
  1369. { "half", TTC_HALF, 0 },
  1370. { "underline", TTC_ULINE, 0 }
  1371. };
  1372. int ncursors = 3;
  1373. struct keytab ttyptab[] = {
  1374. { "aaa", TT_AAA, CM_INV }, /* AnnArbor */
  1375. { "adm3a", TT_ADM3A, 0 }, /* LSI ADM-3A */
  1376. { "adm5", TT_ADM5, 0 }, /* LSI ADM-5 */
  1377. { "aixterm", TT_AIXTERM, 0 }, /* IBM AIXterm */
  1378. { "annarbor", TT_AAA, 0 }, /* AnnArbor */
  1379. { "ansi-bbs", TT_ANSI, 0 }, /* ANSI.SYS (BBS) */
  1380. { "at386", TT_AT386, 0 }, /* Unixware ANSI */
  1381. { "avatar/0+",TT_ANSI, 0 }, /* AVATAR/0+ */
  1382. { "ba80", TT_BA80, 0 }, /* Nixdorf BA80 */
  1383. { "be", TT_BEOS, CM_INV|CM_ABR },
  1384. { "beos-ansi",TT_BEOS, CM_INV }, /* BeOS ANSI */
  1385. { "beterm", TT_BEOS, 0 }, /* BeOS Terminal (as of PR2 ) */
  1386. { "d200", TT_DG200, CM_INV|CM_ABR }, /* Data General DASHER 200 */
  1387. { "d210", TT_DG210, CM_INV|CM_ABR }, /* Data General DASHER 210 */
  1388. { "d217", TT_DG217, CM_INV|CM_ABR }, /* Data General DASHER 217 */
  1389. { "dg200", TT_DG200, 0 }, /* Data General DASHER 200 */
  1390. { "dg210", TT_DG210, 0 }, /* Data General DASHER 210 */
  1391. { "dg217", TT_DG217, 0 }, /* Data General DASHER 217 */
  1392. { "h1500", TT_HZL1500, CM_INV }, /* Hazeltine 1500 */
  1393. { "h19", TT_H19, CM_INV }, /* Heath-19 */
  1394. { "heath19", TT_H19, 0 }, /* Heath-19 */
  1395. { "hft", TT_HFT, 0 }, /* IBM High Function Terminal */
  1396. { "hp2621a", TT_HP2621, 0 }, /* HP 2621A */
  1397. { "hpterm", TT_HPTERM, 0 }, /* HP TERM */
  1398. { "hz1500", TT_HZL1500, 0 }, /* Hazeltine 1500 */
  1399. { "ibm3151", TT_IBM31, 0 }, /* IBM 3101-xx,3161 */
  1400. { "linux", TT_LINUX, 0 }, /* Linux */
  1401. { "qansi", TT_QANSI, 0 }, /* QNX ANSI */
  1402. { "qnx", TT_QNX, 0 }, /* QNX Console */
  1403. { "scoansi", TT_SCOANSI, 0 }, /* SCO ANSI */
  1404. { "sni-97801",TT_97801, 0 }, /* SNI 97801 */
  1405. { "sun", TT_SUN, 0 }, /* SUN Console */
  1406. /*
  1407. The idea of NONE is to let the console driver handle the escape sequences,
  1408. which, in theory at least, would give not only ANSI emulation, but also any
  1409. other kind of emulation that might be provided by alternative console
  1410. drivers, if any existed.
  1411. For this to work, ckocon.c would need to be modified to make higher-level
  1412. calls, like VioWrtTTY(), DosWrite(), or (simply) write(), rather than
  1413. VioWrt*Cell() and similar, and it would also have to give up its rollback
  1414. feature, and its status line and help screens would also have to be
  1415. forgotten or else done in an ANSI way.
  1416. As matters stand, we already have perfectly good ANSI emulation built in,
  1417. and there are no alternative console drivers available, so there is no point
  1418. in having a terminal type of NONE, so it is commented out. However, should
  1419. you uncomment it, it will work like a "glass tty" -- no escape sequence
  1420. interpretation at all; somewhat similar to debug mode, except without the
  1421. debugging (no highlighting of control chars or escape sequences); help
  1422. screens, status line, and rollback will still work.
  1423. */
  1424. #ifdef OS2PM
  1425. #ifdef COMMENT
  1426. { "tek4014", TT_TEK40, 0 },
  1427. #endif /* COMMENT */
  1428. #endif /* OS2PM */
  1429. { "tty", TT_NONE, 0 },
  1430. { "tvi910+", TT_TVI910, 0 },
  1431. { "tvi925", TT_TVI925, 0 },
  1432. { "tvi950", TT_TVI950, 0 },
  1433. { "vc404", TT_VC4404, 0 },
  1434. { "vc4404", TT_VC4404, CM_INV },
  1435. { "vip7809", TT_VIP7809,0 },
  1436. { "vt100", TT_VT100, 0 },
  1437. { "vt102", TT_VT102, 0 },
  1438. { "vt220", TT_VT220, 0 },
  1439. { "vt220pc", TT_VT220PC,0 },
  1440. { "vt320", TT_VT320, 0 },
  1441. { "vt320pc", TT_VT320PC,0 },
  1442. { "vt52", TT_VT52, 0 },
  1443. #ifdef NT
  1444. { "vtnt", TT_VTNT, 0 },
  1445. #else /* NT */
  1446. { "vtnt", TT_VTNT, CM_INV },
  1447. #endif /* NT */
  1448. { "wy160", TT_WY160, 0 },
  1449. { "wy30", TT_WY30, 0 },
  1450. { "wy370", TT_WY370, 0 },
  1451. { "wy50", TT_WY50, 0 },
  1452. { "wy60", TT_WY60, 0 },
  1453. { "wyse30", TT_WY30, CM_INV },
  1454. { "wyse370", TT_WY370, CM_INV },
  1455. { "wyse50", TT_WY50, CM_INV },
  1456. { "wyse60", TT_WY60, CM_INV }
  1457. };
  1458. int nttyp = (sizeof(ttyptab) / sizeof(struct keytab));
  1459. struct keytab ttkeytab[] = {
  1460. { "aaa", TT_AAA, CM_INV }, /* AnnArbor */
  1461. { "adm3a", TT_ADM3A, 0 }, /* LSI ADM-3A */
  1462. { "adm5", TT_ADM5, 0 }, /* LSI ADM-5 */
  1463. { "aixterm", TT_AIXTERM, 0 }, /* IBM AIXterm */
  1464. { "annarbor", TT_AAA, 0 }, /* AnnArbor */
  1465. { "ansi-bbs", TT_ANSI, 0 }, /* ANSI.SYS (BBS) */
  1466. { "at386", TT_AT386, 0 }, /* Unixware ANSI */
  1467. { "avatar/0+", TT_ANSI, 0 }, /* AVATAR/0+ */
  1468. { "ba80", TT_BA80, 0 }, /* Nixdorf BA80 */
  1469. { "be", TT_BEOS, CM_INV|CM_ABR },
  1470. { "beos-ansi", TT_BEOS, CM_INV }, /* BeOS ANSI */
  1471. { "beterm", TT_BEOS, 0 }, /* BeOS Terminal (DR2) */
  1472. { "d200", TT_DG200, CM_INV|CM_ABR }, /* DG DASHER 200 */
  1473. { "d210", TT_DG210, CM_INV|CM_ABR }, /* DG DASHER 210 */
  1474. { "d217", TT_DG217, CM_INV|CM_ABR }, /* DG DASHER 217 */
  1475. { "dg200", TT_DG200, 0 }, /* DG DASHER 200 */
  1476. { "dg210", TT_DG210, 0 }, /* DG DASHER 210 */
  1477. { "dg217", TT_DG217, 0 }, /* DG DASHER 217 */
  1478. { "emacs", TT_KBM_EMACS, 0 }, /* Emacs mode */
  1479. { "h19", TT_H19, CM_INV }, /* Heath-19 */
  1480. { "heath19", TT_H19, 0 }, /* Heath-19 */
  1481. { "hebrew", TT_KBM_HEBREW, 0 }, /* Hebrew mode */
  1482. { "hft", TT_HFT, 0 }, /* IBM High Function Term */
  1483. { "hp2621a", TT_HP2621, 0 }, /* HP 2621A */
  1484. { "hpterm", TT_HPTERM, 0 }, /* HP TERM */
  1485. { "hz1500", TT_HZL1500, 0 }, /* Hazeltine 1500 */
  1486. { "ibm3151", TT_IBM31, 0 }, /* IBM 3101-xx,3161 */
  1487. { "linux", TT_LINUX, 0 }, /* Linux */
  1488. { "qansi", TT_QANSI, 0 }, /* QNX ANSI */
  1489. { "qnx", TT_QNX, 0 }, /* QNX */
  1490. { "russian", TT_KBM_RUSSIAN,0 }, /* Russian mode */
  1491. { "scoansi", TT_SCOANSI, 0 }, /* SCO ANSI */
  1492. { "sni-97801", TT_97801, 0 }, /* SNI 97801 */
  1493. { "sun", TT_SUN, 0 }, /* SUN Console */
  1494. #ifdef OS2PM
  1495. #ifdef COMMENT
  1496. { "tek4014", TT_TEK40, 0 },
  1497. #endif /* COMMENT */
  1498. #endif /* OS2PM */
  1499. { "tty", TT_NONE, 0 },
  1500. { "tvi910+", TT_TVI910, 0 },
  1501. { "tvi925", TT_TVI925, 0 },
  1502. { "tvi950", TT_TVI950, 0 },
  1503. { "vc404", TT_VC4404, 0 },
  1504. { "vc4404", TT_VC4404, CM_INV },
  1505. { "vip7809", TT_VIP7809, 0 },
  1506. { "vt100", TT_VT100, 0 },
  1507. { "vt102", TT_VT102, 0 },
  1508. { "vt220", TT_VT220, 0 },
  1509. { "vt220pc", TT_VT220PC, 0 },
  1510. { "vt320", TT_VT320, 0 },
  1511. { "vt320pc", TT_VT320PC, 0 },
  1512. { "vt52", TT_VT52, 0 },
  1513. { "vtnt", TT_VTNT, CM_INV },
  1514. { "wp", TT_KBM_WP, 0 }, /* Word Perfect mode */
  1515. { "wy160", TT_WY160, 0 },
  1516. { "wy30", TT_WY30, 0 },
  1517. { "wy370", TT_WY370, 0 },
  1518. { "wy50", TT_WY50, 0 },
  1519. { "wy60", TT_WY60, 0 },
  1520. { "wyse30", TT_WY30, CM_INV },
  1521. { "wyse370", TT_WY370, CM_INV },
  1522. { "wyse50", TT_WY50, CM_INV },
  1523. { "wyse60", TT_WY60, CM_INV }
  1524. };
  1525. int nttkey = (sizeof(ttkeytab) / sizeof(struct keytab));
  1526. #ifndef NOSETKEY
  1527. struct keytab kbmodtab[] = {
  1528. { "emacs", KBM_EM, 0 },
  1529. { "english", KBM_EN, CM_INV },
  1530. { "hebrew", KBM_HE, 0 },
  1531. { "normal", KBM_EN, 0 },
  1532. { "none", KBM_EN, CM_INV },
  1533. { "russian", KBM_RU, 0 },
  1534. { "wp", KBM_WP, 0 }
  1535. };
  1536. int nkbmodtab = (sizeof(kbmodtab) / sizeof(struct keytab));
  1537. #endif /* NOSETKEY */
  1538. #endif /* NOLOCAL */
  1539. int tt_inpacing = 0; /* input-pacing (none) */
  1540. struct keytab prtytab[] = { /* OS/2 Priority Levels */
  1541. { "foreground-server", XYP_SRV, 0 },
  1542. { "idle", XYP_IDLE, CM_INV },
  1543. { "regular", XYP_REG, 0 },
  1544. { "time-critical", XYP_RTP, 0 }
  1545. };
  1546. int nprty = (sizeof(prtytab) / sizeof(struct keytab));
  1547. #endif /* OS2 */
  1548. #ifdef NT
  1549. struct keytab win95tab[] = { /* Win95 work-arounds */
  1550. { "8.3-filenames", XYW8_3, 0 },
  1551. { "alt-gr", XYWAGR, 0 },
  1552. { "horizontal-scan-line-substitutions", XYWHSL, 0 },
  1553. { "keyboard-translation", XYWKEY, 0 },
  1554. { "lucida-substitutions", XYWLUC, 0 },
  1555. { "overlapped-io", XYWOIO, 0 },
  1556. { "popups", XYWPOPUP, 0 },
  1557. { "select-bug", XYWSELECT, 0 }
  1558. };
  1559. int nwin95 = (sizeof(win95tab) / sizeof(struct keytab));
  1560. #endif /* NT */
  1561. #ifdef OS2MOUSE
  1562. extern int wideresult;
  1563. int tt_mouse = 1; /* Terminal mouse on/off */
  1564. struct keytab mousetab[] = { /* Mouse items */
  1565. { "activate", XYM_ON, 0 },
  1566. { "button", XYM_BUTTON, 0 },
  1567. { "clear", XYM_CLEAR, 0 },
  1568. { "debug", XYM_DEBUG, 0 }
  1569. };
  1570. int nmtab = (sizeof(mousetab)/sizeof(struct keytab));
  1571. struct keytab mousebuttontab[] = { /* event button */
  1572. { "1", XYM_B1, 0 },
  1573. { "2", XYM_B2, 0 },
  1574. { "3", XYM_B3, 0 },
  1575. { "one", XYM_B1, CM_INV },
  1576. { "three", XYM_B3, CM_INV },
  1577. { "two", XYM_B2, CM_INV }
  1578. };
  1579. int nmbtab = (sizeof(mousebuttontab) / sizeof(struct keytab));
  1580. struct keytab mousemodtab[] = { /* event button key modifier */
  1581. { "alt", XYM_ALT, 0 },
  1582. { "alt-shift", XYM_SHIFT|XYM_ALT, 0 },
  1583. { "ctrl", XYM_CTRL, 0 },
  1584. { "ctrl-alt", XYM_CTRL|XYM_ALT, 0 },
  1585. { "ctrl-alt-shift", XYM_CTRL|XYM_SHIFT|XYM_ALT, 0 },
  1586. { "ctrl-shift", XYM_CTRL|XYM_SHIFT, 0 },
  1587. { "none", 0, 0 },
  1588. { "shift", XYM_SHIFT, 0 }
  1589. };
  1590. int nmmtab = (sizeof(mousemodtab) / sizeof(struct keytab));
  1591. struct keytab mclicktab[] = { /* event button click modifier */
  1592. { "click", XYM_C1, 0 },
  1593. { "drag", XYM_DRAG, 0 },
  1594. { "double-click", XYM_C2, 0 }
  1595. };
  1596. int nmctab = (sizeof(mclicktab) / sizeof(struct keytab));
  1597. #ifndef NOKVERBS
  1598. extern int nkverbs;
  1599. extern struct keytab kverbs[];
  1600. #endif /* NOKVERBS */
  1601. #endif /* OS2MOUSE */
  1602. /* #ifdef VMS */
  1603. struct keytab fbtab[] = { /* Binary record types for VMS */
  1604. { "fixed", XYFT_B, 0 }, /* Fixed is normal for binary */
  1605. { "undefined", XYFT_U, 0 } /* Undefined if they ask for it */
  1606. };
  1607. int nfbtyp = (sizeof(fbtab) / sizeof(struct keytab));
  1608. /* #endif */
  1609. #ifdef VMS
  1610. struct keytab lbltab[] = { /* Labeled File info */
  1611. { "acl", LBL_ACL, 0 },
  1612. { "backup-date", LBL_BCK, 0 },
  1613. { "name", LBL_NAM, 0 },
  1614. { "owner", LBL_OWN, 0 },
  1615. { "path", LBL_PTH, 0 }
  1616. };
  1617. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1618. #else
  1619. #ifdef OS2
  1620. struct keytab lbltab[] = { /* Labeled File info */
  1621. { "archive", LBL_ARC, 0 },
  1622. { "extended", LBL_EXT, 0 },
  1623. { "hidden", LBL_HID, 0 },
  1624. { "read-only", LBL_RO, 0 },
  1625. { "system", LBL_SYS, 0 }
  1626. };
  1627. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1628. #endif /* OS2 */
  1629. #endif /* VMS */
  1630. #ifdef CK_CURSES
  1631. #ifdef CK_PCT_BAR
  1632. static struct keytab fdftab[] = { /* SET FILE DISPLAY FULL options */
  1633. { "thermometer", 1, 0, },
  1634. { "no-thermometer", 0, 0 }
  1635. };
  1636. extern int thermometer;
  1637. #endif /* CK_PCT_BAR */
  1638. #endif /* CK_CURSES */
  1639. static struct keytab fdtab[] = { /* SET FILE DISPLAY options */
  1640. #ifdef MAC /* Macintosh */
  1641. { "fullscreen", XYFD_R, 0 }, /* Full-screen but not curses */
  1642. { "none", XYFD_N, 0 },
  1643. { "off", XYFD_N, CM_INV },
  1644. { "on", XYFD_R, CM_INV },
  1645. { "quiet", XYFD_N, CM_INV },
  1646. #else /* Not Mac */
  1647. { "brief", XYFD_B, 0 }, /* Brief */
  1648. { "crt", XYFD_S, 0 }, /* CRT display */
  1649. #ifdef CK_CURSES
  1650. #ifdef COMMENT
  1651. { "curses", XYFD_C, CM_INV }, /* Full-screen, curses */
  1652. #endif /* COMMENT */
  1653. { "fullscreen", XYFD_C, 0 }, /* Full-screen, whatever the method */
  1654. #endif /* CK_CURSES */
  1655. #ifdef KUI
  1656. { "gui", XYFD_G, 0 }, /* GUI */
  1657. #endif /* KUI */
  1658. { "none", XYFD_N, 0 }, /* No display */
  1659. { "off", XYFD_N, CM_INV }, /* Ditto */
  1660. { "on", XYFD_R, CM_INV }, /* On = Serial */
  1661. { "quiet", XYFD_N, CM_INV }, /* No display */
  1662. { "serial", XYFD_R, 0 }, /* Serial */
  1663. #endif /* MAC */
  1664. { "", 0, 0 }
  1665. };
  1666. int nfdtab = (sizeof(fdtab) / sizeof(struct keytab)) - 1;
  1667. struct keytab rsrtab[] = { /* For REMOTE SET RECEIVE */
  1668. { "packet-length", XYLEN, 0 },
  1669. { "timeout", XYTIMO, 0 }
  1670. };
  1671. int nrsrtab = (sizeof(rsrtab) / sizeof(struct keytab));
  1672. /* Send/Receive Parameters */
  1673. struct keytab srtab[] = {
  1674. { "backup", XYBUP, 0 },
  1675. #ifndef NOCSETS
  1676. { "character-set-selection", XYCSET, 0 },
  1677. #endif /* NOCSETS */
  1678. { "control-prefix", XYQCTL, 0 },
  1679. #ifdef CKXXCHAR
  1680. { "double-character", XYDBL, 0 },
  1681. #endif /* CKXXCHAR */
  1682. { "end-of-packet", XYEOL, 0 },
  1683. #ifdef PIPESEND
  1684. { "filter", XYFLTR, 0 },
  1685. #endif /* PIPESEND */
  1686. #ifdef CKXXCHAR
  1687. { "ignore-character", XYIGN, 0 },
  1688. #endif /* CKXXCHAR */
  1689. { "i-packets", 993, 0 },
  1690. { "move-to", XYMOVE, 0 },
  1691. { "negotiation-string-max-length", XYINIL, CM_INV },
  1692. { "packet-length", XYLEN, 0 },
  1693. { "pad-character", XYPADC, 0 },
  1694. { "padding", XYNPAD, 0 },
  1695. { "pathnames", XYFPATH, 0 },
  1696. { "pause", XYPAUS, 0 },
  1697. #ifdef CK_PERMS
  1698. { "permissions", 994, 0}, /* 206 */
  1699. #endif /* CK_PERMS */
  1700. { "quote", XYQCTL, CM_INV }, /* = CONTROL-PREFIX */
  1701. { "rename-to", XYRENAME, 0 },
  1702. { "start-of-packet", XYMARK, 0 },
  1703. { "timeout", XYTIMO, 0 },
  1704. #ifdef VMS
  1705. { "version-numbers", 887, 0 }, /* VMS version numbers */
  1706. #endif /* VMS */
  1707. { "", 0, 0 }
  1708. };
  1709. int nsrtab = (sizeof(srtab) / sizeof(struct keytab)) - 1;
  1710. #ifdef UNICODE
  1711. #define UCS_BOM 1
  1712. #define UCS_BYT 2
  1713. static struct keytab ucstab[] = {
  1714. { "bom", UCS_BOM, 0 },
  1715. { "byte-order", UCS_BYT, 0 },
  1716. { "", 0, 0 }
  1717. };
  1718. int nucstab = (sizeof(ucstab) / sizeof(struct keytab)) - 1;
  1719. static struct keytab botab[] = {
  1720. { "big-endian", 0, 0 },
  1721. { "little-endian", 1, 0 }
  1722. };
  1723. static int nbotab = 2;
  1724. #endif /* UNICODE */
  1725. /* REMOTE SET */
  1726. struct keytab rmstab[] = {
  1727. { "attributes", XYATTR, 0 },
  1728. { "block-check", XYCHKT, 0 },
  1729. { "file", XYFILE, 0 },
  1730. { "incomplete", XYIFD, CM_INV }, /* = REMOTE SET FILE INCOMPLETE */
  1731. { "match", XYMATCH,0 },
  1732. { "receive", XYRECV, 0 },
  1733. { "retry", XYRETR, 0 },
  1734. { "server", XYSERV, 0 },
  1735. { "transfer", XYXFER, 0 },
  1736. { "window", XYWIND, 0 },
  1737. { "xfer", XYXFER, CM_INV }
  1738. };
  1739. int nrms = (sizeof(rmstab) / sizeof(struct keytab));
  1740. struct keytab attrtab[] = {
  1741. #ifdef STRATUS
  1742. { "account", AT_ACCT, 0 },
  1743. #endif /* STRATUS */
  1744. { "all", AT_XALL, 0 },
  1745. #ifdef COMMENT
  1746. { "blocksize", AT_BLKS, 0 }, /* (not used) */
  1747. #endif /* COMMENT */
  1748. #ifndef NOCSETS
  1749. { "character-set", AT_ENCO, 0 },
  1750. #endif /* NOCSETS */
  1751. #ifdef STRATUS
  1752. { "creator", AT_CREA, 0 },
  1753. #endif /* STRATUS */
  1754. { "date", AT_DATE, 0 },
  1755. { "disposition", AT_DISP, 0 },
  1756. { "encoding", AT_ENCO, CM_INV },
  1757. { "format", AT_RECF, CM_INV },
  1758. { "length", AT_LENK, 0 },
  1759. { "off", AT_ALLN, 0 },
  1760. { "on", AT_ALLY, 0 },
  1761. #ifdef COMMENT
  1762. { "os-specific", AT_SYSP, 0 }, /* (not used by UNIX or VMS) */
  1763. #endif /* COMMENT */
  1764. #ifdef CK_PERMS
  1765. { "protection", AT_LPRO, 0 },
  1766. { "permissions", AT_LPRO, CM_INV },
  1767. #endif /* CK_PERMS */
  1768. { "record-format", AT_RECF, 0 },
  1769. { "system-id", AT_SYSI, 0 },
  1770. { "type", AT_FTYP, 0 }
  1771. };
  1772. int natr = (sizeof(attrtab) / sizeof(struct keytab)); /* how many attributes */
  1773. #ifdef CKTIDLE
  1774. struct keytab idlacts[] = {
  1775. { "exit", IDLE_EXIT, 0 },
  1776. { "hangup", IDLE_HANG, 0 },
  1777. { "output", IDLE_OUT, 0 },
  1778. { "return", IDLE_RET, 0 },
  1779. #ifdef TNCODE
  1780. { "telnet-nop", IDLE_TNOP, 0 },
  1781. { "telnet-ayt", IDLE_TAYT, 0 },
  1782. #endif /* TNCODE */
  1783. { "", 0, 0 }
  1784. };
  1785. int nidlacts = (sizeof(idlacts) / sizeof(struct keytab)) - 1;
  1786. #endif /* CKTIDLE */
  1787. #ifndef NOSPL
  1788. extern int indef, inecho, insilence, inbufsize, inautodl, inintr;
  1789. #ifdef CKFLOAT
  1790. extern CKFLOAT inscale;
  1791. #endif /* CKFLOAT */
  1792. extern char * inpbuf, * inpbp;
  1793. #ifdef OS2
  1794. extern int interm;
  1795. #endif /* OS2 */
  1796. struct keytab inptab[] = { /* SET INPUT parameters */
  1797. #ifdef CK_AUTODL
  1798. { "autodownload", IN_ADL, 0 },
  1799. #endif /* CK_AUTODL */
  1800. { "buffer-length", IN_BUF, 0 },
  1801. { "cancellation", IN_CAN, 0 },
  1802. { "case", IN_CAS, 0 },
  1803. { "default-timeout", IN_DEF, CM_INV }, /* There is no default timeout */
  1804. { "echo", IN_ECH, 0 },
  1805. #ifdef OS2
  1806. { "pacing", IN_PAC, CM_INV },
  1807. #endif /* OS2 */
  1808. { "scale-factor", IN_SCA, 0 },
  1809. { "silence", IN_SIL, 0 },
  1810. #ifdef OS2
  1811. { "terminal", IN_TRM, 0 },
  1812. #endif /* OS2 */
  1813. { "timeout-action", IN_TIM, 0 }
  1814. };
  1815. int ninp = (sizeof(inptab) / sizeof(struct keytab));
  1816. struct keytab intimt[] = { /* SET INPUT TIMEOUT parameters */
  1817. { "proceed", 0, 0 }, /* 0 = proceed */
  1818. { "quit", 1, 0 } /* 1 = quit */
  1819. };
  1820. struct keytab incast[] = { /* SET INPUT CASE parameters */
  1821. { "ignore", 0, 0 }, /* 0 = ignore */
  1822. { "observe", 1, 0 } /* 1 = observe */
  1823. };
  1824. #endif /* NOSPL */
  1825. struct keytab nabltab[] = { /* For any command that needs */
  1826. { "disabled", 0, 0 },
  1827. { "enabled", 1, 0 },
  1828. { "off", 0, CM_INV }, /* these keywords... */
  1829. { "on", 1, CM_INV }
  1830. };
  1831. int nnabltab = sizeof(nabltab) / sizeof(struct keytab);
  1832. #ifdef OS2
  1833. struct keytab tvctab[] = { /* SET TERM VIDEO-CHANGE */
  1834. { "disabled", TVC_DIS, 0 },
  1835. { "enabled", TVC_ENA, 0 },
  1836. #ifdef NT
  1837. { "win95-safe", TVC_W95, 0 },
  1838. #endif /* NT */
  1839. { "", 0, 0 }
  1840. };
  1841. int ntvctab = (sizeof(tvctab) / sizeof(struct keytab)) - 1;
  1842. struct keytab msktab[] = { /* SET MS-DOS KERMIT compatibilities */
  1843. #ifdef COMMENT
  1844. { "color", MSK_COLOR, 0 },
  1845. #endif /* COMMENT */
  1846. { "file-renaming", MSK_REN, 0 },
  1847. { "keycodes", MSK_KEYS, 0 }
  1848. };
  1849. int nmsk = (sizeof(msktab) / sizeof(struct keytab));
  1850. struct keytab scrnupd[] = { /* SET TERMINAL SCREEN-UPDATE */
  1851. { "fast", TTU_FAST, 0 },
  1852. { "smooth", TTU_SMOOTH, 0 }
  1853. };
  1854. int nscrnupd = (sizeof(scrnupd) / sizeof(struct keytab));
  1855. #ifdef PCFONTS
  1856. /* This definition of the term_font[] table is only for */
  1857. /* the OS/2 Full Screen Session and is not used on Windows */
  1858. struct keytab term_font[] = { /* SET TERMINAL FONT */
  1859. #ifdef COMMENT
  1860. { "cp111", TTF_111, 0 },
  1861. { "cp112", TTF_112, 0 },
  1862. { "cp113", TTF_113, 0 },
  1863. #endif /* COMMENT */
  1864. { "cp437", TTF_437, 0 },
  1865. { "cp850", TTF_850, 0 },
  1866. #ifdef COMMENT
  1867. { "cp851", TTF_851, 0 },
  1868. #endif /* COMMENT */
  1869. { "cp852", TTF_852, 0 },
  1870. #ifdef COMMENT
  1871. { "cp853", TTF_853, 0 },
  1872. { "cp860", TTF_860, 0 },
  1873. { "cp861", TTF_861, 0 },
  1874. #endif /* COMMENT */
  1875. { "cp862", TTF_862, 0 },
  1876. #ifdef COMMENT
  1877. { "cp863", TTF_863, 0 },
  1878. { "cp864", TTF_864, 0 },
  1879. { "cp865", TTF_865, 0 },
  1880. #endif /* COMMENT */
  1881. { "cp866", TTF_866, 0 },
  1882. #ifdef COMMENT
  1883. { "cp880", TTF_880, 0 },
  1884. { "cp881", TTF_881, 0 },
  1885. { "cp882", TTF_882, 0 },
  1886. { "cp883", TTF_883, 0 },
  1887. { "cp884", TTF_884, 0 },
  1888. { "cp885", TTF_885, 0 },
  1889. #endif /* COMMENT */
  1890. { "default",TTF_ROM,0 }
  1891. };
  1892. int ntermfont = (sizeof(term_font) / sizeof(struct keytab));
  1893. int tt_font = TTF_ROM; /* Terminal screen font */
  1894. #else /* PCFONTS */
  1895. #ifdef NT
  1896. #ifdef KUI
  1897. struct keytab * term_font = NULL;
  1898. struct keytab * _term_font = NULL;
  1899. char * tt_facename = NULL;
  1900. int ntermfont = 0;
  1901. int tt_font = 0;
  1902. int tt_font_size = 0;
  1903. #endif /* KUI */
  1904. #endif /* NT */
  1905. #endif /* PCFONTS */
  1906. struct keytab anbktab[] = { /* For any command that needs */
  1907. { "message", 2, 0 }, /* these keywords... */
  1908. { "off", 0, 0 },
  1909. { "on", 1, 0 },
  1910. { "unsafe-messag0", 99, CM_INV },
  1911. { "unsafe-message", 3, CM_INV }
  1912. };
  1913. int nansbk = (sizeof(anbktab) / sizeof(struct keytab));
  1914. int win95_popup = 1;
  1915. #ifdef NT
  1916. #ifdef KUI
  1917. int win95lucida = 0;
  1918. int win95hsl = 1;
  1919. #else /* KUI */
  1920. int win95lucida = 1;
  1921. int win95hsl = 1;
  1922. #endif /* KUI */
  1923. #else /* NT */
  1924. int win95lucida = 0;
  1925. int win95hsl = 1;
  1926. #endif /* NT */
  1927. #ifdef NT
  1928. int win95altgr = 0;
  1929. extern int win95selectbug;
  1930. extern int win95_8_3;
  1931. #ifdef COMMENT
  1932. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);
  1933. extern struct keytab tcstab[];
  1934. extern int ntcs;
  1935. #endif /* COMMENT */
  1936. extern int maxow, maxow_usr; owwait; /* Overlapped I/O variables */
  1937. #endif /* NT */
  1938. #endif /* OS2 */
  1939. /* The following routines broken out of doprm() to give compilers a break. */
  1940. /* S E T O N -- Parse on/off (default on), set parameter to result */
  1941. int
  1942. seton(prm) int *prm; {
  1943. int x, y;
  1944. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  1945. if ((x = cmcfm()) < 0) return(x);
  1946. *prm = y;
  1947. return(1);
  1948. }
  1949. /* S E T O N A U T O -- Parse on/off/auto (default auto) & set result */
  1950. struct keytab onoffaut[] = {
  1951. { "auto", SET_AUTO, 0 }, /* 2 */
  1952. { "off", SET_OFF, 0 }, /* 0 */
  1953. { "on", SET_ON, 0 } /* 1 */
  1954. };
  1955. int
  1956. setonaut(prm) int *prm; {
  1957. int x, y;
  1958. if ((y = cmkey(onoffaut,3,"","auto",xxstring)) < 0) return(y);
  1959. if ((x = cmcfm()) < 0) return(x);
  1960. *prm = y;
  1961. return(1);
  1962. }
  1963. /* S E T N U M -- Set parameter to result of cmnum() parse. */
  1964. /*
  1965. Call with pointer to integer variable to be set,
  1966. x = number from cnum parse, y = return code from cmnum,
  1967. max = maximum value to accept, -1 if no maximum.
  1968. Returns -9 on failure, after printing a message, or 1 on success.
  1969. */
  1970. int
  1971. setnum(prm,x,y,max) int x, y, *prm, max; {
  1972. debug(F101,"setnum","",y);
  1973. if (y == -3) {
  1974. printf("\n?Value required\n");
  1975. return(-9);
  1976. }
  1977. if (y == -2) {
  1978. printf("%s?Not a number: %s\n",cmflgs == 1 ? "" : "\n", atxbuf);
  1979. return(-9);
  1980. }
  1981. if (y < 0) return(y);
  1982. if (max > -1 && x > max) {
  1983. printf("?Sorry, %d is the maximum\n",max);
  1984. return(-9);
  1985. }
  1986. if ((y = cmcfm()) < 0) return(y);
  1987. *prm = x;
  1988. return(1);
  1989. }
  1990. /* S E T C C -- Set parameter var to an ASCII control character value. */
  1991. /*
  1992. Parses a number, or a literal control character, or a caret (^) followed
  1993. by an ASCII character whose value is 63-95 or 97-122, then gets confirmation,
  1994. then sets the parameter to the code value of the character given. If there
  1995. are any parse errors, they are returned, otherwise on success 1 is returned.
  1996. */
  1997. int
  1998. setcc(dflt,var) char *dflt; int *var; {
  1999. int x, y;
  2000. unsigned int c;
  2001. char *hlpmsg = "Control character,\n\
  2002. numeric ASCII value,\n\
  2003. or in ^X notation,\n\
  2004. or preceded by a backslash and entered literally";
  2005. /* This is a hack to turn off complaints from expression evaluator. */
  2006. x_ifnum = 1;
  2007. y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */
  2008. x_ifnum = 0; /* Allow complaints again */
  2009. if (y < 0) { /* Parse failed */
  2010. if (y != -2) /* Reparse needed or somesuch */
  2011. return(y); /* Pass failure back up the chain */
  2012. }
  2013. /* Real control character or literal 8-bit character... */
  2014. for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */
  2015. if (atmbuf[c] == SP) atmbuf[c] = NUL;
  2016. if (y < 0) { /* It was not a number */
  2017. if (((c = atmbuf[0])) && !atmbuf[1]) { /* Literal character? */
  2018. c &= 0xff;
  2019. if (((c > 31) && (c < 127)) || (c > 255)) {
  2020. printf("\n?%d: Out of range - must be 0-31 or 127-255\n",c);
  2021. return(-9);
  2022. } else {
  2023. if ((y = cmcfm()) < 0) /* Confirm */
  2024. return(y);
  2025. *var = c; /* Set the variable */
  2026. return(1);
  2027. }
  2028. } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */
  2029. c = atmbuf[1];
  2030. if (islower((char) c)) /* Uppercase lowercase letters */
  2031. c = toupper(c);
  2032. if (c > 62 && c < 96) { /* Check range */
  2033. if ((y = cmcfm()) < 0)
  2034. return(y);
  2035. *var = ctl(c); /* OK */
  2036. return(1);
  2037. } else {
  2038. printf("?Not a control character - %s\n", atmbuf);
  2039. return(-9);
  2040. }
  2041. } else { /* Something illegal was typed */
  2042. printf("?Not valid here - '%s'\n", atmbuf);
  2043. return(-9);
  2044. }
  2045. }
  2046. if (((x > 31) && (x < 127)) || (x > 255)) { /* They typed a number */
  2047. printf("\n?%d: Out of range - must be 0-31 or 127-255\n",x);
  2048. return(-9);
  2049. }
  2050. if ((y = cmcfm()) < 0) /* In range, confirm */
  2051. return(y);
  2052. *var = x; /* Set variable */
  2053. return(1);
  2054. }
  2055. #ifndef NOSPL /* The SORT command... */
  2056. static struct keytab srtswtab[] = { /* SORT command switches */
  2057. { "/case", SRT_CAS, CM_ARG },
  2058. { "/key", SRT_KEY, CM_ARG },
  2059. { "/numeric", SRT_NUM, 0 },
  2060. { "/range", SRT_RNG, CM_ARG },
  2061. { "/reverse", SRT_REV, 0 }
  2062. };
  2063. static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);
  2064. extern char **a_ptr[]; /* Array pointers */
  2065. extern int a_dim[]; /* Array dimensions */
  2066. int
  2067. dosort() { /* Do the SORT command */
  2068. char c, *p = NULL, ** ap, ** xp = NULL;
  2069. struct FDB sw, fl, cm;
  2070. int hi, lo;
  2071. int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0;
  2072. int getval = 0, range[2], confirmed = 0;
  2073. cmfdbi(&sw, /* First FDB - command switches */
  2074. _CMKEY, /* fcode */
  2075. "Array name or switch",
  2076. "", /* default */
  2077. "", /* addtl string data */
  2078. nsrtswtab, /* addtl numeric data 1: tbl size */
  2079. 4, /* addtl numeric data 2: 4 = cmswi */
  2080. NULL, /* Processing function */
  2081. srtswtab, /* Keyword table */
  2082. &fl /* Pointer to next FDB */
  2083. );
  2084. cmfdbi(&fl, /* Anything that doesn't match */
  2085. _CMFLD, /* fcode */
  2086. "Array name", /* hlpmsg */
  2087. "", /* default */
  2088. "", /* addtl string data */
  2089. 0, /* addtl numeric data 1 */
  2090. 0, /* addtl numeric data 2 */
  2091. NULL,
  2092. NULL,
  2093. &cm
  2094. );
  2095. cmfdbi(&cm, /* Or premature confirmation */
  2096. _CMCFM, /* fcode */
  2097. "", /* hlpmsg */
  2098. "", /* default */
  2099. "", /* addtl string data */
  2100. 0, /* addtl numeric data 1 */
  2101. 0, /* addtl numeric data 2 */
  2102. NULL,
  2103. NULL,
  2104. NULL
  2105. );
  2106. range[0] = -1;
  2107. range[1] = -1;
  2108. while (1) { /* Parse 0 or more switches */
  2109. x = cmfdb(&sw);
  2110. if (x < 0)
  2111. return(x);
  2112. if (cmresult.fcode != _CMKEY) /* Break out if not a switch */
  2113. break;
  2114. c = cmgbrk();
  2115. getval = (c == ':' || c == '=');
  2116. if (getval && !(cmresult.kflags & CM_ARG)) {
  2117. printf("?This switch does not take arguments\n");
  2118. return(-9);
  2119. }
  2120. switch (cmresult.nresult) {
  2121. case SRT_REV:
  2122. xr = 1;
  2123. break;
  2124. case SRT_KEY:
  2125. if (getval) {
  2126. if ((y = cmnum("Column for comparison (1-based)",
  2127. "1",10,&x,xxstring)) < 0)
  2128. return(y);
  2129. xk = x - 1;
  2130. } else
  2131. xk = 0;
  2132. break;
  2133. case SRT_CAS:
  2134. if (getval) {
  2135. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  2136. return(y);
  2137. xc = y;
  2138. } else
  2139. xc = 1;
  2140. break;
  2141. case SRT_RNG: /* /RANGE */
  2142. if (getval) {
  2143. char buf[32];
  2144. char buf2[16];
  2145. int i;
  2146. char * p, * q;
  2147. if ((y = cmfld("low:high element","1",&s,NULL)) < 0)
  2148. return(y);
  2149. s = brstrip(s);
  2150. ckstrncpy(buf,s,32);
  2151. p = buf;
  2152. for (i = 0; *p && i < 2; i++) { /* Get low and high */
  2153. q = p; /* Start of this piece */
  2154. while (*p) { /* Find end of this piece */
  2155. if (*p == ':') {
  2156. *p = NUL;
  2157. p++;
  2158. break;
  2159. }
  2160. p++;
  2161. }
  2162. y = 15; /* Evaluate this piece */
  2163. s = buf2;
  2164. zzstring(q,&s,&y);
  2165. s = evalx(buf2);
  2166. if (s) if (*s) ckstrncpy(buf2,s,16);
  2167. if (!rdigits(buf2)) {
  2168. printf("?Not numeric: %s\n",buf2);
  2169. return(-9);
  2170. }
  2171. range[i] = atoi(buf2);
  2172. }
  2173. }
  2174. break;
  2175. case SRT_NUM: /* /NUMERIC */
  2176. xn = 1;
  2177. break;
  2178. default:
  2179. return(-2);
  2180. }
  2181. }
  2182. switch (cmresult.fcode) {
  2183. case _CMCFM:
  2184. confirmed = 1;
  2185. break;
  2186. case _CMFLD:
  2187. ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */
  2188. s = line;
  2189. break;
  2190. default:
  2191. printf("?Unexpected function code: %d\n",cmresult.fcode);
  2192. return(-9);
  2193. }
  2194. if (confirmed) {
  2195. printf("?Array name required\n");
  2196. return(-9);
  2197. }
  2198. ckmakmsg(tmpbuf,TMPBUFSIZ,
  2199. "Second array to sort according to ",s,NULL,NULL);
  2200. if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0)
  2201. if (x != -3)
  2202. return(x);
  2203. tmpbuf[0] = NUL;
  2204. ckstrncpy(tmpbuf,p,TMPBUFSIZ);
  2205. p = tmpbuf;
  2206. if ((x = cmcfm()) < 0) /* Get confirmation */
  2207. return(x);
  2208. x = arraybounds(s,&lo,&hi); /* Get array index & bounds */
  2209. if (x < 0) { /* Check */
  2210. printf("?Bad array name: %s\n",s);
  2211. return(-9);
  2212. }
  2213. if (lo > -1) range[0] = lo; /* Set range */
  2214. if (hi > -1) range[1] = hi;
  2215. ap = a_ptr[x]; /* Get pointer to array element list */
  2216. if (!ap) { /* Check */
  2217. printf("?Array not declared: %s\n", s);
  2218. return(-9);
  2219. }
  2220. if (range[0] < 0) /* Starting element */
  2221. range[0] = 1;
  2222. if (range[1] < 0) /* Final element */
  2223. range[1] = a_dim[x];
  2224. if (range[1] > a_dim[x]) {
  2225. printf("?range %d:%d exceeds array dimension %d\n",
  2226. range[0],range[1],a_dim[x]
  2227. );
  2228. return(-9);
  2229. }
  2230. ap += range[0];
  2231. xs = range[1] - range[0] + 1; /* Number of elements to sort */
  2232. if (xs < 1) { /* Check */
  2233. printf("?Bad range: %d:%d\n",range[0],range[1]);
  2234. return(-9);
  2235. }
  2236. if (xk < 0) xk = 0; /* Key position */
  2237. if (xr < 0) xr = 0; /* Reverse flag */
  2238. if (xn) /* Numeric flag */
  2239. xc = 2;
  2240. else if (xc < 0) /* Not numeric */
  2241. xc = inpcas[cmdlvl]; /* so alpha case option */
  2242. if (*p) { /* Parallel array given? */
  2243. y = xarray(p); /* Yes, get its index. */
  2244. if (y < 0) {
  2245. printf("?Bad array name: %s\n", p);
  2246. return(-9);
  2247. }
  2248. if (y != x) { /* If the 2 arrays are different */
  2249. xp = a_ptr[y]; /* Pointer to 2nd array element list */
  2250. if (!xp) {
  2251. printf("?Array not declared: %s\n", p);
  2252. return(-9);
  2253. }
  2254. if (a_dim[y] < range[1]) {
  2255. printf("?Array %s smaller than %s\n", p, s);
  2256. return(-9);
  2257. }
  2258. xp += range[0]; /* Set base to same as 1st array */
  2259. }
  2260. }
  2261. sh_sort(ap,xp,xs,xk,xr,xc); /* Sort the array(s) */
  2262. return(success = 1); /* Always succeeds */
  2263. }
  2264. #endif /* NOSPL */
  2265. static struct keytab purgtab[] = { /* PURGE command switches */
  2266. { "/after", PU_AFT, CM_ARG },
  2267. { "/ask", PU_ASK, 0 },
  2268. { "/before", PU_BEF, CM_ARG },
  2269. { "/delete", PU_DELE, CM_INV },
  2270. #ifdef UNIXOROSK
  2271. { "/dotfiles", PU_DOT, 0 },
  2272. #endif /* UNIXOROSK */
  2273. { "/except", PU_EXC, CM_ARG },
  2274. { "/heading", PU_HDG, 0 },
  2275. { "/keep", PU_KEEP, CM_ARG },
  2276. { "/larger-than", PU_LAR, CM_ARG },
  2277. { "/list", PU_LIST, 0 },
  2278. { "/log", PU_LIST, CM_INV },
  2279. { "/noask", PU_NASK, 0 },
  2280. { "/nodelete", PU_NODE, CM_INV },
  2281. #ifdef UNIXOROSK
  2282. { "/nodotfiles", PU_NODOT,0 },
  2283. #endif /* UNIXOROSK */
  2284. { "/noheading", PU_NOH, 0 },
  2285. { "/nol", PU_NOLI, CM_INV|CM_ABR },
  2286. { "/nolist", PU_NOLI, 0 },
  2287. { "/nolog", PU_NOLI, CM_INV },
  2288. #ifdef CK_TTGWSIZ
  2289. { "/nopage", PU_NOPA, 0 },
  2290. #endif /* CK_TTGWSIZ */
  2291. { "/not-after", PU_NAF, CM_ARG },
  2292. { "/not-before", PU_NBF, CM_ARG },
  2293. { "/not-since", PU_NAF, CM_INV|CM_ARG },
  2294. #ifdef CK_TTGWSIZ
  2295. { "/page", PU_PAGE, 0 },
  2296. #endif /* CK_TTGWSIZ */
  2297. { "/quiet", PU_QUIE, CM_INV },
  2298. #ifdef RECURSIVE
  2299. { "/recursive", PU_RECU, 0 },
  2300. #endif /* RECURSIVE */
  2301. { "/since", PU_AFT, CM_ARG|CM_INV },
  2302. { "/simulate", PU_NODE, 0 },
  2303. { "/smaller-than", PU_SMA, CM_ARG },
  2304. { "/verbose", PU_VERB, CM_INV }
  2305. };
  2306. static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);
  2307. int
  2308. bkupnum(s,i) char * s; int *i; {
  2309. int k = 0, pos = 0;
  2310. char * p = NULL, *q;
  2311. *i = pos;
  2312. if (!s) s = "";
  2313. if (!*s)
  2314. return(-1);
  2315. if ((k = strlen(s)) < 5)
  2316. return(-1);
  2317. if (s[k-1] != '~')
  2318. return(-1);
  2319. pos = k - 2;
  2320. q = s + pos;
  2321. while (q >= s && isdigit(*q)) {
  2322. p = q--;
  2323. pos--;
  2324. }
  2325. if (!p)
  2326. return(-1);
  2327. if (q < s+2)
  2328. return(-1);
  2329. if (*q != '~' || *(q-1) != '.')
  2330. return(-1);
  2331. pos--;
  2332. *i = pos;
  2333. debug(F111,"bkupnum",s+pos,pos);
  2334. return(atoi(p));
  2335. }
  2336. #ifdef CKPURGE
  2337. /* Presently only for UNIX because we need direct access to the file array. */
  2338. /* Not needed for VMS anyway, because we don't make backup files there. */
  2339. #define MAXKEEP 32 /* Biggest /KEEP: value */
  2340. static int
  2341. pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;
  2342. #ifdef CK_TTGWSIZ
  2343. static int pu_page = -1;
  2344. #else
  2345. static int pu_page = 0;
  2346. #endif /* CK_TTGWSIZ */
  2347. #ifndef NOSHOW
  2348. VOID
  2349. showpurgopts() { /* SHOW PURGE command options */
  2350. int x = 0;
  2351. extern int optlines;
  2352. prtopt(&optlines,"PURGE");
  2353. if (pu_ask > -1) {
  2354. x++;
  2355. prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK");
  2356. }
  2357. #ifdef UNIXOROSK
  2358. if (pu_dot > -1) {
  2359. x++;
  2360. prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES");
  2361. }
  2362. #endif /* UNIXOROSK */
  2363. if (pu_keep > -1) {
  2364. x++;
  2365. ckmakmsg(tmpbuf,TMPBUFSIZ,"/KEEP:",ckitoa(pu_keep),NULL,NULL);
  2366. prtopt(&optlines,tmpbuf);
  2367. }
  2368. if (pu_list > -1) {
  2369. x++;
  2370. prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST");
  2371. }
  2372. if (pu_hdg > -1) {
  2373. x++;
  2374. prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING");
  2375. }
  2376. #ifdef CK_TTGWSIZ
  2377. if (pu_page > -1) {
  2378. x++;
  2379. prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE");
  2380. }
  2381. #endif /* CK_TTGWSIZ */
  2382. if (!x) prtopt(&optlines,"(no options set)");
  2383. prtopt(&optlines,"");
  2384. }
  2385. #endif /* NOSHOW */
  2386. int
  2387. setpurgopts() { /* Set PURGE command options */
  2388. int c, z, getval = 0;
  2389. int
  2390. x_keep = -1, x_list = -1, x_page = -1,
  2391. x_hdg = -1, x_ask = -1, x_dot = -1;
  2392. while (1) {
  2393. if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) {
  2394. if (y == -3)
  2395. break;
  2396. else
  2397. return(y);
  2398. }
  2399. c = cmgbrk();
  2400. if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2401. printf("?This switch does not take an argument\n");
  2402. return(-9);
  2403. }
  2404. if (!getval && (cmgkwflgs() & CM_ARG)) {
  2405. printf("?This switch requires an argument\n");
  2406. return(-9);
  2407. }
  2408. switch (y) {
  2409. case PU_KEEP:
  2410. z = 1;
  2411. if (c == ':' || c == '=')
  2412. if ((y = cmnum("How many backup files to keep",
  2413. "1",10,&z,xxstring)) < 0)
  2414. return(y);
  2415. if (z < 0 || z > MAXKEEP) {
  2416. printf("?Please specify a number between 0 and %d\n",
  2417. MAXKEEP
  2418. );
  2419. return(-9);
  2420. }
  2421. x_keep = z;
  2422. break;
  2423. case PU_LIST:
  2424. case PU_VERB:
  2425. x_list = 1;
  2426. break;
  2427. case PU_QUIE:
  2428. case PU_NOLI:
  2429. x_list = 0;
  2430. break;
  2431. #ifdef CK_TTGWSIZ
  2432. case PU_PAGE:
  2433. x_page = 1;
  2434. break;
  2435. case PU_NOPA:
  2436. x_page = 0;
  2437. break;
  2438. #endif /* CK_TTGWSIZ */
  2439. case PU_HDG:
  2440. x_hdg = 1;
  2441. break;
  2442. case PU_NOH:
  2443. x_hdg = 0;
  2444. break;
  2445. case PU_ASK:
  2446. x_ask = 1;
  2447. break;
  2448. case PU_NASK:
  2449. x_ask = 0;
  2450. break;
  2451. #ifdef UNIXOROSK
  2452. case PU_DOT:
  2453. x_dot = 1;
  2454. break;
  2455. case PU_NODOT:
  2456. x_dot = 0;
  2457. break;
  2458. #endif /* UNIXOROSK */
  2459. default:
  2460. printf("?This option can not be set\n");
  2461. return(-9);
  2462. }
  2463. }
  2464. if ((x = cmcfm()) < 0) /* Get confirmation */
  2465. return(x);
  2466. if (x_keep > -1) /* Set PURGE defaults. */
  2467. pu_keep = x_keep;
  2468. if (x_list > -1)
  2469. pu_list = x_list;
  2470. #ifdef CK_TTGWSIZ
  2471. if (x_page > -1)
  2472. pu_page = x_page;
  2473. #endif /* CK_TTGWSIZ */
  2474. if (x_hdg > -1)
  2475. pu_hdg = x_hdg;
  2476. if (x_ask > -1)
  2477. pu_ask = x_ask;
  2478. if (x_dot > -1)
  2479. pu_dot = x_dot;
  2480. return(success = 1);
  2481. }
  2482. int
  2483. dopurge() { /* Do the PURGE command */
  2484. extern char ** mtchs;
  2485. extern int xaskmore, cmd_rows, recursive;
  2486. int simulate = 0, asking = 0;
  2487. int listing = 0, paging = -1, lines = 0, deleting = 1, errors = 0;
  2488. struct FDB sw, sf, cm;
  2489. int g, i, j, k, m = 0, n, x, y, z, done = 0, count = 0, flags = 0;
  2490. int tokeep = 0, getval = 0, havename = 0, confirmed = 0;
  2491. int xx[MAXKEEP+1]; /* Array of numbers to keep */
  2492. int min = -1;
  2493. int x_hdg = 0, fs = 0, rc = 0;
  2494. CK_OFF_T minsize = -1L, maxsize = -1L;
  2495. char namebuf[CKMAXPATH+4];
  2496. char basebuf[CKMAXPATH+4];
  2497. char
  2498. * pu_aft = NULL,
  2499. * pu_bef = NULL,
  2500. * pu_naf = NULL,
  2501. * pu_nbf = NULL,
  2502. * pu_exc = NULL;
  2503. char * pxlist[8]; /* Exception list */
  2504. if (pu_keep > -1) /* Set PURGE defaults. */
  2505. tokeep = pu_keep;
  2506. if (pu_list > -1)
  2507. listing = pu_list;
  2508. #ifdef CK_TTGWSIZ
  2509. if (pu_page > -1)
  2510. paging = pu_page;
  2511. #endif /* CK_TTGWSIZ */
  2512. for (i = 0; i <= MAXKEEP; i++) /* Clear this number buffer */
  2513. xx[i] = 0;
  2514. for (i = 0; i < 8; i++) /* Initialize these... */
  2515. pxlist[i] = NULL;
  2516. g_matchdot = matchdot; /* Save these... */
  2517. cmfdbi(&sw, /* 1st FDB - PURGE switches */
  2518. _CMKEY, /* fcode */
  2519. "Filename or switch", /* hlpmsg */
  2520. "", /* default */
  2521. "", /* addtl string data */
  2522. npurgtab, /* addtl numeric data 1: tbl size */
  2523. 4, /* addtl numeric data 2: 4 = cmswi */
  2524. xxstring, /* Processing function */
  2525. purgtab, /* Keyword table */
  2526. &sf /* Pointer to next FDB */
  2527. );
  2528. cmfdbi(&sf, /* 2nd FDB - filespec to purge */
  2529. _CMIFI, /* fcode */
  2530. "",
  2531. "", /* default */
  2532. "", /* addtl string data */
  2533. 0, /* addtl numeric data 1 */
  2534. 0, /* addtl numeric data 2 */
  2535. xxstring,
  2536. NULL,
  2537. &cm
  2538. );
  2539. cmfdbi(&cm, /* Or premature confirmation */
  2540. _CMCFM, /* fcode */
  2541. "", /* hlpmsg */
  2542. "", /* default */
  2543. "", /* addtl string data */
  2544. 0, /* addtl numeric data 1 */
  2545. 0, /* addtl numeric data 2 */
  2546. NULL,
  2547. NULL,
  2548. NULL
  2549. );
  2550. while (!havename && !confirmed) {
  2551. x = cmfdb(&sw); /* Parse something */
  2552. if (x < 0) { /* Error */
  2553. rc = x;
  2554. goto xpurge;
  2555. } else if (cmresult.fcode == _CMKEY) {
  2556. char c;
  2557. c = cmgbrk();
  2558. if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2559. printf("?This switch does not take an argument\n");
  2560. rc = -9;
  2561. goto xpurge;
  2562. }
  2563. if (!getval && (cmgkwflgs() & CM_ARG)) {
  2564. printf("?This switch requires an argument\n");
  2565. rc = -9;
  2566. goto xpurge;
  2567. }
  2568. switch (k = cmresult.nresult) {
  2569. case PU_KEEP:
  2570. z = 1;
  2571. if (c == ':' || c == '=') {
  2572. if ((y = cmnum("How many backup files to keep",
  2573. "1",10,&z,xxstring)) < 0) {
  2574. rc = y;
  2575. goto xpurge;
  2576. }
  2577. }
  2578. if (z < 0 || z > MAXKEEP) {
  2579. printf("?Please specify a number between 0 and %d\n",
  2580. MAXKEEP
  2581. );
  2582. rc = -9;
  2583. goto xpurge;
  2584. }
  2585. tokeep = z;
  2586. break;
  2587. case PU_LIST:
  2588. listing = 1;
  2589. break;
  2590. case PU_NOLI:
  2591. listing = 0;
  2592. break;
  2593. #ifdef CK_TTGWSIZ
  2594. case PU_PAGE:
  2595. paging = 1;
  2596. break;
  2597. case PU_NOPA:
  2598. paging = 0;
  2599. break;
  2600. #endif /* CK_TTGWSIZ */
  2601. case PU_DELE:
  2602. deleting = 1;
  2603. break;
  2604. case PU_NODE:
  2605. deleting = 0;
  2606. simulate = 1;
  2607. listing = 1;
  2608. break;
  2609. case PU_ASK:
  2610. asking = 1;
  2611. break;
  2612. case PU_NASK:
  2613. asking = 0;
  2614. break;
  2615. case PU_AFT:
  2616. case PU_BEF:
  2617. case PU_NAF:
  2618. case PU_NBF:
  2619. if ((x = cmdate("File-time","",&s,0,xxstring)) < 0) {
  2620. if (x == -3) {
  2621. printf("?Date-time required\n");
  2622. rc = -9;
  2623. } else
  2624. rc = x;
  2625. goto xpurge;
  2626. }
  2627. fs++;
  2628. switch (k) {
  2629. case PU_AFT: makestr(&pu_aft,s); break;
  2630. case PU_BEF: makestr(&pu_bef,s); break;
  2631. case PU_NAF: makestr(&pu_naf,s); break;
  2632. case PU_NBF: makestr(&pu_nbf,s); break;
  2633. }
  2634. break;
  2635. case PU_SMA:
  2636. case PU_LAR:
  2637. if ((x = cmnum("File size in bytes","0",10,&y,xxstring)) < 0) {
  2638. rc = x;
  2639. goto xpurge;
  2640. }
  2641. fs++;
  2642. switch (cmresult.nresult) {
  2643. case PU_SMA: minsize = y; break;
  2644. case PU_LAR: maxsize = y; break;
  2645. }
  2646. break;
  2647. case PU_DOT:
  2648. matchdot = 1;
  2649. break;
  2650. case PU_NODOT:
  2651. matchdot = 0;
  2652. break;
  2653. case PU_EXC:
  2654. if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  2655. if (x == -3) {
  2656. printf("?Pattern required\n");
  2657. rc = -9;
  2658. } else
  2659. rc = x;
  2660. goto xpurge;
  2661. }
  2662. fs++;
  2663. makestr(&pu_exc,s);
  2664. break;
  2665. case PU_HDG:
  2666. x_hdg = 1;
  2667. break;
  2668. #ifdef RECURSIVE
  2669. case PU_RECU: /* /RECURSIVE */
  2670. recursive = 2;
  2671. break;
  2672. #endif /* RECURSIVE */
  2673. default:
  2674. printf("?Not implemented yet - \"%s\"\n",atmbuf);
  2675. rc = -9;
  2676. goto xpurge;
  2677. }
  2678. } else if (cmresult.fcode == _CMIFI) {
  2679. havename = 1;
  2680. } else if (cmresult.fcode == _CMCFM) {
  2681. confirmed = 1;
  2682. } else {
  2683. rc = -2;
  2684. goto xpurge;
  2685. }
  2686. }
  2687. if (havename) {
  2688. #ifdef CKREGEX
  2689. ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~[1-9]*~",NULL,NULL);
  2690. #else
  2691. ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~*~",NULL,NULL);
  2692. #endif /* CKREGEX */
  2693. } else {
  2694. #ifdef CKREGEX
  2695. ckstrncpy(line,"*.~[1-9]*~",LINBUFSIZ);
  2696. #else
  2697. ckstrncpy(line,"*.~*~",LINBUFSIZ);
  2698. #endif /* CKREGEX */
  2699. }
  2700. if (!confirmed) {
  2701. if ((x = cmcfm()) < 0) {
  2702. rc = x;
  2703. goto xpurge;
  2704. }
  2705. }
  2706. /* Parse finished - now action */
  2707. #ifdef CK_LOGIN
  2708. if (isguest) {
  2709. printf("?File deletion by guests not permitted.\n");
  2710. rc = -9;
  2711. goto xpurge;
  2712. }
  2713. #endif /* CK_LOGIN */
  2714. #ifdef CK_TTGWSIZ
  2715. if (paging < 0) /* /[NO]PAGE not given */
  2716. paging = xaskmore; /* so use prevailing */
  2717. #endif /* CK_TTGWSIZ */
  2718. lines = 0;
  2719. if (x_hdg > 0) {
  2720. printf("Purging %s, keeping %d...%s\n",
  2721. s,
  2722. tokeep,
  2723. simulate ? " (SIMULATION)" : "");
  2724. lines += 2;
  2725. }
  2726. flags = ZX_FILONLY;
  2727. if (recursive) flags |= ZX_RECURSE;
  2728. n = nzxpand(line,flags); /* Get list of backup files */
  2729. if (tokeep < 1) { /* Deleting all of them... */
  2730. for (i = 0; i < n; i++) {
  2731. if (fs) if (fileselect(mtchs[i],
  2732. pu_aft,pu_bef,pu_naf,pu_nbf,
  2733. minsize,maxsize,0,8,pxlist) < 1) {
  2734. if (listing > 0) {
  2735. printf(" %s (SKIPPED)\n",mtchs[i]);
  2736. #ifdef CK_TTGWSIZ
  2737. if (paging)
  2738. if (++lines > cmd_rows - 3) {
  2739. if (!askmore()) goto xpurge; else lines = 0;
  2740. }
  2741. #endif /* CK_TTGWSIZ */
  2742. }
  2743. continue;
  2744. }
  2745. if (asking) {
  2746. int x;
  2747. ckmakmsg(tmpbuf,TMPBUFSIZ," Delete ",mtchs[i],"?",NULL);
  2748. x = getyesno(tmpbuf,1);
  2749. switch (x) {
  2750. case 0: continue;
  2751. case 1: break;
  2752. case 2: goto xpurge;
  2753. }
  2754. }
  2755. x = deleting ? zdelet(mtchs[i]) : 0;
  2756. if (x > -1) {
  2757. if (listing)
  2758. printf(" %s (%s)\n", mtchs[i],deleting ? "OK" : "SELECTED");
  2759. count++;
  2760. } else {
  2761. errors++;
  2762. if (listing)
  2763. printf(" %s (FAILED)\n", mtchs[i]);
  2764. }
  2765. #ifdef CK_TTGWSIZ
  2766. if (listing && paging)
  2767. if (++lines > cmd_rows - 3) {
  2768. if (!askmore()) goto xpurge; else lines = 0;
  2769. }
  2770. #endif /* CK_TTGWSIZ */
  2771. }
  2772. goto xpurge;
  2773. }
  2774. if (n < tokeep) { /* Not deleting any */
  2775. count = 0;
  2776. if (listing)
  2777. printf(" Matches = %d: Not enough to purge.\n",n);
  2778. goto xpurge;
  2779. }
  2780. /* General case - delete some but not others */
  2781. sh_sort(mtchs,NULL,n,0,0,filecase); /* Alphabetize the list (ESSENTIAL) */
  2782. g = 0; /* Start of current group */
  2783. for (i = 0; i < n; i++) { /* Go thru sorted file list */
  2784. x = znext(namebuf); /* Get next file */
  2785. if (x < 1 || !namebuf[0] || i == n - 1) /* No more? */
  2786. done = 1; /* NOTE: 'done' must be 0 or 1 only */
  2787. if (fs) if (fileselect(namebuf,
  2788. pu_aft,pu_bef,pu_naf,pu_nbf,
  2789. minsize,maxsize,0,8,pxlist) < 1) {
  2790. if (listing > 0) {
  2791. printf(" %s (SKIPPED)\n",namebuf);
  2792. if (++lines > cmd_rows - 3)
  2793. if (!askmore()) goto xpurge; else lines = 0;
  2794. }
  2795. continue;
  2796. }
  2797. if (x > 0)
  2798. if ((m = bkupnum(namebuf,&z)) < 0) /* This file's backup number. */
  2799. continue;
  2800. for (j = 0; j < tokeep; j++) { /* Insert in list. */
  2801. if (m > xx[j]) {
  2802. for (k = tokeep - 1; k > j; k--)
  2803. xx[k] = xx[k-1];
  2804. xx[j] = m;
  2805. break;
  2806. }
  2807. }
  2808. /* New group? */
  2809. if (done || (i > 0 && ckstrcmp(namebuf,basebuf,z,1))) {
  2810. if (i + done - g > tokeep) { /* Do we have enough to purge? */
  2811. min = xx[tokeep-1]; /* Yes, lowest backup number to keep */
  2812. debug(F111,"dopurge group",basebuf,min);
  2813. for (j = g; j < i + done; j++) { /* Go through this group */
  2814. x = bkupnum(mtchs[j],&z); /* Get file backup number */
  2815. if (x > 0 && x < min) { /* Below minimum? */
  2816. x = deleting ? zdelet(mtchs[j]) : 0;
  2817. if (x < 0) errors++;
  2818. if (listing)
  2819. printf(" %s (%s)\n",
  2820. mtchs[j],
  2821. ((x < 0) ? "ERROR" :
  2822. (deleting ? "DELETED" : "SELECTED"))
  2823. );
  2824. count++;
  2825. } else if (listing) /* Not below minimum - keep this one */
  2826. printf(" %s (KEPT)\n",mtchs[j]);
  2827. #ifdef CK_TTGWSIZ
  2828. if (listing && paging)
  2829. if (++lines > cmd_rows - 3) {
  2830. if (!askmore()) goto xpurge; else lines = 0;
  2831. }
  2832. #endif /* CK_TTGWSIZ */
  2833. }
  2834. } else if (listing && paging) { /* Not enough to purge */
  2835. printf(" %s.~*~ (KEPT)\n",basebuf);
  2836. #ifdef CK_TTGWSIZ
  2837. if (++lines > cmd_rows - 3) {
  2838. if (!askmore()) goto xpurge; else lines = 0;
  2839. }
  2840. #endif /* CK_TTGWSIZ */
  2841. }
  2842. for (j = 0; j < tokeep; j++) /* Clear the backup number list */
  2843. xx[j] = 0;
  2844. g = i; /* Reset the group pointer */
  2845. }
  2846. if (done) /* No more files, done. */
  2847. break;
  2848. strncpy(basebuf,namebuf,z); /* Set basename of this file */
  2849. basebuf[z] = NUL;
  2850. }
  2851. xpurge: /* Common exit point */
  2852. if (g_matchdot > -1) {
  2853. matchdot = g_matchdot; /* Restore these... */
  2854. g_matchdot = -1;
  2855. }
  2856. if (rc < 0) return(rc); /* Parse error */
  2857. if (x_hdg)
  2858. printf("Files purged: %d%s\n",
  2859. count,
  2860. deleting ? "" : " (not really)"
  2861. );
  2862. return(success = count > 0 ? 1 : (errors > 0) ? 0 : 1);
  2863. }
  2864. #endif /* CKPURGE */
  2865. #ifndef NOXFER
  2866. #ifndef NOLOCAL
  2867. int
  2868. doxdis(which) int which; { /* 1 = Kermit, 2 = FTP */
  2869. extern int nolocal;
  2870. int x, y = 0, z;
  2871. #ifdef NEWFTP
  2872. extern int ftp_dis;
  2873. #endif /* NEWFTP */
  2874. #ifdef COMMENT
  2875. char *s;
  2876. #endif /* COMMENT */
  2877. if ((x = cmkey(fdtab,nfdtab,"file transfer display style","",
  2878. xxstring)) < 0)
  2879. return(x);
  2880. #ifdef CK_PCT_BAR
  2881. if ((y = cmkey(fdftab,2,"","thermometer",xxstring)) < 0)
  2882. return(y);
  2883. #endif /* CK_PCT_BAR */
  2884. if ((z = cmcfm()) < 0) return(z);
  2885. #ifdef CK_CURSES
  2886. if (x == XYFD_C) { /* FULLSCREEN */
  2887. #ifdef COMMENT
  2888. #ifndef MYCURSES
  2889. extern char * trmbuf; /* Real curses */
  2890. int z;
  2891. #endif /* MYCURSES */
  2892. #endif /* COMMENT */
  2893. if (nolocal) /* Nothing to do in this case */
  2894. return(success = 1);
  2895. #ifdef COMMENT
  2896. #ifndef MYCURSES
  2897. #ifndef VMS
  2898. s = getenv("TERM");
  2899. debug(F110,"doxdis TERM",s,0);
  2900. if (!s) s = "";
  2901. fxdinit(x);
  2902. if (*s && trmbuf) { /* Don't call tgetent */
  2903. z = tgetent(trmbuf,s); /* if trmbuf not allocated */
  2904. debug(F111,"doxdis tgetent",s,z);
  2905. } else {
  2906. z = 0;
  2907. debug(F110,"doxdis tgetent skipped",s,0);
  2908. }
  2909. if (z < 1) {
  2910. printf("Sorry, terminal type unknown: \"%s\"\n",s);
  2911. return(success = 0);
  2912. }
  2913. #endif /* VMS */
  2914. #endif /* MYCURSES */
  2915. #else
  2916. fxdinit(x);
  2917. #endif /* COMMENT */
  2918. #ifdef CK_PCT_BAR
  2919. thermometer = y;
  2920. #endif /* CK_PCT_BAR */
  2921. line[0] = '\0'; /* (What's this for?) */
  2922. }
  2923. #endif /* CK_CURSES */
  2924. if (which == 1) /* It's OK. */
  2925. fdispla = x;
  2926. #ifdef NEWFTP
  2927. else if (which == 2)
  2928. ftp_dis = x;
  2929. #endif /* NEWFTP */
  2930. return(success = 1);
  2931. }
  2932. #endif /* NOLOCAL */
  2933. #endif /* NOXFER */
  2934. int
  2935. setfil(rmsflg) int rmsflg; {
  2936. #ifdef COMMENT
  2937. extern int en_del;
  2938. #endif /* COMMENT */
  2939. #ifndef NOXFER
  2940. if (rmsflg) {
  2941. if ((y = cmkey(rfiltab,nrfilp,"Remote file parameter","",
  2942. xxstring)) < 0) {
  2943. if (y == -3) {
  2944. printf("?Remote file parameter required\n");
  2945. return(-9);
  2946. } else return(y);
  2947. }
  2948. } else {
  2949. #endif /* NOXFER */
  2950. if ((y = cmkey(filtab,nfilp,"File parameter","",xxstring)) < 0)
  2951. return(y);
  2952. #ifndef NOXFER
  2953. }
  2954. #endif /* NOXFER */
  2955. switch (y) {
  2956. #ifdef COMMENT /* Not needed */
  2957. case XYFILB: /* Blocksize */
  2958. if ((y = cmnum("file block size",ckitoa(DBLKSIZ),10,&z,xxstring)) < 0)
  2959. return(y);
  2960. if ((x = cmcfm()) < 0) return(x);
  2961. if (rmsflg) {
  2962. sstate = setgen('S', "311", ckitoa(z), "");
  2963. return((int) sstate);
  2964. } else {
  2965. fblksiz = z;
  2966. return(success = 1);
  2967. }
  2968. #endif /* COMMENT */
  2969. #ifndef NOXFER
  2970. case XYFILS: /* Byte size */
  2971. if ((y = cmnum("file byte size (7 or 8)","8",10,&z,xxstring)) < 0)
  2972. return(y);
  2973. if (z != 7 && z != 8) {
  2974. printf("\n?The choices are 7 and 8\n");
  2975. return(0);
  2976. }
  2977. if ((y = cmcfm()) < 0) return(y);
  2978. if (z == 7) fmask = 0177;
  2979. else if (z == 8) fmask = 0377;
  2980. return(success = 1);
  2981. #ifndef NOCSETS
  2982. case XYFILC: { /* Character set */
  2983. char * csetname = NULL;
  2984. extern int
  2985. r_cset, s_cset, afcset[]; /* SEND CHARACTER-SET AUTO or MANUAL */
  2986. struct FDB kw, fl;
  2987. cmfdbi(&kw, /* First FDB - command switches */
  2988. _CMKEY, /* fcode */
  2989. rmsflg ? "server character-set name" : "", /* help */
  2990. "", /* default */
  2991. "", /* addtl string data */
  2992. nfilc, /* addtl numeric data 1: tbl size */
  2993. 0, /* addtl numeric data 2: 0 = keyword */
  2994. xxstring, /* Processing function */
  2995. fcstab, /* Keyword table */
  2996. rmsflg ? &fl : NULL /* Pointer to next FDB */
  2997. );
  2998. cmfdbi(&fl, /* Anything that doesn't match */
  2999. _CMFLD, /* fcode */
  3000. "", /* hlpmsg */
  3001. "", /* default */
  3002. "", /* addtl string data */
  3003. 0, /* addtl numeric data 1 */
  3004. 0, /* addtl numeric data 2 */
  3005. xxstring,
  3006. NULL,
  3007. NULL
  3008. );
  3009. if ((x = cmfdb(&kw)) < 0)
  3010. return(x);
  3011. if (cmresult.fcode == _CMKEY) {
  3012. x = cmresult.nresult;
  3013. csetname = fcsinfo[x].keyword;
  3014. } else {
  3015. ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  3016. csetname = line;
  3017. }
  3018. if ((z = cmcfm()) < 0) return(z);
  3019. if (rmsflg) {
  3020. sstate = setgen('S', "320", csetname, "");
  3021. return((int) sstate);
  3022. }
  3023. fcharset = x;
  3024. if (s_cset == XMODE_A) /* If SEND CHARACTER-SET is AUTO */
  3025. if (x > -1 && x <= MAXFCSETS)
  3026. if (afcset[x] > -1 && afcset[x] <= MAXTCSETS)
  3027. tcharset = afcset[x]; /* Pick corresponding xfer charset */
  3028. setxlatype(tcharset,fcharset); /* Translation type */
  3029. /* If I say SET FILE CHARACTER-SET blah, I want to be blah! */
  3030. r_cset = XMODE_M; /* Don't switch incoming set! */
  3031. x = fcsinfo[fcharset].size; /* Also set default x-bit charset */
  3032. if (x == 128) /* 7-bit... */
  3033. dcset7 = fcharset;
  3034. else if (x == 256) /* 8-bit... */
  3035. dcset8 = fcharset;
  3036. return(success = 1);
  3037. }
  3038. #endif /* NOCSETS */
  3039. #ifndef NOLOCAL
  3040. case XYFILD: /* Display */
  3041. return(doxdis(1)); /* 1 == kermit */
  3042. #endif /* NOLOCAL */
  3043. #endif /* NOXFER */
  3044. case XYFILA: /* End-of-line */
  3045. #ifdef NLCHAR
  3046. s = "";
  3047. if (NLCHAR == 015)
  3048. s = "cr";
  3049. else if (NLCHAR == 012)
  3050. s = "lf";
  3051. if ((x = cmkey(eoltab, neoltab,
  3052. "local text-file line terminator",s,xxstring)) < 0)
  3053. return(x);
  3054. #else
  3055. if ((x = cmkey(eoltab, neoltab,
  3056. "local text-file line terminator","crlf",xxstring)) < 0)
  3057. return(x);
  3058. #endif /* NLCHAR */
  3059. if ((z = cmcfm()) < 0) return(z);
  3060. feol = (CHAR) x;
  3061. return(success = 1);
  3062. #ifndef NOXFER
  3063. case XYFILN: /* Names */
  3064. if ((x = cmkey(fntab,nfntab,"how to handle filenames","converted",
  3065. xxstring)) < 0)
  3066. return(x);
  3067. if ((z = cmcfm()) < 0) return(z);
  3068. if (rmsflg) {
  3069. sstate = setgen('S', "301", ckitoa(1 - x), "");
  3070. return((int) sstate);
  3071. } else {
  3072. ptab[protocol].fncn = x; /* Set structure */
  3073. fncnv = x; /* Set variable */
  3074. f_save = x; /* And set "permanent" variable */
  3075. return(success = 1);
  3076. }
  3077. case XYFILR: /* Record length */
  3078. if ((y = cmnum("file record length",
  3079. ckitoa(DLRECL),10,&z,xxstring)) < 0)
  3080. return(y);
  3081. if ((x = cmcfm()) < 0) return(x);
  3082. if (rmsflg) {
  3083. sstate = setgen('S', "312", ckitoa(z), "");
  3084. return((int) sstate);
  3085. } else {
  3086. frecl = z;
  3087. return(success = 1);
  3088. }
  3089. #ifdef COMMENT
  3090. case XYFILO: /* Organization */
  3091. if ((x = cmkey(forgtab,nforg,"file organization","sequential",
  3092. xxstring)) < 0)
  3093. return(x);
  3094. if ((y = cmcfm()) < 0) return(y);
  3095. if (rmsflg) {
  3096. sstate = setgen('S', "314", ckitoa(x), "");
  3097. return((int) sstate);
  3098. } else {
  3099. forg = x;
  3100. return(success = 1);
  3101. }
  3102. #endif /* COMMENT */
  3103. #ifdef COMMENT /* Not needed */
  3104. case XYFILF: /* Format */
  3105. if ((x = cmkey(frectab,nfrec,"file record format","stream",
  3106. xxstring)) < 0)
  3107. return(x);
  3108. if ((y = cmcfm()) < 0) return(y);
  3109. if (rmsflg) {
  3110. sstate = setgen('S', "313", ckitoa(x), "");
  3111. return((int) sstate);
  3112. } else {
  3113. frecfm = x;
  3114. return(success = 1);
  3115. }
  3116. #endif /* COMMENT */
  3117. #ifdef COMMENT
  3118. case XYFILP: /* Printer carriage control */
  3119. if ((x = cmkey(fcctab,nfcc,"file carriage control","newline",
  3120. xxstring)) < 0)
  3121. return(x);
  3122. if ((y = cmcfm()) < 0) return(y);
  3123. if (rmsflg) {
  3124. sstate = setgen('S', "315", ckitoa(x), "");
  3125. return((int) sstate);
  3126. } else {
  3127. fcctrl = x;
  3128. return(success = 1);
  3129. }
  3130. #endif /* COMMENT */
  3131. #endif /* NOXFER */
  3132. case XYFILT: /* Type */
  3133. if ((x = cmkey(rmsflg ? rfttab : fttab,
  3134. rmsflg ? nrfttyp : nfttyp,
  3135. "type of file transfer","text",xxstring)) < 0)
  3136. return(x);
  3137. #ifdef VMS
  3138. /* Allow VMS users to choose record format for binary files */
  3139. if ((x == XYFT_B) && (rmsflg == 0)) {
  3140. if ((x = cmkey(fbtab,nfbtyp,"VMS record format","fixed",
  3141. xxstring)) < 0)
  3142. return(x);
  3143. }
  3144. #endif /* VMS */
  3145. if ((y = cmcfm()) < 0) return(y);
  3146. binary = x;
  3147. b_save = x;
  3148. #ifdef MAC
  3149. (void) mac_setfildflg(binary);
  3150. #endif /* MAC */
  3151. #ifndef NOXFER
  3152. if (rmsflg) {
  3153. /* Allow for LABELED in VMS & OS/2 */
  3154. sstate = setgen('S', "300", ckitoa(x), "");
  3155. return((int) sstate);
  3156. } else {
  3157. #endif /* NOXFER */
  3158. return(success = 1);
  3159. #ifndef NOXFER
  3160. }
  3161. #endif /* NOXFER */
  3162. #ifndef NOXFER
  3163. case XYFILX: /* Collision Action */
  3164. if ((x = cmkey(colxtab,ncolx,"Filename collision action","backup",
  3165. xxstring)) < 0)
  3166. return(x);
  3167. if ((y = cmcfm()) < 0) return(y);
  3168. #ifdef CK_LOGIN
  3169. if (isguest) {
  3170. /* Don't let guests change existing files */
  3171. printf("?This command not valid for guests\n");
  3172. return(-9);
  3173. }
  3174. #endif /* CK_LOGIN */
  3175. #ifdef COMMENT
  3176. /* Not appropriate - DISABLE DELETE only refers to server */
  3177. if ((x == XYFX_X || x == XYFX_B || x == XYFX_U || x == XYFX_A) &&
  3178. (!ENABLED(en_del))) {
  3179. printf("?Sorry, file deletion is disabled.\n");
  3180. return(-9);
  3181. }
  3182. #endif /* COMMENT */
  3183. fncact = x;
  3184. ptab[protocol].fnca = x;
  3185. if (rmsflg) {
  3186. sstate = setgen('S', "302", ckitoa(fncact), "");
  3187. return((int) sstate);
  3188. } else {
  3189. if (fncact == XYFX_R) ckwarn = 1; /* FILE WARNING implications */
  3190. if (fncact == XYFX_X) ckwarn = 0; /* ... */
  3191. return(success = 1);
  3192. }
  3193. case XYFILW: /* Warning/Write-Protect */
  3194. if ((x = seton(&ckwarn)) < 0) return(x);
  3195. if (ckwarn)
  3196. fncact = XYFX_R;
  3197. else
  3198. fncact = XYFX_X;
  3199. return(success = 1);
  3200. #ifdef CK_LABELED
  3201. case XYFILL: /* LABELED FILE parameters */
  3202. if ((x = cmkey(lbltab,nlblp,"Labeled file feature","",
  3203. xxstring)) < 0)
  3204. return(x);
  3205. if ((success = seton(&y)) < 0)
  3206. return(success);
  3207. if (y) /* Set or reset the selected bit */
  3208. lf_opts |= x; /* in the options bitmask. */
  3209. else
  3210. lf_opts &= ~x;
  3211. return(success);
  3212. #endif /* CK_LABELED */
  3213. case XYFILI: { /* INCOMPLETE */
  3214. extern struct keytab ifdatab[];
  3215. extern int keep;
  3216. if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  3217. if ((x = cmcfm()) < 0) return(x);
  3218. if (rmsflg) {
  3219. sstate = setgen('S',
  3220. "310",
  3221. y == 0 ? "0" : (y == 1 ? "1" : "2"),
  3222. ""
  3223. );
  3224. return((int) sstate);
  3225. } else {
  3226. keep = y;
  3227. return(success = 1);
  3228. }
  3229. }
  3230. #ifdef CK_TMPDIR
  3231. case XYFILG: { /* Download directory */
  3232. int x;
  3233. char *s;
  3234. #ifdef ZFNQFP
  3235. struct zfnfp * fnp;
  3236. #endif /* ZFNQFP */
  3237. #ifdef MAC
  3238. char temp[34];
  3239. #endif /* MAC */
  3240. #ifdef GEMDOS
  3241. if ((x = cmdir("Name of local directory, or carriage return",
  3242. "",&s,
  3243. NULL)) < 0 ) {
  3244. if (x != -3)
  3245. return(x);
  3246. }
  3247. #else
  3248. #ifdef OS2
  3249. if ((x = cmdir("Name of PC disk and/or directory,\n\
  3250. or press the Enter key to use current directory",
  3251. "",&s,xxstring)) < 0 ) {
  3252. if (x != -3)
  3253. return(x);
  3254. }
  3255. #else
  3256. #ifdef MAC
  3257. x = ckstrncpy(temp,zhome(),32);
  3258. if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  3259. if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  3260. or press the Return key for the desktop on the boot disk",
  3261. temp,&s, xxstring)) < 0 )
  3262. return(x);
  3263. #else
  3264. if ((x = cmdir("Name of local directory, or carriage return",
  3265. "", &s, xxstring)) < 0 ) {
  3266. if (x != -3)
  3267. return(x);
  3268. }
  3269. #endif /* MAC */
  3270. #endif /* OS2 */
  3271. #endif /* GEMDOS */
  3272. debug(F110,"download dir",s,0);
  3273. #ifndef MAC
  3274. if (x == 2) {
  3275. printf("?Wildcards not allowed in directory name\n");
  3276. return(-9);
  3277. }
  3278. #endif /* MAC */
  3279. #ifdef ZFNQFP
  3280. if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3281. if (fnp->fpath)
  3282. if ((int) strlen(fnp->fpath) > 0)
  3283. s = fnp->fpath;
  3284. }
  3285. debug(F110,"download zfnqfp",s,0);
  3286. #endif /* ZFNQFP */
  3287. ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy */
  3288. #ifndef MAC
  3289. if ((x = cmcfm()) < 0) /* Get confirmation */
  3290. return(x);
  3291. #endif /* MAC */
  3292. #ifdef CK_LOGIN
  3293. if (isguest) {
  3294. /* Don't let guests change existing files */
  3295. printf("?This command not valid for guests\n");
  3296. return(-9);
  3297. }
  3298. #endif /* CK_LOGIN */
  3299. x = strlen(s);
  3300. if (x) {
  3301. #ifdef datageneral /* AOS/VS */
  3302. if (s[x-1] == ':') /* homdir ends in colon, */
  3303. s[x-1] = NUL; /* and "dir" doesn't like that... */
  3304. #else
  3305. #ifdef OS2ORUNIX /* Unix or K-95... */
  3306. if ((x < (LINBUFSIZ - 2)) && /* Add trailing dirsep */
  3307. (s[x-1] != '/')) { /* if none present. */
  3308. s[x] = '/'; /* Note that Windows path has */
  3309. s[x+1] = NUL; /* been canonicalized to forward */
  3310. } /* slashes at this point. */
  3311. #endif /* OS2ORUNIX */
  3312. #endif /* datageneral */
  3313. makestr(&dldir,s);
  3314. } else
  3315. makestr(&dldir,NULL); /* dldir is NULL when not assigned */
  3316. return(success = 1);
  3317. }
  3318. #endif /* CK_TMPDIR */
  3319. case XYFILY:
  3320. return(setdest());
  3321. #endif /* NOXFER */
  3322. #ifdef CK_CTRLZ
  3323. case XYFILV: { /* EOF */
  3324. extern int eofmethod;
  3325. if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  3326. xxstring)) < 0)
  3327. return(x);
  3328. if ((y = cmcfm()) < 0)
  3329. return(y);
  3330. eofmethod = x;
  3331. return(success = 1);
  3332. }
  3333. #endif /* CK_CTRLZ */
  3334. #ifndef NOXFER
  3335. #ifdef UNIX
  3336. case XYFILH: { /* OUTPUT */
  3337. extern int zofbuffer, zobufsize, zofblock;
  3338. #ifdef DYNAMIC
  3339. extern char * zoutbuffer;
  3340. #endif /* DYNAMIC */
  3341. if ((x = cmkey(zoftab,nzoftab,"output file writing method","",
  3342. xxstring)) < 0)
  3343. return(x);
  3344. if (x == ZOF_BUF || x == ZOF_NBUF) {
  3345. if ((y = cmnum("output buffer size","32768",10,&z,xxstring)) < 0)
  3346. return(y);
  3347. if (z < 1) {
  3348. printf("?Bad size - %d\n", z);
  3349. return(-9);
  3350. }
  3351. }
  3352. if ((y = cmcfm()) < 0) return(y);
  3353. switch (x) {
  3354. case ZOF_BUF:
  3355. case ZOF_NBUF:
  3356. zofbuffer = (x == ZOF_BUF);
  3357. zobufsize = z;
  3358. break;
  3359. case ZOF_BLK:
  3360. case ZOF_NBLK:
  3361. zofblock = (x == ZOF_BLK);
  3362. break;
  3363. }
  3364. #ifdef DYNAMIC
  3365. if (zoutbuffer) free(zoutbuffer);
  3366. if (!(zoutbuffer = (char *)malloc(z))) {
  3367. printf("MEMORY ALLOCATION ERROR - FATAL\n");
  3368. doexit(BAD_EXIT,-1);
  3369. } else
  3370. zobufsize = z;
  3371. #else
  3372. if (z <= OBUFSIZE) {
  3373. zobufsize = z;
  3374. } else {
  3375. printf("?Sorry, %d is too big - %d is the maximum\n",z,OBUFSIZE);
  3376. return(-9);
  3377. }
  3378. #endif /* DYNAMIC */
  3379. return(success = 1);
  3380. }
  3381. #endif /* UNIX */
  3382. #ifdef PATTERNS
  3383. case XYFIBP: /* BINARY-PATTERN */
  3384. case XYFITP: { /* TEXT-PATTERN */
  3385. char * tmp[FTPATTERNS];
  3386. int i, n = 0;
  3387. while (n < FTPATTERNS) {
  3388. tmp[n] = NULL;
  3389. if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  3390. break;
  3391. ckstrncpy(line,s,LINBUFSIZ);
  3392. s = brstrip(line);
  3393. makestr(&(tmp[n++]),s);
  3394. }
  3395. if (x == -3) x = cmcfm();
  3396. for (i = 0; i <= n; i++) {
  3397. if (x > -1) {
  3398. if (y == XYFIBP)
  3399. makestr(&(binpatterns[i]),tmp[i]);
  3400. else
  3401. makestr(&(txtpatterns[i]),tmp[i]);
  3402. }
  3403. free(tmp[i]);
  3404. }
  3405. if (y == XYFIBP) /* Null-terminate the list */
  3406. makestr(&(binpatterns[i]),NULL);
  3407. else
  3408. makestr(&(txtpatterns[i]),NULL);
  3409. return(x);
  3410. }
  3411. case XYFIPA: /* PATTERNS */
  3412. if ((x = setonaut(&patterns)) < 0)
  3413. return(x);
  3414. return(success = 1);
  3415. #endif /* PATTERNS */
  3416. #endif /* NOXFER */
  3417. #ifdef UNICODE
  3418. case XYFILU: { /* UCS */
  3419. extern int ucsorder, ucsbom, byteorder;
  3420. if ((x = cmkey(ucstab,nucstab,"","",xxstring)) < 0)
  3421. return(x);
  3422. switch (x) {
  3423. case UCS_BYT:
  3424. if ((y = cmkey(botab,nbotab,
  3425. "Byte order",
  3426. byteorder ? "little-endian" : "big-endian",
  3427. xxstring
  3428. )
  3429. ) < 0)
  3430. return(y);
  3431. if ((x = cmcfm()) < 0)
  3432. return(x);
  3433. ucsorder = y;
  3434. return(success = 1);
  3435. case UCS_BOM:
  3436. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  3437. return(y);
  3438. if ((x = cmcfm()) < 0)
  3439. return(x);
  3440. ucsbom = y;
  3441. return(success = 1);
  3442. default:
  3443. return(-2);
  3444. }
  3445. }
  3446. #endif /* UNICODE */
  3447. #ifndef datageneral
  3448. case XYF_INSP: { /* SCAN (INSPECTION) */
  3449. extern int filepeek, nscanfile;
  3450. if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  3451. return(x);
  3452. if (y) {
  3453. if ((y = cmnum("How much to scan",ckitoa(SCANFILEBUF),
  3454. 10,&z,xxstring)) < 0)
  3455. return(y);
  3456. }
  3457. if ((y = cmcfm()) < 0)
  3458. return(y);
  3459. #ifdef VMS
  3460. filepeek = 0;
  3461. nscanfile = 0;
  3462. return(success = 0);
  3463. #else
  3464. filepeek = x;
  3465. nscanfile = z;
  3466. return(success = 1);
  3467. #endif /* VMS */
  3468. }
  3469. #endif /* datageneral */
  3470. case XYF_DFLT:
  3471. y = 0;
  3472. #ifndef NOCSETS
  3473. if ((y = cmkey(fdfltab,nfdflt,"","",xxstring)) < 0)
  3474. return(y);
  3475. if (y == 7 || y == 8) {
  3476. if (y == 7)
  3477. s = fcsinfo[dcset7].keyword;
  3478. else
  3479. s = fcsinfo[dcset8].keyword;
  3480. if ((x = cmkey(fcstab,nfilc,"character-set",s,xxstring)) < 0)
  3481. return(x);
  3482. }
  3483. ckstrncpy(line,fcsinfo[x].keyword,LINBUFSIZ);
  3484. s = line;
  3485. #endif /* NOCSETS */
  3486. if ((z = cmcfm()) < 0)
  3487. return(z);
  3488. switch (y) {
  3489. #ifndef NOCSETS
  3490. case 7:
  3491. if (fcsinfo[x].size != 128) {
  3492. printf("%s - Not a 7-bit set\n",s);
  3493. return(-9);
  3494. }
  3495. dcset7 = x;
  3496. break;
  3497. case 8:
  3498. if (fcsinfo[x].size != 256) {
  3499. printf("%s - Not an 8-bit set\n",s);
  3500. return(-9);
  3501. }
  3502. dcset8 = x;
  3503. break;
  3504. #endif /* NOCSETS */
  3505. default:
  3506. return(-2);
  3507. }
  3508. return(success = 1);
  3509. #ifndef NOXFER
  3510. case 9997: /* FASTLOOKUPS */
  3511. return(success = seton(&stathack));
  3512. #endif /* NOXFER */
  3513. #ifdef UNIX
  3514. #ifdef DYNAMIC
  3515. case XYF_LSIZ: { /* LISTSIZE */
  3516. int zz;
  3517. y = cmnum("Maximum number of filenames","",10,&x,xxstring);
  3518. if ((x = setnum(&zz,x,y,-1)) < 0)
  3519. return(x);
  3520. if (zsetfil(zz,3) < 0) {
  3521. printf("?Memory allocation failure\n");
  3522. return(-9);
  3523. }
  3524. return(success = 1);
  3525. }
  3526. case XYF_SSPA: { /* STRINGSPACE */
  3527. int zz;
  3528. y = cmnum("Number of characters for filename list",
  3529. "",10,&x,xxstring);
  3530. if ((x = setnum(&zz,x,y,-1)) < 0)
  3531. return(x);
  3532. if (zsetfil(zz,1) < 0) {
  3533. printf("?Memory allocation failure\n");
  3534. return(-9);
  3535. }
  3536. return(success = 1);
  3537. }
  3538. #endif /* DYNAMIC */
  3539. #endif /* UNIX */
  3540. default:
  3541. printf("?unexpected file parameter\n");
  3542. return(-2);
  3543. }
  3544. }
  3545. #ifdef UNIX
  3546. #ifndef NOPUTENV
  3547. #ifdef BIGBUFOK
  3548. #define NPUTENVS 4096
  3549. #else
  3550. #define NPUTENVS 128
  3551. #endif /* BIGBUFOK */
  3552. /* environment variables must be static, not automatic */
  3553. static char * putenvs[NPUTENVS]; /* Array of environment var strings */
  3554. static int nputenvs = -1; /* Pointer into array */
  3555. /*
  3556. If anyone ever notices the limitation on the number of PUTENVs, the list
  3557. can be made dynamic, we can recycle entries with the same name, etc.
  3558. */
  3559. int
  3560. doputenv(s1, s2) char * s1; char * s2; {
  3561. char * s, * t = tmpbuf; /* Create or alter environment var */
  3562. if (nputenvs == -1) { /* Table not used yet */
  3563. int i; /* Initialize the pointers */
  3564. for (i = 0; i < NPUTENVS; i++)
  3565. putenvs[i] = NULL;
  3566. nputenvs = 0;
  3567. }
  3568. if (!s1) return(1); /* Nothing to do */
  3569. if (!*s1) return(1); /* ditto */
  3570. if (ckindex("=",s1,0,0,0)) { /* Does the name contain an '='? */
  3571. printf( /* putenv() does not allow this. */
  3572. /* This also catches the 'putenv name=value' case */
  3573. "?PUTENV - Equal sign in variable name - 'help putenv' for info.\n");
  3574. return(-9);
  3575. }
  3576. nputenvs++; /* Point to next free string */
  3577. debug(F111,"doputenv s1",s1,nputenvs);
  3578. debug(F111,"doputenv s2",s2,nputenvs);
  3579. if (nputenvs > NPUTENVS - 1) { /* Notice the end */
  3580. printf("?PUTENV - static buffer space exhausted\n");
  3581. return(-9);
  3582. }
  3583. /* Quotes are not needed but we allow them for familiarity */
  3584. /* but then we strip them, so syntax is same as for Unix shell */
  3585. if (s2) {
  3586. s2 = brstrip(s2);
  3587. } else {
  3588. s2 = (char *)"";
  3589. }
  3590. ckmakmsg(t,TMPBUFSIZ,s1,"=",s2,NULL);
  3591. debug(F111,"doputenv",t,nputenvs);
  3592. (VOID) makestr(&(putenvs[nputenvs]),t); /* Make a safe permananent copy */
  3593. if (!putenvs[nputenvs]) {
  3594. printf("?PUTENV - memory allocation failure\n");
  3595. return(-9);
  3596. }
  3597. if (putenv(putenvs[nputenvs])) {
  3598. printf("?PUTENV - %s\n",ck_errstr());
  3599. return(-9);
  3600. } else return(success = 1);
  3601. }
  3602. #endif /* NOPUTENV */
  3603. #endif /* UNIX */
  3604. int
  3605. settrmtyp() {
  3606. #ifdef OS2
  3607. #ifdef TNCODE
  3608. extern int ttnum; /* Last Telnet Terminal Type sent */
  3609. extern int ttnumend; /* Has end of list been found */
  3610. #endif /* TNCODE */
  3611. if ((x = cmkey(ttyptab,nttyp,"","vt220",xxstring)) < 0)
  3612. return(x);
  3613. if ((y = cmcfm()) < 0)
  3614. return(y);
  3615. settermtype(x,1);
  3616. #ifdef TNCODE
  3617. /* So we send the correct terminal name to the host if it asks for it */
  3618. ttnum = -1; /* Last Telnet Terminal Type sent */
  3619. ttnumend = 0; /* end of list not found */
  3620. #endif /* TNCODE */
  3621. return(success = 1);
  3622. #else /* Not OS2 */
  3623. #ifdef UNIX
  3624. extern int fxd_inited;
  3625. x = cmtxt("Terminal type name, case sensitive","",&s,NULL);
  3626. #ifdef NOPUTENV
  3627. success = 1;
  3628. #else
  3629. success = doputenv("TERM",s); /* Set the TERM variable */
  3630. #ifdef CK_CURSES
  3631. fxd_inited = 0; /* Force reinitialization of curses database */
  3632. (void)doxdis(0); /* Re-initialize file transfer display */
  3633. concb((char)escape); /* Fix command terminal */
  3634. #endif /* CK_CURSES */
  3635. #endif /* NOPUTENV */
  3636. return(success);
  3637. #else
  3638. printf(
  3639. "\n Sorry, this version of C-Kermit does not support the SET TERMINAL TYPE\n");
  3640. printf(
  3641. " command. Type \"help set terminal\" for further information.\n");
  3642. return(success = 0);
  3643. #endif /* UNIX */
  3644. #endif /* OS2 */
  3645. }
  3646. #ifndef NOLOCAL
  3647. #ifdef OS2
  3648. /* MS-DOS KERMIT compatibility modes */
  3649. int
  3650. setmsk() {
  3651. if ((y = cmkey(msktab,nmsk,"MS-DOS Kermit compatibility mode",
  3652. "keycodes",xxstring)) < 0) return(y);
  3653. switch ( y ) {
  3654. #ifdef COMMENT
  3655. case MSK_COLOR:
  3656. return(seton(&mskcolors));
  3657. #endif /* COMMENT */
  3658. case MSK_KEYS:
  3659. return(seton(&mskkeys));
  3660. case MSK_REN:
  3661. return(seton(&mskrename));
  3662. default: /* Shouldn't get here. */
  3663. return(-2);
  3664. }
  3665. }
  3666. #endif /* OS2 */
  3667. #ifdef CKTIDLE
  3668. static char iactbuf[132];
  3669. char *
  3670. getiact() {
  3671. switch (tt_idleact) {
  3672. case IDLE_RET: return("return");
  3673. case IDLE_EXIT: return("exit");
  3674. case IDLE_HANG: return("hangup");
  3675. #ifdef TNCODE
  3676. case IDLE_TNOP: return("Telnet NOP");
  3677. case IDLE_TAYT: return("Telnet AYT");
  3678. #endif /* TNCODE */
  3679. case IDLE_OUT: {
  3680. int c, k, n;
  3681. char * p, * q, * t;
  3682. k = ckstrncpy(iactbuf,"output ",132);
  3683. n = k;
  3684. q = &iactbuf[k];
  3685. p = tt_idlestr;
  3686. if (!p) p = "";
  3687. if (!*p) return("output NUL");
  3688. while ((c = *p++) && n < 131) {
  3689. c &= 0xff;
  3690. if (c == '\\') {
  3691. if (n > 130) break;
  3692. *q++ = '\\';
  3693. *q++ = '\\';
  3694. *q = NUL;
  3695. n += 2;
  3696. } else if ((c > 32 && c < 127) || c > 159) {
  3697. *q++ = c;
  3698. *q = NUL;
  3699. n++;
  3700. } else {
  3701. if (n > (131 - 6))
  3702. break;
  3703. sprintf(q,"\\{%d}",c);
  3704. k = strlen(q);
  3705. q += k;
  3706. n += k;
  3707. *q = NUL;
  3708. }
  3709. }
  3710. *q = NUL;
  3711. #ifdef OS2
  3712. k = tt_cols[VTERM];
  3713. #else
  3714. k = tt_cols;
  3715. #endif /* OS2 */
  3716. if (n > k - 52) {
  3717. n = k - 52;
  3718. iactbuf[n-2] = '.';
  3719. iactbuf[n-1] = '.';
  3720. iactbuf[n] = NUL;
  3721. }
  3722. return(iactbuf);
  3723. }
  3724. default: return("unknown");
  3725. }
  3726. }
  3727. #endif /* CKTIDLE */
  3728. #ifndef NOCSETS
  3729. VOID
  3730. setlclcharset(x) int x; {
  3731. int i;
  3732. tcsl = y; /* Local character set */
  3733. #ifdef OS2
  3734. for (i = 0; i < 4; i++) {
  3735. G[i].init = TRUE;
  3736. x = G[i].designation;
  3737. G[i].c1 = (x != tcsl) && cs_is_std(x);
  3738. x = G[i].def_designation;
  3739. G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  3740. }
  3741. #endif /* OS2 */
  3742. }
  3743. VOID
  3744. setremcharset(x, z) int x, z; {
  3745. int i;
  3746. #ifdef KUI
  3747. KuiSetProperty( KUI_TERM_REMCHARSET, (long) x, (long) z ) ;
  3748. #endif /* KUI */
  3749. #ifdef UNICODE
  3750. if (x == TX_TRANSP)
  3751. #else /* UNICODE */
  3752. if (x == FC_TRANSP)
  3753. #endif /* UNICODE */
  3754. { /* TRANSPARENT? */
  3755. #ifndef OS2
  3756. tcsr = tcsl; /* Make both sets the same */
  3757. #else /* OS2 */
  3758. #ifdef CKOUNI
  3759. tt_utf8 = 0; /* Turn off UTF8 flag */
  3760. tcsr = tcsl = dec_kbd = TX_TRANSP; /* No translation */
  3761. tcs_transp = 1;
  3762. if (!cs_is_nrc(tcsl)) {
  3763. G[0].def_designation = G[0].designation = TX_ASCII;
  3764. G[0].init = TRUE;
  3765. G[0].def_c1 = G[0].c1 = FALSE;
  3766. G[0].size = cs94;
  3767. G[0].national = FALSE;
  3768. }
  3769. for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  3770. G[i].def_designation = G[i].designation = tcsl;
  3771. G[i].init = TRUE;
  3772. G[i].def_c1 = G[i].c1 = FALSE;
  3773. switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  3774. case 128:
  3775. case 96:
  3776. G[i].size = G[i].def_size = cs96;
  3777. break;
  3778. case 94:
  3779. G[i].size = G[i].def_size = cs94;
  3780. break;
  3781. default:
  3782. G[i].size = G[i].def_size = csmb;
  3783. break;
  3784. }
  3785. G[i].national = cs_is_nrc(x);
  3786. }
  3787. #else /* CKOUNI */
  3788. tcsr = tcsl; /* Make both sets the same */
  3789. for (i = 0; i < 4; i++) {
  3790. G[i].def_designation = G[i].designation = FC_TRANSP;
  3791. G[i].init = FALSE;
  3792. G[i].size = G[i].def_size = cs96;
  3793. G[i].c1 = G[i].def_c1 = FALSE;
  3794. G[i].rtoi = NULL;
  3795. G[i].itol = NULL;
  3796. G[i].ltoi = NULL;
  3797. G[i].itor = NULL;
  3798. G[i].national = FALSE;
  3799. }
  3800. #endif /* CKOUNI */
  3801. #endif /* OS2 */
  3802. return;
  3803. }
  3804. #ifdef OS2
  3805. #ifdef CKOUNI
  3806. else if (x == TX_UTF8) {
  3807. tcs_transp = 0;
  3808. tt_utf8 = 1; /* Turn it on if we are UTF8 */
  3809. return;
  3810. }
  3811. #endif /* CKOUNI */
  3812. else {
  3813. tcs_transp = 0;
  3814. tcsr = x; /* Remote character set */
  3815. #ifdef CKOUNI
  3816. tt_utf8 = 0; /* Turn off UTF8 flag */
  3817. #endif /* CKOUNI */
  3818. if (z == TT_GR_ALL) {
  3819. int i;
  3820. #ifdef UNICODE
  3821. dec_kbd = x;
  3822. #endif /* UNICODE */
  3823. for (i = 0; i < 4; i++) {
  3824. G[i].init = TRUE;
  3825. if ( i == 0 && !cs_is_nrc(x) ) {
  3826. G[0].designation = G[0].def_designation = FC_USASCII;
  3827. G[0].size = G[0].def_size = cs94;
  3828. G[0].national = 1;
  3829. } else {
  3830. G[i].def_designation = G[i].designation = x;
  3831. switch (cs_size(x)) { /* 94, 96, or 128 */
  3832. case 128:
  3833. case 96:
  3834. G[i].size = G[i].def_size = cs96;
  3835. break;
  3836. case 94:
  3837. G[i].size = G[i].def_size = cs94;
  3838. break;
  3839. default:
  3840. G[i].size = G[i].def_size = csmb;
  3841. break;
  3842. }
  3843. G[i].national = cs_is_nrc(x);
  3844. }
  3845. G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  3846. }
  3847. #ifdef UNICODE
  3848. } else if (z == TT_GR_KBD) { /* Keyboard only */
  3849. dec_kbd = x;
  3850. #endif /* UNICODE */
  3851. } else { /* Specific Gn */
  3852. G[z].def_designation = G[z].designation = x;
  3853. G[z].init = TRUE;
  3854. switch (cs_size(x)) { /* 94, 96, or 128 */
  3855. case 128:
  3856. case 96:
  3857. G[z].size = G[z].def_size = cs96;
  3858. break;
  3859. case 94:
  3860. G[z].size = G[z].def_size = cs94;
  3861. break;
  3862. default:
  3863. G[z].size = G[z].def_size = csmb;
  3864. break;
  3865. }
  3866. G[z].c1 = G[z].def_c1 = x != tcsl && cs_is_std(x);
  3867. G[z].national = cs_is_nrc(x);
  3868. }
  3869. }
  3870. #else /* not OS2 */
  3871. tcsr = x; /* Remote character set */
  3872. #endif /* OS2 */
  3873. }
  3874. #endif /* NOCSETS */
  3875. VOID
  3876. setcmask(x) int x; {
  3877. if (x == 7) {
  3878. cmask = 0177;
  3879. } else if (x == 8) {
  3880. cmask = 0377;
  3881. parity = 0;
  3882. }
  3883. #ifdef KUI
  3884. KuiSetProperty(KUI_TERM_CMASK,x,0);
  3885. #endif /* KUI */
  3886. }
  3887. #ifdef CK_AUTODL
  3888. VOID
  3889. setautodl(x,y) int x,y; {
  3890. autodl = x;
  3891. adl_ask = y;
  3892. #ifdef KUI
  3893. KuiSetProperty(KUI_TERM_AUTODOWNLOAD,x?(y?2:1):0,0);
  3894. #endif /* KUI */
  3895. }
  3896. #endif /* CK_AUTODL */
  3897. #ifdef OS2
  3898. VOID
  3899. seturlhl(int x) {
  3900. tt_url_hilite = x;
  3901. #ifdef KUI
  3902. KuiSetProperty(KUI_TERM_URL_HIGHLIGHT,x,0);
  3903. #endif /* KUI */
  3904. }
  3905. VOID
  3906. setaprint(int x) {
  3907. extern int aprint;
  3908. aprint = x;
  3909. #ifdef KUI
  3910. KuiSetProperty(KUI_TERM_PRINTERCOPY,x,0);
  3911. #endif /* KUI */
  3912. }
  3913. #endif /* OS2 */
  3914. int
  3915. settrm() {
  3916. int i = 0;
  3917. #ifdef OS2
  3918. extern int colorreset, user_erasemode;
  3919. #endif /* OS2 */
  3920. if ((y = cmkey(trmtab,ntrm,"", "",xxstring)) < 0) return(y);
  3921. #ifdef MAC
  3922. printf("\n?Sorry, not implemented yet. Please use the Settings menu.\n");
  3923. return(-9);
  3924. #else
  3925. #ifdef IKSD
  3926. if (inserver) {
  3927. if ((y = cmcfm()) < 0) return(y);
  3928. printf("?Sorry, command disabled.\r\n");
  3929. return(success = 0);
  3930. }
  3931. #endif /* IKSD */
  3932. switch (y) {
  3933. case XYTBYT: /* SET TERMINAL BYTESIZE */
  3934. if ((y = cmnum("bytesize for terminal connection","8",10,&x,
  3935. xxstring)) < 0)
  3936. return(y);
  3937. if (x != 7 && x != 8) {
  3938. printf("\n?The choices are 7 and 8\n");
  3939. return(success = 0);
  3940. }
  3941. if ((y = cmcfm()) < 0) return(y);
  3942. setcmask(x);
  3943. #ifdef OS2
  3944. if (IS97801(tt_type_mode))
  3945. SNI_bitmode(x);
  3946. #endif /* OS2 */
  3947. return(success = 1);
  3948. case XYTSO: /* SET TERMINAL LOCKING-SHIFT */
  3949. return(seton(&sosi));
  3950. case XYTNL: /* SET TERMINAL NEWLINE-MODE */
  3951. return(seton(&tnlm));
  3952. #ifdef OS2
  3953. case XYTCOL:
  3954. if ((x = cmkey(ttycoltab,ncolors,"","terminal",xxstring)) < 0)
  3955. return(x);
  3956. else if (x == TTCOLRES) {
  3957. if ((y = cmkey(ttcolmodetab,ncolmode,
  3958. "","default-color",xxstring)) < 0)
  3959. return(y);
  3960. if ((z = cmcfm()) < 0)
  3961. return(z);
  3962. colorreset = y;
  3963. return(success = 1);
  3964. } else if (x == TTCOLERA) {
  3965. if ((y = cmkey(ttcolmodetab,ncolmode,"",
  3966. "current-color",xxstring)) < 0)
  3967. return(y);
  3968. if ((z = cmcfm()) < 0)
  3969. return(z);
  3970. user_erasemode = y;
  3971. return(success=1);
  3972. } else { /* No parse error */
  3973. int fg = 0, bg = 0;
  3974. fg = cmkey(ttyclrtab, nclrs,
  3975. (x == TTCOLBOR ?
  3976. "color for screen border" :
  3977. "foreground color and then background color"),
  3978. "lgray", xxstring);
  3979. if (fg < 0)
  3980. return(fg);
  3981. if (x != TTCOLBOR) {
  3982. if ((bg = cmkey(ttyclrtab,nclrs,
  3983. "background color","blue",xxstring)) < 0)
  3984. return(bg);
  3985. }
  3986. if ((y = cmcfm()) < 0)
  3987. return(y);
  3988. switch (x) {
  3989. case TTCOLNOR:
  3990. colornormal = fg | bg << 4;
  3991. fgi = fg & 0x08;
  3992. bgi = bg & 0x08;
  3993. break;
  3994. case TTCOLREV:
  3995. colorreverse = fg | bg << 4;
  3996. break;
  3997. case TTCOLITA:
  3998. coloritalic = fg | bg << 4;
  3999. break;
  4000. case TTCOLUND:
  4001. colorunderline = fg | bg << 4;
  4002. break;
  4003. case TTCOLGRP:
  4004. colorgraphic = fg | bg << 4;
  4005. break;
  4006. case TTCOLDEB:
  4007. colordebug = fg | bg << 4;
  4008. break;
  4009. case TTCOLSTA:
  4010. colorstatus = fg | bg << 4;
  4011. break;
  4012. case TTCOLHLP:
  4013. colorhelp = fg | bg << 4;
  4014. break;
  4015. case TTCOLBOR:
  4016. colorborder = fg;
  4017. break;
  4018. case TTCOLSEL:
  4019. colorselect = fg | bg << 4;
  4020. break;
  4021. default:
  4022. printf("%s - invalid\n",cmdbuf);
  4023. return(-9);
  4024. break;
  4025. }
  4026. scrninitialized[VTERM] = 0;
  4027. VscrnInit(VTERM);
  4028. }
  4029. return(success = 1);
  4030. case XYTCUR: { /* SET TERMINAL CURSOR */
  4031. extern int cursorena[];
  4032. extern int cursoron[] ; /* Cursor state on/off */
  4033. if ((x = cmkey(ttycurtab,ncursors,"","underline",xxstring)) < 0)
  4034. return(x);
  4035. if ((z = cmkey(curontab,ncuron,"","on",xxstring)) < 0)
  4036. return(z);
  4037. if ((y = cmcfm()) < 0) return(y);
  4038. tt_cursor = tt_cursor_usr = x;
  4039. if ( z == 2 ) {
  4040. cursorena[VTERM] = tt_cursorena_usr = 1;
  4041. tt_cursor_blink = 0;
  4042. } else {
  4043. cursorena[VTERM] = tt_cursorena_usr = z;/* turn cursor on/off */
  4044. tt_cursor_blink = 1;
  4045. }
  4046. cursoron[VTERM] = FALSE; /* Force newcursor to restore the cursor */
  4047. return(success = 1);
  4048. }
  4049. #endif /* OS2 */
  4050. case XYTTYP: /* SET TERMINAL TYPE */
  4051. return(settrmtyp());
  4052. #ifdef OS2
  4053. case XYTARR: /* SET TERMINAL ARROW-KEYS */
  4054. if ((x = cmkey(akmtab,2,"","",xxstring)) < 0) return(x);
  4055. if ((y = cmcfm()) < 0) return(y);
  4056. tt_arrow = x; /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4057. return(success = 1);
  4058. case XYTKPD: /* SET TERMINAL KEYPAD-MODE */
  4059. if ((x = cmkey(kpmtab,2,"","",xxstring)) < 0) return(x);
  4060. if ((y = cmcfm()) < 0) return(y);
  4061. tt_keypad = x; /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4062. return(success = 1);
  4063. case XYTUNX: { /* SET TERM UNIX-MODE (DG) */
  4064. extern int dgunix,dgunix_usr;
  4065. x = seton(&dgunix);
  4066. dgunix_usr = dgunix;
  4067. return(x);
  4068. }
  4069. case XYTKBMOD: { /* SET TERM KEYBOARD MODE */
  4070. extern int tt_kb_mode;
  4071. if ((x = cmkey(kbmodtab,
  4072. nkbmodtab,
  4073. "normal",
  4074. "special keyboard mode for terminal emulation",
  4075. xxstring)
  4076. ) < 0)
  4077. return(x);
  4078. if ((y = cmcfm()) < 0) return(y);
  4079. tt_kb_mode = x;
  4080. return(success = 1);
  4081. }
  4082. case XYTWRP: /* SET TERMINAL WRAP */
  4083. return(seton(&tt_wrap));
  4084. case XYSCRS:
  4085. if ((y = cmnum("CONNECT scrollback buffer size, lines","2000",10,&x,
  4086. xxstring)) < 0)
  4087. return(y);
  4088. /* The max number of lines is the RAM */
  4089. /* we can actually dedicate to a */
  4090. /* scrollback buffer given the maximum */
  4091. /* process memory space of 512MB */
  4092. if (x < 256 || x > 2000000L) {
  4093. printf("\n?The size must be between 256 and 2,000,000.\n");
  4094. return(success = 0);
  4095. }
  4096. if ((y = cmcfm()) < 0) return(y);
  4097. tt_scrsize[VTERM] = x;
  4098. VscrnInit(VTERM);
  4099. return(success = 1);
  4100. #endif /* OS2 */
  4101. #ifndef NOCSETS
  4102. case XYTCS: { /* SET TERMINAL CHARACTER-SET */
  4103. int eol;
  4104. /* set terminal character-set <remote> <local> */
  4105. if ((x = cmkey(
  4106. #ifdef CKOUNI
  4107. txrtab,ntxrtab,
  4108. #else /* CKOUNI */
  4109. ttcstab,ntermc,
  4110. #endif /* CKOUNI */
  4111. "remote terminal character-set","",xxstring)) < 0)
  4112. return(x);
  4113. #ifdef UNICODE
  4114. if (x == TX_TRANSP
  4115. #ifdef CKOUNI
  4116. || x == TX_UTF8
  4117. #endif /* CKOUNI */
  4118. ) {
  4119. if ((y = cmcfm()) < 0) /* Confirm the command */
  4120. return(y);
  4121. #ifdef OS2
  4122. if ( isunicode() && x == TX_TRANSP ) {
  4123. /* If we are in unicode display mode then transparent
  4124. * only affects the output direction. We need to know
  4125. * the actual remote character set in order to perform
  4126. * the tcsr -> ucs2 translation for display.
  4127. */
  4128. x = y = tcsl;
  4129. } else
  4130. #endif /* OS2 */
  4131. y = x;
  4132. }
  4133. #else /* UNICODE */
  4134. if (x == FC_TRANSP) {
  4135. if ((y = cmcfm()) < 0) /* Confirm the command */
  4136. return(y);
  4137. y = x;
  4138. }
  4139. #endif /* UNICODE */
  4140. /* Not transparent or UTF8, so get local set to translate it into */
  4141. s = "";
  4142. #ifdef OS2
  4143. y = os2getcp(); /* Default is current code page */
  4144. switch (y) {
  4145. case 437: s = "cp437"; break;
  4146. case 850: s = "cp850"; break;
  4147. case 852: s = "cp852"; break;
  4148. case 857: s = "cp857"; break;
  4149. case 858: s = "cp858"; break;
  4150. case 862: s = "cp862"; break;
  4151. case 866: s = "cp866"; break;
  4152. case 869: s = "cp869"; break;
  4153. case 1250: s = "cp1250"; break;
  4154. case 1251: s = "cp1251"; break;
  4155. case 1252: s = "cp1252"; break;
  4156. case 1253: s = "cp1253"; break;
  4157. case 1254: s = "cp1254"; break;
  4158. case 1255: s = "cp1255"; break;
  4159. case 1256: s = "cp1256"; break;
  4160. case 1257: s = "cp1257"; break;
  4161. case 1258: s = "cp1258"; break;
  4162. }
  4163. #ifdef PCFONTS
  4164. /*
  4165. If the user has loaded a font with SET TERMINAL FONT then we want
  4166. to change the default code page to the font that was loaded.
  4167. */
  4168. if (tt_font != TTF_ROM) {
  4169. for (y = 0; y < ntermfont; y++ ) {
  4170. if (term_font[y].kwval == tt_font) {
  4171. s = term_font[y].kwd;
  4172. break;
  4173. }
  4174. }
  4175. }
  4176. #endif /* PCFONTS */
  4177. #else /* Not K95... */
  4178. s = fcsinfo[fcharset].keyword;
  4179. #endif /* OS2 */
  4180. if ((y = cmkey(
  4181. #ifdef CKOUNI
  4182. txrtab,ntxrtab,
  4183. #else /* CKOUNI */
  4184. ttcstab,ntermc,
  4185. #endif /* CKOUNI */
  4186. "local character-set",s,xxstring)) < 0)
  4187. return(y);
  4188. #ifdef UNICODE
  4189. if (y == TX_UTF8) {
  4190. printf("?UTF8 may not be used as a local character set.\r\n");
  4191. return(-9);
  4192. }
  4193. #endif /* UNICODE */
  4194. #ifdef OS2
  4195. if ((z = cmkey(graphsettab,ngraphset,
  4196. "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4197. return(z);
  4198. #endif /* OS2 */
  4199. if ((eol = cmcfm()) < 0)
  4200. return(eol); /* Confirm the command */
  4201. /* End of command parsing - actions begin */
  4202. setlclcharset(y);
  4203. setremcharset(x,z);
  4204. return(success = 1);
  4205. }
  4206. #endif /* NOCSETS */
  4207. #ifndef NOCSETS
  4208. case XYTLCS: /* SET TERMINAL LOCAL-CHARACTER-SET */
  4209. /* set terminal character-set <local> */
  4210. s = getdcset(); /* Get display character-set name */
  4211. if ((y = cmkey(
  4212. #ifdef CKOUNI
  4213. txrtab,ntxrtab,
  4214. #else /* CKOUNI */
  4215. fcstab,nfilc,
  4216. #endif /* CKOUNI */
  4217. "local character-set",s,xxstring)) < 0)
  4218. return(y);
  4219. #ifdef UNICODE
  4220. if (y == TX_UTF8) {
  4221. printf("?UTF8 may not be used as a local character set.\r\n");
  4222. return(-9);
  4223. }
  4224. #endif /* UNICODE */
  4225. if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4226. /* End of command parsing - action begins */
  4227. setlclcharset(y);
  4228. return(success = 1);
  4229. #endif /* NOCSETS */
  4230. #ifndef NOCSETS
  4231. #ifdef UNICODE
  4232. case XYTUNI: /* SET TERMINAL UNICODE */
  4233. return(seton(&tt_unicode));
  4234. #endif /* UNICODE */
  4235. case XYTRCS: /* SET TERMINAL REMOTE-CHARACTER-SET */
  4236. /* set terminal character-set <remote> <Graphic-set> */
  4237. if ((x = cmkey(
  4238. #ifdef CKOUNI
  4239. txrtab, ntxrtab,
  4240. #else /* CKOUNI */
  4241. ttcstab,ntermc,
  4242. #endif /* CKOUNI */
  4243. "remote terminal character-set","",xxstring)) < 0)
  4244. return(x);
  4245. #ifdef UNICODE
  4246. if (x == TX_TRANSP
  4247. #ifdef CKOUNI
  4248. || x == TX_UTF8
  4249. #endif /* CKOUNI */
  4250. ) {
  4251. if ((y = cmcfm()) < 0) /* Confirm the command */
  4252. return(y);
  4253. #ifdef OS2
  4254. if ( isunicode() && x == TX_TRANSP ) {
  4255. /* If we are in unicode display mode then transparent
  4256. * only affects the output direction. We need to know
  4257. * the actual remote character set in order to perform
  4258. * the tcsr -> ucs2 translation for display.
  4259. */
  4260. x = tcsl;
  4261. }
  4262. #endif /* OS2 */
  4263. }
  4264. #else /* UNICODE */
  4265. if (x == FC_TRANSP) {
  4266. if ((y = cmcfm()) < 0) /* Confirm the command */
  4267. return(y);
  4268. }
  4269. #endif /* UNICODE */
  4270. else {
  4271. #ifdef OS2
  4272. if ((z = cmkey(graphsettab,ngraphset,
  4273. "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4274. return(z);
  4275. #endif /* OS2 */
  4276. if ((y = cmcfm()) < 0) /* Confirm the command */
  4277. return(y);
  4278. }
  4279. /* Command parsing ends here */
  4280. setremcharset(x,z);
  4281. return(success = 1);
  4282. #endif /* NOCSETS */
  4283. case XYTEC: /* SET TERMINAL ECHO */
  4284. if ((x = cmkey(rltab,nrlt,"which side echos during CONNECT",
  4285. "remote", xxstring)) < 0) return(x);
  4286. if ((y = cmcfm()) < 0) return(y);
  4287. #ifdef NETCONN
  4288. oldplex = x;
  4289. #endif /* NETCONN */
  4290. duplex = x;
  4291. return(success = 1);
  4292. case XYTESC: /* SET TERM ESC */
  4293. if ((x = cmkey(nabltab,nnabltab,"","enabled",xxstring)) < 0)
  4294. return(x);
  4295. if ((y = cmcfm()) < 0) return(y);
  4296. tt_escape = x;
  4297. return(1);
  4298. case XYTCRD: /* SET TERMINAL CR-DISPLAY */
  4299. if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4300. if ((y = cmcfm()) < 0) return(y);
  4301. tt_crd = x;
  4302. return(success = 1);
  4303. case XYTLFD: /* SET TERMINAL LF-DISPLAY */
  4304. if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4305. if ((y = cmcfm()) < 0) return(y);
  4306. tt_lfd = x;
  4307. return(success = 1);
  4308. #ifdef OS2
  4309. case XYTANS: { /* SET TERMINAL ANSWERBACK */
  4310. /*
  4311. NOTE: We let them enable and disable the answerback sequence, but we
  4312. do NOT let them change it, and we definitely do not let the host set it.
  4313. This is a security feature.
  4314. As of 1.1.8 we allow the SET TERM ANSWERBACK MESSAGE <string> to be
  4315. used just as MS-DOS Kermit does. C0 and C1 controls as well as DEL
  4316. are not allowed to be used as characters. They are translated to
  4317. underscore. This may not be set by APC.
  4318. */
  4319. if ((x = cmkey(anbktab,nansbk,"", "off", xxstring)) < 0)
  4320. return(x);
  4321. if (x < 2) {
  4322. if ((y = cmcfm()) < 0)
  4323. return(y);
  4324. tt_answer = x;
  4325. return(success = 1);
  4326. } else if ( x == 2 || x == 3) {
  4327. int len = 0;
  4328. extern int safeanswerbk;
  4329. extern char useranswerbk[];
  4330. if ((y = cmtxt("Answerback extension","",&s,xxstring)) < 0)
  4331. return(y);
  4332. if (apcactive == APC_LOCAL ||
  4333. (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4334. return(success = 0);
  4335. len = strlen(s);
  4336. if (x == 2) {
  4337. /* Safe Answerback's don't have C0/C1 chars */
  4338. for (z = 0; z < len; z++) {
  4339. if ((s[z] & 0x7F) <= SP || (s[z] & 0x7F) == DEL)
  4340. useranswerbk[z] = '_';
  4341. else
  4342. useranswerbk[z] = s[z];
  4343. }
  4344. useranswerbk[z] = '\0';
  4345. safeanswerbk = 1 ; /* TRUE */
  4346. } else {
  4347. ckstrncpy(useranswerbk,s,60); /* (see ckocon.c) */
  4348. safeanswerbk = 0; /* FALSE */
  4349. }
  4350. updanswerbk();
  4351. return(success = 1);
  4352. } else
  4353. return(success = 0);
  4354. }
  4355. #endif /* OS2 */
  4356. #ifdef CK_APC
  4357. case XYTAPC:
  4358. if ((y = cmkey(apctab,napctab,
  4359. "application program command execution","",
  4360. xxstring)) < 0)
  4361. return(y);
  4362. if ((x = cmcfm()) < 0)
  4363. return(x);
  4364. if (apcactive == APC_LOCAL ||
  4365. (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4366. return(success = 0);
  4367. apcstatus = y;
  4368. return(success = 1);
  4369. #ifdef CK_AUTODL
  4370. case XYTAUTODL: /* AUTODOWNLOAD */
  4371. if ((y = cmkey(adltab,nadltab,"Auto-download options","",
  4372. xxstring)) < 0)
  4373. return(y);
  4374. switch (y) {
  4375. case TAD_ON:
  4376. case TAD_OFF:
  4377. if ((x = cmcfm()) < 0)
  4378. return(x);
  4379. setautodl(y,0);
  4380. break;
  4381. case TAD_ASK:
  4382. if ((x = cmcfm()) < 0)
  4383. return(x);
  4384. setautodl(TAD_ON,1);
  4385. break;
  4386. case TAD_ERR:
  4387. if ((y = cmkey(adlerrtab,nadlerrtab,"","", xxstring)) < 0)
  4388. return(y);
  4389. if ((x = cmcfm()) < 0)
  4390. return(x);
  4391. adl_err = y;
  4392. break;
  4393. #ifdef OS2
  4394. case TAD_K:
  4395. if ((y = cmkey(adlxtab,nadlxtab,"","", xxstring)) < 0)
  4396. return(y);
  4397. switch (y) {
  4398. case TAD_X_C0:
  4399. if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4400. "processed-by-emulator",xxstring)) < 0)
  4401. return(y);
  4402. if ((x = cmcfm()) < 0)
  4403. return(x);
  4404. adl_kc0 = y;
  4405. break;
  4406. case TAD_X_DETECT:
  4407. if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4408. return(y);
  4409. if ((x = cmcfm()) < 0)
  4410. return(x);
  4411. adl_kmode = y;
  4412. break;
  4413. case TAD_X_STR:
  4414. if ((y = cmtxt("Kermit start string","KERMIT READY TO SEND...",
  4415. &s,xxstring)) < 0)
  4416. return(y);
  4417. free(adl_kstr);
  4418. adl_kstr = strdup(s);
  4419. break;
  4420. }
  4421. break;
  4422. case TAD_Z:
  4423. if ((y = cmkey(adlxtab,nadlxtab,"","",xxstring)) < 0)
  4424. return(y);
  4425. switch (y) {
  4426. case TAD_X_C0:
  4427. if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4428. "processed-by-emulator",xxstring)) < 0)
  4429. return(y);
  4430. if ((x = cmcfm()) < 0)
  4431. return(x);
  4432. adl_zc0 = y;
  4433. break;
  4434. case TAD_X_DETECT:
  4435. if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4436. return(y);
  4437. if ((x = cmcfm()) < 0)
  4438. return(x);
  4439. adl_zmode = y;
  4440. break;
  4441. case TAD_X_STR:
  4442. if ((y = cmtxt("","rz\\{13}",&s,xxstring)) < 0)
  4443. return(y);
  4444. free(adl_zstr);
  4445. adl_zstr = strdup(s);
  4446. break;
  4447. }
  4448. break;
  4449. #endif /* OS2 */
  4450. }
  4451. return(success = 1);
  4452. #endif /* CK_AUTODL */
  4453. #endif /* CK_APC */
  4454. #ifdef OS2
  4455. case XYTBEL:
  4456. return(success = setbell());
  4457. case XYTMBEL: /* MARGIN-BELL */
  4458. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4459. if (y) { /* ON */
  4460. if ((z = cmnum("Column at which to set margin bell",
  4461. "72",10,&x,xxstring)) < 0)
  4462. return(z);
  4463. }
  4464. if ((z = cmcfm()) < 0) return(z);
  4465. marginbell = y;
  4466. marginbellcol = x;
  4467. return(success = 1);
  4468. #endif /* OS2 */
  4469. #ifdef CKTIDLE
  4470. case XYTIDLE: /* IDLE-SEND */
  4471. case XYTITMO: /* IDLE-TIMEOUT */
  4472. if ((z = cmnum("seconds of idle time to wait, or 0 to disable",
  4473. "0",10,&x,xxstring)) < 0)
  4474. return(z);
  4475. if (y == XYTIDLE) {
  4476. if ((y = cmtxt("string to send, may contain kverbs and variables",
  4477. "\\v(newline)",&s,xxstring)) < 0)
  4478. return(y);
  4479. tt_idlesnd_tmo = x; /* (old) */
  4480. tt_idlelimit = x; /* (new) */
  4481. makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4482. tt_idlesnd_str = tt_idlestr; /* (old) */
  4483. tt_idleact = IDLE_OUT; /* (new) */
  4484. } else {
  4485. if ((y = cmcfm()) < 0)
  4486. return(y);
  4487. tt_idlelimit = x;
  4488. }
  4489. #ifdef OS2
  4490. puterror(VTERM);
  4491. #endif /* OS2 */
  4492. return(success = 1);
  4493. case XYTIACT: { /* SET TERM IDLE-ACTION */
  4494. if ((y = cmkey(idlacts,nidlacts,"","",xxstring)) < 0)
  4495. return(y);
  4496. if (y == IDLE_OUT) {
  4497. if ((x = cmtxt("string to send, may contain kverbs and variables"
  4498. , "",&s,xxstring)) < 0)
  4499. return(x);
  4500. makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4501. tt_idlesnd_str = tt_idlestr; /* (old) */
  4502. } else {
  4503. if ((x = cmcfm()) < 0)
  4504. return(x);
  4505. }
  4506. tt_idleact = y;
  4507. return(success = 1);
  4508. }
  4509. #endif /* CKTIDLE */
  4510. case XYTDEB: /* TERMINAL DEBUG */
  4511. y = seton(&x); /* Go parse ON or OFF */
  4512. if (y > 0) /* Command succeeded? */
  4513. setdebses(x);
  4514. return(y);
  4515. #ifdef OS2
  4516. case XYTASCRL: /* SET TERMINAL AUTOSCROLL */
  4517. y = seton(&autoscroll);
  4518. return(y);
  4519. case XYTAPAGE: /* SET TERMINAL AUTOPAGE */
  4520. y = seton(&wy_autopage);
  4521. return(y);
  4522. case XYTROL: /* SET TERMINAL ROLL */
  4523. if ((y = cmkey(rolltab,nroll,"scrollback mode","insert",xxstring))<0)
  4524. return(y);
  4525. if (y == TTR_KEYS) {
  4526. if ((x = cmkey(rollkeytab,nrollkey,"","send",xxstring))<0)
  4527. return(x);
  4528. if ((z = cmcfm()) < 0) return(z);
  4529. tt_rkeys[VTERM] = x;
  4530. } else {
  4531. if ((x = cmcfm()) < 0) return(x);
  4532. tt_roll[VTERM] = y;
  4533. }
  4534. return(success = 1);
  4535. case XYTCTS: /* SET TERMINAL TRANSMIT-TIMEOUT */
  4536. y = cmnum("Maximum seconds to allow CTS off during CONNECT",
  4537. "5",10,&x,xxstring);
  4538. return(setnum(&tt_ctstmo,x,y,10000));
  4539. case XYTCPG: { /* SET TERMINAL CODE-PAGE */
  4540. int i;
  4541. int cp = -1;
  4542. y = cmnum("PC code page to use during terminal emulation",
  4543. ckitoa(os2getcp()),10,&x,xxstring);
  4544. if ((x = setnum(&cp,x,y,11000)) < 0) return(x);
  4545. if (os2setcp(cp) != 1) {
  4546. #ifdef NT
  4547. if (isWin95())
  4548. printf(
  4549. "Sorry, Windows 95 does not support code page switching\n");
  4550. else
  4551. #endif /* NT */
  4552. printf(
  4553. "Sorry, %d is not a valid code page for this system.\n",cp);
  4554. return(-9);
  4555. }
  4556. /* Force the terminal character-sets conversions to be updated */
  4557. for ( i = 0; i < 4; i++ )
  4558. G[i].init = TRUE;
  4559. return(1);
  4560. }
  4561. case XYTPAC: /* SET TERMINAL OUTPUT-PACING */
  4562. y = cmnum(
  4563. "Pause between sending each character during CONNECT, milliseconds",
  4564. "-1",10,&x,xxstring);
  4565. return(setnum(&tt_pacing,x,y,10000));
  4566. #ifdef OS2MOUSE
  4567. case XYTMOU: { /* SET TERMINAL MOUSE */
  4568. int old_mou = tt_mouse;
  4569. if ((x = seton(&tt_mouse)) < 0)
  4570. return(x);
  4571. if (tt_mouse != old_mou)
  4572. if (tt_mouse)
  4573. os2_mouseon();
  4574. else
  4575. os2_mouseoff();
  4576. return(1);
  4577. }
  4578. #endif /* OS2MOUSE */
  4579. #endif /* OS2 */
  4580. case XYTWID: {
  4581. if ((y = cmnum(
  4582. #ifdef OS2
  4583. "number of columns in display window during CONNECT",
  4584. #else
  4585. "number of columns on your screen",
  4586. #endif /* OS2 */
  4587. "80",10,&x,xxstring)) < 0)
  4588. return(y);
  4589. if ((y = cmcfm()) < 0) return(y);
  4590. #ifdef OS2
  4591. return(success = os2_settermwidth(x));
  4592. #else /* Not OS/2 */
  4593. tt_cols = x;
  4594. return(success = 1);
  4595. #endif /* OS2 */
  4596. }
  4597. case XYTHIG:
  4598. if ((y = cmnum(
  4599. #ifdef OS2
  4600. "number of rows in display window during CONNECT, not including status line",
  4601. tt_status[VTERM]?"24":"25",
  4602. #else
  4603. "24","number of rows on your screen",
  4604. #endif /* OS2 */
  4605. 10,&x,xxstring)) < 0)
  4606. return(y);
  4607. if ((y = cmcfm()) < 0) return(y);
  4608. #ifdef OS2
  4609. return (success = os2_settermheight(x));
  4610. #else /* Not OS/2 */
  4611. tt_rows = x;
  4612. return(success = 1);
  4613. #endif /* OS2 */
  4614. #ifdef OS2
  4615. case XYTPRN: { /* Print Mode */
  4616. extern bool xprint, aprint, cprint, uprint;
  4617. if ((y = cmkey(prnmtab,nprnmtab,"","off", xxstring)) < 0) return(y);
  4618. if ((x = cmcfm()) < 0) return(x);
  4619. switch (y) {
  4620. case 0:
  4621. if (cprint || uprint || aprint || xprint)
  4622. printeroff();
  4623. cprint = xprint = uprint = 0;
  4624. setaprint(0);
  4625. break;
  4626. case 1:
  4627. if (!(cprint || uprint || aprint || xprint))
  4628. printeron();
  4629. setaprint(1);
  4630. cprint = xprint = uprint = 0;
  4631. break;
  4632. case 2:
  4633. if (!(cprint || uprint || aprint || xprint))
  4634. printeron();
  4635. cprint = 1;
  4636. setaprint(0);
  4637. xprint = uprint = 0;
  4638. break;
  4639. case 3:
  4640. if (!(cprint || uprint || aprint || xprint))
  4641. printeron();
  4642. uprint = 1;
  4643. setaprint(0);
  4644. xprint = cprint = 0;
  4645. break;
  4646. }
  4647. return(1);
  4648. }
  4649. #else
  4650. #ifdef XPRINT
  4651. case XYTPRN: {
  4652. extern int tt_print;
  4653. if ((x = seton(&tt_print)) < 0)
  4654. return(x);
  4655. return(success = 1);
  4656. }
  4657. #endif /* XPRINT */
  4658. #endif /* OS2 */
  4659. #ifdef OS2
  4660. case XYTSCNM: {
  4661. extern int decscnm, decscnm_usr;
  4662. if ((y = cmkey(normrev,4,"",
  4663. decscnm_usr?"reverse":"normal",
  4664. xxstring)
  4665. ) < 0)
  4666. return(y);
  4667. if ((x = cmcfm()) < 0) return(x);
  4668. decscnm_usr = y;
  4669. if (decscnm != decscnm_usr)
  4670. flipscreen(VTERM);
  4671. return(1);
  4672. }
  4673. case XYTOPTI:
  4674. if ((y = cmkey(onoff,2,"",tt_diff_upd?"on":"off",
  4675. xxstring)) < 0) return(y);
  4676. if ((x = cmcfm()) < 0) return(x);
  4677. tt_diff_upd = y;
  4678. return(1);
  4679. case XYTUPD: {
  4680. int mode, delay;
  4681. if ((mode = cmkey(scrnupd,nscrnupd,"","fast",xxstring)) < 0) {
  4682. return(mode);
  4683. } else {
  4684. y = cmnum(
  4685. "Pause between FAST screen updates in CONNECT mode, milliseconds",
  4686. "100",10,&x,xxstring
  4687. );
  4688. if (x < 0 || x > 1000 ) {
  4689. printf(
  4690. "\n?The update rate must be between 0 and 1000 milliseconds.\n"
  4691. );
  4692. return(success = 0);
  4693. }
  4694. if ((y = cmcfm()) < 0) return(y);
  4695. updmode = tt_updmode = mode;
  4696. return(setnum(&tt_update,x,y,10000));
  4697. }
  4698. }
  4699. case XYTCTRL:
  4700. if ((x = cmkey(termctrl,ntermctrl,"","7",xxstring)) < 0) {
  4701. return(x);
  4702. } else {
  4703. if ((y = cmcfm()) < 0)
  4704. return(y);
  4705. switch ( x ) {
  4706. case 8:
  4707. send_c1 = send_c1_usr = TRUE;
  4708. break;
  4709. case 7:
  4710. default:
  4711. send_c1 = send_c1_usr = FALSE;
  4712. break;
  4713. }
  4714. }
  4715. return(success = TRUE);
  4716. break;
  4717. #ifdef PCFONTS
  4718. case XYTFON:
  4719. if ( !IsOS2FullScreen() ) {
  4720. printf(
  4721. "\n?SET TERMINAL FONT is only supported in Full Screen sessions.\n");
  4722. return(success = FALSE);
  4723. }
  4724. if ((x = cmkey(term_font,ntermfont,"","default",xxstring)) < 0) {
  4725. return(x);
  4726. } else {
  4727. if ((y = cmcfm()) < 0) return(y);
  4728. if ( !os2LoadPCFonts() ) {
  4729. tt_font = x;
  4730. return(success = TRUE);
  4731. } else {
  4732. printf(
  4733. "\n?PCFONTS.DLL is not available in CKERMIT executable directory.\n");
  4734. return(success = FALSE);
  4735. }
  4736. }
  4737. break;
  4738. #else /* PCFONTS */
  4739. #ifdef NT
  4740. #ifdef KUI
  4741. case XYTFON:
  4742. return(setguifont()); /* ckuus3.c */
  4743. #endif /* KUI */
  4744. #endif /* NT */
  4745. #endif /* PCFONTS */
  4746. case XYTVCH: {
  4747. extern int pheight, marginbot, cmd_rows, cmd_cols;
  4748. if ((x = cmkey(tvctab,ntvctab,"",isWin95()?"win95-safe":"enabled",
  4749. xxstring)) < 0)
  4750. return(x);
  4751. if ((y = cmcfm()) < 0) return(y);
  4752. #ifndef KUI
  4753. if (x != tt_modechg) {
  4754. switch (x) {
  4755. case TVC_DIS:
  4756. /* When disabled the heights of all of the virtual screens */
  4757. /* must be equal to the physical height of the console */
  4758. /* window and may not be changed. */
  4759. /* The width of the window may not be altered. */
  4760. tt_modechg = TVC_ENA; /* Temporary */
  4761. if (marginbot > pheight-(tt_status[VTERM]?1:0))
  4762. marginbot = pheight-(tt_status[VTERM]?1:0);
  4763. tt_szchng[VCMD] = 1 ;
  4764. tt_rows[VCMD] = pheight;
  4765. VscrnInit(VCMD);
  4766. SetCols(VCMD);
  4767. cmd_rows = y;
  4768. tt_szchng[VTERM] = 2 ;
  4769. tt_rows[VTERM] = pheight - (tt_status[VTERM]?1:0);
  4770. VscrnInit(VTERM);
  4771. break;
  4772. case TVC_ENA:
  4773. /* When enabled the physical height of the console windows */
  4774. /* should be adjusted to the height of the virtual screen */
  4775. /* The width may be set to anything. */
  4776. /* nothing to do */
  4777. break;
  4778. case TVC_W95:
  4779. /* Win95-safe mode allows the physical height to change */
  4780. /* but restricts it to a width of 80 and a height equal to */
  4781. /* 25, 43, or 50. Must be adjusted now. */
  4782. /* The virtual heights must be equal to the above. */
  4783. if (pheight != 25 && pheight != 43 && pheight != 50) {
  4784. if (pheight < 25)
  4785. y = 25;
  4786. else if (pheight < 43)
  4787. y = 43;
  4788. else
  4789. y = 50;
  4790. } else
  4791. y = pheight;
  4792. tt_modechg = TVC_ENA; /* Temporary */
  4793. tt_szchng[VCMD] = 1;
  4794. tt_rows[VCMD] = y;
  4795. tt_cols[VCMD] = 80;
  4796. VscrnInit(VCMD);
  4797. SetCols(VCMD);
  4798. cmd_rows = y;
  4799. cmd_cols = 80;
  4800. marginbot = y-(tt_status[VTERM]?1:0);
  4801. tt_szchng[VTERM] = 2;
  4802. tt_rows[VTERM] = y - (tt_status[VTERM]?1:0);
  4803. tt_cols[VTERM] = 80;
  4804. VscrnInit(VTERM);
  4805. break;
  4806. }
  4807. tt_modechg = x;
  4808. }
  4809. return(success = 1);
  4810. #else
  4811. return(success = 0);
  4812. #endif /* KUI */
  4813. }
  4814. case XYTSTAT: {
  4815. extern int marginbot;
  4816. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4817. if ((x = cmcfm()) < 0) return(x);
  4818. if (y != tt_status[VTERM] || y != tt_status_usr[VTERM]) {
  4819. /* Might need to fixup the margins */
  4820. if ( marginbot == VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  4821. if (y) {
  4822. marginbot--;
  4823. } else {
  4824. marginbot++;
  4825. }
  4826. tt_status_usr[VTERM] = tt_status[VTERM] = y;
  4827. if (y) {
  4828. tt_szchng[VTERM] = 2;
  4829. tt_rows[VTERM]--;
  4830. VscrnInit(VTERM); /* Height set here */
  4831. #ifdef TNCODE
  4832. if (TELOPT_ME(TELOPT_NAWS))
  4833. tn_snaws();
  4834. #endif /* TNCODE */
  4835. #ifdef RLOGCODE
  4836. if (TELOPT_ME(TELOPT_NAWS))
  4837. rlog_naws();
  4838. #endif /* RLOGCODE */
  4839. #ifdef SSHBUILTIN
  4840. if (TELOPT_ME(TELOPT_NAWS))
  4841. ssh_snaws();
  4842. #endif /* SSHBUILTIN */
  4843. } else {
  4844. tt_szchng[VTERM] = 1;
  4845. tt_rows[VTERM]++;
  4846. VscrnInit(VTERM); /* Height set here */
  4847. #ifdef TNCODE
  4848. if (TELOPT_ME(TELOPT_NAWS))
  4849. tn_snaws();
  4850. #endif /* TNCODE */
  4851. #ifdef RLOGCODE
  4852. if (TELOPT_ME(TELOPT_NAWS))
  4853. rlog_naws();
  4854. #endif /* RLOGCODE */
  4855. #ifdef SSHBUILTIN
  4856. if (TELOPT_ME(TELOPT_NAWS))
  4857. ssh_snaws();
  4858. #endif /* SSHBUILTIN */
  4859. }
  4860. }
  4861. return(1);
  4862. }
  4863. #endif /* OS2 */
  4864. #ifdef NT
  4865. case XYTATTBUG:
  4866. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4867. if ((x = cmcfm()) < 0) return(x);
  4868. tt_attr_bug = y;
  4869. return(1);
  4870. #endif /* NT */
  4871. #ifdef OS2
  4872. case XYTSGRC:
  4873. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4874. if ((x = cmcfm()) < 0) return(x);
  4875. sgrcolors = y;
  4876. return(1);
  4877. case XYTSEND:
  4878. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4879. if ((x = cmcfm()) < 0) return(x);
  4880. tt_senddata = y;
  4881. return(1);
  4882. case XYTSEOB:
  4883. if ((y = cmkey(ttyseobtab,2,"","us_cr",xxstring)) < 0) return(y);
  4884. if ((x = cmcfm()) < 0) return(x);
  4885. wy_blockend = y;
  4886. return(1);
  4887. case XYTURLHI: {
  4888. int done = 0, attr = VT_CHAR_ATTR_NORMAL;
  4889. if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  4890. return(x);
  4891. if (x) {
  4892. z = 0;
  4893. while (!done) {
  4894. if ((y = cmkey(ttyprotab,nprotect,"",
  4895. z?"done":"reverse",xxstring)) < 0)
  4896. return(y);
  4897. switch (y) {
  4898. case TTATTDONE:
  4899. done = TRUE;
  4900. break;
  4901. case TTATTBLI:
  4902. attr |= VT_CHAR_ATTR_BLINK;
  4903. break;
  4904. case TTATTREV:
  4905. attr |= VT_CHAR_ATTR_REVERSE;
  4906. break;
  4907. case TTATTITA:
  4908. attr |= VT_CHAR_ATTR_ITALIC;
  4909. break;
  4910. case TTATTUND:
  4911. attr |= VT_CHAR_ATTR_UNDERLINE;
  4912. break;
  4913. case TTATTBLD:
  4914. attr |= VT_CHAR_ATTR_BOLD;
  4915. break;
  4916. case TTATTDIM:
  4917. attr |= VT_CHAR_ATTR_DIM;
  4918. break;
  4919. case TTATTINV:
  4920. attr |= VT_CHAR_ATTR_INVISIBLE;
  4921. break;
  4922. case TTATTNOR:
  4923. break;
  4924. }
  4925. z = 1; /* One attribute has been chosen */
  4926. }
  4927. }
  4928. if ((z = cmcfm()) < 0) return(z);
  4929. seturlhl(x);
  4930. if (x)
  4931. tt_url_hilite_attr = attr;
  4932. return(1);
  4933. }
  4934. case XYTATTR:
  4935. if ((x = cmkey(ttyattrtab,nattrib,"","underline",xxstring)) < 0)
  4936. return(x);
  4937. switch (x) {
  4938. case TTATTBLI:
  4939. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4940. if ((x = cmcfm()) < 0) return(x);
  4941. trueblink = y;
  4942. #ifndef KUI
  4943. if ( !trueblink && trueunderline ) {
  4944. trueunderline = 0;
  4945. printf("Warning: Underline being simulated by color.\n");
  4946. }
  4947. #endif /* KUI */
  4948. break;
  4949. case TTATTDIM:
  4950. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4951. if ((x = cmcfm()) < 0) return(x);
  4952. truedim = y;
  4953. break;
  4954. case TTATTREV:
  4955. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4956. if ((x = cmcfm()) < 0) return(x);
  4957. truereverse = y;
  4958. break;
  4959. case TTATTUND:
  4960. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4961. if ((x = cmcfm()) < 0) return(x);
  4962. trueunderline = y;
  4963. #ifndef KUI
  4964. if (!trueblink && trueunderline) {
  4965. trueblink = 1;
  4966. printf("Warning: True blink mode is active.\n");
  4967. }
  4968. #endif /* KUI */
  4969. break;
  4970. case TTATTITA:
  4971. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4972. if ((x = cmcfm()) < 0) return(x);
  4973. trueitalic = y;
  4974. break;
  4975. case TTATTPRO: { /* Set default Protected Character attribute */
  4976. extern vtattrib WPattrib; /* current WP Mode Attrib */
  4977. extern vtattrib defWPattrib; /* default WP Mode Attrib */
  4978. vtattrib wpa = {0,0,0,0,0,1,0,0,0,0,0}; /* Protected */
  4979. int done = 0;
  4980. x = 0;
  4981. while (!done) {
  4982. if ((y = cmkey(ttyprotab,nprotect,"",
  4983. x?"done":"dim",xxstring)) < 0)
  4984. return(y);
  4985. switch (y) {
  4986. case TTATTNOR:
  4987. break;
  4988. case TTATTBLI: /* Blinking doesn't work */
  4989. wpa.blinking = TRUE;
  4990. break;
  4991. case TTATTREV:
  4992. wpa.reversed = TRUE;
  4993. break;
  4994. case TTATTITA:
  4995. wpa.italic = TRUE;
  4996. break;
  4997. case TTATTUND:
  4998. wpa.underlined = TRUE;
  4999. break;
  5000. case TTATTBLD:
  5001. wpa.bold = TRUE;
  5002. break;
  5003. case TTATTDIM:
  5004. wpa.dim = TRUE;
  5005. break;
  5006. case TTATTINV:
  5007. wpa.invisible = TRUE ;
  5008. break;
  5009. case TTATTDONE:
  5010. done = TRUE;
  5011. break;
  5012. }
  5013. x = 1; /* One attribute has been chosen */
  5014. }
  5015. if ((x = cmcfm()) < 0) return(x);
  5016. WPattrib = defWPattrib = wpa;
  5017. break;
  5018. }
  5019. }
  5020. return(1);
  5021. case XYTKEY: { /* SET TERMINAL KEY */
  5022. int t, x, y;
  5023. int clear = 0, deflt = 0;
  5024. int confirmed = 0;
  5025. int flag = 0;
  5026. int kc = -1; /* Key code */
  5027. int litstr = 0; /* Literal String? */
  5028. char *s = NULL; /* Key binding */
  5029. #ifndef NOKVERBS
  5030. char *p = NULL; /* Worker */
  5031. #endif /* NOKVERBS */
  5032. con_event defevt;
  5033. extern int os2gks;
  5034. extern int mskkeys;
  5035. extern int initvik;
  5036. struct FDB kw,sw,nu,cm;
  5037. defevt.type = error;
  5038. if ((t = cmkey(ttkeytab,nttkey,"","",xxstring)) < 0)
  5039. return(t);
  5040. cmfdbi(&nu, /* First FDB - command switches */
  5041. _CMNUM, /* fcode */
  5042. "/literal, keycode, or action",
  5043. "", /* default */
  5044. "", /* addtl string data */
  5045. 10, /* addtl numeric data 1: radix */
  5046. 0, /* addtl numeric data 2: 0 */
  5047. xxstring, /* Processing function */
  5048. NULL, /* Keyword table */
  5049. &sw /* Pointer to next FDB */
  5050. ); /* */
  5051. cmfdbi(&sw, /* Second FDB - switches */
  5052. _CMKEY, /* fcode */
  5053. "",
  5054. "", /* default */
  5055. "", /* addtl string data */
  5056. nstrmswitab, /* addtl numeric data 1: tbl size */
  5057. 4, /* addtl numeric data 2: 4 = cmswi */
  5058. xxstring, /* Processing function */
  5059. strmswitab, /* Keyword table */
  5060. &kw /* Pointer to next FDB */
  5061. );
  5062. cmfdbi(&kw, /* Third FDB - command switches */
  5063. _CMKEY, /* fcode */
  5064. "/literal, keycode, or action",
  5065. "", /* default */
  5066. "", /* addtl string data */
  5067. nstrmkeytab, /* addtl numeric data 1: tbl size */
  5068. 0, /* addtl numeric data 2 */
  5069. xxstring, /* Processing function */
  5070. strmkeytab, /* Keyword table */
  5071. &cm /* Pointer to next FDB */
  5072. );
  5073. cmfdbi(&cm, /* Final FDB - Confirmation */
  5074. _CMCFM, /* fcode */
  5075. "",
  5076. "", /* default */
  5077. "", /* addtl string data */
  5078. 0, /* addtl numeric data 1: tbl size */
  5079. 0, /* addtl numeric data 2: 4 = cmswi */
  5080. xxstring, /* Processing function */
  5081. NULL, /* Keyword table */
  5082. NULL /* Pointer to next FDB */
  5083. );
  5084. while (kc < 0) {
  5085. x = cmfdb(&nu); /* Parse something */
  5086. if (x < 0)
  5087. return(x);
  5088. switch (cmresult.fcode) {
  5089. case _CMCFM:
  5090. printf(" Press key to be defined: ");
  5091. conbin((char)escape); /* Put terminal in binary mode */
  5092. os2gks = 0; /* Turn off Kverb preprocessing */
  5093. kc = congks(0); /* Get character or scan code */
  5094. os2gks = 1; /* Turn on Kverb preprocessing */
  5095. concb((char)escape); /* Restore terminal to cbreak mode */
  5096. if (kc < 0) { /* Check for error */
  5097. printf("?Error reading key\n");
  5098. return(0);
  5099. }
  5100. shokeycode(kc,t); /* Show current definition */
  5101. flag = 1; /* Remember it's a multiline command */
  5102. break;
  5103. case _CMNUM:
  5104. kc = cmresult.nresult;
  5105. break;
  5106. case _CMKEY:
  5107. if (cmresult.fdbaddr == &sw) { /* Switch */
  5108. if (cmresult.nresult == 0)
  5109. litstr = 1;
  5110. } else if (cmresult.fdbaddr == &kw) { /* Keyword */
  5111. if (cmresult.nresult == 0)
  5112. clear = 1;
  5113. else
  5114. deflt = 1;
  5115. if ((x = cmcfm()) < 0)
  5116. return(x);
  5117. if (clear)
  5118. clearkeymap(t);
  5119. else if (deflt)
  5120. defaultkeymap(t);
  5121. initvik = 1;
  5122. return(1);
  5123. }
  5124. }
  5125. }
  5126. /* Normal SET TERMINAL KEY <terminal> <scancode> <value> command... */
  5127. if (mskkeys)
  5128. kc = msktock(kc);
  5129. if (kc < 0 || kc >= KMSIZE) {
  5130. printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5131. return(-9);
  5132. }
  5133. if (kc == escape) {
  5134. printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5135. return(-9);
  5136. }
  5137. wideresult = -1;
  5138. if (flag) {
  5139. cmsavp(psave,PROMPTL);
  5140. cmsetp(" Enter new definition: ");
  5141. cmini(ckxech);
  5142. }
  5143. def_again:
  5144. if (flag) prompt(NULL);
  5145. if ((y = cmtxt("key definition,\n\
  5146. or Ctrl-C to cancel this command,\n\
  5147. or Enter to restore default definition",
  5148. "",&s,NULL)) < 0) {
  5149. if (flag) /* Handle parse errors */
  5150. goto def_again;
  5151. else
  5152. return(y);
  5153. }
  5154. s = brstrip(s);
  5155. #ifndef NOKVERBS
  5156. p = s; /* Save this place */
  5157. #endif /* NOKVERBS */
  5158. /*
  5159. If the definition included any \Kverbs, quote the backslash so the \Kverb
  5160. will still be in the definition when the key is pressed. We don't do this
  5161. in zzstring(), because \Kverbs are valid only in this context and nowhere
  5162. else.
  5163. We use this code active for all versions that support SET KEY, even if they
  5164. don't support \Kverbs, because otherwise \K would behave differently for
  5165. different versions.
  5166. */
  5167. for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5168. if ((x > 0) &&
  5169. (s[x] == 'K' || s[x] == 'k')
  5170. ) { /* Have K */
  5171. if ((x == 1 && s[x-1] == CMDQ) ||
  5172. (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5173. line[y++] = CMDQ; /* Make it \\K */
  5174. }
  5175. if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5176. line[y-1] = CMDQ; /* Have \{K */
  5177. line[y++] = '{'; /* Make it \\{K */
  5178. }
  5179. }
  5180. line[y] = s[x];
  5181. }
  5182. line[y++] = NUL; /* Terminate */
  5183. s = line + y + 1; /* Point to after it */
  5184. x = LINBUFSIZ - (int) strlen(line) - 1; /* Get remaining space */
  5185. if ((x < (LINBUFSIZ / 2)) ||
  5186. (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5187. printf("?Key definition too long\n");
  5188. if (flag) cmsetp(psave);
  5189. return(-9);
  5190. }
  5191. s = line + y + 1; /* Point to result. */
  5192. #ifndef NOKVERBS
  5193. /*
  5194. Special case: see if the definition starts with a \Kverb.
  5195. If it does, point to it with p, otherwise set p to NULL.
  5196. */
  5197. p = s;
  5198. if (*p++ == CMDQ) {
  5199. if (*p == '{') p++;
  5200. p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5201. }
  5202. #endif /* NOKVERBS */
  5203. switch (strlen(s)) { /* Action depends on length */
  5204. case 0: /* Clear individual key def */
  5205. deletekeymap(t,kc);
  5206. break;
  5207. case 1:
  5208. if (!litstr) {
  5209. defevt.type = key; /* Single character */
  5210. defevt.key.scancode = *s;
  5211. break;
  5212. }
  5213. default: /* Character string */
  5214. #ifndef NOKVERBS
  5215. if (p) {
  5216. y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5217. /* Need exact match */
  5218. debug(F101,"set key kverb lookup",0,y);
  5219. if (y > -1) {
  5220. defevt.type = kverb;
  5221. defevt.kverb.id = y;
  5222. break;
  5223. }
  5224. }
  5225. #endif /* NOKVERBS */
  5226. if (litstr) {
  5227. defevt.type = literal;
  5228. defevt.literal.string = (char *) malloc(strlen(s)+1);
  5229. if (defevt.literal.string)
  5230. strcpy(defevt.literal.string, s); /* safe */
  5231. } else {
  5232. defevt.type = macro;
  5233. defevt.macro.string = (char *) malloc(strlen(s)+1);
  5234. if (defevt.macro.string)
  5235. strcpy(defevt.macro.string, s); /* safe */
  5236. }
  5237. break;
  5238. }
  5239. insertkeymap(t, kc, defevt);
  5240. if (flag)
  5241. cmsetp(psave);
  5242. initvik = 1; /* Update VIK table */
  5243. return(1);
  5244. }
  5245. #ifdef PCTERM
  5246. case XYTPCTERM: /* PCTERM Keyboard Mode */
  5247. if ((x = seton(&tt_pcterm)) < 0) return(x);
  5248. return(success = 1);
  5249. #endif /* PCTERM */
  5250. #endif /* OS2 */
  5251. #ifdef CK_TRIGGER
  5252. case XYTRIGGER:
  5253. if ((y = cmtxt("String to trigger automatic return to command mode",
  5254. "",&s,xxstring)) < 0)
  5255. return(y);
  5256. makelist(s,tt_trigger,TRIGGERS);
  5257. return(1);
  5258. #endif /* CK_TRIGGER */
  5259. #ifdef OS2
  5260. case XYTSAC:
  5261. if ((y = cmnum("ASCII value to use for spacing attributes",
  5262. "32",10,&x,xxstring)) < 0)
  5263. return(y);
  5264. if ((y = cmcfm()) < 0) return(y);
  5265. tt_sac = x;
  5266. return(success = 1);
  5267. case XYTKBDGL: { /* SET TERM KBD-FOLLOWS-GL/GR */
  5268. extern int tt_kb_glgr; /* from ckoco3.c */
  5269. if ((x = seton(&tt_kb_glgr)) < 0)
  5270. return(x);
  5271. return(success = 1);
  5272. }
  5273. #ifndef NOCSETS
  5274. case XYTVTLNG: /* SET TERM DEC-LANGUAGE */
  5275. if ((y = cmkey(vtlangtab,nvtlangtab,"VT language",
  5276. IS97801(tt_type_mode)?"german":"north-american",
  5277. xxstring)) < 0)
  5278. return(y);
  5279. if ((x = cmcfm()) < 0) return(x);
  5280. /* A real VT terminal would use the language to set the */
  5281. /* default keyboard language for both 8-bit multinational */
  5282. /* and 7-bit national modes. For 8-bit mode it would */
  5283. /* set the terminal character-set to the ISO set if it */
  5284. /* is not already set. */
  5285. /* Latin-1 can be replaced by DEC Multinational */
  5286. switch (y) {
  5287. case VTL_NORTH_AM: /* North American */
  5288. /* Multinational: Latin-1 */
  5289. /* National: US_ASCII */
  5290. dec_lang = y;
  5291. dec_nrc = TX_ASCII;
  5292. dec_kbd = TX_8859_1;
  5293. break;
  5294. case VTL_BRITISH :
  5295. /* Multinational: Latin-1 */
  5296. /* National: UK_ASCII */
  5297. dec_lang = y;
  5298. dec_nrc = TX_BRITISH;
  5299. dec_kbd = TX_8859_1;
  5300. break;
  5301. case VTL_FRENCH :
  5302. case VTL_BELGIAN :
  5303. case VTL_CANADIAN:
  5304. /* Multinational: Latin-1 */
  5305. /* National: FR_ASCII */
  5306. dec_lang = y;
  5307. dec_nrc = TX_FRENCH;
  5308. dec_kbd = TX_8859_1;
  5309. break;
  5310. case VTL_FR_CAN :
  5311. /* Multinational: Latin-1 */
  5312. /* National: FC_ASCII */
  5313. dec_lang = y;
  5314. dec_nrc = TX_CN_FRENCH;
  5315. dec_kbd = TX_8859_1;
  5316. break;
  5317. case VTL_DANISH :
  5318. case VTL_NORWEGIA:
  5319. /* Multinational: Latin-1 */
  5320. /* National: NO_ASCII */
  5321. dec_lang = y;
  5322. dec_nrc = TX_NORWEGIAN;
  5323. dec_kbd = TX_8859_1;
  5324. break;
  5325. case VTL_FINNISH :
  5326. /* Multinational: Latin-1 */
  5327. /* National: FI_ASCII */
  5328. dec_lang = y;
  5329. dec_nrc = TX_FINNISH;
  5330. dec_kbd = TX_8859_1;
  5331. break;
  5332. case VTL_GERMAN :
  5333. /* Multinational: Latin-1 */
  5334. /* National: GR_ASCII */
  5335. dec_lang = y;
  5336. dec_nrc = TX_GERMAN;
  5337. dec_kbd = TX_8859_1;
  5338. break;
  5339. case VTL_DUTCH :
  5340. /* Multinational: Latin-1 */
  5341. /* National: DU_ASCII */
  5342. dec_lang = y;
  5343. dec_nrc = TX_DUTCH;
  5344. dec_kbd = TX_8859_1;
  5345. break;
  5346. case VTL_ITALIAN :
  5347. /* Multinational: Latin-1 */
  5348. /* National: IT_ASCII */
  5349. dec_lang = y;
  5350. dec_nrc = TX_ITALIAN;
  5351. dec_kbd = TX_8859_1;
  5352. break;
  5353. case VTL_SW_FR :
  5354. case VTL_SW_GR :
  5355. /* Multinational: Latin-1 */
  5356. /* National: CH_ASCII */
  5357. dec_lang = y;
  5358. dec_nrc = TX_SWISS;
  5359. dec_kbd = TX_8859_1;
  5360. break;
  5361. case VTL_SWEDISH :
  5362. /* Multinational: Latin-1 */
  5363. /* National: SW_ASCII */
  5364. dec_lang = y;
  5365. dec_nrc = TX_SWEDISH;
  5366. dec_kbd = TX_8859_1;
  5367. break;
  5368. case VTL_SPANISH :
  5369. /* Multinational: Latin-1 */
  5370. /* National: SP_ASCII */
  5371. dec_lang = y;
  5372. dec_nrc = TX_SPANISH;
  5373. dec_kbd = TX_8859_1;
  5374. break;
  5375. case VTL_PORTUGES:
  5376. /* Multinational: Latin-1 */
  5377. /* National: Portugese ASCII */
  5378. dec_lang = y;
  5379. dec_nrc = TX_PORTUGUESE;
  5380. dec_kbd = TX_8859_1;
  5381. break;
  5382. case VTL_HEBREW :
  5383. /* Multinational: Latin-Hebrew / DEC-Hebrew */
  5384. /* National: DEC 7-bit Hebrew */
  5385. dec_lang = y;
  5386. dec_nrc = TX_HE7;
  5387. dec_kbd = TX_8859_8;
  5388. break;
  5389. case VTL_GREEK :
  5390. /* Multinational: Latin-Greek / DEC-Greek */
  5391. /* National: DEC Greek NRC */
  5392. /* is ELOT927 equivalent to DEC Greek???? */
  5393. dec_lang = y;
  5394. dec_nrc = TX_ELOT927;
  5395. dec_kbd = TX_8859_7;
  5396. break;
  5397. #ifdef COMMENT
  5398. case VTL_TURK_Q :
  5399. case VTL_TURK_F :
  5400. /* Multinational: Latin-Turkish / DEC-Turkish */
  5401. /* National: DEC 7-bit Turkish */
  5402. break;
  5403. #endif /* COMMENT */
  5404. case VTL_HUNGARIA:
  5405. /* Multinational: Latin-2 */
  5406. /* National: no national mode */
  5407. dec_lang = y;
  5408. dec_nrc = TX_HUNGARIAN;
  5409. dec_kbd = TX_8859_2;
  5410. break;
  5411. case VTL_SLOVAK :
  5412. case VTL_CZECH :
  5413. case VTL_POLISH :
  5414. case VTL_ROMANIAN:
  5415. /* Multinational: Latin-2 */
  5416. /* National: no national mode */
  5417. dec_lang = y;
  5418. dec_nrc = TX_ASCII;
  5419. dec_kbd = TX_8859_2;
  5420. break;
  5421. case VTL_RUSSIAN :
  5422. /* Multinational: Latin-Cyrillic / KOI-8 */
  5423. /* National: DEC Russian NRC */
  5424. dec_lang = y;
  5425. dec_nrc = TX_KOI7;
  5426. dec_kbd = TX_8859_5;
  5427. break;
  5428. case VTL_LATIN_AM:
  5429. /* Multinational: not listed in table */
  5430. /* National: not listed in table */
  5431. dec_lang = y;
  5432. dec_nrc = TX_ASCII;
  5433. dec_kbd = TX_8859_1;
  5434. break;
  5435. #ifdef COMMENT
  5436. case VTL_SCS :
  5437. /* Multinational: Latin-2 */
  5438. /* National: SCS NRC */
  5439. break;
  5440. #endif /* COMMENT */
  5441. default:
  5442. return(success = 0);
  5443. }
  5444. if (IS97801(tt_type_mode)) {
  5445. SNI_bitmode(cmask == 0377 ? 8 : 7);
  5446. }
  5447. return(success = 1);
  5448. #endif /* NOCSETS */
  5449. case XYTVTNRC: { /* SET TERM DEC-NRC-MODE */
  5450. extern int decnrcm_usr, decnrcm; /* from ckoco3.c */
  5451. if ((x = seton(&decnrcm_usr)) < 0)
  5452. return(x);
  5453. decnrcm = decnrcm_usr;
  5454. return(success = 1);
  5455. }
  5456. case XYTSNIPM: { /* SET TERM SNI-PAGEMODE */
  5457. extern int sni_pagemode, sni_pagemode_usr;
  5458. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5459. if ((x = cmcfm()) < 0) return(x);
  5460. sni_pagemode_usr = sni_pagemode = y;
  5461. return(success = 1);
  5462. }
  5463. case XYTSNISM: { /* SET TERM SNI-SCROLLMODE */
  5464. extern int sni_scroll_mode, sni_scroll_mode_usr;
  5465. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5466. if ((x = cmcfm()) < 0) return(x);
  5467. sni_scroll_mode_usr = sni_scroll_mode = y;
  5468. return(success = 1);
  5469. }
  5470. case XYTSNICC: { /* SET TERM SNI-CH.CODE */
  5471. extern int sni_chcode_usr;
  5472. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5473. if ((x = cmcfm()) < 0) return(x);
  5474. sni_chcode_usr = y;
  5475. SNI_chcode(y);
  5476. return(success = 1);
  5477. }
  5478. case XYTSNIFV: { /* SET TERM SNI-FIRMWARE-VERSIONS */
  5479. extern CHAR sni_kbd_firmware[], sni_term_firmware[];
  5480. CHAR kbd[7],term[7];
  5481. if ((x = cmfld("Keyboard Firmware Version",sni_kbd_firmware,
  5482. &s, xxstring)) < 0)
  5483. return(x);
  5484. if ((int)strlen(s) != 6) {
  5485. printf("?Sorry - the firmware version must be 6 digits long\n");
  5486. return(-9);
  5487. }
  5488. for (i = 0; i < 6; i++) {
  5489. if (!isdigit(s[i])) {
  5490. printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5491. return(-9);
  5492. }
  5493. }
  5494. ckstrncpy(kbd,s,7);
  5495. if ((x = cmfld("Terminal Firmware Version",sni_term_firmware,
  5496. &s, xxstring)) < 0)
  5497. return(x);
  5498. if ((int)strlen(s) != 6) {
  5499. printf("?Sorry - the firmware version must be 6 digits long\n");
  5500. return(-9);
  5501. }
  5502. for (i = 0; i < 6; i++) {
  5503. if (!isdigit(s[i])) {
  5504. printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5505. return(-9);
  5506. }
  5507. }
  5508. ckstrncpy(term,s,7);
  5509. if ((x = cmcfm()) < 0) return(x);
  5510. ckstrncpy(sni_kbd_firmware,kbd,7);
  5511. ckstrncpy(sni_term_firmware,term,7);
  5512. return(success = 1);
  5513. }
  5514. case XYTLSP: { /* SET TERM LINE-SPACING */
  5515. if ((x = cmfld("Line Spacing","1",&s, xxstring)) < 0)
  5516. return(x);
  5517. if (isfloat(s,0) < 1) { /* (sets floatval) */
  5518. printf("?Integer or floating-point number required\n");
  5519. return(-9);
  5520. }
  5521. if (floatval < 1.0 || floatval > 3.0) {
  5522. printf("?Value must within the range 1.0 and 3.0 (inclusive)\n");
  5523. return(-9);
  5524. }
  5525. if ((x = cmcfm()) < 0) return(x);
  5526. #ifdef KUI
  5527. tt_linespacing[VCMD] = tt_linespacing[VTERM] = floatval;
  5528. return(success = 1);
  5529. #else /* KUI */
  5530. printf("?Sorry, Line-spacing is only supported in K95G.EXE.\n");
  5531. return(success = 0);
  5532. #endif /* KUI */
  5533. }
  5534. #endif /* OS2 */
  5535. default: /* Shouldn't get here. */
  5536. return(-2);
  5537. }
  5538. #endif /* MAC */
  5539. #ifdef COMMENT
  5540. /*
  5541. This was supposed to shut up picky compilers but instead it makes
  5542. most compilers complain about "statement not reached".
  5543. */
  5544. return(-2);
  5545. #endif /* COMMENT */
  5546. #ifdef OS2
  5547. return(-2);
  5548. #endif /* OS2 */
  5549. }
  5550. #ifdef OS2
  5551. int
  5552. settitle(void) {
  5553. extern char usertitle[];
  5554. if ((y = cmtxt("title text","",&s,xxstring)) < 0)
  5555. return(y);
  5556. #ifdef IKSD
  5557. if (inserver) {
  5558. printf("?Sorry, command disabled.\r\n");
  5559. return(success = 0);
  5560. }
  5561. #endif /* IKSD */
  5562. s = brstrip(s);
  5563. ckstrncpy(usertitle,s,64);
  5564. os2settitle("",1);
  5565. return(1);
  5566. }
  5567. static struct keytab dialertab[] = { /* K95 Dialer types */
  5568. "backspace", 0, 0,
  5569. "enter", 1, 0
  5570. };
  5571. static int ndialer = 2;
  5572. int
  5573. setdialer(void) {
  5574. int t, x, y;
  5575. int clear = 0, deflt = 0;
  5576. int kc; /* Key code */
  5577. char *s = NULL; /* Key binding */
  5578. #ifndef NOKVERBS
  5579. char *p = NULL; /* Worker */
  5580. #endif /* NOKVERBS */
  5581. con_event defevt;
  5582. extern int os2gks;
  5583. extern int mskkeys;
  5584. extern int initvik;
  5585. defevt.type = error;
  5586. if (( x = cmkey(dialertab, ndialer,
  5587. "Kermit-95 dialer work-arounds",
  5588. "", xxstring)) < 0 )
  5589. return(x);
  5590. switch (x) {
  5591. case 0: /* Backspace */
  5592. kc = 264;
  5593. break;
  5594. case 1: /* Enter */
  5595. kc = 269;
  5596. break;
  5597. default:
  5598. printf("Illegal value in setdialer()\n");
  5599. return(-9);
  5600. }
  5601. if ((y = cmtxt("Key definition","",&s,xxstring)) < 0)
  5602. return(y);
  5603. #ifdef IKSD
  5604. if (inserver) {
  5605. printf("?Sorry, command disabled.\r\n");
  5606. return(success = 0);
  5607. }
  5608. #endif /* IKSD */
  5609. s = brstrip(s);
  5610. #ifndef NOKVERBS
  5611. p = s; /* Save this place */
  5612. #endif /* NOKVERBS */
  5613. /*
  5614. If the definition included any \Kverbs, quote the backslash so the \Kverb
  5615. will still be in the definition when the key is pressed. We don't do this
  5616. in zzstring(), because \Kverbs are valid only in this context and nowhere
  5617. else.
  5618. We use this code active for all versions that support SET KEY, even if they
  5619. don't support \Kverbs, because otherwise \K would behave differently for
  5620. different versions.
  5621. */
  5622. for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5623. if ((x > 0) &&
  5624. (s[x] == 'K' || s[x] == 'k')
  5625. ) { /* Have K */
  5626. if ((x == 1 && s[x-1] == CMDQ) ||
  5627. (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5628. line[y++] = CMDQ; /* Make it \\K */
  5629. }
  5630. if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5631. line[y-1] = CMDQ; /* Have \{K */
  5632. line[y++] = '{'; /* Make it \\{K */
  5633. }
  5634. }
  5635. line[y] = s[x];
  5636. }
  5637. line[y++] = NUL; /* Terminate */
  5638. s = line + y + 1; /* Point to after it */
  5639. x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5640. if ((x < (LINBUFSIZ / 2)) ||
  5641. (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5642. printf("?Key definition too long\n");
  5643. return(-9);
  5644. }
  5645. s = line + y + 1; /* Point to result. */
  5646. #ifndef NOKVERBS
  5647. /*
  5648. Special case: see if the definition starts with a \Kverb.
  5649. If it does, point to it with p, otherwise set p to NULL.
  5650. */
  5651. p = s;
  5652. if (*p++ == CMDQ) {
  5653. if (*p == '{') p++;
  5654. p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5655. }
  5656. #endif /* NOKVERBS */
  5657. /* Clear the definition for SET KEY */
  5658. if (macrotab[kc]) { /* Possibly free old macro from key. */
  5659. free((char *)macrotab[kc]);
  5660. macrotab[kc] = NULL;
  5661. }
  5662. keymap[kc] = (KEY) kc;
  5663. /* Now reprogram the default value for all terminal types */
  5664. /* remember to treat Wyse and Televideo terminals special */
  5665. /* because of their use of Kverbs for Backspace and Enter */
  5666. for (t = 0; t <= TT_MAX; t++) {
  5667. if ( ISDG200(t) && kc == 264) {
  5668. extern char * udkfkeys[] ;
  5669. if (kc == 264) { /* \Kdgbs */
  5670. if (udkfkeys[83])
  5671. free(udkfkeys[83]);
  5672. udkfkeys[83] = strdup(s);
  5673. }
  5674. } else if (ISWYSE(t) || ISTVI(t)) {
  5675. extern char * udkfkeys[] ;
  5676. if (kc == 264) { /* \Kwybs or \Ktvibs */
  5677. if (udkfkeys[32])
  5678. free(udkfkeys[32]);
  5679. udkfkeys[32] = strdup(s);
  5680. }
  5681. if (kc == 269) { /* \Kwyenter and \Kwyreturn */
  5682. if (udkfkeys[39]) /* \Ktvienter and \Ktvireturn */
  5683. free(udkfkeys[39]);
  5684. udkfkeys[39] = strdup(s);
  5685. if (udkfkeys[49])
  5686. free(udkfkeys[49]);
  5687. udkfkeys[49] = strdup(s);
  5688. }
  5689. } else {
  5690. switch (strlen(s)) { /* Action depends on length */
  5691. case 0: /* Clear individual key def */
  5692. deletekeymap(t,kc);
  5693. break;
  5694. case 1:
  5695. defevt.type = key; /* Single character */
  5696. defevt.key.scancode = *s;
  5697. break;
  5698. default: /* Character string */
  5699. #ifndef NOKVERBS
  5700. if (p) {
  5701. y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5702. /* Exact match req'd */
  5703. debug(F101,"set key kverb lookup",0,y);
  5704. if (y > -1) {
  5705. defevt.type = kverb;
  5706. defevt.kverb.id = y;
  5707. break;
  5708. }
  5709. }
  5710. #endif /* NOKVERBS */
  5711. defevt.type = macro;
  5712. defevt.macro.string = (char *) malloc(strlen(s)+1);
  5713. if (defevt.macro.string)
  5714. strcpy(defevt.macro.string, s); /* safe */
  5715. break;
  5716. }
  5717. insertkeymap( t, kc, defevt ) ;
  5718. initvik = 1; /* Update VIK table */
  5719. }
  5720. }
  5721. return(1);
  5722. }
  5723. #endif /* OS2 */
  5724. #ifdef NT
  5725. int
  5726. setwin95( void ) {
  5727. int x, y, z;
  5728. if (( y = cmkey(win95tab, nwin95,
  5729. "Windows 95 specific work-arounds",
  5730. "keyboard-translation",
  5731. xxstring)) < 0 )
  5732. return (y);
  5733. switch (y) {
  5734. case XYWPOPUP:
  5735. if ((y = cmkey(onoff,2,"popups are used to prompt the user for data",
  5736. "on",xxstring)) < 0)
  5737. return(y);
  5738. if ((x = cmcfm()) < 0) return(x);
  5739. win95_popup = y;
  5740. return(1);
  5741. case XYW8_3:
  5742. if ((y = cmkey(onoff,2,"8.3 FAT file names","off",xxstring)) < 0)
  5743. return(y);
  5744. if ((x = cmcfm()) < 0) return(x);
  5745. win95_8_3 = y;
  5746. return(1);
  5747. case XYWSELECT:
  5748. if ((y = cmkey(onoff,2,"\"select()\" fails on write","off",
  5749. xxstring)) < 0)
  5750. return(y);
  5751. if ((x = cmcfm()) < 0) return(x);
  5752. win95selectbug = y;
  5753. return(1);
  5754. case XYWAGR:
  5755. if ((y = cmkey(onoff,2,"Right-Alt is Alt-Gr","off",xxstring)) < 0)
  5756. return(y);
  5757. if ((x = cmcfm()) < 0) return(x);
  5758. win95altgr = y;
  5759. return(1);
  5760. case XYWOIO:
  5761. if ((y = cmkey(onoff,2,"Use Overlapped I/O","on",xxstring)) < 0)
  5762. return(y);
  5763. if (y) {
  5764. if ((x = cmnum("Maximum number of outstanding I/O requests",
  5765. "10",10,&z,xxstring)) < 0)
  5766. return(x);
  5767. if (z < 1 || z > 7) {
  5768. printf(
  5769. "?Maximum outstanding I/O requests must be between 1 and 7.\n");
  5770. return(-9);
  5771. }
  5772. } else
  5773. z = 1;
  5774. if ((x = cmcfm()) < 0) return(x);
  5775. owwait = !y;
  5776. maxow = maxow_usr = z;
  5777. return(1);
  5778. case XYWKEY:
  5779. #ifndef COMMENT
  5780. printf("\n?\"Keyboard-Translation\" is no longer required.\n");
  5781. return(-9);
  5782. #else /* COMMENT */
  5783. if (( z = cmkey(tcstab, ntcs,
  5784. "Keyboard Character Set",
  5785. "latin1-iso",
  5786. xxstring)) < 0)
  5787. return (z);
  5788. if ((x = cmcfm()) < 0)
  5789. return(x);
  5790. win95kcsi = z;
  5791. win95kl2 = (win95kcsi == TC_2LATIN);
  5792. if (win95kcsi == TC_TRANSP) {
  5793. win95kcs = NULL;
  5794. } else {
  5795. #ifdef UNICODE
  5796. win95kcs = xlr[win95kcsi][tx2fc(tcsl)];
  5797. #else /* UNICODE */
  5798. win95kcs = xlr[win95kcsi][tcsl];
  5799. #endif /* UNICODE */
  5800. }
  5801. return(1);
  5802. #endif /* COMMENT */
  5803. case XYWLUC:
  5804. if ((y = cmkey(onoff,2,"Unicode-to-Lucida-Console substitutions",
  5805. "on",xxstring)) < 0)
  5806. return(y);
  5807. if ((x = cmcfm()) < 0) return(x);
  5808. win95lucida = y;
  5809. return(1);
  5810. case XYWHSL:
  5811. if ((y = cmkey(onoff,2,"Horizontal Scan Line substitutions",
  5812. "on",xxstring)) < 0)
  5813. return(y);
  5814. if ((x = cmcfm()) < 0) return(x);
  5815. win95hsl = y;
  5816. return(1);
  5817. default:
  5818. printf("Illegal value in setwin95()\n");
  5819. return(-9);
  5820. }
  5821. }
  5822. #endif /* NT */
  5823. #ifdef OS2
  5824. int
  5825. setprty (
  5826. #ifdef CK_ANSIC
  5827. void
  5828. #endif /* CK_ANSIC */
  5829. /* setprty */ ) {
  5830. int x, y, z;
  5831. if (( y = cmkey(prtytab, nprty,
  5832. "priority level of terminal and communication threads",
  5833. "foreground-server",
  5834. xxstring)) < 0 )
  5835. return (y);
  5836. if ((x = cmcfm()) < 0)
  5837. return (x);
  5838. #ifdef IKSD
  5839. if (inserver &&
  5840. #ifdef IKSDCONF
  5841. iksdcf
  5842. #else
  5843. 1
  5844. #endif /* IKSDCONF */
  5845. ) {
  5846. if ((y = cmcfm()) < 0) return(y);
  5847. printf("?Sorry, command disabled.\r\n");
  5848. return(success = 0);
  5849. }
  5850. #endif /* IKSD */
  5851. priority = y;
  5852. return(TRUE);
  5853. }
  5854. #endif /* OS2 */
  5855. int
  5856. setbell() {
  5857. int y, x;
  5858. #ifdef OS2
  5859. int z;
  5860. #endif /* OS2 */
  5861. if ((y = cmkey(beltab,nbeltab,
  5862. #ifdef OS2
  5863. "how console and terminal bells should\nbe generated", "audible",
  5864. #else
  5865. "Whether Kermit should ring the terminal bell (beep)", "on",
  5866. #endif /* OS2 */
  5867. xxstring)) < 0)
  5868. return(y);
  5869. #ifdef IKSD
  5870. if (inserver) {
  5871. if ((y = cmcfm()) < 0) return(y);
  5872. printf("?Sorry, command disabled.\r\n");
  5873. return(success = 0);
  5874. }
  5875. #endif /* IKSD */
  5876. switch (y) { /* SET BELL */
  5877. case XYB_NONE:
  5878. #ifdef OS2
  5879. case XYB_VIS:
  5880. #endif /* OS2 */
  5881. if ((x = cmcfm()) < 0)
  5882. return(x);
  5883. #ifdef OS2
  5884. tt_bell = y;
  5885. #else
  5886. tt_bell = 0;
  5887. #endif /* OS2 */
  5888. break;
  5889. case XYB_AUD:
  5890. #ifdef OS2
  5891. if ((x = cmkey(audibletab, naudibletab,
  5892. "how audible console and terminal\nbells should be generated",
  5893. "beep",xxstring))<0)
  5894. return(x);
  5895. if ((z = cmcfm()) < 0)
  5896. return(z);
  5897. tt_bell = y | x;
  5898. #else
  5899. /* This lets C-Kermit accept but ignore trailing K95 keywords */
  5900. if ((x = cmtxt("Confirm with carriage return","",&s,xxstring)) < 0)
  5901. return(x);
  5902. tt_bell = 1;
  5903. #endif /* OS2 */
  5904. break;
  5905. }
  5906. return(1);
  5907. }
  5908. #ifdef OS2MOUSE
  5909. int
  5910. setmou(
  5911. #ifdef CK_ANSIC
  5912. void
  5913. #endif /* CK_ANSIC */
  5914. /* setmou */ ) {
  5915. extern int initvik;
  5916. int button = 0, event = 0;
  5917. char * p;
  5918. if ((y = cmkey(mousetab,nmtab,"","",xxstring)) < 0)
  5919. return(y);
  5920. #ifdef IKSD
  5921. if (inserver) {
  5922. if ((y = cmcfm()) < 0) return(y);
  5923. printf("?Sorry, command disabled.\r\n");
  5924. return(success = 0);
  5925. }
  5926. #endif /* IKSD */
  5927. if (y == XYM_ON) { /* MOUSE ACTIVATION */
  5928. int old_mou = tt_mouse;
  5929. if ((x = seton(&tt_mouse)) < 0)
  5930. return(x);
  5931. if (tt_mouse != old_mou)
  5932. if (tt_mouse)
  5933. os2_mouseon();
  5934. else
  5935. os2_mouseoff();
  5936. return(1);
  5937. }
  5938. if (y == XYM_DEBUG) { /* MOUSE DEBUG */
  5939. extern int MouseDebug;
  5940. if ((x = seton(&MouseDebug)) < 0)
  5941. return(x);
  5942. return(1);
  5943. }
  5944. if (y == XYM_CLEAR) { /* Reset Mouse Defaults */
  5945. if ((x = cmcfm()) < 0) return(x);
  5946. mousemapinit(-1,-1);
  5947. initvik = 1; /* Update VIK Table */
  5948. return 1;
  5949. }
  5950. if (y != XYM_BUTTON) { /* Shouldn't happen. */
  5951. printf("Internal parsing error\n");
  5952. return(-9);
  5953. }
  5954. /* MOUSE EVENT ... */
  5955. if ((button = cmkey(mousebuttontab,nmbtab,
  5956. "Button number","1",
  5957. xxstring)) < 0)
  5958. return(button);
  5959. if ((y = cmkey(mousemodtab,nmmtab,
  5960. "Keyboard modifier","none",
  5961. xxstring)) < 0)
  5962. return(y);
  5963. event |= y; /* OR in the bits */
  5964. if ((y = cmkey(mclicktab,nmctab,"","click",xxstring)) < 0)
  5965. return(y);
  5966. /* Two bits are assigned, if neither are set then it is button one */
  5967. event |= y; /* OR in the bit */
  5968. wideresult = -1;
  5969. if ((y = cmtxt("definition,\n\
  5970. or Ctrl-C to cancel this command,\n\
  5971. or Enter to restore default definition",
  5972. "",&s,NULL)) < 0) {
  5973. return(y);
  5974. }
  5975. s = brstrip(s);
  5976. p = s; /* Save this place */
  5977. /*
  5978. If the definition included any \Kverbs, quote the backslash so the \Kverb
  5979. will still be in the definition when the key is pressed. We don't do this
  5980. in zzstring(), because \Kverbs are valid only in this context and nowhere
  5981. else. This code copied from SET KEY, q.v. for addt'l commentary.
  5982. */
  5983. for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5984. if ((x > 0) &&
  5985. (s[x] == 'K' || s[x] == 'k')
  5986. ) { /* Have K */
  5987. if ((x == 1 && s[x-1] == CMDQ) ||
  5988. (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5989. line[y++] = CMDQ; /* Make it \\K */
  5990. }
  5991. if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5992. line[y-1] = CMDQ; /* Have \{K */
  5993. line[y++] = '{'; /* Make it \\{K */
  5994. }
  5995. }
  5996. line[y] = s[x];
  5997. }
  5998. line[y++] = NUL; /* Terminate */
  5999. s = line + y + 1; /* Point to after it */
  6000. x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6001. if ((x < (LINBUFSIZ / 2)) ||
  6002. (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6003. printf("?Key definition too long\n");
  6004. return(-9);
  6005. }
  6006. s = line + y + 1; /* Point to result. */
  6007. #ifndef NOKVERBS
  6008. /*
  6009. Special case: see if the definition starts with a \Kverb.
  6010. If it does, point to it with p, otherwise set p to NULL.
  6011. */
  6012. p = s;
  6013. if (*p++ == CMDQ) {
  6014. if (*p == '{') p++;
  6015. p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6016. }
  6017. #else
  6018. p = NULL;
  6019. #endif /* NOKVERBS */
  6020. /* free the old definition if necessary */
  6021. if (mousemap[button][event].type == macro) {
  6022. free( mousemap[button][event].macro.string);
  6023. mousemap[button][event].macro.string = NULL;
  6024. }
  6025. switch (strlen(s)) { /* Action depends on length */
  6026. case 0: /* Reset to default binding */
  6027. mousemapinit( button, event );
  6028. break;
  6029. case 1: /* Single character */
  6030. mousemap[button][event].type = key;
  6031. mousemap[button][event].key.scancode = *s;
  6032. break;
  6033. default: /* Character string */
  6034. #ifndef NOKVERBS
  6035. if (p) {
  6036. y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6037. debug(F101,"set mouse kverb lookup",0,y); /* need exact match */
  6038. if (y > -1) {
  6039. /* Assign the kverb to the event */
  6040. mousemap[button][event].type = kverb;
  6041. mousemap[button][event].kverb.id = F_KVERB | y;
  6042. break;
  6043. }
  6044. }
  6045. #endif /* NOKVERBS */
  6046. /* Otherwise, it's a macro, so assign the macro to the event */
  6047. mousemap[button][event].type = macro;
  6048. mousemap[button][event].macro.string = (MACRO) malloc(strlen(s)+1);
  6049. if (mousemap[button][event].macro.string)
  6050. strcpy((char *) mousemap[button][event].macro.string, s); /* safe */
  6051. break;
  6052. }
  6053. initvik = 1; /* Update VIK Table */
  6054. if ( (button == XYM_B3) && (mousebuttoncount() < 3) && !quiet )
  6055. {
  6056. printf("?Warning: this machine does not have a three button mouse.\n");
  6057. return(0);
  6058. }
  6059. return(1);
  6060. }
  6061. #endif /* OS2MOUSE */
  6062. #endif /* NOLOCAL */
  6063. #ifndef NOXFER
  6064. int /* SET SEND/RECEIVE */
  6065. setsr(xx, rmsflg) int xx; int rmsflg; {
  6066. if (xx == XYRECV)
  6067. ckstrncpy(line,"Parameter for inbound packets",LINBUFSIZ);
  6068. else
  6069. ckstrncpy(line,"Parameter for outbound packets",LINBUFSIZ);
  6070. if (rmsflg) {
  6071. if ((y = cmkey(rsrtab,nrsrtab,line,"",xxstring)) < 0) {
  6072. if (y == -3) {
  6073. printf("?Remote receive parameter required\n");
  6074. return(-9);
  6075. } else return(y);
  6076. }
  6077. } else {
  6078. if ((y = cmkey(srtab,nsrtab,line,"",xxstring)) < 0) return(y);
  6079. }
  6080. switch (y) {
  6081. case XYQCTL: /* CONTROL-PREFIX */
  6082. if ((x = cmnum("ASCII value of control prefix","",10,&y,xxstring)) < 0)
  6083. return(x);
  6084. if ((x = cmcfm()) < 0) return(x);
  6085. if ((y > 32 && y < 63) || (y > 95 && y < 127)) {
  6086. if (xx == XYRECV)
  6087. ctlq = (CHAR) y; /* RECEIVE prefix, use with caution! */
  6088. else
  6089. myctlq = (CHAR) y; /* SEND prefix, OK to change */
  6090. return(success = 1);
  6091. } else {
  6092. printf("?Illegal value for prefix character\n");
  6093. return(-9);
  6094. }
  6095. case XYEOL:
  6096. if ((y = setcc("13",&z)) < 0)
  6097. return(y);
  6098. if (z > 31) {
  6099. printf("Sorry, the legal values are 0-31\n");
  6100. return(-9);
  6101. }
  6102. if (xx == XYRECV)
  6103. eol = (CHAR) z;
  6104. else
  6105. seol = (CHAR) z;
  6106. return(success = y);
  6107. case XYLEN:
  6108. y = cmnum("Maximum number of characters in a packet","90",10,&x,
  6109. xxstring);
  6110. if (xx == XYRECV) { /* Receive... */
  6111. if ((y = setnum(&z,x,y,maxrps)) < 0)
  6112. return(y);
  6113. if (protocol != PROTO_K) {
  6114. printf("?Sorry, this command does not apply to %s protocol.\n",
  6115. ptab[protocol].p_name
  6116. );
  6117. printf("Use SET SEND PACKET-LENGTH for XYZMODEM\n");
  6118. return(-9);
  6119. }
  6120. if (z < 10) {
  6121. printf("Sorry, 10 is the minimum\n");
  6122. return(-9);
  6123. }
  6124. if (rmsflg) {
  6125. sstate = setgen('S', "401", ckitoa(z), "");
  6126. return((int) sstate);
  6127. } else {
  6128. if (protocol == PROTO_K) {
  6129. if (z > MAXRP) z = MAXRP;
  6130. y = adjpkl(z,wslotr,bigrbsiz);
  6131. if (y != z) {
  6132. urpsiz = y;
  6133. if (!xcmdsrc)
  6134. if (msgflg) printf(
  6135. " Adjusting receive packet-length to %d for %d window slots\n",
  6136. y, wslotr);
  6137. }
  6138. urpsiz = y;
  6139. ptab[protocol].rpktlen = urpsiz;
  6140. rpsiz = (y > 94) ? 94 : y;
  6141. } else {
  6142. #ifdef CK_XYZ
  6143. if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6144. z != 128 && z != 1024) {
  6145. printf("Sorry, bad packet length for XMODEM.\n");
  6146. printf("Please use 128 or 1024.\n");
  6147. return(-9);
  6148. }
  6149. #endif /* CK_XYZ */
  6150. urpsiz = rpsiz = z;
  6151. }
  6152. }
  6153. } else { /* Send... */
  6154. if ((y = setnum(&z,x,y,maxsps)) < 0)
  6155. return(y);
  6156. if (z < 10) {
  6157. printf("Sorry, 10 is the minimum\n");
  6158. return(-9);
  6159. }
  6160. if (protocol == PROTO_K) {
  6161. if (z > MAXSP) z = MAXSP;
  6162. spsiz = z; /* Set it */
  6163. y = adjpkl(spsiz,wslotr,bigsbsiz);
  6164. if (y != spsiz && !xcmdsrc)
  6165. if (msgflg)
  6166. printf("Adjusting packet size to %d for %d window slots\n",
  6167. y,wslotr);
  6168. } else
  6169. y = z;
  6170. #ifdef CK_XYZ
  6171. if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6172. z != 128 && z != 1024) {
  6173. printf("Sorry, bad packet length for XMODEM.\n");
  6174. printf("Please use 128 or 1024.\n");
  6175. return(-9);
  6176. }
  6177. #endif /* CK_XYZ */
  6178. spsiz = spmax = spsizr = y; /* Set it and flag that it was set */
  6179. spsizf = 1; /* to allow overriding Send-Init. */
  6180. ptab[protocol].spktflg = spsizf;
  6181. ptab[protocol].spktlen = spsiz;
  6182. }
  6183. if (pflag && protocol == PROTO_K && !xcmdsrc) {
  6184. if (z > 94 && !reliable && msgflg) {
  6185. /* printf("Extended-length packets requested.\n"); */
  6186. if (bctr < 2 && z > 200) printf("\
  6187. Remember to SET BLOCK 2 or 3 for long packets.\n");
  6188. }
  6189. if (speed <= 0L) speed = ttgspd();
  6190. #ifdef COMMENT
  6191. /*
  6192. Kermit does this now itself.
  6193. */
  6194. if (speed <= 0L && z > 200 && msgflg) {
  6195. printf("\
  6196. Make sure your timeout interval is long enough for %d-byte packets.\n",z);
  6197. }
  6198. #endif /* COMMENT */
  6199. }
  6200. return(success = y);
  6201. case XYMARK:
  6202. #ifdef DOOMSDAY
  6203. /*
  6204. Printable start-of-packet works for UNIX and VMS only!
  6205. */
  6206. x_ifnum = 1;
  6207. y = cmnum("Code for packet-start character","1",10,&x,xxstring);
  6208. x_ifnum = 0;
  6209. if ((y = setnum(&z,x,y,126)) < 0) return(y);
  6210. #else
  6211. if ((y = setcc("1",&z)) < 0)
  6212. return(y);
  6213. #endif /* DOOMSDAY */
  6214. if (xx == XYRECV)
  6215. stchr = (CHAR) z;
  6216. else {
  6217. mystch = (CHAR) z;
  6218. #ifdef IKS_OPTION
  6219. /* If IKS negotiation in use */
  6220. if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT))
  6221. tn_siks(KERMIT_SOP); /* Report change to other side */
  6222. #endif /* IKS_OPTION */
  6223. }
  6224. return(success = y);
  6225. case XYNPAD: /* PADDING */
  6226. y = cmnum("How many padding characters for inbound packets","0",10,&x,
  6227. xxstring);
  6228. if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6229. if (xx == XYRECV)
  6230. mypadn = (CHAR) z;
  6231. else
  6232. npad = (CHAR) z;
  6233. return(success = y);
  6234. case XYPADC: /* PAD-CHARACTER */
  6235. if ((y = setcc("0",&z)) < 0) return(y);
  6236. if (xx == XYRECV) mypadc = z; else padch = z;
  6237. return(success = y);
  6238. case XYTIMO: /* TIMEOUT */
  6239. if (xx == XYRECV) {
  6240. y = cmnum("Packet timeout interval",ckitoa(URTIME),10,&x,xxstring);
  6241. if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6242. if (rmsflg) { /* REMOTE SET RECEIVE TIMEOUT */
  6243. sstate = setgen('S', "402", ckitoa(z), "");
  6244. return((int) sstate);
  6245. } else { /* SET RECEIVE TIMEOUT */
  6246. pkttim = z; /* Value to put in my negotiation */
  6247. } /* packet for other Kermit to use */
  6248. } else { /* SET SEND TIMEOUT */
  6249. #ifdef CK_TIMERS
  6250. extern int rttflg, mintime, maxtime;
  6251. int tmin = 0, tmax = 0;
  6252. #endif /* CK_TIMERS */
  6253. y = cmnum("Packet timeout interval",ckitoa(DMYTIM),10,&x,xxstring);
  6254. if (y == -3) { /* They cancelled a previous */
  6255. x = DMYTIM; /* SET SEND command, so restore */
  6256. timef = 0; /* and turn off the override flag */
  6257. y = cmcfm();
  6258. }
  6259. #ifdef CK_TIMERS
  6260. if (y < 0) return(y);
  6261. if (x < 0) {
  6262. printf("?Out of range - %d\n",x);
  6263. return(-9);
  6264. }
  6265. if ((z = cmkey(timotab,2,"","dynamic",xxstring)) < 0) return(z);
  6266. if (z) {
  6267. if ((y = cmnum("Minimum timeout to allow",
  6268. "1",10,&tmin,xxstring)) < 0)
  6269. return(y);
  6270. if (tmin < 1) {
  6271. printf("?Out of range - %d\n",tmin);
  6272. return(-9);
  6273. }
  6274. if ((y = cmnum("Maximum timeout to allow",
  6275. "0",10,&tmax,xxstring)) < 0)
  6276. return(y);
  6277. /* 0 means let Kermit choose, < 0 means no maximum */
  6278. }
  6279. if ((y = cmcfm()) < 0)
  6280. return(y);
  6281. rttflg = z; /* Round-trip timer flag */
  6282. z = x;
  6283. #else
  6284. if ((y = setnum(&z,x,y,94)) < 0)
  6285. return(y);
  6286. #endif /* CK_TIMERS */
  6287. timef = 1; /* Turn on the override flag */
  6288. timint = rtimo = z; /* Override value for me to use */
  6289. #ifdef CK_TIMERS
  6290. if (rttflg) { /* Lower and upper bounds */
  6291. mintime = tmin;
  6292. maxtime = tmax;
  6293. }
  6294. #endif /* CK_TIMERS */
  6295. }
  6296. return(success = 1);
  6297. case XYFPATH: /* PATHNAMES */
  6298. if (xx == XYRECV) {
  6299. y = cmkey(rpathtab,nrpathtab,"","auto",xxstring);
  6300. } else {
  6301. y = cmkey(pathtab,npathtab,"","off",xxstring);
  6302. }
  6303. if (y < 0) return(y);
  6304. if ((x = cmcfm()) < 0) return(x);
  6305. if (xx == XYRECV) { /* SET RECEIVE PATHNAMES */
  6306. fnrpath = y;
  6307. ptab[protocol].fnrp = fnrpath;
  6308. } else { /* SET SEND PATHNAMES */
  6309. fnspath = y;
  6310. ptab[protocol].fnsp = fnspath;
  6311. }
  6312. return(success = 1); /* Note: 0 = ON, 1 = OFF */
  6313. /* In other words, ON = leave pathnames ON, OFF = take them off. */
  6314. case XYPAUS: /* SET SEND/RECEIVE PAUSE */
  6315. y = cmnum("Milliseconds to pause between packets","0",10,&x,xxstring);
  6316. if ((y = setnum(&z,x,y,15000)) < 0)
  6317. return(y);
  6318. pktpaus = z;
  6319. return(success = 1);
  6320. #ifdef CKXXCHAR /* SET SEND/RECEIVE IGNORE/DOUBLE */
  6321. case XYIGN:
  6322. case XYDBL: {
  6323. int i, zz;
  6324. short *p;
  6325. extern short dblt[];
  6326. extern int dblflag, ignflag;
  6327. /* Make space for a temporary copy of the ignore/double table */
  6328. zz = y;
  6329. #ifdef COMMENT
  6330. if (zz == XYIGN && xx == XYSEND) {
  6331. blah blah who cares
  6332. }
  6333. if (zz == XYDBL && xx == XYRECV) {
  6334. blah blah
  6335. }
  6336. #endif /* COMMENT */
  6337. p = (short *)malloc(256 * sizeof(short));
  6338. if (!p) {
  6339. printf("?Internal error - malloc failure\n");
  6340. return(-9);
  6341. }
  6342. for (i = 0; i < 256; i++) p[i] = dblt[i]; /* Copy current table */
  6343. while (1) { /* Collect a list of numbers */
  6344. #ifndef NOSPL
  6345. x_ifnum = 1; /* Turn off complaints from eval() */
  6346. #endif /* NOSPL */
  6347. if ((x = cmnum(zz == XYDBL ?
  6348. "Character to double" :
  6349. "Character to ignore",
  6350. "",10,&y,xxstring
  6351. )) < 0) {
  6352. #ifndef NOSPL
  6353. x_ifnum = 0;
  6354. #endif /* NOSPL */
  6355. if (x == -3) /* Done */
  6356. break;
  6357. if (x == -2) {
  6358. if (p) { free(p); p = NULL; }
  6359. debug(F110,"SET S/R DOUBLE/IGNORE atmbuf",atmbuf,0);
  6360. if (!ckstrcmp(atmbuf,"none",4,0) ||
  6361. !ckstrcmp(atmbuf,"non",3,0) ||
  6362. !ckstrcmp(atmbuf,"no",2,0) ||
  6363. !ckstrcmp(atmbuf,"n",1,0)) {
  6364. if ((x = cmcfm()) < 0) /* Get confirmation */
  6365. return(x);
  6366. for (y = 0; y < 256; y++)
  6367. dblt[y] &= (zz == XYDBL) ? 1 : 2;
  6368. if (zz == XYDBL) dblflag = 0;
  6369. if (zz == XYIGN) ignflag = 0;
  6370. return(success = 1);
  6371. } else {
  6372. printf(
  6373. "?Please specify a number or the word NONE\n");
  6374. return(-9);
  6375. }
  6376. } else {
  6377. free(p);
  6378. p = NULL;
  6379. return(x);
  6380. }
  6381. }
  6382. #ifndef NOSPL
  6383. x_ifnum = 0;
  6384. #endif /* NOSPL */
  6385. if (y < 0 || y > 255) {
  6386. printf("?Please enter a character code in range 0-255\n");
  6387. free(p);
  6388. p = NULL;
  6389. return(-9);
  6390. }
  6391. p[y] |= (zz == XYDBL) ? 2 : 1;
  6392. if (zz == XYDBL) dblflag = 1;
  6393. if (zz == XYIGN) ignflag = 1;
  6394. } /* End of while loop */
  6395. if ((x = cmcfm()) < 0) return(x);
  6396. /*
  6397. Get here only if they have made no mistakes. Copy temporary table back to
  6398. permanent one, then free temporary table and return successfully.
  6399. */
  6400. if (p) {
  6401. for (i = 0; i < 256; i++) dblt[i] = p[i];
  6402. free(p);
  6403. p = NULL;
  6404. }
  6405. return(success = 1);
  6406. }
  6407. #endif /* CKXXCHAR */
  6408. #ifdef PIPESEND
  6409. case XYFLTR: { /* SET { SEND, RECEIVE } FILTER */
  6410. if ((y = cmtxt((xx == XYSEND) ?
  6411. "Filter program for sending files -\n\
  6412. use \\v(filename) to substitute filename" :
  6413. "Filter program for receiving files -\n\
  6414. use \\v(filename) to substitute filename",
  6415. "",&s,NULL)) < 0)
  6416. return(y);
  6417. if (!*s) { /* Removing a filter... */
  6418. if (xx == XYSEND && sndfilter) {
  6419. makestr(&g_sfilter,NULL);
  6420. makestr(&sndfilter,NULL);
  6421. } else if (rcvfilter) {
  6422. makestr(&g_rfilter,NULL);
  6423. makestr(&rcvfilter,NULL);
  6424. }
  6425. return(success = 1);
  6426. } /* Adding a filter... */
  6427. s = brstrip(s); /* Strip any braces */
  6428. y = strlen(s);
  6429. if (xx == XYSEND) { /* For SEND filter... */
  6430. for (x = 0; x < y; x++) { /* make sure they included "\v(...)" */
  6431. if (s[x] != '\\') continue;
  6432. if (s[x+1] == 'v') break;
  6433. }
  6434. if (x == y) {
  6435. printf(
  6436. "?Filter must contain a replacement variable for filename.\n"
  6437. );
  6438. return(-9);
  6439. }
  6440. }
  6441. if (xx == XYSEND) {
  6442. makestr(&sndfilter,s);
  6443. makestr(&g_sfilter,s);
  6444. } else {
  6445. makestr(&rcvfilter,s);
  6446. makestr(&g_rfilter,s);
  6447. }
  6448. return(success = 1);
  6449. }
  6450. #endif /* PIPESEND */
  6451. case XYINIL:
  6452. y = cmnum("Max length for protocol init string","-1",10,&x,xxstring);
  6453. if ((y = setnum(&z,x,y,-1)) < 0)
  6454. return(y);
  6455. if (xx == XYSEND)
  6456. sprmlen = z;
  6457. else
  6458. rprmlen = z;
  6459. return(success = 1);
  6460. case 993: {
  6461. extern int sendipkts;
  6462. if (xx == XYSEND) {
  6463. if ((x = seton(&sendipkts)) < 0)
  6464. return(x);
  6465. }
  6466. return(1);
  6467. }
  6468. #ifdef CK_PERMS
  6469. case 994:
  6470. switch(xx) {
  6471. case XYSEND:
  6472. if ((x = seton(&atlpro)) < 0) return(x);
  6473. atgpro = atlpro;
  6474. return(1);
  6475. case XYRECV:
  6476. if ((x = seton(&atlpri)) < 0) return(x);
  6477. atgpri = atlpri;
  6478. return(1);
  6479. default:
  6480. return(-2);
  6481. }
  6482. #endif /* CK_PERMS */
  6483. #ifndef NOCSETS
  6484. case XYCSET: { /* CHARACTER-SET-SELECTION */
  6485. extern struct keytab xfrmtab[];
  6486. extern int r_cset, s_cset;
  6487. if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  6488. return(y);
  6489. if ((x = cmcfm()) < 0)
  6490. return(x);
  6491. if (xx == XYSEND)
  6492. s_cset = y;
  6493. else
  6494. r_cset = y;
  6495. return(success = 1);
  6496. }
  6497. #endif /* NOCSETS */
  6498. case XYBUP:
  6499. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  6500. return(y);
  6501. if ((x = cmcfm()) < 0) return(x);
  6502. if (xx == XYSEND) {
  6503. extern int skipbup;
  6504. skipbup = (y == 0) ? 1 : 0;
  6505. return(success = 1);
  6506. } else {
  6507. printf(
  6508. "?Please use SET FILE COLLISION to choose the desired action\n");
  6509. return(-9);
  6510. }
  6511. case XYMOVE:
  6512. #ifdef COMMENT
  6513. y = cmdir("Directory to move file(s) to after successful transfer",
  6514. "",&s,xxstring);
  6515. #else
  6516. y = cmtxt("Directory to move file(s) to after successful transfer",
  6517. "",&s,xxstring);
  6518. #endif /* COMMENT */
  6519. if (y < 0 && y != -3)
  6520. return(y);
  6521. ckstrncpy(line,s,LINBUFSIZ);
  6522. s = brstrip(line);
  6523. #ifdef COMMENT
  6524. /* Only needed for cmdir() */
  6525. if ((x = cmcfm()) < 0)
  6526. return(x);
  6527. #endif /* COMMENT */
  6528. /* Check directory existence if absolute */
  6529. /* THIS MEANS IT CAN'T INCLUDE ANY DEFERRED VARIABLES! */
  6530. if (s) if (*s) {
  6531. if (isabsolute(s) && !isdir(s)) {
  6532. printf("?Directory does not exist - %s\n",s);
  6533. return(-9);
  6534. }
  6535. }
  6536. if (xx == XYSEND) {
  6537. if (*s) {
  6538. #ifdef COMMENT
  6539. /* Allow it to be relative */
  6540. zfnqfp(s,LINBUFSIZ,line);
  6541. #endif /* COMMENT */
  6542. makestr(&snd_move,line);
  6543. makestr(&g_snd_move,line);
  6544. } else {
  6545. makestr(&snd_move,NULL);
  6546. makestr(&g_snd_move,NULL);
  6547. }
  6548. } else {
  6549. if (*s) {
  6550. #ifdef COMMENT
  6551. /* Allow it to be relative */
  6552. zfnqfp(s,LINBUFSIZ,line);
  6553. #endif /* COMMENT */
  6554. makestr(&rcv_move,line);
  6555. makestr(&g_rcv_move,line);
  6556. } else {
  6557. makestr(&rcv_move,NULL);
  6558. makestr(&g_rcv_move,NULL);
  6559. }
  6560. }
  6561. return(success = 1);
  6562. case XYRENAME:
  6563. y = cmtxt("Template to rename file(s) to after successful transfer",
  6564. "",&s,NULL); /* NOTE: no xxstring */
  6565. if (y < 0 && y != -3) /* Evaluation is deferred */
  6566. return(y);
  6567. ckstrncpy(line,s,LINBUFSIZ);
  6568. s = brstrip(line);
  6569. if ((x = cmcfm()) < 0)
  6570. return(x);
  6571. if (xx == XYSEND) {
  6572. if (*s) {
  6573. makestr(&snd_rename,s);
  6574. makestr(&g_snd_rename,s);
  6575. } else {
  6576. makestr(&snd_rename,NULL);
  6577. makestr(&g_snd_rename,NULL);
  6578. }
  6579. } else {
  6580. if (*s) {
  6581. makestr(&rcv_rename,s);
  6582. makestr(&g_rcv_rename,s);
  6583. } else {
  6584. makestr(&rcv_rename,NULL);
  6585. makestr(&g_rcv_rename,NULL);
  6586. }
  6587. }
  6588. return(success = 1);
  6589. #ifdef VMS
  6590. case 887: /* VERSION-NUMBERS */
  6591. if (xx == XYSEND) {
  6592. extern int vmssversions;
  6593. return(seton(&vmssversions));
  6594. } else {
  6595. extern int vmsrversions;
  6596. return(seton(&vmsrversions));
  6597. }
  6598. #endif /* VMS */
  6599. default:
  6600. return(-2);
  6601. } /* End of SET SEND/RECEIVE... */
  6602. }
  6603. #endif /* NOXFER */
  6604. #ifndef NOXMIT
  6605. int
  6606. setxmit() {
  6607. if ((y = cmkey(xmitab,nxmit,"","",xxstring)) < 0) return(y);
  6608. switch (y) {
  6609. case XMITE: /* EOF */
  6610. y = cmtxt("Characters to send at end of file,\n\
  6611. Use backslash codes for control characters","",&s,xxstring);
  6612. if (y < 0) return(y);
  6613. if ((int)strlen(s) > XMBUFL) {
  6614. printf("?Too many characters, %d maximum\n",XMBUFL);
  6615. return(-2);
  6616. }
  6617. ckstrncpy(xmitbuf,s,XMBUFL);
  6618. return(success = 1);
  6619. case XMITF: /* Fill */
  6620. y = cmnum("Numeric code for blank-line fill character","0",10,&x,
  6621. xxstring);
  6622. if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6623. xmitf = z;
  6624. return(success = 1);
  6625. case XMITL: /* Linefeed */
  6626. return(seton(&xmitl));
  6627. case XMITS: /* Locking-Shift */
  6628. return(seton(&xmits));
  6629. case XMITP: /* Prompt */
  6630. y = cmnum("Numeric code for host's prompt character, 0 for none",
  6631. "10",10,&x,xxstring);
  6632. if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6633. xmitp = z;
  6634. return(success = 1);
  6635. case XMITX: /* Echo */
  6636. return(seton(&xmitx));
  6637. case XMITW: /* Pause */
  6638. y = cmnum("Number of milliseconds to pause between binary characters\n\
  6639. or text lines during transmission","0",10,&x,xxstring);
  6640. if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6641. xmitw = z;
  6642. return(success = 1);
  6643. case XMITT: /* Timeout */
  6644. y = cmnum("Seconds to wait for each character to echo",
  6645. "1",10,&x,xxstring);
  6646. if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6647. xmitt = z;
  6648. return(success = 1);
  6649. default:
  6650. return(-2);
  6651. }
  6652. }
  6653. #endif /* NOXMIT */
  6654. #ifndef NOXFER
  6655. /* D O R M T -- Do a remote command */
  6656. VOID
  6657. rmsg() {
  6658. if (pflag && !quiet && fdispla != XYFD_N)
  6659. printf(
  6660. #ifdef CK_NEED_SIG
  6661. " Type your escape character, %s, followed by X or E to cancel.\n",
  6662. dbchr(escape)
  6663. #else
  6664. " Press the X or E key to cancel.\n"
  6665. #endif /* CK_NEED_SIG */
  6666. );
  6667. }
  6668. static int xzcmd = 0; /* Global copy of REMOTE cmd index */
  6669. /* R E M C F M -- Confirm a REMOTE command */
  6670. /*
  6671. Like cmcfm(), but allows for a redirection indicator on the end,
  6672. like "> filename" or "| command". Returns what cmcfm() would have
  6673. returned: -1 if reparse needed, etc etc blah blah. On success,
  6674. returns 1 with:
  6675. char * remdest containing the name of the file or command.
  6676. int remfile set to 1 if there is to be any redirection.
  6677. int remappd set to 1 if output file is to be appended to.
  6678. int rempipe set to 1 if remdest is a command, 0 if it is a file.
  6679. */
  6680. static int
  6681. remcfm() {
  6682. int x = 0;
  6683. char *s;
  6684. char *helptxt = "> filename, | command,\n\
  6685. or type carriage return to confirm the command";
  6686. char c;
  6687. remfile = 0;
  6688. rempipe = 0;
  6689. remappd = 0;
  6690. if ((x = cmtxt(helptxt,"",&s,xxstring)) < 0) {
  6691. return(x);
  6692. }
  6693. if (remdest) {
  6694. free(remdest);
  6695. remdest = NULL;
  6696. }
  6697. debug(F101,"remcfm local","",local);
  6698. debug(F110,"remcfm s",s,0);
  6699. debug(F101,"remcfm cmd","",xzcmd);
  6700. /*
  6701. This check was added in C-Kermit 6.0 or 7.0 but it turns out to be
  6702. unhelpful in the situation where the remote is running a script that sends
  6703. REMOTE commands to the local workstation. What happens is, the local
  6704. server executes the command and sends the result back as screen text, which
  6705. is indicated by using an X packet instead of an F packet as the file
  6706. header. There are two parts to this: executing the command under control
  6707. of the remote Kermit, which is desirable (and in fact some big applications
  6708. depend on it, and therefore never installed any new C-Kermit versions after
  6709. 5A), and displaying the result. Commenting out the check allows the
  6710. command to be executed, but the result is still sent back to the remote in
  6711. a file transfer, where it vanishes into the ether. Actually it's on the
  6712. communication connection, mixed in with the packets. Pretty amazing that
  6713. the file transfer still works, right?
  6714. */
  6715. #ifdef COMMENT
  6716. if (!*s) { /* No redirection indicator */
  6717. if (!local &&
  6718. (xzcmd == XZDIR || xzcmd == XZTYP ||
  6719. xzcmd == XZXIT || xzcmd == XZSPA ||
  6720. xzcmd == XZHLP || xzcmd == XZPWD ||
  6721. xzcmd == XZLGI || xzcmd == XZLGO ||
  6722. xzcmd == XZWHO || xzcmd == XZHOS)) {
  6723. printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6724. return(-9);
  6725. } else
  6726. return(1);
  6727. }
  6728. #endif /* COMMENT */
  6729. if (!s) s = ""; /* 2014-11-03 */
  6730. if (!*s) return(1); /* 2014-11-03 */
  6731. c = *s; /* We have something */
  6732. if (c != '>' && c != '|') { /* Is it > or | ? */
  6733. printf("?Not confirmed\n"); /* No */
  6734. return(-9);
  6735. }
  6736. s++; /* See what follows */
  6737. if (c == '>' && *s == '>') { /* Allow for ">>" too */
  6738. s++;
  6739. remappd = 1; /* Append to output file */
  6740. }
  6741. while (*s == SP || *s == HT) s++; /* Strip intervening whitespace */
  6742. if (!*s) {
  6743. printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  6744. return(-9);
  6745. }
  6746. if (c == '>' && zchko(s) < 0) { /* Check accessibility */
  6747. printf("?Access denied - %s\n", s);
  6748. return(-9);
  6749. }
  6750. remfile = 1; /* Set global results */
  6751. rempipe = (c == '|');
  6752. if (rempipe
  6753. #ifndef NOPUSH
  6754. && nopush
  6755. #endif /* NOPUSH */
  6756. ) {
  6757. printf("?Sorry, access to external commands is disabled.\n");
  6758. return(-9);
  6759. }
  6760. makestr(&remdest,s);
  6761. #ifndef NODEBUG
  6762. if (deblog) {
  6763. debug(F101,"remcfm remfile","",remfile);
  6764. debug(F101,"remcfm remappd","",remappd);
  6765. debug(F101,"remcfm rempipe","",rempipe);
  6766. debug(F110,"remcfm remdest",remdest, 0);
  6767. }
  6768. #endif /* NODEBUG */
  6769. return(1);
  6770. }
  6771. /* R E M T X T -- Like remcfm()... */
  6772. /*
  6773. ... but for REMOTE commands that end with cmtxt().
  6774. Here we must decipher braces to discover whether the trailing
  6775. redirection indicator is intended for local use, or to be sent out
  6776. to the server, as in:
  6777. remote host blah blah > file This end
  6778. remote host { blah blah } > file This end
  6779. remote host { blah blah > file } That end
  6780. remote host { blah blah > file } > file Both ends
  6781. Pipes too:
  6782. remote host blah blah | cmd This end
  6783. remote host { blah blah } | cmd This end
  6784. remote host { blah blah | cmd } That end
  6785. remote host { blah blah | cmd } | cmd Both ends
  6786. Or both:
  6787. remote host blah blah | cmd > file This end, etc etc...
  6788. Note: this really only makes sense for REMOTE HOST, but why be picky?
  6789. Call after calling cmtxt(), with pointer to string that cmtxt() parsed,
  6790. as in "remtxt(&s);".
  6791. Returns:
  6792. 1 on success with braces & redirection things removed & pointer updated,
  6793. -9 on failure (bad indirection), after printing error message.
  6794. */
  6795. int
  6796. remtxt(p) char ** p; {
  6797. int i, x, bpos, ppos;
  6798. char c, *s, *q;
  6799. remfile = 0; /* Initialize global results */
  6800. rempipe = 0;
  6801. remappd = 0;
  6802. if (remdest) {
  6803. free(remdest);
  6804. remdest = NULL;
  6805. }
  6806. s = *p;
  6807. if (!s) /* No redirection indicator */
  6808. s = "";
  6809. #ifdef COMMENT
  6810. if (!*s) { /* Ditto */
  6811. if (!local &&
  6812. (xzcmd == XZDIR || xzcmd == XZTYP ||
  6813. xzcmd == XZXIT || xzcmd == XZSPA ||
  6814. xzcmd == XZHLP || xzcmd == XZPWD ||
  6815. xzcmd == XZLGI || xzcmd == XZLGO ||
  6816. xzcmd == XZWHO || xzcmd == XZHOS)) {
  6817. printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6818. if (hints) {
  6819. printf("Hint: Try again with an output redirector.\n");
  6820. }
  6821. return(-9);
  6822. } else
  6823. return(1);
  6824. }
  6825. #endif /* COMMENT */
  6826. bpos = -1; /* Position of > (bracket) */
  6827. ppos = -1; /* Position of | (pipe) */
  6828. x = strlen(s); /* Length of cmtxt() string */
  6829. for (i = x-1; i >= 0; i--) { /* Search right to left. */
  6830. c = s[i];
  6831. if (c == '}') /* Break on first right brace */
  6832. break; /* Don't look at contents of braces */
  6833. else if (c == '>') /* Record position of > */
  6834. bpos = i;
  6835. else if (c == '|') /* and of | */
  6836. ppos = i;
  6837. }
  6838. if (bpos < 0 && ppos < 0) { /* No redirectors. */
  6839. #ifdef COMMENT
  6840. if (!local &&
  6841. (xzcmd == XZDIR || xzcmd == XZTYP ||
  6842. xzcmd == XZXIT || xzcmd == XZSPA ||
  6843. xzcmd == XZHLP || xzcmd == XZPWD ||
  6844. xzcmd == XZLGI || xzcmd == XZLGO ||
  6845. xzcmd == XZWHO || xzcmd == XZHOS)) {
  6846. printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6847. if (hints) {
  6848. printf("Hint: Try again with an output redirector.\n");
  6849. }
  6850. return(-9);
  6851. }
  6852. #endif /* COMMENT */
  6853. s = brstrip(s); /* Remove outer braces if any. */
  6854. *p = s; /* Point to result */
  6855. return(1); /* and return. */
  6856. }
  6857. remfile = 1; /* It's | or > */
  6858. i = -1; /* Get leftmost symbol */
  6859. if (bpos > -1) /* Bracket */
  6860. i = bpos;
  6861. if (ppos > -1 && (ppos < bpos || bpos < 0)) { /* or pipe */
  6862. i = ppos;
  6863. rempipe = 1;
  6864. }
  6865. if (rempipe
  6866. #ifndef NOPUSH
  6867. && nopush
  6868. #endif /* NOPUSH */
  6869. ) {
  6870. printf("?Sorry, access to external commands is disabled.\n");
  6871. return(-9);
  6872. }
  6873. c = s[i]; /* Copy of symbol */
  6874. if (c == '>' && s[i+1] == '>') /* ">>" for append? */
  6875. remappd = 1; /* It's not just a flag it's a number */
  6876. q = s + i + 1 + remappd; /* Point past symbol in string */
  6877. while (*q == SP || *q == HT) q++; /* and any intervening whitespace */
  6878. if (!*q) {
  6879. printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  6880. return(-9);
  6881. }
  6882. if (c == '>' && zchko(q) < 0) { /* (Doesn't work for | cmd > file) */
  6883. printf("?Access denied - %s\n", q);
  6884. return(-9);
  6885. }
  6886. makestr(&remdest,q); /* Create the destination string */
  6887. q = s + i - 1; /* Point before symbol */
  6888. while (q > s && (*q == SP || *q == HT)) /* Strip trailing whitespace */
  6889. q--;
  6890. *(q+1) = NUL; /* Terminate the string. */
  6891. s = brstrip(s); /* Remove any braces */
  6892. *p = s; /* Set return value */
  6893. #ifndef NODEBUG
  6894. if (deblog) {
  6895. debug(F101,"remtxt remfile","",remfile);
  6896. debug(F101,"remtxt remappd","",remappd);
  6897. debug(F101,"remtxt rempipe","",rempipe);
  6898. debug(F110,"remtxt remdest",remdest, 0);
  6899. debug(F110,"remtxt command",s,0);
  6900. }
  6901. #endif /* NODEBUG */
  6902. return(1);
  6903. }
  6904. int
  6905. plogin(xx) int xx; {
  6906. char *p1 = NULL, *p2 = NULL, *p3 = NULL;
  6907. int psaved = 0, rc = 0;
  6908. #ifdef CK_RECALL
  6909. extern int on_recall; /* around Password prompting */
  6910. #endif /* CK_RECALL */
  6911. debug(F101,"plogin local","",local);
  6912. if (!local || (network && ttchk() < 0)) {
  6913. printf("?No connection\n");
  6914. return(-9);
  6915. }
  6916. if ((x = cmfld("User ID","",&s,xxstring)) < 0) { /* Get User ID */
  6917. if (x != -3) return(x);
  6918. }
  6919. y = strlen(s);
  6920. if (y > 0) {
  6921. if ((p1 = malloc(y + 1)) == NULL) {
  6922. printf("?Internal error: malloc\n");
  6923. rc = -9;
  6924. goto XZXLGI;
  6925. } else
  6926. strcpy(p1,s); /* safe */
  6927. if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  6928. if (rc != -3) goto XZXLGI;
  6929. y = strlen(s);
  6930. if (y > 0) {
  6931. if ((p2 = malloc(y + 1)) == NULL) {
  6932. printf("?Internal error: malloc\n");
  6933. rc = -9;
  6934. goto XZXLGI;
  6935. } else
  6936. strcpy(p2,s); /* safe */
  6937. if ((rc = cmfld("Account","",&s,xxstring)) < 0)
  6938. if (rc != -3) goto XZXLGI;
  6939. y = strlen(s);
  6940. if (y > 0) {
  6941. if ((p3 = malloc(y + 1)) == NULL) {
  6942. printf("?Internal error: malloc\n");
  6943. rc = -9;
  6944. goto XZXLGI;
  6945. } else
  6946. strcpy(p3,s); /* safe */
  6947. }
  6948. }
  6949. }
  6950. if ((rc = remtxt(&s)) < 0) /* Confirm & handle redirectors */
  6951. goto XZXLGI;
  6952. if (!p1) { /* No Userid specified... */
  6953. debok = 0; /* Don't log this */
  6954. /* Prompt for username, password, and account */
  6955. #ifdef CK_RECALL
  6956. on_recall = 0;
  6957. #endif /* CK_RECALL */
  6958. cmsavp(psave,PROMPTL); /* Save old prompt */
  6959. psaved = 1;
  6960. debug(F110,"REMOTE LOGIN saved",psave,0);
  6961. cmsetp("Username: "); /* Make new prompt */
  6962. concb((char)escape); /* Put console in cbreak mode */
  6963. cmini(1);
  6964. prompt(xxstring);
  6965. rc = -9;
  6966. for (x = -1; x < 0; ) { /* Prompt till they answer */
  6967. cmres(); /* Reset the parser */
  6968. x = cmtxt("","",&s,NULL); /* Get a literal line of text */
  6969. }
  6970. y = strlen(s);
  6971. if (y < 1) {
  6972. printf("?Canceled\n");
  6973. goto XZXLGI;
  6974. }
  6975. if ((p1 = malloc(y + 1)) == NULL) {
  6976. printf("?Internal error: malloc\n");
  6977. goto XZXLGI;
  6978. } else
  6979. strcpy(p1,s); /* safe */
  6980. cmsetp("Password: "); /* Make new prompt */
  6981. concb((char)escape); /* Put console in cbreak mode */
  6982. cmini(0); /* No echo */
  6983. prompt(xxstring);
  6984. debok = 0;
  6985. for (x = -1; x < 0 && x != -3; ) { /* Get answer */
  6986. cmres(); /* Reset the parser */
  6987. x = cmtxt("","",&s,NULL); /* Get literal line of text */
  6988. }
  6989. if ((p2 = malloc((int)strlen(s) + 1)) == NULL) {
  6990. printf("?Internal error: malloc\n");
  6991. goto XZXLGI;
  6992. } else
  6993. strcpy(p2,s); /* safe */
  6994. printf("\r\n");
  6995. if ((rc = cmcfm()) < 0)
  6996. goto XZXLGI;
  6997. }
  6998. sstate = setgen('I',p1,p2,p3); /* Get here with at least user ID */
  6999. rc = 0;
  7000. XZXLGI: /* Common exit point */
  7001. if (psaved)
  7002. cmsetp(psave); /* Restore original prompt */
  7003. if (p3) { free(p3); p3 = NULL; } /* Free malloc'd storage */
  7004. if (p2) { free(p2); p2 = NULL; }
  7005. if (p1) { free(p1); p1 = NULL; }
  7006. if (rc > -1) {
  7007. if (local && rc > -1) /* If local, flush tty input buffer */
  7008. ttflui();
  7009. }
  7010. return(rc);
  7011. }
  7012. #ifdef OS2
  7013. #ifndef NOLOCAL
  7014. int
  7015. dormt(xx) int xx; {
  7016. int rc = 0;
  7017. extern int term_io;
  7018. int term_io_sav = term_io;
  7019. #ifdef NEWFTP
  7020. extern int ftpget, ftpisopen();
  7021. if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7022. return(doftprmt(xx,0));
  7023. #endif /* NEWFTP */
  7024. term_io = 0;
  7025. rc = xxdormt(xx);
  7026. term_io = term_io_sav;
  7027. return rc;
  7028. }
  7029. int
  7030. xxdormt(xx) int xx;
  7031. #else /* NOLOCAL */
  7032. int
  7033. dormt(xx) int xx;
  7034. #endif /* NOLOCAL */
  7035. #else /* OS2 */
  7036. int
  7037. dormt(xx) int xx;
  7038. #endif /* OS2 */
  7039. { /* REMOTE commands */
  7040. int x, y, retcode;
  7041. char *s, sbuf[50], *s2;
  7042. #ifdef NEWFTP
  7043. extern int ftpget, ftpisopen();
  7044. if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7045. return(doftprmt(xx,0));
  7046. #endif /* NEWFTP */
  7047. remfile = 0; /* Clear these */
  7048. rempipe = 0;
  7049. remappd = 0;
  7050. debug(F101,"XXX xxdormt xx","",xx);
  7051. if (xx < 0) return(xx); /* REMOTE what? */
  7052. xzcmd = xx; /* Make global copy of arg */
  7053. if (xx == XZSET) { /* REMOTE SET */
  7054. if ((y = cmkey(rmstab,nrms,"","",xxstring)) < 0) {
  7055. if (y == -3) {
  7056. printf("?Parameter name required\n");
  7057. return(-9);
  7058. } else return(y);
  7059. }
  7060. return(doprm(y,1));
  7061. }
  7062. switch (xx) { /* Others... */
  7063. case XZCDU:
  7064. if ((x = cmcfm()) < 0) return(x);
  7065. printf("?Sorry, REMOTE CDUP not supported yet\n");
  7066. return(-9);
  7067. case XZCWD: /* CWD (CD) */
  7068. if ((x = cmtxt("Remote directory name","",&s,xxstring)) < 0)
  7069. return(x);
  7070. if ((x = remtxt(&s)) < 0)
  7071. return(x);
  7072. debug(F111,"XZCWD: ",s,x);
  7073. *sbuf = NUL;
  7074. s2 = sbuf;
  7075. /*
  7076. The following is commented out because since the disappearance of the
  7077. DECSYSTEM-20 from the planet, no known computer requires a password for
  7078. changing directory.
  7079. */
  7080. #ifdef DIRPWDPR
  7081. if (*s != NUL) { /* If directory name given, */
  7082. /* get password on separate line. */
  7083. if (tlevel > -1) { /* From take file... */
  7084. if (fgets(sbuf,50,tfile[tlevel]) == NULL)
  7085. fatal("take file ends prematurely in 'remote cwd'");
  7086. debug(F110," pswd from take file",s2,0);
  7087. for (x = (int)strlen(sbuf);
  7088. x > 0 && (sbuf[x-1] == NL || sbuf[x-1] == CR);
  7089. x--)
  7090. sbuf[x-1] = '\0';
  7091. } else { /* From terminal... */
  7092. printf(" Password: "); /* get a password */
  7093. #ifdef IKSD
  7094. if (!local && inserver) {
  7095. x = coninc(0);
  7096. } else
  7097. #endif /* IKSD */
  7098. #ifdef OS2
  7099. x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7100. getchar();
  7101. #else /* OS2 */
  7102. x = getchar();
  7103. #endif /* OS2 */
  7104. while ((x != NL) && (x != CR)) {
  7105. if ((x &= 0177) == '?') {
  7106. printf("? Password of remote directory\n Password: ");
  7107. s2 = sbuf;
  7108. *sbuf = NUL;
  7109. } else if (x == ESC) /* Mini command line editor... */
  7110. bleep(BP_WARN);
  7111. else if (x == BS || x == 0177)
  7112. s2--;
  7113. else if (x == 025) { /* Ctrl-U */
  7114. s2 = sbuf;
  7115. *sbuf = NUL;
  7116. } else
  7117. *s2++ = x;
  7118. /* Get the next character */
  7119. #ifdef IKSD
  7120. if (!local && inserver) {
  7121. x = coninc(0);
  7122. } else
  7123. #endif /* IKSD */
  7124. #ifdef OS2
  7125. x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7126. getchar();
  7127. #else /* OS2 */
  7128. x = getchar();
  7129. #endif /* OS2 */
  7130. }
  7131. *s2 = NUL;
  7132. putchar('\n');
  7133. }
  7134. s2 = sbuf;
  7135. } else s2 = "";
  7136. #endif /* DIRPWDPR */
  7137. debug(F110," password",s2,0);
  7138. rcdactive = 1;
  7139. sstate = setgen('C',s,s2,"");
  7140. retcode = 0;
  7141. break;
  7142. case XZDEL: /* Delete */
  7143. if ((x = cmtxt("Name of remote file(s) to delete",
  7144. "",&s,xxstring)) < 0) {
  7145. if (x == -3) {
  7146. printf("?Name of remote file(s) required\n");
  7147. return(-9);
  7148. } else return(x);
  7149. }
  7150. if ((x = remtxt(&s)) < 0)
  7151. return(x);
  7152. if (local) ttflui(); /* If local, flush tty input buffer */
  7153. retcode = sstate = rfilop(s,'E');
  7154. break;
  7155. case XZDIR: /* Directory */
  7156. if ((x = cmtxt("Remote directory or file specification","",&s,
  7157. xxstring)) < 0)
  7158. return(x);
  7159. if ((x = remtxt(&s)) < 0)
  7160. return(x);
  7161. if (local) ttflui(); /* If local, flush tty input buffer */
  7162. rmsg();
  7163. retcode = sstate = setgen('D',s,"","");
  7164. break;
  7165. case XZHLP: /* Help */
  7166. if ((x = remcfm()) < 0) return(x);
  7167. sstate = setgen('H',"","","");
  7168. retcode = 0;
  7169. break;
  7170. case XZHOS: /* Host */
  7171. if ((x = cmtxt("Command for remote system","",&s,xxstring)) < 0)
  7172. return(x);
  7173. if ((x = remtxt(&s)) < 0)
  7174. return(x);
  7175. if ((y = (int)strlen(s)) < 1)
  7176. return(x);
  7177. ckstrncpy(line,s,LINBUFSIZ);
  7178. cmarg = line;
  7179. rmsg();
  7180. retcode = sstate = 'c';
  7181. break;
  7182. #ifndef NOFRILLS
  7183. case XZKER:
  7184. if ((x = cmtxt("Command for remote Kermit","",&s,xxstring)) < 0)
  7185. return(x);
  7186. if ((x = remtxt(&s)) < 0)
  7187. return(x);
  7188. if ((int)strlen(s) < 1) {
  7189. if (x == -3) {
  7190. printf("?Remote Kermit command required\n");
  7191. return(-9);
  7192. } else return(x);
  7193. }
  7194. ckstrncpy(line,s,LINBUFSIZ);
  7195. cmarg = line;
  7196. retcode = sstate = 'k';
  7197. rmsg();
  7198. break;
  7199. case XZLGI: /* Login */
  7200. rcdactive = 1; /* Suppress "Logged in" msg if quiet */
  7201. return(plogin(XXREM));
  7202. case XZLGO: { /* Logout */
  7203. extern int bye_active;
  7204. if ((x = remcfm()) < 0) return(x);
  7205. sstate = setgen('I',"","","");
  7206. retcode = 0;
  7207. bye_active = 1; /* Close connection when done */
  7208. break;
  7209. }
  7210. case XZPRI: /* Print */
  7211. if (!atdiso || !atcapr) { /* Disposition attribute off? */
  7212. printf("?Disposition Attribute is Off\n");
  7213. return(-2);
  7214. }
  7215. cmarg = "";
  7216. cmarg2 = "";
  7217. if ((x = cmifi("Local file(s) to print on remote printer","",&s,&y,
  7218. xxstring)) < 0) {
  7219. if (x == -3) {
  7220. printf("?Name of local file(s) required\n");
  7221. return(-9);
  7222. }
  7223. return(x);
  7224. }
  7225. ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy of filename */
  7226. *optbuf = NUL; /* Wipe out any old options */
  7227. if ((x = cmtxt("Options for remote print command","",&s,xxstring)) < 0)
  7228. return(x);
  7229. if ((x = remtxt(&s)) < 0)
  7230. return(x);
  7231. if ((int)strlen(optbuf) > 94) { /* Make sure this is legal */
  7232. printf("?Option string too long\n");
  7233. return(-9);
  7234. }
  7235. ckstrncpy(optbuf,s,OPTBUFLEN); /* Make a safe copy of options */
  7236. nfils = -1; /* Expand file list internally */
  7237. cmarg = line; /* Point to file list. */
  7238. rprintf = 1; /* REMOTE PRINT modifier for SEND */
  7239. sstate = 's'; /* Set start state to SEND */
  7240. if (local) displa = 1;
  7241. retcode = 0;
  7242. break;
  7243. #endif /* NOFRILLS */
  7244. case XZSPA: /* Space */
  7245. if ((x = cmtxt("Confirm, or remote directory name",
  7246. "",&s,xxstring)) < 0)
  7247. return(x);
  7248. if ((x = remtxt(&s)) < 0)
  7249. return(x);
  7250. retcode = sstate = setgen('U',s,"","");
  7251. break;
  7252. case XZMSG: /* Message */
  7253. if ((x = cmtxt("Short text message for server","",&s,xxstring)) < 0)
  7254. return(x);
  7255. if ((x = remtxt(&s)) < 0)
  7256. return(x);
  7257. retcode = sstate = setgen('M',s,"","");
  7258. break;
  7259. #ifndef NOFRILLS
  7260. case XZTYP: /* Type */
  7261. if ((x = cmtxt("Remote file specification","",&s,xxstring)) < 0)
  7262. return(x);
  7263. if ((int)strlen(s) < 1) {
  7264. printf("?Remote filename required\n");
  7265. return(-9);
  7266. }
  7267. if ((x = remtxt(&s)) < 0)
  7268. return(x);
  7269. rmsg();
  7270. retcode = sstate = rfilop(s,'T');
  7271. break;
  7272. #endif /* NOFRILLS */
  7273. #ifndef NOFRILLS
  7274. case XZWHO:
  7275. if ((x = cmtxt("Remote user name, or carriage return",
  7276. "",&s,xxstring)) < 0)
  7277. return(x);
  7278. if ((x = remtxt(&s)) < 0)
  7279. return(x);
  7280. retcode = sstate = setgen('W',s,"","");
  7281. break;
  7282. #endif /* NOFRILLS */
  7283. case XZPWD: /* PWD */
  7284. if ((x = remcfm()) < 0) return(x);
  7285. sstate = setgen('A',"","","");
  7286. retcode = 0;
  7287. break;
  7288. #ifndef NOSPL
  7289. case XZQUE: { /* Query */
  7290. char buf[2];
  7291. extern char querybuf[], * qbufp;
  7292. extern int qbufn;
  7293. if ((y = cmkey(vartyp,nvartyp,"","",xxstring)) < 0)
  7294. return(y);
  7295. if ((x = cmtxt(y == 'F' ? "Remote function invocation" :
  7296. ('K' ? "Remote variable name or function":
  7297. "Remote variable name"),
  7298. "",
  7299. &s,
  7300. (y == 'K') ? xxstring : NULL
  7301. )) < 0) /* Don't evaluate */
  7302. return(x);
  7303. if ((x = remtxt(&s)) < 0)
  7304. return(x);
  7305. query = 1; /* QUERY is active */
  7306. qbufp = querybuf; /* Initialize query response buffer */
  7307. qbufn = 0;
  7308. querybuf[0] = NUL;
  7309. buf[0] = (char) (y & 127);
  7310. buf[1] = NUL;
  7311. retcode = sstate = setgen('V',"Q",(char *)buf,s);
  7312. break;
  7313. }
  7314. case XZASG: { /* Assign */
  7315. char buf[VNAML];
  7316. if ((y = cmfld("Remote variable name","",&s,NULL)) < 0) /* No eval */
  7317. return(y);
  7318. if ((int)strlen(s) >= VNAML) {
  7319. printf("?Too long\n");
  7320. return(-9);
  7321. }
  7322. ckstrncpy(buf,s,VNAML);
  7323. if ((x = cmtxt("Assignment for remote variable",
  7324. "",&s,xxstring)) < 0) /* Evaluate this one */
  7325. return(x);
  7326. if ((x = remtxt(&s)) < 0)
  7327. return(x);
  7328. #ifdef COMMENT
  7329. /*
  7330. Server commands can't be long packets. In principle there's no reason
  7331. why they shouldn't be, except that we don't know at this point if the
  7332. server is capable of accepting long packets because we haven't started
  7333. the protocol yet. In practice, allowing a long packet here breaks a lot
  7334. of assumptions, causes buffer overruns and crashes, etc. To be fixed
  7335. later. (But since this is commented out, evidently I fixed it later...)
  7336. */
  7337. if ((int)strlen(s) > 85) { /* Allow for encoding expansion */
  7338. printf("?Sorry, value is too long - 85 characters max\n");
  7339. return(-9);
  7340. }
  7341. #endif /* COMMENT */
  7342. retcode = sstate = setgen('V',"S",(char *)buf,s);
  7343. break;
  7344. }
  7345. #endif /* NOSPL */
  7346. case XZCPY: { /* COPY */
  7347. char buf[TMPBUFSIZ];
  7348. buf[TMPBUFSIZ-1] = '\0';
  7349. if ((x = cmfld("Name of remote file to copy","",&s,xxstring)) < 0) {
  7350. if (x == -3) {
  7351. printf("?Name of remote file required\n");
  7352. return(-9);
  7353. }
  7354. else
  7355. return(x);
  7356. }
  7357. ckstrncpy(buf,s,TMPBUFSIZ);
  7358. if ((x = cmfld("Name of remote destination file or directory",
  7359. "",&s, xxstring)) < 0) {
  7360. if (x == -3) {
  7361. printf("?Name of remote file or directory required\n");
  7362. return(-9);
  7363. } else return(x);
  7364. }
  7365. ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7366. if ((x = remcfm()) < 0)
  7367. return(x);
  7368. if (local) ttflui(); /* If local, flush tty input buffer */
  7369. retcode = sstate = setgen('K',buf,tmpbuf,"");
  7370. break;
  7371. }
  7372. case XZREN: { /* Rename */
  7373. char buf[TMPBUFSIZ];
  7374. buf[TMPBUFSIZ-1] = '\0';
  7375. if ((x = cmfld("Name of remote file to rename",
  7376. "",&s,xxstring)) < 0) {
  7377. if (x == -3) {
  7378. printf("?Name of remote file required\n");
  7379. return(-9);
  7380. } else return(x);
  7381. }
  7382. ckstrncpy(buf,s,TMPBUFSIZ);
  7383. if ((x = cmfld("New name of remote file","",&s, xxstring)) < 0) {
  7384. if (x == -3) {
  7385. printf("?Name of remote file required\n");
  7386. return(-9);
  7387. } else return(x);
  7388. }
  7389. ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7390. if ((x = remcfm()) < 0)
  7391. return(x);
  7392. if (local) ttflui(); /* If local, flush device buffer */
  7393. retcode = sstate = setgen('R',buf,tmpbuf,"");
  7394. break;
  7395. }
  7396. case XZMKD: /* mkdir */
  7397. case XZRMD: /* rmdir */
  7398. if ((x = cmtxt((xx == XZMKD) ?
  7399. "Name of remote directory to create" :
  7400. "Name of remote directory to delete",
  7401. "",
  7402. &s,
  7403. xxstring
  7404. )) < 0) {
  7405. if (x == -3) {
  7406. printf("?Name required\n");
  7407. return(-9);
  7408. } else return(x);
  7409. }
  7410. if ((x = remtxt(&s)) < 0)
  7411. return(x);
  7412. if (local) ttflui(); /* If local, flush tty input buffer */
  7413. retcode = sstate = rfilop(s, (char)(xx == XZMKD ? 'm' : 'd'));
  7414. break;
  7415. case XZXIT: /* Exit */
  7416. if ((x = remcfm()) < 0) return(x);
  7417. sstate = setgen('X',"","","");
  7418. retcode = 0;
  7419. break;
  7420. default:
  7421. if ((x = remcfm()) < 0) return(x);
  7422. printf("?Not implemented - %s\n",cmdbuf);
  7423. return(-2);
  7424. }
  7425. if (local && retcode > -1) /* If local, flush tty input buffer */
  7426. ttflui();
  7427. return(retcode);
  7428. }
  7429. /* R F I L O P -- Remote File Operation */
  7430. CHAR
  7431. #ifdef CK_ANSIC
  7432. rfilop(char * s, char t)
  7433. #else
  7434. rfilop(s,t) char *s, t;
  7435. #endif /* CK_ANSIC */
  7436. /* rfilop */ {
  7437. if (*s == NUL) {
  7438. printf("?File specification required\n");
  7439. return((CHAR) 0);
  7440. }
  7441. debug(F111,"rfilop",s,t);
  7442. return(setgen(t,s,"",""));
  7443. }
  7444. #endif /* NOXFER */
  7445. #ifdef ANYX25
  7446. int
  7447. setx25() {
  7448. if ((y = cmkey(x25tab,nx25,"X.25 call options","",xxstring)) < 0)
  7449. return(y);
  7450. switch (y) {
  7451. case XYUDAT:
  7452. if ((z = cmkey(onoff,2,"X.25 call user data","",xxstring))
  7453. < 0) return(z);
  7454. if (z == 0) {
  7455. if ((z = cmcfm()) < 0) return(z);
  7456. cudata = 0; /* disable call user data */
  7457. return (success = 1);
  7458. }
  7459. if ((x = cmtxt("X.25 call user data string","",&s,xxstring)) < 0)
  7460. return(x);
  7461. if ((int)strlen(s) == 0) {
  7462. return (-3);
  7463. } else if ((int)strlen(s) > MAXCUDATA) {
  7464. printf("?The length must be > 0 and <= %d\n",MAXCUDATA);
  7465. return(-2);
  7466. }
  7467. if ((y = cmcfm()) < 0) return(y);
  7468. ckstrncpy(udata,s,MAXCUDATA);
  7469. cudata = 1; /* X.25 call user data specified */
  7470. return (success = 1);
  7471. case XYCLOS:
  7472. if ((z = cmkey(onoff,2,"X.25 closed user group call","",xxstring))
  7473. < 0) return(z);
  7474. if (z == 0) {
  7475. if ((z = cmcfm()) < 0) return(z);
  7476. closgr = -1; /* disable closed user group */
  7477. return (success = 1);
  7478. }
  7479. if ((y = cmnum("0 <= cug index >= 99","",10,&x,xxstring)) < 0)
  7480. return(y);
  7481. if (x < 0 || x > 99) {
  7482. printf("?The choices are 0 <= cug index >= 99\n");
  7483. return(-2);
  7484. }
  7485. if ((y = cmcfm()) < 0) return(y);
  7486. closgr = x; /* closed user group selected */
  7487. return (success = 1);
  7488. case XYREVC:
  7489. if((z = cmkey(onoff,2,"X.25 reverse charge call","",xxstring)) < 0)
  7490. return(z);
  7491. if ((x = cmcfm()) < 0) return(x);
  7492. revcall = z;
  7493. return (success = 1);
  7494. }
  7495. }
  7496. #ifndef IBMX25
  7497. int
  7498. setpadp() {
  7499. if ((y = cmkey(padx3tab,npadx3,"PAD X.3 parameter name","",xxstring)) < 0)
  7500. return(y);
  7501. x = y;
  7502. switch (x) {
  7503. case PAD_BREAK_CHARACTER:
  7504. if ((y = cmnum("PAD break character value","",10,&z,xxstring)) < 0)
  7505. return(y);
  7506. if ((y = cmcfm()) < 0) return(y);
  7507. break;
  7508. case PAD_ESCAPE:
  7509. if ((y = cmnum("PAD escape","",10,&z,xxstring)) < 0) return(y);
  7510. if (z != 0 && z != 1) {
  7511. printf("?The choices are 0 or 1\n");
  7512. return(-2);
  7513. }
  7514. if ((y = cmcfm()) < 0) return(y);
  7515. break;
  7516. case PAD_ECHO:
  7517. if ((y = cmnum("PAD echo","",10,&z,xxstring)) < 0) return(y);
  7518. if (z != 0 && z != 1) {
  7519. printf("?The choices are 0 or 1\n");
  7520. return(-2);
  7521. }
  7522. if ((y = cmcfm()) < 0) return(y);
  7523. break;
  7524. case PAD_DATA_FORWARD_CHAR:
  7525. if ((y = cmnum("PAD data forward char","",10,&z,xxstring)) < 0)
  7526. return(y);
  7527. if (z != 0 && z != 2) {
  7528. printf("?The choices are 0 or 2\n");
  7529. return(-2);
  7530. }
  7531. if ((y = cmcfm()) < 0) return(y);
  7532. break;
  7533. case PAD_DATA_FORWARD_TIMEOUT:
  7534. if ((y = cmnum("PAD data forward timeout","",10,&z,xxstring)) < 0)
  7535. return(y);
  7536. if (z < 0 || z > 255) {
  7537. printf("?The choices are 0 or 1 <= timeout <= 255\n");
  7538. return(-2);
  7539. }
  7540. if ((y = cmcfm()) < 0) return(y);
  7541. break;
  7542. case PAD_FLOW_CONTROL_BY_PAD:
  7543. if ((y = cmnum("PAD pad flow control","",10,&z,xxstring)) < 0)
  7544. return(y);
  7545. if (z != 0 && z != 1) {
  7546. printf("?The choices are 0 or 1\n");
  7547. return(-2);
  7548. }
  7549. if ((y = cmcfm()) < 0) return(y);
  7550. break;
  7551. case PAD_SUPPRESSION_OF_SIGNALS:
  7552. if ((y = cmnum("PAD service","",10,&z,xxstring)) < 0) return(y);
  7553. if (z != 0 && z != 1) {
  7554. printf("?The choices are 0 or 1\n");
  7555. return(-2);
  7556. }
  7557. if ((y = cmcfm()) < 0) return(y);
  7558. break;
  7559. case PAD_BREAK_ACTION:
  7560. if ((y = cmnum("PAD break action","",10,&z,xxstring)) < 0) return(y);
  7561. if (z != 0 && z != 1 && z != 2 && z != 5 && z != 8 && z != 21) {
  7562. printf("?The choices are 0, 1, 2, 5, 8 or 21\n");
  7563. return(-2);
  7564. }
  7565. if ((y = cmcfm()) < 0) return(y);
  7566. break;
  7567. case PAD_SUPPRESSION_OF_DATA:
  7568. if ((y = cmnum("PAD data delivery","",10,&z,xxstring)) < 0) return(y);
  7569. if (z != 0 && z != 1) {
  7570. printf("?The choices are 0 or 1\n");
  7571. return(-2);
  7572. }
  7573. if ((y = cmcfm()) < 0) return(y);
  7574. break;
  7575. case PAD_PADDING_AFTER_CR:
  7576. if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7577. if (z < 0 || z > 7) {
  7578. printf("?The choices are 0 or 1 <= crpad <= 7\n");
  7579. return(-2);
  7580. }
  7581. if ((y = cmcfm()) < 0) return(y);
  7582. break;
  7583. case PAD_LINE_FOLDING:
  7584. if ((y = cmnum("PAD linefold","",10,&z,xxstring)) < 0) return(y);
  7585. if (z < 0 || z > 255) {
  7586. printf("?The choices are 0 or 1 <= linefold <= 255\n");
  7587. return(-2);
  7588. }
  7589. if ((y = cmcfm()) < 0) return(y);
  7590. break;
  7591. case PAD_LINE_SPEED:
  7592. if ((y = cmnum("PAD baudrate","",10,&z,xxstring)) < 0) return(y);
  7593. if (z < 0 || z > 18) {
  7594. printf("?The choices are 0 <= baudrate <= 18\n");
  7595. return(-2);
  7596. }
  7597. if ((y = cmcfm()) < 0) return(y);
  7598. break;
  7599. case PAD_FLOW_CONTROL_BY_USER:
  7600. if ((y = cmnum("PAD terminal flow control","",10,&z,xxstring)) < 0)
  7601. return(y);
  7602. if (z != 0 && z != 1) {
  7603. printf("?The choices are 0 or 1\n");
  7604. return(-2);
  7605. }
  7606. if ((y = cmcfm()) < 0) return(y);
  7607. break;
  7608. case PAD_LF_AFTER_CR:
  7609. if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7610. if (z < 0 || z == 3 || z > 7) {
  7611. printf("?The choices are 0, 1, 2, 4, 5, 6 or 7\n");
  7612. return(-2);
  7613. }
  7614. if ((y = cmcfm()) < 0) return(y);
  7615. break;
  7616. case PAD_PADDING_AFTER_LF:
  7617. if ((y = cmnum("PAD lfpad","",10,&z,xxstring)) < 0) return(y);
  7618. if (z < 0 || z > 7) {
  7619. printf("?The choices are 0 or 1 <= lfpad <= 7\n");
  7620. return(-2);
  7621. }
  7622. if ((y = cmcfm()) < 0) return(y);
  7623. break;
  7624. case PAD_EDITING:
  7625. if ((y = cmnum("PAD edit control","",10,&z,xxstring)) < 0) return(y);
  7626. if (z != 0 && z != 1) {
  7627. printf("?The choices are 0 or 1\n");
  7628. return(-2);
  7629. }
  7630. if ((y = cmcfm()) < 0) return(y);
  7631. break;
  7632. case PAD_CHAR_DELETE_CHAR:
  7633. if ((y = cmnum("PAD char delete char","",10,&z,xxstring)) < 0)
  7634. return(y);
  7635. if (z < 0 || z > 127) {
  7636. printf("?The choices are 0 or 1 <= chardelete <= 127\n");
  7637. return(-2);
  7638. }
  7639. if ((y = cmcfm()) < 0) return(y);
  7640. break;
  7641. case PAD_BUFFER_DELETE_CHAR:
  7642. if ((y = cmnum("PAD buffer delete char","",10,&z,xxstring)) < 0)
  7643. return(y);
  7644. if (z < 0 || z > 127) {
  7645. printf("?The choices are 0 or 1 <= bufferdelete <= 127\n");
  7646. return(-2);
  7647. }
  7648. if ((y = cmcfm()) < 0) return(y);
  7649. break;
  7650. case PAD_BUFFER_DISPLAY_CHAR:
  7651. if ((y = cmnum("PAD display line char","",10,&z,xxstring)) < 0)
  7652. return(y);
  7653. if (z < 0 || z > 127) {
  7654. printf("?The choices are 0 or 1 <= displayline <= 127\n");
  7655. return(-2);
  7656. }
  7657. if ((y = cmcfm()) < 0) return(y);
  7658. break;
  7659. }
  7660. padparms[x] = z;
  7661. return(success = 1);
  7662. }
  7663. #endif /* IBMX25 */
  7664. #endif /* ANYX25 */
  7665. #ifndef NOXFER
  7666. int
  7667. setat(rmsflg) int rmsflg; {
  7668. int xx;
  7669. if ((y = cmkey(attrtab,natr,"File Attribute packets","",xxstring)) < 0)
  7670. return(y);
  7671. if (y == AT_XALL) { /* ATTRIBUTES ALL ON or ALL OFF */
  7672. if ((z = seton(&xx)) < 0) return(z);
  7673. if (rmsflg) {
  7674. printf("Sorry, command not available\n");
  7675. return(-9);
  7676. } else {
  7677. atenci = xx; /* Encoding in */
  7678. atenco = xx; /* Encoding out */
  7679. atdati = xx; /* Date in */
  7680. atdato = xx; /* Date out */
  7681. atdisi = xx; /* Disposition in/out */
  7682. atdiso = xx;
  7683. atleni = xx; /* Length in/out (both kinds) */
  7684. atleno = xx;
  7685. atblki = xx; /* Blocksize in/out */
  7686. atblko = xx;
  7687. attypi = xx; /* File type in/out */
  7688. attypo = xx;
  7689. atsidi = xx; /* System ID in/out */
  7690. atsido = xx;
  7691. atsysi = xx; /* System-dependent params in/out */
  7692. atsyso = xx;
  7693. #ifdef CK_PERMS /* Protection */
  7694. atlpri = xx; /* Local in */
  7695. atlpro = xx; /* Local out */
  7696. atgpri = xx; /* Generic in */
  7697. atgpro = xx; /* Generic out */
  7698. #endif /* CK_PERMS */
  7699. #ifdef STRATUS
  7700. atfrmi = xx; /* Format in/out */
  7701. atfrmo = xx;
  7702. atcrei = xx; /* Creator id in/out */
  7703. atcreo = xx;
  7704. atacti = xx; /* Account in/out */
  7705. atacto = xx;
  7706. #endif /* STRATUS */
  7707. }
  7708. return(z);
  7709. } else if (y == AT_ALLY || y == AT_ALLN) { /* ATTRIBUTES ON or OFF */
  7710. if ((x = cmcfm()) < 0) return(x);
  7711. atcapr = (y == AT_ALLY) ? 1 : 0;
  7712. if (rmsflg) {
  7713. sstate = setgen('S', "132", atcapr ? "1" : "0", "");
  7714. return((int) sstate);
  7715. } else return(success = 1);
  7716. }
  7717. /* Otherwise, it's an individual attribute that wants turning off/on */
  7718. if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  7719. if ((x = cmcfm()) < 0) return(x);
  7720. /* There are better ways to do this... */
  7721. /* The real problem is that we're not separating the in and out cases */
  7722. /* and so we have to arbitrarily pick the "in" case, i.e tell the remote */
  7723. /* server to ignore incoming attributes of the specified type, rather */
  7724. /* than telling it not to send them. The protocol does not (yet) define */
  7725. /* codes for "in-and-out-at-the-same-time". */
  7726. switch (y) {
  7727. #ifdef CK_PERMS
  7728. /* We're lumping local and generic protection together for now... */
  7729. case AT_LPRO:
  7730. case AT_GPRO:
  7731. if (rmsflg) {
  7732. sstate = setgen('S', "143", z ? "1" : "0", "");
  7733. return((int) sstate);
  7734. }
  7735. atlpri = atlpro = atgpri = atgpro = z; break;
  7736. #endif /* CK_PERMS */
  7737. case AT_DISP:
  7738. if (rmsflg) {
  7739. sstate = setgen('S', "142", z ? "1" : "0", "");
  7740. return((int) sstate);
  7741. }
  7742. atdisi = atdiso = z; break;
  7743. case AT_ENCO:
  7744. if (rmsflg) {
  7745. sstate = setgen('S', "141", z ? "1" : "0", "");
  7746. return((int) sstate);
  7747. }
  7748. atenci = atenco = z; break;
  7749. case AT_DATE:
  7750. if (rmsflg) {
  7751. sstate = setgen('S', "135", z ? "1" : "0", "");
  7752. return((int) sstate);
  7753. }
  7754. atdati = atdato = z; break;
  7755. case AT_LENB:
  7756. case AT_LENK:
  7757. if (rmsflg) {
  7758. sstate = setgen('S', "133", z ? "1" : "0", "");
  7759. return((int) sstate);
  7760. }
  7761. atleni = atleno = z; break;
  7762. case AT_BLKS:
  7763. if (rmsflg) {
  7764. sstate = setgen('S', "139", z ? "1" : "0", "");
  7765. return((int) sstate);
  7766. }
  7767. atblki = atblko = z; break;
  7768. case AT_FTYP:
  7769. if (rmsflg) {
  7770. sstate = setgen('S', "134", z ? "1" : "0", "");
  7771. return((int) sstate);
  7772. }
  7773. attypi = attypo = z; break;
  7774. #ifdef STRATUS
  7775. case AT_CREA:
  7776. if (rmsflg) {
  7777. sstate = setgen('S', "136", z ? "1" : "0", "");
  7778. return((int) sstate);
  7779. }
  7780. atcrei = atcreo = z; break;
  7781. case AT_ACCT:
  7782. if (rmsflg) {
  7783. sstate = setgen('S', "137", z ? "1" : "0", "");
  7784. return((int) sstate);
  7785. }
  7786. atacti = atacto = z; break;
  7787. #endif /* STRATUS */
  7788. case AT_SYSI:
  7789. if (rmsflg) {
  7790. sstate = setgen('S', "145", z ? "1" : "0", "");
  7791. return((int) sstate);
  7792. }
  7793. atsidi = atsido = z; break;
  7794. case AT_RECF:
  7795. if (rmsflg) {
  7796. sstate = setgen('S', "146", z ? "1" : "0", "");
  7797. return((int) sstate);
  7798. }
  7799. atfrmi = atfrmo = z; break;
  7800. case AT_SYSP:
  7801. if (rmsflg) {
  7802. sstate = setgen('S', "147", z ? "1" : "0", "");
  7803. return((int) sstate);
  7804. }
  7805. atsysi = atsyso = z; break;
  7806. default:
  7807. printf("?Not available\n");
  7808. return(-2);
  7809. }
  7810. return(1);
  7811. }
  7812. #endif /* NOXFER */
  7813. #ifndef NOSPL
  7814. int
  7815. setinp() {
  7816. if ((y = cmkey(inptab,ninp,"","",xxstring)) < 0) return(y);
  7817. switch (y) {
  7818. #ifdef OS2
  7819. case IN_PAC: /* SET INPUT PACING */
  7820. z = cmnum("milliseconds","0",10,&x,xxstring);
  7821. return(setnum(&tt_inpacing,x,z,1000));
  7822. case IN_TRM: /* SET INPUT TERMINAL */
  7823. return(seton(&interm));
  7824. #endif /* OS2 */
  7825. case IN_DEF: /* SET INPUT DEFAULT-TIMEOUT */
  7826. z = cmnum("Positive number","",10,&x,xxstring);
  7827. return(setnum(&indef,x,z,94));
  7828. #ifdef CKFLOAT
  7829. case IN_SCA: /* SET INPUT SCALE-FACTOR */
  7830. if ((x = cmfld("Number such as 2 or 0.5","1.0",&s, xxstring)) < 0)
  7831. return(x);
  7832. if (isfloat(s,0)) { /* A floating-point number? */
  7833. extern char * inpscale;
  7834. inscale = floatval; /* Yes, get its value */
  7835. makestr(&inpscale,s); /* Save it as \v(inscale) */
  7836. return(success = 1);
  7837. } else {
  7838. return(-2);
  7839. }
  7840. #endif /* CKFLOAT */
  7841. case IN_TIM: /* SET INPUT TIMEOUT-ACTION */
  7842. if ((z = cmkey(intimt,2,"","",xxstring)) < 0) return(z);
  7843. if ((x = cmcfm()) < 0) return(x);
  7844. intime[cmdlvl] = z;
  7845. return(success = 1);
  7846. case IN_CAS: /* SET INPUT CASE */
  7847. if ((z = cmkey(incast,2,"","",xxstring)) < 0) return(z);
  7848. if ((x = cmcfm()) < 0) return(x);
  7849. inpcas[cmdlvl] = z;
  7850. return(success = 1);
  7851. case IN_ECH: /* SET INPUT ECHO */
  7852. return(seton(&inecho));
  7853. case IN_SIL: /* SET INPUT SILENCE */
  7854. z = cmnum("Seconds of inactivity before INPUT fails","",10,&x,
  7855. xxstring);
  7856. return(setnum(&insilence,x,z,-1));
  7857. case IN_BUF: /* SET INPUT BUFFER-SIZE */
  7858. if ((z = cmnum("Number of bytes in INPUT buffer",
  7859. ckitoa(INPBUFSIZ),10,&x, xxstring)) < 0)
  7860. return(z);
  7861. if ((y = cmcfm()) < 0) return(y);
  7862. inbufsize = 0;
  7863. if (inpbuf) {
  7864. free(inpbuf);
  7865. inpbuf = NULL;
  7866. inpbp = NULL;
  7867. }
  7868. if (!(s = (char *)malloc(x + 1)))
  7869. return(0);
  7870. inpbuf = s;
  7871. inpbp = s;
  7872. inbufsize = x;
  7873. for (x = 0; x <= inbufsize; x++)
  7874. inpbuf[x] = NUL;
  7875. return(success = 1);
  7876. #ifdef CK_AUTODL
  7877. case IN_ADL: /* AUTODOWNLOAD */
  7878. return(seton(&inautodl));
  7879. #endif /* CK_AUTODL */
  7880. case IN_CAN: /* SET INPUT INTERRUPTS */
  7881. return(seton(&inintr));
  7882. }
  7883. return(0);
  7884. }
  7885. #endif /* NOSPL */
  7886. #ifdef NETCONN
  7887. VOID
  7888. ndreset() {
  7889. #ifndef NODIAL /* This depends on DIAL... */
  7890. int i=0, j=0;
  7891. if (!ndinited) /* Don't free garbage... */
  7892. return;
  7893. for (i = 0; i < nhcount; i++) { /* Clean out previous list */
  7894. if (nh_p[i])
  7895. free(nh_p[i]);
  7896. nh_p[i] = NULL;
  7897. if (nh_p2[i])
  7898. free(nh_p2[i]);
  7899. nh_p2[i] = NULL;
  7900. for (j = 0; j < 4; j++) {
  7901. if (nh_px[j][i])
  7902. free(nh_px[j][i]);
  7903. nh_px[j][i] = NULL;
  7904. }
  7905. }
  7906. #endif /* NODIAL */
  7907. }
  7908. VOID
  7909. ndinit() { /* Net directory pointers */
  7910. #ifndef NODIAL /* This depends on DIAL... */
  7911. int i, j;
  7912. if (ndinited++) /* Don't do this more than once. */
  7913. return;
  7914. for (i = 0; i < MAXDDIR; i++) { /* Init all pointers to NULL */
  7915. netdir[i] = NULL;
  7916. }
  7917. for (i = 0; i < MAXDNUMS; i++) {
  7918. nh_p[i] = NULL;
  7919. nh_p2[i] = NULL;
  7920. for (j = 0; j < 4; j++)
  7921. nh_px[j][i] = NULL;
  7922. }
  7923. #endif /* NODIAL */
  7924. }
  7925. #ifndef NODIAL
  7926. #ifdef NETCONN
  7927. VOID /* Get net defaults from environment */
  7928. getnetenv() {
  7929. char *p = NULL;
  7930. makestr(&p,getenv("K_NET_DIRECTORY")); /* Dialing directories */
  7931. if (p) {
  7932. int i;
  7933. xwords(p,MAXDDIR,netdir,0);
  7934. for (i = 0; i < MAXDDIR; i++) { /* Fill in any gaps... */
  7935. if (!netdir[i+1])
  7936. break;
  7937. else
  7938. netdir[i] = netdir[i+1];
  7939. debug(F111,"netdir[i]",netdir[i],i);
  7940. }
  7941. nnetdir = i;
  7942. }
  7943. }
  7944. #endif /* NETCONN */
  7945. #endif /* NODIAL */
  7946. int
  7947. #ifdef CK_ANSIC
  7948. lunet(char *s) /* s = name to look up */
  7949. #else
  7950. lunet(s) char *s;
  7951. #endif /* CK_ANSIC */
  7952. /* lunet */ {
  7953. #ifndef NODIAL /* This depends on DIAL... */
  7954. int n, n1, t, dd = 0;
  7955. int ambiguous = 0;
  7956. FILE * f;
  7957. char *line = NULL;
  7958. extern int dialdpy;
  7959. int netdpy = dialdpy;
  7960. char *info[8];
  7961. nhcount = 0; /* Set this before returning */
  7962. if (!s || nnetdir < 1) /* Validate arguments */
  7963. return(-1);
  7964. if (isdigit(*s) || *s == '*' || *s == '.')
  7965. return(0);
  7966. if ((n1 = (int) strlen(s)) < 1) /* Length of string to look up */
  7967. return(-1);
  7968. if (!(line = malloc(1024))) /* Allocate input buffer */
  7969. return(-1);
  7970. lu_again:
  7971. f = NULL; /* Network directory file descriptor */
  7972. t = nhcount = 0; /* Match count */
  7973. dd = 0; /* Directory counter */
  7974. dirline = 0;
  7975. while (1) { /* We make one pass */
  7976. if (!f) { /* Directory not open */
  7977. if (dd >= nnetdir) /* No directories left? */
  7978. break; /* Done. */
  7979. if ((f = fopen(netdir[dd],"r")) == NULL) { /* Open it */
  7980. perror(netdir[dd]); /* Can't, print message saying why */
  7981. dd++;
  7982. continue; /* But go on to next one. */
  7983. }
  7984. if (netdpy)
  7985. printf("Opening %s...\n",netdir[dd]);
  7986. dd++;
  7987. }
  7988. line[0] = NUL;
  7989. if (getnct(line,1023,f,1) < 0) { /* Read a line */
  7990. if (f) { /* f can be clobbered! */
  7991. fclose(f); /* Close the file */
  7992. f = NULL; /* Indicate next one needs opening */
  7993. }
  7994. continue;
  7995. }
  7996. if (!line[0]) /* Empty line */
  7997. continue;
  7998. xwords(line,7,info,0); /* Parse it */
  7999. if (!info[1] || !info[2] || !info[3]) /* Required fields */
  8000. continue;
  8001. if (*info[1] == ';') /* Full-line comment */
  8002. continue;
  8003. if ((n = (int) strlen(info[1])) < 1) /* Length of name-tag */
  8004. continue;
  8005. if (n < n1) /* Search name is longer */
  8006. continue; /* Can't possibly match */
  8007. if (ambiguous && n != n1)
  8008. continue;
  8009. if (ckstrcmp(s,info[1],n1,0)) /* Compare using length of */
  8010. continue; /* search string s. */
  8011. /* Have a match */
  8012. makestr(&(nh_p[nhcount]), info[3]); /* address */
  8013. makestr(&(nh_p2[nhcount]),info[2]); /* net type */
  8014. makestr(&(nh_px[0][nhcount]),info[4]); /* net-specific stuff... */
  8015. makestr(&(nh_px[1][nhcount]),info[5]);
  8016. makestr(&(nh_px[2][nhcount]),info[6]);
  8017. makestr(&(nh_px[3][nhcount]),info[7]);
  8018. nhcount++; /* Count this match */
  8019. if (nhcount > MAXDNUMS) { /* Watch out for too many */
  8020. printf("Warning: %d matches found, %d max\n",
  8021. nhcount,
  8022. MAXDNUMS
  8023. );
  8024. nhcount = MAXDNUMS;
  8025. break;
  8026. }
  8027. if (nhcount == 1) { /* First one - save entry name */
  8028. if (n_name) { /* Free the one from before if any */
  8029. free(n_name);
  8030. n_name = NULL;
  8031. }
  8032. if (!(n_name = (char *)malloc(n + 1))) { /* Allocate new storage */
  8033. printf("?memory allocation error - lunet:3\n");
  8034. if (line) {
  8035. free(line);
  8036. line = NULL;
  8037. }
  8038. nhcount = 0;
  8039. return(-1);
  8040. }
  8041. t = n; /* Remember its length */
  8042. strcpy(n_name,info[1]); /* safe */
  8043. } else { /* Second or subsequent one */
  8044. if ((int) strlen(info[1]) == t) /* Lengths compare */
  8045. if (!ckstrcmp(n_name,info[1],t,0)) /* Caseless compare OK */
  8046. continue;
  8047. /* Name given by user matches entries with different names */
  8048. if (ambiguous) /* Been here before */
  8049. break;
  8050. ambiguous = 1; /* Now an exact match is required */
  8051. ndreset(); /* Clear out previous list */
  8052. goto lu_again; /* Do it all over again. */
  8053. }
  8054. }
  8055. if (line) {
  8056. free(line);
  8057. line = NULL;
  8058. }
  8059. if (nhcount == 0 && ambiguous)
  8060. printf("?\"%s\" - ambiguous in network directory\n",s);
  8061. #else
  8062. nhcount = 0;
  8063. #endif /* NODIAL */
  8064. return(nhcount);
  8065. }
  8066. #endif /* NETCONN */
  8067. #ifndef NOLOCAL
  8068. /* C L S C O N N X -- Close connection */
  8069. int
  8070. clsconnx(ask) int ask; {
  8071. int x, rc = 0;
  8072. #ifdef NEWFTP
  8073. extern int ftpget, ftpisopen();
  8074. if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  8075. return(success = ftpbye());
  8076. #endif /* NEWFTP */
  8077. debug(F101,"clsconnx local","",local);
  8078. if (local) {
  8079. x = ask ? hupok(1) : 1; /* Make sure it's OK to close */
  8080. if (!x) {
  8081. rc = -1;
  8082. debug(F101,"clsconnx hupok says no","",rc);
  8083. return(rc);
  8084. }
  8085. ttflui(); /* Clear away buffered up junk */
  8086. #ifndef NODIAL
  8087. #ifdef OS2ONLY
  8088. /* Don't hangup a line that is shared with the SLIP or PPP driver */
  8089. if (!ttslip && !ttppp)
  8090. #endif /* OS2ONLY */
  8091. mdmhup();
  8092. #endif /* NODIAL */
  8093. if (network && msgflg)
  8094. printf(" Closing connection\n");
  8095. ttclos(0); /* Close old connection, if any */
  8096. rc = 1;
  8097. {
  8098. extern int wasclosed, whyclosed;
  8099. if (wasclosed) {
  8100. whyclosed = WC_CLOS;
  8101. #ifndef NOSPL
  8102. if (nmac) { /* Any macros defined? */
  8103. int k; /* Yes */
  8104. /* printf("ON_CLOSE CLSCONNX\n"); */
  8105. wasclosed = 0;
  8106. k = mlook(mactab,"on_close",nmac); /* Look this up */
  8107. if (k >= 0) { /* If found, */
  8108. if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  8109. parser(1); /* and execute it */
  8110. }
  8111. }
  8112. #endif /* NOSPL */
  8113. whyclosed = WC_REMO;
  8114. wasclosed = 0;
  8115. }
  8116. }
  8117. }
  8118. #ifdef VMS /* Or maybe #ifndef UNIX? */
  8119. else { /* Need to do this in VMS to */
  8120. ttclos(0); /* free the tty channel number */
  8121. rc = 1; /* obtained in ttopen() or else */
  8122. } /* subsequent ttopen's won't work */
  8123. #endif /* VMS */
  8124. dologend();
  8125. haveline = 0;
  8126. if (mdmtyp < 0) { /* Switching from net to async? */
  8127. if (mdmsav > -1) /* Restore modem type from last */
  8128. mdmtyp = mdmsav; /* SET MODEM command, if any. */
  8129. else
  8130. mdmtyp = 0;
  8131. mdmsav = -1;
  8132. }
  8133. if (network)
  8134. network = 0;
  8135. #ifdef NETCONN
  8136. if (oldplex > -1) { /* Restore previous duplex setting. */
  8137. duplex = oldplex;
  8138. oldplex = -1;
  8139. }
  8140. #endif /* NETCONN */
  8141. #ifndef MAC
  8142. ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default communication */
  8143. #endif /* MAC */
  8144. local = dfloc; /* device and local/remote status */
  8145. if (local) {
  8146. cxtype = CXT_DIRECT; /* Something reasonable */
  8147. speed = ttgspd(); /* Get the current speed */
  8148. } else {
  8149. cxtype = CXT_REMOTE;
  8150. speed = -1L;
  8151. }
  8152. #ifndef NOXFER
  8153. if (xreliable > -1 && !setreliable) {
  8154. reliable = xreliable;
  8155. debug(F101,"clsconnx reliable A","",reliable);
  8156. } else if (!setreliable) {
  8157. reliable = SET_AUTO;
  8158. debug(F101,"clsconnx reliable B","",reliable);
  8159. }
  8160. #endif /* NOXFER */
  8161. setflow(); /* Revert flow control */
  8162. return(rc);
  8163. }
  8164. int
  8165. clskconnx(x) int x; { /* Close Kermit connection only */
  8166. int t, rc; /* (not FTP) */
  8167. #ifdef NEWFTP
  8168. extern int ftpget;
  8169. t = ftpget;
  8170. ftpget = 0;
  8171. #endif /* NEWFTP */
  8172. rc = clsconnx(x);
  8173. #ifdef NEWFTP
  8174. ftpget = t;
  8175. #endif /* NEWFTP */
  8176. return(rc);
  8177. }
  8178. /* May 2002: setlin() decomposition starts here ... */
  8179. #ifdef OS2
  8180. #define SRVBUFSIZ PIPENAML
  8181. #else /* OS2 */
  8182. #define SRVBUFSIZ 63
  8183. #endif /* OS2 */
  8184. #define HOSTNAMLEN 15*65
  8185. int netsave = -1;
  8186. static char * tmpstring = NULL;
  8187. static char * tmpusrid = NULL;
  8188. #ifdef SSHCMD
  8189. char * sshcmd = NULL;
  8190. char * defsshcmd = "ssh -e none";
  8191. #else
  8192. #ifdef SSHBUILTIN
  8193. char * sshrcmd = NULL;
  8194. char * sshtmpcmd = NULL;
  8195. #endif /* SSHBUILTIN */
  8196. #endif /* SSHCMD */
  8197. /* c x _ f a i l -- Common error exit routine for cx_net, cx_line */
  8198. int
  8199. cx_fail(msg, text) int msg; char * text; {
  8200. makestr(&slmsg,text); /* For the record (or GUI) */
  8201. if (msg) /* Not GUI, not quiet, etc */
  8202. printf("?%s\n",text); /* Print error message */
  8203. slrestor(); /* Restore LINE/HOST to known state */
  8204. return(msg ? -9 : (success = 0)); /* Return appropriate code */
  8205. }
  8206. #ifdef NETCONN
  8207. /* c x _ n e t -- Make a network connection */
  8208. /*
  8209. Call with:
  8210. net = network type
  8211. protocol = protocol type
  8212. host = string pointer to host name.
  8213. svc = string pointer to service or port on host.
  8214. username = username for connection
  8215. password = password for connection
  8216. command = command to execute
  8217. param1 = Telnet: Authentication type
  8218. SSH: Version
  8219. param2 = Telnet: Encryption type
  8220. SSH: Command as Subsystem
  8221. param3 = Telnet: 1 to wait for negotiations, 0 otherwise
  8222. SSH: X11 Forwarding
  8223. cx = 1 to automatically enter Connect mode, 0 otherwise.
  8224. sx = 1 to automatically enter Server mode, 0 otherwise.
  8225. flag = if no host name given, 1 = close current connection, 0 = resume
  8226. gui = 1 if called from GUI dialog, 0 otherwise.
  8227. Returns:
  8228. 1 on success
  8229. 0 on failure and no message printed, slmsg set to failure message.
  8230. -9 on failure and message printed, ditto.
  8231. */
  8232. int
  8233. #ifdef CK_ANSIC
  8234. cx_net( int net, int protocol, char * xhost, char * svc,
  8235. char * username, char * password, char * command,
  8236. int param1, int param2, int param3, int cx, int sx, int flag, int gui)
  8237. #else /* CK_ANSIC */
  8238. cx_net(net, protocol, xhost, svc,
  8239. username, password, command,
  8240. param1, param2, param3, cx, sx, flag, gui)
  8241. char * xhost, * svc, * username, *password, *command;
  8242. int net, protocol, cx, sx, flag, param1, param2, param3, gui;
  8243. #endif /* CK_ANSIC */
  8244. /* cx_net */ {
  8245. int i, n, x, msg;
  8246. int _local = -1;
  8247. extern char pwbuf[], * g_pswd;
  8248. extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  8249. char srvbuf[SRVBUFSIZ+1]; /* Service */
  8250. char hostbuf[HOSTNAMLEN]; /* Host buffer to manipulate */
  8251. char hostname[HOSTNAMLEN]; /* Copy of host parameter */
  8252. char * host = hostbuf; /* Pointer to copy of host param */
  8253. if (!xhost) xhost = ""; /* Watch out for null pointers */
  8254. if (!svc) svc = "";
  8255. ckstrncpy(host,xhost,HOSTNAMLEN); /* Avoid buffer confusion */
  8256. debug(F110,"cx_net host",host,0);
  8257. debug(F111,"cx_net service",svc,SRVBUFSIZ);
  8258. debug(F101,"cx_net network type","",net);
  8259. msg = (gui == 0) && msgflg; /* Whether to print messages */
  8260. #ifndef NODIAL
  8261. debug(F101,"cx_net nnetdir","",nnetdir);
  8262. x = 0; /* Look up in network directory */
  8263. if (*host == '=') { /* If number starts with = sign */
  8264. host++; /* strip it */
  8265. while (*host == SP) host++; /* and any leading spaces */
  8266. debug(F110,"cx_net host 2",host,0);
  8267. nhcount = 0;
  8268. } else if (*host) { /* We want to look it up. */
  8269. if (nnetdir > 0) /* If there is a directory... */
  8270. x = lunet(host); /* (sets nhcount) */
  8271. else /* otherwise */
  8272. nhcount = 0; /* we didn't find any there */
  8273. if (x < 0) /* Internal error? */
  8274. return(cx_fail(msg,"Network directory lookup error"));
  8275. debug(F111,"cx_net lunet nhcount",host,nhcount);
  8276. }
  8277. #endif /* NODIAL */
  8278. /* New connection wanted. Make a copy of the host name/address... */
  8279. if (clskconnx(1) < 0) /* Close current Kermit connection */
  8280. return(cx_fail(msg,"Error closing previous connection"));
  8281. if (*host) { /* They gave a hostname */
  8282. _local = 1; /* Network connection always local */
  8283. if (mdmsav < 0)
  8284. mdmsav = mdmtyp; /* Remember old modem type */
  8285. mdmtyp = -net; /* Special code for network */
  8286. } else { /* They just said "set host" */
  8287. host = dftty; /* So go back to normal */
  8288. _local = dfloc; /* default tty, location, */
  8289. if (flag) { /* Close current connection */
  8290. setflow(); /* Maybe change flow control */
  8291. haveline = 1; /* (* is this right? *) */
  8292. dologend();
  8293. #ifndef NODIAL
  8294. dialsta = DIA_UNK;
  8295. #endif /* NODIAL */
  8296. #ifdef LOCUS
  8297. if (autolocus) {
  8298. setlocus(1,1);
  8299. }
  8300. #endif /* LOCUS */
  8301. /* XXX - Is this right? */
  8302. /* Should we be returning without doing anything ? */
  8303. /* Yes it's right -- we closed the old connection just above. */
  8304. return(success = 1);
  8305. }
  8306. }
  8307. success = 0;
  8308. if (host != line) /* line[] is a global */
  8309. ckstrncpy(line,host,LINBUFSIZ);
  8310. ckstrncpy(hostname,host,HOSTNAMLEN);
  8311. ckstrncpy(srvbuf,svc,SRVBUFSIZ+1);
  8312. #ifndef NODIAL
  8313. if ((nhcount > 1) && msg) {
  8314. int k;
  8315. printf("%d entr%s found for \"%s\"%s\n",
  8316. nhcount,
  8317. (nhcount == 1) ? "y" : "ies",
  8318. s,
  8319. (nhcount > 0) ? ":" : "."
  8320. );
  8321. for (i = 0; i < nhcount; i++) {
  8322. printf("%3d. %-12s => %-9s %s",
  8323. i+1,n_name,nh_p2[i],nh_p[i]);
  8324. for (k = 0; k < 4; k++) { /* Also list net-specific items */
  8325. if (nh_px[k][i]) /* free format... */
  8326. printf(" %s",nh_px[k][i]);
  8327. else
  8328. break;
  8329. }
  8330. printf("\n");
  8331. }
  8332. }
  8333. if (nhcount == 0)
  8334. n = 1;
  8335. else
  8336. n = nhcount;
  8337. #else
  8338. n = 1;
  8339. nhcount = 0;
  8340. #endif /* NODIAL */
  8341. for (i = 0; i < n; i++) { /* Loop for each entry found */
  8342. debug(F101,"cx_net loop i","",i);
  8343. #ifndef NODIAL
  8344. if (nhcount > 0) { /* If we found at least one entry... */
  8345. ckstrncpy(line,nh_p[i],LINBUFSIZ); /* Copy current entry */
  8346. if (lookup(netcmd,nh_p2[i],nnets,&x) > -1) { /* Net type */
  8347. int xx;
  8348. xx = netcmd[x].kwval;
  8349. /* User specified SSH so don't let net directory override */
  8350. if (net != NET_SSH || xx != NET_TCPB) {
  8351. net = xx;
  8352. mdmtyp = 0 - net;
  8353. }
  8354. } else {
  8355. makestr(&slmsg,"Network type not supported");
  8356. if (msg)
  8357. printf("Error - network type \"%s\" not supported\n",
  8358. nh_p2[i]
  8359. );
  8360. continue;
  8361. }
  8362. switch (net) { /* Net-specific directory things */
  8363. #ifdef SSHBUILTIN
  8364. case NET_SSH: /* SSH */
  8365. /* Any SSH specific network directory stuff? */
  8366. break; /* NET_SSH */
  8367. #endif /* SSHBUILTIN */
  8368. case NET_TCPB: { /* TCP/IP TELNET,RLOGIN,... */
  8369. #ifdef TCPSOCKET
  8370. char *q;
  8371. int flag = 0;
  8372. /* Extract ":service", if any, from host string */
  8373. debug(F110,"cx_net service 1",line,0);
  8374. for (q = line; (*q != '\0') && (*q != ':'); q++)
  8375. ;
  8376. if (*q == ':') { *q++ = NUL; flag = 1; }
  8377. debug(F111,"cx_net service 2",line,flag);
  8378. /* Get service, if any, from directory entry */
  8379. if (!*srvbuf) {
  8380. if (nh_px[0][i]) {
  8381. ckstrncpy(srvbuf,nh_px[0][i],SRVBUFSIZ);
  8382. debug(F110,"cx_net service 3",srvbuf,0);
  8383. }
  8384. if (flag) {
  8385. ckstrncpy(srvbuf,q,SRVBUFSIZ);
  8386. debug(F110,"cx_net service 4",srvbuf,0);
  8387. }
  8388. }
  8389. ckstrncpy(hostname,line,HOSTNAMLEN);
  8390. /* If we have a service, append to host name/address */
  8391. if (*srvbuf) {
  8392. ckstrncat(line, ":", LINBUFSIZ);
  8393. ckstrncat(line, srvbuf, LINBUFSIZ);
  8394. debug(F110,"cx_net service 5",line,0);
  8395. }
  8396. #ifdef RLOGCODE
  8397. /* If no service given but command was RLOGIN */
  8398. else if (ttnproto == NP_RLOGIN) { /* add this... */
  8399. ckstrncat(line, ":login",LINBUFSIZ);
  8400. debug(F110,"cx_net service 6",line,0);
  8401. }
  8402. #ifdef CK_AUTHENTICATION
  8403. #ifdef CK_KERBEROS
  8404. else if (ttnproto == NP_K4LOGIN ||
  8405. ttnproto == NP_K5LOGIN) { /* add this... */
  8406. ckstrncat(line, ":klogin",LINBUFSIZ);
  8407. debug(F110,"cx_net service 7",line,0);
  8408. }
  8409. else if (ttnproto == NP_EK4LOGIN ||
  8410. ttnproto == NP_EK5LOGIN) { /* add this... */
  8411. ckstrncat(line, ":eklogin",LINBUFSIZ);
  8412. debug(F110,"cx_net service 8",line,0);
  8413. }
  8414. #endif /* CK_KERBEROS */
  8415. #endif /* CK_AUTHENTICATION */
  8416. #endif /* RLOGCODE */
  8417. else { /* Otherwise, add ":telnet". */
  8418. ckstrncat(line, ":telnet", LINBUFSIZ);
  8419. debug(F110,"cx_net service 9",line,0);
  8420. }
  8421. if (username) { /* This is a parameter... */
  8422. ckstrncpy(uidbuf,username,UIDBUFLEN);
  8423. uidflag = 1;
  8424. }
  8425. /* Fifth field, if any, is user ID (for rlogin) */
  8426. if (nh_px[1][i] && !uidflag)
  8427. ckstrncpy(uidbuf,username,UIDBUFLEN);
  8428. #ifdef RLOGCODE
  8429. if (IS_RLOGIN() && !uidbuf[0])
  8430. return(cx_fail(msg,"Username required"));
  8431. #endif /* RLOGCODE */
  8432. #endif /* TCPSOCKET */
  8433. break;
  8434. }
  8435. case NET_PIPE: /* Pipe */
  8436. #ifdef NPIPE
  8437. if (!pipename[0]) { /* User didn't give a pipename */
  8438. if (nh_px[0][i]) { /* But directory entry has one */
  8439. if (strcmp(pipename,"\\pipe\\")) {
  8440. ckstrncpy(pipename,"\\pipe\\",LINBUFSIZ);
  8441. ckstrncat(srvbuf,nh_px[0][i],PIPENAML-6);
  8442. } else {
  8443. ckstrncpy(pipename,nh_px[0][i],PIPENAML);
  8444. }
  8445. debug(F110,"cx_net pipeneme",pipename,0);
  8446. }
  8447. }
  8448. #endif /* NPIPE */
  8449. break;
  8450. case NET_SLAT: /* LAT / CTERM */
  8451. #ifdef SUPERLAT
  8452. if (!slat_pwd[0]) { /* User didn't give a password */
  8453. if (nh_px[0][i]) { /* But directory entry has one */
  8454. ckstrncpy(slat_pwd,nh_px[0][i],18);
  8455. debug(F110,"cx_net SuperLAT password",slat_pwd,0);
  8456. }
  8457. }
  8458. #endif /* SUPERLAT */
  8459. break;
  8460. case NET_SX25: /* X.25 keyword parameters */
  8461. case NET_IX25:
  8462. case NET_VX25: {
  8463. #ifdef ANYX25
  8464. int k; /* Cycle through the four fields */
  8465. for (k = 0; k < 4; k++) {
  8466. if (!nh_px[k][i]) /* Bail out if none left */
  8467. break;
  8468. if (!ckstrcmp(nh_px[k][i],"cug=",4,0)) {
  8469. closgr = atoi(nh_px[k][i]+4);
  8470. debug(F101,"X25 CUG","",closgr);
  8471. } else if (!ckstrcmp(nh_px[k][i],"cud=",4,0)) {
  8472. cudata = 1;
  8473. ckstrncpy(udata,nh_px[k][i]+4,MAXCUDATA);
  8474. debug(F110,"X25 CUD",cudata,0);
  8475. } else if (!ckstrcmp(nh_px[k][i],"rev=",4,0)) {
  8476. revcall = !ckstrcmp(nh_px[k][i]+4,"=on",3,0);
  8477. debug(F101,"X25 REV","",revcall);
  8478. #ifndef IBMX25
  8479. } else if (!ckstrcmp(nh_px[k][i],"pad=",4,0)) {
  8480. int x3par, x3val;
  8481. char *s1, *s2;
  8482. s1 = s2 = nh_px[k][i]+4; /* PAD parameters */
  8483. while (*s2) { /* Pick them apart */
  8484. if (*s2 == ':') {
  8485. *s2 = NUL;
  8486. x3par = atoi(s1);
  8487. s1 = ++s2;
  8488. continue;
  8489. } else if (*s2 == ',') {
  8490. *s2 = NUL;
  8491. x3val = atoi(s1);
  8492. s1 = ++s2;
  8493. debug(F111,"X25 PAD",x3par,x3val);
  8494. if (x3par > -1 &&
  8495. x3par <= MAXPADPARMS)
  8496. padparms[x3par] = x3val;
  8497. continue;
  8498. } else
  8499. s2++;
  8500. }
  8501. #endif /* IBMX25 */
  8502. }
  8503. }
  8504. #endif /* ANYX25 */
  8505. break;
  8506. }
  8507. default: /* Nothing special for other nets */
  8508. break;
  8509. }
  8510. } else
  8511. #endif /* NODIAL */
  8512. { /* No directory entries found. */
  8513. ckstrncpy(line,hostname,LINBUFSIZ); /* Put this back... */
  8514. /* If the user gave a TCP service */
  8515. if (net == NET_TCPB || net == NET_SSH)
  8516. if (*srvbuf) { /* Append it to host name/address */
  8517. ckstrncat(line, ":", LINBUFSIZ);
  8518. ckstrncat(line, srvbuf,LINBUFSIZ);
  8519. }
  8520. }
  8521. /*
  8522. Get here with host name/address and all net-specific
  8523. parameters set, ready to open the connection.
  8524. */
  8525. mdmtyp = -net; /* This should have been done */
  8526. /* already but just in case ... */
  8527. debug(F110,"cx_net net line[] before ttopen",line,0);
  8528. debug(F101,"cx_net net mdmtyp before ttopen","",mdmtyp);
  8529. debug(F101,"cx_net net ttnproto","",ttnproto);
  8530. #ifdef SSHBUILTIN
  8531. if (net == NET_SSH) {
  8532. makestr(&ssh_hst,hostname); /* Stash everything */
  8533. if (username) {
  8534. if (!sl_uid_saved) {
  8535. ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  8536. sl_uid_saved = 1;
  8537. }
  8538. ckstrncpy(uidbuf,username,UIDBUFLEN);
  8539. }
  8540. if (srvbuf[0]) {
  8541. makestr(&ssh_prt,srvbuf);
  8542. } else
  8543. makestr(&ssh_prt,NULL);
  8544. if (command) {
  8545. makestr(&ssh_cmd,brstrip(command));
  8546. ssh_cas = param2;
  8547. } else
  8548. makestr(&ssh_cmd,NULL);
  8549. if (param1 > -1) {
  8550. #ifndef SSHTEST
  8551. if (!sl_ssh_ver_saved) {
  8552. sl_ssh_ver = ssh_ver;
  8553. sl_ssh_ver_saved = 1;
  8554. }
  8555. #endif /* SSHTEST */
  8556. ssh_ver = param1;
  8557. }
  8558. if (param3 > -1) {
  8559. #ifndef SSHTEST
  8560. if (!sl_ssh_xfw_saved) {
  8561. sl_ssh_xfw = ssh_xfw;
  8562. sl_ssh_xfw_saved = 1;
  8563. }
  8564. #endif /* SSHTEST */
  8565. ssh_xfw = param3;
  8566. }
  8567. } else /* NET_SSH */
  8568. #endif /* SSHBUILTIN */
  8569. #ifdef TCPSOCKET
  8570. if (net == NET_TCPB) {
  8571. switch (protocol) {
  8572. #ifdef CK_SSL
  8573. #ifdef COMMENT
  8574. /*
  8575. Jeff's version from 30 Dec 2006 - doesn't work - SSL/TLS_RAW still
  8576. start Telnet negotions if a 0xff byte comes in.
  8577. */
  8578. case NP_SSL_RAW:
  8579. ttnproto = NP_SSL_RAW;
  8580. debug(F101,"NP_SSL_RAW ttnproto","",ttnproto);
  8581. ssl_only_flag = 1;
  8582. tls_only_flag = 0;
  8583. break;
  8584. case NP_TLS_RAW:
  8585. ttnproto = NP_TLS_RAW;
  8586. debug(F101,"NP_TLS_RAW ttnproto","",ttnproto);
  8587. ssl_only_flag = 0;
  8588. tls_only_flag = 1;
  8589. break;
  8590. case NP_SSL:
  8591. ttnproto = NP_SSL;
  8592. debug(F101,"NP_SSL ttnproto","",ttnproto);
  8593. ssl_only_flag = 1;
  8594. tls_only_flag = 0;
  8595. break;
  8596. case NP_TLS:
  8597. ttnproto = NP_TLS;
  8598. debug(F101,"NP_TLS ttnproto","",ttnproto);
  8599. ssl_only_flag = 0;
  8600. tls_only_flag = 1;
  8601. break;
  8602. case NP_SSL_TELNET:
  8603. ttnproto = NP_TELNET;
  8604. debug(F101,"NP_SSL_TELNET ttnproto","",ttnproto);
  8605. ssl_only_flag = 1;
  8606. tls_only_flag = 0;
  8607. break;
  8608. case NP_TLS_TELNET:
  8609. ttnproto = NP_TELNET;
  8610. debug(F101,"NP_TLS_TELNET ttnproto","",ttnproto);
  8611. ssl_only_flag = 0;
  8612. tls_only_flag = 1;
  8613. break;
  8614. #else
  8615. /* fdc version of 4 Dec 2006 works OK */
  8616. case NP_SSL_RAW:
  8617. case NP_SSL:
  8618. ssl_raw_flag = (protocol == NP_SSL_RAW) ? 1 : 0;
  8619. ttnproto = protocol;
  8620. debug(F101,protocol==NP_SSL ?
  8621. "NP_SSL ttnproto" :
  8622. "NP_SSL_RAW ttnproto",
  8623. "",ttnproto);
  8624. ssl_only_flag = 1;
  8625. tls_only_flag = 0;
  8626. break;
  8627. case NP_TLS:
  8628. case NP_TLS_RAW:
  8629. tls_raw_flag = (protocol == NP_SSL_RAW) ? 1 : 0;
  8630. ttnproto = protocol;
  8631. debug(F101,protocol==NP_TLS ?
  8632. "NP_TLS ttnproto" :
  8633. "NP_TLS_RAW ttnproto",
  8634. "",ttnproto);
  8635. ssl_only_flag = 0;
  8636. tls_only_flag = 1;
  8637. break;
  8638. case NP_SSL_TELNET:
  8639. ssl_raw_flag = 0;
  8640. ttnproto = NP_TELNET;
  8641. debug(F101,"NP_SSL_TELNET ttnproto","",ttnproto);
  8642. ssl_only_flag = 1;
  8643. tls_only_flag = 0;
  8644. break;
  8645. case NP_TLS_TELNET:
  8646. tls_raw_flag = 0;
  8647. ttnproto = NP_TELNET;
  8648. debug(F101,"NP_TLS_TELNET ttnproto","",ttnproto);
  8649. ssl_only_flag = 0;
  8650. tls_only_flag = 1;
  8651. break;
  8652. #endif /* COMMENT */
  8653. #endif /* CK_SSL */
  8654. case NP_NONE:
  8655. case NP_TCPRAW:
  8656. case NP_RLOGIN:
  8657. case NP_K4LOGIN:
  8658. case NP_K5LOGIN:
  8659. case NP_EK4LOGIN:
  8660. case NP_EK5LOGIN:
  8661. case NP_TELNET:
  8662. case NP_KERMIT:
  8663. default:
  8664. ttnproto = protocol;
  8665. #ifdef CK_SSL
  8666. #ifdef COMMENT
  8667. /* Jeff version from 30 Dec 2006 */
  8668. ssl_only_flag = 0;
  8669. tls_only_flag = 0;
  8670. #else
  8671. /* fdc version from 4 Dec 2006 */
  8672. ssl_raw_flag = 0;
  8673. tls_raw_flag = 0;
  8674. ssl_only_flag = 0;
  8675. tls_only_flag = 0;
  8676. #endif /* COMMENT */
  8677. #endif /* CK_SSL */
  8678. break;
  8679. }
  8680. #ifdef CK_AUTHENTICATION
  8681. if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  8682. param1 > -1) {
  8683. if (!sl_auth_saved) {
  8684. int x;
  8685. for (x = 0; x < AUTHTYPLSTSZ; x++)
  8686. sl_auth_type_user[x] = auth_type_user[x];
  8687. sl_auth_saved = 1;
  8688. }
  8689. if (!sl_topt_a_s_saved) {
  8690. sl_topt_a_su = TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION);
  8691. sl_topt_a_s_saved = 1;
  8692. }
  8693. if (!sl_topt_a_c_saved) {
  8694. sl_topt_a_cm = TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION);
  8695. sl_topt_a_c_saved = 1;
  8696. }
  8697. switch (param1) {
  8698. case AUTHTYPE_AUTO:
  8699. auth_type_user[0] = AUTHTYPE_AUTO;
  8700. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  8701. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  8702. break;
  8703. case AUTHTYPE_NULL:
  8704. auth_type_user[0] = AUTHTYPE_NULL;
  8705. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  8706. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  8707. break;
  8708. #ifdef CK_SRP
  8709. case AUTHTYPE_SRP:
  8710. auth_type_user[0] = AUTHTYPE_SRP;
  8711. auth_type_user[1] = AUTHTYPE_NULL;
  8712. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8713. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8714. break;
  8715. #endif /* CK_SRP */
  8716. #ifdef CK_SSL
  8717. case AUTHTYPE_SSL:
  8718. auth_type_user[0] = AUTHTYPE_SSL;
  8719. auth_type_user[1] = AUTHTYPE_NULL;
  8720. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8721. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8722. break;
  8723. #endif /* CK_SSL */
  8724. #ifdef NT
  8725. case AUTHTYPE_NTLM:
  8726. auth_type_user[0] = AUTHTYPE_NTLM;
  8727. auth_type_user[1] = AUTHTYPE_NULL;
  8728. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8729. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8730. break;
  8731. #endif /* NT */
  8732. #ifdef CK_KERBEROS
  8733. case AUTHTYPE_KERBEROS_V4:
  8734. auth_type_user[0] = AUTHTYPE_KERBEROS_V4;
  8735. auth_type_user[1] = AUTHTYPE_NULL;
  8736. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8737. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8738. break;
  8739. case AUTHTYPE_KERBEROS_V5:
  8740. auth_type_user[0] = AUTHTYPE_KERBEROS_V5;
  8741. auth_type_user[1] = AUTHTYPE_NULL;
  8742. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8743. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  8744. break;
  8745. #endif /* CK_KERBEROS */
  8746. }
  8747. }
  8748. /*
  8749. If the user requires a particular type of Kerberos connection,
  8750. make sure we have a valid TGT.
  8751. */
  8752. makestr(&slmsg,"Authentication failure");
  8753. if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  8754. (line[0] == '*' &&
  8755. TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU ||
  8756. line[0] != '*' &&
  8757. TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU)
  8758. ) {
  8759. #ifdef CK_KERBEROS
  8760. if ( auth_type_user[0] == AUTHTYPE_KERBEROS_V4 ) {
  8761. extern int krb4_autoget;
  8762. if (!ck_krb4_is_installed())
  8763. return(cx_fail(msg,
  8764. "Required authentication method (Kerberos 4) is not installed"));
  8765. #ifdef COMMENT
  8766. /* This code results in false failures when using */
  8767. /* kerberos to machines in realms other than the */
  8768. /* default since we don't know the realm of the */
  8769. /* other machine until perform the reverse DNS */
  8770. /* lookup. */
  8771. else if (line[0] != '*' && !ck_krb4_is_tgt_valid() &&
  8772. (!krb4_autoget ||
  8773. krb4_autoget && !ck_krb4_autoget_TGT(NULL))) {
  8774. return(cx_fail(msg,
  8775. "Kerberos 4: Ticket Getting Ticket not valid"));
  8776. }
  8777. #endif /* COMMENT */
  8778. } else if (auth_type_user[0] == AUTHTYPE_KERBEROS_V5) {
  8779. extern int krb5_autoget;
  8780. if (!ck_krb5_is_installed()) {
  8781. return(cx_fail(msg,
  8782. "Required authentication method (Kerberos 5) is not installed"));
  8783. }
  8784. #ifdef COMMENT
  8785. /* This code results in false failures when using */
  8786. /* kerberos to machines in realms other than the */
  8787. /* default since we don't know the realm of the */
  8788. /* other machine until perform the reverse DNS */
  8789. /* lookup. */
  8790. else if (line[0] != '*' && !ck_krb5_is_tgt_valid() &&
  8791. (!krb5_autoget ||
  8792. krb5_autoget && !ck_krb5_autoget_TGT(NULL))) {
  8793. return(cx_fail(msg,
  8794. "Kerberos 5: Ticket Getting Ticket not valid."));
  8795. }
  8796. #endif /* COMMENT */
  8797. }
  8798. #endif /* CK_KERBEROS */
  8799. #ifdef NT
  8800. if (auth_type_user[0] == AUTHTYPE_NTLM) {
  8801. if (!ck_ntlm_is_installed()) {
  8802. return(cx_fail(msg,
  8803. "Required authentication method (NTLM) is not installed"));
  8804. } else if (line[0] != '*' && !ck_ntlm_is_valid(0)) {
  8805. return(cx_fail(msg,"NTLM: Credentials are unavailable."));
  8806. }
  8807. }
  8808. #endif /* NT */
  8809. #ifdef CK_SSL
  8810. if (auth_type_user[0] == AUTHTYPE_SSL) {
  8811. if (!ck_ssleay_is_installed()) {
  8812. return(cx_fail(msg,
  8813. "Required authentication method (SSL) is not installed"));
  8814. }
  8815. }
  8816. #endif /* CK_SSL */
  8817. #ifdef CK_SRP
  8818. if (auth_type_user[0] == AUTHTYPE_SRP) {
  8819. if (!ck_srp_is_installed()) {
  8820. return(cx_fail(msg,
  8821. "Required authentication method (SRP) is not installed"));
  8822. }
  8823. }
  8824. #endif /* CK_SRP */
  8825. }
  8826. #endif /* CK_AUTHENTICATION */
  8827. #ifdef CK_ENCRYPTION
  8828. if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  8829. param2 > -1) {
  8830. if (!sl_cx_saved) {
  8831. sl_cx_type = cx_type;
  8832. sl_cx_saved = 1;
  8833. }
  8834. if (!sl_topt_e_s_saved) {
  8835. sl_topt_e_su = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
  8836. sl_topt_e_sm = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
  8837. sl_topt_e_s_saved = 1;
  8838. }
  8839. if (!sl_topt_e_c_saved) {
  8840. sl_topt_e_cu = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
  8841. sl_topt_e_cm = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
  8842. sl_topt_e_c_saved = 1;
  8843. }
  8844. cx_type = param2;
  8845. if (cx_type == CX_AUTO) {
  8846. TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  8847. TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  8848. TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  8849. TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  8850. } else if (cx_type == CX_NONE) {
  8851. TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  8852. TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  8853. TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  8854. TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  8855. } else {
  8856. TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  8857. TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  8858. TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  8859. TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  8860. }
  8861. }
  8862. if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN ||
  8863. (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  8864. ((line[0] == '*' &&
  8865. TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  8866. TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU) ||
  8867. (line[0] != '*' &&
  8868. TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  8869. TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU))
  8870. ) {
  8871. if (!ck_crypt_is_installed()) {
  8872. return(cx_fail(msg,
  8873. "Required Encryption methods are not installed"));
  8874. }
  8875. }
  8876. #endif /* CK_ENCRYPTION */
  8877. #ifdef RLOGCODE
  8878. #ifdef CK_KERBEROS
  8879. #ifdef KRB4
  8880. if (ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN) {
  8881. extern int krb4_autoget;
  8882. char tgt[256];
  8883. char * realm;
  8884. /* We don't have the full hostname at yet so */
  8885. /* we do a DNS lookup before calling ttopen() */
  8886. realm = ck_krb4_realmofhost(ckgetfqhostname(hostname));
  8887. ckmakmsg(tgt,256,"krbtgt.",realm,"@",realm);
  8888. if (!ck_krb4_is_installed()) {
  8889. return(cx_fail(msg,
  8890. "Required authentication method (Kerberos 4) is not installed"
  8891. ));
  8892. } else {
  8893. if ((ck_krb4_tkt_isvalid(tgt) <= 0) &&
  8894. (!krb4_autoget ||
  8895. krb4_autoget && !ck_krb4_autoget_TGT(realm))) {
  8896. return(cx_fail(msg,
  8897. "Kerberos 4: Ticket Getting Ticket not valid"));
  8898. }
  8899. }
  8900. }
  8901. #endif /* KRB4 */
  8902. #ifdef KRB5
  8903. if (ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN ||
  8904. ttnproto == NP_K5U2U)
  8905. {
  8906. extern int krb5_autoget;
  8907. char tgt[256];
  8908. char * realm;
  8909. /* Must get full hostname before calling ttopen() */
  8910. realm = ck_krb5_realmofhost(ckgetfqhostname(hostname));
  8911. ckmakmsg(tgt,256,"krbtgt/",realm,"@",realm);
  8912. if (!ck_krb5_is_installed()) {
  8913. return(cx_fail(msg,
  8914. "Required authentication method (Kerberos 5) not installed"));
  8915. } else if (!((ck_krb5_tkt_isvalid(NULL,tgt) > 0) ||
  8916. ck_krb5_is_tgt_valid()) &&
  8917. (!krb5_autoget ||
  8918. krb5_autoget && !ck_krb5_autoget_TGT(realm))) {
  8919. return(cx_fail(msg,
  8920. "Kerberos 5: Ticket Getting Ticket not valid."));
  8921. }
  8922. }
  8923. #endif /* KRB5 */
  8924. #endif /* CK_KERBEROS */
  8925. #endif /* RLOGCODE */
  8926. #ifndef NOSPL
  8927. #ifdef RLOGCODE
  8928. if (username) {
  8929. if (!sl_uid_saved) {
  8930. ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  8931. sl_uid_saved = 1;
  8932. }
  8933. ckstrncpy(uidbuf,username,UIDBUFLEN);
  8934. uidflag = 1;
  8935. }
  8936. #endif /* RLOGCODE */
  8937. #ifdef TNCODE
  8938. if (!sl_tn_saved) {
  8939. sl_tn_wait = tn_wait_flg;
  8940. sl_tn_saved = 1;
  8941. }
  8942. tn_wait_flg = param3;
  8943. #endif /* TNCODE */
  8944. #endif /* NOSPL */
  8945. } /* if (net == NET_TCPB) */
  8946. #endif /* TCPSOCKET */
  8947. #ifndef NOSPL
  8948. #ifdef CK_SECURITY
  8949. if (password) {
  8950. if (password[0]) {
  8951. ckstrncpy(pwbuf,password,PWBUFL+1);
  8952. pwflg = 1;
  8953. pwcrypt = 0;
  8954. } else
  8955. pwflg = 0;
  8956. }
  8957. #endif /* CK_SECURITY */
  8958. #endif /* NOSPL */
  8959. /* Try to open - network */
  8960. ckstrncpy(ttname,line,TTNAMLEN);
  8961. y = ttopen(line, &_local, mdmtyp, 0 );
  8962. #ifndef NOHTTP
  8963. /* If the connection failed and we are using an HTTP Proxy
  8964. * and the reason for the failure was an authentication
  8965. * error, then we need to give the user to ability to
  8966. * enter a username and password, just like a browser.
  8967. *
  8968. * I tried to do all of this within the netopen() call
  8969. * but it is much too much work.
  8970. */
  8971. while (y < 0 && tcp_http_proxy != NULL ) {
  8972. if (tcp_http_proxy_errno == 401 ||
  8973. tcp_http_proxy_errno == 407 ) {
  8974. char uid[UIDBUFLEN];
  8975. char pwd[256];
  8976. struct txtbox tb[2];
  8977. int ok;
  8978. tb[0].t_buf = uid;
  8979. tb[0].t_len = UIDBUFLEN;
  8980. tb[0].t_lbl = "Proxy Userid: ";
  8981. tb[0].t_dflt = NULL;
  8982. tb[0].t_echo = 1;
  8983. tb[1].t_buf = pwd;
  8984. tb[1].t_len = 256;
  8985. tb[1].t_lbl = "Proxy Passphrase: ";
  8986. tb[1].t_dflt = NULL;
  8987. tb[1].t_echo = 2;
  8988. ok = uq_mtxt("Proxy Server Authentication Required\n",
  8989. NULL, 2, tb);
  8990. if (ok && uid[0]) {
  8991. char * proxy_user, * proxy_pwd;
  8992. proxy_user = tcp_http_proxy_user;
  8993. proxy_pwd = tcp_http_proxy_pwd;
  8994. tcp_http_proxy_user = uid;
  8995. tcp_http_proxy_pwd = pwd;
  8996. ckstrncpy(ttname,line,TTNAMLEN);
  8997. y = ttopen(line, &_local, mdmtyp, 0);
  8998. memset(pwd,0,sizeof(pwd));
  8999. tcp_http_proxy_user = proxy_user;
  9000. tcp_http_proxy_pwd = proxy_pwd;
  9001. } else
  9002. break;
  9003. } else
  9004. break;
  9005. }
  9006. #endif /* NOHTTP */
  9007. if (y < 0) {
  9008. slrestor();
  9009. makestr(&slmsg,"Network connection failure");
  9010. #ifdef VMS
  9011. if (msg && hints && !xcmdsrc && IS_RLOGIN()) {
  9012. makestr(&slmsg,"RLOGIN failure");
  9013. if (socket_errno == EACCES) {
  9014. printf("*************************\n");
  9015. printf(
  9016. "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9017. printf(
  9018. "(Use SET HINTS OFF to suppress future hints.)\n");
  9019. printf("*************************\n");
  9020. }
  9021. }
  9022. #else /* Not VMS... */
  9023. if (errno) {
  9024. int x;
  9025. debug(F111,"set host line, errno","",errno);
  9026. makestr(&slmsg,ck_errstr());
  9027. if (msg) {
  9028. #ifdef OS2
  9029. printf("Can't connect to %s\n",line);
  9030. #else /* OS2 */
  9031. #ifdef UNIX
  9032. if (hints && !xcmdsrc && IS_RLOGIN()) {
  9033. makestr(&slmsg,"RLOGIN failure");
  9034. printf("*************************\n");
  9035. printf(
  9036. "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9037. printf(
  9038. "(Use SET HINTS OFF to suppress future hints.)\n");
  9039. printf("*************************\n");
  9040. }
  9041. #endif /* UNIX */
  9042. #endif /* OS2 */
  9043. } else printf("Can't connect to %s\n",line);
  9044. } else
  9045. #endif /* VMS */
  9046. if (msg) printf("Can't open connection to %s\n",line);
  9047. continue;
  9048. } else {
  9049. success = 1;
  9050. #ifndef NODIAL
  9051. dialsta = DIA_UNK;
  9052. #endif /* NODIAL */
  9053. switch (net) {
  9054. case NET_TCPA:
  9055. case NET_TCPB:
  9056. cxtype = CXT_TCPIP;
  9057. #ifdef COMMENT
  9058. /* This works but it messes up interactive anonymous login */
  9059. #ifndef NOXFER
  9060. #ifdef IKS_OPTION
  9061. /* If we have connected to an Internet Kermit service */
  9062. /* and a /USER: switch was given, then log in. */
  9063. if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT)) {
  9064. debug(F111,"cx_net IKSD /USER:",uidbuf,haveuser);
  9065. if (haveuser /* && cx == 0 */ ) { /* /USER: given */
  9066. char * psw = pwbuf; /* Do we have a password? */
  9067. if (!*psw) { /* No... */
  9068. if (!strcmp(uidbuf,"anonymous") ||
  9069. !strcmp(uidbuf,"ftp")) {
  9070. extern char myhost[];
  9071. char * u = (char *)sl_uidbuf;
  9072. char * h = (char *)myhost;
  9073. if (!*u) u = "nobody";
  9074. if (!*h) h = "nowhere";
  9075. ckmakmsg(tmpbuf,TMPBUFSIZ,u,"@",h,NULL);
  9076. psw = tmpbuf;
  9077. debug(F110,"cx_net IKSD anon",psw,0);
  9078. } else {
  9079. readpass(" Password: ",pwbuf,PWBUFL);
  9080. }
  9081. }
  9082. sstate = setgen('I',uidbuf,psw,"");
  9083. }
  9084. }
  9085. #endif /* IKS_OPTION */
  9086. #endif /* NOXFER */
  9087. #endif /* COMMENT */
  9088. break;
  9089. case NET_SSH:
  9090. cxtype = CXT_SSH;
  9091. duplex = 0; /* Remote echo */
  9092. break;
  9093. case NET_SLAT:
  9094. cxtype = CXT_LAT;
  9095. break;
  9096. case NET_SX25:
  9097. case NET_IX25:
  9098. case NET_HX25:
  9099. case NET_VX25:
  9100. cxtype = CXT_X25;
  9101. break;
  9102. case NET_BIOS:
  9103. cxtype = CXT_NETBIOS;
  9104. break;
  9105. case NET_FILE:
  9106. case NET_PIPE:
  9107. case NET_CMD:
  9108. case NET_DLL:
  9109. case NET_PTY:
  9110. cxtype = CXT_PIPE;
  9111. break;
  9112. default:
  9113. cxtype = CXT_PIPE;
  9114. break;
  9115. }
  9116. break;
  9117. }
  9118. } /* for-loop */
  9119. s = line;
  9120. debug(F101,"cx_net post ttopen success","",success);
  9121. if (!success) {
  9122. local = dfloc; /* Go back to normal */
  9123. #ifndef MAC
  9124. ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  9125. #endif /* MAC */
  9126. speed = ttgspd();
  9127. network = 0; /* No network connection active */
  9128. haveline = 0;
  9129. if (mdmtyp < 0) { /* Switching from net to async? */
  9130. if (mdmsav > -1) /* Restore modem type from last */
  9131. mdmtyp = mdmsav; /* SET MODEM command, if any. */
  9132. else
  9133. mdmtyp = 0;
  9134. mdmsav = -1;
  9135. }
  9136. return(0); /* Return failure */
  9137. }
  9138. if (_local > -1) local = _local; /* Opened ok, set local/remote. */
  9139. makestr(&slmsg,NULL);
  9140. network = (mdmtyp < 0); /* Remember connection type. */
  9141. ckstrncpy(ttname,s,TTNAMLEN); /* Copy name into real place. */
  9142. debug(F110,"cx_net ok",ttname,0);
  9143. debug(F101,"cx_net network","",network);
  9144. #ifndef NOXFER
  9145. if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  9146. reliable = SET_OFF;
  9147. #endif /* NOXFER */
  9148. if (!network || istncomport())
  9149. speed = ttgspd(); /* Get the current speed. */
  9150. debug(F101,"cx_net local","",local);
  9151. if (network) {
  9152. debug(F101,"cx_net net","",net);
  9153. #ifndef NOXFER
  9154. /* Force prefixing of 255 on TCP/IP connections... */
  9155. if (net == NET_TCPB
  9156. #ifdef SSHBUILTIN
  9157. || net == NET_SSH
  9158. #endif /* SSHBUILTIN */
  9159. ) {
  9160. debug(F101,"cx_net reliable A","",reliable);
  9161. #ifdef CK_SPEED
  9162. ctlp[(unsigned)255] = 1;
  9163. #endif /* CK_SPEED */
  9164. if ((reliable != SET_OFF || !setreliable)) {
  9165. #ifdef TN_COMPORT
  9166. if (istncomport()) { /* Telnet communication port */
  9167. reliable = SET_OFF; /* Transport is not reliable */
  9168. debug(F101,"cx_net reliable istncomport()","",1);
  9169. } else {
  9170. reliable = SET_ON; /* Transport is reliable end to end */
  9171. debug(F101,"cx_net reliable istncomport()","",0);
  9172. }
  9173. #else
  9174. reliable = SET_ON; /* Transport is reliable end to end */
  9175. #endif /* ifdef TN_COMPORT */
  9176. }
  9177. debug(F101,"cx_net reliable B","",reliable);
  9178. } else if (net == NET_SX25 ||
  9179. net == NET_VX25 ||
  9180. net == NET_IX25 ||
  9181. net == NET_HX25) {
  9182. duplex = 1; /* Local echo for X.25 */
  9183. if (reliable != SET_OFF || !setreliable)
  9184. reliable = SET_ON; /* Transport is reliable end to end */
  9185. }
  9186. #endif /* NOXFER */
  9187. }
  9188. #ifndef NOXFER
  9189. debug(F101,"cx_net reliable","",reliable);
  9190. #endif /* NOXFER */
  9191. #ifdef OS2
  9192. if (mdmtyp <= 0) /* Network or Direct Connection */
  9193. DialerSend(OPT_KERMIT_CONNECT, 0);
  9194. #endif /* OS2 */
  9195. xcx_net:
  9196. setflow(); /* Set appropriate flow control */
  9197. haveline = 1;
  9198. #ifdef CKLOGDIAL
  9199. dolognet();
  9200. #endif /* CKLOGDIAL */
  9201. #ifndef NOSPL
  9202. if (local) {
  9203. if (nmac) { /* Any macros defined? */
  9204. int k; /* Yes */
  9205. k = mlook(mactab,"on_open",nmac); /* Look this up */
  9206. if (k >= 0) { /* If found, */
  9207. if (dodo(k,ttname,0) > -1) /* set it up, */
  9208. parser(1); /* and execute it */
  9209. }
  9210. }
  9211. }
  9212. #endif /* NOSPL */
  9213. if (local && (cx || sx)) { /* /CONNECT or /SERVER switch given */
  9214. if (cx) { /* /CONNECT */
  9215. if (!gui) {
  9216. /* Command was confirmed so we can pre-pop command level. */
  9217. /* This is so CONNECT module won't think we're executing a */
  9218. /* script if CONNECT was the final command in the script. */
  9219. if (cmdlvl > 0)
  9220. prepop();
  9221. }
  9222. #ifndef NODIAL
  9223. dialsta = DIA_UNK;
  9224. #endif /* NODIAL */
  9225. #ifdef LOCUS
  9226. if (autolocus) {
  9227. setlocus(1,1);
  9228. }
  9229. #endif /* LOCUS */
  9230. success = doconect(0, cmdlvl == 0 ? 1 : 0);
  9231. if (ttchk() < 0)
  9232. dologend();
  9233. debug(F101,"cx_net post doconect success","",success);
  9234. return(success);
  9235. #ifndef NOXFER
  9236. } else if (sx) { /* /SERVER */
  9237. sstate = 'x';
  9238. #ifdef MAC
  9239. what = W_RECV;
  9240. scrcreate();
  9241. #endif /* MAC */
  9242. if (local) displa = 1;
  9243. #ifdef AMIGA
  9244. reqoff(); /* No DOS requestors while server */
  9245. #endif /* AMIGA */
  9246. #endif /* NOXFER */
  9247. }
  9248. }
  9249. #ifndef NODIAL
  9250. dialsta = DIA_UNK;
  9251. #endif /* NODIAL */
  9252. #ifdef LOCUS
  9253. if (autolocus) {
  9254. setlocus(1,1);
  9255. }
  9256. #endif /* LOCUS */
  9257. return(success = 1);
  9258. }
  9259. #endif /* NETCONN */
  9260. /* c x _ s e r i a l -- Make a serial connection */
  9261. /*
  9262. Call with:
  9263. device = string pointer to device name.
  9264. cx = 1 to automatically enter Connect mode, 0 otherwise.
  9265. sx = 1 to automatically enter Server mode, 0 otherwise.
  9266. shr = 1 if device should be opened in shareable mode, 0 otherwise.
  9267. flag = if no dev name given: 1 = close current connection, 0 = resume.
  9268. gui = 1 if called from GUI dialog, 0 otherwise.
  9269. Returns:
  9270. 1 on success
  9271. 0 on failure and no message printed, slmsg set to failure message.
  9272. -9 on failure and message printed, ditto.
  9273. */
  9274. /* these are bit flags */
  9275. #define CX_TAPI 1
  9276. #define CX_PPP 2
  9277. #define CX_SLIP 4
  9278. int
  9279. #ifdef CK_ANSIC
  9280. cx_serial(char *device,
  9281. int cx, int sx, int shr, int flag, int gui, int special)
  9282. #else /* CK_ANSIC */
  9283. cx_serial(device, cx, sx, shr, flag, gui, special)
  9284. char * device; int cx, sx, shr, flag, gui, special;
  9285. #endif /* CK_ANSIC */
  9286. /* cx_serial */ {
  9287. int i, n, x, y, msg;
  9288. int _local = -1;
  9289. char *s;
  9290. debug(F110,"cx_serial device",device,0);
  9291. s = device;
  9292. msg = (gui == 0) && msgflg; /* Whether to print messages */
  9293. success = 0;
  9294. #ifndef NODIAL
  9295. dialsta = DIA_UNK;
  9296. #endif /* NODIAL */
  9297. debug(F101,"cx_serial mdmtyp","",mdmtyp);
  9298. if (clskconnx(1) < 0) /* Close the Kermit connection */
  9299. return(success = 0);
  9300. if (*s) { /* They gave a device name */
  9301. _local = -1; /* Let ttopen decide about it */
  9302. } else { /* They just said "set line" */
  9303. s = dftty; /* so go back to normal tty */
  9304. _local = dfloc; /* and mode. */
  9305. }
  9306. #ifdef VMS
  9307. {
  9308. extern int ok_to_share;
  9309. ok_to_share = shr;
  9310. }
  9311. #endif /* VMS */
  9312. #ifdef OS2 /* Must wait until after ttclos() */
  9313. #ifdef NT /* to change these settings */
  9314. #ifdef CK_TAPI
  9315. tttapi = special & CX_TAPI;
  9316. #endif /* CK_TAPI */
  9317. #else
  9318. ttslip = special & CX_SLIP;
  9319. ttppp = special & CX_PPP;
  9320. #endif /* NT */
  9321. ttshare = shr; /* Shareable device ? */
  9322. debug(F110,"OS2 SET PORT final s",s,"");
  9323. #endif /* OS2 */
  9324. /* Open the new line */
  9325. ckstrncpy(ttname,s,TTNAMLEN);
  9326. if ((y = ttopen(s,&_local,mdmtyp,cdtimo)) > -1) {
  9327. cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  9328. #ifndef NODIAL
  9329. dialsta = DIA_UNK;
  9330. #ifdef CK_TAPI
  9331. /* if the line is a tapi device, then we need to auto-execute */
  9332. /* SET MODEM TYPE TAPI - which we do the equivalent of here. */
  9333. if (tttapi) {
  9334. extern int usermdm;
  9335. usermdm = 0;
  9336. initmdm(38); /* From ckudia.c n_TAPI == 38 */
  9337. }
  9338. #endif /* CK_TAPI */
  9339. #endif /* NODIAL */
  9340. success = 1;
  9341. } else { /* Failed */
  9342. #ifdef OS2ONLY
  9343. if (!strcmp(s,dftty)) /* Do not generate an error with dftty */
  9344. ;
  9345. else if (y == -6 && ttslip) {
  9346. makestr(&slmsg,"Can't access SLIP driver");
  9347. if (msg) printf("?%s\n",slmsg);
  9348. } else if (y == -6 && ttppp) {
  9349. makestr(&slmsg,"Can't access PPP driver");
  9350. if (msg) printf("?%s\n",slmsg);
  9351. } else
  9352. #endif /* OS2ONLY */
  9353. if (y == -2) {
  9354. makestr(&slmsg,"Timed out - no carrier");
  9355. if (msg) {
  9356. printf("?%s\n",slmsg);
  9357. if (hints) {
  9358. printf("\n*************************\n");
  9359. printf(
  9360. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9361. printf(
  9362. "Try SET CARRIER OFF and SET LINE again, or else\n");
  9363. printf("SET MODEM, SET LINE, and then DIAL.\n");
  9364. printf("*************************\n\n");
  9365. }
  9366. }
  9367. } else if (y == -3) {
  9368. makestr(&slmsg,"Access to lock denied");
  9369. if (msg) {
  9370. #ifdef UNIX
  9371. printf(
  9372. "Sorry, write access to UUCP lockfile directory denied.\n");
  9373. #ifndef NOHINTS
  9374. if (hints) {
  9375. printf("\n*************************\n");
  9376. printf(
  9377. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9378. printf(
  9379. "Please read the installation instructions file, %sckuins.txt,\n",
  9380. k_info_dir ? k_info_dir : ""
  9381. );
  9382. printf(
  9383. "or the UNIX appendix of the manual, \"Using C-Kermit\"\n"
  9384. );
  9385. printf(
  9386. "or visit http://www.kermitproject.org/ckuins.html \n"
  9387. );
  9388. printf("*************************\n\n");
  9389. }
  9390. #endif /* NOHINTS */
  9391. #else
  9392. printf("Sorry, access to lock denied: %s\n",s);
  9393. #endif /* UNIX */
  9394. }
  9395. } else if (y == -4) {
  9396. makestr(&slmsg,"Access to device denied");
  9397. if (msg) {
  9398. printf("Sorry, access to device denied: %s\n",s);
  9399. #ifdef UNIX
  9400. #ifndef NOHINTS
  9401. if (hints) {
  9402. printf("\n*************************\n");
  9403. printf(
  9404. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9405. printf(
  9406. "Please read the installation instructions file, %sckuins.txt,\n",
  9407. k_info_dir ? k_info_dir : ""
  9408. );
  9409. printf(
  9410. "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9411. );
  9412. printf("*************************\n\n");
  9413. }
  9414. #endif /* NOHINTS */
  9415. #endif /* UNIX */
  9416. }
  9417. } else if (y == -5) {
  9418. makestr(&slmsg,"Device is in use or unavailable");
  9419. if (msg)
  9420. #ifdef VMS
  9421. printf(
  9422. "Sorry, device is in use or otherwise unavailable: %s\n",s);
  9423. #else
  9424. printf("Sorry, device is in use: %s\n",s);
  9425. #endif /* VMS */
  9426. } else { /* Other error. */
  9427. makestr(&slmsg,"Device open failed");
  9428. if (
  9429. #ifdef VMS
  9430. 1
  9431. #else
  9432. errno
  9433. #endif /* VMS */
  9434. ) {
  9435. int x; /* Find a safe, long buffer */
  9436. makestr(&slmsg,ck_errstr());
  9437. #ifndef VMS
  9438. debug(F111,"cx_serial serial errno",slmsg,errno);
  9439. #endif /* VMS */
  9440. if (msg)
  9441. printf("Connection to %s failed: %s\n",s,slmsg);
  9442. } else if (msg)
  9443. printf("Sorry, can't open connection: %s\n",s);
  9444. }
  9445. }
  9446. network = 0; /* No network connection active */
  9447. speed = ttgspd();
  9448. if (!success) {
  9449. local = dfloc; /* Go back to normal */
  9450. #ifndef MAC
  9451. ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  9452. #endif /* MAC */
  9453. haveline = 0;
  9454. if (mdmtyp < 0) { /* Switching from net to async? */
  9455. if (mdmsav > -1) /* Restore modem type from last */
  9456. mdmtyp = mdmsav; /* SET MODEM command, if any. */
  9457. else
  9458. mdmtyp = 0;
  9459. mdmsav = -1;
  9460. }
  9461. return(msg ? -9 : 0); /* Return failure */
  9462. }
  9463. if (_local > -1)
  9464. local = _local; /* Opened ok, set local/remote. */
  9465. makestr(&slmsg,NULL); /* Erase SET LINE message */
  9466. ckstrncpy(ttname,s,TTNAMLEN); /* Copy name into real place. */
  9467. debug(F110,"cx_serial ok",ttname,0);
  9468. #ifndef NOXFER
  9469. if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  9470. reliable = SET_OFF;
  9471. #endif /* NOXFER */
  9472. xcx_serial:
  9473. setflow(); /* Set appropriate flow control */
  9474. haveline = 1;
  9475. #ifdef CKLOGDIAL
  9476. dologline();
  9477. #endif /* CKLOGDIAL */
  9478. #ifndef NOSPL
  9479. if (local) {
  9480. if (nmac) { /* Any macros defined? */
  9481. int k; /* Yes */
  9482. k = mlook(mactab,"on_open",nmac); /* Look this up */
  9483. if (k >= 0) { /* If found, */
  9484. if (dodo(k,ttname,0) > -1) /* set it up, */
  9485. parser(1); /* and execute it */
  9486. }
  9487. }
  9488. }
  9489. #endif /* NOSPL */
  9490. if (local && (cx || sx)) { /* /CONNECT or /SERVER switch given */
  9491. extern int carrier;
  9492. if (carrier != CAR_OFF) { /* Looking for carrier? */
  9493. /* Open() turns on DTR -- wait up to a second for CD to come up */
  9494. int i, x;
  9495. for (i = 0; i < 10; i++) { /* WAIT 1 CD... */
  9496. x = ttgmdm();
  9497. if (x < 0 || x & BM_DCD)
  9498. break;
  9499. msleep(100);
  9500. }
  9501. }
  9502. if (cx) { /* /CONNECT */
  9503. /* Command was confirmed so we can pre-pop command level. */
  9504. /* This is so CONNECT module won't think we're executing a */
  9505. /* script if CONNECT was the final command in the script. */
  9506. if (cmdlvl > 0)
  9507. prepop();
  9508. #ifndef NODIAL
  9509. dialsta = DIA_UNK;
  9510. #endif /* NODIAL */
  9511. #ifdef LOCUS
  9512. if (autolocus) {
  9513. setlocus(1,1);
  9514. }
  9515. #endif /* LOCUS */
  9516. success = doconect(0, cmdlvl == 0 ? 1 : 0);
  9517. if (ttchk() < 0)
  9518. dologend();
  9519. return(success);
  9520. #ifndef NOXFER
  9521. } else if (sx) { /* /SERVER */
  9522. sstate = 'x';
  9523. #ifdef MAC
  9524. what = W_RECV;
  9525. scrcreate();
  9526. #endif /* MAC */
  9527. if (local) displa = 1;
  9528. #ifdef AMIGA
  9529. reqoff(); /* No DOS requestors while server */
  9530. #endif /* AMIGA */
  9531. #endif /* NOXFER */
  9532. }
  9533. }
  9534. #ifndef NODIAL
  9535. dialsta = DIA_UNK;
  9536. #endif /* NODIAL */
  9537. #ifdef LOCUS
  9538. if (autolocus) {
  9539. setlocus(1,1);
  9540. }
  9541. #endif /* LOCUS */
  9542. return(success = 1);
  9543. }
  9544. /* S E T L I N -- parse name of and then open communication device. */
  9545. /*
  9546. Call with:
  9547. xx == XYLINE for a serial (tty) line, XYHOST for a network host,
  9548. zz == 0 means if user doesn't give a device name, continue current
  9549. active connection (if any);
  9550. zz != 0 means if user doesn't give a device name, then close the
  9551. current connection and restore the default communication device.
  9552. fc == 0 to just make the connection, 1 to also CONNECT (e.g. "telnet").
  9553. */
  9554. int
  9555. setlin(xx, zz, fc)
  9556. int xx, zz, fc;
  9557. {
  9558. extern char pwbuf[], * g_pswd;
  9559. extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  9560. int wait;
  9561. /* int tn_wait_sv; */
  9562. int mynet;
  9563. int _local = -1;
  9564. int c, i, haveswitch = 0;
  9565. int haveuser = 0;
  9566. int getval = 0;
  9567. int wild = 0; /* Filespec has wildcards */
  9568. int cx = 0; /* Connect after */
  9569. int sx = 0; /* Become server after */
  9570. int a_type = -1; /* Authentication type */
  9571. int e_type = -1; /* Telnet /ENCRYPT type */
  9572. #ifdef CK_ENCRYPTION
  9573. int encrypt = 0; /* Encrypted? */
  9574. #endif /* CK_ENCRYPTION */
  9575. int shr = 0; /* Share serial device */
  9576. int confirmed = 0; /* Command has been entered */
  9577. struct FDB sw, tx, nx;
  9578. #ifdef OS2
  9579. struct FDB fl;
  9580. #endif /* OS2 */
  9581. char * ss;
  9582. #ifdef TCPSOCKET
  9583. int rawflg = 0;
  9584. #endif /* TCPSOCKET */
  9585. char srvbuf[SRVBUFSIZ+1];
  9586. #ifdef OS2
  9587. #ifdef NT
  9588. int xxtapi = 0;
  9589. #else
  9590. int xxslip = 0, xxppp = 0;
  9591. #endif /* NT */
  9592. #endif /* OS2 */
  9593. int dossh = 0;
  9594. debug(F101,"setlin fc","",fc);
  9595. debug(F101,"setlin zz","",zz);
  9596. debug(F101,"setlin xx","",xx);
  9597. #ifdef SSHCMD
  9598. if (xx == XXSSH) { /* SSH becomes PTY SSH ... */
  9599. dossh = 1;
  9600. xx = XYHOST;
  9601. } else if (!ckstrcmp("ssh ",line,4,0)) { /* 2010/03/01 */
  9602. dossh = 1;
  9603. xx = XYHOST;
  9604. }
  9605. debug(F101,"setlin dossh","",dossh);
  9606. #endif /* SSHCMD */
  9607. #ifdef TNCODE
  9608. /* tn_wait_sv = tn_wait_flg; */
  9609. wait = tn_wait_flg;
  9610. #else
  9611. /* tn_wait_sv = 0; */
  9612. wait = 0;
  9613. #endif /* TNCODE */
  9614. mynet = nettype;
  9615. if (nolocal) {
  9616. makestr(&slmsg,"Making connections is disabled");
  9617. printf("?Sorry, making connections is disabled\n");
  9618. return(-9);
  9619. }
  9620. if (netsave > -1)
  9621. nettype = netsave;
  9622. if (fc != 0 || zz == 0) /* Preset /CONNECT switch */
  9623. cx = 1;
  9624. debug(F101,"setlin cx","",cx);
  9625. *srvbuf = NUL;
  9626. line[0] = NUL;
  9627. s = line;
  9628. #ifdef NETCONN
  9629. #ifdef CK_SECURITY
  9630. if (tmpstring)
  9631. makestr(&tmpstring,NULL);
  9632. #endif /* CK_SECURITY */
  9633. if (tmpusrid)
  9634. makestr(&tmpusrid,NULL);
  9635. #endif /* NETCONN */
  9636. autoflow = 1; /* Enable automatic flow setting */
  9637. if (xx == XYHOST) { /* SET HOST <hostname> */
  9638. #ifndef NETCONN
  9639. makestr(&slmsg,"Network connections not supported");
  9640. printf("?%s\n",slmsg);
  9641. return(-9);
  9642. #else /* NETCONN */
  9643. #ifndef NOPUSH
  9644. if ((mynet == NET_CMD || mynet == NET_PTY || dossh) && nopush) {
  9645. makestr(&slmsg,"Access to external commands is disabled");
  9646. printf("?Sorry, access to external commands is disabled\n");
  9647. return(-9);
  9648. }
  9649. #endif /* NOPUSH */
  9650. #ifdef SSHCMD
  9651. if (dossh) { /* SSH connection via pty */
  9652. int k;
  9653. extern int ttyfd; /* 2010/03/01 */
  9654. k = ckstrncpy(line, sshcmd ? sshcmd : defsshcmd, LINBUFSIZ);
  9655. debug(F111,"setlin sshcmd 1",line,k);
  9656. if ((x = cmtxt("Optional switches and hostname","",&s,xxstring))<0)
  9657. return(x);
  9658. /* 2010-03-30 */
  9659. if (!*s && ttyfd < 0 && !ckstrcmp("ssh ",ttname,4,0)) {
  9660. x = ckstrncpy(line,ttname,LINBUFSIZ);
  9661. } else {
  9662. if (!*s) {
  9663. printf("?SSH to where?\n");
  9664. return(-9);
  9665. }
  9666. if (k < LINBUFSIZ) {
  9667. line[k++] = SP;
  9668. line[k] = NUL;
  9669. debug(F111,"setlin sshcmd 2",line,k);
  9670. } if (k < LINBUFSIZ) {
  9671. ckstrncpy(&line[k],s,LINBUFSIZ-k);
  9672. debug(F111,"setlin sshcmd 3",line,k);
  9673. } else {
  9674. printf("?Too long\n");
  9675. return(-9);
  9676. }
  9677. }
  9678. x = cx_net( NET_PTY, /* network type */
  9679. 0, /* protocol (not used) */
  9680. line, /* host */
  9681. NULL, /* service (not used) */
  9682. NULL, /* username (not used) */
  9683. NULL, /* password (not used) */
  9684. NULL, /* command (not used) */
  9685. -1,-1,-1, /* params 1-3 (not used) */
  9686. 1, /* connect immediately */
  9687. sx, /* server? */
  9688. zz, /* close current? */
  9689. 0); /* not gui */
  9690. debug(F111,"setlin cx_net",line,x);
  9691. return(x);
  9692. }
  9693. #endif /* SSHCMD */
  9694. /*
  9695. Here we parse optional switches and then the hostname or whatever,
  9696. which depends on the network type. The tricky part is, the network type
  9697. can be set by a switch.
  9698. */
  9699. #ifndef NOSPL
  9700. makestr(&g_pswd,pwbuf); /* Save global pwbuf */
  9701. g_pflg = pwflg; /* and flag */
  9702. g_pcpt = pwcrypt;
  9703. #endif /* NOSPL */
  9704. confirmed = 0;
  9705. haveswitch = 0;
  9706. #ifdef NETFILE
  9707. if (mynet != NET_FILE) {
  9708. #endif /* NETFILE */
  9709. ss = (mynet == NET_CMD || mynet == NET_PTY) ?
  9710. "Command, or switch" :
  9711. (mynet == NET_TCPA || mynet == NET_TCPB
  9712. || mynet == NET_SSH) ?
  9713. "Hostname, ip-address, or switch" :
  9714. "Host or switch";
  9715. if (fc) {
  9716. if (mynet == NET_TCPB &&
  9717. (ttnproto == NP_TELNET || ttnproto == NP_KERMIT)) {
  9718. if (nshteltab) {
  9719. haveswitch++;
  9720. cmfdbi(&sw,_CMKEY,ss,"","",nshteltab,4,xxstring,
  9721. shteltab,&nx);
  9722. }
  9723. }
  9724. #ifdef RLOGCODE
  9725. else if (mynet == NET_TCPB && ttnproto == NP_RLOGIN) {
  9726. if (nshrlgtab) {
  9727. haveswitch++;
  9728. cmfdbi(&sw,_CMKEY,ss,"","",nshrlgtab,4,xxstring,
  9729. shrlgtab,&nx);
  9730. }
  9731. }
  9732. #endif /* RLOGCODE */
  9733. } else {
  9734. haveswitch++;
  9735. cmfdbi(&sw,_CMKEY,ss,"","",nshtab,4,xxstring,shtab,&nx);
  9736. }
  9737. #ifdef NETFILE
  9738. }
  9739. #endif /* NETFILE */
  9740. if (mynet == NET_TCPB || mynet == NET_SLAT ||
  9741. mynet == NET_SSH || mynet == NET_DEC) {
  9742. cmfdbi(&nx,_CMFLD,"Host","","",0,0,xxstring,NULL,NULL);
  9743. #ifdef NETFILE
  9744. } else if (mynet == NET_FILE) {
  9745. cmfdbi(&nx,_CMIFI,"Filename","","",0,0,xxstring,NULL,NULL);
  9746. #endif /* NETFILE */
  9747. #ifdef PTYORPIPE
  9748. } else if (mynet == NET_CMD || mynet == NET_PTY) {
  9749. cmfdbi(&nx,_CMTXT,"Command","","",0,0,xxstring,NULL,NULL);
  9750. #endif /* PTYORPIPE */
  9751. } else {
  9752. cmfdbi(&nx,_CMTXT,"Host","","",0,0,xxstring,NULL,NULL);
  9753. }
  9754. while (1) {
  9755. x = cmfdb(haveswitch ? &sw : &nx);
  9756. debug(F101,"setlin cmfdb","",x);
  9757. if (x < 0)
  9758. if (x != -3)
  9759. return(x);
  9760. if (x == -3) {
  9761. if ((x = cmcfm()) < 0) {
  9762. return(x);
  9763. } else {
  9764. confirmed = 1;
  9765. break;
  9766. }
  9767. }
  9768. if (cmresult.fcode != _CMKEY) { /* Not a switch */
  9769. ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Save the data */
  9770. s = line; /* that was parsed... */
  9771. if (cmresult.fcode == _CMIFI) {
  9772. wild = cmresult.nresult;
  9773. } else if (cmresult.fcode == _CMTXT) {
  9774. confirmed = 1;
  9775. }
  9776. break; /* and break out of this loop */
  9777. }
  9778. c = cmgbrk(); /* Have switch - get break character */
  9779. getval = (c == ':' || c == '='); /* Must parse an agument? */
  9780. if (getval && !(cmresult.kflags & CM_ARG)) {
  9781. printf("?This switch does not take arguments\n");
  9782. return(-9);
  9783. }
  9784. if (!getval && (cmgkwflgs() & CM_ARG)) {
  9785. printf("?This switch requires an argument\n");
  9786. return(-9);
  9787. }
  9788. switch (cmresult.nresult) { /* It's a switch.. */
  9789. case SL_CNX: /* /CONNECT */
  9790. cx = 1;
  9791. sx = 0;
  9792. break;
  9793. case SL_SRV: /* /SERVER */
  9794. cx = 0;
  9795. sx = 1;
  9796. break;
  9797. #ifdef NETCMD
  9798. case SL_CMD: /* /COMMAND */
  9799. netsave = mynet;
  9800. mynet = NET_CMD;
  9801. break;
  9802. #endif /* NETCMD */
  9803. #ifdef NETPTY
  9804. case SL_PTY: /* /PTY */
  9805. netsave = mynet;
  9806. mynet = NET_PTY;
  9807. break;
  9808. #endif /* NETPTY */
  9809. case SL_NET: /* /NETWORK-TYPE */
  9810. if ((x = cmkey(netcmd,nnets,"","",xxstring)) < 0)
  9811. return(x);
  9812. mynet = x;
  9813. break;
  9814. #ifdef CK_SECURITY
  9815. case SL_PSW: /* /PASSWORD: */
  9816. if (!getval)
  9817. break;
  9818. debok = 0;
  9819. if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  9820. if (x == -3) {
  9821. makestr(&tmpstring,"");
  9822. } else {
  9823. return(x);
  9824. }
  9825. } else {
  9826. s = brstrip(s);
  9827. if ((x = (int)strlen(s)) > PWBUFL) {
  9828. makestr(&slmsg,"Internal error");
  9829. printf("?Sorry, too long - max = %d\n",PWBUFL);
  9830. return(-9);
  9831. }
  9832. makestr(&tmpstring,s);
  9833. }
  9834. break;
  9835. #endif /* CK_SECURITY */
  9836. case SL_UID: /* /USERID: */
  9837. if (!getval)
  9838. break;
  9839. if ((x = cmfld("Userid","",&s,xxstring)) < 0) {
  9840. if (x == -3) {
  9841. makestr(&tmpusrid,"");
  9842. } else {
  9843. return(x);
  9844. }
  9845. } else {
  9846. s = brstrip(s);
  9847. if ((x = (int)strlen(s)) > 63) {
  9848. makestr(&slmsg,"Internal error");
  9849. printf("?Sorry, too long - max = %d\n",63);
  9850. return(-9);
  9851. }
  9852. makestr(&tmpusrid,s);
  9853. haveuser = 1;
  9854. }
  9855. break;
  9856. #ifdef CK_AUTHENTICATION
  9857. #ifdef CK_SRP
  9858. case SL_SRP:
  9859. a_type = AUTHTYPE_SRP;
  9860. break;
  9861. #endif /* CK_SRP */
  9862. #ifdef CK_SSL
  9863. case SL_SSL:
  9864. a_type = AUTHTYPE_SSL;
  9865. break;
  9866. #endif /* CK_SSL */
  9867. #ifdef NT
  9868. case SL_NTLM:
  9869. a_type = AUTHTYPE_NTLM;
  9870. break;
  9871. #endif /* NT */
  9872. #ifdef CK_KERBEROS
  9873. case SL_KRB4:
  9874. a_type = AUTHTYPE_KERBEROS_V4;
  9875. if (ttnproto == NP_RLOGIN)
  9876. ttnproto =
  9877. #ifdef CK_ENCRYPTION
  9878. encrypt ? NP_EK4LOGIN :
  9879. #endif /* CK_ENCRYPTION */
  9880. NP_K4LOGIN;
  9881. else if (ttnproto == NP_K5LOGIN)
  9882. ttnproto = NP_K4LOGIN;
  9883. #ifdef CK_ENCRYPTION
  9884. else if (ttnproto == NP_EK5LOGIN)
  9885. ttnproto = NP_EK4LOGIN;
  9886. #endif /* CK_ENCRYPTION */
  9887. break;
  9888. case SL_KRB5:
  9889. a_type = AUTHTYPE_KERBEROS_V5;
  9890. if (ttnproto == NP_RLOGIN)
  9891. ttnproto =
  9892. #ifdef CK_ENCRYPTION
  9893. encrypt ? NP_EK5LOGIN :
  9894. #endif /* CK_ENCRYPTION */
  9895. NP_K5LOGIN;
  9896. else if (ttnproto == NP_K4LOGIN)
  9897. ttnproto = NP_K5LOGIN;
  9898. #ifdef CK_ENCRYPTION
  9899. else if (ttnproto == NP_EK4LOGIN)
  9900. ttnproto = NP_EK5LOGIN;
  9901. #endif /* CK_ENCRYPTION */
  9902. break;
  9903. #endif /* CK_KERBEROS */
  9904. case SL_AUTH: {
  9905. extern struct keytab autyptab[];
  9906. extern int nautyp;
  9907. if ((x = cmkey(autyptab,nautyp,"type of authentication",
  9908. "automatic",xxstring)) < 0)
  9909. return(x);
  9910. a_type = x;
  9911. break;
  9912. }
  9913. #endif /* CK_AUTHENTICATION */
  9914. #ifdef CK_ENCRYPTION
  9915. case SL_ENC:
  9916. switch (ttnproto) {
  9917. case NP_K4LOGIN:
  9918. ttnproto = NP_EK4LOGIN;
  9919. encrypt = 1;
  9920. break;
  9921. case NP_K5LOGIN:
  9922. ttnproto = NP_EK5LOGIN;
  9923. encrypt = 1;
  9924. break;
  9925. case NP_KERMIT:
  9926. case NP_TELNET: {
  9927. static struct keytab * tnetbl = NULL;
  9928. static int ntnetbl = 0;
  9929. x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  9930. debug(F101,"ck_get_crypt_table x","",x);
  9931. debug(F101,"ck_get_crypt_table n","",ntnetbl);
  9932. if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  9933. x = 0;
  9934. if (!x) {
  9935. makestr(&slmsg,"Internal error");
  9936. printf("?Oops, types not loaded\n");
  9937. return(-9);
  9938. }
  9939. if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  9940. "automatic",xxstring)) < 0)
  9941. return(x);
  9942. e_type = x;
  9943. break;
  9944. }
  9945. }
  9946. break;
  9947. #endif /* CK_ENCRYPTION */
  9948. case SL_WAIT:
  9949. wait = 1;
  9950. break;
  9951. case SL_NOWAIT:
  9952. wait = 0;
  9953. break;
  9954. }
  9955. }
  9956. #ifdef NETFILE
  9957. if (mynet == NET_FILE) { /* Parsed by cmifi() */
  9958. if ((x = cmcfm()) < 0) /* Needs confirmation */
  9959. return(x);
  9960. x = cx_net(mynet, /* nettype */
  9961. 0, /* protocol (not used) */
  9962. line, /* host */
  9963. "", /* port */
  9964. NULL, /* alternate username */
  9965. NULL, /* password */
  9966. NULL, /* command to execute */
  9967. 0, /* param1 */
  9968. 0, /* param2 */
  9969. 0, /* param3 */
  9970. cx, /* enter CONNECT mode */
  9971. sx, /* enter SERVER mode */
  9972. zz, /* close connection if open */
  9973. 0 /* gui */
  9974. );
  9975. }
  9976. #endif /* NETFILE */
  9977. #ifdef NETCMD
  9978. if (mynet == NET_CMD || mynet == NET_PTY) {
  9979. char *p = NULL;
  9980. if (!confirmed) {
  9981. if ((x = cmtxt("Rest of command","",&s,xxstring)) < 0)
  9982. return(x);
  9983. if (*s) {
  9984. ckstrncat(line," ",LINBUFSIZ);
  9985. ckstrncat(line,s,LINBUFSIZ);
  9986. }
  9987. s = line;
  9988. }
  9989. /* s == line - so we must protect the line buffer */
  9990. s = brstrip(s);
  9991. makestr(&p,s);
  9992. ckstrncpy(line,p,LINBUFSIZ);
  9993. makestr(&p,NULL);
  9994. x = cx_net( mynet, /* nettype */
  9995. 0, /* protocol (not used) */
  9996. line, /* host */
  9997. "", /* port */
  9998. NULL, /* alternate username */
  9999. NULL, /* password */
  10000. NULL, /* command to execute */
  10001. 0, /* param1 */
  10002. 0, /* param2 */
  10003. 0, /* param3 */
  10004. cx, /* enter CONNECT mode */
  10005. sx, /* enter SERVER mode */
  10006. zz, /* close connection if open */
  10007. 0 /* gui */
  10008. );
  10009. }
  10010. #endif /* NETCMD */
  10011. #ifdef NPIPE /* Named pipe */
  10012. if (mynet == NET_PIPE) { /* Needs backslash twiddling */
  10013. if (line[0]) {
  10014. if (strcmp(line,"*")) { /* If remote, begin with */
  10015. char * p = NULL;
  10016. makestr(&p,line);
  10017. ckstrncpy(line,"\\\\",LINBUFSIZ); /* server name */
  10018. ckstrncat(line,p,LINBUFSIZ);
  10019. makestr(&p,NULL);
  10020. } else {
  10021. line[0]='\0';
  10022. }
  10023. ckstrncat(line,"\\pipe\\", LINBUFSIZ); /* Make pipe name */
  10024. ckstrncat(line,pipename, LINBUFSIZ); /* Add name of pipe */
  10025. x = cx_net(mynet, /* nettype */
  10026. 0, /* protocol (not used) */
  10027. line, /* host */
  10028. "", /* port */
  10029. NULL, /* alternate username */
  10030. NULL, /* password */
  10031. NULL, /* command to execute */
  10032. 0, /* param1 */
  10033. 0, /* param2 */
  10034. 0, /* param3 */
  10035. cx, /* enter CONNECT mode */
  10036. sx, /* enter SERVER mode */
  10037. zz, /* close connection if open */
  10038. 0 /* gui */
  10039. );
  10040. }
  10041. }
  10042. #endif /* NPIPE */
  10043. #ifdef SUPERLAT
  10044. if (mynet == NET_SLAT) { /* Needs password, etc. */
  10045. slat_pwd[0] = NUL; /* Erase any previous password */
  10046. debok = 0;
  10047. if (*line) { /* If they gave a host name... */
  10048. if ((x = cmfld(
  10049. "password,\n or carriage return if no password required",
  10050. "",
  10051. &s,
  10052. xxstring
  10053. )) < 0 && x != -3)
  10054. return(x);
  10055. ckstrncpy(slat_pwd,s,18); /* Set the password, if any */
  10056. }
  10057. if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10058. x = cx_net(mynet, /* nettype */
  10059. 0, /* protocol (not used) */
  10060. line, /* host */
  10061. "", /* port */
  10062. NULL, /* alternate username */
  10063. NULL, /* password */
  10064. NULL, /* command to execute */
  10065. 0, /* param1 */
  10066. 0, /* param2 */
  10067. 0, /* param3 */
  10068. cx, /* enter CONNECT mode */
  10069. sx, /* enter SERVER mode */
  10070. zz, /* close connection if open */
  10071. 0 /* gui */
  10072. );
  10073. }
  10074. #endif /* SUPERLAT */
  10075. #ifdef DECNET
  10076. if (mynet == NET_DEC) {
  10077. if (!line[0]) { /* If they gave a host name... */
  10078. printf("?hostname required\n");
  10079. return(-3);
  10080. }
  10081. if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10082. x = cx_net(mynet, /* nettype */
  10083. 0, /* protocol (not used) */
  10084. line, /* host */
  10085. "", /* port */
  10086. NULL, /* alternate username */
  10087. NULL, /* password */
  10088. NULL, /* command to execute */
  10089. 0, /* param1 */
  10090. 0, /* param2 */
  10091. 0, /* param3 */
  10092. cx, /* enter CONNECT mode */
  10093. sx, /* enter SERVER mode */
  10094. zz, /* close connection if open */
  10095. 0 /* gui */
  10096. );
  10097. }
  10098. #endif /* DECNET */
  10099. #ifdef SSHBUILTIN
  10100. if (mynet == NET_SSH) { /* SSH connection */
  10101. int k, havehost = 0, trips = 0;
  10102. int tmpver = -1, tmpxfw = -1, tmpssh_cas;
  10103. #ifndef SSHTEST
  10104. extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  10105. extern int sl_ssh_ver, sl_ssh_ver_saved;
  10106. #endif /* SSHTEST */
  10107. extern struct keytab sshopnsw[];
  10108. extern int nsshopnsw;
  10109. extern char *ssh_tmpcmd, *ssh_tmpport;
  10110. struct FDB sw, kw, fl;
  10111. debug(F110,"setlin SSH service 0",srvbuf,0);
  10112. debug(F110,"setlin SSH host s 2",s,0);
  10113. if (*s) { /* If they gave a host name... */
  10114. debug(F110,"setlin SSH host s 1",s,0);
  10115. if (*s == '*') {
  10116. makestr(&slmsg,"Incoming connections not supported");
  10117. printf(
  10118. "?Sorry, incoming connections not supported for SSH.\n"
  10119. );
  10120. return(-9);
  10121. }
  10122. ckstrncpy(line,s,LINBUFSIZ);
  10123. } else {
  10124. printf("?hostname required\n");
  10125. return(-3);
  10126. }
  10127. /* Parse [ port ] [ switches ] */
  10128. cmfdbi(&kw, /* Switches */
  10129. _CMKEY,
  10130. "Port number or service name,\nor switch",
  10131. "",
  10132. "",
  10133. nsshopnsw,
  10134. 4,
  10135. xxstring,
  10136. sshopnsw,
  10137. &fl
  10138. );
  10139. cmfdbi(&fl, /* Port number or service name */
  10140. _CMFLD,
  10141. "",
  10142. "",
  10143. "",
  10144. 0,
  10145. 0,
  10146. xxstring,
  10147. NULL,
  10148. NULL
  10149. );
  10150. trips = 0; /* Explained below */
  10151. while (1) { /* Parse port and switches */
  10152. y = cmfdb(&kw); /* Get a field */
  10153. if (y == -3) /* User typed CR so quit from loop */
  10154. break;
  10155. if (y < 0) /* Other parse error, pass it back */
  10156. return(y);
  10157. switch (cmresult.fcode) { /* Field or Keyword? */
  10158. case _CMFLD: /* Field */
  10159. ckstrncpy(srvbuf,cmresult.sresult,SRVBUFSIZ);
  10160. break;
  10161. case _CMKEY: /* Keyword */
  10162. switch (cmresult.nresult) { /* Which one? */
  10163. case SSHSW_PWD:
  10164. if (!cmgbrk()) {
  10165. printf("?This switch requires an argument\n");
  10166. return(-9);
  10167. }
  10168. debok = 0;
  10169. if ((y = cmfld("Password","",&s,xxstring)) < 0) {
  10170. if (y == -3) {
  10171. makestr(&tmpstring,"");
  10172. } else {
  10173. return(y);
  10174. }
  10175. } else {
  10176. s = brstrip(s);
  10177. if ((y = (int)strlen(s)) > PWBUFL) {
  10178. makestr(&slmsg,"Internal error");
  10179. printf("?Sorry, too long - max = %d\n",PWBUFL);
  10180. return(-9);
  10181. }
  10182. makestr(&tmpstring,s);
  10183. }
  10184. break;
  10185. case SSHSW_USR: /* /USER: */
  10186. if (!cmgbrk()) {
  10187. printf("?This switch requires an argument\n");
  10188. return(-9);
  10189. }
  10190. if ((y = cmfld("Username","",&s,xxstring)) < 0)
  10191. return(y);
  10192. s = brstrip(s);
  10193. makestr(&tmpusrid,s);
  10194. break;
  10195. case SSHSW_VER:
  10196. if ((y = cmnum("Number","",10,&z,xxstring)) < 0)
  10197. return(y);
  10198. if (z < 1 || z > 2) {
  10199. printf("?Out of range: %d\n",z);
  10200. return(-9);
  10201. }
  10202. tmpver = z;
  10203. break;
  10204. case SSHSW_CMD:
  10205. case SSHSW_SUB:
  10206. if ((y = cmfld("Text","",&s,xxstring)) < 0)
  10207. return(y);
  10208. makestr(&ssh_tmpcmd,s);
  10209. tmpssh_cas = (cmresult.nresult == SSHSW_SUB);
  10210. break;
  10211. case SSHSW_X11:
  10212. if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  10213. return(y);
  10214. tmpxfw = y;
  10215. break;
  10216. default:
  10217. return(-2);
  10218. }
  10219. }
  10220. if (trips++ == 0) { /* After first time through */
  10221. cmfdbi(&kw, /* only parse switches, not port. */
  10222. _CMKEY,
  10223. "Switch",
  10224. "",
  10225. "",
  10226. nsshopnsw,
  10227. 4,
  10228. xxstring,
  10229. sshopnsw,
  10230. NULL
  10231. );
  10232. }
  10233. }
  10234. if ((y = cmcfm()) < 0) /* Get confirmation */
  10235. return(y);
  10236. debug(F110,"setlin pre-cx_net line",line,0);
  10237. debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  10238. x = cx_net( mynet, /* nettype */
  10239. 0, /* protocol (not used) */
  10240. line, /* host */
  10241. srvbuf, /* port */
  10242. tmpusrid, /* alternate username */
  10243. tmpstring, /* password */
  10244. ssh_tmpcmd, /* command to execute */
  10245. tmpver, /* param1 - ssh version */
  10246. tmpssh_cas, /* param2 - ssh cas */
  10247. tmpxfw, /* param3 - ssh x11fwd */
  10248. cx, /* enter CONNECT mode */
  10249. sx, /* enter SERVER mode */
  10250. zz, /* close connection if open */
  10251. 0 /* gui */
  10252. );
  10253. if (tmpusrid)
  10254. makestr(&tmpusrid,NULL);
  10255. if (ssh_tmpcmd)
  10256. makestr(&ssh_tmpcmd,NULL);
  10257. }
  10258. #endif /* SSHBUILTIN */
  10259. #ifdef TCPSOCKET
  10260. if (mynet == NET_TCPB) { /* TCP/IP connection */
  10261. debug(F110,"setlin service 0",srvbuf,0);
  10262. debug(F110,"setlin host s 2",s,0);
  10263. if (*s) { /* If they gave a host name... */
  10264. debug(F110,"setlin host s 1",s,0);
  10265. #ifdef NOLISTEN
  10266. if (*s == '*') {
  10267. makestr(&slmsg,"Incoming connections not supported");
  10268. printf(
  10269. "?Sorry, incoming connections not supported in this version of Kermit.\n"
  10270. );
  10271. return(-9);
  10272. }
  10273. #endif /* NOLISTEN */
  10274. #ifdef RLOGCODE
  10275. /* Allow a username if rlogin is requested */
  10276. if (mynet == NET_TCPB &&
  10277. (ttnproto == NP_RLOGIN || ttnproto == NP_K5LOGIN ||
  10278. ttnproto == NP_EK5LOGIN || ttnproto == NP_K4LOGIN ||
  10279. ttnproto == NP_EK4LOGIN
  10280. )) {
  10281. int y;
  10282. uidflag = 0;
  10283. /* Check for "host:service" */
  10284. for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10285. if (*s) { /* Service, save it */
  10286. *s = NUL;
  10287. ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10288. } else { /* No :service, then use default. */
  10289. #ifdef VMS
  10290. switch (ttnproto) {
  10291. case NP_RLOGIN:
  10292. ckstrncpy(srvbuf,"513",SRVBUFSIZ); /* "login" */
  10293. break;
  10294. case NP_K4LOGIN:
  10295. case NP_K5LOGIN:
  10296. ckstrncpy(srvbuf,"543",SRVBUFSIZ); /* "klogin" */
  10297. break;
  10298. case NP_EK4LOGIN:
  10299. case NP_EK5LOGIN:
  10300. ckstrncpy(srvbuf,"2105",SRVBUFSIZ); /* "eklogin" */
  10301. break;
  10302. }
  10303. #else /* VMS */
  10304. switch (ttnproto) {
  10305. case NP_RLOGIN:
  10306. ckstrncpy(srvbuf,"login",SRVBUFSIZ);
  10307. break;
  10308. case NP_K4LOGIN:
  10309. case NP_K5LOGIN:
  10310. ckstrncpy(srvbuf,"klogin",SRVBUFSIZ);
  10311. break;
  10312. case NP_EK4LOGIN:
  10313. case NP_EK5LOGIN:
  10314. ckstrncpy(srvbuf,"eklogin",SRVBUFSIZ);
  10315. break;
  10316. }
  10317. #endif /* VMS */
  10318. }
  10319. if (!confirmed) {
  10320. y = cmfld("Userid on remote system",
  10321. uidbuf,&s,xxstring);
  10322. if (y < 0 && y != -3)
  10323. return(y);
  10324. if ((int)strlen(s) > 63) {
  10325. makestr(&slmsg,"Internal error");
  10326. printf("Sorry, too long\n");
  10327. return(-9);
  10328. }
  10329. makestr(&tmpusrid,s);
  10330. }
  10331. } else { /* TELNET or SET HOST */
  10332. #endif /* RLOGCODE */
  10333. /* Check for "host:service" */
  10334. for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10335. if (*s) { /* Service, save it */
  10336. *s = NUL;
  10337. ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10338. } else if (!confirmed) {
  10339. /* No :service, let them type one. */
  10340. if (*line != '*') { /* Not incoming */
  10341. if (mynet == NET_TCPB && ttnproto == NP_KERMIT) {
  10342. if ((x = cmfld(
  10343. "TCP service name or number",
  10344. "kermit",&s,xxstring)
  10345. ) < 0 && x != -3)
  10346. return(x);
  10347. #ifdef RLOGCODE
  10348. } else if (mynet == NET_TCPB &&
  10349. ttnproto == NP_RLOGIN) {
  10350. if ((x = cmfld(
  10351. "TCP service name or number,\n or carriage return for rlogin (513)",
  10352. "login",&s,xxstring)
  10353. ) < 0 && x != -3)
  10354. return(x);
  10355. #ifdef CK_AUTHENTICATION
  10356. #ifdef CK_KERBEROS
  10357. } else if (mynet == NET_TCPB &&
  10358. (ttnproto == NP_K4LOGIN ||
  10359. ttnproto == NP_K5LOGIN)) {
  10360. if ((x = cmfld(
  10361. "TCP service name or number,\n or carriage return for klogin (543)",
  10362. "klogin",&s,xxstring)
  10363. ) < 0 && x != -3)
  10364. return(x);
  10365. } else if (mynet == NET_TCPB &&
  10366. (ttnproto == NP_EK4LOGIN ||
  10367. ttnproto == NP_EK5LOGIN)) {
  10368. if ((x = cmfld(
  10369. "TCP service name or number,\n or carriage return for eklogin (2105)",
  10370. "eklogin",&s,xxstring)
  10371. ) < 0 && x != -3)
  10372. return(x);
  10373. #endif /* CK_KERBEROS */
  10374. #endif /* CK_AUTHENTICATION */
  10375. #endif /* RLOGCODE */
  10376. } else {
  10377. /* Do not set a default value in this call */
  10378. /* If you do then it will prevent entries */
  10379. /* in the network directory from accessing */
  10380. /* alternate ports. */
  10381. if ((x = cmfld(
  10382. "TCP service name or number",
  10383. "",&s,xxstring)
  10384. ) < 0 && x != -3)
  10385. return(x);
  10386. }
  10387. } else { /* Incoming connection */
  10388. if ((x = cmfld("TCP service name or number",
  10389. "",&s,xxstring)
  10390. ) < 0 && x != -3)
  10391. return(x);
  10392. }
  10393. if (*s) /* If they gave a service, */
  10394. ckstrncpy(srvbuf,s,SRVBUFSIZ); /* copy it */
  10395. debug(F110,"setlin service 0.5",srvbuf,0);
  10396. }
  10397. #ifdef RLOGCODE
  10398. }
  10399. #endif /* RLOGCODE */
  10400. if (!confirmed) {
  10401. char * defproto;
  10402. switch (ttnproto) {
  10403. case NP_RLOGIN:
  10404. defproto = "/rlogin";
  10405. break;
  10406. case NP_K4LOGIN:
  10407. defproto = "/k4login";
  10408. break;
  10409. case NP_K5LOGIN:
  10410. defproto = "/k5login";
  10411. break;
  10412. case NP_EK4LOGIN:
  10413. defproto = "/ek4login";
  10414. break;
  10415. case NP_EK5LOGIN:
  10416. defproto = "/ek5login";
  10417. break;
  10418. case NP_KERMIT:
  10419. case NP_TELNET:
  10420. defproto = "/telnet";
  10421. break;
  10422. default:
  10423. defproto = "/default";
  10424. }
  10425. if ((x = cmkey(tcprawtab,ntcpraw,"Switch",defproto,
  10426. xxstring)) < 0) {
  10427. if (x != -3)
  10428. return(x);
  10429. else if ((x = cmcfm()) < 0)
  10430. return(x);
  10431. } else {
  10432. rawflg = x;
  10433. if ((x = cmcfm()) < 0)
  10434. return(x);
  10435. }
  10436. }
  10437. }
  10438. debug(F110,"setlin pre-cx_net line",line,0);
  10439. debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  10440. x = cx_net( mynet, /* nettype */
  10441. rawflg /* protocol */,
  10442. line, /* host */
  10443. srvbuf, /* port */
  10444. tmpusrid, /* alternate username */
  10445. tmpstring, /* password */
  10446. NULL, /* command to execute */
  10447. a_type, /* param1 - telnet authtype */
  10448. e_type, /* param2 - telnet enctype */
  10449. wait, /* param3 - telnet wait */
  10450. cx, /* enter CONNECT mode */
  10451. sx, /* enter SERVER mode */
  10452. zz, /* close connection if open */
  10453. 0 /* gui */
  10454. );
  10455. }
  10456. #endif /* TCPSOCKET */
  10457. #ifdef CK_SECURITY
  10458. if (tmpstring)
  10459. makestr(&tmpstring,NULL);
  10460. #endif /* CK_SECURITY */
  10461. if (tmpusrid)
  10462. makestr(&tmpusrid,NULL);
  10463. debug(F111,"setlin cx_net",line,x);
  10464. return(x);
  10465. #endif /* NETCONN */
  10466. }
  10467. /* Serial tty device, possibly modem, connection... */
  10468. #ifdef OS2
  10469. /*
  10470. User can type:
  10471. COM1..COM8 = Regular COM port
  10472. 1..8 = Synonym for COM1..COM8, is translated to COM1..COM8
  10473. _n = (n is a number) = open file handle
  10474. string = any text string = name of some other kind of device,
  10475. taken literally, as given.
  10476. */
  10477. s = "Communication device name";
  10478. #ifdef CK_TAPI
  10479. if (TAPIAvail)
  10480. cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  10481. if (!(tapilinetab && _tapilinetab && ntapiline > 0) &&
  10482. xx == XYTAPI_LIN ) {
  10483. makestr(&slmsg,"TAPI device not configured");
  10484. printf("\nNo TAPI Line Devices are configured for this system\n");
  10485. return(-9);
  10486. }
  10487. if (xx == XYTAPI_LIN) { /* Default (first) TAPI line */
  10488. s = "tapi"; /* (whatever it is) */
  10489. } else { /* Query the user */
  10490. #endif /* CK_TAPI */
  10491. /* Now parse optional switches and then device name */
  10492. confirmed = 0;
  10493. cmfdbi(&sw,_CMKEY,"Device name, or switch",
  10494. "","",npsltab,4,xxstring,psltab,&fl);
  10495. cmfdbi(&fl,_CMFLD,"",dftty,"",0,0,xxstring,NULL,NULL);
  10496. while (1) {
  10497. x = cmfdb(&sw);
  10498. debug(F101,"setlin cmfdb","",x);
  10499. if (x < 0)
  10500. if (x != -3)
  10501. return(x);
  10502. if (x == -3) {
  10503. if ((x = cmcfm()) < 0) {
  10504. return(x);
  10505. } else {
  10506. confirmed = 1;
  10507. break;
  10508. }
  10509. }
  10510. if (cmresult.fcode == _CMFLD) {
  10511. s = cmresult.sresult;
  10512. break;
  10513. } else if (cmresult.fcode == _CMKEY) {
  10514. switch (cmresult.nresult) {
  10515. case SL_CNX: /* /CONNECT */
  10516. cx = 1;
  10517. sx = 0;
  10518. break;
  10519. case SL_SRV: /* /SERVER */
  10520. cx = 0;
  10521. sx = 1;
  10522. break;
  10523. case SL_SHR: /* /SHARE */
  10524. shr = 1;
  10525. break;
  10526. case SL_NSH: /* /NOSHARE */
  10527. shr = 0;
  10528. break;
  10529. }
  10530. }
  10531. }
  10532. #ifdef CK_TAPI
  10533. }
  10534. #endif /* CK_TAPI */
  10535. debug(F110,"OS2 SET PORT s",s,0);
  10536. y = lookup(os2devtab,s,nos2dev,&x); /* Look up in keyword table */
  10537. debug(F101,"OS2 SET PORT x","",x);
  10538. debug(F101,"OS2 SET PORT y","",y);
  10539. if ((y > -1) && (x >= 0 && x < 8)) { /* User typed a digit 1..8 */
  10540. s = os2devtab[x+8].kwd; /* Substitite its real name */
  10541. #ifdef NT
  10542. xxtapi = 0;
  10543. #else /* NT */
  10544. xxslip = xxppp = 0;
  10545. #endif /* NT */
  10546. debug(F110,"OS2 SET PORT subst s",s,"");
  10547. #ifndef NT
  10548. } else if ((y >-1) && (x >= 16 && x < 24)) { /* SLIP access */
  10549. s = os2devtab[x-8].kwd; /* Substitite its real name */
  10550. debug(F110,"OS2 SET PORT SLIP subst s",s,"");
  10551. xxslip = 1;
  10552. xxppp = 0;
  10553. } else if ((y >-1) && (x >= 24 && x < 32)) { /* PPP access */
  10554. s = os2devtab[x-16].kwd; /* Substitite its real name */
  10555. debug(F110,"OS2 SET PORT PPP subst s",s,"");
  10556. xxppp = 1;
  10557. xxslip = 0;
  10558. if ((y = cmkey(os2ppptab,
  10559. nos2ppp,
  10560. "PPP driver interface",
  10561. "ppp0",
  10562. xxstring)
  10563. ) < 0)
  10564. return(y);
  10565. debug(F101,"OS2 SET PORT PPP INTERFACE y","",y);
  10566. xxppp = (y % 10) + 1;
  10567. #endif /* NT */
  10568. } else if (*s == '_') { /* User used "_" prefix */
  10569. s++; /* Remove it */
  10570. /* Rest must be numeric */
  10571. debug(F110,"OS2 SET PORT HANDLE _subst s",s,0);
  10572. if (!rdigits(s)) {
  10573. makestr(&slmsg,"Invalid file handle");
  10574. printf("?Invalid format for file handle\n");
  10575. return(-9);
  10576. }
  10577. #ifdef NT
  10578. xxtapi = 0;
  10579. #else /* NT */
  10580. xxslip = xxppp = 0;
  10581. #endif /* NT */
  10582. } else { /* A normal COMx port or a string */
  10583. s = brstrip(s); /* Strip braces if any */
  10584. #ifdef NT
  10585. #ifdef CK_TAPI
  10586. /* Windows TAPI support - Look up in keyword table */
  10587. if (tapilinetab && _tapilinetab && ntapiline > 0) {
  10588. if (!ckstrcmp(s,"tapi",4,0)) {
  10589. /* Find out what the lowest numbered TAPI device is */
  10590. /* and use it as the default. */
  10591. int j = 9999, k = -1;
  10592. for (i = 0; i < ntapiline; i++) {
  10593. if (tapilinetab[i].kwval < j) {
  10594. j = tapilinetab[i].kwval;
  10595. k = i;
  10596. }
  10597. }
  10598. if (k >= 0)
  10599. s = _tapilinetab[k].kwd;
  10600. else
  10601. s = "";
  10602. if ((y = cmkey(_tapilinetab,ntapiline,
  10603. "TAPI device name",s,xxstring)) < 0)
  10604. return(y);
  10605. xxtapi = 1;
  10606. /* Get the non Underscored string */
  10607. for (i = 0; i < ntapiline; i++ ) {
  10608. if (tapilinetab[i].kwval == y) {
  10609. s = tapilinetab[i].kwd;
  10610. break;
  10611. }
  10612. }
  10613. } else
  10614. xxtapi = 0;
  10615. }
  10616. #endif /* CK_TAPI */
  10617. #else /* NT */
  10618. /* not OS/2 SLIP or PPP */
  10619. xxslip = xxppp = 0;
  10620. #endif /* NT */
  10621. }
  10622. ckstrncpy(tmpbuf,s,TMPBUFSIZ); /* Copy to a safe place */
  10623. s = tmpbuf;
  10624. if ((x = cmcfm()) < 0)
  10625. return(x);
  10626. #else /* !OS2 */
  10627. cmfdbi(&sw,_CMKEY,"Device name, or switch",
  10628. "","",npsltab,4,xxstring,psltab,&tx);
  10629. cmfdbi(&tx,_CMTXT,"",dftty,"",0,0,xxstring,NULL,NULL);
  10630. while (!confirmed) {
  10631. x = cmfdb(&sw);
  10632. debug(F101,"setlin cmfdb","",x);
  10633. if (x < 0)
  10634. if (x != -3)
  10635. return(x);
  10636. if (x == -3) {
  10637. if ((x = cmcfm()) < 0) {
  10638. return(x);
  10639. } else {
  10640. confirmed = 1;
  10641. break;
  10642. }
  10643. }
  10644. switch (cmresult.fcode) {
  10645. case _CMTXT:
  10646. ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  10647. s = tmpbuf;
  10648. debug(F110,"setlin CMTXT",tmpbuf,0);
  10649. confirmed = 1;
  10650. break;
  10651. case _CMKEY: /* Switch */
  10652. debug(F101,"setlin CMKEY",tmpbuf,cmresult.nresult);
  10653. switch (cmresult.nresult) {
  10654. case SL_CNX: /* /CONNECT */
  10655. cx = 1;
  10656. sx = 0;
  10657. break;
  10658. case SL_SRV: /* /SERVER */
  10659. cx = 0;
  10660. sx = 1;
  10661. break;
  10662. #ifdef VMS
  10663. case SL_SHR: /* /SHARE */
  10664. shr = 1;
  10665. break;
  10666. case SL_NSH: /* /NOSHARE */
  10667. shr = 0;
  10668. break;
  10669. #endif /* VMS */
  10670. }
  10671. continue;
  10672. default:
  10673. debug(F101,"setlin bad cmfdb result","",cmresult.fcode);
  10674. makestr(&slmsg,"Internal error");
  10675. printf("?Internal parsing error\n");
  10676. return(-9);
  10677. }
  10678. }
  10679. #endif /* OS2 */
  10680. if (!confirmed)
  10681. if ((x = cmcfm()) < 0)
  10682. return(x);
  10683. debug(F110,"setlin pre-cx_serial s",s,0);
  10684. debug(F110,"setlin pre-cx_serial line",line,0);
  10685. x = cx_serial(s,cx,sx,shr,zz,0,
  10686. #ifdef OS2
  10687. #ifdef NT
  10688. (xxtapi ? CX_TAPI : 0)
  10689. #else
  10690. (xxslip ? CX_SLIP : 0) | (xxppp ? CX_PPP : 0)
  10691. #endif /* NT */
  10692. #else /* OS2 */
  10693. 0
  10694. #endif /* OS2 */
  10695. );
  10696. debug(F111,"setlin cx_serial",line,x);
  10697. return(x);
  10698. }
  10699. #endif /* NOLOCAL */
  10700. #ifdef CKCHANNELIO
  10701. /*
  10702. C-Library based file-i/o package for scripts. This should be portable to
  10703. all C-Kermit versions since it uses the same APIs we have always used for
  10704. processing command files. The entire channel i/o package is contained
  10705. herein, apart from some keyword table entries in the main keyword table
  10706. and the help text in the HELP command module.
  10707. On platforms like VMS and VOS, this package handles only UNIX-style
  10708. stream files. If desired, it can be replaced for those platforms by
  10709. <#>ifdef'ing out this code and adding the equivalent replacement routines
  10710. to the ck?fio.c module, e.g. for RMS-based file i/o in ckvfio.c.
  10711. */
  10712. #ifndef NOSTAT
  10713. #ifdef VMS
  10714. /* 2010-03-09 SMS. VAX C needs help to find "sys". It's easier not to try. */
  10715. #include <stat.h>
  10716. #else /* def VMS */
  10717. #include <sys/stat.h>
  10718. #endif /* def VMS [else] */
  10719. #endif /* NOSTAT */
  10720. #ifdef NLCHAR
  10721. static int z_lt = 1; /* Length of line terminator */
  10722. #else
  10723. static int z_lt = 2;
  10724. #endif /* NLCHAR */
  10725. struct ckz_file { /* C-Kermit file struct */
  10726. FILE * z_fp; /* Includes the C-Lib file struct */
  10727. unsigned int z_flags; /* Plus C-Kermit mode flags, */
  10728. CK_OFF_T z_nline; /* current line number if known, */
  10729. char z_name[CKMAXPATH+2]; /* and the file's name. */
  10730. };
  10731. static struct ckz_file ** z_file = NULL; /* Array of C-Kermit file structs */
  10732. static int z_inited = 0; /* Flag for array initialized */
  10733. int z_maxchan = Z_MAXCHAN; /* Max number of C-Kermit channels */
  10734. int z_openmax = CKMAXOPEN; /* Max number of open files overall */
  10735. int z_nopen = 0; /* How many channels presently open */
  10736. int z_error = 0; /* Most recent error */
  10737. int z_filcount = -1; /* Most recent FILE COUNT result */
  10738. #define RD_LINE 0 /* FILE READ options */
  10739. #define RD_CHAR 1
  10740. #define RD_SIZE 2
  10741. #define RD_TRIM 8 /* Like Snobol &TRIM = 1 */
  10742. #define RD_UNTA 9 /* Untabify */
  10743. #define WR_LINE RD_LINE /* FILE WRITE options */
  10744. #define WR_CHAR RD_CHAR
  10745. #define WR_SIZE RD_SIZE
  10746. #define WR_STRI 3
  10747. #define WR_LPAD 4
  10748. #define WR_RPAD 5
  10749. #ifdef UNIX
  10750. extern int ckmaxfiles; /* Filled in by sysinit(). */
  10751. #endif /* UNIX */
  10752. /* See ckcker.h for error numbers */
  10753. /* See ckcdeb.h for Z_MAXCHAN and CKMAXOPEN definitions */
  10754. /* NOTE: For VMS we might be able to fill in ckmaxfiles */
  10755. /* from FILLM and CHANNELCNT -- find out about these... */
  10756. static char * fopnargs[] = { /* Mode combinations for fopen() */
  10757. #ifdef COMMENT
  10758. /* All combinations of rwa */
  10759. "", "r", "w", "rw", "a", "ra", "wa", "rwa", /* Text mode */
  10760. "b", "rb", "wb", "rwb", "ab", "rab", "wab", "rwab" /* Binary mode */
  10761. #else
  10762. /* Combinations and syntax permitted by C libraries... */
  10763. "", "r", "w", "r+", "a", "", "a", "", /* Text mode */
  10764. #ifdef OS2
  10765. "", "rb", "wb", "r+b", "ab", "", "ab", "" /* Binary modes for K95 */
  10766. #else
  10767. #ifdef VMS
  10768. "", "rb", "wb", "r+b", "ab", "", "ab", "" /* Binary modes for VMS */
  10769. #else
  10770. "", "r", "w", "r+", "a", "", "a", "" /* Binary modes for UNIX */
  10771. #endif /* VMS */
  10772. #endif /* OS2 */
  10773. #endif /* COMMENT */
  10774. };
  10775. static int nfopnargs = sizeof(fopnargs) / sizeof(char *);
  10776. char * /* Error messages */
  10777. ckferror(n) int n; {
  10778. switch (n) {
  10779. case FX_NER: return("No error");
  10780. case FX_SYS: return(ck_errstr());
  10781. case FX_EOF: return("End of file");
  10782. case FX_NOP: return("File not open");
  10783. case FX_CHN: return("Channel out of range");
  10784. case FX_RNG: return("Parameter out of range");
  10785. case FX_NMF: return("Too many files open");
  10786. case FX_FOP: return("Operation conflicts with OPEN mode");
  10787. case FX_NYI: return("OPEN mode not supported");
  10788. case FX_BOM: return("Illegal combination of OPEN modes");
  10789. case FX_ACC: return("Access denied");
  10790. case FX_FNF: return("File not found");
  10791. case FX_OFL: return("Buffer overflow");
  10792. case FX_LNU: return("Current line number unknown");
  10793. case FX_ROO: return("Off limits");
  10794. case FX_UNK: return("Operation fails - reason unknown");
  10795. default: return("Error number out of range");
  10796. }
  10797. }
  10798. /*
  10799. Z _ O P E N -- Open a file for the requested type of access.
  10800. Call with:
  10801. name: Name of file to be opened.
  10802. flags: Any combination of FM_xxx values except FM_EOF (ckcker.h).
  10803. Returns:
  10804. >= 0 on success: The assigned channel number
  10805. < 0 on failure: A negative FX_xxx error code (ckcker.h).
  10806. */
  10807. int
  10808. z_open(name, flags) char * name; int flags; {
  10809. int i, n;
  10810. FILE * t;
  10811. char * mode;
  10812. debug(F111,"z_open",name,flags);
  10813. if (!name) name = ""; /* Check name argument */
  10814. if (!name[0])
  10815. return(z_error = FX_BFN);
  10816. if (flags & FM_CMD) /* Opening pipes not implemented yet */
  10817. return(z_error = FX_NYI); /* (and not portable either) */
  10818. debug(F101,"z_open nfopnargs","",nfopnargs);
  10819. if (flags & FM_STDIN) { /* Read from standard input */
  10820. mode = "r";
  10821. } else if (flags & (FM_STDOUT|FM_STDERR)) {
  10822. mode = "w";
  10823. } else { /* If regular file, not stdin.. */
  10824. if (flags < 0 || flags >= nfopnargs) /* Range check flags */
  10825. return(z_error = FX_RNG);
  10826. mode = fopnargs[flags]; /* Get fopen() arg */
  10827. debug(F111,"z_open fopen args",mode,flags);
  10828. if (!mode[0]) /* Check for illegal combinations */
  10829. return(z_error = FX_BOM);
  10830. }
  10831. if (!z_inited) { /* If file structs not inited */
  10832. debug(F101,"z_open z_maxchan 1","",z_maxchan);
  10833. #ifdef UNIX
  10834. debug(F101,"z_open ckmaxfiles","",ckmaxfiles);
  10835. if (ckmaxfiles > 0) { /* Set in ck?tio.c: sysinit() */
  10836. int x;
  10837. x = ckmaxfiles - ZNFILS - 5;
  10838. if (x > z_maxchan) /* sysconf() value greater than */
  10839. z_maxchan = x; /* value from header files. */
  10840. debug(F101,"z_open z_maxchan 2","",z_maxchan);
  10841. }
  10842. #endif /* UNIX */
  10843. if (z_maxchan < Z_MINCHAN) /* Allocate at least this many. */
  10844. z_maxchan = Z_MINCHAN;
  10845. debug(F101,"z_open z_maxchan 3","",z_maxchan);
  10846. /* Note: This could be a pretty big chunk of memory */
  10847. /* if z_maxchan is a big number. If this becomes a problem */
  10848. /* we'll need to malloc and free each element at open/close time */
  10849. #ifdef COMMENT
  10850. /* May 2006 - it's time - in current Linux this about 3MB */
  10851. if (!(z_file = (struct ckz_file *)
  10852. malloc(sizeof(struct ckz_file) * (z_maxchan + 1))))
  10853. return(z_error = FX_NMF);
  10854. for (i = 0; i < z_maxchan; i++) {
  10855. z_file[i].z_fp = NULL;
  10856. z_file[i].z_flags = 0;
  10857. z_file[i].z_nline = 0;
  10858. *(z_file[i].z_name) = '\0';
  10859. }
  10860. #else
  10861. /* New economical way, allocate storage for each channel as needed */
  10862. if (!z_file) {
  10863. debug(F100,"z_file[] is NULL","",0);
  10864. debug(F101,"sizeof(struct ckz_file *)","",
  10865. sizeof(struct ckz_file *));
  10866. z_file = (struct ckz_file **)malloc((z_maxchan + 1) *
  10867. sizeof(struct ckz_file *));
  10868. debug(F101,"z_open z_maxchan 4","",z_maxchan);
  10869. if (!z_file)
  10870. return(z_error = FX_NMF);
  10871. for (i = 0; i < z_maxchan; i++)
  10872. z_file[i] = NULL;
  10873. debug(F101,"z_open z_maxchan 5","",z_maxchan);
  10874. }
  10875. #endif /* COMMENT */
  10876. debug(F101,"z_open z_maxchan 6","",z_maxchan);
  10877. z_inited = 1; /* Remember we initialized */
  10878. }
  10879. for (n = -1, i = 0; i < z_maxchan; i++) { /* Find a free channel */
  10880. #ifdef COMMENT
  10881. if (!z_file[i].z_fp) {
  10882. n = i;
  10883. break;
  10884. }
  10885. #else
  10886. debug(F101,"z_open find-free-channel loop","",i);
  10887. if (!z_file[i]) {
  10888. z_file[i] = (struct ckz_file *) malloc(sizeof(struct ckz_file));
  10889. if (!z_file[i])
  10890. return(z_error = FX_NMF);
  10891. n = i;
  10892. break;
  10893. }
  10894. #endif /* COMMENT */
  10895. }
  10896. debug(F101,"z_open found free channel","",n);
  10897. if (n < 0 || n >= z_maxchan) /* Any free channels? */
  10898. return(z_error = FX_NMF); /* No, fail. */
  10899. debug(F100,"z_open check n ok","",0);
  10900. errno = 0;
  10901. debug(F100,"z_open errno ok","",0);
  10902. z_file[n]->z_flags = 0; /* In case of failure... */
  10903. debug(F100,"z_open z_file[n] flags ok","",0);
  10904. z_file[n]->z_fp = NULL; /* Set file pointer to NULL */
  10905. debug(F100,"z_open z_file[n] fps ok","",0);
  10906. #ifdef UNIX
  10907. if (flags & FM_STDIN) { /* Standard input */
  10908. t = (FILE *)stdin; /* We just use the ready-made stream */
  10909. z_nopen++; /* Count it. */
  10910. z_file[n]->z_fp = t; /* Stash the file pointer */
  10911. z_file[n]->z_flags = flags; /* and the flags */
  10912. z_file[n]->z_nline = 0; /* Current line number is 0 */
  10913. ckstrncpy(z_file[n]->z_name,name,CKMAXPATH); /* "filename" */
  10914. z_error = 0; /* No error so far */
  10915. return(n); /* Return the channel number */
  10916. }
  10917. if (flags & FM_STDOUT) { /* Standard output */
  10918. t = (FILE *)stdout; /* Same deal */
  10919. z_nopen++;
  10920. z_file[n]->z_fp = t;
  10921. z_file[n]->z_flags = flags;
  10922. z_file[n]->z_nline = 0;
  10923. ckstrncpy(z_file[n]->z_name,name,CKMAXPATH);
  10924. z_error = 0;
  10925. return(n);
  10926. }
  10927. if (flags & FM_STDERR) { /* Standard error */
  10928. t = (FILE *)stderr;
  10929. z_nopen++;
  10930. z_file[n]->z_fp = t;
  10931. z_file[n]->z_flags = flags;
  10932. z_file[n]->z_nline = 0;
  10933. ckstrncpy(z_file[n]->z_name,name,CKMAXPATH);
  10934. z_error = 0;
  10935. return(n);
  10936. }
  10937. #endif /* UNIX */
  10938. t = fopen(name, mode); /* Try to open the file. */
  10939. if (!t) { /* Failed... */
  10940. debug(F111,"z_open error",name,errno);
  10941. #ifdef EMFILE
  10942. if (errno == EMFILE)
  10943. return(z_error = FX_NMF);
  10944. #endif /* EMFILE */
  10945. free(z_file[n]);
  10946. z_file[n] = NULL;
  10947. return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error code */
  10948. }
  10949. #ifdef NT
  10950. #ifdef O_SEQUENTIAL
  10951. if (t) /* Caching hint for NT */
  10952. _setmode(_fileno(t),O_SEQUENTIAL);
  10953. #endif /* O_SEQUENTIAL */
  10954. #endif /* NT */
  10955. z_nopen++; /* Open, count it. */
  10956. z_file[n]->z_fp = t; /* Stash the file pointer */
  10957. z_file[n]->z_flags = flags; /* and the flags */
  10958. z_file[n]->z_nline = 0; /* Current line number is 0 */
  10959. z_error = 0;
  10960. zfnqfp(name,CKMAXPATH,z_file[n]->z_name); /* and the file's full name */
  10961. return(n); /* Return the channel number */
  10962. }
  10963. int
  10964. z_close(channel) int channel; { /* Close file on given channel */
  10965. int x;
  10966. FILE * t;
  10967. if (!z_inited) /* Called before any files are open? */
  10968. return(z_error = FX_NOP);
  10969. if (channel >= z_maxchan) /* Channel out of range? */
  10970. return(z_error = FX_CHN);
  10971. if (!z_file[channel])
  10972. return(z_error = FX_NOP);
  10973. if (!(t = z_file[channel]->z_fp)) /* Channel wasn't open? */
  10974. return(z_error = FX_NOP);
  10975. errno = 0; /* Set errno 0 to get a good reading */
  10976. if (!(z_file[channel]->z_flags & FM_STDM)) /* If not stdin/out/err... */
  10977. x = fclose(t); /* Try to close */
  10978. if (x == EOF) /* On failure */
  10979. return(z_error = FX_SYS); /* indicate system error. */
  10980. z_nopen--; /* Closed OK, decrement open count */
  10981. z_file[channel]->z_fp = NULL; /* Set file pointer to NULL */
  10982. z_file[channel]->z_nline = 0; /* Current line number is 0 */
  10983. z_file[channel]->z_flags = 0; /* Set flags to 0 */
  10984. *(z_file[channel]->z_name) = '\0'; /* Clear name */
  10985. free(z_file[channel]);
  10986. z_file[channel] = NULL;
  10987. return(z_error = 0);
  10988. }
  10989. /*
  10990. Z _ O U T -- Output string to channel.
  10991. Call with:
  10992. channel: Channel number to write to.
  10993. s: String to write.
  10994. length > -1: How many characters of s to write.
  10995. length < 0: Write entire NUL-terminated string.
  10996. flags == 0: Supply line termination.
  10997. flags > 0: Don't supply line termination.
  10998. flags < 0: Write 'length' NUL characters.
  10999. Special case:
  11000. If flags > -1 and s is empty or NULL and length == 1, write 1 NUL.
  11001. Returns:
  11002. Number of characters written to channel on success, or
  11003. negative FX_xxx error code on failure.
  11004. */
  11005. int
  11006. z_out(channel,s,length,flags) int channel, flags, length; char * s; {
  11007. FILE * t;
  11008. int x, n;
  11009. char c = '\0';
  11010. if (!s) s = ""; /* Guard against null pointer */
  11011. #ifdef DEBUG
  11012. if (deblog) {
  11013. debug(F111,"z_out",s,channel);
  11014. debug(F101,"z_out length","",length);
  11015. debug(F101,"z_out flags","",flags);
  11016. }
  11017. #endif /* DEBUG */
  11018. if (!z_inited) /* File i/o inited? */
  11019. return(z_error = FX_NOP);
  11020. if (channel >= z_maxchan) /* Channel in range? */
  11021. return(z_error = FX_CHN);
  11022. if (!z_file[channel])
  11023. return(z_error = FX_NOP);
  11024. if (!(t = z_file[channel]->z_fp)) /* File open? */
  11025. return(z_error = FX_NOP);
  11026. if (!((z_file[channel]->z_flags) & (FM_WRI|FM_APP))) /* In write mode? */
  11027. return(z_error = FX_FOP);
  11028. n = length; /* Length of string to write */
  11029. if (n < 0) { /* Negative means get it ourselves */
  11030. if (flags < 0) /* Except when told to write NULs in */
  11031. return(z_error = FX_RNG); /* which case args are inconsistent */
  11032. n = strlen(s); /* Get length of string arg */
  11033. }
  11034. errno = 0; /* Reset errno */
  11035. debug(F101,"z_out n","",n);
  11036. if (flags < 0) { /* Writing NULs... */
  11037. int i;
  11038. for (i = 0; i < n; i++) {
  11039. x = fwrite(&c,1,1,t);
  11040. if (x < 1)
  11041. return(z_error = (errno ? FX_SYS : FX_UNK));
  11042. }
  11043. z_file[channel]->z_nline = -1; /* Current line no longer known */
  11044. z_error = 0;
  11045. return(i);
  11046. } else { /* Writing string arg */
  11047. if (n == 1 && !s[0]) /* Writing one char but it's NUL */
  11048. x = fwrite(&c,1,1,t);
  11049. else /* Writing non-NUL char or string */
  11050. x = fwrite(s,1,n,t);
  11051. debug(F101,"z_out fwrite",ckitoa(x),errno);
  11052. if (x < n) /* Failure to write requested amount */
  11053. return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error */
  11054. if (flags == 0) { /* If supplying line termination */
  11055. if (fwrite("\n",1,1,t)) /* do that */
  11056. x += z_lt; /* count the terminator */
  11057. if (z_file[channel]->z_nline > -1) /* count this line */
  11058. z_file[channel]->z_nline++;
  11059. } else {
  11060. z_file[channel]->z_nline = -1; /* Current line no longer known */
  11061. }
  11062. }
  11063. z_error = 0;
  11064. return(x);
  11065. }
  11066. #define Z_INBUFLEN 64
  11067. /*
  11068. Z _ I N -- Multichannel i/o file input function.
  11069. Call with:
  11070. channel number to read from.
  11071. s = address of destination buffer.
  11072. buflen = destination buffer length.
  11073. length = Number of bytes to read, must be < buflen.
  11074. flags: 0 = read a line; nonzero = read the given number of bytes.
  11075. Returns:
  11076. Number of bytes read into buffer or a negative error code.
  11077. A terminating NUL is deposited after the last byte that was read.
  11078. */
  11079. int
  11080. z_in(channel,s,buflen,length,flags)
  11081. int channel, buflen, length, flags; char * s;
  11082. /* z_in */ {
  11083. int i, j, x;
  11084. FILE * t;
  11085. char * p;
  11086. if (!z_inited) /* Check everything... */
  11087. return(z_error = FX_NOP);
  11088. if (channel >= z_maxchan)
  11089. return(z_error = FX_CHN);
  11090. if (!z_file[channel])
  11091. return(z_error = FX_NOP);
  11092. if (!(t = z_file[channel]->z_fp))
  11093. return(z_error = FX_NOP);
  11094. if (!((z_file[channel]->z_flags) & FM_REA))
  11095. return(z_error = FX_FOP);
  11096. if (!s) /* Check destination */
  11097. return(z_error = FX_RNG);
  11098. s[0] = NUL;
  11099. if (length == 0) /* Read 0 bytes - easy. */
  11100. return(z_error = 0);
  11101. debug(F101,"z_in channel","",channel);
  11102. debug(F101,"z_in buflen","",buflen);
  11103. debug(F101,"z_in length","",length);
  11104. debug(F101,"z_in flags","",flags);
  11105. if (length < 0 || buflen < 0) /* Check length args */
  11106. return(z_error = FX_RNG);
  11107. if (buflen <= length)
  11108. return(z_error = FX_RNG);
  11109. errno = 0; /* Reset errno */
  11110. if (flags) { /* Read block or byte */
  11111. int n; /* 20050912 */
  11112. n = length; /* 20050912 */
  11113. i = 0; /* 20050912 */
  11114. while (n > 0) { /* 20050912 */
  11115. i = fread(s,1,n,t); /* 20050912 */
  11116. #ifdef DEBUG
  11117. if (deblog) {
  11118. debug(F111,"z_in block",s,i);
  11119. debug(F101,"z_in block errno","",errno);
  11120. debug(F101,"z_in block ferror","",ferror(t));
  11121. debug(F101,"z_in block feof","",feof(t));
  11122. }
  11123. #endif /* DEBUG */
  11124. if (i == 0) break; /* 20050912 */
  11125. s += i; /* 20050912 */
  11126. n -= i; /* 20050912 */
  11127. }
  11128. /* Current line no longer known */
  11129. z_file[channel]->z_nline = (CK_OFF_T)-1;
  11130. } else { /* Read line */
  11131. #ifndef COMMENT
  11132. /* This method is used because it's simpler than the others */
  11133. /* and also marginally faster. */
  11134. debug(F101,"z_in getc loop","",CKFTELL(t));
  11135. for (i = 0; i < length; i++) {
  11136. if ((x = getc(t)) == EOF) {
  11137. debug(F101,"z_in getc error","",CKFTELL(t));
  11138. s[i] = '\0';
  11139. break;
  11140. }
  11141. s[i] = x;
  11142. if (s[i] == '\n') {
  11143. s[i] = '\0';
  11144. break;
  11145. }
  11146. }
  11147. debug(F111,"z_in line byte loop",ckitoa(errno),i);
  11148. debug(F111,"z_in line got",s,z_file[channel]->z_nline);
  11149. if (z_file[channel]->z_nline > -1)
  11150. z_file[channel]->z_nline++;
  11151. #else
  11152. #ifdef COMMENT2
  11153. /* Straightforward but strlen() slows it down. */
  11154. s[0] = '\0';
  11155. i = 0;
  11156. if (fgets(s,length,t)) {
  11157. i = strlen(s);
  11158. if (i > 0 && s[i-1] == '\n') i--;
  11159. }
  11160. debug(F111,"z_in line fgets",ckitoa(errno),i);
  11161. if (z_file[channel]->z_nline > -1)
  11162. z_file[channel]->z_nline++;
  11163. #else
  11164. /* This is a do-it-yourself fgets() with its own readahead and */
  11165. /* putback. It's a bit faster than real fgets() but not enough */
  11166. /* to justify the added complexity or the risk of the ftell() and */
  11167. /* fseek() calls failing. */
  11168. int k, flag = 0;
  11169. CK_OFF_T pos;
  11170. for (i = 0; !flag && i <= (length - Z_INBUFLEN); i += Z_INBUFLEN) {
  11171. k = ((length - i) < Z_INBUFLEN) ? length - i : Z_INBUFLEN;
  11172. if ((x = fread(s+i,1,k,t)) < 1)
  11173. break;
  11174. s[i+x] = '\0';
  11175. for (j = 0; j < x; j++) {
  11176. if (s[i+j] == '\n') {
  11177. s[i+j] = '\0';
  11178. flag ++;
  11179. pos = CKFTELL(t);
  11180. if (pos > -1) {
  11181. pos -= (x - j - 1);
  11182. x = CKFSEEK(t, pos, 0);
  11183. i += j;
  11184. break;
  11185. } else
  11186. return(z_error = FX_SYS);
  11187. }
  11188. }
  11189. }
  11190. if (z_file[channel]->z_nline > -1)
  11191. z_file[channel]->z_nline++;
  11192. debug(F111,"z_in line chunk loop",ckitoa(errno),i);
  11193. #endif /* COMMENT2 */
  11194. #endif /* COMMENT */
  11195. }
  11196. debug(F111,"z_in i",ckitoa(errno),i);
  11197. if (i < 0) i = 0; /* NUL-terminate result */
  11198. s[i] = '\0';
  11199. if (i > 0) {
  11200. z_error = 0;
  11201. return(i);
  11202. }
  11203. if (i == 0 && feof(t)) /* EOF on reading? */
  11204. return(z_error = FX_EOF); /* Return EOF code */
  11205. return(errno ? (z_error = -1) : i); /* Return length or system error */
  11206. }
  11207. int
  11208. z_flush(channel) int channel; { /* Flush output channel */
  11209. FILE * t;
  11210. int x;
  11211. if (!z_inited) /* Regular checks */
  11212. return(z_error = FX_NOP);
  11213. if (channel >= z_maxchan)
  11214. return(z_error = FX_CHN);
  11215. if (!z_file[channel])
  11216. return(z_error = FX_NOP);
  11217. if (!(t = z_file[channel]->z_fp))
  11218. return(z_error = FX_NOP);
  11219. if (!((z_file[channel]->z_flags) & (FM_WRI|FM_APP))) /* Write access? */
  11220. return(z_error = FX_FOP);
  11221. errno = 0; /* Reset errno */
  11222. x = fflush(t); /* Try to flush */
  11223. return(x ? (z_error = FX_SYS) : 0); /* Return system error or 0 if OK */
  11224. }
  11225. int
  11226. #ifdef CK_ANSIC
  11227. z_seek(int channel, CK_OFF_T pos) /* Move file pointer to byte */
  11228. #else
  11229. z_seek(channel,pos) int channel; CK_OFF_T pos; /* (seek to given position) */
  11230. #endif /* CK_ANSIC */
  11231. {
  11232. int i, x = 0, rc;
  11233. FILE * t;
  11234. if (!z_inited) /* Check... */
  11235. return(z_error = FX_NOP);
  11236. if (channel >= z_maxchan)
  11237. return(z_error = FX_CHN);
  11238. if (!z_file[channel])
  11239. return(z_error = FX_NOP);
  11240. if (!(t = z_file[channel]->z_fp))
  11241. return(z_error = FX_NOP);
  11242. if (pos < 0L) {
  11243. x = 2;
  11244. pos = (pos == -2) ? -1L : 0L;
  11245. }
  11246. errno = 0;
  11247. rc = CKFSEEK(t,pos,x); /* Try to seek */
  11248. debug(F111,"z_seek",ckitoa(errno),rc);
  11249. if (rc < 0) /* OK? */
  11250. return(z_error = FX_SYS); /* No. */
  11251. z_file[channel]->z_nline = ((pos || x) ? -1 : 0);
  11252. return(z_error = 0);
  11253. }
  11254. int
  11255. #ifdef CK_ANSIC
  11256. z_line(int channel, CK_OFF_T pos) /* Move file pointer to line */
  11257. #else
  11258. z_line(channel,pos) int channel; CK_OFF_T pos; /* (seek to given position) */
  11259. #endif /* CK_ANSIC */
  11260. {
  11261. int i, len, x = 0;
  11262. CK_OFF_T current = (CK_OFF_T)0, prev = (CK_OFF_T)-1, old = (CK_OFF_T)-1;
  11263. FILE * t;
  11264. char tmpbuf[256];
  11265. if (!z_inited) /* Check... */
  11266. return(z_error = FX_NOP);
  11267. if (channel >= z_maxchan)
  11268. return(z_error = FX_CHN);
  11269. if (!z_file[channel])
  11270. return(z_error = FX_NOP);
  11271. if (!(t = z_file[channel]->z_fp))
  11272. return(z_error = FX_NOP);
  11273. debug(F101,"z_line pos","",pos);
  11274. if (pos < 0L) { /* EOF wanted */
  11275. CK_OFF_T n;
  11276. n = z_file[channel]->z_nline;
  11277. debug(F101,"z_line n","",n);
  11278. if (n < 0 || pos < 0) {
  11279. rewind(t);
  11280. n = 0;
  11281. }
  11282. while (1) { /* This could take a while... */
  11283. if ((x = getc(t)) == EOF)
  11284. break;
  11285. if (x == '\n') {
  11286. n++;
  11287. if (pos == -2) {
  11288. old = prev;
  11289. prev = CKFTELL(t);
  11290. }
  11291. }
  11292. }
  11293. debug(F101,"z_line old","",old);
  11294. debug(F101,"z_line prev","",prev);
  11295. if (pos == -2) {
  11296. if ((x = z_seek(channel,old)) < 0)
  11297. return(z_error = x);
  11298. else
  11299. n--;
  11300. }
  11301. z_file[channel]->z_nline = n;
  11302. return(z_error = 0);
  11303. }
  11304. if (pos == 0L) { /* Rewind wanted */
  11305. z_file[channel]->z_nline = 0L;
  11306. rewind(t);
  11307. debug(F100,"z_line rewind","",0);
  11308. return(0L);
  11309. }
  11310. tmpbuf[255] = NUL; /* Make sure buf is NUL terminated */
  11311. current = z_file[channel]->z_nline; /* Current line */
  11312. /*
  11313. If necessary the following could be optimized, e.g. for positioning
  11314. to a previous line in a large file without starting over.
  11315. */
  11316. if (current < 0 || pos < current) { /* Not known or behind us... */
  11317. debug(F101,"z_line rewinding","",pos);
  11318. if ((x = z_seek(channel, 0L)) < 0) /* Rewind */
  11319. return(z_error = x);
  11320. if (pos == 0) /* If 0th line wanted we're done */
  11321. return(z_error = 0);
  11322. current = 0;
  11323. }
  11324. while (current < pos) { /* Search for specified line */
  11325. if (fgets(tmpbuf,255,t)) {
  11326. len = strlen(tmpbuf);
  11327. if (len > 0 && tmpbuf[len-1] == '\n') {
  11328. current++;
  11329. debug(F111,"z_line read",ckitoa(len),current);
  11330. } else if (len == 0) {
  11331. return(z_error = FX_UNK);
  11332. }
  11333. } else {
  11334. z_file[channel]->z_nline = -1L;
  11335. debug(F101,"z_line premature EOF","",current);
  11336. return(z_error = FX_EOF);
  11337. }
  11338. }
  11339. z_file[channel]->z_nline = current;
  11340. debug(F101,"z_line result","",current);
  11341. z_error = 0;
  11342. return(current);
  11343. }
  11344. char *
  11345. z_getname(channel) int channel; { /* Return name of file on channel */
  11346. FILE * t;
  11347. if (!z_inited) {
  11348. z_error = FX_NOP;
  11349. return(NULL);
  11350. }
  11351. if (channel >= z_maxchan) {
  11352. z_error = FX_CHN;
  11353. return(NULL);
  11354. }
  11355. if (!z_file[channel]) {
  11356. z_error = FX_NOP;
  11357. return(NULL);
  11358. }
  11359. if (!(t = z_file[channel]->z_fp)) {
  11360. z_error = FX_NOP;
  11361. return(NULL);
  11362. }
  11363. return((char *)(z_file[channel]->z_name));
  11364. }
  11365. int
  11366. z_getmode(channel) int channel; { /* Return OPEN modes of channel */
  11367. FILE * t; /* 0 if file not open */
  11368. #ifndef NOSTAT
  11369. #ifdef NT
  11370. struct _stat statbuf;
  11371. #else /* NT */
  11372. struct stat statbuf;
  11373. #endif /* NT */
  11374. #endif /* NOSTAT */
  11375. int x;
  11376. if (!z_inited)
  11377. return(0);
  11378. if (channel >= z_maxchan)
  11379. return(z_error = FX_CHN);
  11380. if (!z_file[channel])
  11381. return(0);
  11382. if (!(t = z_file[channel]->z_fp))
  11383. return(0);
  11384. x = z_file[channel]->z_flags;
  11385. if (feof(t)) { /* This might not work for */
  11386. x |= FM_EOF; /* output files */
  11387. #ifndef NOSTAT
  11388. /* But this does if we can use it. */
  11389. } else if (stat(z_file[channel]->z_name,&statbuf) > -1) {
  11390. if (CKFTELL(t) == statbuf.st_size)
  11391. x |= FM_EOF;
  11392. #endif /* NOSTAT */
  11393. }
  11394. return(x);
  11395. }
  11396. CK_OFF_T
  11397. z_getpos(channel) int channel; { /* Get file pointer position */
  11398. FILE * t; /* on this channel */
  11399. CK_OFF_T x;
  11400. if (!z_inited)
  11401. return(z_error = FX_NOP);
  11402. if (channel >= z_maxchan)
  11403. return(z_error = FX_CHN);
  11404. if (!z_file[channel])
  11405. return(z_error = FX_NOP);
  11406. if (!(t = z_file[channel]->z_fp))
  11407. return(z_error = FX_NOP);
  11408. x = CKFTELL(t);
  11409. return((x < 0L) ? (z_error = FX_SYS) : x);
  11410. }
  11411. CK_OFF_T
  11412. z_getline(channel) int channel; { /* Get current line number */
  11413. FILE * t; /* in file on this channel */
  11414. CK_OFF_T rc;
  11415. if (!z_inited)
  11416. return(z_error = FX_NOP);
  11417. if (channel >= z_maxchan)
  11418. return(z_error = FX_CHN);
  11419. if (!z_file[channel])
  11420. return(z_error = FX_NOP);
  11421. if (!(t = z_file[channel]->z_fp))
  11422. return(z_error = FX_NOP);
  11423. debug(F101,"z_getline","",z_file[channel]->z_nline);
  11424. rc = z_file[channel]->z_nline;
  11425. return((rc < 0) ? (z_error = FX_LNU) : rc);
  11426. }
  11427. int
  11428. z_getfnum(channel) int channel; { /* Get file number / handle */
  11429. FILE * t; /* for file on this channel */
  11430. if (!z_inited)
  11431. return(z_error = FX_NOP);
  11432. if (channel >= z_maxchan)
  11433. return(z_error = FX_CHN);
  11434. if (!z_file[channel])
  11435. return(z_error = FX_NOP);
  11436. if (!(t = z_file[channel]->z_fp))
  11437. return(z_error = FX_NOP);
  11438. z_error = 0;
  11439. return(fileno(t));
  11440. }
  11441. /*
  11442. Line-oriented counts and seeks are as dumb as they can be at the moment.
  11443. Later we can speed them up by building little indexes.
  11444. */
  11445. CK_OFF_T
  11446. z_count(channel, what) int channel, what; { /* Count bytes or lines in file */
  11447. FILE * t;
  11448. int i, x;
  11449. CK_OFF_T pos, count = (CK_OFF_T)0;
  11450. if (!z_inited) /* Check stuff... */
  11451. return(z_error = FX_NOP);
  11452. if (channel >= z_maxchan)
  11453. return(z_error = FX_CHN);
  11454. if (!z_file[channel])
  11455. return(z_error = FX_NOP);
  11456. if (!(t = z_file[channel]->z_fp))
  11457. return(z_error = FX_NOP);
  11458. pos = CKFTELL(t); /* Save current file pointer */
  11459. errno = 0;
  11460. z_error = 0;
  11461. if (what == RD_CHAR) { /* Size in bytes requested */
  11462. #ifdef COMMENT
  11463. if (!CKFSEEK(t,0L,2)) { /* Seek to end */
  11464. count = CKFTELL(t); /* Get file pointer */
  11465. CKFSEEK(t,pos,0); /* Restore file file pointer */
  11466. return(count);
  11467. } else /* Fallback in case seek fails */
  11468. #endif /* COMMENT */
  11469. return(zgetfs(z_file[channel]->z_name));
  11470. }
  11471. rewind(t); /* Line count requested - rewind. */
  11472. while (1) { /* Count lines. */
  11473. if ((x = getc(t)) == EOF) /* Stupid byte loop */
  11474. break; /* but it works as well as anything */
  11475. if (x == '\n') /* else... */
  11476. count++;
  11477. }
  11478. x = CKFSEEK(t,pos,0); /* Restore file pointer */
  11479. return(count);
  11480. }
  11481. /* User interface for generalized channel-oriented file i/o */
  11482. struct keytab fctab[] = { /* FILE subcommands */
  11483. { "close", FIL_CLS, 0 },
  11484. { "count", FIL_COU, 0 },
  11485. { "flush", FIL_FLU, 0 },
  11486. { "list", FIL_LIS, 0 },
  11487. { "open", FIL_OPN, 0 },
  11488. { "read", FIL_REA, 0 },
  11489. { "rewind", FIL_REW, 0 },
  11490. { "seek", FIL_SEE, 0 },
  11491. { "status", FIL_STA, 0 },
  11492. { "write", FIL_WRI, 0 }
  11493. };
  11494. int nfctab = (sizeof (fctab) / sizeof (struct keytab));
  11495. static struct keytab fcswtab[] = { /* OPEN modes */
  11496. { "/append", FM_APP, 0 },
  11497. { "/binary", FM_BIN, 0 },
  11498. #ifdef COMMENT
  11499. { "/command", FM_CMD, 0 }, /* Not implemented */
  11500. #endif /* COMMENT */
  11501. { "/read", FM_REA, 0 },
  11502. #ifdef UNIX /* Could be expanded to VMS etc.. */
  11503. { "/stderr", FM_STDERR,0 },
  11504. { "/stdin", FM_STDIN,0 },
  11505. { "/stdout", FM_STDOUT,0 },
  11506. #endif /* UNIX */
  11507. { "/write", FM_WRI, 0 }
  11508. };
  11509. static int nfcswtab = (sizeof (fcswtab) / sizeof (struct keytab));
  11510. static struct keytab fclkwtab[] = { /* CLOSE options */
  11511. { "all", 1, 0 }
  11512. };
  11513. static struct keytab fsekwtab[] = { /* SEEK symbols */
  11514. { "eof", 1, 0 },
  11515. { "last", 2, 0 }
  11516. };
  11517. static int nfsekwtab = (sizeof (fsekwtab) / sizeof (struct keytab));
  11518. #define SEE_LINE RD_LINE /* SEEK options */
  11519. #define SEE_CHAR RD_CHAR
  11520. #define SEE_REL 3
  11521. #define SEE_ABS 4
  11522. #define SEE_FIND 5
  11523. static struct keytab fskswtab[] = {
  11524. { "/absolute", SEE_ABS, 0 },
  11525. { "/byte", SEE_CHAR, 0 },
  11526. { "/character", SEE_CHAR, CM_INV },
  11527. { "/find", SEE_FIND, CM_ARG },
  11528. { "/line", SEE_LINE, 0 },
  11529. { "/relative", SEE_REL, 0 }
  11530. };
  11531. static int nfskswtab = (sizeof (fskswtab) / sizeof (struct keytab));
  11532. #define COU_LINE RD_LINE /* COUNT options */
  11533. #define COU_CHAR RD_CHAR
  11534. #define COU_LIS 3
  11535. #define COU_NOL 4
  11536. static struct keytab fcoswtab[] = {
  11537. { "/bytes", COU_CHAR, 0 },
  11538. { "/characters",COU_CHAR, CM_INV },
  11539. { "/lines", COU_LINE, 0 },
  11540. { "/list", COU_LIS, 0 },
  11541. { "/nolist", COU_NOL, 0 },
  11542. { "/quiet", COU_NOL, CM_INV }
  11543. };
  11544. static int nfcoswtab = (sizeof (fcoswtab) / sizeof (struct keytab));
  11545. static struct keytab frdtab[] = { /* READ types */
  11546. { "/block", RD_SIZE, CM_INV|CM_ARG },
  11547. { "/byte", RD_CHAR, CM_INV },
  11548. { "/character", RD_CHAR, 0 },
  11549. { "/line", RD_LINE, 0 },
  11550. { "/size", RD_SIZE, CM_ARG },
  11551. { "/trim", RD_TRIM, 0 },
  11552. { "/untabify", RD_UNTA, 0 }
  11553. };
  11554. static int nfrdtab = (sizeof (frdtab) / sizeof (struct keytab));
  11555. static struct keytab fwrtab[] = { /* WRITE types */
  11556. { "/block", WR_SIZE, CM_INV|CM_ARG },
  11557. { "/byte", WR_CHAR, CM_INV },
  11558. { "/character", WR_CHAR, 0 },
  11559. { "/line", WR_LINE, 0 },
  11560. { "/lpad", WR_LPAD, CM_ARG },
  11561. { "/rpad", WR_RPAD, CM_ARG },
  11562. { "/size", WR_SIZE, CM_ARG },
  11563. { "/string", WR_STRI, 0 }
  11564. };
  11565. static int nfwrtab = (sizeof (fwrtab) / sizeof (struct keytab));
  11566. static char blanks[] = "\040\040\040\040"; /* Some blanks for formatting */
  11567. static char * seek_target = NULL;
  11568. int
  11569. dofile(op) int op; { /* Do the FILE command */
  11570. char vnambuf[VNAML]; /* Buffer for variable names */
  11571. char *vnp = NULL; /* Pointer to same */
  11572. char zfilnam[CKMAXPATH+2];
  11573. char * p, * m;
  11574. struct FDB fl, sw, nu;
  11575. CK_OFF_T z;
  11576. int rsize, filmode = 0, relative = -1, eofflg = 0;
  11577. int rc, x, y, cx, n, getval, dummy, confirmed, listing = -1;
  11578. int charflag = 0, sizeflag = 0;
  11579. int pad = 32, wr_lpad = 0, wr_rpad = 0, rd_trim = 0, rd_untab = 0;
  11580. makestr(&seek_target,NULL);
  11581. if (op == XXFILE) { /* FILE command was given */
  11582. /* Get subcommand */
  11583. if ((cx = cmkey(fctab,nfctab,"Operation","",xxstring)) < 0) {
  11584. if (cx == -3) {
  11585. printf("?File operation required\n");
  11586. x = -9;
  11587. }
  11588. return(cx);
  11589. }
  11590. } else { /* Shorthand command was given */
  11591. switch (op) {
  11592. case XXF_CL: cx = FIL_CLS; break; /* FCLOSE */
  11593. case XXF_FL: cx = FIL_FLU; break; /* FFLUSH */
  11594. case XXF_LI: cx = FIL_LIS; break; /* FLIST */
  11595. case XXF_OP: cx = FIL_OPN; break; /* etc... */
  11596. case XXF_RE: cx = FIL_REA; break;
  11597. case XXF_RW: cx = FIL_REW; break;
  11598. case XXF_SE: cx = FIL_SEE; break;
  11599. case XXF_ST: cx = FIL_STA; break;
  11600. case XXF_WR: cx = FIL_WRI; break;
  11601. case XXF_CO: cx = FIL_COU; break;
  11602. default: return(-2);
  11603. }
  11604. }
  11605. switch (cx) { /* Do requested subcommand */
  11606. case FIL_OPN: /* OPEN */
  11607. cmfdbi(&sw, /* Switches */
  11608. _CMKEY, /* fcode */
  11609. "Variable or switch", /* hlpmsg */
  11610. "", /* default */
  11611. "", /* addtl string data */
  11612. nfcswtab, /* addtl numeric data 1: tbl size */
  11613. 4, /* addtl numeric data 2: 4 = cmswi */
  11614. xxstring, /* Processing function */
  11615. fcswtab, /* Keyword table */
  11616. &fl /* Pointer to next FDB */
  11617. );
  11618. cmfdbi(&fl, /* Anything that doesn't match */
  11619. _CMFLD, /* fcode */
  11620. "Variable", /* hlpmsg */
  11621. "",
  11622. "",
  11623. 0,
  11624. 0,
  11625. NULL,
  11626. NULL,
  11627. NULL
  11628. );
  11629. while (1) {
  11630. x = cmfdb(&sw); /* Parse something */
  11631. if (x < 0) {
  11632. if (x == -3) {
  11633. printf("?Variable name and file name required\n");
  11634. x = -9;
  11635. }
  11636. return(x);
  11637. }
  11638. if (cmresult.fcode == _CMFLD)
  11639. break;
  11640. else if (cmresult.fcode == _CMKEY) {
  11641. char c;
  11642. c = cmgbrk();
  11643. if ((getval =
  11644. (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11645. printf("?This switch does not take an argument\n");
  11646. return(-9);
  11647. }
  11648. #ifdef COMMENT
  11649. /* Uncomment if we add any FOPEN switches that take args */
  11650. if (!getval && (cmgkwflgs() & CM_ARG)) {
  11651. printf("?This switch requires an argument\n");
  11652. return(-9); /* (none do...) */
  11653. }
  11654. #endif /* COMMENT */
  11655. debug(F101,"filmode A","",filmode);
  11656. filmode |= cmresult.nresult; /* OR in the file mode */
  11657. debug(F101,"filmode B","",filmode);
  11658. debug(F101,"filmode & (FM_REA|FM_STDIN)","",
  11659. filmode & (FM_REA|FM_STDIN));
  11660. debug(F101,"filmode & (FM_WRI|FM_STDOUT|FM_STDERR)","",
  11661. filmode & (FM_WRI|FM_STDOUT|FM_STDERR));
  11662. if ((filmode & (FM_REA|FM_STDIN)) &&
  11663. (filmode & (FM_WRI|FM_STDOUT|FM_STDERR))) {
  11664. printf("?Conflicting file modes\n");
  11665. return(-9);
  11666. }
  11667. } else
  11668. return(-2);
  11669. }
  11670. /* Not a switch - get the string */
  11671. ckstrncpy(vnambuf,cmresult.sresult,VNAML);
  11672. if (!vnambuf[0] || chknum(vnambuf)) { /* (if there is one...) */
  11673. printf("?Variable name required\n");
  11674. return(-9);
  11675. }
  11676. vnp = vnambuf; /* Check variable-name syntax */
  11677. if (vnambuf[0] == CMDQ &&
  11678. (vnambuf[1] == '%' || vnambuf[1] == '&'))
  11679. vnp++;
  11680. y = 0;
  11681. if (*vnp == '%' || *vnp == '&') {
  11682. if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  11683. printf("?Syntax error in variable name\n");
  11684. return(-9);
  11685. }
  11686. }
  11687. /* Assign a negative channel number in case we fail */
  11688. addmac(vnambuf,"-1");
  11689. if (!(filmode & FM_RWA)) /* If no access mode specified */
  11690. filmode |= FM_REA; /* default to /READ. */
  11691. #ifdef UNIX
  11692. if (filmode & FM_STDIN) { /* If STDIN specified */
  11693. filmode |= FM_REA; /* it implies /READ */
  11694. /* We don't need to parse anything further */
  11695. s = "(stdin)";
  11696. goto xdofile; /* Skip around the following */
  11697. }
  11698. if (filmode & FM_STDOUT) { /* If STDIN specified */
  11699. filmode |= FM_WRI; /* it implies /WRITE */
  11700. /* We don't need to parse anything further */
  11701. s = "(stdout)";
  11702. goto xdofile; /* Skip around the following */
  11703. }
  11704. if (filmode & FM_STDIN) { /* If STDIN specified */
  11705. filmode |= FM_WRI; /* it implies /WRITE */
  11706. /* We don't need to parse anything further */
  11707. s = "(stderr)";
  11708. goto xdofile; /* Skip around the following */
  11709. }
  11710. #endif /* UNIX */
  11711. y = 0; /* Now parse the filename */
  11712. if ((filmode & FM_RWA) == FM_WRI) {
  11713. x = cmofi("Name of new file","",&s,xxstring);
  11714. } else if ((filmode & FM_RWA) == FM_REA) {
  11715. x = cmifi("Name of existing file","",&s,&y,xxstring);
  11716. } else {
  11717. x = cmiofi("Filename","",&s,&y,xxstring);
  11718. debug(F111,"fopen /append x",s,x);
  11719. }
  11720. if (x < 0) {
  11721. if (x == -3) {
  11722. printf("?Filename required\n");
  11723. x = -9;
  11724. }
  11725. return(x);
  11726. }
  11727. if (y) { /* No wildcards */
  11728. printf("?Wildcards not allowed here\n");
  11729. return(-9);
  11730. }
  11731. if (filmode & (FM_APP|FM_WRI)) { /* Check output access */
  11732. #ifndef VMS
  11733. if (zchko(s) < 0) { /* and set error code if denied */
  11734. z_error = FX_ACC;
  11735. printf("?Write access denied - \"%s\"\n",s);
  11736. return(-9);
  11737. }
  11738. #endif /* VMS */
  11739. }
  11740. xdofile:
  11741. ckstrncpy(zfilnam,s,CKMAXPATH); /* Is OK - make safe copy */
  11742. if ((x = cmcfm()) < 0) /* Get confirmation of command */
  11743. return(x);
  11744. if ((n = z_open(zfilnam,filmode)) < 0) {
  11745. printf("?OPEN failed - %s: %s\n",zfilnam,ckferror(n));
  11746. return(-9);
  11747. }
  11748. addmac(vnambuf,ckitoa(n)); /* Assign channel number to variable */
  11749. return(success = 1);
  11750. case FIL_REW: /* REWIND */
  11751. if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  11752. if (x == -3) {
  11753. printf("?Channel number required\n");
  11754. x = -9;
  11755. }
  11756. return(x);
  11757. }
  11758. if ((x = cmcfm()) < 0)
  11759. return(x);
  11760. if (n == -9) return(success = 0);
  11761. if (n == -8) return(success = 1);
  11762. if ((rc = z_seek(n,0L)) < 0) {
  11763. printf("?REWIND failed - Channel %d: %s\n",n,ckferror(rc));
  11764. return(-9);
  11765. }
  11766. return(success = 1);
  11767. case FIL_CLS: /* CLOSE */
  11768. #ifdef COMMENT /* fdc 20100804 - bad idea */
  11769. {
  11770. int i, j, k; /* Supply default if only one open */
  11771. s = "";
  11772. for (k = 0, j = 0, i = 0; i < z_maxchan; i++) {
  11773. if (z_file)
  11774. if (z_file[i])
  11775. if (z_file[i]->z_fp) { k++; j = i; }
  11776. }
  11777. if (k == 1) s = ckitoa(j);
  11778. }
  11779. #endif /* COMMENT */
  11780. cmfdbi(&nu, /* Second FDB - channel number */
  11781. _CMNUM, /* fcode */
  11782. "Channel number or ALL", /* Help message */
  11783. s, /* default */
  11784. "", /* addtl string data */
  11785. 10, /* addtl numeric data 1: radix */
  11786. 0, /* addtl numeric data 2: 0 */
  11787. xxstring, /* Processing function */
  11788. NULL, /* Keyword table */
  11789. &sw /* Pointer to next FDB */
  11790. ); /* Pointer to next FDB */
  11791. cmfdbi(&sw, /* First FDB - command switches */
  11792. _CMKEY, /* fcode */
  11793. "", /* help message */
  11794. "", /* Default */
  11795. "", /* No addtl string data */
  11796. 1, /* addtl numeric data 1: tbl size */
  11797. 0, /* addtl numeric data 2: 4 = cmswi */
  11798. xxstring, /* Processing function */
  11799. fclkwtab, /* Keyword table */
  11800. NULL /* Last in chain */
  11801. );
  11802. x = cmfdb(&nu); /* Parse something */
  11803. if (x < 0) {
  11804. if (x == -3) {
  11805. printf("?Channel number or ALL required\n");
  11806. x = -9;
  11807. }
  11808. return(x);
  11809. }
  11810. if (cmresult.fcode == _CMNUM)
  11811. n = cmresult.nresult;
  11812. else if (cmresult.fcode == _CMKEY)
  11813. n = -1;
  11814. if ((x = cmcfm()) < 0)
  11815. return(x);
  11816. if (n == -9) return(success = 0);
  11817. if (n == -8) return(success = 1);
  11818. rc = 1;
  11819. if (n < 0) {
  11820. int count = 0;
  11821. int i;
  11822. for (i = 0; i < z_maxchan; i++) {
  11823. x = z_close(i);
  11824. if (x == FX_SYS) {
  11825. printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11826. rc = 0;
  11827. } else if (x > -1)
  11828. count++;
  11829. }
  11830. debug(F101,"FILE CLOSE ALL","",count);
  11831. } else if ((x = z_close(n)) < 0) {
  11832. printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11833. return(-9);
  11834. }
  11835. return(success = rc);
  11836. case FIL_REA: /* READ */
  11837. case FIL_WRI: /* WRITE */
  11838. rsize = 0;
  11839. cmfdbi(&sw, /* Switches */
  11840. _CMKEY, /* fcode */
  11841. "Channel or switch", /* hlpmsg */
  11842. "", /* default */
  11843. "", /* addtl string data */
  11844. (cx == FIL_REA) ? nfrdtab : nfwrtab,
  11845. 4, /* addtl numeric data 2: 4 = cmswi */
  11846. xxstring, /* Processing function */
  11847. (cx == FIL_REA) ? frdtab : fwrtab, /* Keyword table */
  11848. &nu /* Pointer to next FDB */
  11849. );
  11850. cmfdbi(&nu, /* Channel number */
  11851. _CMNUM, /* fcode */
  11852. "Channel",
  11853. "", /* default */
  11854. "", /* addtl string data */
  11855. 10, /* addtl numeric data 1: radix */
  11856. 0, /* addtl numeric data 2: 0 */
  11857. xxstring, /* Processing function */
  11858. NULL, /* Keyword table */
  11859. NULL /* Pointer to next FDB */
  11860. );
  11861. do {
  11862. x = cmfdb(&sw); /* Parse something */
  11863. if (x < 0) {
  11864. if (x == -3) {
  11865. printf("?Channel number required\n");
  11866. x = -9;
  11867. }
  11868. return(x);
  11869. }
  11870. if (cmresult.fcode == _CMNUM) /* Channel number */
  11871. break;
  11872. else if (cmresult.fcode == _CMKEY) { /* Switch */
  11873. char c;
  11874. c = cmgbrk();
  11875. if ((getval =
  11876. (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11877. printf("?This switch does not take an argument\n");
  11878. return(-9);
  11879. }
  11880. if (!getval && (cmgkwflgs() & CM_ARG)) {
  11881. printf("?This switch requires an argument\n");
  11882. return(-9);
  11883. }
  11884. switch (cmresult.nresult) {
  11885. case WR_LINE:
  11886. charflag = 0;
  11887. sizeflag = 0;
  11888. rsize = 0;
  11889. break;
  11890. case WR_CHAR:
  11891. rsize = 1;
  11892. charflag = 1;
  11893. sizeflag = 1;
  11894. break;
  11895. case WR_SIZE:
  11896. if ((x = cmnum("Bytes","",10,&rsize, xxstring)) < 0) {
  11897. if (x == -3) {
  11898. printf("?Number required\n");
  11899. x = -9;
  11900. }
  11901. return(x);
  11902. }
  11903. if (rsize > LINBUFSIZ) {
  11904. printf("?Maximum FREAD/FWRITE size is %d\n",LINBUFSIZ);
  11905. rsize = 0;
  11906. return(-9);
  11907. }
  11908. charflag = 0;
  11909. sizeflag = 1;
  11910. break;
  11911. case WR_STRI:
  11912. rsize = 1;
  11913. charflag = 0;
  11914. sizeflag = 0;
  11915. break;
  11916. case WR_LPAD:
  11917. case WR_RPAD:
  11918. if ((x = cmnum("Numeric ASCII character value",
  11919. "32",10,&pad, xxstring)) < 0)
  11920. return(x);
  11921. if (cmresult.nresult == WR_LPAD)
  11922. wr_lpad = 1;
  11923. else
  11924. wr_rpad = 1;
  11925. break;
  11926. case RD_TRIM:
  11927. rd_trim = 1;
  11928. break;
  11929. case RD_UNTA:
  11930. rd_untab = 1;
  11931. break;
  11932. }
  11933. debug(F101,"FILE READ rsize 2","",rsize);
  11934. } else
  11935. return(-2);
  11936. } while
  11937. (cmresult.fcode == _CMKEY);
  11938. n = cmresult.nresult; /* Channel */
  11939. debug(F101,"FILE READ/WRITE channel","",n);
  11940. if (cx == FIL_WRI) { /* WRITE */
  11941. int len = 0;
  11942. if ((x = cmtxt("Text","",&s,xxstring)) < 0)
  11943. return(x);
  11944. if (n == -9) return(success = 0);
  11945. if (n == -8) return(success = 1);
  11946. ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy */
  11947. s = line;
  11948. s = brstrip(s); /* Strip braces */
  11949. if (charflag) { /* Write one char */
  11950. len = 1; /* So length = 1 */
  11951. rsize = 1; /* Don't supply terminator */
  11952. } else if (!sizeflag) { /* Write a string */
  11953. len = -1; /* So length is unspecified */
  11954. } else { /* Write a block of given size */
  11955. int i, k, xx;
  11956. if (rsize > TMPBUFSIZ) {
  11957. z_error = FX_OFL;
  11958. printf("?Buffer overflow\n");
  11959. return(-9);
  11960. }
  11961. len = rsize; /* rsize is really length */
  11962. rsize = 1; /* Don't supply a terminator */
  11963. xx = strlen(s); /* Size of given string */
  11964. if (xx >= len) { /* Bigger or equal */
  11965. s[len] = NUL;
  11966. } else if (wr_lpad) { /* Smaller, left-padding requested */
  11967. for (i = 0; i < len - xx; i++) /* Must make a copy */
  11968. tmpbuf[i] = pad;
  11969. ckstrncpy(tmpbuf+i,s,TMPBUFSIZ-i);
  11970. tmpbuf[len] = NUL;
  11971. s = tmpbuf; /* Redirect write source */
  11972. } else if (wr_rpad) { /* Smaller with right-padding */
  11973. for (i = xx; i < len; i++)
  11974. s[i] = pad;
  11975. s[len] = NUL;
  11976. }
  11977. }
  11978. if ((rc = z_out(n,s,len,rsize)) < 0) { /* Try to write */
  11979. printf("?Channel %d WRITE error: %s\n",n,ckferror(rc));
  11980. return(-9);
  11981. }
  11982. } else { /* FIL_REA READ */
  11983. confirmed = 0;
  11984. vnambuf[0] = NUL;
  11985. x = cmfld("Variable name","",&s,NULL);
  11986. debug(F111,"FILE READ cmfld",s,x);
  11987. if (x < 0) {
  11988. if (x == -3 || !*s) {
  11989. if ((x = cmcfm()) < 0)
  11990. return(x);
  11991. else
  11992. confirmed++;
  11993. } else
  11994. return(x);
  11995. }
  11996. ckstrncpy(vnambuf,s,VNAML);
  11997. debug(F111,"FILE READ vnambuf",vnambuf,confirmed);
  11998. if (vnambuf[0]) { /* Variable name given, check it */
  11999. if (!confirmed) {
  12000. x = cmcfm();
  12001. if (x < 0)
  12002. return(x);
  12003. else
  12004. confirmed++;
  12005. }
  12006. vnp = vnambuf;
  12007. if (vnambuf[0] == CMDQ &&
  12008. (vnambuf[1] == '%' || vnambuf[1] == '&'))
  12009. vnp++;
  12010. y = 0;
  12011. if (*vnp == '%' || *vnp == '&') {
  12012. if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  12013. printf("?Syntax error in variable name\n");
  12014. return(-9);
  12015. }
  12016. }
  12017. }
  12018. debug(F111,"FILE READ variable",vnambuf,confirmed);
  12019. if (!confirmed)
  12020. if ((x = cmcfm()) < 0)
  12021. return(x);
  12022. if (n == -9) return(success = 0);
  12023. if (n == -8) return(success = 1);
  12024. line[0] = NUL; /* Clear destination buffer */
  12025. #ifdef COMMENT
  12026. if (rsize >= LINBUFSIZ) /* Don't overrun it */
  12027. rsize = LINBUFSIZ - 1;
  12028. #endif /* COMMENT */
  12029. if (rsize == 0) { /* Read a line */
  12030. rc = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  12031. } else {
  12032. rc = z_in(n,line,LINBUFSIZ,rsize,1); /* Read a block */
  12033. }
  12034. if (rc < 0) { /* Error... */
  12035. debug(F101,"FILE READ error","",rc);
  12036. debug(F101,"FILE READ errno","",errno);
  12037. if (rc == FX_EOF) { /* EOF - fail but no error message */
  12038. return(success = 0);
  12039. } else { /* Other error - fail and print msg */
  12040. printf("?READ error: %s\n",ckferror(rc));
  12041. return(-9);
  12042. }
  12043. }
  12044. if (rsize == 0) { /* FREAD /LINE postprocessing */
  12045. if (rd_trim) { /* Trim */
  12046. int i, k;
  12047. k = strlen(line);
  12048. if (k > 0) {
  12049. for (i = k-1; i > 0; i--) {
  12050. if (line[i] == SP || line[i] == '\t')
  12051. line[i] = NUL;
  12052. else
  12053. break;
  12054. }
  12055. }
  12056. }
  12057. if (rd_untab) { /* Untabify */
  12058. if (untabify(line,tmpbuf,TMPBUFSIZ) > -1)
  12059. ckstrncpy(line,tmpbuf,LINBUFSIZ);
  12060. }
  12061. }
  12062. debug(F110,"FILE READ data",line,0);
  12063. if (vnambuf[0]) /* Read OK - If variable name given */
  12064. addmac(vnambuf,line); /* Assign result to variable */
  12065. else /* otherwise */
  12066. printf("%s\n",line); /* just print it */
  12067. }
  12068. return(success = 1);
  12069. case FIL_SEE: /* SEEK */
  12070. case FIL_COU: /* COUNT */
  12071. rsize = RD_CHAR; /* Defaults to /BYTE */
  12072. cmfdbi(&sw, /* Switches */
  12073. _CMKEY, /* fcode */
  12074. "Channel or switch", /* hlpmsg */
  12075. "", /* default */
  12076. "", /* addtl string data */
  12077. ((cx == FIL_SEE) ? nfskswtab : nfcoswtab),
  12078. 4, /* addtl numeric data 2: 4 = cmswi */
  12079. xxstring, /* Processing function */
  12080. ((cx == FIL_SEE) ? fskswtab : fcoswtab),
  12081. &nu /* Pointer to next FDB */
  12082. );
  12083. cmfdbi(&nu, /* Channel number */
  12084. _CMNUM, /* fcode */
  12085. "Channel",
  12086. "", /* default */
  12087. "", /* addtl string data */
  12088. 10, /* addtl numeric data 1: radix */
  12089. 0, /* addtl numeric data 2: 0 */
  12090. xxstring, /* Processing function */
  12091. NULL, /* Keyword table */
  12092. NULL /* Pointer to next FDB */
  12093. );
  12094. do {
  12095. x = cmfdb(&sw); /* Parse something */
  12096. if (x < 0) {
  12097. if (x == -3) {
  12098. printf("?Channel number required\n");
  12099. x = -9;
  12100. }
  12101. return(x);
  12102. }
  12103. if (cmresult.fcode == _CMNUM) /* Channel number */
  12104. break;
  12105. else if (cmresult.fcode == _CMKEY) { /* Switch */
  12106. char c;
  12107. c = cmgbrk();
  12108. if ((getval =
  12109. (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12110. printf("?This switch does not take an argument\n");
  12111. return(-9);
  12112. }
  12113. if (cx == FIL_SEE) {
  12114. switch (cmresult.nresult) {
  12115. case SEE_REL: relative = 1; break;
  12116. case SEE_ABS: relative = 0; break;
  12117. case SEE_FIND: {
  12118. if (getval) {
  12119. y = cmfld("string or pattern","",&s,xxstring);
  12120. if (y < 0)
  12121. return(y);
  12122. makestr(&seek_target,brstrip(s));
  12123. break;
  12124. }
  12125. }
  12126. default: rsize = cmresult.nresult;
  12127. }
  12128. } else if (cx == FIL_COU) {
  12129. switch (cmresult.nresult) {
  12130. case COU_LIS: listing = 1; break;
  12131. case COU_NOL: listing = 0; break;
  12132. default: rsize = cmresult.nresult;
  12133. }
  12134. }
  12135. }
  12136. } while
  12137. (cmresult.fcode == _CMKEY);
  12138. n = cmresult.nresult; /* Channel */
  12139. debug(F101,"FILE SEEK/COUNT channel","",n);
  12140. if (cx == FIL_COU) {
  12141. if ((x = cmcfm()) < 0)
  12142. return(x);
  12143. if (n == -9) return(success = 0);
  12144. if (n == -8) return(success = 1);
  12145. z_filcount = z_count(n,rsize);
  12146. if (z_filcount < 0) {
  12147. rc = z_filcount;
  12148. printf("?COUNT error: %s\n",ckferror(rc));
  12149. return(-9);
  12150. }
  12151. if (listing < 0)
  12152. listing = !xcmdsrc;
  12153. if (listing)
  12154. printf(" %ld %s%s\n",
  12155. z_filcount,
  12156. ((rsize == RD_CHAR) ? "byte" : "line"),
  12157. ((z_filcount == 1L) ? "" : "s")
  12158. );
  12159. return(success = (z_filcount > -1) ? 1 : 0);
  12160. }
  12161. m = (rsize == RD_CHAR) ?
  12162. "Number of bytes;\n or keyword" :
  12163. "Number of lines;\n or keyword";
  12164. cmfdbi(&sw, /* SEEK symbolic targets (EOF) */
  12165. _CMKEY, /* fcode */
  12166. m,
  12167. "",
  12168. "", /* addtl string data */
  12169. nfsekwtab, /* addtl numeric data 1: table size */
  12170. 0, /* addtl numeric data 2: 4 = cmswi */
  12171. xxstring, /* Processing function */
  12172. fsekwtab, /* Keyword table */
  12173. &nu /* Pointer to next FDB */
  12174. );
  12175. cmfdbi(&nu, /* Byte or line number */
  12176. _CMNUW, /* fcode */
  12177. "",
  12178. "", /* default */
  12179. "", /* addtl string data */
  12180. 10, /* addtl numeric data 1: radix */
  12181. 0, /* addtl numeric data 2: 0 */
  12182. xxstring, /* Processing function */
  12183. NULL, /* Keyword table */
  12184. NULL /* Pointer to next FDB */
  12185. );
  12186. x = cmfdb(&sw); /* Parse something */
  12187. if (x < 0) {
  12188. if (x == -3) {
  12189. printf("?Channel number or EOF required\n");
  12190. x = -9;
  12191. }
  12192. return(x);
  12193. }
  12194. if (cmresult.fcode == _CMNUW) {
  12195. z = cmresult.wresult;
  12196. debug(F110,"FILE SEEK atmbuf",atmbuf,0);
  12197. if (relative < 0) {
  12198. if (cx == FIL_SEE && (atmbuf[0] == '+' || atmbuf[0] == '-'))
  12199. relative = 1;
  12200. else
  12201. relative = 0;
  12202. }
  12203. } else if (cmresult.fcode == _CMKEY) {
  12204. eofflg = cmresult.nresult;
  12205. relative = 0;
  12206. y = 0 - eofflg;
  12207. }
  12208. if ((x = cmcfm()) < 0)
  12209. return(x);
  12210. if (n == -9) return(success = 0);
  12211. if (n == -8) return(success = 1);
  12212. y = 1; /* Recycle this */
  12213. z_flush(n);
  12214. debug(F101,"FILE SEEK relative","",relative);
  12215. debug(F101,"FILE SEEK rsize","",rsize);
  12216. if (rsize == RD_CHAR) { /* Seek to byte position */
  12217. if (relative > 0) {
  12218. CK_OFF_T pos;
  12219. pos = z_getpos(n);
  12220. if (pos < (CK_OFF_T)0) {
  12221. rc = pos;
  12222. printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12223. return(-9);
  12224. }
  12225. z += pos;
  12226. } else {
  12227. if (z < 0 && !eofflg) { /* Negative arg but not relative */
  12228. y = 0; /* Remember this was bad */
  12229. z = 0; /* but substitute 0 */
  12230. }
  12231. }
  12232. debug(F101,"FILE SEEK /CHAR z","",z);
  12233. if (z < 0 && !eofflg) {
  12234. z_error = FX_RNG;
  12235. return(success = 0);
  12236. }
  12237. if ((rc = z_seek(n,z)) < 0) {
  12238. if (rc == FX_EOF) return(success = 0);
  12239. printf("?SEEK /BYTE failed - Channel %d: %s\n",n,ckferror(rc));
  12240. return(-9);
  12241. }
  12242. } else { /* Seek to line */
  12243. if (relative > 0) {
  12244. CK_OFF_T pos;
  12245. pos = z_getline(n);
  12246. debug(F101,"FILE SEEK /LINE pos","",pos);
  12247. if (pos < 0) {
  12248. rc = pos;
  12249. printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12250. return(-9);
  12251. }
  12252. z += pos;
  12253. }
  12254. debug(F101,"FILE SEEK /LINE z","",z);
  12255. debug(F101,"FILE SEEK /LINE eofflg","",eofflg);
  12256. if (z < 0 && !eofflg) {
  12257. z_error = FX_RNG;
  12258. return(success = 0);
  12259. }
  12260. if ((rc = z_line(n,z)) < 0) {
  12261. if (rc == FX_EOF) return(success = 0);
  12262. printf("?SEEK /LINE failed - Channel %d: %s\n",n,ckferror(rc));
  12263. return(-9);
  12264. }
  12265. }
  12266. /*
  12267. Now, having sought to the desired starting spot, if a /FIND:
  12268. target was specified, look for it now.
  12269. */
  12270. if (seek_target) {
  12271. int flag = 0, ispat = 0, matchresult = 0;
  12272. while (!flag) {
  12273. y = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  12274. if (y < 0) {
  12275. y = 0;
  12276. break;
  12277. }
  12278. if (ispattern(seek_target)) {
  12279. matchresult = ckmatch(seek_target,line,inpcas[cmdlvl],1+4);
  12280. } else {
  12281. /* This is faster */
  12282. matchresult = ckindex(seek_target,line,0,0,inpcas[cmdlvl]);
  12283. }
  12284. if (matchresult) {
  12285. flag = 1;
  12286. break;
  12287. }
  12288. }
  12289. if (flag) {
  12290. debug(F111,"FSEEK HAVE MATCH",seek_target,z_getline(n));
  12291. /* Back up to beginning of line where target found */
  12292. if ((y = z_line(n,z_getline(n)-1)) < 0) {
  12293. if (rc == FX_EOF) return(success = 0);
  12294. printf("?SEEK /LINE failed - Channel %d: %s\n",
  12295. n,ckferror(rc));
  12296. return(-9);
  12297. }
  12298. debug(F101,"FSEEK LINE","",y);
  12299. }
  12300. }
  12301. return(success = (y < 0) ? 0 : 1);
  12302. case FIL_LIS: { /* LIST open files */
  12303. #ifdef CK_TTGWSIZ
  12304. extern int cmd_rows, cmd_cols;
  12305. #endif /* CK_TTGWSIZ */
  12306. extern int xaskmore;
  12307. int i, x, n = 0, paging = 0;
  12308. char * s;
  12309. if ((x = cmcfm()) < 0)
  12310. return(x);
  12311. #ifdef CK_TTGWSIZ
  12312. if (cmd_rows > 0 && cmd_cols > 0)
  12313. #endif /* CK_TTGWSIZ */
  12314. paging = xaskmore;
  12315. printf("System open file limit:%5d\n", z_openmax);
  12316. printf("Maximum for FILE OPEN: %5d\n", z_maxchan);
  12317. printf("Files currently open: %5d\n\n", z_nopen);
  12318. n = 4;
  12319. for (i = 0; i < z_maxchan; i++) {
  12320. s = z_getname(i); /* Got one? */
  12321. if (s) { /* Yes */
  12322. char m[8];
  12323. m[0] = NUL;
  12324. printf("%2d. %s",i,s); /* Print name */
  12325. n++; /* Count it */
  12326. x = z_getmode(i); /* Get modes & print them */
  12327. if (x > 0) {
  12328. if (x & FM_REA) ckstrncat(m,"R",8);
  12329. if (x & FM_WRI) ckstrncat(m,"W",8);
  12330. if (x & FM_APP) ckstrncat(m,"A",8);
  12331. if (x & FM_BIN) ckstrncat(m,"B",8);
  12332. if (m[0])
  12333. printf(" (%s)",m);
  12334. if (x & FM_EOF)
  12335. printf(" [EOF]");
  12336. else /* And file position too */
  12337. printf(" %s",ckfstoa(z_getpos(i)));
  12338. }
  12339. printf("\n");
  12340. #ifdef CK_TTGWSIZ
  12341. if (paging > 0) { /* Pause at end of screen */
  12342. if (n > cmd_rows - 3) {
  12343. if (!askmore())
  12344. break;
  12345. else
  12346. n = 0;
  12347. }
  12348. }
  12349. #endif /* CK_TTGWSIZ */
  12350. }
  12351. }
  12352. return(success = 1);
  12353. }
  12354. case FIL_FLU: /* FLUSH */
  12355. if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12356. if (x == -3) {
  12357. printf("?Channel number required\n");
  12358. x = -9;
  12359. }
  12360. return(x);
  12361. }
  12362. if ((x = cmcfm()) < 0)
  12363. return(x);
  12364. if (n == -9) return(success = 0);
  12365. if (n == -8) return(success = 1);
  12366. if ((rc = z_flush(n)) < 0) {
  12367. printf("?FLUSH failed - Channel %d: %s\n",n,ckferror(rc));
  12368. return(-9);
  12369. }
  12370. return(success = 1);
  12371. case FIL_STA: /* STATUS */
  12372. {
  12373. int i, j, k; /* Supply default if only one open */
  12374. s = "";
  12375. for (k = 0, j = 0, i = 0; i < z_maxchan; i++) {
  12376. if (z_file)
  12377. if (z_file[i])
  12378. if (z_file[i]->z_fp) { k++; j = i; }
  12379. }
  12380. if (k == 1) s = ckitoa(j);
  12381. }
  12382. if ((x = cmnum("Channel number",s,10,&n, xxstring)) < 0) {
  12383. if (x == -3) {
  12384. if (z_nopen > 1) {
  12385. printf("?%d files open - please supply channel number\n",
  12386. z_nopen);
  12387. return(-9);
  12388. }
  12389. } else
  12390. return(x);
  12391. }
  12392. if ((y = cmcfm()) < 0)
  12393. return(y);
  12394. if ((!z_file || z_nopen == 0) && x == -3) {
  12395. printf("No files open\n");
  12396. return(success = 1);
  12397. }
  12398. p = blanks + 3; /* Tricky formatting... */
  12399. if (n < 1000) p--;
  12400. if (n < 100) p--;
  12401. if (n < 10) p--;
  12402. if ((rc = z_getmode(n)) < 0) {
  12403. printf("Channel %d:%s%s\n",n,p,ckferror(rc));
  12404. return(success = 0);
  12405. } else if (!rc) {
  12406. printf("Channel %d:%sNot open\n",n,p);
  12407. return(success = 0);
  12408. } else {
  12409. CK_OFF_T xx;
  12410. s = z_getname(n);
  12411. if (!s) s = "(name unknown)";
  12412. printf("Channel %d:%sOpen\n",n,p);
  12413. printf(" File: %s\n Modes: ",s);
  12414. if (rc & FM_REA) printf(" /READ");
  12415. if (rc & FM_WRI) printf(" /WRITE");
  12416. if (rc & FM_APP) printf(" /APPEND");
  12417. if (rc & FM_BIN) printf(" /BINARY");
  12418. if (rc & FM_CMD) printf(" /COMMAND");
  12419. if (rc & FM_EOF) printf(" [EOF]");
  12420. printf("\n Size: %s\n",ckfstoa(z_count(n,RD_CHAR)));
  12421. printf(" At byte: %s\n",ckfstoa(z_getpos(n)));
  12422. xx = z_getline(n);
  12423. if (xx > (CK_OFF_T)-1)
  12424. printf(" At line: %s\n",ckfstoa(xx));
  12425. return(success = 1);
  12426. }
  12427. default:
  12428. return(-2);
  12429. }
  12430. }
  12431. #endif /* CKCHANNELIO */
  12432. #ifndef NOSETKEY
  12433. /* Save Key maps and in OS/2 Mouse maps */
  12434. int
  12435. savkeys(name,disp) char * name; int disp; {
  12436. char *tp;
  12437. static struct filinfo xx;
  12438. int savfil, i, j, k;
  12439. char buf[1024];
  12440. zclose(ZMFILE);
  12441. if (disp) {
  12442. xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  12443. xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  12444. xx.lblopts = 0;
  12445. savfil = zopeno(ZMFILE,name,NULL,&xx);
  12446. } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  12447. if (savfil) {
  12448. #ifdef OS2
  12449. ztime(&tp);
  12450. zsout(ZMFILE, "; Kermit 95 SAVE KEYMAP file: ");
  12451. zsoutl(ZMFILE,tp);
  12452. if (mskkeys) {
  12453. zsoutl(ZMFILE,
  12454. "if eq \"\\v(program)\" \"C-Kermit\" set mskermit keycodes on");
  12455. } else {
  12456. zsoutl(ZMFILE,
  12457. "if NOT eq \"\\v(program)\" \"C-Kermit\" stop 1 C-Kermit required.");
  12458. zsoutl(ZMFILE,"set mskermit keycodes off");
  12459. }
  12460. zsoutl(ZMFILE,"");
  12461. #else /* OS2 */
  12462. ztime(&tp);
  12463. zsout(ZMFILE, "; C-Kermit SAVE KEYMAP file: ");
  12464. zsoutl(ZMFILE,tp);
  12465. #endif /* OS2 */
  12466. zsoutl(ZMFILE,"; Clear previous keyboard mappings ");
  12467. zsoutl(ZMFILE,"set key clear");
  12468. #ifdef OS2
  12469. for (k = 0; k < nttkey; k++) {
  12470. if (!ttkeytab[k].flgs) {
  12471. ckmakmsg(buf,1024,
  12472. "set terminal key ",
  12473. ttkeytab[k].kwd,
  12474. " clear",
  12475. NULL
  12476. );
  12477. zsoutl(ZMFILE,buf);
  12478. }
  12479. }
  12480. #endif /* OS2 */
  12481. zsoutl(ZMFILE,"");
  12482. for (i = 0; i < KMSIZE; i++) {
  12483. if (macrotab[i]) {
  12484. int len = strlen((char *)macrotab[i]);
  12485. #ifdef OS2
  12486. ckmakmsg(buf,
  12487. 1024,
  12488. "set key \\",
  12489. ckitoa(mskkeys ? cktomsk(i) : i),
  12490. " ",
  12491. NULL
  12492. );
  12493. #else /* OS2 */
  12494. ckmakmsg(buf,
  12495. 1024,
  12496. "set key \\",
  12497. ckitoa(i),
  12498. NULL,NULL
  12499. );
  12500. #endif /* OS2 */
  12501. zsout(ZMFILE,buf);
  12502. for (j = 0; j < len; j++) {
  12503. char ch = macrotab[i][j];
  12504. if (ch <= SP || ch >= DEL ||
  12505. ch == '-' || ch == ',' ||
  12506. ch == '{' || ch == '}' ||
  12507. ch == ';' || ch == '?' ||
  12508. ch == '.' || ch == '\'' ||
  12509. ch == '\\' || ch == '/' ||
  12510. ch == '#') {
  12511. ckmakmsg(buf,1024,"\\{",ckitoa((int)ch),"}",NULL);
  12512. zsout(ZMFILE,buf);
  12513. } else {
  12514. ckmakmsg(buf,1024,ckctoa((char)ch),NULL,NULL,NULL);
  12515. zsout(ZMFILE,buf);
  12516. }
  12517. }
  12518. #ifdef OS2
  12519. ckmakmsg(buf,1024,"\t; ",keyname(i),NULL,NULL);
  12520. zsoutl(ZMFILE,buf);
  12521. #else
  12522. zsoutl(ZMFILE,"");
  12523. #endif /* OS2 */
  12524. } else if ( keymap[i] != i ) {
  12525. #ifndef NOKVERBS
  12526. if (IS_KVERB(keymap[i])) {
  12527. for (j = 0; j < nkverbs; j++)
  12528. if (kverbs[j].kwval == (keymap[i] & ~F_KVERB))
  12529. break;
  12530. if (j != nkverbs) {
  12531. #ifdef OS2
  12532. #ifdef COMMENT
  12533. sprintf(buf, "set key \\%d \\K%s\t; %s",
  12534. mskkeys ? cktomsk(i) : i,
  12535. kverbs[j].kwd, keyname(i)
  12536. );
  12537. #else
  12538. ckmakxmsg(buf, /* 12 string args */
  12539. 1024,
  12540. "set key \\",
  12541. ckitoa(mskkeys ? cktomsk(i) : i),
  12542. " \\K",
  12543. kverbs[j].kwd,
  12544. "\t; ",
  12545. keyname(i),
  12546. NULL, NULL, NULL, NULL, NULL, NULL);
  12547. #endif /* COMMENT */
  12548. zsoutl(ZMFILE,buf);
  12549. #else
  12550. #ifdef COMMENT
  12551. sprintf(buf, "set key \\%d \\K%s", i, kverbs[j].kwd);
  12552. #else
  12553. ckmakmsg(buf,1024,
  12554. "set key \\",
  12555. ckitoa(i),
  12556. " \\K",
  12557. kverbs[j].kwd
  12558. );
  12559. #endif /* COMMENT */
  12560. zsoutl(ZMFILE,buf);
  12561. #endif
  12562. }
  12563. } else
  12564. #endif /* NOKVERBS */
  12565. {
  12566. #ifdef OS2
  12567. #ifdef COMMENT
  12568. sprintf(buf, "set key \\%d \\{%d}\t; %s",
  12569. mskkeys ? cktomsk(i) : i,
  12570. keymap[i],
  12571. keyname(i)
  12572. );
  12573. #else
  12574. ckmakxmsg(buf, /* 8 string args */
  12575. 1024,
  12576. "set key \\",
  12577. ckitoa(mskkeys ? cktomsk(i) : i),
  12578. " \\{",
  12579. ckitoa(keymap[i]),
  12580. "}\t; ",
  12581. keyname(i),
  12582. NULL,NULL,NULL,NULL,NULL,NULL);
  12583. #endif /* COMMENT */
  12584. zsoutl(ZMFILE,buf);
  12585. #else
  12586. #ifdef COMMENT
  12587. sprintf(buf, "set key \\%d \\{%d}", i, keymap[i]);
  12588. #else
  12589. ckmakxmsg(buf,1024,
  12590. "set key \\",
  12591. ckitoa(i),
  12592. " \\{",
  12593. ckitoa(keymap[i]),
  12594. "}",
  12595. NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12596. #endif /* COMMENT */
  12597. zsoutl(ZMFILE,buf);
  12598. #endif /* OS2 */
  12599. }
  12600. }
  12601. }
  12602. #ifdef OS2
  12603. /* OS/2 also has the SET TERMINAL KEY <termtype> defines */
  12604. for (k = 0; k < nttkey; k++) {
  12605. extern struct keynode * ttkeymap[];
  12606. struct keynode * pnode = NULL;
  12607. if (ttkeytab[k].flgs) /* Don't process CM_INV or CM_ABR */
  12608. continue;
  12609. zsoutl(ZMFILE,"");
  12610. ckmakmsg(buf,1024,"; SET TERMINAL KEY ",ttkeytab[k].kwd,NULL,NULL);
  12611. zsoutl(ZMFILE,buf);
  12612. for (pnode = ttkeymap[ttkeytab[k].kwval];
  12613. pnode;
  12614. pnode = pnode->next
  12615. ) {
  12616. switch (pnode->def.type) {
  12617. case key:
  12618. #ifdef COMMENT
  12619. sprintf(buf, "set terminal key %s \\%d \\{%d}\t; %s",
  12620. ttkeytab[k].kwd,
  12621. mskkeys ? cktomsk(pnode->key) : pnode->key,
  12622. pnode->def.key.scancode,
  12623. keyname(pnode->key)
  12624. );
  12625. #else
  12626. ckmakxmsg(buf,
  12627. 1024,
  12628. "set terminal key ",
  12629. ttkeytab[k].kwd,
  12630. " \\",
  12631. ckitoa(mskkeys ?
  12632. cktomsk(pnode->key) :
  12633. pnode->key),
  12634. " \\{",
  12635. ckitoa(pnode->def.key.scancode),
  12636. "}\t; ",
  12637. keyname(pnode->key),
  12638. NULL,NULL,NULL,NULL
  12639. );
  12640. #endif /* COMMENT */
  12641. zsoutl(ZMFILE,buf);
  12642. break;
  12643. case kverb:
  12644. for (j = 0; j < nkverbs; j++)
  12645. if (kverbs[j].kwval == (pnode->def.kverb.id & ~F_KVERB))
  12646. break;
  12647. if (j != nkverbs) {
  12648. #ifdef COMMENT
  12649. sprintf(buf, "set terminal key %s \\%d \\K%s\t; %s",
  12650. ttkeytab[k].kwd,
  12651. mskkeys ? cktomsk(pnode->key) : pnode->key,
  12652. kverbs[j].kwd, keyname(pnode->key)
  12653. );
  12654. #else
  12655. ckmakxmsg(buf,
  12656. 1024,
  12657. "set terminal key ",
  12658. ttkeytab[k].kwd,
  12659. " \\",
  12660. ckitoa(mskkeys ?
  12661. cktomsk(pnode->key) :
  12662. pnode->key),
  12663. " \\K",
  12664. kverbs[j].kwd,
  12665. "\t; ",
  12666. keyname(pnode->key),
  12667. NULL,NULL,NULL,NULL
  12668. );
  12669. #endif /* COMMENT */
  12670. zsoutl(ZMFILE,buf);
  12671. }
  12672. break;
  12673. case macro: {
  12674. int len = strlen((char *)pnode->def.macro.string);
  12675. #ifdef COMMENT
  12676. sprintf(buf,"set terminal key %s \\%d ",
  12677. ttkeytab[k].kwd,
  12678. mskkeys ? cktomsk(pnode->key) : pnode->key);
  12679. #else
  12680. ckmakxmsg(buf,
  12681. 1024,
  12682. "set terminal key ",
  12683. ttkeytab[k].kwd,
  12684. " \\",
  12685. ckitoa(mskkeys ?
  12686. cktomsk(pnode->key) :
  12687. pnode->key),
  12688. " ",
  12689. NULL,NULL,NULL,NULL,NULL,NULL,NULL
  12690. );
  12691. #endif /* COMMENT */
  12692. zsout(ZMFILE,buf);
  12693. for (j = 0; j < len; j++) {
  12694. char ch = pnode->def.macro.string[j];
  12695. if (ch <= SP || ch >= DEL ||
  12696. ch == '-' || ch == ',' ||
  12697. ch == '{' || ch == '}' ||
  12698. ch == ';' || ch == '?' ||
  12699. ch == '.' || ch == '\'' ||
  12700. ch == '\\' || ch == '/' ||
  12701. ch == '#') {
  12702. ckmakmsg(buf,1024,
  12703. "\\{",ckitoa((int)ch),"}",NULL);
  12704. zsout(ZMFILE,buf);
  12705. } else {
  12706. ckmakmsg(buf,1024,
  12707. ckctoa((char)ch),NULL,NULL,NULL);
  12708. zsout(ZMFILE,buf);
  12709. }
  12710. }
  12711. ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12712. zsoutl(ZMFILE,buf);
  12713. break;
  12714. }
  12715. case literal: {
  12716. int len = strlen((char *)pnode->def.literal.string);
  12717. #ifdef COMMENT
  12718. sprintf(buf,"set terminal key %s /literal \\%d ",
  12719. ttkeytab[k].kwd,
  12720. mskkeys ? cktomsk(pnode->key) : pnode->key);
  12721. #else
  12722. ckmakxmsg(buf,
  12723. 1024,
  12724. "set terminal key ",
  12725. ttkeytab[k].kwd,
  12726. " /literal \\",
  12727. ckitoa(mskkeys ?
  12728. cktomsk(pnode->key) :
  12729. pnode->key),
  12730. " ",
  12731. NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12732. #endif /* COMMENT */
  12733. zsout(ZMFILE,buf);
  12734. for (j = 0; j < len; j++) {
  12735. char ch = pnode->def.literal.string[j];
  12736. if (ch <= SP || ch >= DEL ||
  12737. ch == '-' || ch == ',' ||
  12738. ch == '{' || ch == '}' ||
  12739. ch == ';' || ch == '?' ||
  12740. ch == '.' || ch == '\'' ||
  12741. ch == '\\' || ch == '/' ||
  12742. ch == '#') {
  12743. ckmakmsg(buf,1024,
  12744. "\\{",ckitoa((int)ch),"}",NULL);
  12745. zsout(ZMFILE,buf);
  12746. } else {
  12747. ckmakmsg(buf,1024,
  12748. ckctoa((char)ch),NULL,NULL,NULL);
  12749. zsout(ZMFILE,buf);
  12750. }
  12751. }
  12752. ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12753. zsoutl(ZMFILE,buf);
  12754. break;
  12755. }
  12756. case esc:
  12757. #ifdef COMMENT
  12758. sprintf(buf,
  12759. "set terminal key %s /literal \\%d \\{%d}\\{%d}\t; %s",
  12760. ttkeytab[k].kwd,
  12761. mskkeys ? cktomsk(pnode->key) : pnode->key,
  12762. ISDG200(ttkeytab[k].kwval) ? 30 : 27,
  12763. pnode->def.esc.key & ~F_ESC,
  12764. keyname(pnode->key)
  12765. );
  12766. #else
  12767. ckmakxmsg(buf,
  12768. 1024,
  12769. "set terminal key ",
  12770. ttkeytab[k].kwd,
  12771. " /literal \\",
  12772. ckitoa(mskkeys ?
  12773. cktomsk(pnode->key) :
  12774. pnode->key),
  12775. " \\{",
  12776. ckitoa(ISDG200(ttkeytab[k].kwval) ? 30 : 27),
  12777. "}\\{",
  12778. ckitoa(pnode->def.esc.key & ~F_ESC),
  12779. "}\t; ",
  12780. keyname(pnode->key),
  12781. NULL,NULL
  12782. );
  12783. #endif /* COMMENT */
  12784. zsoutl(ZMFILE,buf);
  12785. break;
  12786. case csi:
  12787. #ifdef COMMENT
  12788. sprintf(buf,
  12789. "set terminal key %s /literal \\%d \\{27}[\\{%d}\t; %s",
  12790. ttkeytab[k].kwd,
  12791. mskkeys ? cktomsk(pnode->key) : pnode->key,
  12792. pnode->def.csi.key & ~F_CSI,
  12793. keyname(pnode->key)
  12794. );
  12795. #else
  12796. ckmakxmsg(buf,
  12797. 1024,
  12798. "set terminal key ",
  12799. ttkeytab[k].kwd,
  12800. " /literal \\",
  12801. ckitoa(mskkeys ?
  12802. cktomsk(pnode->key) :
  12803. pnode->key),
  12804. " \\{27}[\\{",
  12805. ckitoa(pnode->def.csi.key & ~F_CSI),
  12806. "}\t; ",
  12807. keyname(pnode->key),
  12808. NULL,NULL,NULL,NULL
  12809. );
  12810. #endif /* COMMENT */
  12811. zsoutl(ZMFILE,buf);
  12812. break;
  12813. default:
  12814. continue;
  12815. }
  12816. }
  12817. }
  12818. #endif /* OS2 */
  12819. zsoutl(ZMFILE,"");
  12820. zsoutl(ZMFILE,"; End");
  12821. zclose(ZMFILE);
  12822. return(success = 1);
  12823. } else {
  12824. return(success = 0);
  12825. }
  12826. }
  12827. #endif /* NOSETKEY */
  12828. #define SV_SCRL 0
  12829. #define SV_HIST 1
  12830. #ifdef OS2
  12831. #ifndef NOLOCAL
  12832. static struct keytab trmtrmopt[] = {
  12833. { "scrollback", SV_SCRL, 0 }
  12834. };
  12835. #endif /* NOLOCAL */
  12836. #endif /* OS2 */
  12837. static struct keytab cmdtrmopt[] = {
  12838. #ifdef CK_RECALL
  12839. { "history", SV_HIST, 0 },
  12840. #endif /* CK_RECALL */
  12841. #ifdef OS2
  12842. #ifndef NOLOCAL
  12843. { "scrollback", SV_SCRL, 0 },
  12844. #endif /* NOLOCAL */
  12845. #endif /* OS2 */
  12846. { "", 0, 0 }
  12847. };
  12848. static int ncmdtrmopt = (sizeof (cmdtrmopt) / sizeof (struct keytab)) - 1;
  12849. #ifdef OS2
  12850. #ifndef NOLOCAL
  12851. _PROTOTYP(int savscrbk, (int, char *, int));
  12852. #endif /* NOLOCAL */
  12853. #endif /* OS2 */
  12854. #ifdef CK_RECALL
  12855. _PROTOTYP(int savhistory, (char *, int));
  12856. #endif /* CK_RECALL */
  12857. int
  12858. dosave(xx) int xx; {
  12859. int x, y = 0, disp;
  12860. char * s = NULL;
  12861. extern struct keytab disptb[];
  12862. #ifdef ZFNQFP
  12863. struct zfnfp * fnp;
  12864. #endif /* ZFNQFP */
  12865. #ifndef NOSETKEY
  12866. if (xx == XSKEY) { /* SAVE KEYMAP.. */
  12867. z = cmofi("Name of Kermit command file","keymap.ksc",&s,xxstring);
  12868. } else {
  12869. #endif /* NOSETKEY */
  12870. switch (xx) {
  12871. case XSCMD: /* SAVE COMMAND.. */
  12872. if ((y = cmkey(cmdtrmopt, ncmdtrmopt, "What to save",
  12873. #ifdef OS2
  12874. "scrollback",
  12875. #else
  12876. "history",
  12877. #endif /* OS2 */
  12878. xxstring)) < 0)
  12879. return(y);
  12880. break;
  12881. #ifdef OS2
  12882. #ifndef NOLOCAL
  12883. case XSTERM: /* SAVE TERMINAL.. */
  12884. if ((y = cmkey(trmtrmopt,1,
  12885. "What to save","scrollback",xxstring)) < 0)
  12886. return(y);
  12887. break;
  12888. #endif /* NOLOCAL */
  12889. #endif /* OS2 */
  12890. }
  12891. z = cmofi("Filename",
  12892. ((y == SV_SCRL) ? "scrollbk.txt" : "history.txt"),
  12893. &s,
  12894. xxstring
  12895. );
  12896. #ifndef NOSETKEY
  12897. }
  12898. #endif /* NOSETKEY */
  12899. if (z < 0) /* Check output-file parse results */
  12900. return(z);
  12901. if (z == 2) {
  12902. printf("?Sorry, %s is a directory name\n",s);
  12903. return(-9);
  12904. }
  12905. #ifdef ZFNQFP
  12906. if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {/* Convert to full pathname */
  12907. if (fnp->fpath)
  12908. if ((int) strlen(fnp->fpath) > 0)
  12909. s = fnp->fpath;
  12910. }
  12911. #endif /* ZFNQFP */
  12912. ckstrncpy(line,s,LINBUFSIZ); /* Make safe copy of pathname */
  12913. s = line;
  12914. #ifdef MAC
  12915. z = 0;
  12916. #else
  12917. /* Get NEW/APPEND disposition */
  12918. if ((z = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  12919. return(z);
  12920. #endif /* MAC */
  12921. disp = z;
  12922. if ((x = cmcfm()) < 0) /* Get confirmation */
  12923. return(x);
  12924. switch (xx) { /* Do action.. */
  12925. #ifndef NOSETKEY
  12926. case XSKEY: /* SAVE KEYMAP */
  12927. return (savkeys(s,disp));
  12928. #endif /* NOSETKEY */
  12929. case XSCMD: /* SAVE COMMAND.. */
  12930. #ifdef OS2
  12931. #ifndef NOLOCAL
  12932. if (y == SV_SCRL) /* .. SCROLLBACK */
  12933. return(success = savscrbk(VCMD,s,disp));
  12934. #endif /* NOLOCAL */
  12935. #endif /* OS2 */
  12936. #ifndef NORECALL
  12937. if (y == SV_HIST) /* .. HISTORY */
  12938. return(success = savhistory(s,disp));
  12939. #endif /* NORECALL */
  12940. break;
  12941. #ifdef OS2
  12942. #ifndef NOLOCAL
  12943. case XSTERM: /* SAVE TERMINAL SCROLLBACK */
  12944. return(success = savscrbk(VTERM,s,disp));
  12945. #endif /* NOLOCAL */
  12946. #endif /* OS2 */
  12947. }
  12948. success = 0;
  12949. return(-2);
  12950. }
  12951. /*
  12952. R E A D T E X T
  12953. Read text with a custom prompt into given buffer using command parser but
  12954. with no echoing or entry into recall buffer.
  12955. */
  12956. int
  12957. readtext(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  12958. #ifdef CK_RECALL
  12959. extern int on_recall; /* Around Password prompting */
  12960. #endif /* CK_RECALL */
  12961. int rc;
  12962. #ifndef NOLOCAL
  12963. #ifdef OS2
  12964. extern BYTE vmode;
  12965. extern int startflags;
  12966. int vmode_sav = vmode;
  12967. if (!prmpt) prmpt = "";
  12968. if (win95_popup && !(startflags & 96)
  12969. #ifdef IKSD
  12970. && !inserver
  12971. #endif /* IKSD */
  12972. )
  12973. return(popup_readtext(vmode,NULL,prmpt,buffer,bufsiz,0));
  12974. if (vmode == VTERM) {
  12975. vmode = VCMD;
  12976. VscrnIsDirty(VTERM);
  12977. VscrnIsDirty(VCMD);
  12978. }
  12979. #endif /* OS2 */
  12980. #endif /* NOLOCAL */
  12981. #ifdef CK_RECALL
  12982. on_recall = 0;
  12983. #endif /* CK_RECALL */
  12984. cmsavp(psave,PROMPTL); /* Save old prompt */
  12985. cmsetp(prmpt); /* Make new prompt */
  12986. concb((char)escape); /* Put console in cbreak mode */
  12987. cmini(1); /* and echo mode */
  12988. if (pflag) prompt(xxstring); /* Issue prompt if at top level */
  12989. cmres(); /* Reset the parser */
  12990. for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  12991. rc = cmtxt("","",&s,NULL); /* Get a literal line of text */
  12992. cmres(); /* Reset the parser again */
  12993. }
  12994. ckstrncpy(buffer,s,bufsiz);
  12995. cmsetp(psave); /* Restore original prompt */
  12996. #ifndef NOLOCAL
  12997. #ifdef OS2
  12998. if (vmode != vmode_sav) {
  12999. vmode = VTERM;
  13000. VscrnIsDirty(VCMD);
  13001. VscrnIsDirty(VTERM);
  13002. }
  13003. #endif /* OS2 */
  13004. #endif /* NOLOCAL */
  13005. return(0);
  13006. }
  13007. #endif /* NOICP */
  13008. /* A general function to allow a Password or other information */
  13009. /* to be read from the command prompt without it going into */
  13010. /* the recall buffer or being echo'd. */
  13011. int
  13012. readpass(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  13013. int x;
  13014. #ifdef NOICP
  13015. if (!prmpt) prmpt = "";
  13016. printf("%s", prmpt);
  13017. #ifdef COMMENT
  13018. /* Some linkers won't allow this because it's unsafe */
  13019. gets(buffer);
  13020. #else /* COMMENT */
  13021. {
  13022. int c, i; char * p;
  13023. p = buffer;
  13024. for (i = 0; i < bufsiz-1; i++) {
  13025. if ((c = getchar()) == EOF)
  13026. break;
  13027. if (c < SP)
  13028. break;
  13029. buffer[i] = c;
  13030. }
  13031. buffer[i] = NUL;
  13032. }
  13033. #endif /* COMMENT */
  13034. return(1);
  13035. #else /* NOICP */
  13036. #ifdef CK_RECALL
  13037. extern int on_recall; /* around Password prompting */
  13038. #endif /* CK_RECALL */
  13039. int rc;
  13040. #ifndef NOLOCAL
  13041. #ifdef OS2
  13042. extern BYTE vmode;
  13043. extern int startflags;
  13044. int vmode_sav = vmode;
  13045. #endif /* OS2 */
  13046. #endif /* NOLOCAL */
  13047. #ifdef CKSYSLOG
  13048. int savlog;
  13049. #endif /* CKSYSLOG */
  13050. if (!prmpt) prmpt = "";
  13051. #ifndef NOLOCAL
  13052. debok = 0; /* Don't log */
  13053. #ifdef OS2
  13054. if (win95_popup && !(startflags & 96)
  13055. #ifdef IKSD
  13056. && !inserver
  13057. #endif /* IKSD */
  13058. ) {
  13059. x = popup_readpass(vmode,NULL,prmpt,buffer,bufsiz,0);
  13060. debok = 1;
  13061. return(x);
  13062. }
  13063. #endif /* OS2 */
  13064. #endif /* NOLOCAL */
  13065. #ifdef CKSYSLOG
  13066. savlog = ckxsyslog; /* Save and turn off syslogging */
  13067. ckxsyslog = 0;
  13068. #endif /* CKSYSLOG */
  13069. #ifndef NOLOCAL
  13070. #ifdef OS2
  13071. if (vmode == VTERM) {
  13072. vmode = VCMD;
  13073. VscrnIsDirty(VTERM);
  13074. VscrnIsDirty(VCMD);
  13075. }
  13076. #endif /* OS2 */
  13077. #endif /* NOLOCAL */
  13078. #ifdef CK_RECALL
  13079. on_recall = 0;
  13080. #endif /* CK_RECALL */
  13081. cmsavp(psave,PROMPTL); /* Save old prompt */
  13082. cmsetp(prmpt); /* Make new prompt */
  13083. concb((char)escape); /* Put console in cbreak mode */
  13084. cmini(0); /* and no-echo mode */
  13085. if (pflag) prompt(xxstring); /* Issue prompt if at top level */
  13086. cmres(); /* Reset the parser */
  13087. for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  13088. rc = cmtxt("","",&s,NULL); /* Get a literal line of text */
  13089. cmres(); /* Reset the parser again */
  13090. }
  13091. ckstrncpy(buffer,s,bufsiz);
  13092. printf("\r\n"); /* Echo a CRLF */
  13093. cmsetp(psave); /* Restore original prompt */
  13094. cmini(1); /* Restore echo mode */
  13095. #ifndef NOLOCAL
  13096. #ifdef OS2
  13097. if (vmode != vmode_sav) {
  13098. vmode = VTERM;
  13099. VscrnIsDirty(VCMD);
  13100. VscrnIsDirty(VTERM);
  13101. }
  13102. #endif /* OS2 */
  13103. #endif /* NOLOCAL */
  13104. #ifdef CKSYSLOG
  13105. ckxsyslog = savlog; /* Restore syslogging */
  13106. #endif /* CKSYSLOG */
  13107. debok = 1;
  13108. return(0);
  13109. #endif /* NOICP */
  13110. }
  13111. #ifndef NOICP
  13112. struct keytab authtab[] = { /* Available authentication types */
  13113. #ifdef CK_KERBEROS
  13114. { "k4", AUTH_KRB4, CM_INV },
  13115. { "k5", AUTH_KRB5, CM_INV },
  13116. { "kerberos4", AUTH_KRB4, 0 },
  13117. { "kerberos5", AUTH_KRB5, 0 },
  13118. { "krb4", AUTH_KRB4, CM_INV },
  13119. { "krb5", AUTH_KRB5, CM_INV },
  13120. #endif /* CK_KERBEROS */
  13121. #ifdef NT
  13122. { "ntlm", AUTH_NTLM, 0 },
  13123. #endif /* NT */
  13124. #ifdef CK_SRP
  13125. { "srp", AUTH_SRP, 0 },
  13126. #endif /* CK_SRP */
  13127. #ifdef CK_SSL
  13128. { "ssl", AUTH_SSL, 0 },
  13129. #endif /* CK_SSL */
  13130. { "", 0, 0 }
  13131. };
  13132. int authtabn = sizeof(authtab)/sizeof(struct keytab)-1;
  13133. #ifdef CK_KERBEROS
  13134. struct keytab kerbtab[] = { /* Kerberos authentication types */
  13135. { "k4", AUTH_KRB4, CM_INV },
  13136. { "k5", AUTH_KRB5, CM_INV },
  13137. { "kerberos4", AUTH_KRB4, 0 },
  13138. { "kerberos5", AUTH_KRB5, 0 },
  13139. { "krb4", AUTH_KRB4, CM_INV },
  13140. { "krb5", AUTH_KRB5, CM_INV }
  13141. };
  13142. int kerbtabn = sizeof(kerbtab)/sizeof(struct keytab);
  13143. static struct keytab krb_s_tbl[] = { /* AUTHENTICATE command switches: */
  13144. { "/cache", KRB_S_CA, CM_ARG }
  13145. };
  13146. static int krb_s_n = sizeof(krb_s_tbl)/sizeof(struct keytab);
  13147. static struct keytab krb_v_tbl[] = { /* KERBEROS version values: */
  13148. { "4", 4, 0 },
  13149. { "5", 5, 0 }, /* (add others as needed...) */
  13150. { "auto", 0, 0 } /* Note: 0 = auto */
  13151. };
  13152. static int krb_v_n = sizeof(krb_v_tbl)/sizeof(struct keytab);
  13153. static struct keytab krb_a_tbl[] = { /* KERBEROS actions: */
  13154. { "destroy", KRB_A_DE, 0 },
  13155. { "initialize", KRB_A_IN, 0 },
  13156. { "list-credentials", KRB_A_LC, 0 }
  13157. };
  13158. static int krb_a_n = sizeof(krb_a_tbl)/sizeof(struct keytab);
  13159. static struct keytab krb4_i_tbl[] = { /* KERBEROS 4 INITIALIZE switches: */
  13160. { "/brief", KRB_I_BR, 0 }, /* /BRIEF */
  13161. { "/instance", KRB_I_IN, CM_ARG }, /* /INSTANCE: */
  13162. { "/lifetime", KRB_I_LF, CM_ARG }, /* /LIFETIME: */
  13163. { "/not-preauth", KRB_I_NPA, 0 }, /* /NOT-PREAUTH */
  13164. { "/password", KRB_I_PW, CM_ARG }, /* /PASSWORD: */
  13165. #ifdef OS2
  13166. { "/popup", KRB_I_POP, 0 }, /* /POPUP */
  13167. #endif /* OS2 */
  13168. { "/preauth", KRB_I_PA, 0 }, /* /PREAUTH */
  13169. { "/realm", KRB_I_RL, CM_ARG }, /* /REALM: */
  13170. { "/verbose", KRB_I_VB, 0 }, /* /VERBOSE */
  13171. { "", 0, 0 }
  13172. };
  13173. static int krb4_i_n = sizeof(krb4_i_tbl)/sizeof(struct keytab) - 1;
  13174. static struct keytab krb5_i_tbl[] = { /* KERBEROS 5 INITIALIZE switches: */
  13175. { "/addresses", KRB_I_ADR, CM_ARG },
  13176. { "/forwardable", KRB_I_FW, 0 }, /* /FORWARDABLE */
  13177. { "/instance", KRB_I_IN, CM_ARG }, /* /INSTANCE: */
  13178. { "/k4", KRB_I_K4, CM_INV }, /* /KERBEROS4 */
  13179. { "/kerberos4", KRB_I_K4, 0 }, /* /KERBEROS4 */
  13180. { "/krb4", KRB_I_K4, CM_INV }, /* /KERBEROS4 */
  13181. { "/lifetime", KRB_I_LF, CM_ARG }, /* /LIFETIME: */
  13182. { "/no-addresses", KRB_I_NAD, 0 }, /* /NO-ADDRESSES */
  13183. { "/no-k4", KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13184. { "/no-kerberos4", KRB_I_NK4, 0 }, /* /NO-KERBEROS4 */
  13185. { "/no-krb4", KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13186. { "/not-forwardable", KRB_I_NFW, 0 }, /* /NOT-FORWARDABLE */
  13187. { "/not-proxiable", KRB_I_NPR, 0 }, /* /NOT-PROXIABLE */
  13188. { "/password", KRB_I_PW, CM_ARG }, /* /PASSWORD: */
  13189. #ifdef OS2
  13190. { "/popup", KRB_I_POP, 0 }, /* /POPUP */
  13191. #endif /* OS2 */
  13192. { "/postdate", KRB_I_PD, CM_ARG }, /* /POSTDATE: */
  13193. { "/pr", KRB_I_PR, CM_INV|CM_ABR }, /* to allow for */
  13194. { "/pro", KRB_I_PR, CM_INV|CM_ABR }, /* different spellings */
  13195. { "/prox", KRB_I_PR, CM_INV|CM_ABR },
  13196. { "/proxiable", KRB_I_PR, 0 }, /* /PROXIABLE */
  13197. { "/proxyable", KRB_I_PR, CM_INV }, /* /PROXYABLE */
  13198. { "/realm", KRB_I_RL, CM_ARG }, /* /REALM: */
  13199. { "/renew", KRB_I_RN, 0 }, /* /RENEW */
  13200. { "/renewable", KRB_I_RB, CM_ARG }, /* /RENEWABLE: */
  13201. { "/service", KRB_I_SR, CM_ARG }, /* /SERVICE: */
  13202. { "/validate", KRB_I_VA, 0 }, /* /VALIDATE */
  13203. { "", 0, 0 }
  13204. };
  13205. static int krb5_i_n = sizeof(krb5_i_tbl)/sizeof(struct keytab) - 1;
  13206. static struct keytab klctab[] = { /* List Credentials switches*/
  13207. { "/addresses", XYKLCAD, 0 },
  13208. { "/encryption", XYKLCEN, 0 },
  13209. { "/flags", XYKLCFL, 0 }
  13210. };
  13211. static int nklctab = sizeof(klctab)/sizeof(struct keytab);
  13212. extern int krb_action;
  13213. extern struct krb_op_data krb_op;
  13214. extern struct krb5_list_cred_data krb5_lc;
  13215. extern struct krb5_init_data krb5_init;
  13216. extern char * krb5_d_principal; /* Default principal */
  13217. extern char * krb5_d_instance;
  13218. extern char * krb5_d_realm; /* Default realm */
  13219. extern char * krb5_d_cc; /* Default credentials cache */
  13220. extern char * krb5_d_srv; /* Default service name */
  13221. extern int krb5_d_lifetime; /* Default lifetime */
  13222. extern int krb5_d_forwardable;
  13223. extern int krb5_d_proxiable;
  13224. extern int krb5_d_renewable;
  13225. extern int krb5_autoget;
  13226. extern int krb5_autodel;
  13227. extern int krb5_d_getk4;
  13228. extern int krb5_d_no_addresses;
  13229. extern int krb5_checkaddrs;
  13230. extern char * krb5_d_addrs[];
  13231. extern char * k5_keytab; /* Keytab file */
  13232. extern struct krb4_init_data krb4_init;
  13233. extern char * krb4_d_principal; /* Default principal */
  13234. extern char * krb4_d_realm; /* Default realm */
  13235. extern char * krb4_d_srv; /* Default service name */
  13236. extern int krb4_d_lifetime; /* Default lifetime */
  13237. extern int krb4_d_preauth;
  13238. extern char * krb4_d_instance;
  13239. extern int krb4_autoget;
  13240. extern int krb4_autodel;
  13241. extern int krb4_checkaddrs;
  13242. extern char * k4_keytab; /* Keytab file */
  13243. #endif /* CK_KERBEROS */
  13244. #ifndef NOSHOW
  13245. int
  13246. sho_iks() {
  13247. #ifdef IKSDCONF
  13248. #ifdef CK_LOGIN
  13249. extern int ckxsyslog, ckxwtmp, ckxanon;
  13250. #ifdef UNIX
  13251. extern int ckxpriv;
  13252. #endif /* UNIX */
  13253. #ifdef CK_PERMS
  13254. extern int ckxperms;
  13255. #endif /* CK_PERMS */
  13256. extern char * anonfile, * userfile, * anonroot;
  13257. #ifdef OS2
  13258. extern char * anonacct;
  13259. #endif /* OS2 */
  13260. #ifdef NT
  13261. extern char * iks_domain;
  13262. #endif /* NT */
  13263. #endif /* CK_LOGIN */
  13264. #ifdef CKWTMP
  13265. extern char * wtmpfile;
  13266. #endif /* CKWTMP */
  13267. #ifdef IKSDB
  13268. extern char * dbfile;
  13269. extern int dbenabled;
  13270. #endif /* IKSDB */
  13271. #ifdef CK_LOGIN
  13272. extern int logintimo;
  13273. #endif /* CK_LOGIN */
  13274. extern int srvcdmsg, success, iksdcf, noinit, arg_x;
  13275. extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  13276. char * bannerfile = NULL;
  13277. char * helpfile = NULL;
  13278. extern int xferlog;
  13279. extern char * xferfile;
  13280. int i;
  13281. if (isguest) {
  13282. printf("?Command disabled\r\n");
  13283. return(success = 0);
  13284. }
  13285. printf("IKS Settings\r\n");
  13286. #ifdef CK_LOGIN
  13287. #ifdef OS2
  13288. printf(" Anonymous Account: %s\r\n",anonacct?anonacct:"<none>");
  13289. #endif /* OS2 */
  13290. printf(" Anonymous Initfile: %s\r\n",anonfile?anonfile:"<none>");
  13291. printf(" Anonymous Login: %d\r\n",ckxanon);
  13292. printf(" Anonymous Root: %s\r\n",anonroot?anonroot:"<none>");
  13293. #endif /* CK_LOGIN */
  13294. printf(" Bannerfile: %s\r\n",bannerfile?bannerfile:"<none>");
  13295. printf(" CDfile: %s\r\n",cdmsgfile[0]?cdmsgfile[0]:"<none>");
  13296. for ( i=1;i<16 && cdmsgfile[i];i++ )
  13297. printf(" CDfile: %s\r\n",cdmsgfile[i]);
  13298. printf(" CDMessage: %d\r\n",srvcdmsg);
  13299. #ifdef IKSDB
  13300. printf(" DBfile: %s\r\n",dbfile?dbfile:"<none>");
  13301. printf(" DBenabled: %d\r\n",dbenabled);
  13302. #endif /* IKSDB */
  13303. #ifdef CK_LOGIN
  13304. #ifdef NT
  13305. printf(" Default-domain: %s\r\n",iks_domain?iks_domain:".");
  13306. #endif /* NT */
  13307. #endif /* CK_LOGIN */
  13308. printf(" Helpfile: %s\r\n",helpfile?helpfile:"<none>");
  13309. printf(" Initfile: %s\r\n",kermrc?kermrc:"<none>");
  13310. printf(" No-Initfile: %d\r\n",noinit);
  13311. #ifdef CK_LOGIN
  13312. #ifdef CK_PERM
  13313. printf(" Permission code: %0d\r\n",ckxperms);
  13314. #endif /* CK_PERM */
  13315. #ifdef UNIX
  13316. printf(" Privileged Login: %d\r\n",ckxpriv);
  13317. #endif /* UNIX */
  13318. #endif /* CK_LOGIN */
  13319. printf(" Server-only: %d\r\n",arg_x);
  13320. printf(" Syslog: %d\r\n",ckxsyslog);
  13321. printf(" Timeout (seconds): %d\r\n",logintimo);
  13322. printf(" Userfile: %s\r\n",userfile?userfile:"<none>");
  13323. #ifdef CK_LOGIN
  13324. #ifdef CKWTMP
  13325. printf(" Wtmplog: %d\r\n",ckxwtmp);
  13326. printf(" Wtmpfile: %s\r\n",wtmpfile?wtmpfile:"<none>");
  13327. #endif /* CKWTMP */
  13328. #endif /* CK_LOGIN */
  13329. printf(" Xferfile: %s\r\n",xferfile?xferfile:"<none>");
  13330. printf(" Xferlog: %d\r\n",xferlog);
  13331. #else /* IKSDCONF */
  13332. printf("?Nothing to show.\r\n");
  13333. #endif /* IKSDCONF */
  13334. return(success = 1);
  13335. }
  13336. #ifdef CK_AUTHENTICATION
  13337. int
  13338. sho_auth(cx) int cx; {
  13339. extern int auth_type_user[], cmd_rows;
  13340. int i;
  13341. char * p;
  13342. int kv = 0, all = 0, n = 0;
  13343. #ifdef IKSD
  13344. if (inserver && isguest) {
  13345. printf("?Sorry, command disabled.\r\n");
  13346. return(success = 0);
  13347. }
  13348. #endif /* IKSD */
  13349. if (cx) {
  13350. kv = cx;
  13351. } else if (auth_type_user[0] != AUTHTYPE_AUTO) {
  13352. kv = auth_type_user[0];
  13353. } else {
  13354. all = 1;
  13355. kv = AUTHTYPE_KERBEROS_V4;
  13356. }
  13357. while (kv) {
  13358. switch (kv) {
  13359. case AUTHTYPE_KERBEROS_V4:
  13360. kv = all ? AUTHTYPE_KERBEROS_V5 : 0;
  13361. if (ck_krb4_is_installed()) {
  13362. printf(" Authentication: Kerberos 4\n");
  13363. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13364. } else {
  13365. printf(" Authentication: Kerberos 4 (not installed)\n");
  13366. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13367. continue;
  13368. }
  13369. #ifdef CK_KERBEROS
  13370. printf(" Keytab file: %s\n",
  13371. k4_keytab ? k4_keytab : "(none)");
  13372. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13373. if (krb_action < 0) {
  13374. p = "(none)";
  13375. } else {
  13376. for (p = "", i = 0; i < krb_a_n; i++) {
  13377. if (krb_action == krb_a_tbl[i].kwval) {
  13378. p = krb_a_tbl[i].kwd;
  13379. break;
  13380. }
  13381. }
  13382. }
  13383. printf(" Action: %s\n", p);
  13384. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13385. printf(" Default lifetime %d\n",krb4_d_lifetime);
  13386. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13387. printf(" Lifetime: %d (minutes)\n",krb4_init.lifetime);
  13388. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13389. printf(" Default preauth: %d\n",krb4_d_preauth);
  13390. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13391. printf(" Preauth: %d\n",krb4_init.preauth);
  13392. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13393. printf(" Default principal: \"%s\"\n",
  13394. krb4_d_principal ? krb4_d_principal : "");
  13395. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13396. printf(" Principal: \"%s\"\n",
  13397. krb4_init.principal ? krb4_init.principal : "");
  13398. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13399. printf(" Default realm: \"%s\"\n",
  13400. krb4_d_realm ? krb4_d_realm : "");
  13401. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13402. printf(" Realm: \"%s\"\n",
  13403. krb4_init.realm ? krb4_init.realm : "");
  13404. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13405. printf(" Default instance: \"%s\"\n",
  13406. krb4_d_instance ? krb4_d_instance : "");
  13407. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13408. printf(" Instance: \"%s\"\n",
  13409. krb4_init.instance ? krb4_init.instance : "");
  13410. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13411. printf(" Auto-Get TGTs: %d\n",krb4_autoget);
  13412. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13413. printf(" Auto-Destroy TGTs: %s\n",
  13414. krb4_autodel==KRB_DEL_NO?"never":
  13415. krb4_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13416. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13417. printf(" Check IP Addresses: %d\n",krb4_checkaddrs);
  13418. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13419. #ifdef COMMENT
  13420. printf(" Password: \"%s\"\n",
  13421. krb4_init.password ? krb4_init.password : "");
  13422. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13423. #endif /* COMMENT */
  13424. #endif /* CK_KERBEROS */
  13425. printf("\n");
  13426. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13427. break;
  13428. case AUTHTYPE_KERBEROS_V5:
  13429. kv = all ? AUTHTYPE_SSL : 0;
  13430. if (ck_krb5_is_installed()) {
  13431. if (ck_gssapi_is_installed())
  13432. printf(" Authentication: Kerberos 5 plus GSSAPI\n");
  13433. else
  13434. printf(" Authentication: Kerberos 5\n");
  13435. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13436. } else {
  13437. printf(" Authentication: Kerberos 5 (not installed)\n");
  13438. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13439. continue;
  13440. }
  13441. #ifdef CK_KERBEROS
  13442. printf(" Cache file: %s\n",
  13443. krb_op.cache ? krb_op.cache : "(none)");
  13444. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13445. printf(" Default cache: %s\n",
  13446. krb5_d_cc ? krb5_d_cc : "(none)");
  13447. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13448. printf(" Keytab file: %s\n",
  13449. k5_keytab ? k5_keytab : "(none)");
  13450. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13451. if (krb_action < 0) {
  13452. p = "(none)";
  13453. } else {
  13454. for (p = "", i = 0; i < krb_a_n; i++) {
  13455. if (krb_action == krb_a_tbl[i].kwval) {
  13456. p = krb_a_tbl[i].kwd;
  13457. break;
  13458. }
  13459. }
  13460. }
  13461. printf(" Action: %s\n", p);
  13462. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13463. printf(" Default forwardable %d\n",krb5_d_forwardable);
  13464. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13465. printf(" Forwardable: %d\n",krb5_init.forwardable);
  13466. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13467. printf(" Default lifetime %d\n",krb5_d_lifetime);
  13468. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13469. printf(" Lifetime: %d (minutes)\n",krb5_init.lifetime);
  13470. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13471. printf(" Postdate: \"%s\"\n",
  13472. krb5_init.postdate ? krb5_init.postdate: "");
  13473. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13474. printf(" Default proxiable: %d\n",krb5_d_proxiable);
  13475. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13476. printf(" Proxiable: %d\n",krb5_init.proxiable);
  13477. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13478. printf(" Renew: %d\n",krb5_init.renew);
  13479. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13480. printf(" Default renewable: %d (minutes)\n",krb5_d_renewable);
  13481. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13482. printf(" Renewable: %d (minutes)\n",krb5_init.renewable);
  13483. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13484. printf(" Service: \"%s\"\n",
  13485. krb5_init.service ? krb5_init.service : "");
  13486. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13487. printf(" Validate: %d\n",krb5_init.validate);
  13488. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13489. printf(" Default principal: \"%s\"\n",
  13490. krb5_d_principal ? krb5_d_principal : "");
  13491. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13492. printf(" Principal: \"%s\"\n",
  13493. krb5_init.principal ? krb5_init.principal : "");
  13494. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13495. printf(" Default instance: \"%s\"\n",
  13496. krb5_d_instance ? krb5_d_instance : "");
  13497. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13498. printf(" Default realm: \"%s\"\n",
  13499. krb5_d_realm ? krb5_d_realm : "");
  13500. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13501. printf(" Realm: \"%s\"\n",
  13502. krb5_init.realm ? krb5_init.realm : "");
  13503. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13504. printf(" Auto-Get TGTs: %d\n",krb5_autoget);
  13505. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13506. printf(" Auto-Destroy TGTs: %s\n",
  13507. krb5_autodel==KRB_DEL_NO?"never":
  13508. krb5_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13509. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13510. printf(" Default get K4 TGTs: %d\n",krb5_d_getk4);
  13511. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13512. printf(" Get K4 TGTs: %d\n",krb5_init.getk4);
  13513. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13514. printf(" Check IP Addresses: %d\n",krb5_checkaddrs);
  13515. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13516. printf(" No IP Addresses: %d\n",krb5_d_no_addresses);
  13517. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13518. printf(" IP-Addresses: ");
  13519. if (krb5_init.addrs && krb5_init.addrs[0]) {
  13520. for (i = 0; krb5_init.addrs[i]; i++) {
  13521. if (i)
  13522. printf(",");
  13523. printf("%s",krb5_init.addrs[i]);
  13524. }
  13525. } else if (krb5_d_addrs[0]) {
  13526. for (i = 0;i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];i++) {
  13527. if (i)
  13528. printf(",");
  13529. printf("%s",krb5_d_addrs[i]);
  13530. }
  13531. } else {
  13532. printf("(use default)");
  13533. }
  13534. printf("\n");
  13535. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13536. #ifdef COMMENT
  13537. printf(" Password: \"%s\"\n",
  13538. krb5_init.password ? krb5_init.password : "");
  13539. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13540. #endif /* COMMENT */
  13541. #endif /* CK_KERBEROS */
  13542. printf("\n");
  13543. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13544. break;
  13545. #ifdef CK_SSL
  13546. case AUTHTYPE_SSL:
  13547. kv = all ? AUTHTYPE_SRP : 0;
  13548. if (ck_ssleay_is_installed()) {
  13549. printf(" Authentication: SSL/TLS (%s)\n",
  13550. SSLeay_version(SSLEAY_VERSION));
  13551. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13552. } else {
  13553. printf(" Authentication: SSL/TLS (not installed)\n");
  13554. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13555. continue;
  13556. }
  13557. printf(" RSA Certs file: %s\n",ssl_rsa_cert_file?
  13558. ssl_rsa_cert_file:"(none)");
  13559. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13560. printf(" RSA Certs Chain file: %s\n",ssl_rsa_cert_chain_file?
  13561. ssl_rsa_cert_chain_file:"(none)");
  13562. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13563. printf(" RSA Key file: %s\n",ssl_rsa_key_file?
  13564. ssl_rsa_key_file:"(none)");
  13565. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13566. printf(" DSA Certs file: %s\n",ssl_dsa_cert_file?
  13567. ssl_dsa_cert_file:"(none)");
  13568. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13569. printf(" DSA Certs Chain file: %s\n",ssl_dsa_cert_chain_file?
  13570. ssl_dsa_cert_chain_file:"(none)");
  13571. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13572. printf(" DH Key file: %s\n",ssl_dh_key_file?
  13573. ssl_dh_key_file:"(none)");
  13574. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13575. printf(" DH Param file: %s\n",ssl_dh_param_file?
  13576. ssl_dh_param_file:"(none)");
  13577. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13578. printf(" CRL file: %s\n",ssl_crl_file?
  13579. ssl_crl_file:"(none)");
  13580. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13581. printf(" CRL dir: %s\n",ssl_crl_dir?
  13582. ssl_crl_dir:"(none)");
  13583. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13584. printf(" Random file: %s\n",ssl_rnd_file?
  13585. ssl_rnd_file:"(none)");
  13586. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13587. printf(" Verify file: %s\n",ssl_verify_file?
  13588. ssl_verify_file:"(none)");
  13589. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13590. printf(" Verify dir: %s\n",ssl_verify_dir?
  13591. ssl_verify_dir:"(none)");
  13592. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13593. printf(" Cipher list: %s\n",ssl_cipher_list ? ssl_cipher_list :
  13594. DEFAULT_CIPHER_LIST);
  13595. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13596. if (ssl_con == NULL) {
  13597. SSL_library_init();
  13598. ssl_ctx = (SSL_CTX *)
  13599. SSL_CTX_new((SSL_METHOD *)TLS_method());
  13600. if (ssl_ctx != NULL)
  13601. ssl_con= (SSL *) SSL_new(ssl_ctx);
  13602. }
  13603. if (ssl_con != NULL) {
  13604. CHAR * p = NULL;
  13605. int i;
  13606. for (i = 0; ; i++) {
  13607. p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  13608. if (p == NULL)
  13609. break;
  13610. printf(" %s\n",p);
  13611. if (++n > cmd_rows - 3)
  13612. if (!askmore()) return(0); else n = 0;
  13613. }
  13614. }
  13615. printf(" Certs OK? %s\n",ssl_certsok_flag? "yes" : "no");
  13616. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13617. printf(" Debug mode: %s\n", ssl_debug_flag ? "on" : "off");
  13618. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13619. printf(" Verbose mode: %s\n", ssl_verbose_flag ? "on" : "off");
  13620. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13621. printf(" Verify mode: %s\n",
  13622. ssl_verify_flag == SSL_VERIFY_NONE ? "none" :
  13623. ssl_verify_flag == SSL_VERIFY_PEER ? "peer-cert" :
  13624. "fail-if-no-peer-cert");
  13625. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13626. printf(" SSL only? %s\n", ssl_only_flag ? "yes" : "no");
  13627. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13628. printf(" TLS only? %s\n", tls_only_flag ? "yes" : "no");
  13629. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13630. #endif /* CK_SSL */
  13631. break;
  13632. case AUTHTYPE_NTLM:
  13633. kv = 0;
  13634. if (ck_ntlm_is_installed()) {
  13635. printf(" Authentication: NTLM\n");
  13636. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13637. printf(" No options\n");
  13638. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13639. } else {
  13640. printf(" Authentication: NTLM (not installed)\n");
  13641. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13642. continue;
  13643. }
  13644. printf("\n");
  13645. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13646. break;
  13647. case AUTHTYPE_SRP:
  13648. kv = all ? AUTHTYPE_NTLM : 0;
  13649. if (ck_srp_is_installed()) {
  13650. if (ck_krypto_is_installed())
  13651. printf(" Authentication: SRP plus Krypto API\n");
  13652. else
  13653. printf(" Authentication: SRP\n");
  13654. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13655. printf(" No options\n");
  13656. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13657. } else {
  13658. printf(" Authentication: SRP (not installed)\n");
  13659. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13660. continue;
  13661. }
  13662. printf("\n");
  13663. if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13664. break;
  13665. }
  13666. }
  13667. return(success = 1);
  13668. }
  13669. #endif /* CK_AUTHENTICATION */
  13670. #endif /* NOSHOW */
  13671. #ifdef CK_KERBEROS
  13672. /* C P _ A U T H -- AUTHENTICATE command parsing */
  13673. int
  13674. cp_auth() { /* Command_Parse AUTHENTICATE */
  13675. int c, i, n; /* Workers */
  13676. int rc = 0; /* Return code */
  13677. int getval; /* Parsing helpers */
  13678. int tmpauth = 0; /* Temporary authentication type */
  13679. int kv = 0; /* Temporary Kerberos version */
  13680. int tmp_action = -1; /* Temporary Kerberos action */
  13681. int tmp_klc = 0; /* Temporary list-credentials */
  13682. char tmphlp[256]; /* For building help message */
  13683. char * p;
  13684. char * tmppswd = NULL; /* Password */
  13685. char * tmpprinz = NULL; /* Principal */
  13686. char * tmprealm = NULL; /* Realm */
  13687. char * tmpcache = NULL; /* Cache file */
  13688. char * tmpinst = NULL; /* K4 Instance */
  13689. char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  13690. #ifdef CK_RECALL
  13691. extern int on_recall; /* around Password prompting */
  13692. #endif /* CK_RECALL */
  13693. struct stringint pv[KRB_I_MAX+1]; /* Temporary array for switch values */
  13694. struct FDB kw, sw, fl; /* FDBs for each parse function */
  13695. krb_action = -1; /* Initialize Kerberos action. */
  13696. tmp_action = -1; /* And our local copy. */
  13697. for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  13698. tmpaddrs[i] = NULL;
  13699. if ((y = cmkey(kerbtab,kerbtabn,"authentication type","",xxstring)) < 0)
  13700. {
  13701. if (y == -3)
  13702. printf("?Authentication type not specified - nothing happens\n");
  13703. return(y);
  13704. }
  13705. tmpauth = y;
  13706. debug(F101,"kerberos authentication","",tmpauth);
  13707. switch (tmpauth) {
  13708. case AUTH_KRB4: kv = 4; break; /* Don't assume values are the same */
  13709. case AUTH_KRB5: kv = 5; break;
  13710. default:
  13711. printf("?Authentication type not supported: \"%s\"\n",atmbuf);
  13712. return(-9);
  13713. }
  13714. /* From here down is Kerberos */
  13715. ini_kerb(); /* Reset Init data to defaults */
  13716. if (kv == 4) { /* Set K4 defaults */
  13717. if (krb4_d_realm)
  13718. makestr(&tmprealm,krb4_d_realm);
  13719. if (krb4_d_principal)
  13720. makestr(&tmpprinz,krb4_d_principal);
  13721. if (krb4_d_instance)
  13722. makestr(&tmpinst,krb4_d_instance);
  13723. } else if (kv == 5) { /* Set K5 defaults */
  13724. if (krb5_d_cc)
  13725. makestr(&tmpcache,krb5_d_cc);
  13726. if (krb5_d_realm)
  13727. makestr(&tmprealm,krb5_d_realm);
  13728. if (krb5_d_principal)
  13729. makestr(&tmpprinz,krb5_d_principal);
  13730. if (krb5_d_instance)
  13731. makestr(&tmpinst,krb5_d_instance);
  13732. }
  13733. for (i = 0; i <= KRB_I_MAX; i++) { /* Initialize switch values */
  13734. pv[i].sval = NULL; /* to null pointers */
  13735. pv[i].ival = 0; /* and 0 int values */
  13736. pv[i].wval = (CK_OFF_T)-1; /* and -1 wide values */
  13737. }
  13738. if (kv == 4) { /* Kerberos 4 */
  13739. pv[KRB_I_LF].ival = krb4_d_lifetime;
  13740. pv[KRB_I_PA].ival = krb4_d_preauth;
  13741. if ((n = cmkey(krb_a_tbl,krb_a_n,"Kerberos 4 action","",xxstring)) < 0)
  13742. {
  13743. if (n == -3)
  13744. printf("?Action not specified - nothing happens.\n");
  13745. return(n);
  13746. }
  13747. } else if (kv == 5) { /* Kerberos 5 */
  13748. pv[KRB_I_FW].ival = krb5_d_forwardable;
  13749. pv[KRB_I_PR].ival = krb5_d_proxiable;
  13750. pv[KRB_I_LF].ival = krb5_d_lifetime;
  13751. pv[KRB_I_RB].ival = krb5_d_renewable;
  13752. pv[KRB_I_K4].ival = krb5_d_getk4;
  13753. pv[KRB_I_NAD].ival = krb5_d_no_addresses;
  13754. /* Make help message that shows switches and action keywords */
  13755. ckstrncpy(tmphlp,"Kerberos 5 action, one of the following:\n ",256);
  13756. for (i = 0; i < krb_a_n; i++) {
  13757. ckstrncat(tmphlp,krb_a_tbl[i].kwd,sizeof(tmphlp));
  13758. if (i == krb_a_n - 1)
  13759. ckstrncat(tmphlp,"\nor switch",sizeof(tmphlp));
  13760. else
  13761. ckstrncat(tmphlp," ",sizeof(tmphlp));
  13762. }
  13763. /* Set up first set of chained FDB's */
  13764. cmfdbi(&sw, /* First FDB - command switches */
  13765. _CMKEY, /* fcode */
  13766. tmphlp, /* hlpmsg */
  13767. "", /* default (none) */
  13768. "", /* addtl string data */
  13769. krb_s_n, /* Switch table size */
  13770. 4, /* addtl numeric data 2: 4 = cmswi */
  13771. xxstring, /* Processing function */
  13772. krb_s_tbl, /* Switch table */
  13773. &kw /* Pointer to next FDB */
  13774. );
  13775. cmfdbi(&kw, /* Second FDB - action keywords */
  13776. _CMKEY, /* fcode */
  13777. "Kerberos action", /* hlpmsg */
  13778. "", /* default (none) */
  13779. "", /* addtl string data */
  13780. krb_a_n, /* Switch table size */
  13781. 0, /* addtl num data (0 = NOT switch) */
  13782. xxstring, /* Processing function */
  13783. krb_a_tbl, /* Keyword table */
  13784. NULL /* Pointer to next FDB (none) */
  13785. );
  13786. /* Parse */
  13787. while (1) { /* Parse 0 or more switches */
  13788. rc = cmfdb(&sw); /* Parse something */
  13789. debug(F101,"kerberos cmfdb 1 rc","",rc);
  13790. if (rc < 0) { /* Error */
  13791. if (rc == -3)
  13792. printf("?Action not specified - nothing happens.\n");
  13793. return(rc); /* or reparse needed */
  13794. }
  13795. if (cmresult.fdbaddr != &sw) /* Break out if not a switch */
  13796. break;
  13797. c = cmgbrk(); /* Have switch - get break character */
  13798. getval = (c == ':' || c == '='); /* Must parse an agument? */
  13799. if (getval && !(cmresult.kflags & CM_ARG)) {
  13800. printf("?This switch does not take arguments\n");
  13801. return(-9); /* OK because nothing malloc'd yet */
  13802. }
  13803. if (!getval && (cmgkwflgs() & CM_ARG)) {
  13804. printf("?This switch requires an argument\n");
  13805. return(-9);
  13806. }
  13807. n = cmresult.nresult; /* Numeric result = switch value */
  13808. debug(F101,"kerberos command switch","",n);
  13809. switch (n) { /* Handle the switch */
  13810. case KRB_S_CA: /* /CACHE:<filename> */
  13811. p = krb5_d_cc ? krb5_d_cc : "";
  13812. if ((y = cmofi("Name of cache file",p,&s,xxstring)) < 0) {
  13813. if (y == -3)
  13814. s = NULL;
  13815. else
  13816. return(y);
  13817. }
  13818. makestr(&tmpcache,s);
  13819. break;
  13820. default:
  13821. printf("?Unexpected switch value - internal error\n");
  13822. return(-9); /* (if) nothing malloc'd yet. */
  13823. }
  13824. }
  13825. if (cmresult.fdbaddr != &kw) { /* Checking... */
  13826. printf("?Unexpected result - internal error\n");
  13827. return(-9); /* Nothing malloc'd yet. */
  13828. }
  13829. n = cmresult.nresult; /* Get keyword value */
  13830. } else {
  13831. printf("?Unexpected Kerberos version - Internal error\n");
  13832. return(-9);
  13833. }
  13834. debug(F101,"kerberos action","",n);
  13835. switch (n) {
  13836. case KRB_A_IN: /* INITIALIZE */
  13837. case KRB_A_DE: /* DESTROY */
  13838. case KRB_A_LC: /* LIST-CREDENTIALS */
  13839. tmp_action = n; /* OK, set */
  13840. break;
  13841. default: /* Not OK, punt. */
  13842. printf("?Unexpected action - internal error\n");
  13843. return(-9);
  13844. }
  13845. if (tmp_action == KRB_A_IN) { /* Action is INITIALIZE */
  13846. int x;
  13847. cmfdbi(&sw, /* INITIALIZE switches */
  13848. _CMKEY, /* fcode */
  13849. "Principal,\n or optional INITIALIZE switch(es)", /* hlpmsg */
  13850. "", /* default (none) */
  13851. "", /* addtl string data */
  13852. kv == 4 ? krb4_i_n : krb5_i_n, /* Switch table size */
  13853. 4, /* addtl numeric data 2: 4 = cmswi */
  13854. xxstring, /* Processing function */
  13855. kv == 4 ? krb4_i_tbl : krb5_i_tbl, /* Switch table */
  13856. &fl /* Pointer to next FDB */
  13857. );
  13858. cmfdbi(&fl, /* 3rd FDB - command to send from */
  13859. _CMFLD, /* fcode */
  13860. "Principal", /* hlpmsg */
  13861. kv == 4 ? krb4_d_principal : krb5_d_principal, /* principal */
  13862. "", /* addtl string data */
  13863. 0, /* addtl numeric data 1 */
  13864. 0, /* addtl numeric data 2 */
  13865. xxstring,
  13866. NULL,
  13867. NULL
  13868. );
  13869. while (1) { /* Parse INIT switches or principal */
  13870. rc = cmfdb(&sw);
  13871. debug(F101,"kerberos cmfdb 2 rc","",rc);
  13872. if (rc < 0) {
  13873. if (rc == -3)
  13874. printf("?Principal name required\n");
  13875. goto kerbx;
  13876. }
  13877. debug(F101,"kerberos cmfdb 2 fcode","",cmresult.fcode);
  13878. if (cmresult.fcode != _CMKEY) /* Not a switch, quit switch loop */
  13879. break;
  13880. c = cmgbrk(); /* Switch - get break character */
  13881. debug(F101,"kerberos cmfdb 2 cmgbrk","",c);
  13882. getval = (c == ':' || c == '=');
  13883. if (getval && !(cmresult.kflags & CM_ARG)) {
  13884. printf("?This switch does not take arguments\n");
  13885. return(-9); /* OK because nothing malloc'd yet */
  13886. }
  13887. if (!getval && (cmgkwflgs() & CM_ARG)) {
  13888. printf("?This switch requires an argument\n");
  13889. return(-9);
  13890. }
  13891. n = cmresult.nresult; /* Numeric result = switch value */
  13892. switch (n) {
  13893. /* These don't take args... */
  13894. case KRB_I_PA: /* /PREAUTH */
  13895. case KRB_I_FW: /* /FORWARDABLE */
  13896. case KRB_I_PR: /* /PROXIABLE */
  13897. case KRB_I_RN: /* /RENEW */
  13898. case KRB_I_VA: /* /VALIDATE */
  13899. case KRB_I_NPA: /* /NOT-PREAUTH */
  13900. case KRB_I_NFW: /* /NOT-FORWARDABLE */
  13901. case KRB_I_NPR: /* /NOT-PROXIABLE */
  13902. case KRB_I_VB: /* /VERBOSE */
  13903. case KRB_I_BR: /* /BRIEF */
  13904. case KRB_I_K4: /* /KERBEROS4 */
  13905. case KRB_I_NK4: /* /NO-KERBEROS4 */
  13906. case KRB_I_POP: /* /POPUP */
  13907. case KRB_I_NAD: /* /NO-ADDRESSES */
  13908. if (getval) {
  13909. printf("?This switch does not take a value\n");
  13910. rc = -9;
  13911. goto kerbx;
  13912. }
  13913. switch (n) {
  13914. case KRB_I_NPA:
  13915. pv[KRB_I_PA].ival = 0;
  13916. break;
  13917. case KRB_I_NFW:
  13918. pv[KRB_I_FW].ival = 0;
  13919. break;
  13920. case KRB_I_NPR:
  13921. pv[KRB_I_PR].ival = 0;
  13922. break;
  13923. case KRB_I_VB:
  13924. pv[KRB_I_BR].ival = 0;
  13925. break;
  13926. case KRB_I_NK4:
  13927. pv[KRB_I_K4].ival = 0;
  13928. break;
  13929. default:
  13930. pv[n].ival = 1;
  13931. }
  13932. break;
  13933. /* These do take arguments */
  13934. case KRB_I_RB: /* /RENEWABLE:<minutes> */
  13935. pv[n].ival = 0;
  13936. if (!getval) break;
  13937. if ((rc = cmnum("Minutes",ckitoa(krb5_init.renewable),
  13938. 10,&y, xxstring)) < 0)
  13939. goto kerbx;
  13940. pv[n].ival = y;
  13941. break;
  13942. case KRB_I_LF: /* /LIFETIME:<minutes> */
  13943. pv[n].ival = 0;
  13944. /* Default is previous value */
  13945. sprintf(tmpbuf,"%d", /* SAFE */
  13946. kv == 4 ?
  13947. krb4_init.lifetime :
  13948. krb5_init.lifetime
  13949. );
  13950. if (!getval) break;
  13951. if ((rc = cmnum("Minutes",tmpbuf,10,&y, xxstring)) < 0)
  13952. goto kerbx;
  13953. pv[n].ival = y;
  13954. break;
  13955. case KRB_I_PD: /* /POSTDATE:<timestamp> */
  13956. if (pv[n].sval) {
  13957. free(pv[n].sval);
  13958. pv[n].sval = NULL;
  13959. }
  13960. if (!getval) break;
  13961. if ((rc = cmdate("date-time","",&s,0,xxstring)) < 0)
  13962. goto kerbx;
  13963. makestr(&(pv[n].sval),s);
  13964. break;
  13965. case KRB_I_SR: /* /SERVICE:<name> */
  13966. if (pv[n].sval) {
  13967. free(pv[n].sval);
  13968. pv[n].sval = NULL;
  13969. }
  13970. if (!getval) break;
  13971. if ((rc = cmfld("Service-name","",&s,xxstring)) < 0)
  13972. goto kerbx;
  13973. makestr(&(pv[n].sval),s);
  13974. break;
  13975. case KRB_I_RL: /* /REALM:<name> */
  13976. if (pv[n].sval) {
  13977. free(pv[n].sval);
  13978. pv[n].sval = NULL;
  13979. }
  13980. if (!getval) break;
  13981. if (kv == 4)
  13982. p = krb4_d_realm ? krb4_d_realm : "";
  13983. else
  13984. p = krb5_d_realm ? krb5_d_realm : "";
  13985. if ((rc = cmfld("Realm",p,&s,xxstring)) < 0)
  13986. goto kerbx;
  13987. makestr(&(pv[n].sval),s);
  13988. break;
  13989. case KRB_I_IN: /* /INSTANCE:<name> */
  13990. if (pv[n].sval) {
  13991. free(pv[n].sval);
  13992. pv[n].sval = NULL;
  13993. }
  13994. if (!getval) break;
  13995. if (kv == 4)
  13996. p = krb4_d_instance ? krb4_d_instance : "";
  13997. else
  13998. p = krb5_d_instance ? krb5_d_instance : "";
  13999. if ((rc = cmfld("Instance",p,&s,xxstring)) < 0)
  14000. goto kerbx;
  14001. makestr(&(pv[n].sval),s);
  14002. break;
  14003. case KRB_I_PW: /* /PASSWORD:<password> */
  14004. debok = 0;
  14005. if (pv[n].sval) {
  14006. free(pv[n].sval);
  14007. pv[n].sval = NULL;
  14008. }
  14009. if (!getval) break;
  14010. if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  14011. if (rc != -3)
  14012. goto kerbx;
  14013. makestr(&(pv[n].sval),s);
  14014. break;
  14015. case KRB_I_ADR: /* /ADDRESSES:{<address-list>} */
  14016. if (pv[n].sval) {
  14017. free(pv[n].sval);
  14018. pv[n].sval = NULL;
  14019. }
  14020. if (!getval) break;
  14021. if ((rc = cmfld("List of IP addresses","",&s,xxstring)) < 0)
  14022. goto kerbx;
  14023. makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  14024. for (i = 0; i < KRB5_NUM_OF_ADDRS && tmpaddrs[i]; i++) {
  14025. if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  14026. printf("invalid ip address: %s\n",tmpaddrs[i]);
  14027. rc = -9;
  14028. goto kerbx;
  14029. }
  14030. }
  14031. pv[KRB_I_NAD].ival = 0;
  14032. break;
  14033. default:
  14034. printf("?Unexpected switch value - internal error\n");
  14035. rc = -9;
  14036. goto kerbx;
  14037. }
  14038. }
  14039. if (cmresult.fcode != _CMFLD) {
  14040. printf("?Unexected result - internal error\n");
  14041. rc = -9;
  14042. goto kerbx;
  14043. }
  14044. /* cmresult.sresult may be of the form PRINCIPAL@REALM */
  14045. i = ckindex("@",cmresult.sresult,0,0,0);
  14046. if (i != 0) {
  14047. makestr(&tmprealm,&cmresult.sresult[i]);
  14048. cmresult.sresult[i-1] = '\0';
  14049. }
  14050. makestr(&tmpprinz,cmresult.sresult); /* Principal (user) */
  14051. if ((rc = cmcfm()) < 0) { /* Now get confirmation */
  14052. if (rc == -3) {
  14053. printf("?Principal name required\n");
  14054. }
  14055. goto kerbx;
  14056. }
  14057. if (!tmpprinz || !tmpprinz[0]) {
  14058. printf("?Principal name required\n");
  14059. goto kerbx;
  14060. }
  14061. if (!pv[KRB_I_RN].ival && !pv[KRB_I_VA].ival) {
  14062. /* Don't use a password if Validating or Renewing */
  14063. if (pv[KRB_I_PW].sval) { /* If they gave a /PASSWORD switch */
  14064. makestr(&tmppswd,pv[KRB_I_PW].sval); /* use this value */
  14065. }
  14066. #ifdef COMMENT
  14067. /* Password prompting has been moved to ck_krb[45]_initTGT() */
  14068. else { /* Otherwise must prompt for it */
  14069. char prmpt[80];
  14070. if (pv[KRB_I_RL].sval)
  14071. sprintf(prmpt,"%s@%s's Password: ",
  14072. tmpprinz,pv[KRB_I_RL].sval);
  14073. else if (tmprealm)
  14074. sprintf(prmpt,"%s@%s's Password: ",
  14075. tmpprinz,tmprealm);
  14076. else
  14077. sprintf(prmpt,"%s's Password: ",tmpprinz);
  14078. #ifdef OS2
  14079. if (pv[KRB_I_POP].ival) {
  14080. char passwd[80]="";
  14081. readpass(prmpt,passwd,80);
  14082. makestr(&tmppswd,passwd);
  14083. memset(passwd,0,80);
  14084. } else
  14085. #endif /* OS2 */
  14086. {
  14087. #ifdef CK_RECALL
  14088. on_recall = 0;
  14089. #endif /* CK_RECALL */
  14090. cmsavp(psave,PROMPTL); /* Save old prompt */
  14091. cmsetp(prmpt); /* Make new prompt */
  14092. concb((char)escape); /* Put console in cbreak mode */
  14093. cmini(0); /* and no-echo mode */
  14094. /* Issue prompt if at top level */
  14095. if (pflag) prompt(xxstring);
  14096. cmres(); /* Reset the parser */
  14097. for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  14098. /* Get a literal line of text */
  14099. rc = cmtxt("","",&s,NULL);
  14100. cmres(); /* Reset the parser again */
  14101. }
  14102. makestr(&tmppswd,s);
  14103. printf("\n"); /* Echo a CRLF */
  14104. cmsetp(psave); /* Restore original prompt */
  14105. }
  14106. }
  14107. x = 0; /* Check for password */
  14108. if (tmppswd)
  14109. if (*tmppswd)
  14110. x = 1;
  14111. if (!x) {
  14112. printf("?Password required\n");
  14113. goto kerbx;
  14114. }
  14115. #endif /* COMMENT */
  14116. }
  14117. } else if (kv == 5 && tmp_action == KRB_A_LC) { /* LIST-CREDENTIALS */
  14118. tmp_klc = 0;
  14119. while (1) {
  14120. if ((x = cmkey(klctab,nklctab,"Switch","",xxstring)) < 0) {
  14121. if (x == -3) {
  14122. if ((rc = cmcfm()) < 0)
  14123. goto kerbx;
  14124. else
  14125. break;
  14126. } else {
  14127. rc = x;
  14128. goto kerbx;
  14129. }
  14130. }
  14131. tmp_klc |= x;
  14132. }
  14133. } else if ((rc = cmcfm()) < 0) /* DESTROY, just confirm */
  14134. goto kerbx;
  14135. /* Done - Move confirmed data to final locations */
  14136. krb_action = tmp_action; /* Action requested */
  14137. krb_op.version = kv; /* Kerberos version */
  14138. krb_op.cache = tmpcache; /* Cache file */
  14139. tmpcache = NULL; /* So we don't free it */
  14140. switch (krb_action) {
  14141. case KRB_A_IN: /* INITIALIZE */
  14142. if (kv == 5) {
  14143. krb5_init.forwardable = pv[KRB_I_FW].ival;
  14144. krb5_init.proxiable = pv[KRB_I_PR].ival;
  14145. krb5_init.lifetime = pv[KRB_I_LF].ival;
  14146. krb5_init.renew = pv[KRB_I_RN].ival;
  14147. krb5_init.renewable = pv[KRB_I_RB].ival;
  14148. krb5_init.validate = pv[KRB_I_VA].ival;
  14149. /* Here we just reassign the pointers and then set them to NULL */
  14150. /* so they won't be freed below. */
  14151. krb5_init.postdate = pv[KRB_I_PD].sval; pv[KRB_I_PD].sval = NULL;
  14152. krb5_init.service = pv[KRB_I_SR].sval; pv[KRB_I_SR].sval = NULL;
  14153. if (pv[KRB_I_RL].sval) {
  14154. krb5_init.realm = pv[KRB_I_RL].sval; pv[KRB_I_RL].sval = NULL;
  14155. } else if (tmprealm) {
  14156. krb5_init.realm = tmprealm; tmprealm = NULL;
  14157. }
  14158. if (pv[KRB_I_IN].sval) {
  14159. krb5_init.instance = pv[KRB_I_IN].sval;
  14160. pv[KRB_I_IN].sval = NULL;
  14161. } else if ( tmpinst ) {
  14162. krb5_init.instance = tmpinst;
  14163. tmpinst = NULL;
  14164. }
  14165. if (tmpprinz) {
  14166. krb5_init.principal = tmpprinz;
  14167. tmpprinz = NULL;
  14168. }
  14169. krb5_init.password = tmppswd;
  14170. tmppswd = NULL;
  14171. krb5_init.getk4 = pv[KRB_I_K4].ival;
  14172. if (krb5_init.getk4) {
  14173. krb4_init.lifetime = pv[KRB_I_LF].ival;
  14174. if (krb5_init.realm)
  14175. makestr(&krb4_init.realm,krb5_init.realm);
  14176. krb4_init.preauth = krb4_d_preauth;
  14177. krb4_init.verbose = pv[KRB_I_BR].ival ? 0 : 1;
  14178. if (krb5_init.principal)
  14179. makestr(&krb4_init.principal,krb5_init.principal);
  14180. if (krb5_init.principal)
  14181. makestr(&krb4_init.password,krb5_init.password);
  14182. }
  14183. krb5_init.no_addresses = pv[KRB_I_NAD].ival;
  14184. if (tmpaddrs[0]) {
  14185. for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14186. if (krb5_init.addrs[i]) {
  14187. free(krb5_init.addrs[i]);
  14188. krb5_init.addrs[i] = NULL;
  14189. }
  14190. krb5_init.addrs[i] = tmpaddrs[i];
  14191. tmpaddrs[i] = NULL;
  14192. }
  14193. }
  14194. } else if (kv == 4) { /* Same deal for Kerberos 4 */
  14195. krb4_init.lifetime = pv[KRB_I_LF].ival;
  14196. if (pv[KRB_I_RL].sval) {
  14197. krb4_init.realm = pv[KRB_I_RL].sval;
  14198. pv[KRB_I_RL].sval = NULL;
  14199. } else if ( tmprealm ) {
  14200. krb4_init.realm = tmprealm;
  14201. tmprealm = NULL;
  14202. }
  14203. if (pv[KRB_I_IN].sval) {
  14204. krb4_init.instance = pv[KRB_I_IN].sval;
  14205. pv[KRB_I_IN].sval = NULL;
  14206. } else if ( tmpinst ) {
  14207. krb4_init.instance = tmpinst;
  14208. tmpinst = NULL;
  14209. }
  14210. krb4_init.preauth = pv[KRB_I_PA].ival;
  14211. krb4_init.verbose = pv[KRB_I_BR].ival ? 0 : 1;
  14212. if (tmpprinz) {
  14213. krb4_init.principal = tmpprinz;
  14214. tmpprinz = NULL;
  14215. }
  14216. krb4_init.password = tmppswd;
  14217. tmppswd = NULL;
  14218. }
  14219. break;
  14220. case KRB_A_LC: /* List Credentials */
  14221. krb5_lc.encryption = tmp_klc & XYKLCEN;
  14222. krb5_lc.flags = tmp_klc & XYKLCFL;
  14223. krb5_lc.addr = tmp_klc & XYKLCAD;
  14224. break;
  14225. }
  14226. /* Common exit - Free temporary storage */
  14227. kerbx:
  14228. for (i = 0; i <= KRB_I_MAX; i++) { /* Free malloc'd switch data */
  14229. if (pv[i].sval)
  14230. free(pv[i].sval);
  14231. }
  14232. for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14233. if (tmpaddrs[i])
  14234. free(tmpaddrs[i]);
  14235. }
  14236. if (tmpprinz) free(tmpprinz); /* And these too. */
  14237. if (tmppswd) free(tmppswd);
  14238. if (tmpcache) free(tmpcache);
  14239. if (tmprealm) free(tmprealm);
  14240. if (tmpinst) free(tmpinst);
  14241. return(rc); /* Return the return code */
  14242. }
  14243. #endif /* CK_KERBEROS */
  14244. #ifdef CK_LOGIN
  14245. int
  14246. #ifdef CK_ANSIC
  14247. ckxlogin(CHAR * userid, CHAR * passwd, CHAR * acct, int promptok)
  14248. #else /* CK_ANSIC */
  14249. ckxlogin(userid, passwd, acct, promptok)
  14250. CHAR * userid; CHAR * passwd; CHAR * acct; int promptok;
  14251. #endif /* CK_ANSIC */
  14252. /* ckxlogin */ {
  14253. #ifdef CK_RECALL
  14254. extern int on_recall; /* around Password prompting */
  14255. #endif /* CK_RECALL */
  14256. #ifdef COMMENT
  14257. extern int guest;
  14258. #endif /* COMMENT */
  14259. int rprompt = 0; /* Restore prompt */
  14260. #ifdef CKSYSLOG
  14261. int savlog;
  14262. #endif /* CKSYSLOG */
  14263. extern int what, srvcdmsg;
  14264. int x = 0, ok = 0, rc = 0;
  14265. CHAR * _u = NULL, * _p = NULL, * _a = NULL;
  14266. debug(F111,"ckxlogin userid",userid,promptok);
  14267. debug(F110,"ckxlogin passwd",passwd,0);
  14268. isguest = 1; /* Global "anonymous" flag */
  14269. userid = "anonymous"; /* Default to anonymous guest */
  14270. passwd = "anonymous"; /* Default to anonymous without password */
  14271. if (!userid) userid = (CHAR *)"";
  14272. if (!passwd) passwd = (CHAR *)"";
  14273. debug(F111,"ckxlogin userid",userid,what);
  14274. #ifdef CK_RECALL
  14275. on_recall = 0;
  14276. #endif /* CK_RECALL */
  14277. #ifdef CKSYSLOG
  14278. savlog = ckxsyslog; /* Save and turn off syslogging */
  14279. #endif /* CKSYSLOG */
  14280. if ((!*userid || !*passwd) && /* Need to prompt for missing info */
  14281. promptok) {
  14282. cmsavp(psave,PROMPTL); /* Save old prompt */
  14283. debug(F110,"ckxlogin saved",psave,0);
  14284. rprompt = 1;
  14285. }
  14286. if (!*userid) {
  14287. if (!promptok)
  14288. return(0);
  14289. cmsetp("Username: "); /* Make new prompt */
  14290. concb((char)escape); /* Put console in cbreak mode */
  14291. cmini(1);
  14292. /* Flush typeahead */
  14293. #ifdef IKS_OPTION
  14294. debug(F101,
  14295. "ckxlogin TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14296. "",
  14297. TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14298. );
  14299. #endif /* IKS_OPTION */
  14300. while (ttchk() > 0) {
  14301. x = ttinc(0);
  14302. debug(F101,"ckxlogin flush user x","",x);
  14303. if (x < 0)
  14304. doexit(GOOD_EXIT,0); /* Connection lost */
  14305. #ifdef TNCODE
  14306. if (sstelnet) {
  14307. if (x == IAC) {
  14308. x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14309. debug(F101,"ckxlogin user tn_doop","",x);
  14310. #ifdef IKS_OPTION
  14311. debug(F101,
  14312. "ckxlogin user TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14313. "",
  14314. TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14315. );
  14316. #endif /* IKS_OPTION */
  14317. if (x < 0)
  14318. goto XCKXLOG;
  14319. switch (x) {
  14320. case 1: ckxech = 1; break; /* Turn on echoing */
  14321. case 2: ckxech = 0; break; /* Turn off echoing */
  14322. #ifdef IKS_OPTION
  14323. case 4: /* IKS event */
  14324. if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14325. break; /* else fall thru... */
  14326. #endif /* IKS_OPTION */
  14327. case 6: /* Logout */
  14328. goto XCKXLOG;
  14329. }
  14330. }
  14331. }
  14332. #endif /* TNCODE */
  14333. }
  14334. if (pflag) prompt(xxstring); /* Issue prompt if at top level */
  14335. cmres(); /* Reset the parser */
  14336. for (x = -1; x < 0;) { /* Prompt till they answer */
  14337. /* Get a literal line of text */
  14338. x=cmtxt("Your username, or \"ftp\", or \"anonymous\"","",&s,NULL);
  14339. if (x == -4 || x == -10) {
  14340. printf("\r\n%sLogin cancelled\n",
  14341. x == -10 ? "Timed out: " : "");
  14342. #ifdef CKSYSLOG
  14343. ckxsyslog = savlog;
  14344. #endif /* CKSYSLOG */
  14345. doexit(GOOD_EXIT,0);
  14346. }
  14347. if (sstate) /* Did a packet come instead? */
  14348. goto XCKXLOG;
  14349. cmres(); /* Reset the parser again */
  14350. }
  14351. if ((_u = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14352. printf("?Internal error: malloc\n");
  14353. goto XCKXLOG;
  14354. } else {
  14355. strcpy((char *)_u,s); /* safe */
  14356. userid = _u;
  14357. }
  14358. }
  14359. ok = zvuser((char *)userid); /* Verify username */
  14360. debug(F111,"ckxlogin zvuser",userid,ok);
  14361. if (!*passwd && promptok
  14362. #ifdef COMMENT
  14363. && guest
  14364. #endif /* COMMENT */
  14365. ) {
  14366. char prmpt[80];
  14367. #ifdef CKSYSLOG
  14368. savlog = ckxsyslog; /* Save and turn off syslogging */
  14369. ckxsyslog = 0;
  14370. #endif /* CKSYSLOG */
  14371. /* Flush typeahead again */
  14372. while (ttchk() > 0) {
  14373. x = ttinc(0);
  14374. debug(F101,"ckxlogin flush user x","",x);
  14375. #ifdef TNCODE
  14376. if (sstelnet) {
  14377. if (x == IAC) {
  14378. x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14379. debug(F101,"ckxlogin pass tn_doop","",x);
  14380. #ifdef IKS_OPTION
  14381. debug(F101,
  14382. "ckxlogin pass TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14383. "",
  14384. TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14385. );
  14386. #endif /* IKS_OPTION */
  14387. if (x < 0)
  14388. goto XCKXLOG;
  14389. switch (x) {
  14390. case 1: ckxech = 1; break; /* Turn on echoing */
  14391. case 2: ckxech = 0; break; /* Turn off echoing */
  14392. case 4: /* IKS event */
  14393. if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14394. break; /* else fall thru... */
  14395. case 6: /* Logout */
  14396. goto XCKXLOG;
  14397. }
  14398. }
  14399. }
  14400. #endif /* TNCODE */
  14401. }
  14402. if (!strcmp((char *)userid,"anonymous") ||
  14403. !strcmp((char *)userid,"ftp")) {
  14404. if (!ok)
  14405. goto XCKXLOG;
  14406. ckstrncpy(prmpt,"Enter e-mail address: ",80);
  14407. } else if (*userid && strlen((char *)userid) < 60) {
  14408. #ifdef NT
  14409. extern CHAR * pReferenceDomainName;
  14410. if (pReferenceDomainName)
  14411. ckmakxmsg(prmpt,
  14412. 80,
  14413. "Enter ",
  14414. pReferenceDomainName,
  14415. "\\\\",
  14416. userid,
  14417. "'s Password: ",
  14418. NULL,NULL,NULL,NULL,NULL,NULL,NULL
  14419. );
  14420. else
  14421. #endif /* NT */
  14422. ckmakmsg(prmpt,80,"Enter ",(char *)userid,"'s Password: ",NULL);
  14423. } else
  14424. ckstrncpy(prmpt,"Enter Password: ",80);
  14425. cmsetp(prmpt); /* Make new prompt */
  14426. concb((char)escape); /* Put console in cbreak mode */
  14427. if (strcmp((char *)userid,"anonymous") &&
  14428. strcmp((char *)userid,"ftp")) { /* and if not anonymous */
  14429. debok = 0;
  14430. cmini(0); /* and no-echo mode */
  14431. } else {
  14432. cmini(1);
  14433. }
  14434. if (pflag) prompt(xxstring); /* Issue prompt if at top level */
  14435. cmres(); /* Reset the parser */
  14436. for (x = -1; x < 0;) { /* Prompt till they answer */
  14437. #ifdef CK_PAM
  14438. gotemptypasswd=0;
  14439. #endif /* CK_PAM */
  14440. x = cmtxt("","",&s,NULL); /* Get a literal line of text */
  14441. if (x == -4 || x == -10) {
  14442. printf("\r\n%sLogin cancelled\n",
  14443. x == -10 ? "Timed out: " : "");
  14444. #ifdef CKSYSLOG
  14445. ckxsyslog = savlog;
  14446. #endif /* CKSYSLOG */
  14447. doexit(GOOD_EXIT,0);
  14448. }
  14449. #ifdef CK_PAM
  14450. if (!*s)
  14451. gotemptypasswd = 1;
  14452. #endif /* CK_PAM */
  14453. if (sstate) /* In case of a Kermit packet */
  14454. goto XCKXLOG;
  14455. cmres(); /* Reset the parser again */
  14456. }
  14457. printf("\r\n"); /* Echo a CRLF */
  14458. if ((_p = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14459. printf("?Internal error: malloc\n");
  14460. goto XCKXLOG;
  14461. } else {
  14462. strcpy((char *)_p,s); /* safe */
  14463. passwd = _p;
  14464. }
  14465. }
  14466. #ifdef CK_PAM
  14467. else {
  14468. cmres(); /* Reset the parser */
  14469. /* We restore the prompt now because the PAM engine will call */
  14470. /* readpass() which will overwrite psave. */
  14471. if (rprompt) {
  14472. cmsetp(psave); /* Restore original prompt */
  14473. debug(F110,"ckxlogin restored",psave,0);
  14474. rprompt = 0;
  14475. }
  14476. }
  14477. #endif /* CK_PAM */
  14478. #ifdef CKSYSLOG
  14479. ckxsyslog = savlog;
  14480. #endif /* CKSYSLOG */
  14481. if (ok) {
  14482. ok = zvpass((char *)passwd); /* Check password */
  14483. debug(F101,"ckxlogin zvpass","",ok);
  14484. #ifdef CK_PAM
  14485. } else {
  14486. /* Fake pam password failure for nonexistent users */
  14487. sleep(1);
  14488. printf("Authentication failure\n");
  14489. #endif /* CK_PAM */
  14490. }
  14491. if (ok > 0 && isguest) {
  14492. #ifndef NOPUSH
  14493. nopush = 1;
  14494. #endif /* NOPUSH */
  14495. srvcdmsg = 1;
  14496. }
  14497. rc = ok; /* Set the return code */
  14498. if ((char *)uidbuf != (char *)userid)
  14499. ckstrncpy(uidbuf,(char *)userid,UIDBUFLEN); /* Remember username */
  14500. XCKXLOG: /* Common exit */
  14501. #ifdef CKSYSLOG
  14502. ckxsyslog = savlog; /* In case of GOTO above */
  14503. #endif /* CKSYSLOG */
  14504. if (rprompt) {
  14505. cmsetp(psave); /* Restore original prompt */
  14506. debug(F110,"ckxlogin restored",psave,0);
  14507. }
  14508. if (_u || _p || _a) {
  14509. if (_u) free(_u);
  14510. if (_p) free(_p);
  14511. if (_a) free(_a);
  14512. }
  14513. return(rc);
  14514. }
  14515. int
  14516. ckxlogout() {
  14517. doexit(GOOD_EXIT,0); /* doexit calls zvlogout */
  14518. return(0); /* not reached */
  14519. }
  14520. #endif /* CK_LOGIN */
  14521. #endif /* NOICP */