; TeX output 1994.08.03:14283ڍ&gUNj cmbx12UGNUƧHistoryLibrary 0G c2K`y 3 cmr10Editionf2.0,for3isnegativ!e,thesearchproMceedsbackwardfrompMos,otherwiseforward.ReturnsUthefabsoluteindexofthehistoryelemen!twherestring~wasfound,or-1otherwise.EyLM2.3.6d(ManagingMtheHistoryFile#)썑The[Historylibrarycanreadthehistoryfromandwriteittoa le. ThissectiondoMcumen!tsthefunctionsfformanagingahistory le.Feunctionintread#؎historyy(charf*filename)UAddgthecon!tentsgof lenamentothehistorylist,galineatatime.If lenameisNULL,Uthenfreadfrom`~/.history'.Returns0ifsuccessful,orerrnoifnot.Feunctionintread#؎history#؎rangey(charf*filename,intfrom,intto)UReadHarangeoflinesfrom lename,@addingthemtothehistorylist.aStartreadingatUline+fromandendatto.tIffromiszero,startatthebMeginning.Iftoislessthanfrom,Uthen readun!tiltheendofthe le. If lenameisNULL,#thenreadfrom`~/.history'.UReturnsf0ifsuccessful,orerrnoifnot. <10cOGNUfHistoryLibrary3ڍЍFeunctionintwrite#؎historyy(charf*filename)UWeritethecurren!thistoryto lename,overwriting lenameWifnecessarye.If lenameUisLNULL,.thenwritethehistorylistto`~/.history'.$Vealuesreturnedareasinread_Uhistoryf().&/퍍Feunctionintappb"end#؎historyy(intfnelements,char*filename)UAppMendfthelastnelemen!tsofthehistorylistto lename.Feunctioninthistory#؎truncate#؎ ley(charf*filename,intnlines)UTeruncatefthehistory le lename,lea!vingonlythelastnlineslines.0_ڍM2.3.7d(HistoryMExpansion!Theseffunctionsimplemen!tcsh-likehistoryexpansion.Feunctioninthistory#؎expandy(charf*string,char**output)UExpandstring,Zplacingtheresultin!tooutput,apMoin!tertoastring(seeSection1.1U[HistoryfIn!teraction],page1).Returns:#U0VHIfnoexpansionstoMokplace(or,Xiiftheonlyc!hangeinthetextwastheVHde-slashifyingfofthehistoryexpansionc!haracter);/U1VHiffexpansionsdidtak!eplace;U-1VHifftherew!asanerrorinexpansion;U2VHif-thereturnedlineshouldonlybMedispla!yed,Ebut-notexecuted,aswiththeVH:pfmoMdi er(seeSection1.1.3[Modi ers],page2).UIffanerroroMcurredinexpansion,thenoutputfcon!tainsadescriptiveerrormessage.&/퍍Feunctionchar*history#؎arg#؎extracty(intffirst,intlast,char*string)UExtractZastringsegmen!tconsistingofthe rstZthroughlastargumen!tspresentinstring.UArgumen!tsfarebrokenupasinBash.Feunctionchar*get#؎history#؎eventy(charf*string,int*cindex,intqchar)UReturnsTthetextofthehistoryev!entTbMeginningatstringl+*cindex.,*cindexismodi edUtopMoin!ttoaftertheeventspMeci er.Atfunctionentrye,cindexLpMointstotheindexinto HChapterf2:ProgrammingwithGNUHistory}113ڍЍUstring#where3thehistoryev!ent3spMeci cationbegins.qc!harisacharacterthatisallowedUtofendtheev!entfspMeci cationinadditiontothe\normal"terminatingc!haracters.)썍Feunctionchar**history#؎tokenizey(charf*string)UReturn anarra!yoftokensparsedoutofstring,?omuchastheshellmight.M&ThetokensUare~splitonwhitespaceandonthec!haracters()<>;&|$,:yandshellquotingconventionsUarefobMey!ed.>očE2.4HistoryMVfariables!ThisfsectiondescribMestheexternallyvisiblevdDariablesexportedb!ytheGNUHistoryLibrarye..Veariableinthistory#؎baseUTheflogicalo setofthe rsten!tryinthehistorylist..Veariableinthistory#؎lengthUThefn!umbMerofentriescurrentlystoredinthehistorylist..Veariableintmax#؎input#؎historyUThemaxim!umnumbMerofhistoryentries.ThismustbMechangedusingstifle_historyU()..Veariablecharhistory#؎expansion#؎charUThefc!haracterthatstartsahistoryevent.Thedefaultis`!'..Veariablecharhistory#؎subst#؎charUThe8c!haracterthatinvokeswordsubstitutioniffoundatthestartofaline.#ThedefaultUisf`^'..Veariablecharhistory#؎comment#؎charUDuringYtok!enization,(ifthischaracterisseenasthe rstcharacterofaword,(thenitandUallTGsubsequen!tcharactersuptoanewlineareignored,suppressinghistoryexpansionUforftheremainderoftheline.Thisisdisabledb!ydefault. Qߍ12cOGNUfHistoryLibrary3ڍЍ.Veariablechar*history#؎no#؎expand#؎charsUTheline);J}?fQelseif(strncmp(line,"delete",6)==0)J{Vdintwhich;Vdif((sscanf(line+6,"%d",&which))==1)aM{mcHIST_ENTRY*entry=remove_history(which);mcif(!entry)xfprintf(stderr,"Nosuchentry%d\n",which);mcelsex{bIfree(entry->line);bIfree(entry);x}aM}VdelseaM{mcfprintf(stderr,"non-numericarggivento`delete'\n");aM}J}3}U}_U14cOGNUfHistoryLibrary3ڟd@AppMendixfA:ConceptIndexC;153ڍЍApp=endixMA QConceptIndexu\(EAo cmr9anc9horedTsearch{ꍑU5" cmmi9:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:8EEev9entTdesignatorsVU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: 1 expansion`͍U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:1 EH historyTev9entsxU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:1 HistoryTSearc9hing4U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:8d16cOGNUfHistoryLibrary3ڟl>AppMendixfB:FeunctionandVariableIndex173ڍЍApp=endixMB QFaGunctionandVariableIndex\(xEAߤN cmtt9add$c4Žfhistory(؍U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:Z7append$c4Žfhistory U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: ;K10ECcurrent$c4ŽfhistoryčU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: .8EGget$c4Žfhistory$c4Ževent/U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:10EHhistory$c4Žfarg$c4Žextract* U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:[Ĭ10history$c4Žfbase1`U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:MǬ11history$c4Žfcomment$c4ŽchartXU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:11history$c4Žfexpand U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: ;K10history$c4Žfexpansion$c4Žchar2U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:11history$c4Žfget(؍U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:Z8history$c4Žfget$c4Žhistory$c4Žstate=U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:oq6history$c4Žfis$c4ŽstifledcU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:7history$c4Žflength:U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:11history$c4ŽflistEU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: 7history$c4Žfno$c4Žexpand$c4Žchars1U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:N^12history$c4Žfsearch=U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:nڬ9history$c4Žfsearch$c4ŽposcU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:9history$c4Žfsearch$c4ŽprefixΪU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:e9history$c4Žfset$c4Žhistory$c4Žstate=U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:oq6history$c4Žfset$c4Žpos䍑U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:ɟ8history$c4Žfsubst$c4Žchar~U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: -11x history$c4ŽftokenizeljU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:%11 history$c4Žftotal$c4ŽbyteskЍU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:8 history$c4Žftruncate$c4Žfile㍑U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:10 EM max$c4Žfinput$c4ŽhistoryQٍU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:n@11 EN next$c4ŽfhistoryEU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: 8 EP previous$c4Žfhistory1U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:8 ER read$c4ŽfhistoryEU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U: 9 read$c4Žfhistory$c4ŽrangecU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:9 remove$c4Žfhistory=U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:nڬ7 replace$c4Žfhistory$c4ŽentryΪU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:e7 ES stifle$c4Žfhistory=U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:nڬ7 EU unstifle$c4Žfhistory1U:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:7 using$c4ŽfhistoryU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:m6 EW where$c4ŽfhistoryU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:m8 write$c4ŽfhistoryU:pU:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:U:m9l18cOGNUfHistoryLibrary3ڟSҶi3ڍЍTaGableMofConutents*E132UsingffHistoryInteractively232Kgff cmmi12K:Q 32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32: E1$1.1 5HistoryfIn!teraction9q9 b> 3 cmmi10:ۍ::::::::::::::::::::::::::::::::::::::::::::::: 1H1.1.1 5Ev!entfDesignatorsd:ۍ:::::::::::::::::::::::::::::::::::::::01H1.1.2 5WeordfDesignators76:ۍ::::::::::::::::::::::::::::::::::::::: n2H1.1.3 5MoMdi ersf:ۍ::::::::::::::::::::::::::::::::::::::::::::::: (2E232ProgrammingffwithGNUHistory֍32K:Q 32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32: =E5$2.1 5In!troMductionftoHistoryv:ۍ:::::::::::::::::::::::::::::::::::::::::::5$2.2 5HistoryfStorage#:ۍ:::::::::::::::::::::::::::::::::::::::::::::::::: F5$2.3 5HistoryfFeunctionsҍ:ۍ:::::::::::::::::::::::::::::::::::::::::::::::: B 6H2.3.1 5InitializingfHistoryandStateManagemen!t?̍:ۍ:::::::::::::: 6H2.3.2 5HistoryfListManagemen!tK:ۍ::::::::::::::::::::::::::::::: 7H2.3.3 5InformationfAbMouttheHistoryList&:ۍ::::::::::::::::::::::7H2.3.4 5Mo!vingfAroundtheHistoryListts:ۍ:::::::::::::::::::::::::8H2.3.5 5Searc!hingftheHistoryListm:ۍ::::::::::::::::::::::::::::::: 8H2.3.6 5ManagingftheHistoryFile2M:ۍ:::::::::::::::::::::::::::::::9H2.3.7 5HistoryfExpansionҍ:ۍ::::::::::::::::::::::::::::::::::::: [ 10$2.4 5HistoryfVeariablesH:ۍ::::::::::::::::::::::::::::::::::::::::::::::::G11$2.5 5HistoryfProgrammingExample瘍:ۍ:::::::::::::::::::::::::::::::::: k12EApps3endixffA32ConceptIndexP32K:Q 32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:32:E15!Apps3endixffB32FfunctionandVariableIndexį32K:Q 32:32:32:32:32:32:32:32:32:32: |E17iih-GNUfHistoryLibrary3ڟ/;3GUNj cmbx12MN # cmbx12Kgff cmmi12ENff cmbx12=NG cmbx12< 3 cmmi107m#R 3 cmss106p0J 3 cmsl103