Lines Matching refs:hp

71 #define hist_ind(hp,c)	((int)((c)&(hp)->histmask))  argument
133 static int acctinit(History_t *hp) in acctinit() argument
136 Namval_t *np = nv_search("ACCTFILE",((Shell_t*)hp->histshell)->var_tree,0); in acctinit()
178 static int sh_checkaudit(History_t *hp, const char *name, char *logbuf, size_t len) in sh_checkaudit() argument
231 register History_t *hp; in sh_histinit() local
251 if(hp=wasopen) in sh_histinit()
255 shgd->hist_ptr = hist_ptr = hp; in sh_histinit()
256 if(strcmp(histname,hp->histname)==0) in sh_histinit()
309 if(!(hp=new_of(History_t,(--histmask)*sizeof(off_t)))) in sh_histinit()
314 shgd->hist_ptr = hist_ptr = hp; in sh_histinit()
315 hp->histshell = (void*)shp; in sh_histinit()
316 hp->histsize = maxlines; in sh_histinit()
317 hp->histmask = histmask; in sh_histinit()
318 hp->histfp= sfnew(NIL(Sfio_t*),hp->histbuff,HIST_BSIZE,fd,SF_READ|SF_WRITE|SF_APPENDWR|SF_SHARE); in sh_histinit()
319 memset((char*)hp->histcmds,0,sizeof(off_t)*(hp->histmask+1)); in sh_histinit()
320 hp->histind = 1; in sh_histinit()
321 hp->histcmds[1] = 2; in sh_histinit()
322 hp->histcnt = 2; in sh_histinit()
323 hp->histname = strdup(histname); in sh_histinit()
324 hp->histdisc = hist_disc; in sh_histinit()
328 sfwrite(hp->histfp,(char*)hist_stamp,2); in sh_histinit()
329 sfsync(hp->histfp); in sh_histinit()
336 hp->histind = first = hist_nearend(hp,hp->histfp,hsize-size); in sh_histinit()
338 hist_eof(hp); /* this sets histind to last command */ in sh_histinit()
339 if((hist_start = (last=(int)hp->histind)-maxlines) <=0) in sh_histinit()
341 mark = hp->histmarker; in sh_histinit()
345 first = hist_nearend(hp,hp->histfp,hsize-size); in sh_histinit()
346 hp->histind = first; in sh_histinit()
349 hist_eof(hp); in sh_histinit()
352 sfseek(hp->histfp,hp->histcnt=hsize,SEEK_SET); in sh_histinit()
353 hp->histind = last; in sh_histinit()
354 hp->histmarker = mark; in sh_histinit()
369 hp = hist_trim(hp,(int)hp->histind-maxlines); in sh_histinit()
371 sfdisc(hp->histfp,&hp->histdisc); in sh_histinit()
373 (HISTCUR)->nvalue.lp = (&hp->histind); in sh_histinit()
375 sh_timeradd(1000L*(HIST_RECENT-30), 1, hist_touch, (void*)hp->histname); in sh_histinit()
378 acctinit(hp); in sh_histinit()
383 hp->auditfp = 0; in sh_histinit()
384 …if(sh_isstate(SH_INTERACTIVE) && (hp->auditmask=sh_checkaudit(hp,SHOPT_AUDITFILE, buff, sizeof(buf… in sh_histinit()
398 hp->tty = strdup(ttyname(2)); in sh_histinit()
399 hp->auditfp = sfnew((Sfio_t*)0,NULL,-1,fd,SF_WRITE); in sh_histinit()
411 void hist_close(register History_t *hp) in hist_close() argument
413 sfclose(hp->histfp); in hist_close()
415 if(hp->auditfp) in hist_close()
417 if(hp->tty) in hist_close()
418 free((void*)hp->tty); in hist_close()
419 sfclose(hp->auditfp); in hist_close()
422 free((char*)hp); in hist_close()
459 static History_t* hist_trim(History_t *hp, int n) in hist_trim() argument
463 register History_t *hist_new, *hist_old = hp; in hist_trim()
499 if(!sh_histinit(hp->histshell)) in hist_trim()
558 static int hist_nearend(History_t *hp, Sfio_t *iop, register off_t size) in hist_nearend() argument
599 hp->histmarker = hp->histcnt = size+4; in hist_nearend()
611 hp->histmarker = hp->histcnt = 2L; in hist_nearend()
625 void hist_eof(register History_t *hp) in hist_eof() argument
629 register off_t count = hp->histcnt; in hist_eof()
631 off_t last = sfseek(hp->histfp,(off_t)0,SEEK_END); in hist_eof()
636 oldind = hp->histind; in hist_eof()
637 if((hp->histind -= hp->histsize) < 0) in hist_eof()
638 hp->histind = 1; in hist_eof()
641 sfseek(hp->histfp,count,SEEK_SET); in hist_eof()
642 while(cp=(char*)sfreserve(hp->histfp,SF_UNBOUND,0)) in hist_eof()
644 n = sfvalue(hp->histfp); in hist_eof()
654 n = hist_ind(hp, ++hp->histind); in hist_eof()
656 if(count==hp->histcmds[n]) in hist_eof()
667 hp->histcmds[n] = count; in hist_eof()
675 hp->histmarker=count+2; in hist_eof()
677 hp->histind--; in hist_eof()
681 hp->histind = ((marker[0]<<16)|(marker[1]<<8)|marker[2] -1); in hist_eof()
689 hp->histind-=2; in hist_eof()
717 hp->histcmds[hist_ind(hp,++hp->histind)] = count; in hist_eof()
719 hp->histcnt = count; in hist_eof()
722 sfputc(hp->histfp,0); in hist_eof()
723 hist_cancel(hp); in hist_eof()
726 oldind -= hp->histind; in hist_eof()
727 hp->histind = hp->histind-hp->histsize + oldind +2; in hist_eof()
728 if(hp->histind<0) in hist_eof()
729 hp->histind = 1; in hist_eof()
733 int fd = open(hp->histname,O_RDWR); in hist_eof()
736 hist_marker(buff,hp->histind); in hist_eof()
751 void hist_cancel(register History_t *hp) in hist_cancel() argument
754 if(!hp) in hist_cancel()
756 sfputc(hp->histfp,HIST_UNDO); in hist_cancel()
757 sfputc(hp->histfp,0); in hist_cancel()
758 sfsync(hp->histfp); in hist_cancel()
759 hp->histcnt += 2; in hist_cancel()
760 c = hist_ind(hp,--hp->histind); in hist_cancel()
761 hp->histcmds[c] = hp->histcnt; in hist_cancel()
768 void hist_flush(register History_t *hp) in hist_flush() argument
771 if(hp) in hist_flush()
773 if(buff=(char*)sfreserve(hp->histfp,0,SF_LOCKR)) in hist_flush()
775 hp->histflush = sfvalue(hp->histfp)+1; in hist_flush()
776 sfwrite(hp->histfp,buff,0); in hist_flush()
779 hp->histflush=0; in hist_flush()
780 if(sfsync(hp->histfp)<0) in hist_flush()
782 hist_close(hp); in hist_flush()
783 if(!sh_histinit(hp->histshell)) in hist_flush()
786 hp->histflush = 0; in hist_flush()
802 register History_t *hp = (History_t*)handle; in hist_write() local
808 if(!hp->histflush) in hist_write()
815 hp->histcnt = cur; in hist_write()
834 if(hp->auditfp) in hist_write()
837 …sfprintf(hp->auditfp,"%u;%u;%s;%*s%c",sh_isoption(SH_PRIVILEGED)?shgd->euserid:shgd->userid,t,hp->… in hist_write()
838 sfsync(hp->auditfp); in hist_write()
860 hp->histcnt += size; in hist_write()
861 c = hist_ind(hp,++hp->histind); in hist_write()
862 hp->histcmds[c] = hp->histcnt; in hist_write()
863 if(hp->histflush>HIST_MARKSZ && hp->histcnt > hp->histmarker+HIST_BSIZE/2) in hist_write()
867 hp->histcnt += HIST_MARKSZ; in hist_write()
868 hist_marker(bufptr,hp->histind); in hist_write()
869 hp->histmarker = hp->histcmds[hist_ind(hp,c)] = hp->histcnt; in hist_write()
878 hp->histwfail = 0; in hist_write()
902 off_t hist_tell(register History_t *hp, int n) in hist_tell() argument
904 return(hp->histcmds[hist_ind(hp,n)]); in hist_tell()
910 off_t hist_seek(register History_t *hp, int n) in hist_seek() argument
912 return(sfseek(hp->histfp,hp->histcmds[hist_ind(hp,n)],SEEK_SET)); in hist_seek()
921 void hist_list(register History_t *hp,Sfio_t *outfile, off_t offset,int last, char *nl) in hist_list() argument
925 if(offset<0 || !hp) in hist_list()
930 sfseek(hp->histfp,offset,SEEK_SET); in hist_list()
931 while((c = sfgetc(hp->histfp)) != EOF) in hist_list()
952 Histloc_t hist_find(register History_t*hp,char *string,register int index1,int flag,int direction) in hist_find() argument
961 if(!hp) in hist_find()
977 index2 = (int)hp->histind; in hist_find()
980 index2 -= hp->histsize; in hist_find()
991 offset = hist_tell(hp,index1); in hist_find()
992 if((location.hist_line=hist_match(hp,offset,string,coffset))>=0) in hist_find()
999 if(((Shell_t*)hp->histshell)->trapnote&SH_SIGSET) in hist_find()
1012 int hist_match(register History_t *hp,off_t offset,char *string,int *coffset) in hist_match() argument
1019 sfseek(hp->histfp,offset,SEEK_SET); in hist_match()
1020 if(!(cp = first = (unsigned char*)sfgetr(hp->histfp,0,0))) in hist_match()
1022 m = sfvalue(hp->histfp); in hist_match()
1060 register History_t *hp = shgd->hist_ptr; in hist_copy() local
1063 if(!hp) in hist_copy()
1065 hist_seek(hp,command); in hist_copy()
1066 while ((c = sfgetc(hp->histfp)) && c!=EOF) in hist_copy()
1086 sfseek(hp->histfp,(off_t)0,SEEK_END); in hist_copy()
1105 History_t *hp = hist_ptr; in hist_word() local
1106 if(!hp) in hist_word()
1108 hist_copy(string,size,(int)hp->histind-1,-1); in hist_word()
1140 Histloc_t hist_locate(History_t *hp,register int command,register int line,int lines) in hist_locate() argument
1144 if(!hp) in hist_locate()
1152 while(command <= hp->histind) in hist_locate()
1163 register int least = (int)hp->histind-hp->histsize; in hist_locate()
1192 History_t *hp = (History_t*)handle; in hist_exceptf() local
1195 if(errno==ENOSPC || hp->histwfail++ >= 10) in hist_exceptf()
1199 if((newfd=open(hp->histname,O_BINARY|O_APPEND|O_CREAT|O_RDWR,S_IRUSR|S_IWUSR)) >= 0) in hist_exceptf()
1205 if(lseek(oldfd,(off_t)0,SEEK_END) < hp->histcnt) in hist_exceptf()
1207 register int index = hp->histind; in hist_exceptf()
1209 hp->histcnt = 2; in hist_exceptf()
1210 hp->histind = 1; in hist_exceptf()
1211 hp->histcmds[1] = 2; in hist_exceptf()
1212 hist_eof(hp); in hist_exceptf()
1213 hp->histmarker = hp->histcnt; in hist_exceptf()
1214 hp->histind = index; in hist_exceptf()
1218 errormsg(SH_DICT,2,"History file write error-%d %s: file unrecoverable",errno,hp->histname); in hist_exceptf()